Introduction
Applications often need to access services across cloud providers. For example, an application running on a Google Cloud Platform (GCP) Compute Engine virtual machine might need to read an object from Oracle Cloud Infrastructure (OCI) Object Storage or retrieve a secret from OCI Vault.
One approach is to provision OCI API credentials and make them available to the application. As the number of workloads grows, distributing, securing, and rotating those credentials becomes an operational responsibility.
Workload Identity Federation (WIF) provides another approach: a workload uses an identity issued by a trusted provider to obtain temporary credentials for a target environment. The target validates the workload’s identity, maps it to an authorized principal, and grants access according to its access policies.
In this blog, we will demonstrate federation from a workload running in GCP to OCI. We will retrieve a Google-signed ID token from a Compute Engine VM, exchange it for an OCI User Principal Session Token (UPST), and use the resulting session credentials to access OCI services. We will then extend the exchange to use CIMD and a signed client assertion instead of a client secret.
For our scenario:
- Workload: An application running on a GCP Compute Engine VM.
- Source identity: The GCP service account attached to the VM.
- Identity token issuer: Google.
- Target environment: OCI.
- OCI principal: A service user selected through the configured identity mapping.
- Target resources: OCI Object Storage and OCI Vault secrets.
Here, WIF describes federation into OCI. This walkthrough does not require creating a Google Cloud Workload Identity Pool, which is used for federation into Google Cloud.
High-level flow
The VM obtains a Google-signed ID token, exchanges it for a temporary OCI token, and uses it to call OCI services.

Before you begin
OCI requirements
- An OCI tenancy and IAM identity domain, with administrator access to create the service user, confidential application, and Identity Propagation Trust.
- Permission to manage groups and create IAM policies for access to OCI resources.
- An Object Storage bucket containing a sample object and an OCI secret for testing.
GCP requirements
- A GCP project and a user with permission to create a VM, create a service account, attach it to the VM, and connect through SSH.
- A Linux VM with network access to its metadata server, the OCI IAM domain, Object Storage, Secrets, and the package repositories used below.
Use an API client such as Postman for the OCI setup requests, the Google Cloud Console for VM and service-account setup, and Bash inside the VM for token exchange and API calls. Replace all values enclosed in angle brackets. Use the OCI domain URL without a trailing slash throughout.
Preparing the OCI IAM domain
Before configuring OCI, obtain an access token with the Identity Domain Administrator role. Follow Oracle’s instructions to configure an administrative confidential application and generate an access token using client credentials.
Use this token as the Bearer token in the service-user and trust API requests below. You can send these requests using an API client such as Postman.
1. Create a service user
Create a service user to represent the federated GCP workload in OCI. Send a POST request to the following endpoint with the headers and JSON body shown below.
Request
POST https://<Your-domain>.identity.oraclecloud.com/admin/v1/Users
Authorization: Bearer <identity-domain-admin-access-token>
Content-Type: application/json
Body
{
"schemas": [
"urn:ietf:params:scim:schemas:core:2.0:User"
],
"userName": "gcp-wif-service-user",
"urn:ietf:params:scim:schemas:oracle:idcs:extension:user:User": {
"serviceUser": true
}
}
Copy the service user’s ocid from the response. We will use it when creating the trust configuration.
In the OCI Console, add this user to a group and create an IAM policy granting access to OCI resources such as Object Storage and Secrets. For example, create a group named gcp-wif-workloads and use these policy statements:
Allow group '<domain-name>'/'gcp-wif-workloads' to read objects in compartment <object-compartment-name>
Allow group '<domain-name>'/'gcp-wif-workloads' to read secret-bundles in compartment <secret-compartment-name>
Replace the domain and compartment names with your values.
2. Create a token exchange OAuth client
Create a confidential application using the OCI Console. The GCP workload will use its client ID and client secret for client authentication at the OCI token endpoint.
- Open Identity & Security → Domains and select your identity domain.
- Select Integrated applications → Add application → Confidential Application.
- Enter an application name and configure the application as an OAuth client.
- Select Client credentials as the allowed grant type. Leave administrative app roles unassigned for this token exchange client.
- Finish the workflow and activate the application.
- Record the client ID and client secret.
3. Configure Identity Propagation Trust
Create a trust configuration that validates Google-issued ID tokens and maps the accepted identity to the service user. Send a POST request with the following headers and body.
Request
POST https://<your-domain>.identity.oraclecloud.com/admin/v1/IdentityPropagationTrusts
Authorization: Bearer <identity-domain-admin-access-token>
Content-Type: application/json
Body
{
"schemas": [
"urn:ietf:params:scim:schemas:oracle:idcs:IdentityPropagationTrust"
],
"name": "GCP JWT to OCI UPST",
"type": "JWT",
"active": true,
"issuer": "https://accounts.google.com",
"publicKeyEndpoint": "https://www.googleapis.com/oauth2/v3/certs",
"oauthClients": [
"<token-exchange-client-id>"
],
"allowImpersonation": true,
"subjectType": "User",
"impersonationServiceUsers": [
{
"rule": "sub eq *",
"ocid": "<service-user-ocid>"
}
]
}
Replace <token-exchange-client-id> with the client ID from step 2 and <service-user-ocid> with the user’s OCID from step 1. Save the trust’s returned id; it is used later when adding the CIMD client.
Google publishes the issuer and public-key endpoint in its OpenID configuration.
The sub eq * rule is used here for testing. In production, use specific subject-matching rules to control which GCP service-account identities can map to the OCI service user.
Preparing the GCP workload and calling OCI
1. Create or use an existing VM
In the Google Cloud Console, select your project and open Compute Engine → VM instances.
Select Create instance to create a Linux VM, or use an existing VM. For this walkthrough, I used Debian GNU/Linux 12 (Bookworm) with the E2 e2-micro machine type for low-cost testing.
2. Create and attach a service account
In the Google Cloud Console:
- Open IAM & Admin → Service Accounts → Create service account.
- Enter a name such as
gcp-oci-wifand finish creating the account. - Return to Compute Engine → VM instances and stop the VM.
- Open the VM’s Edit page and select the service account in its Service account settings.
- Save the changes and start the VM.
If you already have a suitable service account, attach that account instead. For detailed instructions, please refer to Google’s service-account creation and attachment steps.
3. Connect to the VM
On the VM instances page, click SSH next to your VM. This opens SSH-in-browser, a terminal in a browser window connected to the VM. Run the following commands in that terminal. (Google’s SSH-in-browser guide)
Confirm the attached service account:
curl -sS \
-H 'Metadata-Flavor: Google' \
'http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/email'
Install the required tools and prepare a working directory. The following commands are for Debian 12:
sudo apt-get update
sudo apt-get install -y python3 python3-pip python3-venv curl openssl
mkdir -p ~/gcp-oci-wif
cd ~/gcp-oci-wif
python3 -m venv ~/oci-wif-venv
source ~/oci-wif-venv/bin/activate
python3 -m pip install oci
4. Obtain a Google-signed ID token
Set your OCI domain URL and request an ID token from the metadata server:
export OCI_DOMAIN_URL='https://<your-domain>.identity.oraclecloud.com'
export GCP_ID_TOKEN="$(
curl -sS --get \
-H 'Metadata-Flavor: Google' \
--data-urlencode "audience=$OCI_DOMAIN_URL" \
--data-urlencode 'format=full' \
'http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity'
)"
echo "$GCP_ID_TOKEN"
Inspect the token. It should contain the following claims:
| Claim | Expected value |
|---|---|
iss | https://accounts.google.com |
aud | The OCI domain URL supplied in the request |
sub | The unique ID of the service account attached to the VM |
email | The service account’s email address |
iat and exp | Token issue and expiration times |

The token is signed by Google. OCI uses Google’s public keys to validate it during the exchange. (Google’s identity-token documentation)
5. Generate an RSA key pair
Generate the private key and extract its public key:
openssl genrsa -out gcp_oci_session_key.pem 2048
openssl rsa \
-in gcp_oci_session_key.pem \
-pubout \
-out gcp_oci_session_pub.pem
export OCI_SESSION_PUBLIC_KEY="$(
sed '/^-----/d' gcp_oci_session_pub.pem | tr -d '\r\n'
)"
The exchange takes the public-key value without PEM headers, footers, or line breaks. The private key will be used later to sign OCI API requests.
6. Exchange the Google ID token for a UPST
Set the client ID and client secret of the token exchange application created in OCI:
export OCI_WIF_CLIENT_ID='<token-exchange-client-id>'
export OCI_WIF_CLIENT_SECRET='<token-exchange-client-secret>'
Call the OCI token endpoint with the Google ID token and public key:
curl -sS --request POST "$OCI_DOMAIN_URL/oauth2/v1/token" \
--user "$OCI_WIF_CLIENT_ID:$OCI_WIF_CLIENT_SECRET" \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \
--data-urlencode 'requested_token_type=urn:oci:token-type:oci-upst' \
--data-urlencode 'subject_token_type=jwt' \
--data-urlencode "subject_token=$GCP_ID_TOKEN" \
--data-urlencode "public_key=$OCI_SESSION_PUBLIC_KEY" \
--output oci-upst-response.json
cat oci-upst-response.json
Inspect the response. A successful exchange returns the UPST in the token field:
{
"token": "<OCI-UPST>"
}

OCI validates the Google token, maps the identity to the configured service user, and issues the UPST bound to the supplied public key. We will use this response file and the matching private key in the next step.
7. Call OCI APIs
Use the UPST and private key with the OCI Python SDK’s SecurityTokenSigner to sign API requests.
Set your target resources. This example assumes the bucket and secret are in the same OCI region:
export OCI_REGION='us-ashburn-1'
export OCI_BUCKET_NAME='<existing-bucket-name>'
export OCI_OBJECT_NAME='<existing-object-name>'
export OCI_SECRET_OCID='<secret-ocid>'
Create the following Python script:
cat > gcp_oci_access.py <<'PY'
import base64
import json
import os
from pathlib import Path
import oci
with open("oci-upst-response.json") as f:
upst = json.load(f)["token"]
private_key = oci.signer.load_private_key_from_file("gcp_oci_session_key.pem")
signer = oci.auth.signers.SecurityTokenSigner(upst, private_key)
config = {"region": os.environ["OCI_REGION"]}
# Access Object Storage.
storage = oci.object_storage.ObjectStorageClient(config, signer=signer)
namespace = storage.get_namespace().data
print("Namespace:", namespace)
response = storage.get_object(
namespace, os.environ["OCI_BUCKET_NAME"], os.environ["OCI_OBJECT_NAME"]
)
Path("downloaded-object").write_bytes(response.data.content)
response.data.close()
print("Object downloaded to: downloaded-object")
# Retrieve and decode the secret.
secrets = oci.secrets.SecretsClient(config, signer=signer)
bundle = secrets.get_secret_bundle(os.environ["OCI_SECRET_OCID"]).data
secret_value = base64.b64decode(bundle.secret_bundle_content.content).decode("utf-8")
print("Secret value:", secret_value)
PY
python3 gcp_oci_access.py
Example output:
Namespace: <your-object-storage-namespace>
Object downloaded to: downloaded-object
Secret value: <your-test-secret-value>
The script retrieves the Object Storage namespace, downloads the selected object, and prints the decoded secret value. OCI authorizes these operations using the service user’s group membership and IAM policies.
When the session expires, obtain a fresh Google ID token and repeat the token exchange. Always use the private key corresponding to the public key submitted for that UPST.
Note: The manual steps above show how token exchange works. For application code, the OCI Python SDK’s
TokenExchangeSignersimplifies this flow by handling RSA key generation, token exchange, OCI session-token renewal, and API request signing.Provide the OCI domain URL, client ID, client secret, and a function that retrieves a fresh Google ID token from the metadata server. The signer can then obtain new OCI session credentials as needed, reducing the code your application needs to manage.
For details and an example, see the blog: Simplifying Token Exchange in OCI with the WIF Python Signer.
The same example using the Python WIF signer
Run this example on the GCP VM using the Python environment and environment variables set above: OCI_DOMAIN_URL, OCI_WIF_CLIENT_ID, OCI_WIF_CLIENT_SECRET, OCI_REGION, OCI_BUCKET_NAME, OCI_OBJECT_NAME, and OCI_SECRET_OCID.
The signer obtains and manages the UPST internally. Pass it directly to the OCI service clients.
cat > gcp_oci_wif_signer.py <<'PY'
import base64
import os
from pathlib import Path
from urllib.parse import urlencode
from urllib.request import Request, urlopen
import oci
def get_google_id_token():
"""Request a fresh Google ID token from the VM metadata server."""
query = urlencode({
"audience": os.environ["OCI_DOMAIN_URL"],
"format": "full"
})
request = Request(
"http://metadata.google.internal/computeMetadata/v1/"
f"instance/service-accounts/default/identity?{query}",
headers={"Metadata-Flavor": "Google"}
)
with urlopen(request, timeout=10) as response:
return response.read().decode("utf-8").strip()
# Pass the function so the signer can request a fresh token when needed.
signer = oci.auth.signers.TokenExchangeSigner(
get_google_id_token,
os.environ["OCI_DOMAIN_URL"],
os.environ["OCI_WIF_CLIENT_ID"],
os.environ["OCI_WIF_CLIENT_SECRET"]
)
config = {"region": os.environ["OCI_REGION"]}
# Download the test object.
storage = oci.object_storage.ObjectStorageClient(config, signer=signer)
namespace = storage.get_namespace().data
print("Namespace:", namespace)
response = storage.get_object(
namespace, os.environ["OCI_BUCKET_NAME"], os.environ["OCI_OBJECT_NAME"]
)
Path("downloaded-object").write_bytes(response.data.content)
response.data.close()
print("Object downloaded to: downloaded-object")
# Retrieve and decode the test secret.
secrets = oci.secrets.SecretsClient(config, signer=signer)
bundle = secrets.get_secret_bundle(os.environ["OCI_SECRET_OCID"]).data
secret_value = base64.b64decode(bundle.secret_bundle_content.content).decode("utf-8")
print("Secret value:", secret_value)
PY
python3 gcp_oci_wif_signer.py
Passing get_google_id_token as a function allows the signer to fetch a fresh Google token whenever it needs to obtain new OCI session credentials. This example uses the client-ID-and-secret authentication flow described above.
Using CIMD for client authentication
The first approach uses a registered OAuth client’s ID and secret. We can also use a Client ID Metadata Document (CIMD): a JSON document hosted at an HTTPS URL, where that URL becomes the client’s client_id.
This approach offers:
- One client identity across domains: Reuse the metadata URL instead of creating a separate persistent client registration in each identity domain.
- No shared client secret: Authenticate using a signed client assertion and a published public key.
- Centralized metadata and public keys: Host the client configuration and JWKS in one place.
Each OCI domain still needs to trust and authorize the client. A signing private key is still required. See OCI CIMD documentation for the domain configuration and the CIMD specification for the metadata model.
We will reuse the VM, service user, IAM policies, and UPST session key pair from the previous steps.
Before starting this section, ensure you have:
- A CIMD-enabled OCI IAM domain. Its authorization-server metadata must advertise
client_id_metadata_document_supported: true. - HTTPS locations where you can publish the client metadata and JWKS documents.
1. Generate the signing key and JWKS file
Prepare the client files using OpenSSL and Python with PyJWT and its cryptographic dependencies installed:
python3 -m pip install 'PyJWT[crypto]'
Generate a separate key for client authentication and a certificate for its public key:
openssl genrsa -out cimd_client_key.pem 2048
openssl req -new -x509 \
-key cimd_client_key.pem \
-out cimd_client_cert.pem \
-days 365 \
-subj '/CN=gcp-oci-cimd-client'
Run the following Python script to generate jwks.json from the public certificate:
python3 - <<'PY'
import base64
import json
from cryptography import x509
from cryptography.hazmat.primitives import serialization
from jwt.algorithms import RSAAlgorithm
with open("cimd_client_cert.pem", "rb") as f:
cert = x509.load_pem_x509_certificate(f.read())
key = RSAAlgorithm.to_jwk(cert.public_key(), as_dict=True)
key.update({
"kid": "gcp-oci-cimd-key-1",
"use": "sig",
"alg": "RS256",
"x5c": [base64.b64encode(
cert.public_bytes(serialization.Encoding.DER)
).decode("ascii")]
})
with open("jwks.json", "w") as f:
json.dump({"keys": [key]}, f, indent=2)
PY
The script generates the JSON Web Key Set (JWKS) file, jwks.json, from the public certificate. Its structure looks like this:
{
"keys": [
{
"kty": "RSA",
"kid": "gcp-oci-cimd-key-1",
"use": "sig",
"alg": "RS256",
"n": "<base64url-encoded-RSA-modulus>",
"e": "AQAB",
"x5c": [
"<base64-encoded-DER-certificate>"
]
}
]
}
Use the actual values written by the script when publishing jwks.json.
2. Publish the CIMD and JWKS
Publish the client metadata document at a stable HTTPS URL. Publish the client’s public keys through the JWKS endpoint referenced by jwks_uri in the metadata document. This follows Oracle’s CIMD hosting model.
For this example, the URLs are:
https://<your-host>/oauth/client-metadata.json— the client metadata document and OAuth client ID.https://<your-host>/oauth/jwks.json— the JWKS endpoint.
Create client-metadata.json with the following content, replacing the host URLs:
{
"client_id": "https://<your-host>/oauth/client-metadata.json",
"client_name": "GCP to OCI WIF Client",
"client_uri": "https://<your-host>",
"redirect_uris": [
"https://oauth.pstmn.io/v1/callback"
],
"grant_types": [
"authorization_code",
"refresh_token",
"client_credentials"
],
"response_types": [
"code"
],
"token_endpoint_auth_method": "private_key_jwt",
"jwks_uri": "https://<your-host>/oauth/jwks.json"
}
The metadata follows the confidential-client structure used for this example. The UPST exchange below does not use the redirect URI or an interactive sign-in.
Publish client-metadata.json and jwks.json at the HTTPS locations above. The CIMD’s client_id must exactly match its own URL, and jwks_uri must return the generated JWKS. Both URLs must return JSON directly over HTTPS, without authentication or redirects.
Check that both HTTPS URLs return the expected JSON:
curl -sS 'https://<your-host>/oauth/client-metadata.json'
curl -sS 'https://<your-host>/oauth/jwks.json'
The CIMD key authenticates the client. The earlier gcp_oci_session_key.pem signs OCI API requests after the exchange. Publish only the two JSON files.
3. Allow the CIMD in the OCI identity domain
Use a CIMD-enabled identity domain. Its /.well-known/oauth-authorization-server response should include "client_id_metadata_document_supported": true.
Using the same administrator access token as before, send this request through Postman:
PATCH https://<your-domain>.identity.oraclecloud.com/admin/v1/Settings/Settings
Authorization: Bearer <identity-domain-admin-access-token>
Content-Type: application/json
Body
{
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:PatchOp"
],
"Operations": [
{
"op": "add",
"path": "allowedCimdDomains",
"value": [
{
"domainUri": "https://<your-host>/oauth/client-metadata.json"
}
]
}
]
}
Use the full CIMD URL for domainUri.
4. Add the CIMD client to the existing trust
Use the id returned when you created the Identity Propagation Trust. Add the CIMD URL to its authorized OAuth clients:
PATCH https://<your-domain>.identity.oraclecloud.com/admin/v1/IdentityPropagationTrusts/<trust-id>
Authorization: Bearer <identity-domain-admin-access-token>
Content-Type: application/json
Body
{
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:PatchOp"
],
"Operations": [
{
"op": "add",
"path": "oauthClients",
"value": [
"https://<your-host>/oauth/client-metadata.json"
]
}
]
}
This adds the CIMD client while retaining the original client for the earlier test.
5. Return to the GCP VM and generate a client assertion
After publishing both documents, allowlisting the CIMD in the IAM domain, and adding the CIMD client ID to the trust, connect to the GCP VM using SSH-in-browser.
Place cimd_client_key.pem in ~/gcp-oci-wif on the VM. This is the private key corresponding to the public key published in the JWKS.
cd ~/gcp-oci-wif
source ~/oci-wif-venv/bin/activate
python3 -m pip install 'PyJWT[crypto]'
export OCI_DOMAIN_URL='https://<your-domain>.identity.oraclecloud.com'
export CIMD_CLIENT_ID='https://<your-host>/oauth/client-metadata.json'
export CIMD_KEY_ID='gcp-oci-cimd-key-1'
Load the session public key and obtain a fresh Google ID token:
export OCI_SESSION_PUBLIC_KEY="$(
sed '/^-----/d' gcp_oci_session_pub.pem | tr -d '\r\n'
)"
export GCP_ID_TOKEN="$(
curl -sS --get \
-H 'Metadata-Flavor: Google' \
--data-urlencode "audience=$OCI_DOMAIN_URL" \
--data-urlencode 'format=full' \
'http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity'
)"
Generate the client assertion next, immediately before submitting the exchange request. The assertion expires after five minutes; regenerate it if you pause before the exchange.
Generate a short-lived client assertion signed with cimd_client_key.pem:
export OCI_CLIENT_ASSERTION="$(
python3 - <<'PY'
import os
import time
import uuid
import jwt
now = int(time.time())
claims = {
"iss": os.environ["CIMD_CLIENT_ID"],
"sub": os.environ["CIMD_CLIENT_ID"],
"aud": ["https://identity.oraclecloud.com/"],
"iat": now,
"nbf": now,
"exp": now + 300,
"jti": str(uuid.uuid4())
}
with open("cimd_client_key.pem", "rb") as f:
private_key = f.read()
print(jwt.encode(
claims,
private_key,
algorithm="RS256",
headers={"kid": os.environ["CIMD_KEY_ID"]}
))
PY
)"
echo "$OCI_CLIENT_ASSERTION"
Inspect the assertion: iss and sub contain the CIMD URL, aud is https://identity.oraclecloud.com/, and exp is five minutes after iat. The header’s kid matches the key in the hosted JWKS.

Use https://identity.oraclecloud.com/ for the client assertion audience, including the trailing slash.
6. Exchange the Google token using the client assertion
Run this request immediately after generating the client assertion. If either the Google ID token or assertion has expired, regenerate it before retrying.
Call the token endpoint using the CIMD client ID and assertion:
curl -sS --request POST "$OCI_DOMAIN_URL/oauth2/v1/token" \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode "client_id=$CIMD_CLIENT_ID" \
--data-urlencode 'client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer' \
--data-urlencode "client_assertion=$OCI_CLIENT_ASSERTION" \
--data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \
--data-urlencode 'requested_token_type=urn:oci:token-type:oci-upst' \
--data-urlencode 'subject_token_type=jwt' \
--data-urlencode "subject_token=$GCP_ID_TOKEN" \
--data-urlencode "public_key=$OCI_SESSION_PUBLIC_KEY" \
--output oci-upst-response.json
cat oci-upst-response.json
This request uses the signed assertion for client authentication, so it has no HTTP Basic authentication or client secret. OCI verifies the assertion using the published JWKS and validates the Google token using the existing trust.
Inspect the returned token. Before rerunning the API example, export the target-resource variables again. These are needed if you reconnected to the VM:
export OCI_REGION='us-ashburn-1'
export OCI_BUCKET_NAME='<existing-bucket-name>'
export OCI_OBJECT_NAME='<existing-object-name>'
export OCI_SECRET_OCID='<secret-ocid>'
python3 gcp_oci_access.py
The application now obtains a UPST through CIMD-based client authentication and uses the same session key to call OCI APIs.
References
- Google Cloud: Verify VM identity
- Google Cloud: Change the attached service account
- Google: OpenID configuration
- OCI: Exchanging a JSON Web Token for a UPST
- OCI: Adding a Confidential Application
- OCI: Common IAM policies
- OCI Python SDK: Signing
- OCI: Client ID Metadata Documents
- A Zero-Downtime Approach to JWT Client Assertion Certificate Rotation in OCI IAM Domain
