Configure OIDC Authentication for Cloud Spanner and CloudSQL
Set up keyless authentication for GCP Cloud Spanner and CloudSQL databases using OpenID Connect (OIDC) with Workload Identity Federation in Harness Database DevOps.
OpenID Connect (OIDC) authentication enables your database connectors to authenticate with GCP databases without storing long-lived service account keys. Harness exchanges a short-lived OIDC token for temporary GCP credentials at runtime.
This topic assumes you have experience with GCP workload identity providers.
Prerequisites
Workload Identity Pool: A configured Workload Identity Pool in your GCP project. Go to Set up the GCP workload identity provider in the CI documentation to create the pool.
OIDC provider: An OIDC provider configured with the correct Harness issuer URL for your account cluster. Go to Set up the GCP workload identity provider in the CI documentation to configure the provider.
Service account access grant: The service account must grant access to your Harness account ID via workload identity pool attribute conditions. Go to Grant access to the service account in the CI documentation for configuration steps.
Service account IAM roles: Assign roles to your GCP service account based on the database type you are connecting to:
Workload Identity (required for all databases):
roles/iam.workloadIdentityUser: Allow the Workload Identity SA to impersonate the GCP service account.
BigQuery:
roles/bigquery.admin: Full access to BigQuery datasets and tables.roles/bigquery.jobUser: Run queries and schema operations.roles/iam.serviceAccountTokenCreator: Required for OIDC token exchange.
Cloud Spanner:
roles/spanner.databaseUser: Read/write access to Spanner databases.roles/spanner.databaseAdmin: Schema changes and admin operations.
CloudSQL:
roles/cloudsql.client: Connect to CloudSQL instances.roles/cloudsql.instanceUser: IAM database authentication.
Database instance: A Cloud Spanner instance, CloudSQL PostgreSQL/MySQL instance with IAM authentication enabled, or BigQuery project with datasets configured.
Harness project access: Connector creation permissions in your Harness project. Go to RBAC in Harness to configure roles.
Required GCP APIs: The following APIs must be enabled in your GCP project. Go to Enable required GCP APIs for instructions.
How OIDC authentication works
When you configure a JDBC connector with OIDC authentication:
Token generation: Harness generates a short-lived OIDC token (JWT) that identifies the pipeline execution or connection test request.
Token exchange: The token is exchanged for a GCP OAuth2 access token using Workload Identity Federation:
Connection test: Exchange happens on the delegate.
Pipeline execution: Exchange happens inside the plugin container using GCP Security Token Service (STS).
Service account impersonation: The access token is used to impersonate the specified service account, which has database permissions.
Database connection: The database connection is established using the impersonated service account credentials.
This flow eliminates the need to store service account keys in Harness or your delegate environment. The GCP access token is short-lived (1 hour) and a new token is generated for each pipeline execution or connection test.
Supported databases
OIDC authentication is available for the following GCP database types:
Cloud Spanner: Uses OAuth2 access token authentication via the
oauthTokenJDBC connection property.CloudSQL PostgreSQL: Uses the CloudSQL Socket Factory with IAM authentication and credentials file.
CloudSQL MySQL: Uses the CloudSQL Socket Factory with IAM authentication and credentials file.
BigQuery: Uses OAuth2 access token authentication via the Simba BigQuery JDBC driver.
Generic PostgreSQL or MySQL databases without CloudSQL Socket Factory are not supported.
BigQuery prerequisites
In addition to the common OIDC prerequisites, BigQuery requires:
Required GCP APIs:
Required IAM roles for the service account:
Role descriptions:
roles/bigquery.dataViewer: Read-only access to BigQuery datasets and tables.roles/bigquery.admin: Full access to BigQuery resources.roles/bigquery.jobUser: Required to run BigQuery jobs (queries and schema operations).roles/iam.serviceAccountTokenCreator: Allows generating access tokens during OIDC exchange.
JDBC URL formats
OIDC authentication requires specific URL formats for each database type.
Cloud Spanner URL format
Example:
POSTGRESQL NOT SUPPORTED FOR SPANNER
The PostgreSQL dialect for Spanner is not currently supported and will cause pipeline failures with an image pull error. Use the standard Cloud Spanner GQL.
CloudSQL PostgreSQL URL format
Example:
Required parameters:
cloudSqlInstance: Instance connection name in the formatproject-id:region:instance-name.socketFactory: Must becom.google.cloud.sql.postgres.SocketFactory.enableIamAuth: Must betrue.
CloudSQL MySQL URL format
Example:
Required parameters:
cloudSqlInstance: Instance connection name in the formatproject-id:region:instance-name.socketFactory: Must becom.google.cloud.sql.mysql.SocketFactory.enableIamAuth: Must betrue.
If any required parameter is missing, the connection test will fail with a validation error before attempting to connect.
BigQuery URL format
Example:
Required parameters:
ProjectId: Your GCP project ID where BigQuery datasets reside.DefaultDataset: The default BigQuery dataset for schema operations.Location: The BigQuery dataset location (for example,us-central1,asia-south1).
Before you configure OIDC
Complete the GCP Workload Identity Federation setup before configuring your JDBC connector. Go to Set up the GCP workload identity provider in the CI documentation, which covers issuer URLs for all Harness account clusters (Prod-1, Prod-2, Prod-3) and the attribute condition required for both connection tests and pipeline executions. Return to this page after completing those steps.
Configure OIDC authentication for Cloud Spanner
Create a JDBC connector: In your Harness project, go to Connectors and select New Connector. Choose JDBC.
Enter connection details: In the Connection URL field, enter your Cloud Spanner JDBC URL in the format:
Replace
YOUR_PROJECT_ID,YOUR_INSTANCE, andYOUR_DATABASEwith your Cloud Spanner resource identifiers.Select OIDC authentication: In the Authentication section, select OIDC as the auth type.
Configure GCP OIDC details:
Provider Type: Select GCP.
Project Number: Enter your GCP project number (numeric identifier, not project ID). Go to the GCP Console dashboard to find the project number.
Workload Pool ID: Enter the Workload Identity Pool ID you created in Set up the GCP workload identity provider. This is the
Pool IDvalue shown in the GCP Console under IAM & Admin > Workload Identity Federation.Provider ID: Enter the OIDC provider ID within the pool. This is the
Provider IDvalue shown when you select the provider in the GCP Console.Service Account Email: Enter the email of the service account that has Spanner Database User permissions (for example,
db-sa@project.iam.gserviceaccount.com).
Test the connection: Select Test Connection to verify that the delegate can authenticate and connect to Cloud Spanner.
The connection test runs on the delegate and exchanges the Harness OIDC token for a GCP access token before connecting to the database.

JDBC connector test for Cloud Spanner with OIDC authentication
Configure OIDC authentication for CloudSQL
In your Harness project, go to Connectors and select New Connector. Choose JDBC.
In the Connection URL field, enter your CloudSQL JDBC URL with the following required parameters:
PostgreSQL format:
jdbc:postgresql:///YOUR_DATABASE?cloudSqlInstance=PROJECT_ID:REGION:INSTANCE_NAME&socketFactory=com.google.cloud.sql.postgres.SocketFactory&enableIamAuth=trueMySQL format:
jdbc:mysql:///YOUR_DATABASE?cloudSqlInstance=PROJECT_ID:REGION:INSTANCE_NAME&socketFactory=com.google.cloud.sql.mysql.SocketFactory&enableIamAuth=true
In above URLs, replace the placeholders with your CloudSQL resource identifiers:
YOUR_DATABASE: The database name within the CloudSQL instance.PROJECT_ID:REGION:INSTANCE_NAME: Your CloudSQL instance connection name (for example,my-project:us-central1:my-instance).
Select OIDC authentication: In the Authentication section, select OIDC as the auth type.
Configure GCP OIDC details:
Provider Type: Select GCP.
Project Number: Enter your GCP project number (numeric identifier, not project ID). Go to the GCP Console dashboard to find the project number.
Workload Pool ID: Enter the Workload Identity Pool ID you created in Set up the GCP workload identity provider. This is the
Pool IDvalue shown in the GCP Console under IAM & Admin > Workload Identity Federation.Provider ID: Enter the OIDC provider ID within the pool. This is the
Provider IDvalue shown when you select the provider in the GCP Console.Service Account Email: Enter the email of the service account that has CloudSQL IAM user permissions (for example,
db-sa@project.iam.gserviceaccount.com).
Select Test Connection to verify that the delegate can authenticate and connect to CloudSQL.
The connection test runs on the delegate and uses the CloudSQL Socket Factory to establish an IAM-authenticated connection.

JDBC connector test for CloudSQL with OIDC authentication
Username derivation: The database username is derived automatically from the service account email:
PostgreSQL: Strips the
.gserviceaccount.comsuffix. For example,db-sa@project.iam.gserviceaccount.combecomesdb-sa@project.iam.MySQL: Uses the prefix before the
@symbol. For example,db-sa@project.iam.gserviceaccount.combecomesdb-sa.
Ensure that a database user with this username exists in your CloudSQL instance and is granted appropriate permissions. Go to CloudSQL IAM authentication to create IAM database users.
Configure OIDC authentication for BigQuery
In your Harness project, go to Connectors and select New Connector. Choose JDBC.
In the Connection URL field, enter your BigQuery JDBC URL:
Replace the placeholders with your BigQuery resource identifiers:
YOUR_PROJECT_ID: Your GCP project ID where BigQuery datasets reside.YOUR_DATASET: The default BigQuery dataset for schema operations.YOUR_REGION: Optional. The BigQuery dataset location (for example,us-central1,asia-south1).
In the Authentication section, select OIDC as the auth type.
Configure GCP OIDC details:
Provider Type: Select GCP.
Project Number: Enter your GCP project number (numeric identifier, not project ID). Go to the GCP Console dashboard to find the project number.
Workload Pool ID: Enter the Workload Identity Pool ID you created in Set up the GCP workload identity provider. This is the
Pool IDvalue shown in the GCP Console under IAM & Admin > Workload Identity Federation.Provider ID: Enter the OIDC provider ID within the pool. This is the
Provider IDvalue shown when you select the provider in the GCP Console.Service Account Email: Enter the email of the service account that has BigQuery permissions (for example,
bigquery-sa@project.iam.gserviceaccount.com).
Select Test Connection to verify that the delegate can authenticate and connect to BigQuery.
The connection test runs on the delegate and exchanges the Harness OIDC token for a GCP access token before connecting to BigQuery using the Simba BigQuery JDBC driver.
Use OIDC connectors in pipelines
When you reference a JDBC connector with OIDC authentication in a Database DevOps step (Liquibase or Flyway), Harness automatically handles the token exchange and authentication flow.
Pipeline execution flow
Token generation: Harness generates a pipeline-scoped OIDC token (JWT) that includes custom attributes identifying the pipeline, organization, project, and connector.
Environment variables: The following environment variables are passed to the plugin container:
PLUGIN_GCP_OIDC_TOKEN: Harness OIDC JWT.PLUGIN_GCP_OIDC_WORKLOAD_POOL_ID: Workload Identity Pool ID.PLUGIN_GCP_OIDC_PROVIDER_ID: OIDC Provider ID.PLUGIN_GCP_OIDC_PROJECT_ID: GCP Project Number.PLUGIN_GCP_OIDC_SERVICE_ACCOUNT_EMAIL: Service Account Email.
Token exchange in plugin: The plugin container exchanges the Harness OIDC token for a GCP access token using GCP Security Token Service (STS). This exchange happens inside the plugin container and the GCP access token never leaves the customer infrastructure.
Database authentication: The plugin uses the GCP access token to authenticate with the database:
Cloud Spanner: Token is passed as the
oauthTokenJDBC connection property.CloudSQL: Token is written to a credentials file and the CloudSQL Socket Factory handles authentication.
Plugin image selection: For CloudSQL PostgreSQL/MySQL connectors with OIDC authentication, Harness automatically selects the CloudSQL-compatible plugin image that includes the Socket Factory.
No additional configuration is required in the step definition. The token exchange and authentication are fully automated.
Example pipeline execution:
The following screenshot shows a successful Database DevOps Apply step execution using OIDC authentication for both Cloud Spanner and CloudSQL databases:

Connector JSON structure
The OIDC connector uses a polymorphic structure that supports multiple cloud providers. The current implementation supports GCP, and the schema is designed to allow future extension to AWS and Azure without breaking changes.
Next steps
Now that you have configured OIDC authentication, you can use your connector in Database DevOps pipelines. Go to Create a Database DevOps pipeline to build automated database change workflows.
Last updated
Was this helpful?