Skip to content

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

PKI enrollments fix

Carlos Monastyrskiff661e98d964
diff --git a/backend/src/db/migrations/20260504432352_cert-manager-applications.ts b/backend/src/db/migrations/20260504432352_cert-manager-applications.ts
index 9b0484846b..ba07dcb306 100644
--- a/backend/src/db/migrations/20260504432352_cert-manager-applications.ts
+++ b/backend/src/db/migrations/20260504432352_cert-manager-applications.ts
@@ -118,6 +118,23 @@ export async function up(knex: Knex): Promise<void> {
await createOnUpdateTrigger(knex, TableName.PkiApplicationProfile);
}
+ for (const tableName of [
+ TableName.PkiApiEnrollmentConfig,
+ TableName.PkiEstEnrollmentConfig,
+ TableName.PkiAcmeEnrollmentConfig,
+ TableName.PkiScepEnrollmentConfig
+ ] as const) {
+ // eslint-disable-next-line no-await-in-loop
+ if (!(await knex.schema.hasColumn(tableName, "applicationProfileId"))) {
+ // eslint-disable-next-line no-await-in-loop
+ await knex.schema.alterTable(tableName, (t) => {
+ t.uuid("applicationProfileId").nullable();
+ t.foreign("applicationProfileId").references("id").inTable(TableName.PkiApplicationProfile).onDelete("CASCADE");
+ t.index("applicationProfileId");
+ });
+ }
+ }
+
if (!(await knex.schema.hasColumn(TableName.Membership, "scopeResourceType"))) {
await knex.schema.alterTable(TableName.Membership, (t) => {
t.string("scopeResourceType", 32);
@@ -344,6 +361,22 @@ export async function down(knex: Knex): Promise<void> {
});
}
+ for (const tableName of [
+ TableName.PkiApiEnrollmentConfig,
+ TableName.PkiEstEnrollmentConfig,
+ TableName.PkiAcmeEnrollmentConfig,
+ TableName.PkiScepEnrollmentConfig
+ ] as const) {
+ // eslint-disable-next-line no-await-in-loop
+ if (await knex.schema.hasColumn(tableName, "applicationProfileId")) {
+ // eslint-disable-next-line no-await-in-loop
+ await knex.schema.alterTable(tableName, (t) => {
+ t.dropForeign(["applicationProfileId"]);
+ t.dropColumn("applicationProfileId");
+ });
+ }
+ }
+
await dropOnUpdateTrigger(knex, TableName.PkiApplicationProfile);
await knex.schema.dropTableIfExists(TableName.PkiApplicationProfile);
diff --git a/backend/src/db/schemas/pki-acme-enrollment-configs.ts b/backend/src/db/schemas/pki-acme-enrollment-configs.ts
index 0b7b9228b7..f9a2b8659a 100644
--- a/backend/src/db/schemas/pki-acme-enrollment-configs.ts
+++ b/backend/src/db/schemas/pki-acme-enrollment-configs.ts
@@ -15,7 +15,8 @@ export const PkiAcmeEnrollmentConfigsSchema = z.object({
createdAt: z.date(),
updatedAt: z.date(),
skipDnsOwnershipVerification: z.boolean().default(false),
- skipEabBinding: z.boolean().default(false)
+ skipEabBinding: z.boolean().default(false),
+ applicationProfileId: z.string().uuid().nullable().optional()
});
export type TPkiAcmeEnrollmentConfigs = z.infer<typeof PkiAcmeEnrollmentConfigsSchema>;
diff --git a/backend/src/db/schemas/pki-api-enrollment-configs.ts b/backend/src/db/schemas/pki-api-enrollment-configs.ts
index 7a1beccdb8..06b5840272 100644
--- a/backend/src/db/schemas/pki-api-enrollment-configs.ts
+++ b/backend/src/db/schemas/pki-api-enrollment-configs.ts
@@ -12,7 +12,8 @@ export const PkiApiEnrollmentConfigsSchema = z.object({
autoRenew: z.boolean().default(false).nullable().optional(),
renewBeforeDays: z.number().nullable().optional(),
createdAt: z.date(),
- updatedAt: z.date()
+ updatedAt: z.date(),
+ applicationProfileId: z.string().uuid().nullable().optional()
});
export type TPkiApiEnrollmentConfigs = z.infer<typeof PkiApiEnrollmentConfigsSchema>;
diff --git a/backend/src/db/schemas/pki-est-enrollment-configs.ts b/backend/src/db/schemas/pki-est-enrollment-configs.ts
index 4a3b16eeb8..ebb727d2ac 100644
--- a/backend/src/db/schemas/pki-est-enrollment-configs.ts
+++ b/backend/src/db/schemas/pki-est-enrollment-configs.ts
@@ -15,7 +15,8 @@ export const PkiEstEnrollmentConfigsSchema = z.object({
hashedPassphrase: z.string(),
encryptedCaChain: zodBuffer.nullable().optional(),
createdAt: z.date(),
- updatedAt: z.date()
+ updatedAt: z.date(),
+ applicationProfileId: z.string().uuid().nullable().optional()
});
export type TPkiEstEnrollmentConfigs = z.infer<typeof PkiEstEnrollmentConfigsSchema>;
diff --git a/backend/src/db/schemas/pki-scep-enrollment-configs.ts b/backend/src/db/schemas/pki-scep-enrollment-configs.ts
index 616b4ee18b..b6f17edd6c 100644
--- a/backend/src/db/schemas/pki-scep-enrollment-configs.ts
+++ b/backend/src/db/schemas/pki-scep-enrollment-configs.ts
@@ -21,7 +21,8 @@ export const PkiScepEnrollmentConfigsSchema = z.object({
updatedAt: z.date(),
challengeType: z.string().default("static"),
dynamicChallengeExpiryMinutes: z.number().nullable().optional(),
- dynamicChallengeMaxPending: z.number().nullable().optional()
+ dynamicChallengeMaxPending: z.number().nullable().optional(),
+ applicationProfileId: z.string().uuid().nullable().optional()
});
export type TPkiScepEnrollmentConfigs = z.infer<typeof PkiScepEnrollmentConfigsSchema>;
diff --git a/backend/src/server/plugins/block-cert-manager-project-access.ts b/backend/src/server/plugins/block-cert-manager-project-access.ts
index 23d011f7f1..13408d488a 100644
--- a/backend/src/server/plugins/block-cert-manager-project-access.ts
+++ b/backend/src/server/plugins/block-cert-manager-project-access.ts
@@ -5,14 +5,16 @@ import RE2 from "re2";
import { ForbiddenRequestError } from "@app/lib/errors";
const ACCESS_PATH_RE = new RE2("/(memberships|identities|groups|roles)(/|$|\\?)");
+const PROJECT_ROUTE_PREFIX_RE = new RE2("^/api/v[12]/(projects|workspace)/");
export const blockCertManagerProjectAccess: FastifyPluginAsync = fp(async (server) => {
server.addHook("preValidation", async (req) => {
- const projectId = (req.params as { projectId?: string } | null)?.projectId;
+ const params = req.params as { projectId?: string; workspaceId?: string } | null;
+ const projectId = params?.projectId ?? params?.workspaceId;
if (!projectId) return;
const routePath = req.routerPath ?? "";
- if (!routePath.startsWith("/api/v1/projects/")) return;
+ if (!PROJECT_ROUTE_PREFIX_RE.test(routePath)) return;
if (!ACCESS_PATH_RE.test(routePath)) return;
const isCertManager = await server.services.certManagerProjectResolver.isCertManagerProject(projectId);
diff --git a/backend/src/server/routes/v1/index.ts b/backend/src/server/routes/v1/index.ts
index dad0976b81..94ecdf7c3d 100644
--- a/backend/src/server/routes/v1/index.ts
+++ b/backend/src/server/routes/v1/index.ts
@@ -146,6 +146,7 @@ export const registerV1Routes = async (server: FastifyZodProvider) => {
await server.register(
async (projectRouter) => {
+ await projectRouter.register(blockCertManagerProjectAccess);
await projectRouter.register(registerDeprecatedProjectRouter);
await projectRouter.register(registerDeprecatedProjectEnvRouter);
// depreciated completed in use
diff --git a/backend/src/server/routes/v2/index.ts b/backend/src/server/routes/v2/index.ts
index 24ca8c2b50..c861931c7c 100644
--- a/backend/src/server/routes/v2/index.ts
+++ b/backend/src/server/routes/v2/index.ts
@@ -1,3 +1,4 @@
+import { blockCertManagerProjectAccess } from "@app/server/plugins/block-cert-manager-project-access";
import { injectCertManagerProjectId } from "@app/server/plugins/inject-cert-manager-project-id";
import { registerCaRouter } from "./certificate-authority-router";
@@ -48,6 +49,7 @@ export const registerV2Routes = async (server: FastifyZodProvider) => {
// moved to v1/projects
await server.register(
async (projectServer) => {
+ await projectServer.register(blockCertManagerProjectAccess);
await projectServer.register(registerDeprecatedProjectRouter);
await projectServer.register(registerDeprecatedIdentityProjectRouter);
await projectServer.register(registerDeprecatedGroupProjectRouter);
diff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-service.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-service.ts
index c969146b31..5637d43a1b 100644
--- a/backend/src/services/pki-alert-v2/pki-alert-v2-service.ts
+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-service.ts
@@ -225,6 +225,12 @@ export const pkiAlertV2ServiceFactory = ({
actor,
actorOrgId
}: TCreateAlertV2DTO): Promise<TAlertV2Response> => {
+ if (!applicationId) {
+ throw new BadRequestError({
+ message: "Alerts must be created inside an Application. Open the Application's Alerts tab and click Add Alert."
+ });
+ }
+
await $assertCanActOnAlert(ProjectPermissionActions.Create, projectId, applicationId, {
actor,
actorId,
diff --git a/backend/src/services/pki-application/pki-application-dal.ts b/backend/src/services/pki-application/pki-application-dal.ts
index 66f0dcd198..d94d37e23d 100644
--- a/backend/src/services/pki-application/pki-application-dal.ts
+++ b/backend/src/services/pki-application/pki-application-dal.ts
@@ -3,6 +3,7 @@ import { Knex } from "knex";
import { TDbClient } from "@app/db";
import { RESOURCE_SCOPE, ResourceType, TableName } from "@app/db/schemas";
import { DatabaseError } from "@app/lib/errors";
+import { sanitizeSqlLikeString } from "@app/lib/fn/string";
import { ormify } from "@app/lib/knex";
import { TPkiApplicationListItem } from "./pki-application-types";
@@ -80,10 +81,11 @@ export const pkiApplicationDALFactory = (db: TDbClient) => {
.offset(offset);
if (search) {
+ const sanitized = sanitizeSqlLikeString(search);
query = query.where((qb) => {
void qb
- .whereILike(`${TableName.PkiApplication}.name`, `%${search}%`)
- .orWhereILike(`${TableName.PkiApplication}.description`, `%${search}%`);
+ .whereILike(`${TableName.PkiApplication}.name`, `%${sanitized}%`)
+ .orWhereILike(`${TableName.PkiApplication}.description`, `%${sanitized}%`);
});
}
@@ -107,8 +109,9 @@ export const pkiApplicationDALFactory = (db: TDbClient) => {
try {
let query = (tx || db.replicaNode())(TableName.PkiApplication).where({ projectId });
if (search) {
+ const sanitized = sanitizeSqlLikeString(search);
query = query.where((qb) => {
- void qb.whereILike("name", `%${search}%`).orWhereILike("description", `%${search}%`);
+ void qb.whereILike("name", `%${sanitized}%`).orWhereILike("description", `%${sanitized}%`);
});
}
if (applicationIds) {
diff --git a/backend/src/services/pki-application/pki-application-enrollment-service.ts b/backend/src/services/pki-application/pki-application-enrollment-service.ts
index a8b76d459d..e203109b17 100644
--- a/backend/src/services/pki-application/pki-application-enrollment-service.ts
+++ b/backend/src/services/pki-application/pki-application-enrollment-service.ts
@@ -276,7 +276,8 @@ export const pkiApplicationEnrollmentServiceFactory = ({
const created = await apiEnrollmentConfigDAL.create(
{
autoRenew: config.autoRenew ?? false,
- renewBeforeDays: config.renewBeforeDays ?? null
+ renewBeforeDays: config.renewBeforeDays ?? null,
+ applicationProfileId: junction.id
},
tx
);
@@ -382,7 +383,8 @@ export const pkiApplicationEnrollmentServiceFactory = ({
{
disableBootstrapCaValidation: config.disableBootstrapCaValidation ?? false,
hashedPassphrase,
- encryptedCaChain
+ encryptedCaChain,
+ applicationProfileId: junction.id
},
tx
);
@@ -466,7 +468,8 @@ export const pkiApplicationEnrollmentServiceFactory = ({
{
skipDnsOwnershipVerification: config.skipDnsOwnershipVerification ?? false,
skipEabBinding: config.skipEabBinding ?? false,
- encryptedEabSecret
+ encryptedEabSecret,
+ applicationProfileId: junction.id
},
tx
);
@@ -670,7 +673,8 @@ export const pkiApplicationEnrollmentServiceFactory = ({
includeCaCertInResponse: config.includeCaCertInResponse ?? true,
allowCertBasedRenewal: config.allowCertBasedRenewal ?? true,
dynamicChallengeExpiryMinutes,
- dynamicChallengeMaxPending
+ dynamicChallengeMaxPending,
+ applicationProfileId: junction.id
},
tx
);
diff --git a/backend/src/services/pki-application/pki-application-membership-service.ts b/backend/src/services/pki-application/pki-application-membership-service.ts
index 33350bbe66..58fa606338 100644
--- a/backend/src/services/pki-application/pki-application-membership-service.ts
+++ b/backend/src/services/pki-application/pki-application-membership-service.ts
@@ -191,6 +191,24 @@ export const pkiApplicationMembershipServiceFactory = ({
);
const membership = await membershipDAL.transaction(async (tx) => {
+ const existingAppMembershipFilter: Record<string, unknown> = {
+ scope: RESOURCE_SCOPE,
+ scopeProjectId: projectId,
+ scopeResourceType: ResourceType.CertificateApplication,
+ scopeResourceId: applicationId
+ };
+ if (userId) existingAppMembershipFilter.actorUserId = userId;
+ else if (identityId) existingAppMembershipFilter.actorIdentityId = identityId;
+ else if (groupId) existingAppMembershipFilter.actorGroupId = groupId;
+ const existingAppMembership = await membershipDAL.find(existingAppMembershipFilter, { tx });
+ if (existingAppMembership.length > 0) {
+ // eslint-disable-next-line no-nested-ternary
+ const subjectLabel = userId ? "user" : identityId ? "identity" : "group";
+ throw new BadRequestError({
+ message: `This ${subjectLabel} is already a member of this Application.`
+ });
+ }
+
const projectMembershipFilter: Record<string, unknown> = {
scope: AccessScope.Project,
scopeProjectId: projectId