mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 05:19:49 +00:00
Add SSH certificate tab + data structure
This commit is contained in:
@@ -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
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user