Use Managed Microsoft AD with Cloud SQL

MySQL  |  PostgreSQL  |  SQL Server

This page describes the ways to use Cloud SQL to:

  • Integrate with Managed Service for Microsoft Active Directory(also called Managed Microsoft AD).
  • Connect to an instance with an AD user.

A Cloud SQL instance that is integrated with Managed Microsoft AD supportsWindows Authenticationin addition to SQL Authentication.

Note: Before integrating, review theOverview of Managed Microsoft AD in Cloud SQL, including theLimitations and alternatives.

Before you begin

  1. In the Google Cloud console,select your project name.
  2. Make sure that billing is enabled for your Google Cloud project.Learn how to confirm billing is enabled for your project.
  3. Install and initializethe gcloud CLI.
  4. Make sure that you have theCloud SQL Admin role on your user account.Go to the IAM page.
  5. Review theprerequisites for integration.

Create an instance with Windows Authentication

Note: If you are integrating with a managed AD domain in a different project,first review theprocedures and constraints.

You can integrate with Managed Microsoft AD duringinstance creation,enabling Windows Authentication for the instance. To integrate, you choose adomain for the instance to join. If joining a domain fails, instance creationfails.

In preparation for creating an instance with Windows Authentication, review thetips and thelimitations and alternatives.

Note: In rare cases, instance creation thatincludes Windows Authentication can take up to 30 minutes.

An instance with public IP is supported, as long as it has private IP as well;private IP must be enabled for the instance. Then you can choose to use publicIP or private IP to connect to the instance, as long as both are available.

Note: After you create an instance with WindowsAuthentication, an extra Cloud SQL for SQL Server login is created. The loginis in the format[domain]\sql_[letters-and-digits]. For example,Cloud SQL might create a login namedAD\sql_1a1a6145bc1aaaa. The loginis in the Managed AD domain. You can ignore the login. You can't remove it.However, if you disable Windows Authentication for the instance, the login isautomatically deleted.

The following are the options for creating an instance that is integrated withManaged Microsoft AD.

Console

Note: Before starting the following steps, review theprerequisites for integration. Additionally, note theprocedures and constraints for integratingwith a managed AD domain in a different project.
  1. In the Google Cloud console, go to theCloud SQL Instances page.

    Go to Cloud SQL Instances

  2. ClickCreate instance.
  3. ClickChoose SQL Server.
  4. Enter a name for the instance. Do not include sensitive or personally identifiable information in your instance name; it is externally visible. You do not need to include the project ID in the instance name. This is created automatically where appropriate (for example, in the log files).
  5. Enter the password for the'sqlserver'user.
  6. Set the region for your instance. See Best practices for integrating with Managed Microsoft AD.
  7. In theConfiguration options section, set your desired options (but wait until the next step for the authentication options).
  8. ClickAuthentication. The dropdown menu for joining a managed Active Directory domain lists any Managed Microsoft AD domains that previously were added in your project.
  9. From the dropdown menu for joining a managed Active Directory domain, select a domain.
  10. When you are finished selecting your configuration options, clickCreate. Cloud SQL automatically creates a Per-Product, Per-Project Service account for you. If the account doesn't have the appropriate role, you are prompted to grant themanagedidentities.sqlintegrator role.

gcloud

Note: Before starting the following steps, review theprerequisites for integration. Additionally, note theprocedures and constraints for integratingwith a managed AD domain in a different project.

The following command creates an instance that is integrated with ManagedMicrosoft AD and thus is enabled for Windows Authentication. For informationabout the basic command for creating an instance, seeCreating instances.

Specify a parameter of--active-directory-domain=DOMAINin thegcloud command. For example, specify the following:--active-directory-domain=ad.mydomain.com

Here is a prototype of thegcloud command:

gcloudbetasqlinstancescreateINSTANCE_NAME\--database-version=EDITION\--root-password=PASSWORD\--active-directory-domain=DOMAIN\--cpu=CPU\--memory=MEMORY\--network=NETWORK

Terraform

To create an instance that is integrated with Managed Microsoft AD, use aTerraform resource.

resource "google_sql_database_instance" "instance_with_ad" {  name             = "database-instance-name"  region           = "us-central1"  database_version = "SQLSERVER_2019_STANDARD"  root_password    = "INSERT-PASSWORD-HERE"  depends_on = [google_service_networking_connection.private_vpc_connection]  settings {    tier = "db-custom-2-7680"    active_directory_config {      domain = "ad.domain.com"    }    ip_configuration {      ipv4_enabled    = "false"      private_network = google_compute_network.private_network.id    }  }  # set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by  # use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.  deletion_protection = false}

REST

Note: Before starting the following steps, review theprerequisites for integration. Additionally, note theprocedures and constraints for integratingwith a managed AD domain in a different project.

Using the REST API, you can create an instance that is integrated withManaged Microsoft AD. Specify a domain, such assubdomain.mydomain.com, for thedomain field,as shown in this prototype of a request:

{   "databaseVersion":"database-version",   "name":"instance-id",   "region":"region",   "rootPassword":"password",   "settings":{      "tier":"machine-type",      "ipConfiguration":{         "privateNetwork":"network"      },      "activeDirectoryConfig":{         "domain":"domain"      }   }}

Update an instance with Windows Authentication

You can update the domain of an existing instance, changing or adding a domain.

Caution: Removing Windows Authentication causesan instanceto restart.

For general information about updating an instance, seeEditing instances.

Note: Before starting the steps in this section,review theprerequisites for integration and thebest practices.

If an instance is currently joined with a Managed AD domain, theinstance is initiallyunjoined from that domain, before it is joined to the new domain. If the updatefails, the instance may no longer be joined to any domain.

Note: An instance with public IP is supported,as long as it has private IP as well; private IP must be enabled forthe instance. Then you can choose to use public IP or private IP to connectto the instance, as long as both are available.

Console

  1. In the Google Cloud console, go to theCloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open theOverview page of an instance, click the instance name.
  3. ClickEdit.
  4. ClickAuthentication. TheJoin an Active Directory domain dropdown menu lists the Managed Microsoft AD domains that previously were added in your project.
  5. From the dropdown menu for joining a managed Active Directory domain, select a new (replacement) domain for your instance.
  6. ClickSave to apply your changes.

gcloud

The following is a prototype of a command to update an existing instance.The command either adds orreplaces a domain. Pass--active-directory-domain=DOMAIN to thecommand, as follows:

gcloudbetasqlinstancespatchINSTANCE_NAME\--active-directory-domain=DOMAIN

REST

Using the REST API, you can update an existing instance. Specify a domain,such assubdomain.mydomain.com, in thedomain field.The following is a prototype of a request:

{   "settings":{      "activeDirectoryConfig":{         "domain":"domain"      }   }}

Integrate with a managed AD domain in a different project

You can integrate your instance with a Managed Microsoft AD domain that is in adifferent project.

Note: Integrating with an AD domain in a differentproject requires use ofgcloud commands or the Cloud SQL REST API.Currently, you can't use the Google Cloud console for this purpose.

While planning your integration, review theconstraints.

Enable domain peering

Before proceeding with the steps in the sections below,enable domain peeringso your domain is available to all necessary projects with Cloud SQL for SQL Server instances.

For a list of domains from other projects that already are available, you canspecify the following:

`gcloudactive-directorypeeringslist`

For more information, seeList domain peerings.

Thegcloud active-directory peerings list command requires themanagedidentities.peerings.list permission. The following roles have thispermission:

  • roles/managedidentities.peeringViewer
  • roles/managedidentities.viewer

For more information, seeAccess control with IAM.

Create a service account

Repeat these steps for each project that contains a Cloud SQL for SQL Server instance that youintend to integrate.

  1. Review thebackground information for creating service accounts.
  2. Use a command similar to the following to create a service account. Specifythe ID of the project containing Cloud SQL for SQL Server instances:

    gcloudbetaservicesidentitycreate--service=sqladmin.googleapis.com\--project=[PROJECT_ID]
  3. Grant themanagedidentities.sqlintegrator role in the projectwith the Managed Microsoft AD instance. Specify the ID of the projectcontaining the Managed Microsoft AD instance:

    gcloudprojectsadd-iam-policy-binding[PROJECT_ID]\--member=serviceAccount:SERVICE_ACCOUNT--role=roles/managedidentities.sqlintegrator

Enable cross-project Windows authentication

You can integrate with an AD domain in a different project usinggcloudcommands or the Cloud SQL REST API. In either case, you must specify the fulldomain resource name.

Specify the full domain resource name when a Cloud SQL for SQL Server instance is created orupdated. Two formats are supported:

  • projects/PROJECT_ID/locations/global/domains/DOMAIN_NAME
  • projects/PROJECT_NUMBER/locations/global/domains/DOMAIN_NAME

Here is an example usinggcloud:

gcloudbetasqlinstancespatchINSTANCE_NAME\--active-directory-domain=projects/PROJECT_ID/locations/global/domains/DOMAIN_NAME

If you use a short domain resource name (such asDOMAIN_NAME), thesystem assumes that your Managed Microsoft AD domain is in the same project asyour Cloud SQL for SQL Server instances.

Constraints for integrating with different projects

If you are integrating with a managed AD domain in a different project, thefollowing constraints apply:

  • Up to 10 networks with Cloud SQL for SQL Server instances can share one ManagedMicrosoft AD instance located in a different project.
  • The Google Cloud console only supports Managed Microsoft AD instances located inthe same project. Instead of using the Google Cloud console, you can integrateusinggcloud commands or the Cloud SQL REST API.
  • If VPC Service Controls are used, Cloud SQL for SQL Server instances and a ManagedMicrosoft AD instance must be located in the same perimeter.

Additionally, if an instance is integrated with a managed AD domain in adifferent project, the fully qualified domain name (FQDN) shown in theGoogle Cloud console might be inaccurate for that instance. Specifically, on theOverview page for that instance, underConnect to this instance, theFQDNs might contain strings separated by slashes, which you can ignore.For example, an inaccurate FQDN might be shown as:

private.myinstance.myregion.myproject.projects/mydirectory/locations/global/domains/mydomain.com

In that case, the accurate FQDN is:

private.myinstance.myregion.myproject.cloudsql.mydomain.com

Remove Windows Authentication from an instance

You can remove Windows Authentication, and thus a Managed Microsoft ADintegration, from an existing instance.

Caution: Removing Windows Authentication causesan instanceto restart.

Console

  1. In the Google Cloud console, go to theCloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open theOverview page of an instance, click the instance name.
  3. ClickEdit.
  4. ClickAuthentication. The dropdown menu for joining a managed Active Directory domain lists the Managed Microsoft AD domains that previously were added in your project.
  5. From the dropdown menu, selectNo domain/Join later for your instance.
  6. Read the message about instance restart, and clickClose.
  7. ClickSave to apply your changes.

gcloud

To remove an instance from a domain, thus removing Windows Authentication,use a blank value for the domain. That is, in your command, use a blank valuefor the--active-directory-domain parameter, as follows:

gcloudbetasqlinstancespatchINSTANCE_NAME\--active-directory-domain=

REST

Using the REST API, you can remove an instance from a domain. Specify a blankvalue in thedomain field, as follows:

{   "settings":{      "activeDirectoryConfig":{         "domain":""      }   }}

Connect to an instance with a user

For Cloud SQL for SQL Server, the defaultuser issqlserver.

After you integrate an instance with Managed Microsoft AD, you can connect tothe instance with thesqlserver user, as follows:

  1. Create a SQL Server login based on a Windows user or group, as follows:

    CREATELOGIN[domain\user_or_group]FROMWINDOWS
  2. Log in to the instance, using Windows Authentication, with the instance DNSname. Examples of instance DNS names to specify are the following:

    • To connect through private IP:

      private.myinstance.us-central1.myproject.cloudsql.mydomain.com

    • To connect via public IP:

      public.myinstance.us-central1.myproject.cloudsql.mydomain.com

    • To connect via the Cloud SQL Auth Proxy(also seebelow):

      proxy.myinstance.us-central1.myproject.cloudsql.mydomain.com

    If you use the instance IP address, you mustconfigurethe Kerberos clients.to support IP hostnames. Cloud SQL doesn't support logins from domainsconnected through a trust relationship.

Note: Cloud SQL doesn't support this connection functionality from domainsconnected using a trust relationship. For such domains, seeOn-premises AD users: Creating a Windows login.

Use the Cloud SQL Auth Proxy with Windows Authentication

You can use the Cloud SQL Auth Proxy with your Managed Microsoft AD integration.

Before you begin, review:

Steps for Windows Authentication

For background on starting the Cloud SQL Auth Proxy, seeStart the Cloud SQL Auth Proxy.

For Windows Authentication, you must run the Cloud SQL Auth Proxy on port 1433.To map a predefined Service Principal Name (SPN) entry to a Cloud SQL Auth Proxy address, use:

proxy.[instance].[location].[project].cloudsql.[domain]

Run the Cloud SQL Auth Proxy locally

If you run the Cloud SQL Auth Proxy locally, use your hosts file to map the following to127.0.0.1:

proxy.[instance].[location].[project].cloudsql.[domain]

As an example, you could add the following to the hosts file(for example, toc:\windows\system32\drivers\etc\hosts):

127.0.0.1proxy.[instance].[location].[project].cloudsql.[domain]

In that example, you could run the Cloud SQL Auth Proxy using this command, and make itavailable on127.0.0.1:1433:

cloud-sql-proxy.exe--credentials-filecredential.jsonproject:name

Run the Cloud SQL Auth Proxy non-locally

To run the Cloud SQL Auth Proxy non-locally, follow the instructions inRunning the Cloud SQL Auth Proxy locally, but use a different entryin the hosts file.

Specifically, if a non-local host is, for example,MyOtherHost,you could add the following to the hosts file:

127.0.0.1MyOtherHostproxy.[instance].[location].[project].cloudsql.[domain]

Troubleshoot for NTLM fallback in clients

If you use Windows Authentication and an instance IPaddress to log in to an instance, you mustconfigure a Kerberos clientto support IP hostnames.

Cloud SQL doesn't support NTLM authentication, but some Kerberos clients might try tofall back to it. As discussed in this section, if you try to connect with SQLServer Management Studio (SSMS), and the following error message occurs, alikely cause is NTLM fallback:

Loginfailed.TheloginisfromanuntrusteddomainandcannotbeusedwithIntegratedauthentication.(MicrosoftSQLServer,Error:18452)

NTLM is a set of Microsoft security protocols for authentication. Also seeReasons for NTLM fallback.

Verification of an NTLM fallback for a Windows client

From Windows, to verify that an NTLM fallback caused an error::

  1. Log in with the desired on-premises credentials (do not use "Run as...").
  2. Open a command prompt.
  3. Runklist purge.
  4. From SSMS, try to connect to SQL Server with Windows Authentication.
  5. Runklist and check if there's a ticket issued for"MSSQLSvc/<address>:1433 @ domain".
  6. If there's no such ticket, NTLM fallback is the likely cause for the error.
  7. If there is such a ticket, check that your SQL Server driver doesn't enforceNTLM authentication. Also check if NTLM authentication is enforced via GroupPolicy.

Verification of an NTLM fallback for a Linux client

From Ubuntu 16.04, to verify that an NTLM fallback caused an error,use the steps in this section. The steps are similar as those for other Linuxdistributions.

Set up Kerberos authentication

  1. Set up a Kerberos client:

    sudoapt-getinstallkrb5-user
  2. When you are prompted for the default realm, type an on-premises domain namein uppercase letters.

  3. Run the following to install SQL Server command-line tools:

    curlhttps://packages.microsoft.com/keys/microsoft.asc|sudoapt-keyadd-curlhttps://packages.microsoft.com/config/ubuntu/16.04/prod.list|sudotee/etc/apt/sources.list.d/msprod.listsudoapt-getupdatesudoapt-getinstallmssql-toolsunixodbc-dev

Connect with Windows Authentication

  1. Run the kinit tool as follows:kinit <user_account>
  2. To connect with Windows Authentication, run:/opt/mssql-tools/bin/sqlcmd -S <address >>
  3. Run theklist command and check whether a ticket was issuedspecifically for:"MSSQLSvc/<address>:1433 @ domain"
  4. If the ticket wasn't issued, the above error likely indicates an issuethat causes NTLM fallback.

Reasons for NTLM fallback

Fallback onto NTLM is a client misconfiguration that can be associated withthe following conditions:

  • By default, Windows doesn't attempt Kerberos authentication for a host if thehostname is an IP address. To enable Kerberos authentication from the manageddomain, try the method described in theMicrosoft documentation.This method doesn't work with on-premises credentials when you must use FQDNS.
  • Kerberos authentication over external trusts doesn't work. Use forest trustsinstead, as describedhere.
  • Kerberos authentication requires name suffix routing to enable the finding ofservices in another forest. Try the method describedhere.
  • Kerberos authentication doesn't work if there's no SPN registered for theservice. Use only FQDNs or IP addresses you obtain from the Google Cloud consoleto connect with Windows Authentication.

On-premises AD users: Creating a Windows login

Note: Using an on-premises AD user to create aWindows login isn't recommended. Instead,use a Managed AD user or asqlserver account in Cloud SQL.

You can use an on-premises AD user to create a Windows login to Cloud SQL forSQL Server.

As an example, you can connect using SQL Server Management Studio(SMSS) running on a Windows VM hosted in your Google Cloud project's VirtualPrivate Cloud (VPC).

For Windows Authentication in this context, Cloud SQL for SQL Server onlysupports the Kerberos protocol. For Kerberos-based Windows Authentication, theclient must resolve the DNS name of the on-premises AD and the Managed MicrosoftAD.

Configure one-way or two-way trust

Initially, decide whether to use aone-way or two-way trust relationship.Note:We strongly recommend that you use a two-way trust relationship between a Managed AD domainand an on-premises domain because one-way trust instances might experiencelong-running connection drops and can't run certain privileged operations, such as create and drop login. For more information, seeUnderstand Active Directory authentication for SQL Server on Linux and containers.

Then, follow theinstructions for establishing trustbetween the on-premises AD domain and the Managed Microsoft AD domain.

Set up a Windows VM and create a Windows login

After you establish trust between the on-premises AD domain and theManaged Microsoft AD domain, complete the following steps. For examplepurposes,these steps use SQL Server Management Studio (SSMS), running on a Windows VM,hosted in your Google Cloud project's VPC:

  1. Create a Windows VM.
    • Create a VMwith aversion of Windows supported by Managed Microsoft AD.
    • Create the VM in the project that hosts your Managed Microsoft ADdomain. If there is a Shared VPC that is an authorized network, you canalso create the VM in any of its service projects.
    • Create the VM on a VPC network that is an authorized network of theManaged Microsoft AD domain and has configured private serviceaccess for Cloud SQL.
  2. Jointhe Windows VM to the Managed Microsoft AD domain.
  3. Install SSMSon the Windows VM.
  4. Resolve the on-premises domain in the VPC network.
    • From the authorized network on which the Windows VM is running, enableon-premises DNS resolution using the steps on theResolve queries for non-Managed Microsoft AD objectspage. The steps on that page are prerequisites for Kerberos-basedWindows Authentication to work for on-premises users.
  5. Create a Windows login for an on-premises user.

    • Follow theCREATE LOGIN instructionsfor creating a Windows login for an on-premises user. For example,specify a command similar to the following:
    CREATELOGIN[DOMAIN_NAME\USER_NAME]FROMWINDOWS
  6. Log in to your Cloud SQL for SQL Server instance using theapplication-specific instructions for logging in an on-premises user. Forexample, if you are using SQL Server Management Studio, refer tothese instructions.

Resolve problems related to an on-premises AD user

If a problem occurs during a login to a Cloud SQL for SQL Server instance, perform theseverifications:

  • Verify the firewall configurations of the on-premises network andproject-authorized VPC, using the instructions forcreating a trust with an on-premises domain.
  • Verify theName Suffix Routingfor the on-premises trust relationship.
  • Verify that you can perform these DNS resolution operations from the WindowsVM that is running SSMS:
    • nslookup fqdn-for-managed-ad-domain
    • nslookup fqdn-for-on-premises-ad-domain
    • nslookup fqdn-for-cloud-sql-server-instance

Tips

Note: In addition to reviewing the tips in thissection, seeLimitations and alternatives.

Troubleshoot

Click the links in the table for details:

For this error...The issue might be...Try this...
Per-product, per-project service account not found.The service account name is incorrect.On the Service Accounts page, ensure that you created a service account for the correct user project.
Insufficient permission to integrate with Managed Service for Microsoft Active Directory domain.Themanagedidentities.sqlintegrator role is missing on the service account.From the IAM and Admin page, add themanagedidentities.sqlintegrator role on your service account.
Domain not found.The domain does not exist or was mistyped.Ensure the domain name is correct. It is case sensitive.
The domain is busy with another operation. Please retry.Another Cloud SQL instance is running an operation on the same Managed Active Directory domain.Retry the operation. If you are performing a batch of updates to Cloud SQL instances connected to the same domain, limit how many are performed in parallel.
The operation completed but an update to Active Directory failed. You may experience issues with Windows Authentication on this instance, please see https://cloud.google.com/sql/docs/sqlserver/configure-ad for tips.The required updates could not be performed on the Managed Active Directory domain.If you experience issues with Windows Authentication, you can try unjoining the managed Active Directory domain and then rejoining it. To do so, use the update procedure to unjoin and then to rejoin the domain. Doing so doesn't remove any existing Windows-authenticated users or logins that exist in your databases. However, removing Windows Authentication causes an instanceto restart.
This instance would need a more recent creation date to support Managed Service for Microsoft Active Directory.In Cloud SQL, if a Cloud SQL for SQL Server instance was created on or before March 12, 2021, it cannot be integrated with Managed Microsoft AD.Try your operation on an instance created after March 12, 2021.

What's next

  • Confirm that you have fully reviewed theoverview page, which includes limitations and unsupported features.That page also includes links to additional documentation.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-18 UTC.