Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(pam): align gcp service account validation with app connections

Andreycf4177187b40
diff --git a/backend/src/ee/services/pam-account/pam-account-connection-test.ts b/backend/src/ee/services/pam-account/pam-account-connection-test.ts
index 3de9bc4770..12aeb850ec 100644
--- a/backend/src/ee/services/pam-account/pam-account-connection-test.ts
+++ b/backend/src/ee/services/pam-account/pam-account-connection-test.ts
@@ -469,12 +469,13 @@ export const CLOUD_CONNECTION_VALIDATORS: Partial<Record<PamAccountType, CloudCo
scope: AZURE_SCOPES.arm
});
},
- [PamAccountType.GcpServiceAccount]: async ({ connectionDetails, credentials }) => {
+ [PamAccountType.GcpServiceAccount]: async ({ connectionDetails, credentials, orgId }) => {
if (!credentials) return;
await mintGcpAccessToken({
serviceAccountEmail: connectionDetails.serviceAccountEmail as string,
authMethod: credentials.authMethod as string,
- serviceAccountKeyJson: credentials.serviceAccountKeyJson as string | undefined
+ serviceAccountKeyJson: credentials.serviceAccountKeyJson as string | undefined,
+ orgId
});
}
};
diff --git a/backend/src/ee/services/pam-session/gcp/gcp-federation.ts b/backend/src/ee/services/pam-session/gcp/gcp-federation.ts
index f2dfdff51b..9fba854283 100644
--- a/backend/src/ee/services/pam-session/gcp/gcp-federation.ts
+++ b/backend/src/ee/services/pam-session/gcp/gcp-federation.ts
@@ -23,11 +23,13 @@ export const mintGcpAccessToken = async ({
serviceAccountEmail,
authMethod,
serviceAccountKeyJson,
+ orgId,
ttlSeconds = 3600
}: {
serviceAccountEmail: string;
authMethod: string;
serviceAccountKeyJson?: string;
+ orgId: string;
ttlSeconds?: number;
}): Promise<string> => {
let tokenResponse;
@@ -54,6 +56,12 @@ export const mintGcpAccessToken = async ({
throw tokenError(serviceAccountEmail, err);
}
} else {
+ const expectedAccountIdSuffix = orgId.split("-").slice(0, 2).join("-");
+ if (!serviceAccountEmail.split("@")[0].endsWith(expectedAccountIdSuffix)) {
+ throw new BadRequestError({
+ message: `GCP service account '${serviceAccountEmail}' can't be impersonated because its ID doesn't end with "${expectedAccountIdSuffix}", e.g. service-account-${expectedAccountIdSuffix}@my-project.iam.gserviceaccount.com`
+ });
+ }
const appCfg = getConfig();
if (!appCfg.INF_APP_CONNECTION_GCP_SERVICE_ACCOUNT_CREDENTIAL) {
throw new InternalServerError({
diff --git a/backend/src/ee/services/pam-session/pam-session-service.ts b/backend/src/ee/services/pam-session/pam-session-service.ts
index 66d995a0f7..03d9e8ff06 100644
--- a/backend/src/ee/services/pam-session/pam-session-service.ts
+++ b/backend/src/ee/services/pam-session/pam-session-service.ts
@@ -264,6 +264,7 @@ export const pamSessionServiceFactory = ({
serviceAccountEmail: connectionDetails.serviceAccountEmail as string,
authMethod: credentials.authMethod as string,
serviceAccountKeyJson: credentials.serviceAccountKeyJson as string | undefined,
+ orgId,
ttlSeconds: Math.min(remainingSeconds, 3600)
});
delete credentials.serviceAccountKeyJson;