forked from Infisical/infisical
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
35 changed files
with
419 additions
and
301 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
36 changes: 36 additions & 0 deletions
36
backend/src/db/migrations/20240821212643_crl-ca-secret-binding.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,36 @@ | ||
import { Knex } from "knex"; | ||
|
||
import { TableName } from "../schemas"; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
if (await knex.schema.hasTable(TableName.CertificateAuthorityCrl)) { | ||
const hasCaSecretIdColumn = await knex.schema.hasColumn(TableName.CertificateAuthorityCrl, "caSecretId"); | ||
if (!hasCaSecretIdColumn) { | ||
await knex.schema.alterTable(TableName.CertificateAuthorityCrl, (t) => { | ||
t.uuid("caSecretId").nullable(); | ||
t.foreign("caSecretId").references("id").inTable(TableName.CertificateAuthoritySecret).onDelete("CASCADE"); | ||
}); | ||
|
||
await knex.raw(` | ||
UPDATE "${TableName.CertificateAuthorityCrl}" crl | ||
SET "caSecretId" = ( | ||
SELECT sec.id | ||
FROM "${TableName.CertificateAuthoritySecret}" sec | ||
WHERE sec."caId" = crl."caId" | ||
) | ||
`); | ||
|
||
await knex.schema.alterTable(TableName.CertificateAuthorityCrl, (t) => { | ||
t.uuid("caSecretId").notNullable().alter(); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
if (await knex.schema.hasTable(TableName.CertificateAuthorityCrl)) { | ||
await knex.schema.alterTable(TableName.CertificateAuthorityCrl, (t) => { | ||
t.dropColumn("caSecretId"); | ||
}); | ||
} | ||
} |
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
75 changes: 10 additions & 65 deletions
75
backend/src/ee/routes/v1/certificate-authority-crl-router.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 |
---|---|---|
@@ -1,86 +1,31 @@ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
import { z } from "zod"; | ||
|
||
import { EventType } from "@app/ee/services/audit-log/audit-log-types"; | ||
import { CERTIFICATE_AUTHORITIES } from "@app/lib/api-docs"; | ||
import { CA_CRLS } from "@app/lib/api-docs"; | ||
import { readLimit } from "@app/server/config/rateLimiter"; | ||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth"; | ||
import { AuthMode } from "@app/services/auth/auth-type"; | ||
|
||
export const registerCaCrlRouter = async (server: FastifyZodProvider) => { | ||
server.route({ | ||
method: "GET", | ||
url: "/:caId/crl", | ||
url: "/:crlId", | ||
config: { | ||
rateLimit: readLimit | ||
}, | ||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), | ||
schema: { | ||
description: "Get CRL of the CA", | ||
description: "Get CRL in DER format", | ||
params: z.object({ | ||
caId: z.string().trim().describe(CERTIFICATE_AUTHORITIES.GET_CRL.caId) | ||
crlId: z.string().trim().describe(CA_CRLS.GET.crlId) | ||
}), | ||
response: { | ||
200: z.object({ | ||
crl: z.string().describe(CERTIFICATE_AUTHORITIES.GET_CRL.crl) | ||
}) | ||
200: z.instanceof(Buffer) | ||
} | ||
}, | ||
handler: async (req) => { | ||
const { crl, ca } = await server.services.certificateAuthorityCrl.getCaCrl({ | ||
caId: req.params.caId, | ||
actor: req.permission.type, | ||
actorId: req.permission.id, | ||
actorAuthMethod: req.permission.authMethod, | ||
actorOrgId: req.permission.orgId | ||
}); | ||
handler: async (req, res) => { | ||
const { crl } = await server.services.certificateAuthorityCrl.getCrlById(req.params.crlId); | ||
|
||
await server.services.auditLog.createAuditLog({ | ||
...req.auditLogInfo, | ||
projectId: ca.projectId, | ||
event: { | ||
type: EventType.GET_CA_CRL, | ||
metadata: { | ||
caId: ca.id, | ||
dn: ca.dn | ||
} | ||
} | ||
}); | ||
res.header("Content-Type", "application/pkix-crl"); | ||
|
||
return { | ||
crl | ||
}; | ||
return Buffer.from(crl); | ||
} | ||
}); | ||
|
||
// server.route({ | ||
// method: "GET", | ||
// url: "/:caId/crl/rotate", | ||
// config: { | ||
// rateLimit: writeLimit | ||
// }, | ||
// onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), | ||
// schema: { | ||
// description: "Rotate CRL of the CA", | ||
// params: z.object({ | ||
// caId: z.string().trim() | ||
// }), | ||
// response: { | ||
// 200: z.object({ | ||
// message: z.string() | ||
// }) | ||
// } | ||
// }, | ||
// handler: async (req) => { | ||
// await server.services.certificateAuthority.rotateCaCrl({ | ||
// caId: req.params.caId, | ||
// actor: req.permission.type, | ||
// actorId: req.permission.id, | ||
// actorAuthMethod: req.permission.authMethod, | ||
// actorOrgId: req.permission.orgId | ||
// }); | ||
// return { | ||
// message: "Successfully rotated CA CRL" | ||
// }; | ||
// } | ||
// }); | ||
}; |
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
4 changes: 3 additions & 1 deletion
4
backend/src/ee/services/certificate-authority-crl/certificate-authority-crl-types.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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { TProjectPermission } from "@app/lib/types"; | ||
|
||
export type TGetCrl = { | ||
export type TGetCrlById = string; | ||
|
||
export type TGetCaCrlsDTO = { | ||
caId: string; | ||
} & Omit<TProjectPermission, "projectId">; |
Oops, something went wrong.