Skip to content

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

remove defaultPamProjectId column from orgs

x03220517a4b2112762
diff --git a/backend/src/@types/fastify.d.ts b/backend/src/@types/fastify.d.ts
index 9675201718..49e9417905 100644
--- a/backend/src/@types/fastify.d.ts
+++ b/backend/src/@types/fastify.d.ts
@@ -33,7 +33,6 @@ import { TKmipServiceFactory } from "@app/ee/services/kmip/kmip-service";
import { TLdapConfigServiceFactory } from "@app/ee/services/ldap-config/ldap-config-service";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { TOidcConfigServiceFactory } from "@app/ee/services/oidc/oidc-config-service";
-import { TPamProjectResolverFactory } from "@app/ee/services/pam-instance/pam-project-resolver";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { TPitServiceFactory } from "@app/ee/services/pit/pit-service";
import { TPkiAcmeServiceFactory } from "@app/ee/services/pki-acme/pki-acme-types";
@@ -252,7 +251,6 @@ declare module "fastify" {
};
auditLogInfo: Pick<TCreateAuditLogDTO, "userAgent" | "userAgentType" | "ipAddress" | "actor" | "orgId">;
internalCertManagerProjectId: string;
- internalPamProjectId: string;
ssoConfig: Awaited<ReturnType<TSamlConfigServiceFactory["getSaml"]>>;
ldapConfig: Awaited<ReturnType<TLdapConfigServiceFactory["getLdapCfg"]>> & {
allowedFields?: TAllowedFields[];
@@ -331,7 +329,6 @@ declare module "fastify" {
signerPolicy: TSignerPolicyServiceFactory;
pkiApplicationEnrollment: TPkiApplicationEnrollmentServiceFactory;
certManagerProjectResolver: TCertManagerProjectResolverFactory;
- pamProjectResolver: TPamProjectResolverFactory;
certManagerInstance: TCertManagerInstanceServiceFactory;
certManagerExport: TCertManagerExportServiceFactory;
sshCertificateAuthority: TSshCertificateAuthorityServiceFactory;
diff --git a/backend/src/db/migrations/20260603030053_pam-revamp.ts b/backend/src/db/migrations/20260603030053_pam-revamp.ts
index 40ca637aa3..7fad535cf1 100644
--- a/backend/src/db/migrations/20260603030053_pam-revamp.ts
+++ b/backend/src/db/migrations/20260603030053_pam-revamp.ts
@@ -56,29 +56,29 @@ const createPamProjectForOrg = async (knex: Knex, orgId: string) => {
})
.returning("id")) as Array<{ id: string }>;
- await knex(TableName.Organization).where("id", orgId).update({ defaultPamProjectId: projectId });
await seedDefaultTemplates(knex, orgId);
return projectId;
};
const backfillPamProjectsForAllOrgs = async (knex: Knex) => {
- const allOrgs = (await knex(TableName.Organization).whereNull("defaultPamProjectId").select("id")) as Array<{
- id: string;
- }>;
+ const allOrgs = (await knex(TableName.Organization).select("id")) as Array<{ id: string }>;
+ const orgToPamProject = new Map<string, string>();
for (let i = 0; i < allOrgs.length; i += BACKFILL_CHUNK_SIZE) {
const chunk = allOrgs.slice(i, i + BACKFILL_CHUNK_SIZE);
- await Promise.all(chunk.map(({ id }) => createPamProjectForOrg(knex, id)));
+ const results = await Promise.all(
+ chunk.map(async ({ id }) => ({ orgId: id, projectId: await createPamProjectForOrg(knex, id) }))
+ );
+ for (const { orgId, projectId } of results) {
+ orgToPamProject.set(orgId, projectId);
+ }
}
+
+ return orgToPamProject;
};
export async function up(knex: Knex): Promise<void> {
- await knex.schema.alterTable(TableName.Organization, (t) => {
- t.string("defaultPamProjectId", 36).nullable();
- t.foreign("defaultPamProjectId").references("id").inTable(TableName.Project).onDelete("SET NULL");
- });
-
await knex.schema.createTable(TableName.PamAccountTemplate, (t) => {
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
@@ -114,7 +114,7 @@ export async function up(knex: Knex): Promise<void> {
// Capture orgs that have a PAM project before backfill
const orgsWithPam = await knex(TableName.Project).where("type", ProjectType.PAM).distinct("orgId").select("orgId");
- await backfillPamProjectsForAllOrgs(knex);
+ const orgToPamProject = await backfillPamProjectsForAllOrgs(knex);
// Drop old folders table and recreate with new schema
await knex.raw(`UPDATE ${TableName.PamAccount} SET "folderId" = NULL WHERE "folderId" IS NOT NULL`);
@@ -195,8 +195,7 @@ export async function up(knex: Knex): Promise<void> {
kmsService.createCipherPairWithDataKey({ type: KmsDataKey.Organization, orgId }, knex);
for (const { orgId } of orgsWithPam) {
- const org = await knex(TableName.Organization).where("id", orgId).first("defaultPamProjectId");
- const newProjectId = org!.defaultPamProjectId as string;
+ const newProjectId = orgToPamProject.get(orgId)!;
const orgCipher = await getOrgCipher(orgId);
const reEncrypt = (oldCipher: Awaited<ReturnType<typeof getProjectCipher>>, blob?: Buffer | null) => {
diff --git a/backend/src/db/schemas/organizations.ts b/backend/src/db/schemas/organizations.ts
index eb9596139e..76ad1aa180 100644
--- a/backend/src/db/schemas/organizations.ts
+++ b/backend/src/db/schemas/organizations.ts
@@ -43,8 +43,7 @@ export const OrganizationsSchema = z.object({
rootOrgId: z.string().uuid().nullable().optional(),
blockDuplicateSecretSyncDestinations: z.boolean().default(false),
secretShareBrandConfig: z.unknown().nullable().optional(),
- defaultCertManagerProjectId: z.string().nullable().optional(),
- defaultPamProjectId: z.string().nullable().optional()
+ defaultCertManagerProjectId: z.string().nullable().optional()
});
export type TOrganizations = z.infer<typeof OrganizationsSchema>;
diff --git a/backend/src/ee/services/pam-instance/pam-project-resolver.ts b/backend/src/ee/services/pam-instance/pam-project-resolver.ts
deleted file mode 100644
index 08a64e13c8..0000000000
--- a/backend/src/ee/services/pam-instance/pam-project-resolver.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import { KeyStorePrefixes, KeyStoreTtls, TKeyStoreFactory } from "@app/keystore/keystore";
-import { withCache } from "@app/lib/cache/with-cache";
-import { BadRequestError } from "@app/lib/errors";
-import { TOrgDALFactory } from "@app/services/org/org-dal";
-
-type TResolverDeps = {
- orgDAL: Pick<TOrgDALFactory, "findById">;
- keyStore: Pick<TKeyStoreFactory, "getItem" | "setItemWithExpiry" | "deleteItem">;
-};
-
-export type TPamProjectResolverFactory = ReturnType<typeof pamProjectResolverFactory>;
-
-export const pamProjectResolverFactory = ({ orgDAL, keyStore }: TResolverDeps) => ({
- resolve: (actorOrgId: string): Promise<string> =>
- withCache({
- keyStore,
- key: KeyStorePrefixes.PamDefaultProject(actorOrgId),
- ttlSeconds: KeyStoreTtls.PamDefaultProjectInSeconds,
- fetcher: async () => {
- const org = await orgDAL.findById(actorOrgId);
- if (!org) {
- throw new BadRequestError({ message: "Organization not found." });
- }
- if (!org.defaultPamProjectId) {
- throw new BadRequestError({
- message: "This organization has no Access Management project. Contact your administrator."
- });
- }
- return org.defaultPamProjectId;
- }
- })
-});
diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.ts
index 7bd6451a27..7c57d7cc33 100644
--- a/backend/src/keystore/keystore.ts
+++ b/backend/src/keystore/keystore.ts
@@ -109,7 +109,6 @@ export const KeyStorePrefixes = {
SecretEtag: (projectId: string, dayStamp: string) => `secret-etag:${projectId}:${dayStamp}` as const,
PamAwsIamAccessKeyId: (sessionId: string) => `pam-aws-iam-access-key-id:${sessionId}` as const,
- PamDefaultProject: (orgId: string) => `pam-default-project:${orgId}` as const,
CertDashboardStats: (projectId: string) => `cert-dashboard-stats:${projectId}` as const,
CertActivityTrend: (projectId: string, range: string) => `cert-activity-trend:${projectId}:${range}` as const,
@@ -155,7 +154,6 @@ export const KeyStoreTtls = {
InvalidatingCacheInSeconds: 1800, // 30 minutes max lock for cache invalidation job
AuditLogMigrationAlertInSeconds: 604800, // 7 days
LicenseCloudPlanInSeconds: 300, // 5 minutes
- PamDefaultProjectInSeconds: 300, // 5 minutes
AiMcpEndpointOAuthFlowInSeconds: 300, // 5 minutes
AiMcpServerOAuthSessionInSeconds: 600, // 10 minutes
DashboardCacheInSeconds: 600, // 10 minutes
diff --git a/backend/src/server/plugins/inject-pam-project-id.ts b/backend/src/server/plugins/inject-pam-project-id.ts
deleted file mode 100644
index 1e40e7688c..0000000000
--- a/backend/src/server/plugins/inject-pam-project-id.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import { FastifyPluginAsync } from "fastify";
-import fp from "fastify-plugin";
-
-const PAM_PREFIX = "/api/v1/pam/";
-
-export const injectPamProjectId: FastifyPluginAsync = fp(async (server) => {
- server.decorateRequest("internalPamProjectId", "");
-
- server.addHook("preValidation", async (req) => {
- if (!req.permission?.orgId) return;
-
- const routePath = req.routeOptions.url ?? "";
- if (!routePath.startsWith(PAM_PREFIX)) return;
-
- req.internalPamProjectId = await server.services.pamProjectResolver.resolve(req.permission.orgId);
- });
-});
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 6cae24e668..338a74e3a5 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -95,7 +95,6 @@ import { licenseDALFactory } from "@app/ee/services/license/license-dal";
import { licenseServiceFactory } from "@app/ee/services/license/license-service";
import { oidcConfigDALFactory } from "@app/ee/services/oidc/oidc-config-dal";
import { oidcConfigServiceFactory } from "@app/ee/services/oidc/oidc-config-service";
-import { pamProjectResolverFactory } from "@app/ee/services/pam-instance/pam-project-resolver";
import { permissionDALFactory } from "@app/ee/services/permission/permission-dal";
import { permissionServiceFactory } from "@app/ee/services/permission/permission-service";
import { pitServiceFactory } from "@app/ee/services/pit/pit-service";
@@ -1483,11 +1482,6 @@ export const registerRoutes = async (
projectDAL
});
- const pamProjectResolver = pamProjectResolverFactory({
- orgDAL,
- keyStore
- });
-
const certManagerInstanceService = certManagerInstanceServiceFactory({
db,
orgDAL,
@@ -3373,7 +3367,6 @@ export const registerRoutes = async (
signerPolicy: signerPolicyService,
pkiApplicationEnrollment: pkiApplicationEnrollmentService,
certManagerProjectResolver,
- pamProjectResolver,
certManagerInstance: certManagerInstanceService,
certManagerExport: certManagerExportService,
certificateAuthorityCrl: certificateAuthorityCrlService,