Learn how to authenticate with Infisical for services on Google Cloud Platform
GCP Auth is a GCP-native authentication method for GCP resources to access Infisical. It consists of two sub-methods/approaches:
The following sequence digram illustrates the GCP ID Token Auth workflow for authenticating GCP resources with Infisical.
At a high-level, Infisical authenticates a GCP resource by verifying its identity and checking that it meets specific requirements (e.g. it is an allowed GCE instance) at the /api/v1/auth/gcp-auth/login
endpoint. If successful,
then Infisical returns a short-lived access token that can be used to make authenticated requests to the Infisical API.
To be more specific:
/api/v1/auth/gcp-auth/login
endpoint.We recommend using one of Infisical’s clients like SDKs or the Infisical Agent to authenticate with Infisical using GCP ID Token Auth as they handle the authentication process including generating the instance ID token for you.
Also, note that Infisical needs network-level access to send requests to the Google Cloud API as part of the GCP Auth workflow.
In the following steps, we explore how to create and use identities for your workloads and applications on GCP to access the Infisical API using the GCP ID Token authentication method.
Creating an identity
To create an identity, head to your Organization Settings > Access Control > Machine Identities and press Create identity.
When creating an identity, you specify an organization level role for it to assume; you can configure roles in Organization Settings > Access Control > Organization Roles.
Now input a few details for your new identity. Here’s some guidance for each field:
Once you’ve created an identity, you’ll be prompted to configure the authentication method for it. Here, select GCP Auth and set the Type to GCP ID Token Auth.
Here’s some more guidance on each field:
test@project.iam.gserviceaccount.com
, 12345-compute@developer.gserviceaccount.com
, etc.<region>-<zone>
like us-central1-a
, us-west1-b
, etc. Note that this validation property will only work for GCE instances.2592000
equivalent to 30 days): The lifetime for an acccess token in seconds. This value will be referenced at renewal time.2592000
equivalent to 30 days): The maximum lifetime for an acccess token in seconds. This value will be referenced at renewal time.0
): The maximum number of times that an access token can be used; a value of 0
implies infinite number of uses.0.0.0.0/0
, allowing usage from any network address.Adding an identity to a project
To enable the identity to access project-level resources such as secrets within a specific project, you should add it to that project.
To do this, head over to the project you want to add the identity to and go to Project Settings > Access Control > Machine Identities and press Add identity.
Next, select the identity you want to add to the project and the project level role you want to allow it to assume. The project role assigned will determine what project level resources this identity can have access to.
Accessing the Infisical API with the identity
To access the Infisical API as the identity, you need to generate an ID token constituting the identity of the present GCE instance and make a request to the /api/v1/auth/gcp-auth/login
endpoint containing the token in exchange for an access token.
We provide a few code examples below of how you can authenticate with Infisical to access the Infisical API.
Sample code for generating the ID token
Start by making a request from the GCE instance to obtain the ID token. For more examples of how to obtain the token in Java, Go, Node.js, etc. refer to the official documentation.
Note that you should replace <identityId>
with the ID of the identity you created in step 1.
Next use send the obtained JWT token along to authenticate with Infisical and obtain an access token.
Next, you can use the access token to access the Infisical API
We recommend using one of Infisical’s clients like SDKs or the Infisical Agent to authenticate with Infisical using GCP IAM Auth as they handle the authentication process including generating the signed JWT token.
Each identity access token has a time-to-live (TLL) which you can infer from the response of the login operation;
the default TTL is 7200
seconds which can be adjusted.
If an identity access token expires, it can no longer authenticate with the Infisical API. In this case,
a new access token should be obtained by performing another login operation.
The following sequence digram illustrates the GCP ID Token Auth workflow for authenticating GCP resources with Infisical.
At a high-level, Infisical authenticates a GCP resource by verifying its identity and checking that it meets specific requirements (e.g. it is an allowed GCE instance) at the /api/v1/auth/gcp-auth/login
endpoint. If successful,
then Infisical returns a short-lived access token that can be used to make authenticated requests to the Infisical API.
To be more specific:
/api/v1/auth/gcp-auth/login
endpoint.We recommend using one of Infisical’s clients like SDKs or the Infisical Agent to authenticate with Infisical using GCP ID Token Auth as they handle the authentication process including generating the instance ID token for you.
Also, note that Infisical needs network-level access to send requests to the Google Cloud API as part of the GCP Auth workflow.
In the following steps, we explore how to create and use identities for your workloads and applications on GCP to access the Infisical API using the GCP ID Token authentication method.
Creating an identity
To create an identity, head to your Organization Settings > Access Control > Machine Identities and press Create identity.
When creating an identity, you specify an organization level role for it to assume; you can configure roles in Organization Settings > Access Control > Organization Roles.
Now input a few details for your new identity. Here’s some guidance for each field:
Once you’ve created an identity, you’ll be prompted to configure the authentication method for it. Here, select GCP Auth and set the Type to GCP ID Token Auth.
Here’s some more guidance on each field:
test@project.iam.gserviceaccount.com
, 12345-compute@developer.gserviceaccount.com
, etc.<region>-<zone>
like us-central1-a
, us-west1-b
, etc. Note that this validation property will only work for GCE instances.2592000
equivalent to 30 days): The lifetime for an acccess token in seconds. This value will be referenced at renewal time.2592000
equivalent to 30 days): The maximum lifetime for an acccess token in seconds. This value will be referenced at renewal time.0
): The maximum number of times that an access token can be used; a value of 0
implies infinite number of uses.0.0.0.0/0
, allowing usage from any network address.Adding an identity to a project
To enable the identity to access project-level resources such as secrets within a specific project, you should add it to that project.
To do this, head over to the project you want to add the identity to and go to Project Settings > Access Control > Machine Identities and press Add identity.
Next, select the identity you want to add to the project and the project level role you want to allow it to assume. The project role assigned will determine what project level resources this identity can have access to.
Accessing the Infisical API with the identity
To access the Infisical API as the identity, you need to generate an ID token constituting the identity of the present GCE instance and make a request to the /api/v1/auth/gcp-auth/login
endpoint containing the token in exchange for an access token.
We provide a few code examples below of how you can authenticate with Infisical to access the Infisical API.
Sample code for generating the ID token
Start by making a request from the GCE instance to obtain the ID token. For more examples of how to obtain the token in Java, Go, Node.js, etc. refer to the official documentation.
Note that you should replace <identityId>
with the ID of the identity you created in step 1.
Next use send the obtained JWT token along to authenticate with Infisical and obtain an access token.
Next, you can use the access token to access the Infisical API
We recommend using one of Infisical’s clients like SDKs or the Infisical Agent to authenticate with Infisical using GCP IAM Auth as they handle the authentication process including generating the signed JWT token.
Each identity access token has a time-to-live (TLL) which you can infer from the response of the login operation;
the default TTL is 7200
seconds which can be adjusted.
If an identity access token expires, it can no longer authenticate with the Infisical API. In this case,
a new access token should be obtained by performing another login operation.
The following sequence digram illustrates the GCP IAM Auth workflow for authenticating GCP IAM service accounts with Infisical.
At a high-level, Infisical authenticates an IAM service account by verifying its identity and checking that it meets specific requirements (e.g. it is an allowed service account) at the /api/v1/auth/gcp-auth/login
endpoint. If successful,
then Infisical returns a short-lived access token that can be used to make authenticated requests to the Infisical API.
To be more specific:
projects.serviceAccounts.signJwt
API method; this is done using the service account credentials associated with the client./api/v1/auth/gcp-auth/login
endpoint.We recommend using one of Infisical’s clients like SDKs or the Infisical Agent to authenticate with Infisical using GCP IAM Auth as they handle the authentication process including generating the signed JWT token.
Also, note that Infisical needs network-level access to send requests to the Google Cloud API as part of the GCP Auth workflow.
In the following steps, we explore how to create and use identities for your workloads and applications on GCP to access the Infisical API using the GCP IAM authentication method.
Creating an identity
To create an identity, head to your Organization Settings > Access Control > Machine Identities and press Create identity.
When creating an identity, you specify an organization level role for it to assume; you can configure roles in Organization Settings > Access Control > Organization Roles.
Now input a few details for your new identity. Here’s some guidance for each field:
Once you’ve created an identity, you’ll be prompted to configure the authentication method for it. Here, select GCP IAM Auth and set the Type to GCP IAM Auth.
Here’s some more guidance on each field:
test@project.iam.gserviceaccount.com
, 12345-compute@developer.gserviceaccount.com
, etc.2592000
equivalent to 30 days): The lifetime for an acccess token in seconds. This value will be referenced at renewal time.2592000
equivalent to 30 days): The maximum lifetime for an acccess token in seconds. This value will be referenced at renewal time.0
): The maximum number of times that an access token can be used; a value of 0
implies infinite number of uses.0.0.0.0/0
, allowing usage from any network address.Adding an identity to a project
To enable the identity to access project-level resources such as secrets within a specific project, you should add it to that project.
To do this, head over to the project you want to add the identity to and go to Project Settings > Access Control > Machine Identities and press Add identity.
Next, select the identity you want to add to the project and the project level role you want to allow it to assume. The project role assigned will determine what project level resources this identity can have access to.
Accessing the Infisical API with the identity
To access the Infisical API as the identity, you need to generate a signed JWT token using the projects.serviceAccounts.signJwt
API method and make a request to the /api/v1/auth/gcp-auth/login
endpoint containing the signed JWT token in exchange for an access token.
Make sure that the service account has the iam.serviceAccounts.signJwt
permission or the roles/iam.serviceAccountTokenCreator
role.
We provide a few code examples below of how you can authenticate with Infisical to access the Infisical API.
Sample code for generating a signed JWT token
The following code provides a generic example of how you can generate a signed JWT token against the projects.serviceAccounts.signJwt
API method.
The shown example uses Node.js and the official google-auth-library package but you can use any language you wish.
Next, you can use the access token to access the Infisical API
We recommend using one of Infisical’s clients like SDKs or the Infisical Agent to authenticate with Infisical using GCP IAM Auth as they handle the authentication process including generating the signed JWT token.
Each identity access token has a time-to-live (TLL) which you can infer from the response of the login operation;
the default TTL is 7200
seconds which can be adjusted.
If an identity access token expires, it can no longer authenticate with the Infisical API. In this case,
a new access token should be obtained by performing another login operation.