Skip to content

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

feat(pam): add GCP IAM service account access type

bernie-g2403b458b98c
diff --git a/backend/src/ee/services/pam-account/pam-account-schemas.ts b/backend/src/ee/services/pam-account/pam-account-schemas.ts
index a5645e4735..76c2bc0b22 100644
--- a/backend/src/ee/services/pam-account/pam-account-schemas.ts
+++ b/backend/src/ee/services/pam-account/pam-account-schemas.ts
@@ -386,6 +386,42 @@ export const ACCOUNT_TYPE_CONFIGS = {
}
},
+ [PamAccountType.GcpIam]: {
+ name: "Google Cloud IAM",
+ icon: "Google Cloud Platform.png",
+ connectionDetails: z.object({
+ serviceAccountEmail: z.string().trim().min(1).max(255)
+ }),
+ credentials: z.discriminatedUnion("authMethod", [
+ z.object({
+ authMethod: z.literal("impersonation")
+ }),
+ z.object({
+ authMethod: z.literal("static-key"),
+ serviceAccountKeyJson: z.string().trim().min(1)
+ })
+ ]),
+ sanitizedCredentials: z.object({
+ authMethod: z.string()
+ }),
+ ui: {
+ serviceAccountEmail: { label: "Service Account Email" },
+ authMethod: {
+ label: "Auth Method",
+ defaultValue: "impersonation",
+ options: [
+ { label: "Impersonation (Recommended)", value: "impersonation" },
+ { label: "Static Key", value: "static-key" }
+ ]
+ },
+ serviceAccountKeyJson: {
+ label: "Service Account Key JSON",
+ widget: PamFieldWidget.Textarea,
+ secret: true
+ }
+ }
+ },
+
[PamAccountType.Windows]: {
name: "Windows",
icon: "Windows.png",
@@ -553,6 +589,8 @@ export const extractGatewayTarget = async (
host: (validated as { hosts: string[]; rdpPort: number }).hosts[0],
port: (validated as { hosts: string[]; rdpPort: number }).rdpPort
};
+ case PamAccountType.GcpIam:
+ return { host: "googleapis.com", port: 443 };
default:
throw new Error(`No gateway target extraction defined for account type '${accountType}'`);
}
diff --git a/backend/src/ee/services/pam-project/pam-project-bootstrap.ts b/backend/src/ee/services/pam-project/pam-project-bootstrap.ts
index c41cf06294..f649002e14 100644
--- a/backend/src/ee/services/pam-project/pam-project-bootstrap.ts
+++ b/backend/src/ee/services/pam-project/pam-project-bootstrap.ts
@@ -149,6 +149,14 @@ export const DEFAULT_ACCOUNT_TEMPLATES: TDefaultTemplate[] = [
recordingStorageBackend: PamRecordingStorageBackend.Postgres
}
},
+ {
+ name: "gcp-iam",
+ type: PamAccountType.GcpIam,
+ settings: {
+ recordingEnabled: true,
+ recordingStorageBackend: PamRecordingStorageBackend.Postgres
+ }
+ },
{
name: "windows",
type: PamAccountType.Windows,
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 3437e5f47b..c2df57a57b 100644
--- a/backend/src/ee/services/pam-session/pam-session-service.ts
+++ b/backend/src/ee/services/pam-session/pam-session-service.ts
@@ -1,3 +1,4 @@
+import { Impersonated, JWT } from "google-auth-library";
import net from "net";
import { TGatewayPoolServiceFactory } from "@app/ee/services/gateway-pool/gateway-pool-service";
@@ -6,11 +7,13 @@ import { TPermissionServiceFactory } from "@app/ee/services/permission/permissio
import { createSshCert, createSshKeyPair } from "@app/ee/services/ssh/ssh-certificate-authority-fns";
import { SshCertType } from "@app/ee/services/ssh/ssh-certificate-authority-types";
import { SshCertKeyAlgorithm } from "@app/ee/services/ssh-certificate/ssh-certificate-types";
-import { BadRequestError, NotFoundError } from "@app/lib/errors";
+import { getConfig } from "@app/lib/config/env";
+import { BadRequestError, InternalServerError, NotFoundError } from "@app/lib/errors";
import { GatewayProxyProtocol } from "@app/lib/gateway/types";
import { createGatewayConnection, createRelayConnection } from "@app/lib/gateway-v2/gateway-v2";
import { logger } from "@app/lib/logger";
import { ms } from "@app/lib/ms";
+import { buildGcpSourceCredential } from "@app/services/app-connection/gcp/gcp-connection-fns";
import { ActorType } from "@app/services/auth/auth-type";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { KmsDataKey } from "@app/services/kms/kms-types";
@@ -208,6 +211,65 @@ export const pamSessionServiceFactory = ({
}
}
+ if (account.accountType === PamAccountType.GcpIam) {
+ const serviceAccountEmail = connectionDetails.serviceAccountEmail as string;
+ const remainingSeconds = Math.floor((new Date(session.expiresAt).getTime() - Date.now()) / 1000);
+ if (remainingSeconds < 60) {
+ throw new BadRequestError({
+ message: `GCP IAM session has insufficient time remaining (${remainingSeconds}s) to generate an access token`
+ });
+ }
+ const sessionTtlSeconds = Math.min(remainingSeconds, 3600);
+
+ let sourceClient;
+ if (credentials.authMethod === "static-key") {
+ const keyJson = JSON.parse(credentials.serviceAccountKeyJson as string) as {
+ client_email?: string;
+ private_key?: string;
+ };
+ sourceClient = new JWT({
+ email: keyJson.client_email,
+ key: keyJson.private_key,
+ scopes: ["https://www.googleapis.com/auth/cloud-platform"]
+ });
+ } else {
+ const appCfg = getConfig();
+ if (!appCfg.INF_APP_CONNECTION_GCP_SERVICE_ACCOUNT_CREDENTIAL) {
+ throw new InternalServerError({
+ message: "Environment variable has not been configured: INF_APP_CONNECTION_GCP_SERVICE_ACCOUNT_CREDENTIAL"
+ });
+ }
+ sourceClient = buildGcpSourceCredential(appCfg.INF_APP_CONNECTION_GCP_SERVICE_ACCOUNT_CREDENTIAL);
+ }
+
+ const impersonated = new Impersonated({
+ sourceClient,
+ targetPrincipal: serviceAccountEmail,
+ lifetime: sessionTtlSeconds,
+ delegates: [],
+ targetScopes: ["https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/iam"]
+ });
+
+ let tokenResponse;
+ try {
+ tokenResponse = await impersonated.getAccessToken();
+ } catch (err) {
+ const msg = err instanceof Error ? err.message : String(err);
+ throw new BadRequestError({
+ message: `Failed to obtain GCP access token for [serviceAccountEmail=${serviceAccountEmail}]: ${msg}`
+ });
+ }
+
+ if (!tokenResponse?.token) {
+ throw new BadRequestError({
+ message: `Failed to obtain GCP access token for [serviceAccountEmail=${serviceAccountEmail}]`
+ });
+ }
+
+ credentials.token = tokenResponse.token;
+ delete credentials.serviceAccountKeyJson;
+ }
+
const sessionStarted = session.status === PamSessionStatus.Starting;
if (sessionStarted) {
@@ -278,10 +340,6 @@ export const pamSessionServiceFactory = ({
connectionDetails
);
- if (sessionStarted) {
- await pamSessionDAL.activateSession(sessionId);
- }
-
return {
credentials: { ...normalizedConnectionDetails, ...credentials },
recording,
@@ -477,7 +535,10 @@ export const pamSessionServiceFactory = ({
const metadata: Record<string, string> = {};
- if (account.accountType === PamAccountType.Kubernetes) {
+ if (account.accountType === PamAccountType.GcpIam) {
+ metadata.serviceAccountEmail = rawConnectionDetails.serviceAccountEmail as string;
+ metadata.authMethod = rawCredentials.authMethod as string;
+ } else if (account.accountType === PamAccountType.Kubernetes) {
metadata.authMethod = rawCredentials.authMethod as string;
if (rawCredentials.namespace) {
metadata.namespace = rawCredentials.namespace as string;
diff --git a/backend/src/ee/services/pam/pam-enums.ts b/backend/src/ee/services/pam/pam-enums.ts
index 21a9628191..17a5299171 100644
--- a/backend/src/ee/services/pam/pam-enums.ts
+++ b/backend/src/ee/services/pam/pam-enums.ts
@@ -8,6 +8,7 @@ export enum PamAccountType {
Redis = "redis",
Kubernetes = "kubernetes",
AwsIam = "aws-iam",
+ GcpIam = "gcp-iam",
Windows = "windows",
ActiveDirectory = "active-directory"
}
diff --git a/frontend/src/hooks/api/pam/enums.ts b/frontend/src/hooks/api/pam/enums.ts
index 7d33f217e0..969436a6bb 100644
--- a/frontend/src/hooks/api/pam/enums.ts
+++ b/frontend/src/hooks/api/pam/enums.ts
@@ -8,6 +8,7 @@ export enum PamAccountType {
Redis = "redis",
Kubernetes = "kubernetes",
AwsIam = "aws-iam",
+ GcpIam = "gcp-iam",
Windows = "windows",
ActiveDirectory = "active-directory"
}