Skip to content

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

fix(identity-auth): gate only creation on the allow list and warn on unbound logins

Calvinf3156f3b33f8
diff --git a/backend/src/db/migrations/20261021120000_identity-aws-gcp-auth-require-allow-list.ts b/backend/src/db/migrations/20261021120000_identity-aws-gcp-auth-require-allow-list.ts
deleted file mode 100644
index e37caad178..0000000000
--- a/backend/src/db/migrations/20261021120000_identity-aws-gcp-auth-require-allow-list.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import { Knex } from "knex";
-
-import { TableName } from "../schemas";
-
-const TABLES = [TableName.IdentityAwsAuth, TableName.IdentityGcpAuth];
-
-export async function up(knex: Knex): Promise<void> {
- for (const tableName of TABLES) {
- // eslint-disable-next-line no-await-in-loop
- const hasColumn = await knex.schema.hasColumn(tableName, "requireAllowList");
- if (!hasColumn) {
- // eslint-disable-next-line no-await-in-loop
- await knex.schema.alterTable(tableName, (t) => {
- t.boolean("requireAllowList").notNullable().defaultTo(false);
- });
- // Rows that exist now were saved before the allow list was enforced, so they get false. Flipping the
- // default afterwards means every row created from here on is enforced, with no backfill needed.
- // eslint-disable-next-line no-await-in-loop
- await knex.raw(`ALTER TABLE ?? ALTER COLUMN "requireAllowList" SET DEFAULT true`, [tableName]);
- }
- }
-}
-
-export async function down(knex: Knex): Promise<void> {
- for (const tableName of TABLES) {
- // eslint-disable-next-line no-await-in-loop
- const hasColumn = await knex.schema.hasColumn(tableName, "requireAllowList");
- if (hasColumn) {
- // eslint-disable-next-line no-await-in-loop
- await knex.schema.alterTable(tableName, (t) => {
- t.dropColumn("requireAllowList");
- });
- }
- }
-}
diff --git a/backend/src/db/schemas/identity-aws-auths.ts b/backend/src/db/schemas/identity-aws-auths.ts
index 0efd26f968..83f5b43cf3 100644
--- a/backend/src/db/schemas/identity-aws-auths.ts
+++ b/backend/src/db/schemas/identity-aws-auths.ts
@@ -20,8 +20,7 @@ export const IdentityAwsAuthsSchema = z.object({
stsEndpoint: z.string(),
allowedPrincipalArns: z.string(),
allowedAccountIds: z.string(),
- accessTokenPeriod: z.coerce.number().default(0),
- requireAllowList: z.boolean().default(true)
+ accessTokenPeriod: z.coerce.number().default(0)
});
export type TIdentityAwsAuths = z.infer<typeof IdentityAwsAuthsSchema>;
diff --git a/backend/src/db/schemas/identity-gcp-auths.ts b/backend/src/db/schemas/identity-gcp-auths.ts
index b8d438d1e7..536e7200aa 100644
--- a/backend/src/db/schemas/identity-gcp-auths.ts
+++ b/backend/src/db/schemas/identity-gcp-auths.ts
@@ -20,8 +20,7 @@ export const IdentityGcpAuthsSchema = z.object({
allowedServiceAccounts: z.string().nullable().optional(),
allowedProjects: z.string().nullable().optional(),
allowedZones: z.string().nullable().optional(),
- accessTokenPeriod: z.coerce.number().default(0),
- requireAllowList: z.boolean().default(true)
+ accessTokenPeriod: z.coerce.number().default(0)
});
export type TIdentityGcpAuths = z.infer<typeof IdentityGcpAuthsSchema>;
diff --git a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts b/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts
index 5b4e96d7e5..302ce45a7b 100644
--- a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts
+++ b/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts
@@ -155,21 +155,7 @@ export const identityAwsAuthServiceFactory = ({
try {
if (!hasAwsTrustBinding(identityAwsAuth)) {
- if (identityAwsAuth.requireAllowList) {
- throw new UnauthorizedError({
- message:
- "Access denied: this identity has no AWS account ID or principal ARN configured. An admin must add one before it can authenticate.",
- detail: {
- reasonCode: "trust_binding_missing",
- identityId: identity.id,
- orgId: identity.orgId,
- identityName: identity.name
- }
- });
- }
- logger.warn(
- `AWS Auth Login: identity has no trust binding and its auth config predates enforcement, allowing [identity-id=${identity.id}]`
- );
+ logger.warn(`AWS Auth Login: identity has no trust binding, allowing [identity-id=${identity.id}]`);
}
const headers: TAwsGetCallerIdentityHeaders = JSON.parse(Buffer.from(iamRequestHeaders, "base64").toString());
@@ -449,7 +435,6 @@ export const identityAwsAuthServiceFactory = ({
identityId: identityMembershipOrg.identity.id,
type: "iam",
stsEndpoint,
- requireAllowList: true,
allowedPrincipalArns,
allowedAccountIds,
accessTokenMaxTTL,
@@ -566,7 +551,6 @@ export const identityAwsAuthServiceFactory = ({
identityAwsAuth.id,
{
stsEndpoint,
- requireAllowList: true,
allowedPrincipalArns,
allowedAccountIds,
accessTokenMaxTTL,
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 d40bb4bb7b..26ffc3cbc3 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
@@ -1,5 +1,8 @@
import { beforeEach, describe, expect, test, vi } from "vitest";
+import { IdentityAuthMethod } from "@app/db/schemas";
+import { logger } from "@app/lib/logger";
+
import { identityGcpAuthServiceFactory } from "./identity-gcp-auth-service";
import { TGcpIdentityDetails } from "./identity-gcp-auth-types";
@@ -43,14 +46,13 @@ const computeEngineDetails = {
};
type TGcpAuthRow = {
- requireAllowList: boolean;
type: "gce" | "iam";
allowedServiceAccounts: string | null;
allowedProjects: string | null;
allowedZones: string | null;
};
-const makeService = (gcpAuth: Partial<TGcpAuthRow> = {}) => {
+const makeService = (gcpAuth: Partial<TGcpAuthRow> = {}, authMethods: string[] = []) => {
const issueIdentityAccessToken = vi.fn().mockResolvedValue({
accessToken: ACCESS_TOKEN,
identityAccessToken: { id: "access-token-id" }
@@ -60,7 +62,6 @@ const makeService = (gcpAuth: Partial<TGcpAuthRow> = {}) => {
identityGcpAuthDAL: {
findOne: vi.fn().mockResolvedValue({
identityId: IDENTITY_ID,
- requireAllowList: true,
type: "gce",
allowedServiceAccounts: null,
allowedProjects: null,
@@ -79,7 +80,13 @@ const makeService = (gcpAuth: Partial<TGcpAuthRow> = {}) => {
orgDAL: {
findById: vi.fn().mockResolvedValue({ id: ORG_ID, name: "org", slug: "org", rootOrgId: null, parentOrgId: null })
} as never,
- membershipIdentityDAL: { update: vi.fn().mockResolvedValue(undefined) } as never,
+ membershipIdentityDAL: {
+ update: vi.fn().mockResolvedValue(undefined),
+ getIdentityById: vi.fn().mockResolvedValue({
+ scopeOrgId: ORG_ID,
+ identity: { id: IDENTITY_ID, orgId: ORG_ID, projectId: null, authMethods }
+ })
+ } as never,
keyStore: { setItemWithExpiryNX: vi.fn().mockResolvedValue(null) } as never,
identityAccessTokenDAL: {} as never,
permissionService: {} as never,
@@ -201,73 +208,83 @@ describe("gcpAuthService.login GCE allow lists", () => {
});
});
-// An identity with no binding would otherwise accept any token that carries its UUID as audience,
-// so the login refuses it before the token is looked at.
-describe("gcpAuthService.login trust binding", () => {
- test("rejects a GCE identity with no service account, project, or zone before verifying the token", async () => {
- const { result, issueIdentityAccessToken } = login(
- { type: "gce" },
- { email: SERVICE_ACCOUNT, computeEngineDetails }
- );
+// Existing identities saved without a binding keep logging in, so the login only warns.
+describe("gcpAuthService.login without a trust binding", () => {
+ test("allows a GCE identity with no service account, project, or zone and logs a warning", async () => {
+ const { result } = login({ type: "gce" }, { email: SERVICE_ACCOUNT, computeEngineDetails });
- await expect(result).rejects.toMatchObject({
- detail: { reasonCode: "trust_binding_missing", identityId: IDENTITY_ID, orgId: ORG_ID }
- });
- expect(validateIdTokenIdentity).not.toHaveBeenCalled();
- 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();
+ await expect(result).resolves.toMatchObject({ accessToken: ACCESS_TOKEN });
+ expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining(IDENTITY_ID));
});
- 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" },
- { email: SERVICE_ACCOUNT }
- );
+ test("allows an IAM identity with no service account and logs a warning", async () => {
+ const { result } = login({ type: "iam" }, { email: SERVICE_ACCOUNT });
- await expect(result).rejects.toMatchObject({ detail: { reasonCode: "trust_binding_missing" } });
- expect(validateIamIdentity).not.toHaveBeenCalled();
+ await expect(result).resolves.toMatchObject({ accessToken: ACCESS_TOKEN });
+ expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining(IDENTITY_ID));
});
- test("treats whitespace-only lists as unset", async () => {
- const { result } = login(
- { type: "gce", allowedServiceAccounts: " ", allowedProjects: " ", allowedZones: "" },
- { email: SERVICE_ACCOUNT, computeEngineDetails }
- );
+ test("does not warn when a service account is set", async () => {
+ const { result } = login({ type: "iam", allowedServiceAccounts: SERVICE_ACCOUNT }, { email: SERVICE_ACCOUNT });
- await expect(result).rejects.toMatchObject({ detail: { reasonCode: "trust_binding_missing" } });
+ await expect(result).resolves.toMatchObject({ accessToken: ACCESS_TOKEN });
+ expect(logger.warn).not.toHaveBeenCalled();
});
});
-describe("gcpAuthService.login legacy identities that do not require an allow list", () => {
- test("allows a GCE identity with no binding saved before the allow list was required", async () => {
- const { result, issueIdentityAccessToken } = login(
- { type: "gce", requireAllowList: false },
- { email: SERVICE_ACCOUNT, computeEngineDetails }
- );
+// Attach and update are the only places a binding can be saved, so they are what keeps new identities bound. The
+// permission service is an empty object here, so a call that got past the binding check would throw a TypeError
+// instead of the binding message.
+describe("gcpAuthService trust binding on write", () => {
+ const BINDING_MESSAGE = "Configure at least one allowed GCP service account";
+
+ const attach = (body: Record<string, unknown>) => {
+ const { service } = makeService({}, []);
+ return service.attachGcpAuth({
+ identityId: IDENTITY_ID,
+ actorOrgId: ORG_ID,
+ type: "gce",
+ allowedServiceAccounts: "",
+ allowedProjects: "",
+ allowedZones: "",
+ accessTokenTTL: 3600,
+ accessTokenMaxTTL: 7200,
+ accessTokenNumUsesLimit: 0,
+ accessTokenTrustedIps: [],
+ ...body
+ } as never);
+ };
+
+ const update = (existing: Partial<TGcpAuthRow>, body: Record<string, unknown>) => {
+ const { service } = makeService(existing, [IdentityAuthMethod.GCP_AUTH]);
+ return service.updateGcpAuth({ identityId: IDENTITY_ID, actorOrgId: ORG_ID, ...body } as never);
+ };
+
+ test("attach rejects a GCE identity with no binding", async () => {
+ await expect(attach({ type: "gce" })).rejects.toThrow(BINDING_MESSAGE);
+ });
- await expect(result).resolves.toMatchObject({ accessToken: ACCESS_TOKEN });
- expect(issueIdentityAccessToken).toHaveBeenCalledTimes(1);
+ test("attach rejects a GCE identity bound only by zone", async () => {
+ await expect(attach({ type: "gce", allowedZones: "us-central1-a" })).rejects.toThrow(BINDING_MESSAGE);
});
- test("allows an IAM identity with no binding saved before the allow list was required", async () => {
- const { result } = login({ type: "iam", requireAllowList: false }, { email: SERVICE_ACCOUNT });
+ test("attach rejects an IAM identity with a project but no service account", async () => {
+ await expect(attach({ type: "iam", allowedProjects: "my-project" })).rejects.toThrow(BINDING_MESSAGE);
+ });
- await expect(result).resolves.toMatchObject({ accessToken: ACCESS_TOKEN });
+ test("update rejects clearing the last binding", async () => {
+ await expect(
+ update({ type: "gce", allowedServiceAccounts: SERVICE_ACCOUNT }, { allowedServiceAccounts: "" })
+ ).rejects.toThrow(BINDING_MESSAGE);
});
- test("denies an unbound identity once the allow list is required", async () => {
- const { result } = login({ type: "gce", requireAllowList: true }, { email: SERVICE_ACCOUNT, computeEngineDetails });
+ test("update rejects a change to an identity that has no binding and does not add one", async () => {
+ await expect(update({ type: "gce" }, { accessTokenTTL: 1800 })).rejects.toThrow(BINDING_MESSAGE);
+ });
- await expect(result).rejects.toMatchObject({ detail: { reasonCode: "trust_binding_missing" } });
+ test("update rejects switching a project-bound GCE identity to IAM", async () => {
+ await expect(update({ type: "gce", allowedProjects: "my-project" }, { type: "iam" })).rejects.toThrow(
+ BINDING_MESSAGE
+ );
});
});
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 f7b74f9091..12101b133d 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
@@ -110,21 +110,7 @@ export const identityGcpAuthServiceFactory = ({
try {
if (!hasGcpTrustBinding(identityGcpAuth)) {
- if (identityGcpAuth.requireAllowList) {
- throw new UnauthorizedError({
- message:
- "Access denied: this identity has no GCP service account, project, or zone configured. An admin must add one before it can authenticate.",
- detail: {
- reasonCode: "trust_binding_missing",
- identityId: identity.id,
- orgId: identity.orgId,
- identityName: identity.name
- }
- });
- }
- logger.warn(
- `GCP Auth Login: identity has no trust binding and its auth config predates enforcement, allowing [identity-id=${identity.id}]`
- );
+ logger.warn(`GCP Auth Login: identity has no trust binding, allowing [identity-id=${identity.id}]`);
}
let gcpIdentityDetails: TGcpIdentityDetails;
@@ -407,7 +393,6 @@ export const identityGcpAuthServiceFactory = ({
{
identityId: identityMembershipOrg.identity.id,
type,
- requireAllowList: true,
allowedServiceAccounts,
allowedProjects,
allowedZones,
@@ -527,7 +512,6 @@ export const identityGcpAuthServiceFactory = ({
identityGcpAuth.id,
{
type,
- requireAllowList: true,
allowedServiceAccounts,
allowedProjects,
allowedZones,