Skip to content

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

chore(gateway): list gcp everywhere, replace method literals with shared types

bernie-gdb0d6c7af33b
diff --git a/backend/src/ee/routes/v1/kmip-server-router.ts b/backend/src/ee/routes/v1/kmip-server-router.ts
index 6be4e25719..efc613683d 100644
--- a/backend/src/ee/routes/v1/kmip-server-router.ts
+++ b/backend/src/ee/routes/v1/kmip-server-router.ts
@@ -4,7 +4,10 @@ import { KmipServersSchema } from "@app/db/schemas";
import { EventType, UserAgentType } from "@app/ee/services/audit-log/audit-log-types";
import { MIN_SERVER_CERT_TTL } from "@app/ee/services/kmip/kmip-service";
import { validateAccountIds, validatePrincipalArns } from "@app/ee/services/resource-auth-method/aws-auth-validators";
-import { ResourceAuthMethodType } from "@app/ee/services/resource-auth-method/resource-auth-method-fns";
+import {
+ ResourceAuthMethodType,
+ TSettableAuthMethod
+} from "@app/ee/services/resource-auth-method/resource-auth-method-fns";
import { AuthMethodViewSchema } from "@app/ee/services/resource-auth-method/resource-auth-method-schemas";
import { ApiDocsTags } from "@app/lib/api-docs";
import { BadRequestError, UnauthorizedError } from "@app/lib/errors";
@@ -161,7 +164,7 @@ export const registerKmipServerRouter = async (server: FastifyZodProvider) => {
resourceType: "kmip",
resourceId: kmipServer.id,
resourceName: kmipServer.name,
- method: view.method as "aws" | "token",
+ method: view.method as TSettableAuthMethod,
methodConfigId: "config" in view && "id" in view.config ? view.config.id : kmipServer.id
}
}
@@ -301,7 +304,7 @@ export const registerKmipServerRouter = async (server: FastifyZodProvider) => {
resourceType: "kmip",
resourceId: req.params.kmipServerId,
resourceName: kmipServer.name,
- method: view.method as "aws" | "token",
+ method: view.method as TSettableAuthMethod,
methodConfigId: "config" in view && "id" in view.config ? view.config.id : req.params.kmipServerId
}
}
diff --git a/backend/src/ee/routes/v2/relay-router.ts b/backend/src/ee/routes/v2/relay-router.ts
index b9417001b1..ae1592a10e 100644
--- a/backend/src/ee/routes/v2/relay-router.ts
+++ b/backend/src/ee/routes/v2/relay-router.ts
@@ -3,7 +3,10 @@ import z from "zod";
import { RelaysSchema } from "@app/db/schemas";
import { EventType, UserAgentType } from "@app/ee/services/audit-log/audit-log-types";
import { validateAccountIds, validatePrincipalArns } from "@app/ee/services/resource-auth-method/aws-auth-validators";
-import { ResourceAuthMethodType } from "@app/ee/services/resource-auth-method/resource-auth-method-fns";
+import {
+ ResourceAuthMethodType,
+ TSettableAuthMethod
+} from "@app/ee/services/resource-auth-method/resource-auth-method-fns";
import { AuthMethodViewSchema } from "@app/ee/services/resource-auth-method/resource-auth-method-schemas";
import { UnauthorizedError } from "@app/lib/errors";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
@@ -114,7 +117,7 @@ export const registerRelayV2Router = async (server: FastifyZodProvider) => {
resourceType: "relay",
resourceId: relay.id,
resourceName: relay.name,
- method: view.method as "aws" | "token",
+ method: view.method as TSettableAuthMethod,
methodConfigId: "config" in view && "id" in view.config ? view.config.id : relay.id
}
}
@@ -250,7 +253,7 @@ export const registerRelayV2Router = async (server: FastifyZodProvider) => {
resourceType: "relay",
resourceId: req.params.relayId,
resourceName: relay.name,
- method: view.method as "aws" | "token",
+ method: view.method as TSettableAuthMethod,
methodConfigId: "config" in view && "id" in view.config ? view.config.id : req.params.relayId
}
}
diff --git a/backend/src/ee/routes/v3/gateway-router.ts b/backend/src/ee/routes/v3/gateway-router.ts
index 7919982dc8..e6d95530d9 100644
--- a/backend/src/ee/routes/v3/gateway-router.ts
+++ b/backend/src/ee/routes/v3/gateway-router.ts
@@ -17,7 +17,8 @@ import {
import {
GcpAuthType,
KubernetesTokenReviewMode,
- ResourceAuthMethodType
+ ResourceAuthMethodType,
+ type TSettableAuthMethod
} from "@app/ee/services/resource-auth-method/resource-auth-method-fns";
import { AuthMethodViewSchema } from "@app/ee/services/resource-auth-method/resource-auth-method-schemas";
import { TAuthMethodView } from "@app/ee/services/resource-auth-method/resource-auth-method-types";
@@ -415,7 +416,7 @@ export const registerGatewayV3Router = async (server: FastifyZodProvider) => {
resourceType: "gateway",
resourceId: req.params.gatewayId,
orgId: req.permission.orgId,
- method: result.method as "aws" | "gcp" | "kubernetes" | "token"
+ method: result.method as TSettableAuthMethod
}
})
.catch((err) => {
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index 84e3daa03f..a36cd07bed 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -7,6 +7,7 @@ import {
TCreateProjectTemplateDTO,
TUpdateProjectTemplateDTO
} from "@app/ee/services/project-template/project-template-types";
+import { TSettableAuthMethod } from "@app/ee/services/resource-auth-method/resource-auth-method-fns";
import { SecretRotation, SecretRotationStatus } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";
import {
TCreateSecretRotationV2DTO,
@@ -7277,7 +7278,7 @@ interface GatewayConnectEvent {
};
}
-type ResourceAuthMethodKind = "aws" | "gcp" | "kubernetes" | "token";
+type ResourceAuthMethodKind = TSettableAuthMethod;
type ResourceAuthMethodResourceType = "gateway" | "relay" | "kmip";
interface ResourceAuthMethodLoginEvent {
diff --git a/backend/src/ee/services/resource-auth-method/gcp-auth-fns.ts b/backend/src/ee/services/resource-auth-method/gcp-auth-fns.ts
index a48550983c..f859447a52 100644
--- a/backend/src/ee/services/resource-auth-method/gcp-auth-fns.ts
+++ b/backend/src/ee/services/resource-auth-method/gcp-auth-fns.ts
@@ -16,18 +16,29 @@ type TVerifyGcpTokenInput = {
// signJwt accepts a payload with no `exp`, which would make the proof replayable forever.
const MAX_IAM_TOKEN_LIFETIME_SECONDS = 12 * 60 * 60;
-export const assertIamTokenLifetime = (payload: { exp?: number } | null, nowSeconds: number) => {
- if (!payload?.exp) return "missing_expiry" as const;
- if (payload.exp <= nowSeconds) return "expired" as const;
- if (payload.exp - nowSeconds > MAX_IAM_TOKEN_LIFETIME_SECONDS) return "lifetime_too_long" as const;
+export const IamTokenLifetimeProblem = {
+ MissingExpiry: "missing_expiry",
+ Expired: "expired",
+ LifetimeTooLong: "lifetime_too_long"
+} as const;
+
+export type TIamTokenLifetimeProblem = (typeof IamTokenLifetimeProblem)[keyof typeof IamTokenLifetimeProblem];
+
+export const assertIamTokenLifetime = (
+ payload: { exp?: number } | null,
+ nowSeconds: number
+): TIamTokenLifetimeProblem | null => {
+ if (!payload?.exp) return IamTokenLifetimeProblem.MissingExpiry;
+ if (payload.exp <= nowSeconds) return IamTokenLifetimeProblem.Expired;
+ if (payload.exp - nowSeconds > MAX_IAM_TOKEN_LIFETIME_SECONDS) return IamTokenLifetimeProblem.LifetimeTooLong;
return null;
};
-const IAM_LIFETIME_MESSAGE = {
- missing_expiry: "carries no expiry",
- expired: "has already expired",
- lifetime_too_long: "expires more than 12 hours from now"
-} as const;
+const IAM_LIFETIME_MESSAGE: Record<TIamTokenLifetimeProblem, string> = {
+ [IamTokenLifetimeProblem.MissingExpiry]: "carries no expiry",
+ [IamTokenLifetimeProblem.Expired]: "has already expired",
+ [IamTokenLifetimeProblem.LifetimeTooLong]: "expires more than 12 hours from now"
+};
export const verifyGcpTokenAndExtractCaller = async ({
type,
diff --git a/backend/src/ee/services/resource-auth-method/resource-auth-method-fns.ts b/backend/src/ee/services/resource-auth-method/resource-auth-method-fns.ts
index 82b4dfdb0c..a7699650f1 100644
--- a/backend/src/ee/services/resource-auth-method/resource-auth-method-fns.ts
+++ b/backend/src/ee/services/resource-auth-method/resource-auth-method-fns.ts
@@ -208,3 +208,6 @@ export type TGcpAuthType = (typeof GcpAuthType)[keyof typeof GcpAuthType];
// eslint-disable-next-line @typescript-eslint/no-redeclare
export type ResourceAuthMethodType = (typeof ResourceAuthMethodType)[keyof typeof ResourceAuthMethodType];
+
+// The methods a resource can actually be configured with; `identity` is legacy and read-only.
+export type TSettableAuthMethod = Exclude<ResourceAuthMethodType, typeof ResourceAuthMethodType.Identity>;
diff --git a/backend/src/ee/services/resource-auth-method/resource-auth-method-service.ts b/backend/src/ee/services/resource-auth-method/resource-auth-method-service.ts
index c939c728ec..a180f17849 100644
--- a/backend/src/ee/services/resource-auth-method/resource-auth-method-service.ts
+++ b/backend/src/ee/services/resource-auth-method/resource-auth-method-service.ts
@@ -57,7 +57,8 @@ import {
RESOURCE_TYPE_RELAY,
ResourceAuthLoginFailureReason,
ResourceAuthMethodType,
- type ResourceRef
+ type ResourceRef,
+ type TSettableAuthMethod
} from "./resource-auth-method-fns";
import {
TAuthMethodView,
@@ -1097,7 +1098,7 @@ export const resourceAuthMethodServiceFactory = ({
}
if (loaded.identityId) {
throw new BadRequestError({
- message: `Identity-bound ${resourceLabel.toLowerCase()}s cannot be revoked directly. Create a new ${resourceLabel.toLowerCase()} with AWS, Kubernetes, or Token auth instead.`
+ message: `Identity-bound ${resourceLabel.toLowerCase()}s cannot be revoked directly. Create a new ${resourceLabel.toLowerCase()} with AWS, GCP, Kubernetes, or Token auth instead.`
});
}
@@ -1114,7 +1115,7 @@ export const resourceAuthMethodServiceFactory = ({
return {
resourceName: loaded.name,
orgId: loaded.orgId,
- method: registry.method as "aws" | "gcp" | "kubernetes" | "token"
+ method: registry.method as TSettableAuthMethod
};
};
diff --git a/backend/src/services/telemetry/telemetry-types.ts b/backend/src/services/telemetry/telemetry-types.ts
index de03313f67..053264a4fd 100644
--- a/backend/src/services/telemetry/telemetry-types.ts
+++ b/backend/src/services/telemetry/telemetry-types.ts
@@ -19,6 +19,7 @@ import {
} from "@app/ee/services/audit-log/audit-log-types";
import { PamSessionEndReason } from "@app/ee/services/pam/pam-enums";
import { ProxiedServiceSubstitutionSurface } from "@app/ee/services/proxied-service/proxied-service-enums";
+import { TSettableAuthMethod } from "@app/ee/services/resource-auth-method/resource-auth-method-fns";
import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";
import { SecretScanningDataSource } from "@app/ee/services/secret-scanning-v2/secret-scanning-v2-enums";
import { EnforcementLevel, SecretSharingAccessType } from "@app/lib/types";
@@ -1276,7 +1277,7 @@ export type TResourceAuthMethodEvent = {
resourceType: "gateway";
resourceId: string;
orgId: string;
- method: "aws" | "gcp" | "kubernetes" | "token";
+ method: TSettableAuthMethod;
};
};
diff --git a/docs/documentation/platform/gateways/gateway-deployment.mdx b/docs/documentation/platform/gateways/gateway-deployment.mdx
index dde328ed85..05717c76e4 100644
--- a/docs/documentation/platform/gateways/gateway-deployment.mdx
+++ b/docs/documentation/platform/gateways/gateway-deployment.mdx
@@ -399,7 +399,7 @@ For the ports, certificates, and traffic flow behind each mode, see [Network arc
From the gateway's detail page (select the gateway row in the list):
- **Generate deploy command**: Generates a fresh enrollment token (token method) or re-displays the start command for the AWS, GCP and Kubernetes methods. Selecting this on a token-method gateway doesn't disconnect the running gateway; the next login with the new token rotates credentials atomically.
-- **Edit auth method**: Switch between Token, AWS, and Kubernetes, or update the allowlists of the current method. Existing gateways keep their JWT until they restart and re-authenticate.
+- **Edit auth method**: Switch between Token, AWS, GCP, and Kubernetes, or update the allowlists of the current method. Existing gateways keep their JWT until they restart and re-authenticate.
- **Options → Revoke Access** — Disconnects the running gateway and invalidates outstanding enrollment tokens. The gateway must re-authenticate to reconnect. Gated by the dedicated `revoke-gateway-access` permission, separate from `edit-gateways`.
- **Options → Delete Gateway** — Permanently removes the gateway.
@@ -523,7 +523,7 @@ For **token-method** gateways, the access token and domain are saved to a config
- **Running as root/sudo:** `/etc/infisical/gateways/<gateway-name>.conf`
- **Running as a regular user:** `~/.infisical/gateways/<gateway-name>.conf`
-For **AWS-method** and **Kubernetes-method** gateways, no JWT is persisted to disk. The gateway re-authenticates on every start, by signing a fresh STS request with the host's AWS credentials or by presenting the pod's service account token. Only the gateway id and domain are stored locally.
+For **AWS-method**, **GCP-method** and **Kubernetes-method** gateways, no JWT is persisted to disk. The gateway re-authenticates on every start, by signing a fresh STS request with the host's AWS credentials, by presenting a GCP identity token, or by presenting the pod's service account token. Only the gateway id and domain are stored locally.
For systemd-based installations, the configuration is at `/etc/infisical/gateways/<gateway-name>.conf`. All config files are created with restricted permissions (0600).
</Accordion>
diff --git a/docs/self-hosting/helm-charts/gateway.mdx b/docs/self-hosting/helm-charts/gateway.mdx
index 38857c7f11..f5b2c523a8 100644
--- a/docs/self-hosting/helm-charts/gateway.mdx
+++ b/docs/self-hosting/helm-charts/gateway.mdx
@@ -133,7 +133,7 @@ helm uninstall infisical-gateway --namespace infisical-gateway
| `gateway.enrollment.credentialsSecretRef` | `""` | Kubernetes secret with credentials injected as env vars. |
| `gateway.relayName` | `""` | Specific relay to connect to. Empty for automatic selection. |
| `gateway.listenAddress` | `""` | `host:port` that Infisical dials to reach the gateway, which runs it in direct listen mode. Empty for relay mode. |
-| `persistence.enabled` | `true` | Enable persistent storage. Required for token auth, optional for AWS and Kubernetes auth. |
+| `persistence.enabled` | `true` | Enable persistent storage. Required for token auth, optional for AWS, GCP and Kubernetes auth. |
| `persistence.storageClass` | `""` | Storage class for the PVC. |
| `persistence.size` | `5Gi` | PVC size. |
| `persistence.existingClaim` | `""` | Use an existing PVC. |
@@ -200,7 +200,7 @@ gateway:
domain: ""
enrollment:
- # Enrollment method: "token", "aws", or "kubernetes".
+ # Enrollment method: "token", "aws", "gcp", or "kubernetes".
# Leave empty to use the legacy machine identity flow (env vars from secret.name).
method: ""
@@ -258,7 +258,7 @@ gateway:
# Persistent storage for the gateway (credentials and session recordings).
# Required when enrollment.method=token so credentials survive pod restarts.
-# Optional when enrollment.method=aws or enrollment.method=kubernetes, since both re-authenticate
+# Optional when enrollment.method is aws, gcp or kubernetes, since all three re-authenticate
# on every start.
# For legacy machine-identity installs (no enrollment.method), persistence only takes effect
# when existingClaim is provided.