Skip to content

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

Address PR claude comments

Carlos Monastyrski47e8a3184a6e
diff --git a/backend/src/db/migrations/20260504432352_cert-manager-applications.ts b/backend/src/db/migrations/20260504432352_cert-manager-applications.ts
index 5af05c9e0f..7a8edfb5e1 100644
--- a/backend/src/db/migrations/20260504432352_cert-manager-applications.ts
+++ b/backend/src/db/migrations/20260504432352_cert-manager-applications.ts
@@ -222,6 +222,14 @@ export async function up(knex: Knex): Promise<void> {
});
}
+ if (!(await knex.schema.hasColumn(TableName.CertificateRequests, "applicationId"))) {
+ await knex.schema.alterTable(TableName.CertificateRequests, (t) => {
+ t.uuid("applicationId").nullable();
+ t.foreign("applicationId").references("id").inTable(TableName.PkiApplication).onDelete("SET NULL");
+ t.index(["projectId", "applicationId"]);
+ });
+ }
+
if (!(await knex.schema.hasColumn(TableName.CertificateInventoryView, "applicationId"))) {
await knex.schema.alterTable(TableName.CertificateInventoryView, (t) => {
t.uuid("applicationId").nullable();
@@ -244,6 +252,14 @@ export async function up(knex: Knex): Promise<void> {
}
export async function down(knex: Knex): Promise<void> {
+ if (await knex.schema.hasColumn(TableName.CertificateRequests, "applicationId")) {
+ await knex.schema.alterTable(TableName.CertificateRequests, (t) => {
+ t.dropForeign(["applicationId"]);
+ t.dropIndex(["projectId", "applicationId"]);
+ t.dropColumn("applicationId");
+ });
+ }
+
if (await knex.schema.hasColumn(TableName.CertificateInventoryView, "applicationId")) {
await knex.raw(`DROP INDEX IF EXISTS "cert_inv_view_personal_unique"`);
await knex.raw(`DROP INDEX IF EXISTS "cert_inv_view_shared_unique"`);
diff --git a/backend/src/db/schemas/certificate-requests.ts b/backend/src/db/schemas/certificate-requests.ts
index b059afbd54..8a7280f7b3 100644
--- a/backend/src/db/schemas/certificate-requests.ts
+++ b/backend/src/db/schemas/certificate-requests.ts
@@ -39,7 +39,8 @@ export const CertificateRequestsSchema = z.object({
country: z.string().nullable().optional(),
state: z.string().nullable().optional(),
locality: z.string().nullable().optional(),
- encryptedPrivateKey: zodBuffer.nullable().optional()
+ encryptedPrivateKey: zodBuffer.nullable().optional(),
+ applicationId: z.string().uuid().nullable().optional()
});
export type TCertificateRequests = z.infer<typeof CertificateRequestsSchema>;
diff --git a/backend/src/ee/services/pki-acme/pki-acme-service.ts b/backend/src/ee/services/pki-acme/pki-acme-service.ts
index cb9f8dca20..884928dd60 100644
--- a/backend/src/ee/services/pki-acme/pki-acme-service.ts
+++ b/backend/src/ee/services/pki-acme/pki-acme-service.ts
@@ -495,11 +495,11 @@ export const pkiAcmeServiceFactory = ({
body: {
status: "valid",
contact: existingAccount.emails,
- orders: buildUrl(profile.id, `/accounts/${existingAccount.id}/orders`, applicationId)
+ orders: buildUrl(profile.id, `/accounts/${existingAccount.id}/orders`)
},
headers: {
- Location: buildUrl(profile.id, `/accounts/${existingAccount.id}`, applicationId),
- Link: `<${buildUrl(profile.id, "/directory", applicationId)}>;rel="index"`
+ Location: buildUrl(profile.id, `/accounts/${existingAccount.id}`),
+ Link: `<${buildUrl(profile.id, "/directory")}>;rel="index"`
}
};
}
@@ -546,11 +546,11 @@ export const pkiAcmeServiceFactory = ({
body: {
status: "valid",
contact: existingAccount.emails,
- orders: buildUrl(profile.id, `/accounts/${existingAccount.id}/orders`, applicationId)
+ orders: buildUrl(profile.id, `/accounts/${existingAccount.id}/orders`)
},
headers: {
- Location: buildUrl(profile.id, `/accounts/${existingAccount.id}`, applicationId),
- Link: `<${buildUrl(profile.id, "/directory", applicationId)}>;rel="index"`
+ Location: buildUrl(profile.id, `/accounts/${existingAccount.id}`),
+ Link: `<${buildUrl(profile.id, "/directory")}>;rel="index"`
}
};
}
@@ -965,6 +965,7 @@ export const pkiAcmeServiceFactory = ({
projectId: profile.projectId,
caId: ca.id,
profileId: profile.id,
+ applicationId,
commonName: updatedCertificateRequest.commonName ?? "",
keyUsages: updatedCertificateRequest.keyUsages?.map((usage) => usage.toString()) ?? [],
extendedKeyUsages: updatedCertificateRequest.extendedKeyUsages?.map((usage) => usage.toString()) ?? [],
diff --git a/backend/src/ee/services/pki-scep/pki-scep-service.ts b/backend/src/ee/services/pki-scep/pki-scep-service.ts
index 6a10a134f6..f8a64e52b4 100644
--- a/backend/src/ee/services/pki-scep/pki-scep-service.ts
+++ b/backend/src/ee/services/pki-scep/pki-scep-service.ts
@@ -734,6 +734,7 @@ export const pkiScepServiceFactory = ({
projectId: profile.projectId,
caId: profile.caId!,
profileId: profile.id,
+ applicationId,
commonName: certRequest.commonName ?? "",
keyUsages: certRequest.keyUsages?.map((u) => u.toString()) ?? [],
extendedKeyUsages: certRequest.extendedKeyUsages?.map((u) => u.toString()) ?? [],
diff --git a/backend/src/services/certificate-request/certificate-request-dal.ts b/backend/src/services/certificate-request/certificate-request-dal.ts
index d492ea2efc..124575449d 100644
--- a/backend/src/services/certificate-request/certificate-request-dal.ts
+++ b/backend/src/services/certificate-request/certificate-request-dal.ts
@@ -158,10 +158,7 @@ export const certificateRequestDALFactory = (db: TDbClient) => {
}
if (applicationId) {
- query = query.whereIn(
- `${TableName.CertificateRequests}.profileId`,
- (tx || db)(TableName.PkiApplicationProfile).select("profileId").where("applicationId", applicationId)
- );
+ query = query.where(`${TableName.CertificateRequests}.applicationId`, applicationId);
}
if (search) {
@@ -239,10 +236,7 @@ export const certificateRequestDALFactory = (db: TDbClient) => {
}
if (applicationId) {
- query = query.whereIn(
- `${TableName.CertificateRequests}.profileId`,
- (tx || db)(TableName.PkiApplicationProfile).select("profileId").where("applicationId", applicationId)
- );
+ query = query.where(`${TableName.CertificateRequests}.applicationId`, applicationId);
}
if (search) {
@@ -337,10 +331,7 @@ export const certificateRequestDALFactory = (db: TDbClient) => {
}
if (applicationId) {
- query = query.whereIn(
- `${TableName.CertificateRequests}.profileId`,
- (tx || db)(TableName.PkiApplicationProfile).select("profileId").where("applicationId", applicationId)
- );
+ query = query.where(`${TableName.CertificateRequests}.applicationId`, applicationId);
}
query = query
diff --git a/backend/src/services/certificate-request/certificate-request-service.ts b/backend/src/services/certificate-request/certificate-request-service.ts
index 99ba043e9f..b9f6f74420 100644
--- a/backend/src/services/certificate-request/certificate-request-service.ts
+++ b/backend/src/services/certificate-request/certificate-request-service.ts
@@ -45,6 +45,7 @@ const subjectAlternativeNameSchema = z.object({
const certificateRequestDataSchema = z
.object({
profileId: z.string().uuid().optional(),
+ applicationId: z.string().uuid().optional(),
caId: z.string().uuid().optional(),
csr: z.string().min(1).optional(),
commonName: z.string().max(255).optional(),
diff --git a/backend/src/services/certificate-request/certificate-request-types.ts b/backend/src/services/certificate-request/certificate-request-types.ts
index 56cede5235..84e8b17cb0 100644
--- a/backend/src/services/certificate-request/certificate-request-types.ts
+++ b/backend/src/services/certificate-request/certificate-request-types.ts
@@ -12,6 +12,7 @@ export type TSubjectAlternativeName = {
export type TCreateCertificateRequestDTO = TProjectPermission & {
profileId?: string;
+ applicationId?: string;
caId?: string;
csr?: string;
commonName?: string;
diff --git a/backend/src/services/certificate-v3/certificate-v3-service.ts b/backend/src/services/certificate-v3/certificate-v3-service.ts
index ef30116c4b..874cb6003d 100644
--- a/backend/src/services/certificate-v3/certificate-v3-service.ts
+++ b/backend/src/services/certificate-v3/certificate-v3-service.ts
@@ -681,7 +681,7 @@ export const certificateV3ServiceFactory = ({
const junctions = await pkiApplicationProfileDAL.findAllByProfileId(profile.id);
if (explicit) {
- if (junctions.length > 0 && !junctions.some((j) => j.applicationId === explicit)) {
+ if (!junctions.some((j) => j.applicationId === explicit)) {
throw new BadRequestError({
message: "This profile is not attached to the specified Application."
});
@@ -1053,6 +1053,7 @@ export const certificateV3ServiceFactory = ({
projectId: profile.projectId,
tx,
profileId: profile.id,
+ applicationId,
commonName: certificateRequest.commonName,
altNames: certificateRequest.altNames,
keyUsages: convertKeyUsageArrayToLegacy(certificateRequest.keyUsages),
@@ -1258,6 +1259,7 @@ export const certificateV3ServiceFactory = ({
tx,
caId: ca.id,
profileId: profile.id,
+ applicationId,
commonName: certificateRequest.commonName,
altNames: certificateRequest.altNames,
keyUsages: convertKeyUsageArrayToLegacy(certificateRequest.keyUsages),
@@ -1668,6 +1670,7 @@ export const certificateV3ServiceFactory = ({
tx,
caId: ca.id,
profileId: profile.id,
+ applicationId,
csr,
commonName: mappedCertificateRequest.commonName,
altNames: mappedCertificateRequest.subjectAlternativeNames,
@@ -2028,6 +2031,7 @@ export const certificateV3ServiceFactory = ({
projectId: profile.projectId,
caId: ca.id,
profileId: profile.id,
+ applicationId,
commonName: certificateOrder.commonName || "",
keyUsages: convertKeyUsageArrayToLegacy(certificateOrder.keyUsages) || [],
extendedKeyUsages: convertExtendedKeyUsageArrayToLegacy(certificateOrder.extendedKeyUsages) || [],
@@ -2464,6 +2468,7 @@ export const certificateV3ServiceFactory = ({
tx,
caId: ca?.id || originalCert.caId || undefined,
profileId: originalCert.profileId || undefined,
+ applicationId: originalCert.applicationId ?? undefined,
commonName: originalCert.commonName || undefined,
altNames: renewalAltNames,
keyUsages: parseKeyUsages(originalCert.keyUsages),
@@ -2520,6 +2525,7 @@ export const certificateV3ServiceFactory = ({
actorOrgId,
projectId: originalCert.projectId,
profileId: profile?.id,
+ applicationId: originalCert.applicationId ?? undefined,
caId: ca.id,
commonName: originalCert.commonName || undefined,
altNames: structuredAltNames.length > 0 ? structuredAltNames : undefined,
diff --git a/backend/src/services/membership/membership-dal.ts b/backend/src/services/membership/membership-dal.ts
index 03ee6af924..a5c55a5ec7 100644
--- a/backend/src/services/membership/membership-dal.ts
+++ b/backend/src/services/membership/membership-dal.ts
@@ -1,10 +1,58 @@
+import { Knex } from "knex";
+
import { TDbClient } from "@app/db";
-import { TableName } from "@app/db/schemas";
+import { RESOURCE_SCOPE, TableName, TMemberships } from "@app/db/schemas";
+import { DatabaseError } from "@app/lib/errors";
import { ormify } from "@app/lib/knex";
+import { ActorType } from "@app/services/auth/auth-type";
export type TMembershipDALFactory = ReturnType<typeof membershipDALFactory>;
export const membershipDALFactory = (db: TDbClient) => {
const orm = ormify(db, TableName.Membership);
- return orm;
+
+ const findResourceMembershipsForActor = async (
+ {
+ projectId,
+ resourceType,
+ actorType,
+ actorId
+ }: {
+ projectId: string;
+ resourceType: string;
+ actorType: ActorType;
+ actorId: string;
+ },
+ tx?: Knex
+ ): Promise<TMemberships[]> => {
+ try {
+ const conn = tx || db.replicaNode();
+
+ const userGroupSubquery = conn(TableName.UserGroupMembership).where("userId", actorId).select("groupId");
+ const identityGroupSubquery = conn(TableName.IdentityGroupMembership)
+ .where("identityId", actorId)
+ .select("groupId");
+
+ return (await conn(TableName.Membership)
+ .where(`${TableName.Membership}.scope`, RESOURCE_SCOPE)
+ .where(`${TableName.Membership}.scopeProjectId`, projectId)
+ .where(`${TableName.Membership}.scopeResourceType`, resourceType)
+ .where((qb) => {
+ if (actorType === ActorType.USER) {
+ void qb
+ .where(`${TableName.Membership}.actorUserId`, actorId)
+ .orWhereIn(`${TableName.Membership}.actorGroupId`, userGroupSubquery);
+ } else {
+ void qb
+ .where(`${TableName.Membership}.actorIdentityId`, actorId)
+ .orWhereIn(`${TableName.Membership}.actorGroupId`, identityGroupSubquery);
+ }
+ })
+ .select(`${TableName.Membership}.*`)) as TMemberships[];
+ } catch (error) {
+ throw new DatabaseError({ error, name: "Find resource memberships for actor" });
+ }
+ };
+
+ return { ...orm, findResourceMembershipsForActor };
};
diff --git a/backend/src/services/pki-application/pki-application-service.ts b/backend/src/services/pki-application/pki-application-service.ts
index 2795c79332..43c46ebeb2 100644
--- a/backend/src/services/pki-application/pki-application-service.ts
+++ b/backend/src/services/pki-application/pki-application-service.ts
@@ -11,7 +11,6 @@ import {
ResourcePermissionSub
} from "@app/ee/services/permission/resource-permission";
import { BadRequestError, DatabaseError, NotFoundError } from "@app/lib/errors";
-import { ActorType } from "@app/services/auth/auth-type";
import { TMembershipDALFactory } from "../membership/membership-dal";
import { TMembershipRoleDALFactory } from "../membership/membership-role-dal";
@@ -45,7 +44,7 @@ type TPkiApplicationServiceFactoryDep = {
TPkiApplicationProfileDALFactory,
"insertMany" | "delete" | "findByApplicationId" | "findOne" | "findProfilesInProject"
>;
- membershipDAL: Pick<TMembershipDALFactory, "find" | "delete">;
+ membershipDAL: Pick<TMembershipDALFactory, "find" | "delete" | "findResourceMembershipsForActor">;
membershipRoleDAL: Pick<TMembershipRoleDALFactory, "delete">;
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission" | "getResourcePermission">;
};
@@ -235,11 +234,11 @@ export const pkiApplicationServiceFactory = ({
return { applications, total };
}
- const memberships = await membershipDAL.find({
- scope: RESOURCE_SCOPE,
- scopeProjectId: projectId,
- scopeResourceType: ResourceType.CertificateApplication,
- ...(actor === ActorType.USER ? { actorUserId: actorId } : { actorIdentityId: actorId })
+ const memberships = await membershipDAL.findResourceMembershipsForActor({
+ projectId,
+ resourceType: ResourceType.CertificateApplication,
+ actorType: actor,
+ actorId
});
const allowedIds = Array.from(
diff --git a/frontend/src/hooks/api/certificates/queries.tsx b/frontend/src/hooks/api/certificates/queries.tsx
index 2788a0201f..4d38364bb7 100644
--- a/frontend/src/hooks/api/certificates/queries.tsx
+++ b/frontend/src/hooks/api/certificates/queries.tsx
@@ -29,6 +29,7 @@ export const certKeys = {
params.fromDate,
params.toDate,
params.profileIds,
+ params.applicationId,
params.sortBy,
params.sortOrder,
params.metadataFilter