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
Make the certificate authority get cert endpoint public
Carlos Monastyrskia222a01c1e23
diff --git a/backend/src/server/routes/v1/certificate-authority-routers/internal-certificate-authority-router.ts b/backend/src/server/routes/v1/certificate-authority-routers/internal-certificate-authority-router.tsindex 90cc860285..6873253e9a 100644--- a/backend/src/server/routes/v1/certificate-authority-routers/internal-certificate-authority-router.ts+++ b/backend/src/server/routes/v1/certificate-authority-routers/internal-certificate-authority-router.ts@@ -278,7 +278,6 @@ export const registerInternalCertificateAuthorityRouter = async (server: Fastifyconfig: {rateLimit: readLimit},- onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),schema: {hide: false,operationId: "getCaCertificates",@@ -300,24 +299,8 @@ export const registerInternalCertificateAuthorityRouter = async (server: Fastify}},handler: async (req) => {- const { caCerts, ca } = await server.services.internalCertificateAuthority.getCaCerts({- caId: req.params.caId,- actor: req.permission.type,- actorId: req.permission.id,- actorAuthMethod: req.permission.authMethod,- actorOrgId: req.permission.orgId- });-- await server.services.auditLog.createAuditLog({- ...req.auditLogInfo,- projectId: ca.projectId,- event: {- type: EventType.GET_CA_CERTS,- metadata: {- caId: ca.id,- dn: ca.dn- }- }+ const { caCerts } = await server.services.internalCertificateAuthority.getCaCertsPublic({+ caId: req.params.caId});return caCerts;@@ -330,7 +313,6 @@ export const registerInternalCertificateAuthorityRouter = async (server: Fastifyconfig: {rateLimit: readLimit},- onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),schema: {hide: false,operationId: "getCaCertificate",@@ -349,27 +331,11 @@ export const registerInternalCertificateAuthorityRouter = async (server: Fastify}},handler: async (req) => {- const { certificate, certificateChain, serialNumber, certId, ca } =- await server.services.internalCertificateAuthority.getCaCert({- caId: req.params.caId,- actor: req.permission.type,- actorId: req.permission.id,- actorAuthMethod: req.permission.authMethod,- actorOrgId: req.permission.orgId+ const { certificate, certificateChain, serialNumber, certId } =+ await server.services.internalCertificateAuthority.getCaCertPublic({+ caId: req.params.caId});- await server.services.auditLog.createAuditLog({- ...req.auditLogInfo,- projectId: ca.projectId,- event: {- type: EventType.GET_CA_CERT,- metadata: {- caId: ca.id,- dn: ca.dn- }- }- });-return {certificate,certificateChain,@@ -385,7 +351,6 @@ export const registerInternalCertificateAuthorityRouter = async (server: Fastifyconfig: {rateLimit: readLimit},- onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),schema: {hide: false,tags: [ApiDocsTags.PkiCertificateAuthorities],@@ -408,36 +373,11 @@ export const registerInternalCertificateAuthorityRouter = async (server: Fastify}},handler: async (req) => {- const {- certificate,- certificateChain,- serialNumber,- certId,- ca,- notBefore,- notAfter,- maxPathLength,- parentCaId- } = await server.services.internalCertificateAuthority.getCaCertByIdWithAuth({- caId: req.params.caId,- certId: req.params.certId,- actor: req.permission.type,- actorId: req.permission.id,- actorAuthMethod: req.permission.authMethod,- actorOrgId: req.permission.orgId- });-- await server.services.auditLog.createAuditLog({- ...req.auditLogInfo,- projectId: ca.projectId,- event: {- type: EventType.GET_CA_CERT,- metadata: {- caId: ca.id,- dn: ca.dn- }- }- });+ const { certificate, certificateChain, serialNumber, certId, notBefore, notAfter, maxPathLength, parentCaId } =+ await server.services.internalCertificateAuthority.getCaCertByIdPublic({+ caId: req.params.caId,+ certId: req.params.certId+ });const formatRfc3339 = (d?: Date) => (d ? `${d.toISOString().replace(/\.\d{3}Z$/, "Z")}` : undefined);diff --git a/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts b/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.tsindex 31f26e8dd7..4b24a3de2c 100644--- a/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts+++ b/backend/src/services/certificate-authority/internal/internal-certificate-authority-service.ts@@ -1075,6 +1075,37 @@ export const internalCertificateAuthorityServiceFactory = ({};};+ // findByIdWithAssociatedCa throws a low-level schema error for a missing CA, so guard existence+ // up front (findById returns undefined instead of throwing) to fail early with a clean 404.+ const $getCaWithAssociationOrThrow = async (caId: string) => {+ const caExists = await certificateAuthorityDAL.findById(caId);+ if (!caExists) throw new NotFoundError({ message: `CA with ID '${caId}' not found` });++ return certificateAuthorityDAL.findByIdWithAssociatedCa(caId);+ };++ /**+ * Return list of past and current CA certificates for a CA. CA certificates are public trust+ * material (no private keys)+ */+ const getCaCertsPublic = async ({ caId }: { caId: string }) => {+ const ca = await $getCaWithAssociationOrThrow(caId);+ if (!ca.internalCa) throw new NotFoundError({ message: `CA with ID '${caId}' not found` });++ const caCertChains = await getCaCertChains({+ caId,+ certificateAuthorityDAL,+ certificateAuthorityCertDAL,+ projectDAL,+ kmsService+ });++ return {+ ca: expandInternalCa(ca),+ caCerts: caCertChains+ };+ };+/*** Return current certificate and certificate chain for CA*/@@ -1115,6 +1146,33 @@ export const internalCertificateAuthorityServiceFactory = ({};};+ /**+ * Return current certificate and certificate chain for CA.+ * CA certificates are public trust material (no private keys).+ */+ const getCaCertPublic = async ({ caId }: { caId: string }) => {+ const ca = await $getCaWithAssociationOrThrow(caId);+ if (!ca.internalCa) throw new NotFoundError({ message: `CA with ID '${caId}' not found` });+ if (!ca.internalCa.activeCaCertId)+ throw new BadRequestError({ message: "CA does not have a certificate installed" });++ const { caCert, caCertChain, serialNumber } = await getCaCertChain({+ caCertId: ca.internalCa.activeCaCertId,+ certificateAuthorityDAL,+ certificateAuthorityCertDAL,+ projectDAL,+ kmsService+ });++ return {+ certificate: caCert,+ certificateChain: caCertChain,+ serialNumber,+ certId: ca.internalCa.activeCaCertId,+ ca: expandInternalCa(ca)+ };+ };+/*** Return CA certificate object by ID*/@@ -1222,6 +1280,63 @@ export const internalCertificateAuthorityServiceFactory = ({};};+ /**+ * Return a specific CA certificate and chain by ID.+ * CA certificates are public trust material (no private keys).+ */+ const getCaCertByIdPublic = async ({ caId, certId }: { caId: string; certId: string }) => {+ const ca = await $getCaWithAssociationOrThrow(caId);+ if (!ca.internalCa) throw new NotFoundError({ message: `CA with ID '${caId}' not found` });++ const caCert = await certificateAuthorityCertDAL.findOne({+ caId,+ id: certId+ });++ if (!caCert) {+ throw new NotFoundError({ message: `Certificate with ID '${certId}' not found for CA with ID '${caId}'` });+ }++ const {+ caCert: certificate,+ caCertChain: certificateChain,+ serialNumber+ } = await getCaCertChain({+ caCertId: certId,+ certificateAuthorityDAL,+ certificateAuthorityCertDAL,+ projectDAL,+ kmsService+ });++ let notBefore: Date | undefined;+ let notAfter: Date | undefined;+ let maxPathLength: number | undefined;+ try {+ const certObj = new x509.X509Certificate(certificate);+ notBefore = certObj.notBefore;+ notAfter = certObj.notAfter;+ const basicConstraintsExt = certObj.getExtension(x509.BasicConstraintsExtension);+ if (basicConstraintsExt && basicConstraintsExt.ca) {+ maxPathLength = basicConstraintsExt.pathLength ?? -1;+ }+ } catch {+ // ignore parse errors and return undefined values+ }++ return {+ certificate,+ certificateChain,+ serialNumber,+ certId,+ notBefore,+ notAfter,+ maxPathLength,+ parentCaId: ca.internalCa.parentCaId ?? undefined,+ ca: expandInternalCa(ca)+ };+ };+/*** Issue certificate to be imported back in for intermediate CA*/@@ -2750,9 +2865,12 @@ export const internalCertificateAuthorityServiceFactory = ({getCaCsr,renewCaCert,getCaCerts,+ getCaCertsPublic,getCaCert,+ getCaCertPublic,getCaCertById,getCaCertByIdWithAuth,+ getCaCertByIdPublic,signIntermediate,importCertToCa,generateIntermediateCaCertificate,