-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2830 from Infisical/ssh-certs
Infisical SSH (SSH Certificates)
- Loading branch information
Showing
101 changed files
with
6,171 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
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.SshCertificateAuthority))) { | ||
await knex.schema.createTable(TableName.SshCertificateAuthority, (t) => { | ||
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid()); | ||
t.timestamps(true, true, true); | ||
t.string("projectId").notNullable(); | ||
t.foreign("projectId").references("id").inTable(TableName.Project).onDelete("CASCADE"); | ||
t.string("status").notNullable(); // active / disabled | ||
t.string("friendlyName").notNullable(); | ||
t.string("keyAlgorithm").notNullable(); | ||
}); | ||
await createOnUpdateTrigger(knex, TableName.SshCertificateAuthority); | ||
} | ||
|
||
if (!(await knex.schema.hasTable(TableName.SshCertificateAuthoritySecret))) { | ||
await knex.schema.createTable(TableName.SshCertificateAuthoritySecret, (t) => { | ||
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid()); | ||
t.timestamps(true, true, true); | ||
t.uuid("sshCaId").notNullable().unique(); | ||
t.foreign("sshCaId").references("id").inTable(TableName.SshCertificateAuthority).onDelete("CASCADE"); | ||
t.binary("encryptedPrivateKey").notNullable(); | ||
}); | ||
await createOnUpdateTrigger(knex, TableName.SshCertificateAuthoritySecret); | ||
} | ||
|
||
if (!(await knex.schema.hasTable(TableName.SshCertificateTemplate))) { | ||
await knex.schema.createTable(TableName.SshCertificateTemplate, (t) => { | ||
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid()); | ||
t.timestamps(true, true, true); | ||
t.uuid("sshCaId").notNullable(); | ||
t.foreign("sshCaId").references("id").inTable(TableName.SshCertificateAuthority).onDelete("CASCADE"); | ||
t.string("status").notNullable(); // active / disabled | ||
t.string("name").notNullable(); | ||
t.string("ttl").notNullable(); | ||
t.string("maxTTL").notNullable(); | ||
t.specificType("allowedUsers", "text[]").notNullable(); | ||
t.specificType("allowedHosts", "text[]").notNullable(); | ||
t.boolean("allowUserCertificates").notNullable(); | ||
t.boolean("allowHostCertificates").notNullable(); | ||
t.boolean("allowCustomKeyIds").notNullable(); | ||
}); | ||
await createOnUpdateTrigger(knex, TableName.SshCertificateTemplate); | ||
} | ||
|
||
if (!(await knex.schema.hasTable(TableName.SshCertificate))) { | ||
await knex.schema.createTable(TableName.SshCertificate, (t) => { | ||
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid()); | ||
t.timestamps(true, true, true); | ||
t.uuid("sshCaId").notNullable(); | ||
t.foreign("sshCaId").references("id").inTable(TableName.SshCertificateAuthority).onDelete("SET NULL"); | ||
t.uuid("sshCertificateTemplateId"); | ||
t.foreign("sshCertificateTemplateId") | ||
.references("id") | ||
.inTable(TableName.SshCertificateTemplate) | ||
.onDelete("SET NULL"); | ||
t.string("serialNumber").notNullable().unique(); | ||
t.string("certType").notNullable(); // user or host | ||
t.specificType("principals", "text[]").notNullable(); | ||
t.string("keyId").notNullable(); | ||
t.datetime("notBefore").notNullable(); | ||
t.datetime("notAfter").notNullable(); | ||
}); | ||
await createOnUpdateTrigger(knex, TableName.SshCertificate); | ||
} | ||
|
||
if (!(await knex.schema.hasTable(TableName.SshCertificateBody))) { | ||
await knex.schema.createTable(TableName.SshCertificateBody, (t) => { | ||
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid()); | ||
t.timestamps(true, true, true); | ||
t.uuid("sshCertId").notNullable().unique(); | ||
t.foreign("sshCertId").references("id").inTable(TableName.SshCertificate).onDelete("CASCADE"); | ||
t.binary("encryptedCertificate").notNullable(); | ||
}); | ||
|
||
await createOnUpdateTrigger(knex, TableName.SshCertificateBody); | ||
} | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
await knex.schema.dropTableIfExists(TableName.SshCertificateBody); | ||
await dropOnUpdateTrigger(knex, TableName.SshCertificateBody); | ||
|
||
await knex.schema.dropTableIfExists(TableName.SshCertificate); | ||
await dropOnUpdateTrigger(knex, TableName.SshCertificate); | ||
|
||
await knex.schema.dropTableIfExists(TableName.SshCertificateTemplate); | ||
await dropOnUpdateTrigger(knex, TableName.SshCertificateTemplate); | ||
|
||
await knex.schema.dropTableIfExists(TableName.SshCertificateAuthoritySecret); | ||
await dropOnUpdateTrigger(knex, TableName.SshCertificateAuthoritySecret); | ||
|
||
await knex.schema.dropTableIfExists(TableName.SshCertificateAuthority); | ||
await dropOnUpdateTrigger(knex, TableName.SshCertificateAuthority); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// 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 SshCertificateAuthoritiesSchema = z.object({ | ||
id: z.string().uuid(), | ||
createdAt: z.date(), | ||
updatedAt: z.date(), | ||
projectId: z.string(), | ||
status: z.string(), | ||
friendlyName: z.string(), | ||
keyAlgorithm: z.string() | ||
}); | ||
|
||
export type TSshCertificateAuthorities = z.infer<typeof SshCertificateAuthoritiesSchema>; | ||
export type TSshCertificateAuthoritiesInsert = Omit<z.input<typeof SshCertificateAuthoritiesSchema>, TImmutableDBKeys>; | ||
export type TSshCertificateAuthoritiesUpdate = Partial< | ||
Omit<z.input<typeof SshCertificateAuthoritiesSchema>, TImmutableDBKeys> | ||
>; |
27 changes: 27 additions & 0 deletions
27
backend/src/db/schemas/ssh-certificate-authority-secrets.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { zodBuffer } from "@app/lib/zod"; | ||
|
||
import { TImmutableDBKeys } from "./models"; | ||
|
||
export const SshCertificateAuthoritySecretsSchema = z.object({ | ||
id: z.string().uuid(), | ||
createdAt: z.date(), | ||
updatedAt: z.date(), | ||
sshCaId: z.string().uuid(), | ||
encryptedPrivateKey: zodBuffer | ||
}); | ||
|
||
export type TSshCertificateAuthoritySecrets = z.infer<typeof SshCertificateAuthoritySecretsSchema>; | ||
export type TSshCertificateAuthoritySecretsInsert = Omit< | ||
z.input<typeof SshCertificateAuthoritySecretsSchema>, | ||
TImmutableDBKeys | ||
>; | ||
export type TSshCertificateAuthoritySecretsUpdate = Partial< | ||
Omit<z.input<typeof SshCertificateAuthoritySecretsSchema>, TImmutableDBKeys> | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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 SshCertificateBodiesSchema = z.object({ | ||
id: z.string().uuid(), | ||
createdAt: z.date(), | ||
updatedAt: z.date(), | ||
sshCertId: z.string().uuid(), | ||
encryptedCertificate: zodBuffer | ||
}); | ||
|
||
export type TSshCertificateBodies = z.infer<typeof SshCertificateBodiesSchema>; | ||
export type TSshCertificateBodiesInsert = Omit<z.input<typeof SshCertificateBodiesSchema>, TImmutableDBKeys>; | ||
export type TSshCertificateBodiesUpdate = Partial<Omit<z.input<typeof SshCertificateBodiesSchema>, TImmutableDBKeys>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 SshCertificateTemplatesSchema = z.object({ | ||
id: z.string().uuid(), | ||
createdAt: z.date(), | ||
updatedAt: z.date(), | ||
sshCaId: z.string().uuid(), | ||
status: z.string(), | ||
name: z.string(), | ||
ttl: z.string(), | ||
maxTTL: z.string(), | ||
allowedUsers: z.string().array(), | ||
allowedHosts: z.string().array(), | ||
allowUserCertificates: z.boolean(), | ||
allowHostCertificates: z.boolean(), | ||
allowCustomKeyIds: z.boolean() | ||
}); | ||
|
||
export type TSshCertificateTemplates = z.infer<typeof SshCertificateTemplatesSchema>; | ||
export type TSshCertificateTemplatesInsert = Omit<z.input<typeof SshCertificateTemplatesSchema>, TImmutableDBKeys>; | ||
export type TSshCertificateTemplatesUpdate = Partial< | ||
Omit<z.input<typeof SshCertificateTemplatesSchema>, TImmutableDBKeys> | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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 SshCertificatesSchema = z.object({ | ||
id: z.string().uuid(), | ||
createdAt: z.date(), | ||
updatedAt: z.date(), | ||
sshCaId: z.string().uuid(), | ||
sshCertificateTemplateId: z.string().uuid().nullable().optional(), | ||
serialNumber: z.string(), | ||
certType: z.string(), | ||
principals: z.string().array(), | ||
keyId: z.string(), | ||
notBefore: z.date(), | ||
notAfter: z.date() | ||
}); | ||
|
||
export type TSshCertificates = z.infer<typeof SshCertificatesSchema>; | ||
export type TSshCertificatesInsert = Omit<z.input<typeof SshCertificatesSchema>, TImmutableDBKeys>; | ||
export type TSshCertificatesUpdate = Partial<Omit<z.input<typeof SshCertificatesSchema>, TImmutableDBKeys>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.