Skip to content

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

Address PR comments

Carlos Monastyrskib089d5cecb58
diff --git a/backend/src/ee/services/permission/default-roles.ts b/backend/src/ee/services/permission/default-roles.ts
index 561cb3bb55..691d80634e 100644
--- a/backend/src/ee/services/permission/default-roles.ts
+++ b/backend/src/ee/services/permission/default-roles.ts
@@ -76,7 +76,7 @@ const buildAdminPermissionRules = () => {
ProjectPermissionCertificateAuthorityActions.Create,
ProjectPermissionCertificateAuthorityActions.Edit,
ProjectPermissionCertificateAuthorityActions.Delete,
- ProjectPermissionCertificateAuthorityActions.Renew,
+ ProjectPermissionCertificateAuthorityActions.Issue,
ProjectPermissionCertificateAuthorityActions.SignIntermediate
],
ProjectPermissionSub.CertificateAuthorities
diff --git a/backend/src/ee/services/permission/project-permission.ts b/backend/src/ee/services/permission/project-permission.ts
index 85efd19aaa..fbb96d9fd6 100644
--- a/backend/src/ee/services/permission/project-permission.ts
+++ b/backend/src/ee/services/permission/project-permission.ts
@@ -28,7 +28,7 @@ export enum ProjectPermissionCertificateAuthorityActions {
Create = "create",
Edit = "edit",
Delete = "delete",
- Renew = "renew",
+ Issue = "issue",
SignIntermediate = "sign-intermediate"
}
diff --git a/backend/src/server/routes/v1/certificate-authority-router.ts b/backend/src/server/routes/v1/certificate-authority-router.ts
index 2917270efe..ced97d9547 100644
--- a/backend/src/server/routes/v1/certificate-authority-router.ts
+++ b/backend/src/server/routes/v1/certificate-authority-router.ts
@@ -71,6 +71,18 @@ export const registerCaRouter = async (server: FastifyZodProvider) => {
"At least one of the fields commonName, organization, ou, country, province, or locality must be non-empty",
path: []
}
+ )
+ .refine(
+ (data) => {
+ if (data.notBefore !== undefined && data.notAfter === undefined) {
+ return false;
+ }
+ return true;
+ },
+ {
+ message: "NotBefore is set but notAfter date is missing",
+ path: []
+ }
),
response: {
200: z.object({
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.ts
index 8d50199fcb..c691c4266c 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
@@ -514,7 +514,7 @@ export const internalCertificateAuthorityServiceFactory = ({
});
ForbiddenError.from(permission).throwUnlessCan(
- ProjectPermissionCertificateAuthorityActions.Renew,
+ ProjectPermissionCertificateAuthorityActions.Issue,
subject(ProjectPermissionSub.CertificateAuthorities, { name: ca.name })
);
@@ -894,34 +894,29 @@ export const internalCertificateAuthorityServiceFactory = ({
/**
* Issue certificate to be imported back in for intermediate CA
*/
- const signIntermediate = async ({
- caId,
- actorId,
- actorAuthMethod,
- actor,
- actorOrgId,
- csr,
- notBefore,
- notAfter,
- maxPathLength
- }: TSignIntermediateDTO) => {
+ const signIntermediate = async (params: TSignIntermediateDTO) => {
+ const { caId, csr, notBefore, notAfter, maxPathLength } = params;
+ const isInternal = "isInternal" in params && params.isInternal === true;
const appCfg = getConfig();
const ca = await certificateAuthorityDAL.findByIdWithAssociatedCa(caId);
if (!ca.internalCa) throw new NotFoundError({ message: "CA not found" });
- const { permission } = await permissionService.getProjectPermission({
- actor,
- actorId,
- projectId: ca.projectId,
- actorAuthMethod,
- actorOrgId,
- actionProjectType: ActionProjectType.CertificateManager
- });
+ if (!isInternal) {
+ const { actor, actorId, actorAuthMethod, actorOrgId } = params;
+ const { permission } = await permissionService.getProjectPermission({
+ actor,
+ actorId,
+ projectId: ca.projectId,
+ actorAuthMethod,
+ actorOrgId,
+ actionProjectType: ActionProjectType.CertificateManager
+ });
- ForbiddenError.from(permission).throwUnlessCan(
- ProjectPermissionCertificateAuthorityActions.SignIntermediate,
- subject(ProjectPermissionSub.CertificateAuthorities, { name: ca.name })
- );
+ ForbiddenError.from(permission).throwUnlessCan(
+ ProjectPermissionCertificateAuthorityActions.SignIntermediate,
+ subject(ProjectPermissionSub.CertificateAuthorities, { name: ca.name })
+ );
+ }
if (ca.status === CaStatus.DISABLED) throw new BadRequestError({ message: "CA is disabled" });
if (!ca.internalCa.activeCaCertId)
@@ -1045,32 +1040,29 @@ export const internalCertificateAuthorityServiceFactory = ({
* Note: Can be used to import an external certificate and certificate chain
* to be into an installed or uninstalled CA.
*/
- const importCertToCa = async ({
- caId,
- actorId,
- actorAuthMethod,
- actor,
- actorOrgId,
- certificate,
- certificateChain,
- parentCaId
- }: TImportCertToCaDTO) => {
+ const importCertToCa = async (params: TImportCertToCaDTO) => {
+ const { caId, certificate, certificateChain } = params;
+ const parentCaId = "parentCaId" in params ? params.parentCaId : undefined;
+ const isInternal = "isInternal" in params && params.isInternal === true;
const ca = await certificateAuthorityDAL.findByIdWithAssociatedCa(caId);
if (!ca.internalCa) throw new NotFoundError({ message: `CA with ID '${caId}' not found` });
- const { permission } = await permissionService.getProjectPermission({
- actor,
- actorId,
- projectId: ca.projectId,
- actorAuthMethod,
- actorOrgId,
- actionProjectType: ActionProjectType.CertificateManager
- });
+ if (!isInternal) {
+ const { actor, actorId, actorAuthMethod, actorOrgId } = params;
+ const { permission } = await permissionService.getProjectPermission({
+ actor,
+ actorId,
+ projectId: ca.projectId,
+ actorAuthMethod,
+ actorOrgId,
+ actionProjectType: ActionProjectType.CertificateManager
+ });
- ForbiddenError.from(permission).throwUnlessCan(
- ProjectPermissionCertificateAuthorityActions.Create,
- subject(ProjectPermissionSub.CertificateAuthorities, { name: ca.name })
- );
+ ForbiddenError.from(permission).throwUnlessCan(
+ ProjectPermissionCertificateAuthorityActions.Create,
+ subject(ProjectPermissionSub.CertificateAuthorities, { name: ca.name })
+ );
+ }
if (ca.internalCa.parentCaId && (!parentCaId || parentCaId !== ca.internalCa.parentCaId)) {
/**
@@ -1222,12 +1214,12 @@ export const internalCertificateAuthorityServiceFactory = ({
});
ForbiddenError.from(permission).throwUnlessCan(
- ProjectPermissionCertificateAuthorityActions.Create,
+ ProjectPermissionCertificateAuthorityActions.Issue,
subject(ProjectPermissionSub.CertificateAuthorities, { name: intermediateCa.name })
);
ForbiddenError.from(permission).throwUnlessCan(
- ProjectPermissionCertificateAuthorityActions.Create,
+ ProjectPermissionCertificateAuthorityActions.SignIntermediate,
subject(ProjectPermissionSub.CertificateAuthorities, { name: parentCa.name })
);
@@ -1288,25 +1280,19 @@ export const internalCertificateAuthorityServiceFactory = ({
const csrPem = csrObj.toString("pem");
const signedResult = await signIntermediate({
+ isInternal: true as const,
caId: parentCaId,
csr: csrPem,
notBefore,
notAfter,
- maxPathLength: maxPathLength ?? -1,
- actorId,
- actorAuthMethod,
- actor,
- actorOrgId
+ maxPathLength: maxPathLength ?? -1
});
await importCertToCa({
+ isInternal: true as const,
caId,
certificate: signedResult.certificate,
certificateChain: signedResult.certificateChain,
- actorId,
- actorAuthMethod,
- actor,
- actorOrgId,
parentCaId
});
@@ -2175,15 +2161,72 @@ export const internalCertificateAuthorityServiceFactory = ({
actionProjectType: ActionProjectType.CertificateManager
});
ForbiddenError.from(permission).throwUnlessCan(
- ProjectPermissionCertificateAuthorityActions.Edit,
+ ProjectPermissionCertificateAuthorityActions.Issue,
subject(ProjectPermissionSub.CertificateAuthorities, { name: ca.name })
);
- return certificateAuthorityDAL.transaction(async (tx) => {
- const notBeforeDate = new Date(notBefore);
- const notAfterDate = new Date(notAfter);
- const serialNumber = createSerialNumber();
+ const notBeforeDate = new Date(notBefore);
+ const notAfterDate = new Date(notAfter);
+ const serialNumber = createSerialNumber();
+
+ const certificateManagerKmsId = await getProjectKmsCertificateKeyId({
+ projectId: ca.projectId,
+ projectDAL,
+ kmsService
+ });
+
+ const kmsEncryptor = await kmsService.encryptWithKmsKey({
+ kmsId: certificateManagerKmsId
+ });
+
+ const caSecret = await certificateAuthoritySecretDAL.findOne({ caId });
+ if (!caSecret) throw new NotFoundError({ message: "CA secret not found" });
+
+ const kmsDecryptor = await kmsService.decryptWithKmsKey({
+ kmsId: certificateManagerKmsId
+ });
+ const privateKeyBlob = await kmsDecryptor({ cipherTextBlob: caSecret.encryptedPrivateKey });
+ if (!ca.internalCa) throw new BadRequestError({ message: "CA internal configuration not found" });
+
+ const alg = keyAlgorithmToAlgCfg(ca.internalCa.keyAlgorithm as CertKeyAlgorithm);
+
+ const actualPrivateKey = await crypto.nativeCrypto.subtle.importKey("pkcs8", privateKeyBlob, alg, true, ["sign"]);
+
+ const skObj = crypto.nativeCrypto.createPrivateKey({ key: privateKeyBlob, format: "der", type: "pkcs8" });
+ const pkObj = crypto.nativeCrypto.createPublicKey(skObj);
+ const publicKeyBuffer = pkObj.export({ format: "der", type: "spki" });
+ const actualPublicKey = await crypto.nativeCrypto.subtle.importKey("spki", publicKeyBuffer, alg, true, ["verify"]);
+
+ const cert = await x509.X509CertificateGenerator.createSelfSigned({
+ name: ca.internalCa.dn,
+ serialNumber,
+ notBefore: notBeforeDate,
+ notAfter: notAfterDate,
+ signingAlgorithm: alg,
+ keys: { privateKey: actualPrivateKey, publicKey: actualPublicKey },
+ extensions: [
+ new x509.BasicConstraintsExtension(
+ true,
+ maxPathLength === -1 || maxPathLength === null || maxPathLength === undefined
+ ? undefined
+ : Number(maxPathLength),
+ true
+ ),
+ // eslint-disable-next-line no-bitwise
+ new x509.KeyUsagesExtension(x509.KeyUsageFlags.keyCertSign | x509.KeyUsageFlags.cRLSign, true),
+ await x509.SubjectKeyIdentifierExtension.create(actualPublicKey)
+ ]
+ });
+
+ const { cipherTextBlob: encryptedCertificate } = await kmsEncryptor({
+ plainText: Buffer.from(new Uint8Array(cert.rawData))
+ });
+
+ const { cipherTextBlob: encryptedCertificateChain } = await kmsEncryptor({
+ plainText: Buffer.alloc(0)
+ });
+ return certificateAuthorityDAL.transaction(async (tx) => {
await internalCertificateAuthorityDAL.updateById(
ca.internalCa!.id,
{
@@ -2195,66 +2238,8 @@ export const internalCertificateAuthorityServiceFactory = ({
tx
);
- const certificateManagerKmsId = await getProjectKmsCertificateKeyId({
- projectId: ca.projectId,
- projectDAL,
- kmsService
- });
- const kmsEncryptor = await kmsService.encryptWithKmsKey({
- kmsId: certificateManagerKmsId
- });
-
- const caSecret = await certificateAuthoritySecretDAL.findOne({ caId });
- if (!caSecret) throw new NotFoundError({ message: "CA secret not found" });
-
- const kmsDecryptor = await kmsService.decryptWithKmsKey({
- kmsId: certificateManagerKmsId
- });
- const privateKeyBlob = await kmsDecryptor({ cipherTextBlob: caSecret.encryptedPrivateKey });
- if (!ca.internalCa) throw new BadRequestError({ message: "CA internal configuration not found" });
-
- const alg = keyAlgorithmToAlgCfg(ca.internalCa.keyAlgorithm as CertKeyAlgorithm);
-
- const actualPrivateKey = await crypto.nativeCrypto.subtle.importKey("pkcs8", privateKeyBlob, alg, true, ["sign"]);
-
- const skObj = crypto.nativeCrypto.createPrivateKey({ key: privateKeyBlob, format: "der", type: "pkcs8" });
- const pkObj = crypto.nativeCrypto.createPublicKey(skObj);
- const publicKeyBuffer = pkObj.export({ format: "der", type: "spki" });
- const actualPublicKey = await crypto.nativeCrypto.subtle.importKey("spki", publicKeyBuffer, alg, true, [
- "verify"
- ]);
-
- const cert = await x509.X509CertificateGenerator.createSelfSigned({
- name: ca.internalCa.dn,
- serialNumber,
- notBefore: notBeforeDate,
- notAfter: notAfterDate,
- signingAlgorithm: alg,
- keys: { privateKey: actualPrivateKey, publicKey: actualPublicKey },
- extensions: [
- new x509.BasicConstraintsExtension(
- true,
- maxPathLength === -1 || maxPathLength === null || maxPathLength === undefined
- ? undefined
- : Number(maxPathLength),
- true
- ),
- // eslint-disable-next-line no-bitwise
- new x509.KeyUsagesExtension(x509.KeyUsageFlags.keyCertSign | x509.KeyUsageFlags.cRLSign, true),
- await x509.SubjectKeyIdentifierExtension.create(actualPublicKey)
- ]
- });
-
- const { cipherTextBlob: encryptedCertificate } = await kmsEncryptor({
- plainText: Buffer.from(new Uint8Array(cert.rawData))
- });
-
- const { cipherTextBlob: encryptedCertificateChain } = await kmsEncryptor({
- plainText: Buffer.alloc(0)
- });
-
- const existingCaCert = ca.internalCa.activeCaCertId
- ? await certificateAuthorityCertDAL.findById(ca.internalCa.activeCaCertId, tx)
+ const existingCaCert = ca.internalCa!.activeCaCertId
+ ? await certificateAuthorityCertDAL.findById(ca.internalCa!.activeCaCertId, tx)
: undefined;
const caCert = await certificateAuthorityCertDAL.create(
@@ -2269,7 +2254,7 @@ export const internalCertificateAuthorityServiceFactory = ({
);
await internalCertificateAuthorityDAL.updateById(
- ca.internalCa.id,
+ ca.internalCa!.id,
{
activeCaCertId: caCert.id
},
diff --git a/backend/src/services/certificate-authority/internal/internal-certificate-authority-types.ts b/backend/src/services/certificate-authority/internal/internal-certificate-authority-types.ts
index 5eeca397be..d8084e5477 100644
--- a/backend/src/services/certificate-authority/internal/internal-certificate-authority-types.ts
+++ b/backend/src/services/certificate-authority/internal/internal-certificate-authority-types.ts
@@ -115,19 +115,53 @@ export type TGetCaCertDTO = {
} & Omit<TProjectPermission, "projectId">;
export type TSignIntermediateDTO = {
- caId: string;
- csr: string;
- notBefore?: string;
- notAfter: string;
- maxPathLength: number;
-} & Omit<TProjectPermission, "projectId">;
+ isInternal?: boolean;
+} & (
+ | {
+ isInternal: true;
+ caId: string;
+ csr: string;
+ notBefore?: string;
+ notAfter: string;
+ maxPathLength: number;
+ actorId?: undefined;
+ actorAuthMethod?: undefined;
+ actor?: undefined;
+ actorOrgId?: undefined;
+ }
+ | ({
+ isInternal?: false;
+ caId: string;
+ csr: string;
+ notBefore?: string;
+ notAfter: string;
+ maxPathLength: number;
+ } & Omit<TProjectPermission, "projectId">)
+);
export type TImportCertToCaDTO = {
- caId: string;
- certificate: string;
- certificateChain: string;
+ isInternal?: boolean;
parentCaId?: string;
-} & Omit<TProjectPermission, "projectId">;
+} & (
+ | {
+ isInternal: true;
+ caId: string;
+ certificate: string;
+ certificateChain: string;
+ parentCaId?: string | undefined;
+ actorId?: undefined;
+ actorAuthMethod?: undefined;
+ actor?: undefined;
+ actorOrgId?: undefined;
+ }
+ | ({
+ isInternal?: false;
+ caId: string;
+ certificate: string;
+ certificateChain: string;
+ parentCaId?: string;
+ } & Omit<TProjectPermission, "projectId">)
+);
export type TIssueCertFromCaDTO = {
caId?: string;
diff --git a/frontend/src/context/ProjectPermissionContext/types.ts b/frontend/src/context/ProjectPermissionContext/types.ts
index 0838b0c36c..99b7b524b6 100644
--- a/frontend/src/context/ProjectPermissionContext/types.ts
+++ b/frontend/src/context/ProjectPermissionContext/types.ts
@@ -137,7 +137,7 @@ export enum ProjectPermissionCertificateAuthorityActions {
Edit = "edit",
Delete = "delete",
List = "list",
- Renew = "renew",
+ Issue = "issue",
SignIntermediate = "sign-intermediate"
}
diff --git a/frontend/src/pages/cert-manager/CertAuthDetailsByIDPage/components/CaDetailsSection.tsx b/frontend/src/pages/cert-manager/CertAuthDetailsByIDPage/components/CaDetailsSection.tsx
index 0cd13eaece..27b537f1ca 100644
--- a/frontend/src/pages/cert-manager/CertAuthDetailsByIDPage/components/CaDetailsSection.tsx
+++ b/frontend/src/pages/cert-manager/CertAuthDetailsByIDPage/components/CaDetailsSection.tsx
@@ -158,7 +158,7 @@ export const CaDetailsSection = ({ caId, handlePopUpOpen }: Props) => {
</div>
{ca.status === CaStatus.ACTIVE && (
<ProjectPermissionCan
- I={ProjectPermissionCertificateAuthorityActions.Renew}
+ I={ProjectPermissionCertificateAuthorityActions.Issue}
a={subject(ProjectPermissionSub.CertificateAuthorities, { name: ca.name })}
>
{(isAllowed) => {
diff --git a/frontend/src/pages/project/RoleDetailsBySlugPage/components/ProjectRoleModifySection.utils.tsx b/frontend/src/pages/project/RoleDetailsBySlugPage/components/ProjectRoleModifySection.utils.tsx
index 86b39498ef..cc29cebe48 100644
--- a/frontend/src/pages/project/RoleDetailsBySlugPage/components/ProjectRoleModifySection.utils.tsx
+++ b/frontend/src/pages/project/RoleDetailsBySlugPage/components/ProjectRoleModifySection.utils.tsx
@@ -68,7 +68,7 @@ const CertificateAuthorityPolicyActionSchema = z.object({
[ProjectPermissionCertificateAuthorityActions.Delete]: z.boolean().optional(),
[ProjectPermissionCertificateAuthorityActions.Edit]: z.boolean().optional(),
[ProjectPermissionCertificateAuthorityActions.Read]: z.boolean().optional(),
- [ProjectPermissionCertificateAuthorityActions.Renew]: z.boolean().optional(),
+ [ProjectPermissionCertificateAuthorityActions.Issue]: z.boolean().optional(),
[ProjectPermissionCertificateAuthorityActions.SignIntermediate]: z.boolean().optional()
});
@@ -875,7 +875,7 @@ export const rolePermission2Form = (permissions: TProjectPermission[] = []) => {
const canCreate = action.includes(ProjectPermissionCertificateAuthorityActions.Create);
const canEdit = action.includes(ProjectPermissionCertificateAuthorityActions.Edit);
const canDelete = action.includes(ProjectPermissionCertificateAuthorityActions.Delete);
- const canRenew = action.includes(ProjectPermissionCertificateAuthorityActions.Renew);
+ const canIssue = action.includes(ProjectPermissionCertificateAuthorityActions.Issue);
const canSignIntermediate = action.includes(
ProjectPermissionCertificateAuthorityActions.SignIntermediate
);
@@ -886,7 +886,7 @@ export const rolePermission2Form = (permissions: TProjectPermission[] = []) => {
[ProjectPermissionCertificateAuthorityActions.Create]: canCreate,
[ProjectPermissionCertificateAuthorityActions.Edit]: canEdit,
[ProjectPermissionCertificateAuthorityActions.Delete]: canDelete,
- [ProjectPermissionCertificateAuthorityActions.Renew]: canRenew,
+ [ProjectPermissionCertificateAuthorityActions.Issue]: canIssue,
[ProjectPermissionCertificateAuthorityActions.SignIntermediate]: canSignIntermediate,
conditions: conditions ? convertCaslConditionToFormOperator(conditions) : [],
inverted
@@ -1657,7 +1657,7 @@ export const PROJECT_PERMISSION_OBJECT: TProjectPermissionObject = {
{ label: "Create", value: ProjectPermissionCertificateAuthorityActions.Create },
{ label: "Modify", value: ProjectPermissionCertificateAuthorityActions.Edit },
{ label: "Remove", value: ProjectPermissionCertificateAuthorityActions.Delete },
- { label: "Renew", value: ProjectPermissionCertificateAuthorityActions.Renew },
+ { label: "Issue", value: ProjectPermissionCertificateAuthorityActions.Issue },
{
label: "Sign Intermediate",
value: ProjectPermissionCertificateAuthorityActions.SignIntermediate