Skip to content

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

fix(identity-auth): a zone alone no longer binds a GCE identity

Calvine54ef6f0ff6e
diff --git a/backend/src/server/routes/v1/identity-aws-iam-auth-router.ts b/backend/src/server/routes/v1/identity-aws-iam-auth-router.ts
index 2981d5c25d..870b902835 100644
--- a/backend/src/server/routes/v1/identity-aws-iam-auth-router.ts
+++ b/backend/src/server/routes/v1/identity-aws-iam-auth-router.ts
@@ -13,7 +13,9 @@ import { ActorType, AuthMode } from "@app/services/auth/auth-type";
import { TIdentityTrustedIp } from "@app/services/identity/identity-types";
import {
validateAccountIds,
- validatePrincipalArns
+ validateAccountIdsForUpdate,
+ validatePrincipalArns,
+ validatePrincipalArnsForUpdate
} from "@app/services/identity-aws-auth/identity-aws-auth-validators";
import { isSuperAdmin } from "@app/services/super-admin/super-admin-fns";
import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
@@ -259,8 +261,8 @@ export const registerIdentityAwsAuthRouter = async (server: FastifyZodProvider)
body: z
.object({
stsEndpoint: z.string().trim().min(1).optional().describe(AWS_AUTH.UPDATE.stsEndpoint),
- allowedPrincipalArns: validatePrincipalArns.optional().describe(AWS_AUTH.UPDATE.allowedPrincipalArns),
- allowedAccountIds: validateAccountIds.optional().describe(AWS_AUTH.UPDATE.allowedAccountIds),
+ allowedPrincipalArns: validatePrincipalArnsForUpdate.describe(AWS_AUTH.UPDATE.allowedPrincipalArns),
+ allowedAccountIds: validateAccountIdsForUpdate.describe(AWS_AUTH.UPDATE.allowedAccountIds),
accessTokenTrustedIps: z
.object({
ipAddress: z.string().trim()
diff --git a/backend/src/services/identity-aws-auth/identity-aws-auth-validators.ts b/backend/src/services/identity-aws-auth/identity-aws-auth-validators.ts
index d7d1da955a..be1bf18968 100644
--- a/backend/src/services/identity-aws-auth/identity-aws-auth-validators.ts
+++ b/backend/src/services/identity-aws-auth/identity-aws-auth-validators.ts
@@ -9,11 +9,10 @@ const arnRegex = new RE2(
/^arn:aws(?:-us-gov)?:(iam|sts)::\d{12}:(user\/[a-zA-Z0-9_.@+*/-]+|role\/[a-zA-Z0-9_.@+*/-]+|assumed-role\/[a-zA-Z0-9_.@+*/-]+|\*)$/
);
-export const validateAccountIds = z
+const accountIdsFormat = z
.string()
.trim()
.max(4096)
- .default("")
// Custom validation to ensure each part is a 12-digit number
.refine(
(data) => {
@@ -37,11 +36,14 @@ export const validateAccountIds = z
.join(", ");
});
-export const validatePrincipalArns = z
+export const validateAccountIds = accountIdsFormat.default("");
+// Omitted on update means "keep the stored value", so this must not carry a default.
+export const validateAccountIdsForUpdate = accountIdsFormat.optional();
+
+const principalArnsFormat = z
.string()
.trim()
.max(4096)
- .default("")
// Custom validation for ARN format
.refine(
(data) => {
@@ -69,3 +71,7 @@ export const validatePrincipalArns = z
.map((arn) => arn.trim())
.join(", ")
);
+
+export const validatePrincipalArns = principalArnsFormat.default("");
+// Omitted on update means "keep the stored value", so this must not carry a default.
+export const validatePrincipalArnsForUpdate = principalArnsFormat.optional();
diff --git a/backend/src/services/identity-gcp-auth/identity-gcp-auth-fns.ts b/backend/src/services/identity-gcp-auth/identity-gcp-auth-fns.ts
index 36dc596d41..54fce57aa3 100644
--- a/backend/src/services/identity-gcp-auth/identity-gcp-auth-fns.ts
+++ b/backend/src/services/identity-gcp-auth/identity-gcp-auth-fns.ts
@@ -7,26 +7,24 @@ import { UnauthorizedError } from "@app/lib/errors";
import { TDecodedGcpIamAuthJwt, TGcpIdTokenPayload } from "./identity-gcp-auth-types";
-// IAM tokens only carry a service account, so that is the only binding that can restrict them. GCE tokens
-// can also be restricted by project or zone, which is what the Compute Engine checks in login read.
+// Zones are shared by every GCP customer, so a zone alone does not tie the identity to an owner. A project
+// does, because a project ID belongs to one customer. Zones can only narrow a service account or project.
export const hasGcpTrustBinding = ({
type,
allowedServiceAccounts,
- allowedProjects,
- allowedZones
+ allowedProjects
}: {
type: string;
allowedServiceAccounts?: string | null;
allowedProjects?: string | null;
- allowedZones?: string | null;
}) => {
if (allowedServiceAccounts?.trim()) return true;
if (type === "iam") return false;
- return Boolean(allowedProjects?.trim()) || Boolean(allowedZones?.trim());
+ return Boolean(allowedProjects?.trim());
};
export const GCP_TRUST_BINDING_REQUIRED_MESSAGE =
- "Configure at least one allowed GCP service account, or for GCE identities a project or zone. Without one, any GCP workload that knows this identity's ID could log in as it.";
+ "Configure at least one allowed GCP service account, or for GCE identities an allowed project. A zone alone is not enough, because zones are shared by every GCP customer. Without one, any GCP workload that knows this identity's ID could log in as it.";
/**
* Validates that the identity token [jwt] sent in from a client GCE instance as part of GCP ID Token authentication
diff --git a/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.test.ts b/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.test.ts
index fcc3ba8a9a..57c74263ee 100644
--- a/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.test.ts
+++ b/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.test.ts
@@ -126,7 +126,7 @@ describe("gcpAuthService.login GCE Compute Engine detail requirement", () => {
test("rejects a token with no Compute Engine details when zones are restricted", async () => {
const { result } = login(
- { type: "gce", allowedZones: "us-central1-a" },
+ { type: "gce", allowedProjects: "my-project", allowedZones: "us-central1-a" },
{ email: SERVICE_ACCOUNT, computeEngineDetails: undefined }
);
@@ -196,7 +196,7 @@ describe("gcpAuthService.login GCE allow lists", () => {
test("rejects an instance running in a zone outside the allow list", async () => {
const { result } = login(
- { type: "gce", allowedZones: "us-east1-b" },
+ { type: "gce", allowedProjects: "my-project", allowedZones: "us-east1-b" },
{ email: SERVICE_ACCOUNT, computeEngineDetails }
);
@@ -220,6 +220,17 @@ describe("gcpAuthService.login trust binding", () => {
expect(issueIdentityAccessToken).not.toHaveBeenCalled();
});
+ // Zone names are shared by every GCP customer, so a zone alone must not count as a binding.
+ test("rejects a GCE identity bound only by zone", async () => {
+ const { result, issueIdentityAccessToken } = login(
+ { type: "gce", allowedZones: "us-central1-a" },
+ { email: SERVICE_ACCOUNT, computeEngineDetails }
+ );
+
+ await expect(result).rejects.toMatchObject({ detail: { reasonCode: "trust_binding_missing" } });
+ expect(issueIdentityAccessToken).not.toHaveBeenCalled();
+ });
+
test("rejects an IAM identity that has only project and zone set", async () => {
const { result } = login(
{ type: "iam", allowedProjects: "my-project", allowedZones: "us-central1-a" },
diff --git a/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts b/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts
index 070eef26f8..f162b9f159 100644
--- a/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts
+++ b/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts
@@ -365,7 +365,7 @@ export const identityGcpAuthServiceFactory = ({
throw new BadRequestError({ message: "Access token TTL cannot be greater than max TTL" });
}
- if (!hasGcpTrustBinding({ type, allowedServiceAccounts, allowedProjects, allowedZones })) {
+ if (!hasGcpTrustBinding({ type, allowedServiceAccounts, allowedProjects })) {
throw new BadRequestError({ message: GCP_TRUST_BINDING_REQUIRED_MESSAGE });
}
@@ -475,8 +475,7 @@ export const identityGcpAuthServiceFactory = ({
!hasGcpTrustBinding({
type: type ?? identityGcpAuth.type,
allowedServiceAccounts: allowedServiceAccounts ?? identityGcpAuth.allowedServiceAccounts,
- allowedProjects: allowedProjects ?? identityGcpAuth.allowedProjects,
- allowedZones: allowedZones ?? identityGcpAuth.allowedZones
+ allowedProjects: allowedProjects ?? identityGcpAuth.allowedProjects
})
) {
throw new BadRequestError({ message: GCP_TRUST_BINDING_REQUIRED_MESSAGE });