Add SSH certificate tab + data structure

This commit is contained in:
Tuan Dang
2024-12-05 23:01:28 -08:00
parent 5b618b07fa
commit 6e720c2f64
33 changed files with 604 additions and 210 deletions
+76 -2
View File
@@ -25,6 +25,8 @@ import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services
import { TProjectUserAdditionalPrivilegeDALFactory } from "@app/ee/services/project-user-additional-privilege/project-user-additional-privilege-dal";
import { TSamlConfigDALFactory } from "@app/ee/services/saml-config/saml-config-dal";
import { TSshCertificateAuthorityDALFactory } from "@app/ee/services/ssh/ssh-certificate-authority-dal";
import { TSshCertificateDALFactory } from "@app/ee/services/ssh-certificate/ssh-certificate-dal";
import { TSshCertificateTemplateDALFactory } from "@app/ee/services/ssh-certificate-template/ssh-certificate-template-dal";
import { getConfig } from "@app/lib/config/env";
import { generateAsymmetricKeyPair } from "@app/lib/crypto";
import { generateSymmetricKey, infisicalSymmetricDecrypt, infisicalSymmetricEncypt } from "@app/lib/crypto/encryption";
@@ -64,6 +66,8 @@ import {
TGetOrgMembershipDTO,
TInviteUserToOrgDTO,
TListOrgSshCasDTO,
TListOrgSshCertificatesDTO,
TListOrgSshCertificateTemplatesDTO,
TListProjectMembershipsByOrgMembershipIdDTO,
TUpdateOrgDTO,
TUpdateOrgMembershipDTO,
@@ -101,6 +105,8 @@ type TOrgServiceFactoryDep = {
projectUserMembershipRoleDAL: Pick<TProjectUserMembershipRoleDALFactory, "insertMany" | "create">;
projectBotService: Pick<TProjectBotServiceFactory, "getBotKey">;
sshCertificateAuthorityDAL: Pick<TSshCertificateAuthorityDALFactory, "find">;
sshCertificateDAL: Pick<TSshCertificateDALFactory, "find" | "countSshCertificatesInOrg">;
sshCertificateTemplateDAL: Pick<TSshCertificateTemplateDALFactory, "find">;
};
export type TOrgServiceFactory = ReturnType<typeof orgServiceFactory>;
@@ -129,6 +135,8 @@ export const orgServiceFactory = ({
projectUserMembershipRoleDAL,
identityMetadataDAL,
sshCertificateAuthorityDAL,
sshCertificateDAL,
sshCertificateTemplateDAL,
projectBotService
}: TOrgServiceFactoryDep) => {
/*
@@ -1132,7 +1140,7 @@ export const orgServiceFactory = ({
};
/**
* Return list of SSH CAs for project
* Return list of SSH CAs for organization
*/
const listOrgSshCas = async ({ actorId, actorOrgId, actorAuthMethod, actor, orgId }: TListOrgSshCasDTO) => {
const { permission } = await permissionService.getOrgPermission(actor, actorId, orgId, actorAuthMethod, actorOrgId);
@@ -1152,6 +1160,70 @@ export const orgServiceFactory = ({
return cas;
};
/**
* Return list of SSH certificates for organization
*/
const listOrgSshCertificates = async ({
limit = 25,
offset = 0,
actorId,
actorOrgId,
actorAuthMethod,
actor,
orgId
}: TListOrgSshCertificatesDTO) => {
const { permission } = await permissionService.getOrgPermission(actor, actorId, orgId, actorAuthMethod, actorOrgId);
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.SshCertificates);
const cas = await sshCertificateAuthorityDAL.find({
orgId
});
const certificates = await sshCertificateDAL.find(
{
$in: {
sshCaId: cas.map((ca) => ca.id)
}
},
{ offset, limit, sort: [["updatedAt", "desc"]] }
);
const count = await sshCertificateDAL.countSshCertificatesInOrg(orgId);
return { certificates, totalCount: count };
};
/**
* Return list of SSH certificate templates for organization
*/
const listOrgSshCertificateTemplates = async ({
actorId,
actorOrgId,
actorAuthMethod,
actor,
orgId
}: TListOrgSshCertificateTemplatesDTO) => {
const { permission } = await permissionService.getOrgPermission(actor, actorId, orgId, actorAuthMethod, actorOrgId);
ForbiddenError.from(permission).throwUnlessCan(
OrgPermissionActions.Read,
OrgPermissionSubjects.SshCertificateTemplates
);
const cas = await sshCertificateAuthorityDAL.find({
orgId
});
const certificateTemplates = await sshCertificateTemplateDAL.find({
$in: {
sshCaId: cas.map((ca) => ca.id)
}
});
return { certificateTemplates };
};
return {
findOrganizationById,
findAllOrgMembers,
@@ -1174,6 +1246,8 @@ export const orgServiceFactory = ({
getOrgGroups,
listProjectMembershipsByOrgMembershipId,
findOrgBySlug,
listOrgSshCas
listOrgSshCas,
listOrgSshCertificates,
listOrgSshCertificateTemplates
};
};
+5
View File
@@ -76,6 +76,11 @@ export type TListProjectMembershipsByOrgMembershipIdDTO = {
} & TOrgPermission;
export type TListOrgSshCasDTO = TOrgPermission;
export type TListOrgSshCertificateTemplatesDTO = TOrgPermission;
export type TListOrgSshCertificatesDTO = {
offset: number;
limit: number;
} & TOrgPermission;
export enum OrgAuthMethod {
OIDC = "oidc",