Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Merge remote-tracking branch 'origin/main' into SECRETS-528
Thiago Araujo da Silva3cc6bd4a8d36
diff --cc backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.tsindex 46aa48a175,fbcf70759f..cb7a5b0e60--- a/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.ts+++ b/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.ts@@@ -33,13 -23,9 +23,14 @@@ importauthAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";+import {+ emitIdentityAuthMethodChanged,+ IdentityAuthMethodChange+} from "@app/services/identity/identity-auth-method-events";import { ActorType } from "../auth/auth-type";+ import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";import { TIdentityDALFactory } from "../identity/identity-dal";import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";diff --cc backend/src/services/identity-aws-auth/identity-aws-auth-service.tsindex c78dbf780d,ba4ab9c4ff..d61120993a--- a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts+++ b/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts@@@ -34,13 -24,9 +24,14 @@@ importauthAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";+import {+ emitIdentityAuthMethodChanged,+ IdentityAuthMethodChange+} from "@app/services/identity/identity-auth-method-events";import { ActorType } from "../auth/auth-type";+ import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";import { TIdentityDALFactory } from "../identity/identity-dal";import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";diff --cc backend/src/services/identity-azure-auth/identity-azure-auth-service.tsindex 1d640a7400,53bee09961..7380c58393--- a/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts+++ b/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts@@@ -29,13 -19,9 +19,14 @@@ importauthAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";+import {+ emitIdentityAuthMethodChanged,+ IdentityAuthMethodChange+} from "@app/services/identity/identity-auth-method-events";import { ActorType } from "../auth/auth-type";+ import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";import { TIdentityDALFactory } from "../identity/identity-dal";import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";diff --cc backend/src/services/identity-gcp-auth/identity-gcp-auth-service.test.tsindex 0000000000,a73b21afb5..94e1216870mode 000000,100644..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,0 -1,183 +1,184 @@@+ import { beforeEach, describe, expect, test, vi } from "vitest";++ import { identityGcpAuthServiceFactory } from "./identity-gcp-auth-service";+ import { TGcpIdentityDetails } from "./identity-gcp-auth-types";++ const { validateIamIdentity, validateIdTokenIdentity } = vi.hoisted(() => ({+ validateIamIdentity: vi.fn(),+ validateIdTokenIdentity: vi.fn()+ }));++ vi.mock("./identity-gcp-auth-fns", () => ({ validateIamIdentity, validateIdTokenIdentity }));++ vi.mock("@app/lib/config/env", () => ({+ getConfig: () => ({ OTEL_TELEMETRY_COLLECTION_ENABLED: false })+ }));++ vi.mock("@fastify/request-context", () => ({+ requestContext: { get: vi.fn(() => undefined) }+ }));++ const IDENTITY_ID = "5d3a8b2e-7c61-4b0f-9f3e-2a1c4d6e8f90";+ const ORG_ID = "org-id";+ const ACCESS_TOKEN = "access-token";++ const SERVICE_ACCOUNT = "[email protected]";+ const OTHER_SERVICE_ACCOUNT = "[email protected]";++ const computeEngineDetails = {+ instance_creation_timestamp: 1700000000,+ instance_id: "3802628075545820873",+ instance_name: "test-instance",+ project_id: "my-project",+ project_number: 123456789,+ zone: "us-central1-a"+ };++ type TGcpAuthRow = {+ type: "gce" | "iam";+ allowedServiceAccounts: string | null;+ allowedProjects: string | null;+ allowedZones: string | null;+ };++ const makeService = (gcpAuth: Partial<TGcpAuthRow> = {}) => {+ const issueIdentityAccessToken = vi.fn().mockResolvedValue({+ accessToken: ACCESS_TOKEN,+ identityAccessToken: { id: "access-token-id" }+ });++ const service = identityGcpAuthServiceFactory({+ identityGcpAuthDAL: {+ findOne: vi.fn().mockResolvedValue({+ identityId: IDENTITY_ID,+ type: "gce",+ allowedServiceAccounts: null,+ allowedProjects: null,+ allowedZones: null,+ accessTokenTTL: 3600,+ accessTokenMaxTTL: 7200,+ accessTokenNumUsesLimit: 0,+ accessTokenPeriod: 0,+ accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }],+ ...gcpAuth+ })+ } as never,+ identityDAL: {+ findById: vi.fn().mockResolvedValue({ id: IDENTITY_ID, orgId: ORG_ID, name: "gce-identity" })+ } as never,+ 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,+ keyStore: { setItemWithExpiryNX: vi.fn().mockResolvedValue(null) } as never,+ identityAccessTokenDAL: {} as never,+ permissionService: {} as never,+ licenseService: {} as never,- identityAccessTokenService: { issueIdentityAccessToken } as never++ identityAccessTokenService: { issueIdentityAccessToken } as never,++ eventEmitter: { emit: vi.fn() } as never+ });++ return { service, issueIdentityAccessToken };+ };++ const login = (gcpAuth: Partial<TGcpAuthRow>, details: TGcpIdentityDetails) => {+ const { service, issueIdentityAccessToken } = makeService(gcpAuth);+ validateIdTokenIdentity.mockResolvedValue(details);+ validateIamIdentity.mockResolvedValue(details);+ return { result: service.login({ identityId: IDENTITY_ID, jwt: "gcp-jwt" }), issueIdentityAccessToken };+ };++ beforeEach(() => {+ vi.clearAllMocks();+ });++ // A GCE ID token only carries google.compute_engine when it was minted by the metadata server on+ // an instance. A token minted any other way by an allowed service account would otherwise sail+ // past the project and zone allow lists, because `undefined === undefined` never matches an entry+ // but the checks below read through an optional chain. Refusing the login is what keeps the+ // allow lists from silently becoming a service-account-only check.+ describe("gcpAuthService.login GCE Compute Engine detail requirement", () => {+ test("rejects a token with no Compute Engine details when projects are restricted", async () => {+ const { result, issueIdentityAccessToken } = login(+ { type: "gce", allowedProjects: "my-project" },+ { email: SERVICE_ACCOUNT, computeEngineDetails: undefined }+ );++ await expect(result).rejects.toThrow("Access denied: GCP identity token is missing the Compute Engine details");+ await expect(result).rejects.toMatchObject({+ detail: { reasonCode: "compute_engine_details_missing", identityId: IDENTITY_ID, orgId: ORG_ID }+ });+ expect(issueIdentityAccessToken).not.toHaveBeenCalled();+ });++ test("rejects a token with no Compute Engine details when zones are restricted", async () => {+ const { result } = login(+ { type: "gce", allowedZones: "us-central1-a" },+ { email: SERVICE_ACCOUNT, computeEngineDetails: undefined }+ );++ await expect(result).rejects.toMatchObject({ detail: { reasonCode: "compute_engine_details_missing" } });+ });++ // Nothing about the identity depends on where the token came from, so requiring GCE details+ // here would break every unrestricted GCE configuration in the field.+ test("allows a token with no Compute Engine details when neither projects nor zones are restricted", async () => {+ const { result } = login({ type: "gce" }, { email: SERVICE_ACCOUNT, computeEngineDetails: undefined });++ await expect(result).resolves.toMatchObject({ accessToken: ACCESS_TOKEN });+ });++ // IAM tokens are signed service account JWTs and never carry GCE details, so the guard must+ // stay scoped to the gce type even when the stale project and zone columns are populated.+ test("allows an IAM login even while project and zone columns are populated", async () => {+ const { result } = login(+ { type: "iam", allowedProjects: "my-project", allowedZones: "us-central1-a" },+ { email: SERVICE_ACCOUNT }+ );++ await expect(result).resolves.toMatchObject({ accessToken: ACCESS_TOKEN });+ });+ });++ describe("gcpAuthService.login GCE allow lists", () => {+ test("allows a token whose project and zone are both allowed", async () => {+ const { result } = login(+ {+ type: "gce",+ allowedServiceAccounts: `${OTHER_SERVICE_ACCOUNT}, ${SERVICE_ACCOUNT}`,+ allowedProjects: "other-project, my-project",+ allowedZones: "us-east1-b, us-central1-a"+ },+ { email: SERVICE_ACCOUNT, computeEngineDetails }+ );++ await expect(result).resolves.toMatchObject({ accessToken: ACCESS_TOKEN });+ });++ test("rejects a service account outside the allow list", async () => {+ const { result } = login(+ { type: "gce", allowedServiceAccounts: OTHER_SERVICE_ACCOUNT },+ { email: SERVICE_ACCOUNT, computeEngineDetails }+ );++ await expect(result).rejects.toMatchObject({ detail: { reasonCode: "service_account_not_allowed" } });+ });++ test("rejects an instance running in a project outside the allow list", async () => {+ const { result } = login(+ { type: "gce", allowedProjects: "other-project" },+ { email: SERVICE_ACCOUNT, computeEngineDetails }+ );++ await expect(result).rejects.toMatchObject({ detail: { reasonCode: "project_not_allowed" } });+ });++ test("rejects an instance running in a zone outside the allow list", async () => {+ const { result } = login(+ { type: "gce", allowedZones: "us-east1-b" },+ { email: SERVICE_ACCOUNT, computeEngineDetails }+ );++ await expect(result).rejects.toMatchObject({ detail: { reasonCode: "zone_not_allowed" } });+ });+ });diff --cc backend/src/services/identity-gcp-auth/identity-gcp-auth-service.tsindex cfa08cc0d8,fe4fbc84b7..b403425d3b--- a/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts+++ b/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts@@@ -29,13 -19,9 +19,14 @@@ importauthAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";+import {+ emitIdentityAuthMethodChanged,+ IdentityAuthMethodChange+} from "@app/services/identity/identity-auth-method-events";import { ActorType } from "../auth/auth-type";+ import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";import { TIdentityDALFactory } from "../identity/identity-dal";import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";diff --cc backend/src/services/identity-jwt-auth/identity-jwt-auth-service.tsindex 7e0b987b0c,3b78bab57d..7c5d3f2722--- a/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts+++ b/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts@@@ -41,13 -31,10 +31,15 @@@ import} from "@app/lib/telemetry/metrics";import { getValueByDot } from "@app/lib/template/dot-access";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";+import {+ emitIdentityAuthMethodChanged,+ IdentityAuthMethodChange+} from "@app/services/identity/identity-auth-method-events";import { ActorType } from "../auth/auth-type";+ import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";+ import { splitCommaSeparatedPolicyValues } from "../identity/identity-auth-policy-values";import { TIdentityDALFactory } from "../identity/identity-dal";import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";diff --cc backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.tsindex 359beb0615,f6fb7fa050..e18ee185be--- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts+++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts@@@ -62,13 -52,9 +52,14 @@@ import} from "@app/lib/telemetry/metrics";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";import { getSharedHttpsAgent, safeRequest } from "@app/lib/validator/safe-request";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";+import {+ emitIdentityAuthMethodChanged,+ IdentityAuthMethodChange+} from "@app/services/identity/identity-auth-method-events";import { ActorType } from "../auth/auth-type";+ import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";import { TIdentityDALFactory } from "../identity/identity-dal";import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";diff --cc backend/src/services/identity-ldap-auth/identity-ldap-auth-service.tsindex 2e90d7c693,21b1b8ad2f..e99db681e4--- a/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts+++ b/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts@@@ -40,13 -35,9 +35,14 @@@ importrecordAuthAttemptMetric} from "@app/lib/telemetry/metrics";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";+import {+ emitIdentityAuthMethodChanged,+ IdentityAuthMethodChange+} from "@app/services/identity/identity-auth-method-events";import { ActorType } from "../auth/auth-type";+ import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";import { TIdentityDALFactory } from "../identity/identity-dal";import {clearIdentityLockoutsForAuthMethod,diff --cc backend/src/services/identity-oci-auth/identity-oci-auth-service.tsindex 23ea38fb2f,cb3ef4c583..02e0ce73d0--- a/backend/src/services/identity-oci-auth/identity-oci-auth-service.ts+++ b/backend/src/services/identity-oci-auth/identity-oci-auth-service.ts@@@ -34,13 -24,9 +24,14 @@@ importauthAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";+import {+ emitIdentityAuthMethodChanged,+ IdentityAuthMethodChange+} from "@app/services/identity/identity-auth-method-events";import { ActorType } from "../auth/auth-type";+ import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";import { TIdentityDALFactory } from "../identity/identity-dal";import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";diff --cc backend/src/services/identity-oidc-auth/identity-oidc-auth-service.tsindex 0cdca953eb,f874954f46..ffd4b822d7--- a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts+++ b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts@@@ -51,13 -41,10 +41,15 @@@ import} from "@app/lib/telemetry/metrics";import { getValueByDot } from "@app/lib/template/dot-access";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";+import {+ emitIdentityAuthMethodChanged,+ IdentityAuthMethodChange+} from "@app/services/identity/identity-auth-method-events";import { ActorType } from "../auth/auth-type";+ import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";+ import { splitCommaSeparatedPolicyValues } from "../identity/identity-auth-policy-values";import { TIdentityDALFactory } from "../identity/identity-dal";import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";diff --cc backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.tsindex f06fbc151c,ef9dcf2ad7..a4ecf13f31--- a/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts+++ b/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts@@@ -39,13 -29,9 +29,14 @@@ importrecordAuthAttemptMetric} from "@app/lib/telemetry/metrics";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";+import {+ emitIdentityAuthMethodChanged,+ IdentityAuthMethodChange+} from "@app/services/identity/identity-auth-method-events";import { ActorType } from "../auth/auth-type";+ import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";import { TIdentityDALFactory } from "../identity/identity-dal";import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";diff --cc backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.tsindex 7febaf7117,81f626a845..8110c3eaf9--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts@@@ -32,13 -22,9 +22,14 @@@ importauthAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";+import {+ emitIdentityAuthMethodChanged,+ IdentityAuthMethodChange+} from "@app/services/identity/identity-auth-method-events";import { ActorType } from "../auth/auth-type";+ import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";import { TIdentityDALFactory } from "../identity/identity-dal";import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";diff --cc backend/src/services/identity-token-auth/identity-token-auth-service.tsindex 5576ae3959,4ac809ea2d..381b7ffe47--- a/backend/src/services/identity-token-auth/identity-token-auth-service.ts+++ b/backend/src/services/identity-token-auth/identity-token-auth-service.ts@@@ -26,13 -16,9 +16,14 @@@ import { BadRequestError, ForbiddenRequimport { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";import { requestMemoKeys } from "@app/lib/request-context/memo-keys";import { requestMemoize } from "@app/lib/request-context/request-memoizer";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";+import {+ emitIdentityAuthMethodChanged,+ IdentityAuthMethodChange+} from "@app/services/identity/identity-auth-method-events";import { ActorType } from "../auth/auth-type";+ import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";import { computeTokenAuthRevokeMarkerExpiry } from "../identity-access-token/identity-access-token-fns";import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";@@@ -71,10 -57,12 +62,13 @@@ type TIdentityTokenAuthServiceFactoryDe| "markPerTokenRevocation"| "invalidateTrustedIpsCache">;- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;+ permissionService: Pick<+ TPermissionServiceFactory,+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities"+ >;licenseService: Pick<TLicenseServiceFactory, "getPlan">;orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;+ eventEmitter: TEventEmitter;};export type TIdentityTokenAuthServiceFactory = ReturnType<typeof identityTokenAuthServiceFactory>;diff --cc backend/src/services/identity-ua/identity-ua-service.tsindex a045555c54,24c9a723dd..5a150e6da2--- a/backend/src/services/identity-ua/identity-ua-service.ts+++ b/backend/src/services/identity-ua/identity-ua-service.ts@@@ -32,13 -27,9 +27,14 @@@ importauthAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";+import {+ emitIdentityAuthMethodChanged,+ IdentityAuthMethodChange+} from "@app/services/identity/identity-auth-method-events";import { ActorType } from "../auth/auth-type";+ import { assertIdentityAuthAccessAllowed } from "../identity/identity-auth-permission-fns";import { TIdentityDALFactory } from "../identity/identity-dal";import {clearIdentityLockoutsForAuthMethod,