mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-18 13:15:39 +00:00
PKI revamp - backend initial changes
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
import { Knex } from "knex";
|
||||
|
||||
import { TableName } from "../schemas";
|
||||
import { createOnUpdateTrigger, dropOnUpdateTrigger } from "../utils";
|
||||
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
if (!(await knex.schema.hasTable(TableName.CertificateTemplateV2))) {
|
||||
await knex.schema.createTable(TableName.CertificateTemplateV2, (t) => {
|
||||
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
|
||||
t.string("projectId").notNullable();
|
||||
t.foreign("projectId").references("id").inTable(TableName.Project).onDelete("CASCADE");
|
||||
|
||||
t.string("name", 64).notNullable();
|
||||
t.string("description");
|
||||
|
||||
t.jsonb("attributes");
|
||||
t.jsonb("keyUsages");
|
||||
t.jsonb("extendedKeyUsages");
|
||||
t.jsonb("subjectAlternativeNames");
|
||||
t.jsonb("validity");
|
||||
t.jsonb("signatureAlgorithm");
|
||||
t.jsonb("keyAlgorithm");
|
||||
|
||||
t.timestamps(true, true, true);
|
||||
});
|
||||
|
||||
await createOnUpdateTrigger(knex, TableName.CertificateTemplateV2);
|
||||
}
|
||||
|
||||
if (!(await knex.schema.hasTable(TableName.EstEnrollmentConfig))) {
|
||||
await knex.schema.createTable(TableName.EstEnrollmentConfig, (t) => {
|
||||
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
|
||||
|
||||
t.boolean("disableBootstrapCaValidation").defaultTo(false);
|
||||
t.text("hashedPassphrase").notNullable();
|
||||
t.binary("encryptedCaChain").notNullable();
|
||||
|
||||
t.timestamps(true, true, true);
|
||||
});
|
||||
|
||||
await createOnUpdateTrigger(knex, TableName.EstEnrollmentConfig);
|
||||
}
|
||||
|
||||
if (!(await knex.schema.hasTable(TableName.ApiEnrollmentConfig))) {
|
||||
await knex.schema.createTable(TableName.ApiEnrollmentConfig, (t) => {
|
||||
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
|
||||
|
||||
t.boolean("autoRenew").defaultTo(false);
|
||||
t.integer("autoRenewDays");
|
||||
|
||||
t.timestamps(true, true, true);
|
||||
});
|
||||
|
||||
await createOnUpdateTrigger(knex, TableName.ApiEnrollmentConfig);
|
||||
}
|
||||
|
||||
if (!(await knex.schema.hasTable(TableName.CertificateProfile))) {
|
||||
await knex.schema.createTable(TableName.CertificateProfile, (t) => {
|
||||
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
|
||||
t.string("projectId").notNullable();
|
||||
t.foreign("projectId").references("id").inTable(TableName.Project).onDelete("CASCADE");
|
||||
|
||||
t.uuid("caId").notNullable();
|
||||
t.foreign("caId").references("id").inTable(TableName.CertificateAuthority).onDelete("CASCADE");
|
||||
|
||||
t.uuid("certificateTemplateId").notNullable();
|
||||
t.foreign("certificateTemplateId").references("id").inTable(TableName.CertificateTemplateV2).onDelete("CASCADE");
|
||||
|
||||
t.string("name", 64).notNullable();
|
||||
t.string("slug").notNullable();
|
||||
t.string("description");
|
||||
t.string("enrollmentType").notNullable().checkIn(["api", "est"]);
|
||||
|
||||
t.uuid("estConfigId");
|
||||
t.foreign("estConfigId").references("id").inTable(TableName.EstEnrollmentConfig).onDelete("SET NULL");
|
||||
|
||||
t.uuid("apiConfigId");
|
||||
t.foreign("apiConfigId").references("id").inTable(TableName.ApiEnrollmentConfig).onDelete("SET NULL");
|
||||
|
||||
t.timestamps(true, true, true);
|
||||
|
||||
t.unique(["slug", "projectId"], { indexName: "certificate_profiles_slug_project_id_unique" });
|
||||
});
|
||||
|
||||
await createOnUpdateTrigger(knex, TableName.CertificateProfile);
|
||||
}
|
||||
|
||||
if (!(await knex.schema.hasColumn(TableName.Certificate, "profileId"))) {
|
||||
await knex.schema.alterTable(TableName.Certificate, (t) => {
|
||||
t.uuid("profileId");
|
||||
t.foreign("profileId").references("id").inTable(TableName.CertificateProfile).onDelete("SET NULL");
|
||||
t.index("profileId", "idx_certificates_profile_id");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
if (await knex.schema.hasColumn(TableName.Certificate, "profileId")) {
|
||||
await knex.schema.alterTable(TableName.Certificate, (t) => {
|
||||
t.dropForeign(["profileId"]);
|
||||
t.dropIndex("profileId", "idx_certificates_profile_id");
|
||||
t.dropColumn("profileId");
|
||||
});
|
||||
}
|
||||
|
||||
await knex.schema.dropTableIfExists(TableName.CertificateProfile);
|
||||
await dropOnUpdateTrigger(knex, TableName.CertificateProfile);
|
||||
|
||||
await knex.schema.dropTableIfExists(TableName.ApiEnrollmentConfig);
|
||||
await dropOnUpdateTrigger(knex, TableName.ApiEnrollmentConfig);
|
||||
|
||||
await knex.schema.dropTableIfExists(TableName.EstEnrollmentConfig);
|
||||
await dropOnUpdateTrigger(knex, TableName.EstEnrollmentConfig);
|
||||
|
||||
await knex.schema.dropTableIfExists(TableName.CertificateTemplateV2);
|
||||
await dropOnUpdateTrigger(knex, TableName.CertificateTemplateV2);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Code generated by automation script, DO NOT EDIT.
|
||||
// Automated by pulling database and generating zod schema
|
||||
// To update. Just run npm run generate:schema
|
||||
// Written by akhilmhdh.
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
import { TImmutableDBKeys } from "./models";
|
||||
|
||||
export const ApiEnrollmentConfigsSchema = z.object({
|
||||
id: z.string().uuid(),
|
||||
autoRenew: z.boolean().default(false).nullable().optional(),
|
||||
autoRenewDays: z.number().nullable().optional(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date()
|
||||
});
|
||||
|
||||
export type TApiEnrollmentConfigs = z.infer<typeof ApiEnrollmentConfigsSchema>;
|
||||
export type TApiEnrollmentConfigsInsert = Omit<z.input<typeof ApiEnrollmentConfigsSchema>, TImmutableDBKeys>;
|
||||
export type TApiEnrollmentConfigsUpdate = Partial<Omit<z.input<typeof ApiEnrollmentConfigsSchema>, TImmutableDBKeys>>;
|
||||
@@ -0,0 +1,27 @@
|
||||
// Code generated by automation script, DO NOT EDIT.
|
||||
// Automated by pulling database and generating zod schema
|
||||
// To update. Just run npm run generate:schema
|
||||
// Written by akhilmhdh.
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
import { TImmutableDBKeys } from "./models";
|
||||
|
||||
export const CertificateProfilesSchema = z.object({
|
||||
id: z.string().uuid(),
|
||||
projectId: z.string(),
|
||||
caId: z.string().uuid(),
|
||||
certificateTemplateId: z.string().uuid(),
|
||||
name: z.string(),
|
||||
slug: z.string(),
|
||||
description: z.string().nullable().optional(),
|
||||
enrollmentType: z.string(),
|
||||
estConfigId: z.string().uuid().nullable().optional(),
|
||||
apiConfigId: z.string().uuid().nullable().optional(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date()
|
||||
});
|
||||
|
||||
export type TCertificateProfiles = z.infer<typeof CertificateProfilesSchema>;
|
||||
export type TCertificateProfilesInsert = Omit<z.input<typeof CertificateProfilesSchema>, TImmutableDBKeys>;
|
||||
export type TCertificateProfilesUpdate = Partial<Omit<z.input<typeof CertificateProfilesSchema>, TImmutableDBKeys>>;
|
||||
@@ -0,0 +1,30 @@
|
||||
// Code generated by automation script, DO NOT EDIT.
|
||||
// Automated by pulling database and generating zod schema
|
||||
// To update. Just run npm run generate:schema
|
||||
// Written by akhilmhdh.
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
import { TImmutableDBKeys } from "./models";
|
||||
|
||||
export const CertificateTemplatesV2Schema = z.object({
|
||||
id: z.string().uuid(),
|
||||
projectId: z.string(),
|
||||
name: z.string(),
|
||||
description: z.string().nullable().optional(),
|
||||
attributes: z.unknown().nullable().optional(),
|
||||
keyUsages: z.unknown().nullable().optional(),
|
||||
extendedKeyUsages: z.unknown().nullable().optional(),
|
||||
subjectAlternativeNames: z.unknown().nullable().optional(),
|
||||
validity: z.unknown().nullable().optional(),
|
||||
signatureAlgorithm: z.unknown().nullable().optional(),
|
||||
keyAlgorithm: z.unknown().nullable().optional(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date()
|
||||
});
|
||||
|
||||
export type TCertificateTemplatesV2 = z.infer<typeof CertificateTemplatesV2Schema>;
|
||||
export type TCertificateTemplatesV2Insert = Omit<z.input<typeof CertificateTemplatesV2Schema>, TImmutableDBKeys>;
|
||||
export type TCertificateTemplatesV2Update = Partial<
|
||||
Omit<z.input<typeof CertificateTemplatesV2Schema>, TImmutableDBKeys>
|
||||
>;
|
||||
@@ -26,7 +26,8 @@ export const CertificatesSchema = z.object({
|
||||
keyUsages: z.string().array().nullable().optional(),
|
||||
extendedKeyUsages: z.string().array().nullable().optional(),
|
||||
projectId: z.string(),
|
||||
pkiSubscriberId: z.string().uuid().nullable().optional()
|
||||
pkiSubscriberId: z.string().uuid().nullable().optional(),
|
||||
profileId: z.string().uuid().nullable().optional()
|
||||
});
|
||||
|
||||
export type TCertificates = z.infer<typeof CertificatesSchema>;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Code generated by automation script, DO NOT EDIT.
|
||||
// Automated by pulling database and generating zod schema
|
||||
// To update. Just run npm run generate:schema
|
||||
// Written by akhilmhdh.
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
import { zodBuffer } from "@app/lib/zod";
|
||||
|
||||
import { TImmutableDBKeys } from "./models";
|
||||
|
||||
export const EstEnrollmentConfigsSchema = z.object({
|
||||
id: z.string().uuid(),
|
||||
disableBootstrapCaValidation: z.boolean().default(false).nullable().optional(),
|
||||
hashedPassphrase: z.string(),
|
||||
encryptedCaChain: zodBuffer,
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date()
|
||||
});
|
||||
|
||||
export type TEstEnrollmentConfigs = z.infer<typeof EstEnrollmentConfigsSchema>;
|
||||
export type TEstEnrollmentConfigsInsert = Omit<z.input<typeof EstEnrollmentConfigsSchema>, TImmutableDBKeys>;
|
||||
export type TEstEnrollmentConfigsUpdate = Partial<Omit<z.input<typeof EstEnrollmentConfigsSchema>, TImmutableDBKeys>>;
|
||||
@@ -3,6 +3,7 @@ export * from "./access-approval-policies-approvers";
|
||||
export * from "./access-approval-policies-bypassers";
|
||||
export * from "./access-approval-requests";
|
||||
export * from "./access-approval-requests-reviewers";
|
||||
export * from "./api-enrollment-configs";
|
||||
export * from "./api-keys";
|
||||
export * from "./app-connections";
|
||||
export * from "./audit-log-streams";
|
||||
@@ -15,12 +16,15 @@ export * from "./certificate-authority-certs";
|
||||
export * from "./certificate-authority-crl";
|
||||
export * from "./certificate-authority-secret";
|
||||
export * from "./certificate-bodies";
|
||||
export * from "./certificate-profiles";
|
||||
export * from "./certificate-secrets";
|
||||
export * from "./certificate-template-est-configs";
|
||||
export * from "./certificate-templates";
|
||||
export * from "./certificate-templates-v2";
|
||||
export * from "./certificates";
|
||||
export * from "./dynamic-secret-leases";
|
||||
export * from "./dynamic-secrets";
|
||||
export * from "./est-enrollment-configs";
|
||||
export * from "./external-certificate-authorities";
|
||||
export * from "./external-group-org-role-mappings";
|
||||
export * from "./external-kms";
|
||||
|
||||
@@ -23,6 +23,10 @@ export enum TableName {
|
||||
CertificateBody = "certificate_bodies",
|
||||
CertificateSecret = "certificate_secrets",
|
||||
CertificateTemplate = "certificate_templates",
|
||||
CertificateTemplateV2 = "certificate_templates_v2",
|
||||
CertificateProfile = "certificate_profiles",
|
||||
EstEnrollmentConfig = "est_enrollment_configs",
|
||||
ApiEnrollmentConfig = "api_enrollment_configs",
|
||||
PkiSubscriber = "pki_subscribers",
|
||||
PkiAlert = "pki_alerts",
|
||||
PkiCollection = "pki_collections",
|
||||
|
||||
Reference in New Issue
Block a user