Skip to content

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

Minor PKI improvements

Carlos Monastyrski58bc9383c077
diff --git a/backend/src/ee/routes/v1/pki-discovery-router.ts b/backend/src/ee/routes/v1/pki-discovery-router.ts
index 7695e8070d..d0ff39b673 100644
--- a/backend/src/ee/routes/v1/pki-discovery-router.ts
+++ b/backend/src/ee/routes/v1/pki-discovery-router.ts
@@ -20,8 +20,8 @@ import { AuthMode } from "@app/services/auth/auth-type";
const NetworkTargetConfigSchema = z
.object({
- ipRanges: z.array(z.string()).optional(),
- domains: z.array(z.string()).optional(),
+ ipRanges: z.array(z.string().max(64)).optional(),
+ domains: z.array(z.string().max(253)).optional(),
ports: z.string().default(DEFAULT_TLS_PORTS)
})
.refine((data) => (data.ipRanges && data.ipRanges.length > 0) || (data.domains && data.domains.length > 0), {
diff --git a/backend/src/ee/services/pki-acme/pki-acme-account-dal.ts b/backend/src/ee/services/pki-acme/pki-acme-account-dal.ts
index b2cdad9ac0..3429a5d5d1 100644
--- a/backend/src/ee/services/pki-acme/pki-acme-account-dal.ts
+++ b/backend/src/ee/services/pki-acme/pki-acme-account-dal.ts
@@ -24,10 +24,17 @@ export const pkiAcmeAccountDALFactory = (db: TDbClient) => {
profileId: string,
alg: string,
publicKeyThumbprint: string,
+ applicationProfileId: string | null,
tx?: Knex
) => {
try {
- const account = await (tx || db)(TableName.PkiAcmeAccount).where({ profileId, alg, publicKeyThumbprint }).first();
+ let query = (tx || db)(TableName.PkiAcmeAccount).where({ profileId, alg, publicKeyThumbprint });
+ if (applicationProfileId === null) {
+ query = query.whereNull("applicationProfileId");
+ } else {
+ query = query.where({ applicationProfileId });
+ }
+ const account = await query.first();
return account || null;
} catch (error) {
throw new DatabaseError({ error, name: "Find PKI ACME account by profile id, public key thumbprint and alg" });
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 105cfbd1ee..cb9f8dca20 100644
--- a/backend/src/ee/services/pki-acme/pki-acme-service.ts
+++ b/backend/src/ee/services/pki-acme/pki-acme-service.ts
@@ -479,10 +479,12 @@ export const pkiAcmeServiceFactory = ({
const effectiveAcmeConfig = applicationId ? junctionAcmeConfig : (profile.acmeConfig ?? null);
const expectedEabKid = applicationId ? junctionAcmeConfig?.id : profile.id;
+ const accountApplicationProfileId = junctionRow?.id ?? null;
const existingAccount: TPkiAcmeAccounts | null = await acmeAccountDAL.findByProfileIdAndPublicKeyThumbprintAndAlg(
profileId,
alg,
- publicKeyThumbprint
+ publicKeyThumbprint,
+ accountApplicationProfileId
);
if (onlyReturnExisting) {
if (!existingAccount) {
@@ -608,13 +610,9 @@ export const pkiAcmeServiceFactory = ({
}
}
- const applicationProfileId = applicationId
- ? ((await pkiApplicationProfileDAL.findOne(applicationId, profile.id))?.id ?? null)
- : null;
-
const newAccount = await acmeAccountDAL.create({
profileId: profile.id,
- applicationProfileId,
+ applicationProfileId: accountApplicationProfileId,
alg,
publicKey: jwk,
publicKeyThumbprint,
diff --git a/backend/src/services/certificate-authority/certificate-issuance-queue.ts b/backend/src/services/certificate-authority/certificate-issuance-queue.ts
index 0ea573d2be..4bc3bd1180 100644
--- a/backend/src/services/certificate-authority/certificate-issuance-queue.ts
+++ b/backend/src/services/certificate-authority/certificate-issuance-queue.ts
@@ -102,6 +102,7 @@ export type TIssueCertificateFromProfileJobData = {
country?: string;
state?: string;
locality?: string;
+ applicationId?: string;
};
type TCertificateIssuanceQueueFactoryDep = {
@@ -126,7 +127,7 @@ type TCertificateIssuanceQueueFactoryDep = {
TCertificateRequestServiceFactory,
"attachCertificateToRequest" | "updateCertificateRequestStatus"
>;
- certificateRequestDAL?: Pick<TCertificateRequestDALFactory, "updateById">;
+ certificateRequestDAL?: Pick<TCertificateRequestDALFactory, "updateById" | "findById">;
resourceMetadataDAL: Pick<TResourceMetadataDALFactory, "find" | "insertMany">;
pkiAlertV2Queue?: Pick<TPkiAlertV2QueueServiceFactory, "queueCertificateEvent">;
gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;
@@ -770,11 +771,31 @@ export const certificateIssuanceQueueFactory = ({
`Successfully processed certificate issuance job with [certificateId=${certificateId}] [caId=${caId}]`
);
+ let scopedApplicationId: string | null = data.applicationId ?? null;
+ try {
+ if (!scopedApplicationId && isRenewal && originalCertificateId) {
+ const orig = await certificateDAL.findById(originalCertificateId);
+ scopedApplicationId = orig?.applicationId ?? null;
+ }
+ if (scopedApplicationId && certificateRequestId && certificateRequestDAL) {
+ const req = await certificateRequestDAL.findById(certificateRequestId);
+ if (req?.certificateId) {
+ await certificateDAL.updateById(req.certificateId, { applicationId: scopedApplicationId });
+ }
+ }
+ } catch (stampErr) {
+ logger.warn(
+ stampErr,
+ `Failed to stamp applicationId on async-issued certificate [certificateRequestId=${certificateRequestId}]`
+ );
+ }
+
try {
await pkiAlertV2Queue?.queueCertificateEvent({
certificateId,
projectId: ca.projectId,
- eventType: isRenewal ? PkiAlertEventType.RENEWAL : PkiAlertEventType.ISSUANCE
+ eventType: isRenewal ? PkiAlertEventType.RENEWAL : PkiAlertEventType.ISSUANCE,
+ applicationId: scopedApplicationId
});
} catch {
logger.debug("Failed to queue PKI alert event for async certificate issuance");
diff --git a/backend/src/services/certificate-v3/certificate-v3-service.ts b/backend/src/services/certificate-v3/certificate-v3-service.ts
index 34f64bf405..223c80e0c6 100644
--- a/backend/src/services/certificate-v3/certificate-v3-service.ts
+++ b/backend/src/services/certificate-v3/certificate-v3-service.ts
@@ -1326,7 +1326,8 @@ export const certificateV3ServiceFactory = ({
await pkiAlertV2Queue?.queueCertificateEvent({
certificateId: cert.id,
projectId: profile.projectId,
- eventType: PkiAlertEventType.ISSUANCE
+ eventType: PkiAlertEventType.ISSUANCE,
+ applicationId: applicationId ?? null
});
} catch {
logger.debug("Failed to queue PKI issuance alert event");
@@ -1715,7 +1716,8 @@ export const certificateV3ServiceFactory = ({
await pkiAlertV2Queue?.queueCertificateEvent({
certificateId: cert.id,
projectId: profile.projectId,
- eventType: PkiAlertEventType.ISSUANCE
+ eventType: PkiAlertEventType.ISSUANCE,
+ applicationId: applicationId ?? null
});
} catch {
logger.debug("Failed to queue PKI issuance alert event");
@@ -2075,7 +2077,8 @@ export const certificateV3ServiceFactory = ({
organizationalUnit: certificateRequest.organizationalUnit,
country: certificateRequest.country,
state: certificateRequest.state,
- locality: certificateRequest.locality
+ locality: certificateRequest.locality,
+ ...(applicationId && { applicationId })
});
return {
@@ -2412,6 +2415,7 @@ export const certificateV3ServiceFactory = ({
profileId: string | null;
renewedFromCertificateId: string;
renewBeforeDays?: number;
+ applicationId?: string | null;
} = {
profileId: originalCert.profileId || null,
renewedFromCertificateId: originalCert.id
@@ -2421,10 +2425,22 @@ export const certificateV3ServiceFactory = ({
renewalUpdateData.renewBeforeDays = finalRenewBeforeDays;
}
+ if (originalCert.applicationId) {
+ renewalUpdateData.applicationId = originalCert.applicationId;
+ }
+
await certificateDAL.updateById(newCert.id, renewalUpdateData, tx);
- } else if (finalRenewBeforeDays !== undefined) {
- // For self-signed certificates, just update the renewBeforeDays if needed
- await certificateDAL.updateById(newCert.id, { renewBeforeDays: finalRenewBeforeDays }, tx);
+ } else {
+ const selfSignedUpdate: { renewBeforeDays?: number; applicationId?: string | null } = {};
+ if (finalRenewBeforeDays !== undefined) {
+ selfSignedUpdate.renewBeforeDays = finalRenewBeforeDays;
+ }
+ if (originalCert.applicationId) {
+ selfSignedUpdate.applicationId = originalCert.applicationId;
+ }
+ if (Object.keys(selfSignedUpdate).length > 0) {
+ await certificateDAL.updateById(newCert.id, selfSignedUpdate, tx);
+ }
}
await certificateDAL.updateById(
@@ -2549,7 +2565,8 @@ export const certificateV3ServiceFactory = ({
locality: originalCert.subjectLocality || undefined,
isRenewal: true,
originalCertificateId: certificateId,
- certificateRequestId: certificateRequest.id
+ certificateRequestId: certificateRequest.id,
+ ...(originalCert.applicationId && { applicationId: originalCert.applicationId })
});
return {
@@ -2586,7 +2603,8 @@ export const certificateV3ServiceFactory = ({
await pkiAlertV2Queue?.queueCertificateEvent({
certificateId: renewalResult.newCert.id,
projectId: renewalResult.originalCert.projectId,
- eventType: PkiAlertEventType.RENEWAL
+ eventType: PkiAlertEventType.RENEWAL,
+ applicationId: renewalResult.originalCert.applicationId ?? null
});
} catch {
logger.debug("Failed to queue PKI renewal alert event");
diff --git a/backend/src/services/certificate/certificate-service.ts b/backend/src/services/certificate/certificate-service.ts
index 9df271deb2..c13be1c065 100644
--- a/backend/src/services/certificate/certificate-service.ts
+++ b/backend/src/services/certificate/certificate-service.ts
@@ -439,7 +439,8 @@ export const certificateServiceFactory = ({
await pkiAlertV2Queue?.queueCertificateEvent({
certificateId: cert.id,
projectId: ca.projectId,
- eventType: PkiAlertEventType.REVOCATION
+ eventType: PkiAlertEventType.REVOCATION,
+ applicationId: cert.applicationId ?? null
});
} catch {
logger.debug("Failed to queue PKI revocation alert event");
diff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-queue.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-queue.ts
index 0c0f9b3591..169a72cfca 100644
--- a/backend/src/services/pki-alert-v2/pki-alert-v2-queue.ts
+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-queue.ts
@@ -201,8 +201,9 @@ export const pkiAlertV2QueueServiceFactory = ({
certificateId: string;
projectId: string;
eventType: PkiAlertEventType;
+ applicationId?: string | null;
}) => {
- const { certificateId, projectId, eventType } = payload;
+ const { certificateId, projectId, eventType, applicationId } = payload;
const alerts = await pkiAlertV2DAL.findByProjectId(projectId, {
eventType,
@@ -211,7 +212,11 @@ export const pkiAlertV2QueueServiceFactory = ({
if (alerts.length === 0) return;
- for (const alert of alerts) {
+ const matchingAlerts = alerts.filter((alert) => !alert.applicationId || alert.applicationId === applicationId);
+
+ if (matchingAlerts.length === 0) return;
+
+ for (const alert of matchingAlerts) {
try {
await pkiAlertV2Service.sendEventNotifications(alert.id, [certificateId], eventType);
logger.info(
@@ -228,6 +233,7 @@ export const pkiAlertV2QueueServiceFactory = ({
certificateId: string;
projectId: string;
eventType: PkiAlertEventType;
+ applicationId?: string | null;
}) => {
await queueService.queue(QueueName.PkiAlertV2Event, QueueJobs.PkiAlertV2ProcessEvent, payload, {
jobId: `pki-alert-event-${payload.projectId}-${payload.certificateId}-${payload.eventType}`,
diff --git a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/AddApplicationMemberModal.tsx b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/AddApplicationMemberModal.tsx
index c628545bb6..534ee55383 100644
--- a/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/AddApplicationMemberModal.tsx
+++ b/frontend/src/pages/cert-manager/ApplicationDetailsByIDPage/components/AddApplicationMemberModal.tsx
@@ -192,7 +192,7 @@ export const AddApplicationMemberModal = ({
<DialogHeader>
<DialogTitle>Add Member</DialogTitle>
<DialogDescription>
- Grant access to this Application. Only project members are eligible.
+ Grant access to this Application. Only organization members are eligible.
</DialogDescription>
</DialogHeader>