From 533d49304a40cf872247f7c3353721a4f5b03f01 Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Thu, 9 May 2024 15:35:50 -0700 Subject: [PATCH] Update GCP documentation --- .../platform/identities/aws-auth.mdx | 2 +- .../platform/identities/gcp-auth.mdx | 360 +++++++++--------- .../platform/identities/universal-auth.mdx | 2 +- 3 files changed, 181 insertions(+), 183 deletions(-) diff --git a/docs/documentation/platform/identities/aws-auth.mdx b/docs/documentation/platform/identities/aws-auth.mdx index cf76ffce7..09fdb8865 100644 --- a/docs/documentation/platform/identities/aws-auth.mdx +++ b/docs/documentation/platform/identities/aws-auth.mdx @@ -37,7 +37,7 @@ At a high-level, Infisical authenticates an IAM principal by verifying its ident then Infisical returns a short-lived access token that can be used to make authenticated requests to the Infisical API. In AWS Auth, an IAM principal signs a `GetCallerIdentity` query using the [AWS Signature v4 algorithm](https://docs.aws.amazon.com/IAM/latest/UserGuide/create-signed-request.html); this is done using the credentials from the AWS environment where the IAM principal is running. -The query data including the request method, request body, and request headers are sent to Infisical afterwhich Infisical forwards the signed query to AWS STS API via the [sts:GetCallerIdentity](https://docs.aws.amazon.com/STS/latest/APIReference/API_GetCallerIdentity.html) method to verify and obtain the identity of the IAM principal. +The query data including the request method, request body, and request headers are sent to Infisical after which Infisical forwards the signed query to AWS STS API via the [sts:GetCallerIdentity](https://docs.aws.amazon.com/STS/latest/APIReference/API_GetCallerIdentity.html) method to verify and obtain the identity of the IAM principal. Once obtained, the identity information is verified against specified requirements such as if the associated IAM principal ARN is allowed to authenticate with Infisical. If all is well, Infisical returns a short-lived access token that can be used to make authenticated requests to the Infisical API. diff --git a/docs/documentation/platform/identities/gcp-auth.mdx b/docs/documentation/platform/identities/gcp-auth.mdx index 401471e4b..012dfdaa3 100644 --- a/docs/documentation/platform/identities/gcp-auth.mdx +++ b/docs/documentation/platform/identities/gcp-auth.mdx @@ -5,10 +5,187 @@ description: "Learn how to authenticate with Infisical for GCE instances and oth **GCP Auth** is a GCP-native authentication method for GCP resources to access Infisical. -- GCP GCE Auth: For Google Compute Engine (GCE) instances to authenticate with Infisical. - GCP IAM Auth: For Google Cloud Platform (GCP) service accounts to authenticate with Infisical. +- GCP GCE Auth: For Google Compute Engine (GCE) instances to authenticate with Infisical. + + + ## Diagram + + The following sequence digram illustrates the GCP IAM Auth workflow for authenticating GCP IAM service accounts with Infisical. + +```mermaid +sequenceDiagram + participant GCE as Client + participant Infis as Infisical + participant Google as Cloud IAM + + Note over GCE,Google: Step 1: Signed JWT Token Generation + GCE->>Google: Request to generate signed JWT token + Google-->>GCE: Return signed JWT token + + Note over GCE,Infis: Step 2: JWT Token Login Operation + GCE->>Infis: Send signed JWT token to /api/v1/auth/gcp-auth/login + Infis->>Google: Request public key + Google-->>Infis: Return public key + + Note over Infis: Step 3: JWT Token Verification + Note over Infis: Step 4: JWT Property Validation + Infis->>GCE: Return short-lived access token + + Note over GCE,Infis: Step 4: Access Infisical API with Token + GCE->>Infis: Make authenticated requests using the short-lived access token +``` + +## Concept + +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. + +In GCP IAM Auth, the client generates a signed JWT using the `projects.serviceAccounts.signJwt` [API method](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signJwt); this is done using the service account credentials from the GCP environment where the client is running. +The signed JWT is sent to Infisical after which Infisical verifies the JWT and checks if the associated service account is allowed to authenticate with Infisical. If all is well, Infisical returns a short-lived access token that can be used to make authenticated requests to 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. + +Also, note that Infisical needs network-level access to send requests to the Google Cloud API +as part of the GCP Auth workflow. + + + +## 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. + + + + To create an identity, head to your Organization Settings > Access Control > Machine Identities and press **Create identity**. + + ![identities organization](/images/platform/identities/identities-org.png) + + When creating an identity, you specify an organization level [role](/documentation/platform/role-based-access-controls) for it to assume; you can configure roles in Organization Settings > Access Control > Organization Roles. + + ![identities organization create](/images/platform/identities/identities-org-create.png) + + Now input a few details for your new identity. Here's some guidance for each field: + + - Name (required): A friendly name for the identity. + - Role (required): A role from the **Organization Roles** tab for the identity to assume. The organization role assigned will determine what organization level resources this identity can have access to. + + 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**. + + ![identities create gcp auth method](/images/platform/identities/identities-org-create-gcp-iam-auth-method.png) + + Here's some more guidance on each field: + + - Service Account JSON: The JSON key file for the GCP service account that will be used by Infisical to look-up other service account details; this service account should have the `iam.serviceAccounts.get` permission that can be found on the `roles/iam.serviceAccountKeyAdmin` role. + - Allowed Service Account Emails: A comma-separated list of trusted IAM service account emails that are allowed to authenticate with Infisical; this could be something like `test@project.iam.gserviceaccount.com`, `12345-compute@developer.gserviceaccount.com`, etc. + - Allowed Projects: A comma-separated list of trusted GCP projects that the IAM service accounts must belong to authenticate with Infisical. + - Access Token TTL (default is `2592000` equivalent to 30 days): The lifetime for an acccess token in seconds. This value will be referenced at renewal time. + - Access Token Max TTL (default is `2592000` equivalent to 30 days): The maximum lifetime for an acccess token in seconds. This value will be referenced at renewal time. + - Access Token Max Number of Uses (default is `0`): The maximum number of times that an access token can be used; a value of `0` implies infinite number of uses. + - Access Token Trusted IPs: The IPs or CIDR ranges that access tokens can be used from. By default, each token is given the `0.0.0.0/0`, allowing usage from any network address. + + + Note that you should enable the [IAM Service Account Credentials API](https://console.developers.google.com/apis/api/iamcredentials.googleapis.com/overview) + in your 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. + + ![identities project](/images/platform/identities/identities-project.png) + + ![identities project create](/images/platform/identities/identities-project-create.png) + + + To access the Infisical API as the identity, you need to generate a signed JWT token using the `projects.serviceAccounts.signJwt` [API method](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signJwt) 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](/api-reference/overview/introduction). + + + + 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](https://github.com/googleapis/google-auth-library-nodejs#readme) package but you can use any language you wish. + + + ```javascript + const { GoogleAuth } = require("google-auth-library"); + + const auth = new GoogleAuth({ + scopes: "https://www.googleapis.com/auth/cloud-platform", + }); + + const credentials = await auth.getCredentials(); + + const identityId = ""; + + const jwtPayload = { + sub: credentials.client_email, + aud: identityId, + }; + + const { data } = await client.request({ + url: `https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${credentials.client_email}:signJwt`, + method: "POST", + data: { payload: JSON.stringify(jwtPayload) }, + }); + + const jwt = data.signedJwt // send this jwt to Infisical in the next step + ``` + + #### Sample request + + ```bash Request + curl --location --request POST 'https://app.infisical.com/api/v1/auth/gcp-auth/login' \ + --header 'Content-Type: application/x-www-form-urlencoded' \ + --data-urlencode 'identityId=...' \ + --data-urlencode 'jwt=...' + ``` + + #### Sample response + + ```bash Response + { + "accessToken": "...", + "expiresIn": 7200, + "accessTokenMaxTTL": 43244 + "tokenType": "Bearer" + } + ``` + + Next, you can use the access token to access the [Infisical API](/api-reference/overview/introduction) + + + + + 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. + + + + + ## Diagram @@ -44,7 +221,7 @@ At a high-level, Infisical authenticates a GCE instance by verifying its identit then Infisical returns a short-lived access token that can be used to make authenticated requests to the Infisical API. In GCP GCE Auth, the client obtains an [instance identity metadata token](https://cloud.google.com/compute/docs/instances/verifying-instance-identity) constituting the identity for a GCE instance; this is a unique JWT token that includes details about the instance as well as Google's [RS256 signature](https://datatracker.ietf.org/doc/html/rfc7518#section-3.3). -The token is sent to Infisical afterwhich Infisical verifies the token against Google's [public OAuth2 certificates](https://www.googleapis.com/oauth2/v3/certs) and checks if the associated instance is allowed to authenticate with Infisical. If all is well, Infisical returns a short-lived access token that can be used to make authenticated requests to the Infisical API. +The token is sent to Infisical after which Infisical verifies the token against Google's [public OAuth2 certificates](https://www.googleapis.com/oauth2/v3/certs) and checks if the associated instance is allowed to authenticate with Infisical. If all is well, Infisical returns a short-lived access token that can be used to make authenticated requests to the Infisical API. We recommend using one of Infisical's clients like SDKs or the Infisical Agent @@ -164,184 +341,5 @@ access the Infisical API using the GCP GCE authentication method. - - ## Diagram - - The following sequence digram illustrates the GCP IAM Auth workflow for authenticating GCP IAM service accounts with Infisical. - -```mermaid -sequenceDiagram - participant GCE as Client - participant Infis as Infisical - participant Google as Cloud IAM - - Note over GCE,Google: Step 1: Signed JWT Token Generation - GCE->>Google: Request to generate signed JWT token - Google-->>GCE: Return signed JWT token - - Note over GCE,Infis: Step 2: JWT Token Login Operation - GCE->>Infis: Send signed JWT token to /api/v1/auth/gcp-auth/login - Infis->>Google: Request public key - Google-->>Infis: Return public key - - Note over Infis: Step 3: JWT Token Verification - Note over Infis: Step 4: JWT Property Validation - Infis->>GCE: Return short-lived access token - - Note over GCE,Infis: Step 4: Access Infisical API with Token - GCE->>Infis: Make authenticated requests using the short-lived access token -``` - -## Concept - -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. - -In GCP IAM Auth, the client generates a signed JWT using the `projects.serviceAccounts.signJwt` [API method](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signJwt); this is done using the service account credentials from the GCP environment where the client is running. -The signed JWT is sent to Infisical afterwhich Infisical verifies the JWT and checks if the associated service account is allowed to authenticate with Infisical. If all is well, Infisical returns a short-lived access token that can be used to make authenticated requests to 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. - -Also, note that Infisical needs network-level access to send requests to the Google Cloud API -as part of the GCP Auth workflow. - - - -## 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. - - - - To create an identity, head to your Organization Settings > Access Control > Machine Identities and press **Create identity**. - - ![identities organization](/images/platform/identities/identities-org.png) - - When creating an identity, you specify an organization level [role](/documentation/platform/role-based-access-controls) for it to assume; you can configure roles in Organization Settings > Access Control > Organization Roles. - - ![identities organization create](/images/platform/identities/identities-org-create.png) - - Now input a few details for your new identity. Here's some guidance for each field: - - - Name (required): A friendly name for the identity. - - Role (required): A role from the **Organization Roles** tab for the identity to assume. The organization role assigned will determine what organization level resources this identity can have access to. - - 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**. - - ![identities create gcp auth method](/images/platform/identities/identities-org-create-gcp-iam-auth-method.png) - - Here's some more guidance on each field: - - - Service Account JSON: The JSON key file for the GCP service account that will be used by Infisical to look-up authenticated service account details. - - Allowed Service Account Emails: A comma-separated list of trusted IAM service account emails that are allowed to authenticate with Infisical; this could be something like `test@project.iam.gserviceaccount.com`, `12345-compute@developer.gserviceaccount.com`, etc. - - Allowed Projects: A comma-separated list of trusted GCP projects that the IAM service accounts must belong to authenticate with Infisical. - - Access Token TTL (default is `2592000` equivalent to 30 days): The lifetime for an acccess token in seconds. This value will be referenced at renewal time. - - Access Token Max TTL (default is `2592000` equivalent to 30 days): The maximum lifetime for an acccess token in seconds. This value will be referenced at renewal time. - - Access Token Max Number of Uses (default is `0`): The maximum number of times that an access token can be used; a value of `0` implies infinite number of uses. - - Access Token Trusted IPs: The IPs or CIDR ranges that access tokens can be used from. By default, each token is given the `0.0.0.0/0`, allowing usage from any network address. - - - Note that you should enable the [IAM Service Account Credentials API](https://console.developers.google.com/apis/api/iamcredentials.googleapis.com/overview) - in your 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. - - ![identities project](/images/platform/identities/identities-project.png) - - ![identities project create](/images/platform/identities/identities-project-create.png) - - - To access the Infisical API as the identity, you need to generate a signed JWT token using the `projects.serviceAccounts.signJwt` [API method](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signJwt) and make a request to the `/api/v1/auth/gcp-auth/login` endpoint containing the signed JWT 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](/api-reference/overview/introduction). - - - - 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](https://github.com/googleapis/google-auth-library-nodejs#readme) package but you can use any language you wish. - - - The example assumes that you have created a GCP service account and have downloaded the JSON key file for it. - - Make sure that the service account has the `iam.serviceAccounts.signJwt` permission; this is available on the `roles/iam.serviceAccountTokenCreator` role. - - - ```javascript - const { GoogleAuth } = require("google-auth-library"); - - const auth = new GoogleAuth({ - keyFile: serviceAccountKeyFile, // path to the service account JSON key file - scopes: "https://www.googleapis.com/auth/cloud-platform", - }); - - const client = await auth.getClient(); - const projectId = await auth.getProjectId(); - - const identityId = ""; - - const jwtPayload = { - sub: client.email, - aud: identityId, - }; - - const { data } = await client.request({ - url: `https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${client.email}:signJwt`, - method: "POST", - data: { payload: JSON.stringify(jwtPayload) }, - }); - - const jwt = data.signedJwt // send this jwt to Infisical in the next step - ``` - - #### Sample request - - ```bash Request - curl --location --request POST 'https://app.infisical.com/api/v1/auth/gcp-auth/login' \ - --header 'Content-Type: application/x-www-form-urlencoded' \ - --data-urlencode 'identityId=...' \ - --data-urlencode 'jwt=...' - ``` - - #### Sample response - - ```bash Response - { - "accessToken": "...", - "expiresIn": 7200, - "accessTokenMaxTTL": 43244 - "tokenType": "Bearer" - } - ``` - - Next, you can use the access token to access the [Infisical API](/api-reference/overview/introduction) - - - - - 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. - - - - - diff --git a/docs/documentation/platform/identities/universal-auth.mdx b/docs/documentation/platform/identities/universal-auth.mdx index bad96c0e3..2517e53b9 100644 --- a/docs/documentation/platform/identities/universal-auth.mdx +++ b/docs/documentation/platform/identities/universal-auth.mdx @@ -148,7 +148,7 @@ using the Universal Auth authentication method. - The client secret/access token is being used from an untrusted IP. - A identity access token can have a time-to-live (TTL) or incremental lifetime afterwhich it expires. + A identity access token can have a time-to-live (TTL) or incremental lifetime after which it expires. In certain cases, you may want to extend the lifespan of an access token; to do so, you must set a max TTL parameter.