Gate PKI feature

# Conflicts:
#	backend/src/ee/services/pki-acme/pki-acme-service.ts
This commit is contained in:
Fang-Pen Lin
2025-11-12 10:47:50 -08:00
parent 2767ff5c2d
commit 33b1ee0247
3 changed files with 24 additions and 1 deletions
@@ -29,6 +29,7 @@ import { TProjectDALFactory } from "@app/services/project/project-dal";
import { getProjectKmsCertificateKeyId } from "@app/services/project/project-fns"; import { getProjectKmsCertificateKeyId } from "@app/services/project/project-fns";
import { getConfig } from "@app/lib/config/env"; import { getConfig } from "@app/lib/config/env";
import { TLicenseServiceFactory } from "../license/license-service";
import { TPkiAcmeAccountDALFactory } from "./pki-acme-account-dal"; import { TPkiAcmeAccountDALFactory } from "./pki-acme-account-dal";
import { TPkiAcmeAuthDALFactory } from "./pki-acme-auth-dal"; import { TPkiAcmeAuthDALFactory } from "./pki-acme-auth-dal";
import { TPkiAcmeChallengeDALFactory } from "./pki-acme-challenge-dal"; import { TPkiAcmeChallengeDALFactory } from "./pki-acme-challenge-dal";
@@ -101,6 +102,7 @@ type TPkiAcmeServiceFactoryDep = {
>; >;
keyStore: Pick<TKeyStoreFactory, "getItem" | "setItemWithExpiry" | "deleteItem">; keyStore: Pick<TKeyStoreFactory, "getItem" | "setItemWithExpiry" | "deleteItem">;
kmsService: Pick<TKmsServiceFactory, "decryptWithKmsKey" | "generateKmsKey">; kmsService: Pick<TKmsServiceFactory, "decryptWithKmsKey" | "generateKmsKey">;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
certificateV3Service: Pick<TCertificateV3ServiceFactory, "signCertificateFromProfile">; certificateV3Service: Pick<TCertificateV3ServiceFactory, "signCertificateFromProfile">;
acmeChallengeService: TPkiAcmeChallengeServiceFactory; acmeChallengeService: TPkiAcmeChallengeServiceFactory;
}; };
@@ -116,6 +118,7 @@ export const pkiAcmeServiceFactory = ({
acmeChallengeDAL, acmeChallengeDAL,
keyStore, keyStore,
kmsService, kmsService,
licenseService,
certificateV3Service, certificateV3Service,
acmeChallengeService acmeChallengeService
}: TPkiAcmeServiceFactoryDep): TPkiAcmeServiceFactory => { }: TPkiAcmeServiceFactoryDep): TPkiAcmeServiceFactory => {
@@ -127,6 +130,10 @@ export const pkiAcmeServiceFactory = ({
if (profile.enrollmentType !== EnrollmentType.ACME) { if (profile.enrollmentType !== EnrollmentType.ACME) {
throw new NotFoundError({ message: "Certificate profile is not configured for ACME enrollment" }); throw new NotFoundError({ message: "Certificate profile is not configured for ACME enrollment" });
} }
const orgLicensePlan = await licenseService.getPlan(profile.project.orgId);
if (!orgLicensePlan.pkiAcme) {
throw new AcmeUnauthorizedError({ message: "The organization does not have a valid license to use ACME" });
}
return profile; return profile;
}; };
@@ -85,6 +85,7 @@ export const certificateProfileDALFactory = (db: TDbClient) => {
const findByIdWithConfigs = async (id: string, tx?: Knex): Promise<TCertificateProfileWithConfigs | undefined> => { const findByIdWithConfigs = async (id: string, tx?: Knex): Promise<TCertificateProfileWithConfigs | undefined> => {
try { try {
const query = (tx || db)(TableName.PkiCertificateProfile) const query = (tx || db)(TableName.PkiCertificateProfile)
.leftJoin(TableName.Project, `${TableName.PkiCertificateProfile}.projectId`, `${TableName.Project}.id`)
.leftJoin( .leftJoin(
TableName.CertificateAuthority, TableName.CertificateAuthority,
`${TableName.PkiCertificateProfile}.caId`, `${TableName.PkiCertificateProfile}.caId`,
@@ -112,6 +113,8 @@ export const certificateProfileDALFactory = (db: TDbClient) => {
) )
.select(selectAllTableCols(TableName.PkiCertificateProfile)) .select(selectAllTableCols(TableName.PkiCertificateProfile))
.select( .select(
db.ref("id").withSchema(TableName.Project).as("projectId"),
db.ref("orgId").withSchema(TableName.Project).as("orgId")
db.ref("id").withSchema(TableName.CertificateAuthority).as("caId"), db.ref("id").withSchema(TableName.CertificateAuthority).as("caId"),
db.ref("projectId").withSchema(TableName.CertificateAuthority).as("caProjectId"), db.ref("projectId").withSchema(TableName.CertificateAuthority).as("caProjectId"),
db.ref("status").withSchema(TableName.CertificateAuthority).as("caStatus"), db.ref("status").withSchema(TableName.CertificateAuthority).as("caStatus"),
@@ -131,7 +134,7 @@ export const certificateProfileDALFactory = (db: TDbClient) => {
db.ref("autoRenew").withSchema(TableName.PkiApiEnrollmentConfig).as("apiConfigAutoRenew"), db.ref("autoRenew").withSchema(TableName.PkiApiEnrollmentConfig).as("apiConfigAutoRenew"),
db.ref("renewBeforeDays").withSchema(TableName.PkiApiEnrollmentConfig).as("apiConfigRenewBeforeDays"), db.ref("renewBeforeDays").withSchema(TableName.PkiApiEnrollmentConfig).as("apiConfigRenewBeforeDays"),
db.ref("id").withSchema(TableName.PkiAcmeEnrollmentConfig).as("acmeConfigId"), db.ref("id").withSchema(TableName.PkiAcmeEnrollmentConfig).as("acmeConfigId"),
db.ref("encryptedEabSecret").withSchema(TableName.PkiAcmeEnrollmentConfig).as("acmeConfigEncryptedEabSecret") db.ref("encryptedEabSecret").withSchema(TableName.PkiAcmeEnrollmentConfig).as("acmeConfigEncryptedEabSecret"),
) )
.where(`${TableName.PkiCertificateProfile}.id`, id) .where(`${TableName.PkiCertificateProfile}.id`, id)
.first(); .first();
@@ -185,6 +188,14 @@ export const certificateProfileDALFactory = (db: TDbClient) => {
} as TCertificateProfileWithConfigs["certificateTemplate"]) } as TCertificateProfileWithConfigs["certificateTemplate"])
: undefined; : undefined;
const project =
result.projectId && result.orgId
? ({
id: result.projectId,
orgId: result.orgId
} as TCertificateProfileWithConfigs["project"])
: undefined;
const transformedResult: TCertificateProfileWithConfigs = { const transformedResult: TCertificateProfileWithConfigs = {
id: result.id, id: result.id,
projectId: result.projectId, projectId: result.projectId,
@@ -201,6 +212,7 @@ export const certificateProfileDALFactory = (db: TDbClient) => {
estConfig, estConfig,
apiConfig, apiConfig,
acmeConfig, acmeConfig,
project,
certificateAuthority, certificateAuthority,
certificateTemplate certificateTemplate
}; };
@@ -33,6 +33,10 @@ export type TCertificateProfileUpdate = Omit<TPkiCertificateProfilesUpdate, "enr
}; };
export type TCertificateProfileWithConfigs = TCertificateProfile & { export type TCertificateProfileWithConfigs = TCertificateProfile & {
project: {
id: string;
orgId: string;
};
certificateAuthority?: { certificateAuthority?: {
id: string; id: string;
projectId: string; projectId: string;