Skip to content

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

Address PR comments

Carlos Monastyrski662b50685995
diff --git a/backend/src/services/certificate-authority/aws-pca/aws-pca-certificate-authority-fns.ts b/backend/src/services/certificate-authority/aws-pca/aws-pca-certificate-authority-fns.ts
index b0163c4f96..1da4430703 100644
--- a/backend/src/services/certificate-authority/aws-pca/aws-pca-certificate-authority-fns.ts
+++ b/backend/src/services/certificate-authority/aws-pca/aws-pca-certificate-authority-fns.ts
@@ -48,7 +48,7 @@ import { getProjectKmsCertificateKeyId } from "@app/services/project/project-fns
import { TCertificateAuthorityDALFactory } from "../certificate-authority-dal";
import { CaStatus, CaType } from "../certificate-authority-enums";
-import { keyAlgorithmToAlgCfg } from "../certificate-authority-fns";
+import { extractDnParts, keyAlgorithmToAlgCfg } from "../certificate-authority-fns";
import { TExternalCertificateAuthorityDALFactory } from "../external-certificate-authority-dal";
import {
API_CSR_PASSTHROUGH_TEMPLATE_ARN,
@@ -132,6 +132,39 @@ const calculateFinalRenewBeforeDays = (
return undefined;
};
+export const buildAwsPcaApiPassthroughSubject = ({
+ csr,
+ csrPem,
+ commonName,
+ organization,
+ organizationalUnit,
+ country,
+ state,
+ locality
+}: {
+ csr?: string;
+ csrPem: string;
+ commonName?: string;
+ organization?: string;
+ organizationalUnit?: string;
+ country?: string;
+ state?: string;
+ locality?: string;
+}): ASN1Subject => {
+ const enforcedSubject = csr
+ ? extractDnParts(new x509.Pkcs10CertificateRequest(csrPem).subjectName)
+ : { commonName, organization, ou: organizationalUnit, country, province: state, locality };
+
+ const subject: ASN1Subject = {};
+ if (enforcedSubject.commonName) subject.CommonName = enforcedSubject.commonName;
+ if (enforcedSubject.organization) subject.Organization = enforcedSubject.organization;
+ if (enforcedSubject.ou) subject.OrganizationalUnit = enforcedSubject.ou;
+ if (enforcedSubject.country) subject.Country = enforcedSubject.country;
+ if (enforcedSubject.province) subject.State = enforcedSubject.province;
+ if (enforcedSubject.locality) subject.Locality = enforcedSubject.locality;
+ return subject;
+};
+
type TAwsPcaCertificateAuthorityFnsDeps = {
appConnectionDAL: Pick<TAppConnectionDALFactory, "findById" | "updateById">;
appConnectionService: Pick<TAppConnectionServiceFactory, "validateAppConnectionUsageById">;
@@ -681,13 +714,16 @@ export const AwsPcaCertificateAuthorityFns = ({
}
};
- const apiPassthroughSubject: ASN1Subject = {};
- if (commonName) apiPassthroughSubject.CommonName = commonName;
- if (organization) apiPassthroughSubject.Organization = organization;
- if (organizationalUnit) apiPassthroughSubject.OrganizationalUnit = organizationalUnit;
- if (country) apiPassthroughSubject.Country = country;
- if (state) apiPassthroughSubject.State = state;
- if (locality) apiPassthroughSubject.Locality = locality;
+ const apiPassthroughSubject = buildAwsPcaApiPassthroughSubject({
+ csr,
+ csrPem,
+ commonName,
+ organization,
+ organizationalUnit,
+ country,
+ state,
+ locality
+ });
const apiPassthrough: ApiPassthrough = {};
if (Object.keys(apiPassthroughSubject).length > 0) {
diff --git a/backend/src/services/certificate-v3/certificate-approval-fns.ts b/backend/src/services/certificate-v3/certificate-approval-fns.ts
index b89a70fa16..6bf92abdf8 100644
--- a/backend/src/services/certificate-v3/certificate-approval-fns.ts
+++ b/backend/src/services/certificate-v3/certificate-approval-fns.ts
@@ -1,5 +1,4 @@
import { ForbiddenError, subject } from "@casl/ability";
-import * as x509 from "@peculiar/x509";
import { randomUUID } from "crypto";
import { ActionProjectType } from "@app/db/schemas";
@@ -20,8 +19,7 @@ import { TCertificateAuthorityDALFactory } from "@app/services/certificate-autho
import { CaType } from "@app/services/certificate-authority/certificate-authority-enums";
import {
assertCaInProfileProject,
- createDistinguishedName,
- extractDnParts
+ createDistinguishedName
} from "@app/services/certificate-authority/certificate-authority-fns";
import { TCertificateIssuanceQueueFactory } from "@app/services/certificate-authority/certificate-issuance-queue";
import { validateGoDaddyIssuanceInputs } from "@app/services/certificate-authority/godaddy/godaddy-certificate-authority-validators";
@@ -450,15 +448,13 @@ export const certificateApprovalServiceFactory = (
});
}
- const csrSubjectParsed = extractDnParts(new x509.Pkcs10CertificateRequest(csr || "").subjectName);
const subjectOverride = createDistinguishedName({
- ...csrSubjectParsed,
- commonName: csrSubjectParsed.commonName ?? reconstructedRequest.commonName,
- organization: csrSubjectParsed.organization ?? reconstructedRequest.organization,
- ou: csrSubjectParsed.ou ?? reconstructedRequest.organizationalUnit,
- country: csrSubjectParsed.country ?? reconstructedRequest.country,
- province: csrSubjectParsed.province ?? reconstructedRequest.state,
- locality: csrSubjectParsed.locality ?? reconstructedRequest.locality
+ commonName: reconstructedRequest.commonName,
+ organization: reconstructedRequest.organization,
+ ou: reconstructedRequest.organizationalUnit,
+ country: reconstructedRequest.country,
+ province: reconstructedRequest.state,
+ locality: reconstructedRequest.locality
});
const { certificate, certificateChain, issuingCaCertificate, serialNumber, cert } =