mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-11 13:29:12 +00:00
Revert "Root encrypted data to kms encryption"
This commit is contained in:
@@ -23,14 +23,14 @@ export default {
|
|||||||
name: "knex-env",
|
name: "knex-env",
|
||||||
transformMode: "ssr",
|
transformMode: "ssr",
|
||||||
async setup() {
|
async setup() {
|
||||||
const logger = initLogger();
|
const logger = await initLogger();
|
||||||
const envConfig = initEnvConfig(logger);
|
const cfg = initEnvConfig(logger);
|
||||||
const db = initDbConnection({
|
const db = initDbConnection({
|
||||||
dbConnectionUri: envConfig.DB_CONNECTION_URI,
|
dbConnectionUri: cfg.DB_CONNECTION_URI,
|
||||||
dbRootCert: envConfig.DB_ROOT_CERT
|
dbRootCert: cfg.DB_ROOT_CERT
|
||||||
});
|
});
|
||||||
|
|
||||||
const redis = new Redis(envConfig.REDIS_URL);
|
const redis = new Redis(cfg.REDIS_URL);
|
||||||
await redis.flushdb("SYNC");
|
await redis.flushdb("SYNC");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -42,7 +42,6 @@ export default {
|
|||||||
},
|
},
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
await db.migrate.latest({
|
await db.migrate.latest({
|
||||||
directory: path.join(__dirname, "../src/db/migrations"),
|
directory: path.join(__dirname, "../src/db/migrations"),
|
||||||
extension: "ts",
|
extension: "ts",
|
||||||
@@ -53,24 +52,14 @@ export default {
|
|||||||
directory: path.join(__dirname, "../src/db/seeds"),
|
directory: path.join(__dirname, "../src/db/seeds"),
|
||||||
extension: "ts"
|
extension: "ts"
|
||||||
});
|
});
|
||||||
|
|
||||||
const smtp = mockSmtpServer();
|
const smtp = mockSmtpServer();
|
||||||
const queue = queueServiceFactory(envConfig.REDIS_URL, { dbConnectionUrl: envConfig.DB_CONNECTION_URI });
|
const queue = queueServiceFactory(cfg.REDIS_URL, { dbConnectionUrl: cfg.DB_CONNECTION_URI });
|
||||||
const keyStore = keyStoreFactory(envConfig.REDIS_URL);
|
const keyStore = keyStoreFactory(cfg.REDIS_URL);
|
||||||
|
|
||||||
const hsmModule = initializeHsmModule(envConfig);
|
const hsmModule = initializeHsmModule();
|
||||||
hsmModule.initialize();
|
hsmModule.initialize();
|
||||||
|
|
||||||
const server = await main({
|
const server = await main({ db, smtp, logger, queue, keyStore, hsmModule: hsmModule.getModule(), redis });
|
||||||
db,
|
|
||||||
smtp,
|
|
||||||
logger,
|
|
||||||
queue,
|
|
||||||
keyStore,
|
|
||||||
hsmModule: hsmModule.getModule(),
|
|
||||||
redis,
|
|
||||||
envConfig
|
|
||||||
});
|
|
||||||
|
|
||||||
// @ts-expect-error type
|
// @ts-expect-error type
|
||||||
globalThis.testServer = server;
|
globalThis.testServer = server;
|
||||||
@@ -84,8 +73,8 @@ export default {
|
|||||||
organizationId: seedData1.organization.id,
|
organizationId: seedData1.organization.id,
|
||||||
accessVersion: 1
|
accessVersion: 1
|
||||||
},
|
},
|
||||||
envConfig.AUTH_SECRET,
|
cfg.AUTH_SECRET,
|
||||||
{ expiresIn: envConfig.JWT_AUTH_LIFETIME }
|
{ expiresIn: cfg.JWT_AUTH_LIFETIME }
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
@@ -120,4 +109,3 @@ export default {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+14
-14
@@ -45,21 +45,21 @@
|
|||||||
"test:e2e-coverage": "vitest run --coverage -c vitest.e2e.config.ts",
|
"test:e2e-coverage": "vitest run --coverage -c vitest.e2e.config.ts",
|
||||||
"generate:component": "tsx ./scripts/create-backend-file.ts",
|
"generate:component": "tsx ./scripts/create-backend-file.ts",
|
||||||
"generate:schema": "tsx ./scripts/generate-schema-types.ts && eslint --fix --ext ts ./src/db/schemas",
|
"generate:schema": "tsx ./scripts/generate-schema-types.ts && eslint --fix --ext ts ./src/db/schemas",
|
||||||
"auditlog-migration:latest": "knex --knexfile ./src/db/auditlog-knexfile.mjs --client pg migrate:latest",
|
"auditlog-migration:latest": "knex --knexfile ./src/db/auditlog-knexfile.ts --client pg migrate:latest",
|
||||||
"auditlog-migration:up": "knex --knexfile ./dist/db/auditlog-knexfile.mjs --client pg migrate:up",
|
"auditlog-migration:up": "knex --knexfile ./src/db/auditlog-knexfile.ts --client pg migrate:up",
|
||||||
"auditlog-migration:down": "knex --knexfile ./dist/db/auditlog-knexfile.mjs --client pg migrate:down",
|
"auditlog-migration:down": "knex --knexfile ./src/db/auditlog-knexfile.ts --client pg migrate:down",
|
||||||
"auditlog-migration:list": "knex --knexfile ./dist/db/auditlog-knexfile.mjs --client pg migrate:list",
|
"auditlog-migration:list": "knex --knexfile ./src/db/auditlog-knexfile.ts --client pg migrate:list",
|
||||||
"auditlog-migration:status": "knex --knexfile ./dist/db/auditlog-knexfile.mjs --client pg migrate:status",
|
"auditlog-migration:status": "knex --knexfile ./src/db/auditlog-knexfile.ts --client pg migrate:status",
|
||||||
"auditlog-migration:unlock": "knex --knexfile ./dist/db/auditlog-knexfile.mjs migrate:unlock",
|
"auditlog-migration:unlock": "knex --knexfile ./src/db/auditlog-knexfile.ts migrate:unlock",
|
||||||
"auditlog-migration:rollback": "knex --knexfile ./dist/db/auditlog-knexfile.mjs migrate:rollback",
|
"auditlog-migration:rollback": "knex --knexfile ./src/db/auditlog-knexfile.ts migrate:rollback",
|
||||||
"migration:new": "tsx ./scripts/create-migration.ts",
|
"migration:new": "tsx ./scripts/create-migration.ts",
|
||||||
"migration:up": "npm run auditlog-migration:up && knex --knexfile ./dist/db/knexfile.mjs --client pg migrate:up",
|
"migration:up": "npm run auditlog-migration:up && knex --knexfile ./src/db/knexfile.ts --client pg migrate:up",
|
||||||
"migration:down": "npm run auditlog-migration:down && knex --knexfile ./dist/db/knexfile.mjs --client pg migrate:down",
|
"migration:down": "npm run auditlog-migration:down && knex --knexfile ./src/db/knexfile.ts --client pg migrate:down",
|
||||||
"migration:list": "npm run auditlog-migration:list && knex --knexfile ./dist/db/knexfile.mjs --client pg migrate:list",
|
"migration:list": "npm run auditlog-migration:list && knex --knexfile ./src/db/knexfile.ts --client pg migrate:list",
|
||||||
"migration:latest": "node ./dist/db/rename-migrations-to-mjs.mjs && npm run auditlog-migration:latest && knex --knexfile ./dist/db/knexfile.mjs --client pg migrate:latest",
|
"migration:latest": "npm run auditlog-migration:latest && knex --knexfile ./src/db/knexfile.ts --client pg migrate:latest",
|
||||||
"migration:status": "npm run auditlog-migration:status && knex --knexfile ./dist/db/knexfile.mjs --client pg migrate:status",
|
"migration:status": "npm run auditlog-migration:status && knex --knexfile ./src/db/knexfile.ts --client pg migrate:status",
|
||||||
"migration:rollback": "npm run auditlog-migration:rollback && knex --knexfile ./dist/db/knexfile.mjs migrate:rollback",
|
"migration:rollback": "npm run auditlog-migration:rollback && knex --knexfile ./src/db/knexfile.ts migrate:rollback",
|
||||||
"migration:unlock": "npm run auditlog-migration:unlock && knex --knexfile ./dist/db/knexfile.mjs migrate:unlock",
|
"migration:unlock": "npm run auditlog-migration:unlock && knex --knexfile ./src/db/knexfile.ts migrate:unlock",
|
||||||
"migrate:org": "tsx ./scripts/migrate-organization.ts",
|
"migrate:org": "tsx ./scripts/migrate-organization.ts",
|
||||||
"seed:new": "tsx ./scripts/create-seed-file.ts",
|
"seed:new": "tsx ./scripts/create-seed-file.ts",
|
||||||
"seed": "knex --knexfile ./src/db/knexfile.ts --client pg seed:run",
|
"seed": "knex --knexfile ./src/db/knexfile.ts --client pg seed:run",
|
||||||
|
|||||||
Vendored
-6
@@ -93,12 +93,6 @@ import { TUserEngagementServiceFactory } from "@app/services/user-engagement/use
|
|||||||
import { TWebhookServiceFactory } from "@app/services/webhook/webhook-service";
|
import { TWebhookServiceFactory } from "@app/services/webhook/webhook-service";
|
||||||
import { TWorkflowIntegrationServiceFactory } from "@app/services/workflow-integration/workflow-integration-service";
|
import { TWorkflowIntegrationServiceFactory } from "@app/services/workflow-integration/workflow-integration-service";
|
||||||
|
|
||||||
declare module "@fastify/request-context" {
|
|
||||||
interface RequestContextData {
|
|
||||||
reqId: string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "fastify" {
|
declare module "fastify" {
|
||||||
interface Session {
|
interface Session {
|
||||||
callbackPort: string;
|
callbackPort: string;
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
import path from "node:path";
|
|
||||||
|
|
||||||
import dotenv from "dotenv";
|
|
||||||
import { Knex } from "knex";
|
|
||||||
import { Logger } from "pino";
|
|
||||||
|
|
||||||
import { PgSqlLock } from "./keystore/keystore";
|
|
||||||
|
|
||||||
dotenv.config();
|
|
||||||
|
|
||||||
type TArgs = {
|
|
||||||
auditLogDb?: Knex;
|
|
||||||
applicationDb: Knex;
|
|
||||||
logger: Logger;
|
|
||||||
};
|
|
||||||
|
|
||||||
const isProduction = process.env.NODE_ENV === "production";
|
|
||||||
const migrationConfig = {
|
|
||||||
directory: path.join(__dirname, "./db/migrations"),
|
|
||||||
loadExtensions: [".mjs", ".ts"],
|
|
||||||
tableName: "infisical_migrations"
|
|
||||||
};
|
|
||||||
|
|
||||||
const migrationStatusCheckErrorHandler = (err: Error) => {
|
|
||||||
// happens for first time in which the migration table itself is not created yet
|
|
||||||
// error: select * from "infisical_migrations" - relation "infisical_migrations" does not exist
|
|
||||||
if (err?.message?.includes("does not exist")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
throw err;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const runMigrations = async ({ applicationDb, auditLogDb, logger }: TArgs) => {
|
|
||||||
try {
|
|
||||||
// akhilmhdh(Feb 10 2025): 2 years from now remove this
|
|
||||||
if (isProduction) {
|
|
||||||
const migrationTable = migrationConfig.tableName;
|
|
||||||
const hasMigrationTable = await applicationDb.schema.hasTable(migrationTable);
|
|
||||||
if (hasMigrationTable) {
|
|
||||||
const firstFile = (await applicationDb(migrationTable).where({}).first()) as { name: string };
|
|
||||||
if (firstFile?.name?.includes(".ts")) {
|
|
||||||
await applicationDb(migrationTable).update({
|
|
||||||
name: applicationDb.raw("REPLACE(name, '.ts', '.mjs')")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (auditLogDb) {
|
|
||||||
const hasMigrationTableInAuditLog = await auditLogDb.schema.hasTable(migrationTable);
|
|
||||||
if (hasMigrationTableInAuditLog) {
|
|
||||||
const firstFile = (await auditLogDb(migrationTable).where({}).first()) as { name: string };
|
|
||||||
if (firstFile?.name?.includes(".ts")) {
|
|
||||||
await auditLogDb(migrationTable).update({
|
|
||||||
name: auditLogDb.raw("REPLACE(name, '.ts', '.mjs')")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const shouldRunMigration = Boolean(
|
|
||||||
await applicationDb.migrate.status(migrationConfig).catch(migrationStatusCheckErrorHandler)
|
|
||||||
); // db.length - code.length
|
|
||||||
if (!shouldRunMigration) {
|
|
||||||
logger.info("No migrations pending: Skipping migration process.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auditLogDb) {
|
|
||||||
await auditLogDb.transaction(async (tx) => {
|
|
||||||
await tx.raw("SELECT pg_advisory_xact_lock(?)", [PgSqlLock.BootUpMigration]);
|
|
||||||
logger.info("Running audit log migrations.");
|
|
||||||
|
|
||||||
const didPreviousInstanceRunMigration = !(await auditLogDb.migrate
|
|
||||||
.status(migrationConfig)
|
|
||||||
.catch(migrationStatusCheckErrorHandler));
|
|
||||||
if (didPreviousInstanceRunMigration) {
|
|
||||||
logger.info("No audit log migrations pending: Applied by previous instance. Skipping migration process.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await auditLogDb.migrate.latest(migrationConfig);
|
|
||||||
logger.info("Finished audit log migrations.");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await applicationDb.transaction(async (tx) => {
|
|
||||||
await tx.raw("SELECT pg_advisory_xact_lock(?)", [PgSqlLock.BootUpMigration]);
|
|
||||||
logger.info("Running application migrations.");
|
|
||||||
|
|
||||||
const didPreviousInstanceRunMigration = !(await applicationDb.migrate
|
|
||||||
.status(migrationConfig)
|
|
||||||
.catch(migrationStatusCheckErrorHandler));
|
|
||||||
if (didPreviousInstanceRunMigration) {
|
|
||||||
logger.info("No application migrations pending: Applied by previous instance. Skipping migration process.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await applicationDb.migrate.latest(migrationConfig);
|
|
||||||
logger.info("Finished application migrations.");
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
logger.error(err, "Boot up migration failed");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -49,9 +49,6 @@ export const initDbConnection = ({
|
|||||||
ca: Buffer.from(dbRootCert, "base64").toString("ascii")
|
ca: Buffer.from(dbRootCert, "base64").toString("ascii")
|
||||||
}
|
}
|
||||||
: false
|
: false
|
||||||
},
|
|
||||||
migrations: {
|
|
||||||
tableName: "infisical_migrations"
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -67,9 +64,6 @@ export const initDbConnection = ({
|
|||||||
ca: Buffer.from(replicaDbCertificate, "base64").toString("ascii")
|
ca: Buffer.from(replicaDbCertificate, "base64").toString("ascii")
|
||||||
}
|
}
|
||||||
: false
|
: false
|
||||||
},
|
|
||||||
migrations: {
|
|
||||||
tableName: "infisical_migrations"
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -104,9 +98,6 @@ export const initAuditLogDbConnection = ({
|
|||||||
ca: Buffer.from(dbRootCert, "base64").toString("ascii")
|
ca: Buffer.from(dbRootCert, "base64").toString("ascii")
|
||||||
}
|
}
|
||||||
: false
|
: false
|
||||||
},
|
|
||||||
migrations: {
|
|
||||||
tableName: "infisical_migrations"
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ export default {
|
|||||||
directory: "./seeds"
|
directory: "./seeds"
|
||||||
},
|
},
|
||||||
migrations: {
|
migrations: {
|
||||||
tableName: "infisical_migrations",
|
tableName: "infisical_migrations"
|
||||||
loadExtensions: [".mjs"]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
production: {
|
production: {
|
||||||
@@ -63,8 +62,7 @@ export default {
|
|||||||
max: 10
|
max: 10
|
||||||
},
|
},
|
||||||
migrations: {
|
migrations: {
|
||||||
tableName: "infisical_migrations",
|
tableName: "infisical_migrations"
|
||||||
loadExtensions: [".mjs"]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} as Knex.Config;
|
} as Knex.Config;
|
||||||
|
|||||||
@@ -1,127 +0,0 @@
|
|||||||
import { Knex } from "knex";
|
|
||||||
|
|
||||||
import { inMemoryKeyStore } from "@app/keystore/memory";
|
|
||||||
import { infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
|
||||||
import { initLogger } from "@app/lib/logger";
|
|
||||||
import { KmsDataKey } from "@app/services/kms/kms-types";
|
|
||||||
|
|
||||||
import { SecretKeyEncoding, TableName } from "../schemas";
|
|
||||||
import { getMigrationEnvConfig } from "./utils/env-config";
|
|
||||||
import { createCircularCache } from "./utils/ring-buffer";
|
|
||||||
import { getMigrationEncryptionServices } from "./utils/services";
|
|
||||||
|
|
||||||
const BATCH_SIZE = 500;
|
|
||||||
export async function up(knex: Knex): Promise<void> {
|
|
||||||
const hasEncryptedKey = await knex.schema.hasColumn(TableName.Webhook, "encryptedPassKey");
|
|
||||||
const hasEncryptedUrl = await knex.schema.hasColumn(TableName.Webhook, "encryptedUrl");
|
|
||||||
const hasUrl = await knex.schema.hasColumn(TableName.Webhook, "url");
|
|
||||||
|
|
||||||
const hasWebhookTable = await knex.schema.hasTable(TableName.Webhook);
|
|
||||||
if (hasWebhookTable) {
|
|
||||||
await knex.schema.alterTable(TableName.Webhook, (t) => {
|
|
||||||
if (!hasEncryptedKey) t.binary("encryptedPassKey");
|
|
||||||
if (!hasEncryptedUrl) t.binary("encryptedUrl");
|
|
||||||
if (hasUrl) t.string("url").nullable().alter();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
initLogger();
|
|
||||||
const envConfig = getMigrationEnvConfig();
|
|
||||||
const keyStore = inMemoryKeyStore();
|
|
||||||
const { kmsService } = await getMigrationEncryptionServices({ envConfig, keyStore, db: knex });
|
|
||||||
const projectEncryptionRingBuffer =
|
|
||||||
createCircularCache<Awaited<ReturnType<(typeof kmsService)["createCipherPairWithDataKey"]>>>(25);
|
|
||||||
const webhooks = await knex(TableName.Webhook)
|
|
||||||
.where({})
|
|
||||||
.join(TableName.Environment, `${TableName.Environment}.id`, `${TableName.Webhook}.envId`)
|
|
||||||
.select(
|
|
||||||
"url",
|
|
||||||
"encryptedSecretKey",
|
|
||||||
"iv",
|
|
||||||
"tag",
|
|
||||||
"keyEncoding",
|
|
||||||
"urlCipherText",
|
|
||||||
"urlIV",
|
|
||||||
"urlTag",
|
|
||||||
knex.ref("id").withSchema(TableName.Webhook),
|
|
||||||
"envId"
|
|
||||||
)
|
|
||||||
.select(knex.ref("projectId").withSchema(TableName.Environment))
|
|
||||||
.orderBy(`${TableName.Environment}.projectId` as "projectId");
|
|
||||||
|
|
||||||
const updatedWebhooks = await Promise.all(
|
|
||||||
webhooks.map(async (el) => {
|
|
||||||
let projectKmsService = projectEncryptionRingBuffer.getItem(el.projectId);
|
|
||||||
if (!projectKmsService) {
|
|
||||||
projectKmsService = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId: el.projectId
|
|
||||||
}, knex);
|
|
||||||
projectEncryptionRingBuffer.push(el.projectId, projectKmsService);
|
|
||||||
}
|
|
||||||
|
|
||||||
let encryptedSecretKey = null;
|
|
||||||
if (el.encryptedSecretKey && el.iv && el.tag && el.keyEncoding) {
|
|
||||||
const decyptedSecretKey = infisicalSymmetricDecrypt({
|
|
||||||
keyEncoding: el.keyEncoding as SecretKeyEncoding,
|
|
||||||
iv: el.iv,
|
|
||||||
tag: el.tag,
|
|
||||||
ciphertext: el.encryptedSecretKey
|
|
||||||
});
|
|
||||||
encryptedSecretKey = projectKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decyptedSecretKey, "utf8")
|
|
||||||
}).cipherTextBlob;
|
|
||||||
}
|
|
||||||
|
|
||||||
const decryptedUrl =
|
|
||||||
el.urlIV && el.urlTag && el.urlCipherText && el.keyEncoding
|
|
||||||
? infisicalSymmetricDecrypt({
|
|
||||||
keyEncoding: el.keyEncoding as SecretKeyEncoding,
|
|
||||||
iv: el.urlIV,
|
|
||||||
tag: el.urlTag,
|
|
||||||
ciphertext: el.urlCipherText
|
|
||||||
})
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const encryptedUrl = projectKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedUrl || el.url || "")
|
|
||||||
}).cipherTextBlob;
|
|
||||||
return { id: el.id, encryptedUrl, encryptedSecretKey, envId: el.envId };
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
for (let i = 0; i < updatedWebhooks.length; i += BATCH_SIZE) {
|
|
||||||
// eslint-disable-next-line no-await-in-loop
|
|
||||||
await knex(TableName.Webhook)
|
|
||||||
.insert(
|
|
||||||
updatedWebhooks.slice(i, i + BATCH_SIZE).map((el) => ({
|
|
||||||
id: el.id,
|
|
||||||
envId: el.envId,
|
|
||||||
url: "",
|
|
||||||
encryptedUrl: el.encryptedUrl,
|
|
||||||
encryptedPassKey: el.encryptedSecretKey
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
.onConflict("id")
|
|
||||||
.merge();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasWebhookTable) {
|
|
||||||
await knex.schema.alterTable(TableName.Webhook, (t) => {
|
|
||||||
if (!hasEncryptedUrl) t.binary("encryptedUrl").notNullable().alter();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function down(knex: Knex): Promise<void> {
|
|
||||||
const hasEncryptedKey = await knex.schema.hasColumn(TableName.Webhook, "encryptedPassKey");
|
|
||||||
const hasEncryptedUrl = await knex.schema.hasColumn(TableName.Webhook, "encryptedUrl");
|
|
||||||
|
|
||||||
const hasWebhookTable = await knex.schema.hasTable(TableName.Webhook);
|
|
||||||
if (hasWebhookTable) {
|
|
||||||
await knex.schema.alterTable(TableName.Webhook, (t) => {
|
|
||||||
if (hasEncryptedKey) t.dropColumn("encryptedPassKey");
|
|
||||||
if (hasEncryptedUrl) t.dropColumn("encryptedUrl");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
import { Knex } from "knex";
|
|
||||||
|
|
||||||
import { inMemoryKeyStore } from "@app/keystore/memory";
|
|
||||||
import { infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
|
||||||
import { selectAllTableCols } from "@app/lib/knex";
|
|
||||||
import { initLogger } from "@app/lib/logger";
|
|
||||||
import { KmsDataKey } from "@app/services/kms/kms-types";
|
|
||||||
|
|
||||||
import { SecretKeyEncoding, TableName } from "../schemas";
|
|
||||||
import { getMigrationEnvConfig } from "./utils/env-config";
|
|
||||||
import { createCircularCache } from "./utils/ring-buffer";
|
|
||||||
import { getMigrationEncryptionServices } from "./utils/services";
|
|
||||||
|
|
||||||
const BATCH_SIZE = 500;
|
|
||||||
export async function up(knex: Knex): Promise<void> {
|
|
||||||
const hasEncryptedInputColumn = await knex.schema.hasColumn(TableName.DynamicSecret, "encryptedInput");
|
|
||||||
const hasInputCiphertextColumn = await knex.schema.hasColumn(TableName.DynamicSecret, "inputCiphertext");
|
|
||||||
const hasInputIVColumn = await knex.schema.hasColumn(TableName.DynamicSecret, "inputIV");
|
|
||||||
const hasInputTagColumn = await knex.schema.hasColumn(TableName.DynamicSecret, "inputTag");
|
|
||||||
|
|
||||||
const hasDynamicSecretTable = await knex.schema.hasTable(TableName.DynamicSecret);
|
|
||||||
if (hasDynamicSecretTable) {
|
|
||||||
await knex.schema.alterTable(TableName.DynamicSecret, (t) => {
|
|
||||||
if (!hasEncryptedInputColumn) t.binary("encryptedInput");
|
|
||||||
if (hasInputCiphertextColumn) t.text("inputCiphertext").nullable().alter();
|
|
||||||
if (hasInputIVColumn) t.string("inputIV").nullable().alter();
|
|
||||||
if (hasInputTagColumn) t.string("inputTag").nullable().alter();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
initLogger();
|
|
||||||
const envConfig = getMigrationEnvConfig();
|
|
||||||
const keyStore = inMemoryKeyStore();
|
|
||||||
const { kmsService } = await getMigrationEncryptionServices({ envConfig, keyStore, db: knex });
|
|
||||||
const projectEncryptionRingBuffer =
|
|
||||||
createCircularCache<Awaited<ReturnType<(typeof kmsService)["createCipherPairWithDataKey"]>>>(25);
|
|
||||||
|
|
||||||
const dynamicSecretRootCredentials = await knex(TableName.DynamicSecret)
|
|
||||||
.join(TableName.SecretFolder, `${TableName.SecretFolder}.id`, `${TableName.DynamicSecret}.folderId`)
|
|
||||||
.join(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)
|
|
||||||
.select(selectAllTableCols(TableName.DynamicSecret))
|
|
||||||
.select(knex.ref("projectId").withSchema(TableName.Environment))
|
|
||||||
.orderBy(`${TableName.Environment}.projectId` as "projectId");
|
|
||||||
|
|
||||||
const updatedDynamicSecrets = await Promise.all(
|
|
||||||
dynamicSecretRootCredentials.map(async ({ projectId, ...el }) => {
|
|
||||||
let projectKmsService = projectEncryptionRingBuffer.getItem(projectId);
|
|
||||||
if (!projectKmsService) {
|
|
||||||
projectKmsService = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId
|
|
||||||
}, knex);
|
|
||||||
projectEncryptionRingBuffer.push(projectId, projectKmsService);
|
|
||||||
}
|
|
||||||
|
|
||||||
const decryptedInputData =
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
el.inputIV && el.inputTag && el.inputCiphertext && el.keyEncoding
|
|
||||||
? infisicalSymmetricDecrypt({
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
keyEncoding: el.keyEncoding as SecretKeyEncoding,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
iv: el.inputIV,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
tag: el.inputTag,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
ciphertext: el.inputCiphertext
|
|
||||||
})
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const encryptedInput = projectKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedInputData)
|
|
||||||
}).cipherTextBlob;
|
|
||||||
|
|
||||||
return { ...el, encryptedInput };
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
for (let i = 0; i < updatedDynamicSecrets.length; i += BATCH_SIZE) {
|
|
||||||
// eslint-disable-next-line no-await-in-loop
|
|
||||||
await knex(TableName.DynamicSecret)
|
|
||||||
.insert(updatedDynamicSecrets.slice(i, i + BATCH_SIZE))
|
|
||||||
.onConflict("id")
|
|
||||||
.merge();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasDynamicSecretTable) {
|
|
||||||
await knex.schema.alterTable(TableName.DynamicSecret, (t) => {
|
|
||||||
if (!hasEncryptedInputColumn) t.binary("encryptedInput").notNullable().alter();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function down(knex: Knex): Promise<void> {
|
|
||||||
const hasEncryptedInputColumn = await knex.schema.hasColumn(TableName.DynamicSecret, "encryptedInput");
|
|
||||||
|
|
||||||
const hasDynamicSecretTable = await knex.schema.hasTable(TableName.DynamicSecret);
|
|
||||||
if (hasDynamicSecretTable) {
|
|
||||||
await knex.schema.alterTable(TableName.DynamicSecret, (t) => {
|
|
||||||
if (hasEncryptedInputColumn) t.dropColumn("encryptedInput");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
import { Knex } from "knex";
|
|
||||||
|
|
||||||
import { inMemoryKeyStore } from "@app/keystore/memory";
|
|
||||||
import { infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
|
||||||
import { selectAllTableCols } from "@app/lib/knex";
|
|
||||||
import { initLogger } from "@app/lib/logger";
|
|
||||||
import { KmsDataKey } from "@app/services/kms/kms-types";
|
|
||||||
|
|
||||||
import { SecretKeyEncoding, TableName } from "../schemas";
|
|
||||||
import { getMigrationEnvConfig } from "./utils/env-config";
|
|
||||||
import { createCircularCache } from "./utils/ring-buffer";
|
|
||||||
import { getMigrationEncryptionServices } from "./utils/services";
|
|
||||||
|
|
||||||
const BATCH_SIZE = 500;
|
|
||||||
export async function up(knex: Knex): Promise<void> {
|
|
||||||
const hasEncryptedRotationData = await knex.schema.hasColumn(TableName.SecretRotation, "encryptedRotationData");
|
|
||||||
|
|
||||||
const hasRotationTable = await knex.schema.hasTable(TableName.SecretRotation);
|
|
||||||
if (hasRotationTable) {
|
|
||||||
await knex.schema.alterTable(TableName.SecretRotation, (t) => {
|
|
||||||
if (!hasEncryptedRotationData) t.binary("encryptedRotationData");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
initLogger();
|
|
||||||
const envConfig = getMigrationEnvConfig();
|
|
||||||
const keyStore = inMemoryKeyStore();
|
|
||||||
const { kmsService } = await getMigrationEncryptionServices({ envConfig, keyStore, db: knex });
|
|
||||||
const projectEncryptionRingBuffer =
|
|
||||||
createCircularCache<Awaited<ReturnType<(typeof kmsService)["createCipherPairWithDataKey"]>>>(25);
|
|
||||||
|
|
||||||
const secretRotations = await knex(TableName.SecretRotation)
|
|
||||||
.join(TableName.Environment, `${TableName.Environment}.id`, `${TableName.SecretRotation}.envId`)
|
|
||||||
.select(selectAllTableCols(TableName.SecretRotation))
|
|
||||||
.select(knex.ref("projectId").withSchema(TableName.Environment))
|
|
||||||
.orderBy(`${TableName.Environment}.projectId` as "projectId");
|
|
||||||
|
|
||||||
const updatedRotationData = await Promise.all(
|
|
||||||
secretRotations.map(async ({ projectId, ...el }) => {
|
|
||||||
let projectKmsService = projectEncryptionRingBuffer.getItem(projectId);
|
|
||||||
if (!projectKmsService) {
|
|
||||||
projectKmsService = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId
|
|
||||||
}, knex);
|
|
||||||
projectEncryptionRingBuffer.push(projectId, projectKmsService);
|
|
||||||
}
|
|
||||||
|
|
||||||
const decryptedRotationData =
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
el.encryptedDataTag && el.encryptedDataIV && el.encryptedData && el.keyEncoding
|
|
||||||
? infisicalSymmetricDecrypt({
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
keyEncoding: el.keyEncoding as SecretKeyEncoding,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
iv: el.encryptedDataIV,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
tag: el.encryptedDataTag,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
ciphertext: el.encryptedData
|
|
||||||
})
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const encryptedRotationData = projectKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedRotationData)
|
|
||||||
}).cipherTextBlob;
|
|
||||||
return { ...el, encryptedRotationData };
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
for (let i = 0; i < updatedRotationData.length; i += BATCH_SIZE) {
|
|
||||||
// eslint-disable-next-line no-await-in-loop
|
|
||||||
await knex(TableName.SecretRotation)
|
|
||||||
.insert(updatedRotationData.slice(i, i + BATCH_SIZE))
|
|
||||||
.onConflict("id")
|
|
||||||
.merge();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasRotationTable) {
|
|
||||||
await knex.schema.alterTable(TableName.SecretRotation, (t) => {
|
|
||||||
if (!hasEncryptedRotationData) t.binary("encryptedRotationData").notNullable().alter();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function down(knex: Knex): Promise<void> {
|
|
||||||
const hasEncryptedRotationData = await knex.schema.hasColumn(TableName.SecretRotation, "encryptedRotationData");
|
|
||||||
|
|
||||||
const hasRotationTable = await knex.schema.hasTable(TableName.SecretRotation);
|
|
||||||
if (hasRotationTable) {
|
|
||||||
await knex.schema.alterTable(TableName.SecretRotation, (t) => {
|
|
||||||
if (hasEncryptedRotationData) t.dropColumn("encryptedRotationData");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
import { Knex } from "knex";
|
|
||||||
|
|
||||||
import { inMemoryKeyStore } from "@app/keystore/memory";
|
|
||||||
import { decryptSymmetric, infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
|
||||||
import { selectAllTableCols } from "@app/lib/knex";
|
|
||||||
import { initLogger } from "@app/lib/logger";
|
|
||||||
import { KmsDataKey } from "@app/services/kms/kms-types";
|
|
||||||
|
|
||||||
import { SecretKeyEncoding, TableName, TOrgBots } from "../schemas";
|
|
||||||
import { getMigrationEnvConfig } from "./utils/env-config";
|
|
||||||
import { createCircularCache } from "./utils/ring-buffer";
|
|
||||||
import { getMigrationEncryptionServices } from "./utils/services";
|
|
||||||
|
|
||||||
const BATCH_SIZE = 500;
|
|
||||||
const reencryptIdentityK8sAuth = async (knex: Knex) => {
|
|
||||||
const hasEncryptedKubernetesTokenReviewerJwt = await knex.schema.hasColumn(
|
|
||||||
TableName.IdentityKubernetesAuth,
|
|
||||||
"encryptedKubernetesTokenReviewerJwt"
|
|
||||||
);
|
|
||||||
const hasEncryptedCertificateColumn = await knex.schema.hasColumn(
|
|
||||||
TableName.IdentityKubernetesAuth,
|
|
||||||
"encryptedKubernetesCaCertificate"
|
|
||||||
);
|
|
||||||
const hasidentityKubernetesAuthTable = await knex.schema.hasTable(TableName.IdentityKubernetesAuth);
|
|
||||||
|
|
||||||
const hasEncryptedCaCertColumn = await knex.schema.hasColumn(TableName.IdentityKubernetesAuth, "encryptedCaCert");
|
|
||||||
const hasCaCertIVColumn = await knex.schema.hasColumn(TableName.IdentityKubernetesAuth, "caCertIV");
|
|
||||||
const hasCaCertTagColumn = await knex.schema.hasColumn(TableName.IdentityKubernetesAuth, "caCertTag");
|
|
||||||
const hasEncryptedTokenReviewerJwtColumn = await knex.schema.hasColumn(
|
|
||||||
TableName.IdentityKubernetesAuth,
|
|
||||||
"encryptedTokenReviewerJwt"
|
|
||||||
);
|
|
||||||
const hasTokenReviewerJwtIVColumn = await knex.schema.hasColumn(
|
|
||||||
TableName.IdentityKubernetesAuth,
|
|
||||||
"tokenReviewerJwtIV"
|
|
||||||
);
|
|
||||||
const hasTokenReviewerJwtTagColumn = await knex.schema.hasColumn(
|
|
||||||
TableName.IdentityKubernetesAuth,
|
|
||||||
"tokenReviewerJwtTag"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (hasidentityKubernetesAuthTable) {
|
|
||||||
await knex.schema.alterTable(TableName.IdentityKubernetesAuth, (t) => {
|
|
||||||
if (hasEncryptedCaCertColumn) t.text("encryptedCaCert").nullable().alter();
|
|
||||||
if (hasCaCertIVColumn) t.string("caCertIV").nullable().alter();
|
|
||||||
if (hasCaCertTagColumn) t.string("caCertTag").nullable().alter();
|
|
||||||
if (hasEncryptedTokenReviewerJwtColumn) t.text("encryptedTokenReviewerJwt").nullable().alter();
|
|
||||||
if (hasTokenReviewerJwtIVColumn) t.string("tokenReviewerJwtIV").nullable().alter();
|
|
||||||
if (hasTokenReviewerJwtTagColumn) t.string("tokenReviewerJwtTag").nullable().alter();
|
|
||||||
|
|
||||||
if (!hasEncryptedKubernetesTokenReviewerJwt) t.binary("encryptedKubernetesTokenReviewerJwt");
|
|
||||||
if (!hasEncryptedCertificateColumn) t.binary("encryptedKubernetesCaCertificate");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
initLogger();
|
|
||||||
const envConfig = getMigrationEnvConfig();
|
|
||||||
const keyStore = inMemoryKeyStore();
|
|
||||||
const { kmsService } = await getMigrationEncryptionServices({ envConfig, keyStore, db: knex });
|
|
||||||
const orgEncryptionRingBuffer =
|
|
||||||
createCircularCache<Awaited<ReturnType<(typeof kmsService)["createCipherPairWithDataKey"]>>>(25);
|
|
||||||
const identityKubernetesConfigs = await knex(TableName.IdentityKubernetesAuth)
|
|
||||||
.join(
|
|
||||||
TableName.IdentityOrgMembership,
|
|
||||||
`${TableName.IdentityOrgMembership}.identityId`,
|
|
||||||
`${TableName.IdentityKubernetesAuth}.identityId`
|
|
||||||
)
|
|
||||||
.join<TOrgBots>(TableName.OrgBot, `${TableName.OrgBot}.orgId`, `${TableName.IdentityOrgMembership}.orgId`)
|
|
||||||
.select(selectAllTableCols(TableName.IdentityKubernetesAuth))
|
|
||||||
.select(
|
|
||||||
knex.ref("encryptedSymmetricKey").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyIV").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyTag").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyKeyEncoding").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("orgId").withSchema(TableName.OrgBot)
|
|
||||||
)
|
|
||||||
.orderBy(`${TableName.OrgBot}.orgId` as "orgId");
|
|
||||||
|
|
||||||
const updatedIdentityKubernetesConfigs = [];
|
|
||||||
|
|
||||||
for (const { encryptedSymmetricKey, symmetricKeyKeyEncoding, symmetricKeyTag, symmetricKeyIV, orgId, ...el } of identityKubernetesConfigs) {
|
|
||||||
let orgKmsService = orgEncryptionRingBuffer.getItem(orgId);
|
|
||||||
|
|
||||||
if (!orgKmsService) {
|
|
||||||
orgKmsService = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.Organization,
|
|
||||||
orgId
|
|
||||||
}, knex);
|
|
||||||
orgEncryptionRingBuffer.push(orgId, orgKmsService);
|
|
||||||
}
|
|
||||||
|
|
||||||
const key = infisicalSymmetricDecrypt({
|
|
||||||
ciphertext: encryptedSymmetricKey,
|
|
||||||
iv: symmetricKeyIV,
|
|
||||||
tag: symmetricKeyTag,
|
|
||||||
keyEncoding: symmetricKeyKeyEncoding as SecretKeyEncoding
|
|
||||||
});
|
|
||||||
|
|
||||||
const decryptedTokenReviewerJwt =
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
el.encryptedTokenReviewerJwt && el.tokenReviewerJwtIV && el.tokenReviewerJwtTag
|
|
||||||
? decryptSymmetric({
|
|
||||||
key,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
iv: el.tokenReviewerJwtIV,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
tag: el.tokenReviewerJwtTag,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
ciphertext: el.encryptedTokenReviewerJwt
|
|
||||||
})
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const decryptedCertificate =
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
el.encryptedCaCert && el.caCertIV && el.caCertTag
|
|
||||||
? decryptSymmetric({
|
|
||||||
key,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
iv: el.caCertIV,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
tag: el.caCertTag,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
ciphertext: el.encryptedCaCert
|
|
||||||
})
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const encryptedKubernetesTokenReviewerJwt = orgKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedTokenReviewerJwt)
|
|
||||||
}).cipherTextBlob;
|
|
||||||
const encryptedKubernetesCaCertificate = orgKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedCertificate)
|
|
||||||
}).cipherTextBlob;
|
|
||||||
|
|
||||||
updatedIdentityKubernetesConfigs.push({
|
|
||||||
...el,
|
|
||||||
accessTokenTrustedIps: JSON.stringify(el.accessTokenTrustedIps),
|
|
||||||
encryptedKubernetesCaCertificate,
|
|
||||||
encryptedKubernetesTokenReviewerJwt
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < updatedIdentityKubernetesConfigs.length; i += BATCH_SIZE) {
|
|
||||||
// eslint-disable-next-line no-await-in-loop
|
|
||||||
await knex(TableName.IdentityKubernetesAuth)
|
|
||||||
.insert(updatedIdentityKubernetesConfigs.slice(i, i + BATCH_SIZE))
|
|
||||||
.onConflict("id")
|
|
||||||
.merge();
|
|
||||||
}
|
|
||||||
if (hasidentityKubernetesAuthTable) {
|
|
||||||
await knex.schema.alterTable(TableName.IdentityKubernetesAuth, (t) => {
|
|
||||||
if (!hasEncryptedKubernetesTokenReviewerJwt)
|
|
||||||
t.binary("encryptedKubernetesTokenReviewerJwt").notNullable().alter();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function up(knex: Knex): Promise<void> {
|
|
||||||
await reencryptIdentityK8sAuth(knex);
|
|
||||||
}
|
|
||||||
|
|
||||||
const dropIdentityK8sColumns = async (knex: Knex) => {
|
|
||||||
const hasEncryptedKubernetesTokenReviewerJwt = await knex.schema.hasColumn(
|
|
||||||
TableName.IdentityKubernetesAuth,
|
|
||||||
"encryptedKubernetesTokenReviewerJwt"
|
|
||||||
);
|
|
||||||
const hasEncryptedCertificateColumn = await knex.schema.hasColumn(
|
|
||||||
TableName.IdentityKubernetesAuth,
|
|
||||||
"encryptedKubernetesCaCertificate"
|
|
||||||
);
|
|
||||||
const hasidentityKubernetesAuthTable = await knex.schema.hasTable(TableName.IdentityKubernetesAuth);
|
|
||||||
|
|
||||||
if (hasidentityKubernetesAuthTable) {
|
|
||||||
await knex.schema.alterTable(TableName.IdentityKubernetesAuth, (t) => {
|
|
||||||
if (hasEncryptedKubernetesTokenReviewerJwt) t.dropColumn("encryptedKubernetesTokenReviewerJwt");
|
|
||||||
if (hasEncryptedCertificateColumn) t.dropColumn("encryptedKubernetesCaCertificate");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function down(knex: Knex): Promise<void> {
|
|
||||||
await dropIdentityK8sColumns(knex);
|
|
||||||
}
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
import { Knex } from "knex";
|
|
||||||
|
|
||||||
import { inMemoryKeyStore } from "@app/keystore/memory";
|
|
||||||
import { decryptSymmetric, infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
|
||||||
import { selectAllTableCols } from "@app/lib/knex";
|
|
||||||
import { initLogger } from "@app/lib/logger";
|
|
||||||
import { KmsDataKey } from "@app/services/kms/kms-types";
|
|
||||||
|
|
||||||
import { SecretKeyEncoding, TableName, TOrgBots } from "../schemas";
|
|
||||||
import { getMigrationEnvConfig } from "./utils/env-config";
|
|
||||||
import { createCircularCache } from "./utils/ring-buffer";
|
|
||||||
import { getMigrationEncryptionServices } from "./utils/services";
|
|
||||||
|
|
||||||
const BATCH_SIZE = 500;
|
|
||||||
const reencryptIdentityOidcAuth = async (knex: Knex) => {
|
|
||||||
const hasEncryptedCertificateColumn = await knex.schema.hasColumn(
|
|
||||||
TableName.IdentityOidcAuth,
|
|
||||||
"encryptedCaCertificate"
|
|
||||||
);
|
|
||||||
const hasidentityOidcAuthTable = await knex.schema.hasTable(TableName.IdentityOidcAuth);
|
|
||||||
|
|
||||||
const hasEncryptedCaCertColumn = await knex.schema.hasColumn(TableName.IdentityOidcAuth, "encryptedCaCert");
|
|
||||||
const hasCaCertIVColumn = await knex.schema.hasColumn(TableName.IdentityOidcAuth, "caCertIV");
|
|
||||||
const hasCaCertTagColumn = await knex.schema.hasColumn(TableName.IdentityOidcAuth, "caCertTag");
|
|
||||||
|
|
||||||
if (hasidentityOidcAuthTable) {
|
|
||||||
await knex.schema.alterTable(TableName.IdentityOidcAuth, (t) => {
|
|
||||||
if (hasEncryptedCaCertColumn) t.text("encryptedCaCert").nullable().alter();
|
|
||||||
if (hasCaCertIVColumn) t.string("caCertIV").nullable().alter();
|
|
||||||
if (hasCaCertTagColumn) t.string("caCertTag").nullable().alter();
|
|
||||||
|
|
||||||
if (!hasEncryptedCertificateColumn) t.binary("encryptedCaCertificate");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
initLogger();
|
|
||||||
const envConfig = getMigrationEnvConfig();
|
|
||||||
const keyStore = inMemoryKeyStore();
|
|
||||||
const { kmsService } = await getMigrationEncryptionServices({ envConfig, keyStore, db: knex });
|
|
||||||
const orgEncryptionRingBuffer =
|
|
||||||
createCircularCache<Awaited<ReturnType<(typeof kmsService)["createCipherPairWithDataKey"]>>>(25);
|
|
||||||
|
|
||||||
const identityOidcConfig = await knex(TableName.IdentityOidcAuth)
|
|
||||||
.join(
|
|
||||||
TableName.IdentityOrgMembership,
|
|
||||||
`${TableName.IdentityOrgMembership}.identityId`,
|
|
||||||
`${TableName.IdentityOidcAuth}.identityId`
|
|
||||||
)
|
|
||||||
.join<TOrgBots>(TableName.OrgBot, `${TableName.OrgBot}.orgId`, `${TableName.IdentityOrgMembership}.orgId`)
|
|
||||||
.select(selectAllTableCols(TableName.IdentityOidcAuth))
|
|
||||||
.select(
|
|
||||||
knex.ref("encryptedSymmetricKey").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyIV").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyTag").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyKeyEncoding").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("orgId").withSchema(TableName.OrgBot)
|
|
||||||
)
|
|
||||||
.orderBy(`${TableName.OrgBot}.orgId` as "orgId");
|
|
||||||
|
|
||||||
const updatedIdentityOidcConfigs = await Promise.all(
|
|
||||||
identityOidcConfig.map(
|
|
||||||
async ({ encryptedSymmetricKey, symmetricKeyKeyEncoding, symmetricKeyTag, symmetricKeyIV, orgId, ...el }) => {
|
|
||||||
let orgKmsService = orgEncryptionRingBuffer.getItem(orgId);
|
|
||||||
if (!orgKmsService) {
|
|
||||||
orgKmsService = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.Organization,
|
|
||||||
orgId
|
|
||||||
}, knex);
|
|
||||||
orgEncryptionRingBuffer.push(orgId, orgKmsService);
|
|
||||||
}
|
|
||||||
const key = infisicalSymmetricDecrypt({
|
|
||||||
ciphertext: encryptedSymmetricKey,
|
|
||||||
iv: symmetricKeyIV,
|
|
||||||
tag: symmetricKeyTag,
|
|
||||||
keyEncoding: symmetricKeyKeyEncoding as SecretKeyEncoding
|
|
||||||
});
|
|
||||||
|
|
||||||
const decryptedCertificate =
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
el.encryptedCaCert && el.caCertIV && el.caCertTag
|
|
||||||
? decryptSymmetric({
|
|
||||||
key,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
iv: el.caCertIV,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
tag: el.caCertTag,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
ciphertext: el.encryptedCaCert
|
|
||||||
})
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const encryptedCaCertificate = orgKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedCertificate)
|
|
||||||
}).cipherTextBlob;
|
|
||||||
|
|
||||||
return {
|
|
||||||
...el,
|
|
||||||
accessTokenTrustedIps: JSON.stringify(el.accessTokenTrustedIps),
|
|
||||||
encryptedCaCertificate
|
|
||||||
};
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
for (let i = 0; i < updatedIdentityOidcConfigs.length; i += BATCH_SIZE) {
|
|
||||||
// eslint-disable-next-line no-await-in-loop
|
|
||||||
await knex(TableName.IdentityOidcAuth)
|
|
||||||
.insert(updatedIdentityOidcConfigs.slice(i, i + BATCH_SIZE))
|
|
||||||
.onConflict("id")
|
|
||||||
.merge();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function up(knex: Knex): Promise<void> {
|
|
||||||
await reencryptIdentityOidcAuth(knex);
|
|
||||||
}
|
|
||||||
|
|
||||||
const dropIdentityOidcColumns = async (knex: Knex) => {
|
|
||||||
const hasEncryptedCertificateColumn = await knex.schema.hasColumn(
|
|
||||||
TableName.IdentityOidcAuth,
|
|
||||||
"encryptedCaCertificate"
|
|
||||||
);
|
|
||||||
const hasidentityOidcTable = await knex.schema.hasTable(TableName.IdentityOidcAuth);
|
|
||||||
|
|
||||||
if (hasidentityOidcTable) {
|
|
||||||
await knex.schema.alterTable(TableName.IdentityOidcAuth, (t) => {
|
|
||||||
if (hasEncryptedCertificateColumn) t.dropColumn("encryptedCaCertificate");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function down(knex: Knex): Promise<void> {
|
|
||||||
await dropIdentityOidcColumns(knex);
|
|
||||||
}
|
|
||||||
@@ -1,484 +0,0 @@
|
|||||||
import { Knex } from "knex";
|
|
||||||
|
|
||||||
import { inMemoryKeyStore } from "@app/keystore/memory";
|
|
||||||
import { decryptSymmetric, infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
|
||||||
import { selectAllTableCols } from "@app/lib/knex";
|
|
||||||
import { initLogger } from "@app/lib/logger";
|
|
||||||
import { KmsDataKey } from "@app/services/kms/kms-types";
|
|
||||||
|
|
||||||
import { SecretKeyEncoding, TableName } from "../schemas";
|
|
||||||
import { getMigrationEnvConfig } from "./utils/env-config";
|
|
||||||
import { createCircularCache } from "./utils/ring-buffer";
|
|
||||||
import { getMigrationEncryptionServices } from "./utils/services";
|
|
||||||
|
|
||||||
const BATCH_SIZE = 500;
|
|
||||||
const reencryptSamlConfig = async (knex: Knex) => {
|
|
||||||
const hasEncryptedEntrypointColumn = await knex.schema.hasColumn(TableName.SamlConfig, "encryptedSamlEntryPoint");
|
|
||||||
const hasEncryptedIssuerColumn = await knex.schema.hasColumn(TableName.SamlConfig, "encryptedSamlIssuer");
|
|
||||||
const hasEncryptedCertificateColumn = await knex.schema.hasColumn(TableName.SamlConfig, "encryptedSamlCertificate");
|
|
||||||
const hasSamlConfigTable = await knex.schema.hasTable(TableName.SamlConfig);
|
|
||||||
|
|
||||||
if (hasSamlConfigTable) {
|
|
||||||
await knex.schema.alterTable(TableName.SamlConfig, (t) => {
|
|
||||||
if (!hasEncryptedEntrypointColumn) t.binary("encryptedSamlEntryPoint");
|
|
||||||
if (!hasEncryptedIssuerColumn) t.binary("encryptedSamlIssuer");
|
|
||||||
if (!hasEncryptedCertificateColumn) t.binary("encryptedSamlCertificate");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
initLogger();
|
|
||||||
const envConfig = getMigrationEnvConfig();
|
|
||||||
const keyStore = inMemoryKeyStore();
|
|
||||||
const { kmsService } = await getMigrationEncryptionServices({ envConfig, keyStore, db: knex });
|
|
||||||
const orgEncryptionRingBuffer =
|
|
||||||
createCircularCache<Awaited<ReturnType<(typeof kmsService)["createCipherPairWithDataKey"]>>>(25);
|
|
||||||
|
|
||||||
const samlConfigs = await knex(TableName.SamlConfig)
|
|
||||||
.join(TableName.OrgBot, `${TableName.OrgBot}.orgId`, `${TableName.SamlConfig}.orgId`)
|
|
||||||
.select(selectAllTableCols(TableName.SamlConfig))
|
|
||||||
.select(
|
|
||||||
knex.ref("encryptedSymmetricKey").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyIV").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyTag").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyKeyEncoding").withSchema(TableName.OrgBot)
|
|
||||||
)
|
|
||||||
.orderBy(`${TableName.OrgBot}.orgId` as "orgId");
|
|
||||||
|
|
||||||
const updatedSamlConfigs = await Promise.all(
|
|
||||||
samlConfigs.map(
|
|
||||||
async ({ encryptedSymmetricKey, symmetricKeyKeyEncoding, symmetricKeyTag, symmetricKeyIV, ...el }) => {
|
|
||||||
let orgKmsService = orgEncryptionRingBuffer.getItem(el.orgId);
|
|
||||||
if (!orgKmsService) {
|
|
||||||
orgKmsService = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.Organization,
|
|
||||||
orgId: el.orgId
|
|
||||||
}, knex);
|
|
||||||
orgEncryptionRingBuffer.push(el.orgId, orgKmsService);
|
|
||||||
}
|
|
||||||
const key = infisicalSymmetricDecrypt({
|
|
||||||
ciphertext: encryptedSymmetricKey,
|
|
||||||
iv: symmetricKeyIV,
|
|
||||||
tag: symmetricKeyTag,
|
|
||||||
keyEncoding: symmetricKeyKeyEncoding as SecretKeyEncoding
|
|
||||||
});
|
|
||||||
|
|
||||||
const decryptedEntryPoint =
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
el.encryptedEntryPoint && el.entryPointIV && el.entryPointTag
|
|
||||||
? decryptSymmetric({
|
|
||||||
key,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
iv: el.entryPointIV,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
tag: el.entryPointTag,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
ciphertext: el.encryptedEntryPoint
|
|
||||||
})
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const decryptedIssuer =
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
el.encryptedIssuer && el.issuerIV && el.issuerTag
|
|
||||||
? decryptSymmetric({
|
|
||||||
key,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
iv: el.issuerIV,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
tag: el.issuerTag,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
ciphertext: el.encryptedIssuer
|
|
||||||
})
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const decryptedCertificate =
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
el.encryptedCert && el.certIV && el.certTag
|
|
||||||
? decryptSymmetric({
|
|
||||||
key,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
iv: el.certIV,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
tag: el.certTag,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
ciphertext: el.encryptedCert
|
|
||||||
})
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const encryptedSamlIssuer = orgKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedIssuer)
|
|
||||||
}).cipherTextBlob;
|
|
||||||
const encryptedSamlCertificate = orgKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedCertificate)
|
|
||||||
}).cipherTextBlob;
|
|
||||||
const encryptedSamlEntryPoint = orgKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedEntryPoint)
|
|
||||||
}).cipherTextBlob;
|
|
||||||
return { ...el, encryptedSamlCertificate, encryptedSamlEntryPoint, encryptedSamlIssuer };
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
for (let i = 0; i < updatedSamlConfigs.length; i += BATCH_SIZE) {
|
|
||||||
// eslint-disable-next-line no-await-in-loop
|
|
||||||
await knex(TableName.SamlConfig)
|
|
||||||
.insert(updatedSamlConfigs.slice(i, i + BATCH_SIZE))
|
|
||||||
.onConflict("id")
|
|
||||||
.merge();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasSamlConfigTable) {
|
|
||||||
await knex.schema.alterTable(TableName.SamlConfig, (t) => {
|
|
||||||
if (!hasEncryptedEntrypointColumn) t.binary("encryptedSamlEntryPoint").notNullable().alter();
|
|
||||||
if (!hasEncryptedIssuerColumn) t.binary("encryptedSamlIssuer").notNullable().alter();
|
|
||||||
if (!hasEncryptedCertificateColumn) t.binary("encryptedSamlCertificate").notNullable().alter();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const reencryptLdapConfig = async (knex: Knex) => {
|
|
||||||
const hasEncryptedLdapBindDNColum = await knex.schema.hasColumn(TableName.LdapConfig, "encryptedLdapBindDN");
|
|
||||||
const hasEncryptedLdapBindPassColumn = await knex.schema.hasColumn(TableName.LdapConfig, "encryptedLdapBindPass");
|
|
||||||
const hasEncryptedCertificateColumn = await knex.schema.hasColumn(TableName.LdapConfig, "encryptedLdapCaCertificate");
|
|
||||||
const hasLdapConfigTable = await knex.schema.hasTable(TableName.LdapConfig);
|
|
||||||
|
|
||||||
const hasEncryptedCACertColumn = await knex.schema.hasColumn(TableName.LdapConfig, "encryptedCACert");
|
|
||||||
const hasCaCertIVColumn = await knex.schema.hasColumn(TableName.LdapConfig, "caCertIV");
|
|
||||||
const hasCaCertTagColumn = await knex.schema.hasColumn(TableName.LdapConfig, "caCertTag");
|
|
||||||
const hasEncryptedBindPassColumn = await knex.schema.hasColumn(TableName.LdapConfig, "encryptedBindPass");
|
|
||||||
const hasBindPassIVColumn = await knex.schema.hasColumn(TableName.LdapConfig, "bindPassIV");
|
|
||||||
const hasBindPassTagColumn = await knex.schema.hasColumn(TableName.LdapConfig, "bindPassTag");
|
|
||||||
const hasEncryptedBindDNColumn = await knex.schema.hasColumn(TableName.LdapConfig, "encryptedBindDN");
|
|
||||||
const hasBindDNIVColumn = await knex.schema.hasColumn(TableName.LdapConfig, "bindDNIV");
|
|
||||||
const hasBindDNTagColumn = await knex.schema.hasColumn(TableName.LdapConfig, "bindDNTag");
|
|
||||||
|
|
||||||
if (hasLdapConfigTable) {
|
|
||||||
await knex.schema.alterTable(TableName.LdapConfig, (t) => {
|
|
||||||
if (hasEncryptedCACertColumn) t.text("encryptedCACert").nullable().alter();
|
|
||||||
if (hasCaCertIVColumn) t.string("caCertIV").nullable().alter();
|
|
||||||
if (hasCaCertTagColumn) t.string("caCertTag").nullable().alter();
|
|
||||||
if (hasEncryptedBindPassColumn) t.string("encryptedBindPass").nullable().alter();
|
|
||||||
if (hasBindPassIVColumn) t.string("bindPassIV").nullable().alter();
|
|
||||||
if (hasBindPassTagColumn) t.string("bindPassTag").nullable().alter();
|
|
||||||
if (hasEncryptedBindDNColumn) t.string("encryptedBindDN").nullable().alter();
|
|
||||||
if (hasBindDNIVColumn) t.string("bindDNIV").nullable().alter();
|
|
||||||
if (hasBindDNTagColumn) t.string("bindDNTag").nullable().alter();
|
|
||||||
|
|
||||||
if (!hasEncryptedLdapBindDNColum) t.binary("encryptedLdapBindDN");
|
|
||||||
if (!hasEncryptedLdapBindPassColumn) t.binary("encryptedLdapBindPass");
|
|
||||||
if (!hasEncryptedCertificateColumn) t.binary("encryptedLdapCaCertificate");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
initLogger();
|
|
||||||
const envConfig = getMigrationEnvConfig();
|
|
||||||
const keyStore = inMemoryKeyStore();
|
|
||||||
const { kmsService } = await getMigrationEncryptionServices({ envConfig, keyStore, db: knex });
|
|
||||||
const orgEncryptionRingBuffer =
|
|
||||||
createCircularCache<Awaited<ReturnType<(typeof kmsService)["createCipherPairWithDataKey"]>>>(25);
|
|
||||||
|
|
||||||
const ldapConfigs = await knex(TableName.LdapConfig)
|
|
||||||
.join(TableName.OrgBot, `${TableName.OrgBot}.orgId`, `${TableName.LdapConfig}.orgId`)
|
|
||||||
.select(selectAllTableCols(TableName.LdapConfig))
|
|
||||||
.select(
|
|
||||||
knex.ref("encryptedSymmetricKey").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyIV").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyTag").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyKeyEncoding").withSchema(TableName.OrgBot)
|
|
||||||
)
|
|
||||||
.orderBy(`${TableName.OrgBot}.orgId` as "orgId");
|
|
||||||
|
|
||||||
const updatedLdapConfigs = await Promise.all(
|
|
||||||
ldapConfigs.map(
|
|
||||||
async ({ encryptedSymmetricKey, symmetricKeyKeyEncoding, symmetricKeyTag, symmetricKeyIV, ...el }) => {
|
|
||||||
let orgKmsService = orgEncryptionRingBuffer.getItem(el.orgId);
|
|
||||||
if (!orgKmsService) {
|
|
||||||
orgKmsService = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.Organization,
|
|
||||||
orgId: el.orgId
|
|
||||||
}, knex);
|
|
||||||
orgEncryptionRingBuffer.push(el.orgId, orgKmsService);
|
|
||||||
}
|
|
||||||
const key = infisicalSymmetricDecrypt({
|
|
||||||
ciphertext: encryptedSymmetricKey,
|
|
||||||
iv: symmetricKeyIV,
|
|
||||||
tag: symmetricKeyTag,
|
|
||||||
keyEncoding: symmetricKeyKeyEncoding as SecretKeyEncoding
|
|
||||||
});
|
|
||||||
|
|
||||||
const decryptedBindDN =
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
el.encryptedBindDN && el.bindDNIV && el.bindDNTag
|
|
||||||
? decryptSymmetric({
|
|
||||||
key,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
iv: el.bindDNIV,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
tag: el.bindDNTag,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
ciphertext: el.encryptedBindDN
|
|
||||||
})
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const decryptedBindPass =
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
el.encryptedBindPass && el.bindPassIV && el.bindPassTag
|
|
||||||
? decryptSymmetric({
|
|
||||||
key,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
iv: el.bindPassIV,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
tag: el.bindPassTag,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
ciphertext: el.encryptedBindPass
|
|
||||||
})
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const decryptedCertificate =
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
el.encryptedCACert && el.caCertIV && el.caCertTag
|
|
||||||
? decryptSymmetric({
|
|
||||||
key,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
iv: el.caCertIV,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
tag: el.caCertTag,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
ciphertext: el.encryptedCACert
|
|
||||||
})
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const encryptedLdapBindDN = orgKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedBindDN)
|
|
||||||
}).cipherTextBlob;
|
|
||||||
const encryptedLdapBindPass = orgKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedBindPass)
|
|
||||||
}).cipherTextBlob;
|
|
||||||
const encryptedLdapCaCertificate = orgKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedCertificate)
|
|
||||||
}).cipherTextBlob;
|
|
||||||
return { ...el, encryptedLdapBindPass, encryptedLdapBindDN, encryptedLdapCaCertificate };
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
for (let i = 0; i < updatedLdapConfigs.length; i += BATCH_SIZE) {
|
|
||||||
// eslint-disable-next-line no-await-in-loop
|
|
||||||
await knex(TableName.LdapConfig)
|
|
||||||
.insert(updatedLdapConfigs.slice(i, i + BATCH_SIZE))
|
|
||||||
.onConflict("id")
|
|
||||||
.merge();
|
|
||||||
}
|
|
||||||
if (hasLdapConfigTable) {
|
|
||||||
await knex.schema.alterTable(TableName.LdapConfig, (t) => {
|
|
||||||
if (!hasEncryptedLdapBindPassColumn) t.binary("encryptedLdapBindPass").notNullable().alter();
|
|
||||||
if (!hasEncryptedLdapBindDNColum) t.binary("encryptedLdapBindDN").notNullable().alter();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const reencryptOidcConfig = async (knex: Knex) => {
|
|
||||||
const hasEncryptedOidcClientIdColumn = await knex.schema.hasColumn(TableName.OidcConfig, "encryptedOidcClientId");
|
|
||||||
const hasEncryptedOidcClientSecretColumn = await knex.schema.hasColumn(
|
|
||||||
TableName.OidcConfig,
|
|
||||||
"encryptedOidcClientSecret"
|
|
||||||
);
|
|
||||||
|
|
||||||
const hasEncryptedClientIdColumn = await knex.schema.hasColumn(TableName.OidcConfig, "encryptedClientId");
|
|
||||||
const hasClientIdIVColumn = await knex.schema.hasColumn(TableName.OidcConfig, "clientIdIV");
|
|
||||||
const hasClientIdTagColumn = await knex.schema.hasColumn(TableName.OidcConfig, "clientIdTag");
|
|
||||||
const hasEncryptedClientSecretColumn = await knex.schema.hasColumn(TableName.OidcConfig, "encryptedClientSecret");
|
|
||||||
const hasClientSecretIVColumn = await knex.schema.hasColumn(TableName.OidcConfig, "clientSecretIV");
|
|
||||||
const hasClientSecretTagColumn = await knex.schema.hasColumn(TableName.OidcConfig, "clientSecretTag");
|
|
||||||
|
|
||||||
const hasOidcConfigTable = await knex.schema.hasTable(TableName.OidcConfig);
|
|
||||||
|
|
||||||
if (hasOidcConfigTable) {
|
|
||||||
await knex.schema.alterTable(TableName.OidcConfig, (t) => {
|
|
||||||
if (hasEncryptedClientIdColumn) t.text("encryptedClientId").nullable().alter();
|
|
||||||
if (hasClientIdIVColumn) t.string("clientIdIV").nullable().alter();
|
|
||||||
if (hasClientIdTagColumn) t.string("clientIdTag").nullable().alter();
|
|
||||||
if (hasEncryptedClientSecretColumn) t.text("encryptedClientSecret").nullable().alter();
|
|
||||||
if (hasClientSecretIVColumn) t.string("clientSecretIV").nullable().alter();
|
|
||||||
if (hasClientSecretTagColumn) t.string("clientSecretTag").nullable().alter();
|
|
||||||
|
|
||||||
if (!hasEncryptedOidcClientIdColumn) t.binary("encryptedOidcClientId");
|
|
||||||
if (!hasEncryptedOidcClientSecretColumn) t.binary("encryptedOidcClientSecret");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
initLogger();
|
|
||||||
const envConfig = getMigrationEnvConfig();
|
|
||||||
const keyStore = inMemoryKeyStore();
|
|
||||||
const { kmsService } = await getMigrationEncryptionServices({ envConfig, keyStore, db: knex });
|
|
||||||
const orgEncryptionRingBuffer =
|
|
||||||
createCircularCache<Awaited<ReturnType<(typeof kmsService)["createCipherPairWithDataKey"]>>>(25);
|
|
||||||
|
|
||||||
const oidcConfigs = await knex(TableName.OidcConfig)
|
|
||||||
.join(TableName.OrgBot, `${TableName.OrgBot}.orgId`, `${TableName.OidcConfig}.orgId`)
|
|
||||||
.select(selectAllTableCols(TableName.OidcConfig))
|
|
||||||
.select(
|
|
||||||
knex.ref("encryptedSymmetricKey").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyIV").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyTag").withSchema(TableName.OrgBot),
|
|
||||||
knex.ref("symmetricKeyKeyEncoding").withSchema(TableName.OrgBot)
|
|
||||||
)
|
|
||||||
.orderBy(`${TableName.OrgBot}.orgId` as "orgId");
|
|
||||||
|
|
||||||
const updatedOidcConfigs = await Promise.all(
|
|
||||||
oidcConfigs.map(
|
|
||||||
async ({ encryptedSymmetricKey, symmetricKeyKeyEncoding, symmetricKeyTag, symmetricKeyIV, ...el }) => {
|
|
||||||
let orgKmsService = orgEncryptionRingBuffer.getItem(el.orgId);
|
|
||||||
if (!orgKmsService) {
|
|
||||||
orgKmsService = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.Organization,
|
|
||||||
orgId: el.orgId
|
|
||||||
}, knex);
|
|
||||||
orgEncryptionRingBuffer.push(el.orgId, orgKmsService);
|
|
||||||
}
|
|
||||||
const key = infisicalSymmetricDecrypt({
|
|
||||||
ciphertext: encryptedSymmetricKey,
|
|
||||||
iv: symmetricKeyIV,
|
|
||||||
tag: symmetricKeyTag,
|
|
||||||
keyEncoding: symmetricKeyKeyEncoding as SecretKeyEncoding
|
|
||||||
});
|
|
||||||
|
|
||||||
const decryptedClientId =
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
el.encryptedClientId && el.clientIdIV && el.clientIdTag
|
|
||||||
? decryptSymmetric({
|
|
||||||
key,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
iv: el.clientIdIV,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
tag: el.clientIdTag,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
ciphertext: el.encryptedClientId
|
|
||||||
})
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const decryptedClientSecret =
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
el.encryptedClientSecret && el.clientSecretIV && el.clientSecretTag
|
|
||||||
? decryptSymmetric({
|
|
||||||
key,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
iv: el.clientSecretIV,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
tag: el.clientSecretTag,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore This will be removed in next cycle so ignore the ts missing error
|
|
||||||
ciphertext: el.encryptedClientSecret
|
|
||||||
})
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const encryptedOidcClientId = orgKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedClientId)
|
|
||||||
}).cipherTextBlob;
|
|
||||||
const encryptedOidcClientSecret = orgKmsService.encryptor({
|
|
||||||
plainText: Buffer.from(decryptedClientSecret)
|
|
||||||
}).cipherTextBlob;
|
|
||||||
return { ...el, encryptedOidcClientId, encryptedOidcClientSecret };
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
for (let i = 0; i < updatedOidcConfigs.length; i += BATCH_SIZE) {
|
|
||||||
// eslint-disable-next-line no-await-in-loop
|
|
||||||
await knex(TableName.OidcConfig)
|
|
||||||
.insert(updatedOidcConfigs.slice(i, i + BATCH_SIZE))
|
|
||||||
.onConflict("id")
|
|
||||||
.merge();
|
|
||||||
}
|
|
||||||
if (hasOidcConfigTable) {
|
|
||||||
await knex.schema.alterTable(TableName.OidcConfig, (t) => {
|
|
||||||
if (!hasEncryptedOidcClientIdColumn) t.binary("encryptedOidcClientId").notNullable().alter();
|
|
||||||
if (!hasEncryptedOidcClientSecretColumn) t.binary("encryptedOidcClientSecret").notNullable().alter();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function up(knex: Knex): Promise<void> {
|
|
||||||
await reencryptSamlConfig(knex);
|
|
||||||
await reencryptLdapConfig(knex);
|
|
||||||
await reencryptOidcConfig(knex);
|
|
||||||
}
|
|
||||||
|
|
||||||
const dropSamlConfigColumns = async (knex: Knex) => {
|
|
||||||
const hasEncryptedEntrypointColumn = await knex.schema.hasColumn(TableName.SamlConfig, "encryptedSamlEntryPoint");
|
|
||||||
const hasEncryptedIssuerColumn = await knex.schema.hasColumn(TableName.SamlConfig, "encryptedSamlIssuer");
|
|
||||||
const hasEncryptedCertificateColumn = await knex.schema.hasColumn(TableName.SamlConfig, "encryptedSamlCertificate");
|
|
||||||
const hasSamlConfigTable = await knex.schema.hasTable(TableName.SamlConfig);
|
|
||||||
|
|
||||||
if (hasSamlConfigTable) {
|
|
||||||
await knex.schema.alterTable(TableName.SamlConfig, (t) => {
|
|
||||||
if (hasEncryptedEntrypointColumn) t.dropColumn("encryptedSamlEntryPoint");
|
|
||||||
if (hasEncryptedIssuerColumn) t.dropColumn("encryptedSamlIssuer");
|
|
||||||
if (hasEncryptedCertificateColumn) t.dropColumn("encryptedSamlCertificate");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const dropLdapConfigColumns = async (knex: Knex) => {
|
|
||||||
const hasEncryptedBindDN = await knex.schema.hasColumn(TableName.LdapConfig, "encryptedLdapBindDN");
|
|
||||||
const hasEncryptedBindPass = await knex.schema.hasColumn(TableName.LdapConfig, "encryptedLdapBindPass");
|
|
||||||
const hasEncryptedCertificateColumn = await knex.schema.hasColumn(TableName.LdapConfig, "encryptedLdapCaCertificate");
|
|
||||||
const hasLdapConfigTable = await knex.schema.hasTable(TableName.LdapConfig);
|
|
||||||
|
|
||||||
if (hasLdapConfigTable) {
|
|
||||||
await knex.schema.alterTable(TableName.LdapConfig, (t) => {
|
|
||||||
if (hasEncryptedBindDN) t.dropColumn("encryptedLdapBindDN");
|
|
||||||
if (hasEncryptedBindPass) t.dropColumn("encryptedLdapBindPass");
|
|
||||||
if (hasEncryptedCertificateColumn) t.dropColumn("encryptedLdapCaCertificate");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const dropOidcConfigColumns = async (knex: Knex) => {
|
|
||||||
const hasEncryptedClientId = await knex.schema.hasColumn(TableName.OidcConfig, "encryptedOidcClientId");
|
|
||||||
const hasEncryptedClientSecret = await knex.schema.hasColumn(TableName.OidcConfig, "encryptedOidcClientSecret");
|
|
||||||
const hasOidcConfigTable = await knex.schema.hasTable(TableName.OidcConfig);
|
|
||||||
|
|
||||||
if (hasOidcConfigTable) {
|
|
||||||
await knex.schema.alterTable(TableName.OidcConfig, (t) => {
|
|
||||||
if (hasEncryptedClientId) t.dropColumn("encryptedOidcClientId");
|
|
||||||
if (hasEncryptedClientSecret) t.dropColumn("encryptedOidcClientSecret");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function down(knex: Knex): Promise<void> {
|
|
||||||
await dropSamlConfigColumns(knex);
|
|
||||||
await dropLdapConfigColumns(knex);
|
|
||||||
await dropOidcConfigColumns(knex);
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
import { z } from "zod";
|
|
||||||
|
|
||||||
import { zpStr } from "@app/lib/zod";
|
|
||||||
|
|
||||||
const envSchema = z
|
|
||||||
.object({
|
|
||||||
DB_CONNECTION_URI: zpStr(z.string().describe("Postgres database connection string")).default(
|
|
||||||
`postgresql://${process.env.DB_USER}:${process.env.DB_PASSWORD}@${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_NAME}`
|
|
||||||
),
|
|
||||||
DB_ROOT_CERT: zpStr(z.string().describe("Postgres database base64-encoded CA cert").optional()),
|
|
||||||
DB_HOST: zpStr(z.string().describe("Postgres database host").optional()),
|
|
||||||
DB_PORT: zpStr(z.string().describe("Postgres database port").optional()).default("5432"),
|
|
||||||
DB_USER: zpStr(z.string().describe("Postgres database username").optional()),
|
|
||||||
DB_PASSWORD: zpStr(z.string().describe("Postgres database password").optional()),
|
|
||||||
DB_NAME: zpStr(z.string().describe("Postgres database name").optional()),
|
|
||||||
// TODO(akhilmhdh): will be changed to one
|
|
||||||
ENCRYPTION_KEY: zpStr(z.string().optional()),
|
|
||||||
ROOT_ENCRYPTION_KEY: zpStr(z.string().optional()),
|
|
||||||
// HSM
|
|
||||||
HSM_LIB_PATH: zpStr(z.string().optional()),
|
|
||||||
HSM_PIN: zpStr(z.string().optional()),
|
|
||||||
HSM_KEY_LABEL: zpStr(z.string().optional()),
|
|
||||||
HSM_SLOT: z.coerce.number().optional().default(0)
|
|
||||||
})
|
|
||||||
// To ensure that basic encryption is always possible.
|
|
||||||
.refine(
|
|
||||||
(data) => Boolean(data.ENCRYPTION_KEY) || Boolean(data.ROOT_ENCRYPTION_KEY),
|
|
||||||
"Either ENCRYPTION_KEY or ROOT_ENCRYPTION_KEY must be defined."
|
|
||||||
)
|
|
||||||
.transform((data) => ({
|
|
||||||
...data,
|
|
||||||
isHsmConfigured:
|
|
||||||
Boolean(data.HSM_LIB_PATH) && Boolean(data.HSM_PIN) && Boolean(data.HSM_KEY_LABEL) && data.HSM_SLOT !== undefined
|
|
||||||
}));
|
|
||||||
|
|
||||||
export type TMigrationEnvConfig = z.infer<typeof envSchema>;
|
|
||||||
|
|
||||||
export const getMigrationEnvConfig = () => {
|
|
||||||
const parsedEnv = envSchema.safeParse(process.env);
|
|
||||||
if (!parsedEnv.success) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.error("Invalid environment variables. Check the error below");
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.error(
|
|
||||||
"Migration is now automatic at startup. Please remove this step from your workflow and start the application as normal."
|
|
||||||
);
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.error(parsedEnv.error.issues);
|
|
||||||
process.exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Object.freeze(parsedEnv.data);
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
import slugify from "@sindresorhus/slugify";
|
||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
import { TableName } from "@app/db/schemas";
|
||||||
|
import { randomSecureBytes } from "@app/lib/crypto";
|
||||||
|
import { symmetricCipherService, SymmetricEncryption } from "@app/lib/crypto/cipher";
|
||||||
|
import { alphaNumericNanoId } from "@app/lib/nanoid";
|
||||||
|
|
||||||
|
const getInstanceRootKey = async (knex: Knex) => {
|
||||||
|
const encryptionKey = process.env.ENCRYPTION_KEY || process.env.ROOT_ENCRYPTION_KEY;
|
||||||
|
// if root key its base64 encoded
|
||||||
|
const isBase64 = !process.env.ENCRYPTION_KEY;
|
||||||
|
if (!encryptionKey) throw new Error("ENCRYPTION_KEY variable needed for migration");
|
||||||
|
const encryptionKeyBuffer = Buffer.from(encryptionKey, isBase64 ? "base64" : "utf8");
|
||||||
|
|
||||||
|
const KMS_ROOT_CONFIG_UUID = "00000000-0000-0000-0000-000000000000";
|
||||||
|
const kmsRootConfig = await knex(TableName.KmsServerRootConfig).where({ id: KMS_ROOT_CONFIG_UUID }).first();
|
||||||
|
const cipher = symmetricCipherService(SymmetricEncryption.AES_GCM_256);
|
||||||
|
if (kmsRootConfig) {
|
||||||
|
const decryptedRootKey = cipher.decrypt(kmsRootConfig.encryptedRootKey, encryptionKeyBuffer);
|
||||||
|
// set the flag so that other instancen nodes can start
|
||||||
|
return decryptedRootKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newRootKey = randomSecureBytes(32);
|
||||||
|
const encryptedRootKey = cipher.encrypt(newRootKey, encryptionKeyBuffer);
|
||||||
|
await knex(TableName.KmsServerRootConfig).insert({
|
||||||
|
encryptedRootKey,
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// @ts-ignore id is kept as fixed for idempotence and to avoid race condition
|
||||||
|
id: KMS_ROOT_CONFIG_UUID
|
||||||
|
});
|
||||||
|
return encryptedRootKey;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getSecretManagerDataKey = async (knex: Knex, projectId: string) => {
|
||||||
|
const KMS_VERSION = "v01";
|
||||||
|
const KMS_VERSION_BLOB_LENGTH = 3;
|
||||||
|
const cipher = symmetricCipherService(SymmetricEncryption.AES_GCM_256);
|
||||||
|
const project = await knex(TableName.Project).where({ id: projectId }).first();
|
||||||
|
if (!project) throw new Error("Missing project id");
|
||||||
|
|
||||||
|
const ROOT_ENCRYPTION_KEY = await getInstanceRootKey(knex);
|
||||||
|
|
||||||
|
let secretManagerKmsKey;
|
||||||
|
const projectSecretManagerKmsId = project?.kmsSecretManagerKeyId;
|
||||||
|
if (projectSecretManagerKmsId) {
|
||||||
|
const kmsDoc = await knex(TableName.KmsKey)
|
||||||
|
.leftJoin(TableName.InternalKms, `${TableName.KmsKey}.id`, `${TableName.InternalKms}.kmsKeyId`)
|
||||||
|
.where({ [`${TableName.KmsKey}.id` as "id"]: projectSecretManagerKmsId })
|
||||||
|
.first();
|
||||||
|
if (!kmsDoc) throw new Error("missing kms");
|
||||||
|
secretManagerKmsKey = cipher.decrypt(kmsDoc.encryptedKey, ROOT_ENCRYPTION_KEY);
|
||||||
|
} else {
|
||||||
|
const [kmsDoc] = await knex(TableName.KmsKey)
|
||||||
|
.insert({
|
||||||
|
name: slugify(alphaNumericNanoId(8).toLowerCase()),
|
||||||
|
orgId: project.orgId,
|
||||||
|
isReserved: false
|
||||||
|
})
|
||||||
|
.returning("*");
|
||||||
|
|
||||||
|
secretManagerKmsKey = randomSecureBytes(32);
|
||||||
|
const encryptedKeyMaterial = cipher.encrypt(secretManagerKmsKey, ROOT_ENCRYPTION_KEY);
|
||||||
|
await knex(TableName.InternalKms).insert({
|
||||||
|
version: 1,
|
||||||
|
encryptedKey: encryptedKeyMaterial,
|
||||||
|
encryptionAlgorithm: SymmetricEncryption.AES_GCM_256,
|
||||||
|
kmsKeyId: kmsDoc.id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const encryptedSecretManagerDataKey = project?.kmsSecretManagerEncryptedDataKey;
|
||||||
|
let dataKey: Buffer;
|
||||||
|
if (!encryptedSecretManagerDataKey) {
|
||||||
|
dataKey = randomSecureBytes();
|
||||||
|
// the below versioning we do it automatically in kms service
|
||||||
|
const unversionedDataKey = cipher.encrypt(dataKey, secretManagerKmsKey);
|
||||||
|
const versionBlob = Buffer.from(KMS_VERSION, "utf8"); // length is 3
|
||||||
|
await knex(TableName.Project)
|
||||||
|
.where({ id: projectId })
|
||||||
|
.update({
|
||||||
|
kmsSecretManagerEncryptedDataKey: Buffer.concat([unversionedDataKey, versionBlob])
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const cipherTextBlob = encryptedSecretManagerDataKey.subarray(0, -KMS_VERSION_BLOB_LENGTH);
|
||||||
|
dataKey = cipher.decrypt(cipherTextBlob, secretManagerKmsKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
encryptor: ({ plainText }: { plainText: Buffer }) => {
|
||||||
|
const encryptedPlainTextBlob = cipher.encrypt(plainText, dataKey);
|
||||||
|
|
||||||
|
// Buffer#1 encrypted text + Buffer#2 version number
|
||||||
|
const versionBlob = Buffer.from(KMS_VERSION, "utf8"); // length is 3
|
||||||
|
const cipherTextBlob = Buffer.concat([encryptedPlainTextBlob, versionBlob]);
|
||||||
|
return { cipherTextBlob };
|
||||||
|
},
|
||||||
|
decryptor: ({ cipherTextBlob: versionedCipherTextBlob }: { cipherTextBlob: Buffer }) => {
|
||||||
|
const cipherTextBlob = versionedCipherTextBlob.subarray(0, -KMS_VERSION_BLOB_LENGTH);
|
||||||
|
const decryptedBlob = cipher.decrypt(cipherTextBlob, dataKey);
|
||||||
|
return decryptedBlob;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
export const createCircularCache = <T>(bufferSize = 10) => {
|
|
||||||
const bufferItems: { id: string; item: T }[] = [];
|
|
||||||
let bufferIndex = 0;
|
|
||||||
|
|
||||||
const push = (id: string, item: T) => {
|
|
||||||
if (bufferItems.length < bufferSize) {
|
|
||||||
bufferItems.push({ id, item });
|
|
||||||
} else {
|
|
||||||
bufferItems[bufferIndex] = { id, item };
|
|
||||||
}
|
|
||||||
bufferIndex = (bufferIndex + 1) % bufferSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getItem = (id: string) => {
|
|
||||||
return bufferItems.find((i) => i.id === id)?.item;
|
|
||||||
};
|
|
||||||
|
|
||||||
return { push, getItem };
|
|
||||||
};
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
import { Knex } from "knex";
|
|
||||||
|
|
||||||
import { initializeHsmModule } from "@app/ee/services/hsm/hsm-fns";
|
|
||||||
import { hsmServiceFactory } from "@app/ee/services/hsm/hsm-service";
|
|
||||||
import { TKeyStoreFactory } from "@app/keystore/keystore";
|
|
||||||
import { internalKmsDALFactory } from "@app/services/kms/internal-kms-dal";
|
|
||||||
import { kmskeyDALFactory } from "@app/services/kms/kms-key-dal";
|
|
||||||
import { kmsRootConfigDALFactory } from "@app/services/kms/kms-root-config-dal";
|
|
||||||
import { kmsServiceFactory } from "@app/services/kms/kms-service";
|
|
||||||
import { orgDALFactory } from "@app/services/org/org-dal";
|
|
||||||
import { projectDALFactory } from "@app/services/project/project-dal";
|
|
||||||
|
|
||||||
import { TMigrationEnvConfig } from "./env-config";
|
|
||||||
|
|
||||||
type TDependencies = {
|
|
||||||
envConfig: TMigrationEnvConfig;
|
|
||||||
db: Knex;
|
|
||||||
keyStore: TKeyStoreFactory;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getMigrationEncryptionServices = async ({ envConfig, db, keyStore }: TDependencies) => {
|
|
||||||
// eslint-disable-next-line no-param-reassign
|
|
||||||
const hsmModule = initializeHsmModule(envConfig);
|
|
||||||
hsmModule.initialize();
|
|
||||||
|
|
||||||
const hsmService = hsmServiceFactory({
|
|
||||||
hsmModule: hsmModule.getModule(),
|
|
||||||
envConfig
|
|
||||||
});
|
|
||||||
|
|
||||||
const orgDAL = orgDALFactory(db);
|
|
||||||
const kmsRootConfigDAL = kmsRootConfigDALFactory(db);
|
|
||||||
const kmsDAL = kmskeyDALFactory(db);
|
|
||||||
const internalKmsDAL = internalKmsDALFactory(db);
|
|
||||||
const projectDAL = projectDALFactory(db);
|
|
||||||
|
|
||||||
const kmsService = kmsServiceFactory({
|
|
||||||
kmsRootConfigDAL,
|
|
||||||
keyStore,
|
|
||||||
kmsDAL,
|
|
||||||
internalKmsDAL,
|
|
||||||
orgDAL,
|
|
||||||
projectDAL,
|
|
||||||
hsmService,
|
|
||||||
envConfig
|
|
||||||
});
|
|
||||||
|
|
||||||
await hsmService.startService();
|
|
||||||
await kmsService.startService();
|
|
||||||
|
|
||||||
return { kmsService };
|
|
||||||
};
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
import path from "node:path";
|
|
||||||
|
|
||||||
import dotenv from "dotenv";
|
|
||||||
|
|
||||||
import { initAuditLogDbConnection, initDbConnection } from "./instance";
|
|
||||||
|
|
||||||
const isProduction = process.env.NODE_ENV === "production";
|
|
||||||
|
|
||||||
// Update with your config settings. .
|
|
||||||
dotenv.config({
|
|
||||||
path: path.join(__dirname, "../../../.env.migration")
|
|
||||||
});
|
|
||||||
dotenv.config({
|
|
||||||
path: path.join(__dirname, "../../../.env")
|
|
||||||
});
|
|
||||||
|
|
||||||
const runRename = async () => {
|
|
||||||
if (!isProduction) return;
|
|
||||||
const migrationTable = "infisical_migrations";
|
|
||||||
const applicationDb = initDbConnection({
|
|
||||||
dbConnectionUri: process.env.DB_CONNECTION_URI as string,
|
|
||||||
dbRootCert: process.env.DB_ROOT_CERT
|
|
||||||
});
|
|
||||||
|
|
||||||
const auditLogDb = process.env.AUDIT_LOGS_DB_CONNECTION_URI
|
|
||||||
? initAuditLogDbConnection({
|
|
||||||
dbConnectionUri: process.env.AUDIT_LOGS_DB_CONNECTION_URI,
|
|
||||||
dbRootCert: process.env.AUDIT_LOGS_DB_ROOT_CERT
|
|
||||||
})
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const hasMigrationTable = await applicationDb.schema.hasTable(migrationTable);
|
|
||||||
if (hasMigrationTable) {
|
|
||||||
const firstFile = (await applicationDb(migrationTable).where({}).first()) as { name: string };
|
|
||||||
if (firstFile?.name?.includes(".ts")) {
|
|
||||||
await applicationDb(migrationTable).update({
|
|
||||||
name: applicationDb.raw("REPLACE(name, '.ts', '.mjs')")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (auditLogDb) {
|
|
||||||
const hasMigrationTableInAuditLog = await auditLogDb.schema.hasTable(migrationTable);
|
|
||||||
if (hasMigrationTableInAuditLog) {
|
|
||||||
const firstFile = (await auditLogDb(migrationTable).where({}).first()) as { name: string };
|
|
||||||
if (firstFile?.name?.includes(".ts")) {
|
|
||||||
await auditLogDb(migrationTable).update({
|
|
||||||
name: auditLogDb.raw("REPLACE(name, '.ts', '.mjs')")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await applicationDb.destroy();
|
|
||||||
await auditLogDb?.destroy();
|
|
||||||
};
|
|
||||||
|
|
||||||
void runRename();
|
|
||||||
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { zodBuffer } from "@app/lib/zod";
|
|
||||||
|
|
||||||
import { TImmutableDBKeys } from "./models";
|
import { TImmutableDBKeys } from "./models";
|
||||||
|
|
||||||
export const DynamicSecretsSchema = z.object({
|
export const DynamicSecretsSchema = z.object({
|
||||||
@@ -16,17 +14,16 @@ export const DynamicSecretsSchema = z.object({
|
|||||||
type: z.string(),
|
type: z.string(),
|
||||||
defaultTTL: z.string(),
|
defaultTTL: z.string(),
|
||||||
maxTTL: z.string().nullable().optional(),
|
maxTTL: z.string().nullable().optional(),
|
||||||
inputIV: z.string().nullable().optional(),
|
inputIV: z.string(),
|
||||||
inputCiphertext: z.string().nullable().optional(),
|
inputCiphertext: z.string(),
|
||||||
inputTag: z.string().nullable().optional(),
|
inputTag: z.string(),
|
||||||
algorithm: z.string().default("aes-256-gcm"),
|
algorithm: z.string().default("aes-256-gcm"),
|
||||||
keyEncoding: z.string().default("utf8"),
|
keyEncoding: z.string().default("utf8"),
|
||||||
folderId: z.string().uuid(),
|
folderId: z.string().uuid(),
|
||||||
status: z.string().nullable().optional(),
|
status: z.string().nullable().optional(),
|
||||||
statusDetails: z.string().nullable().optional(),
|
statusDetails: z.string().nullable().optional(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date(),
|
updatedAt: z.date()
|
||||||
encryptedInput: zodBuffer
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TDynamicSecrets = z.infer<typeof DynamicSecretsSchema>;
|
export type TDynamicSecrets = z.infer<typeof DynamicSecretsSchema>;
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { zodBuffer } from "@app/lib/zod";
|
|
||||||
|
|
||||||
import { TImmutableDBKeys } from "./models";
|
import { TImmutableDBKeys } from "./models";
|
||||||
|
|
||||||
export const IdentityKubernetesAuthsSchema = z.object({
|
export const IdentityKubernetesAuthsSchema = z.object({
|
||||||
@@ -19,17 +17,15 @@ export const IdentityKubernetesAuthsSchema = z.object({
|
|||||||
updatedAt: z.date(),
|
updatedAt: z.date(),
|
||||||
identityId: z.string().uuid(),
|
identityId: z.string().uuid(),
|
||||||
kubernetesHost: z.string(),
|
kubernetesHost: z.string(),
|
||||||
encryptedCaCert: z.string().nullable().optional(),
|
encryptedCaCert: z.string(),
|
||||||
caCertIV: z.string().nullable().optional(),
|
caCertIV: z.string(),
|
||||||
caCertTag: z.string().nullable().optional(),
|
caCertTag: z.string(),
|
||||||
encryptedTokenReviewerJwt: z.string().nullable().optional(),
|
encryptedTokenReviewerJwt: z.string(),
|
||||||
tokenReviewerJwtIV: z.string().nullable().optional(),
|
tokenReviewerJwtIV: z.string(),
|
||||||
tokenReviewerJwtTag: z.string().nullable().optional(),
|
tokenReviewerJwtTag: z.string(),
|
||||||
allowedNamespaces: z.string(),
|
allowedNamespaces: z.string(),
|
||||||
allowedNames: z.string(),
|
allowedNames: z.string(),
|
||||||
allowedAudience: z.string(),
|
allowedAudience: z.string()
|
||||||
encryptedKubernetesTokenReviewerJwt: zodBuffer,
|
|
||||||
encryptedKubernetesCaCertificate: zodBuffer.nullable().optional()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TIdentityKubernetesAuths = z.infer<typeof IdentityKubernetesAuthsSchema>;
|
export type TIdentityKubernetesAuths = z.infer<typeof IdentityKubernetesAuthsSchema>;
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { zodBuffer } from "@app/lib/zod";
|
|
||||||
|
|
||||||
import { TImmutableDBKeys } from "./models";
|
import { TImmutableDBKeys } from "./models";
|
||||||
|
|
||||||
export const IdentityOidcAuthsSchema = z.object({
|
export const IdentityOidcAuthsSchema = z.object({
|
||||||
@@ -17,16 +15,15 @@ export const IdentityOidcAuthsSchema = z.object({
|
|||||||
accessTokenTrustedIps: z.unknown(),
|
accessTokenTrustedIps: z.unknown(),
|
||||||
identityId: z.string().uuid(),
|
identityId: z.string().uuid(),
|
||||||
oidcDiscoveryUrl: z.string(),
|
oidcDiscoveryUrl: z.string(),
|
||||||
encryptedCaCert: z.string().nullable().optional(),
|
encryptedCaCert: z.string(),
|
||||||
caCertIV: z.string().nullable().optional(),
|
caCertIV: z.string(),
|
||||||
caCertTag: z.string().nullable().optional(),
|
caCertTag: z.string(),
|
||||||
boundIssuer: z.string(),
|
boundIssuer: z.string(),
|
||||||
boundAudiences: z.string(),
|
boundAudiences: z.string(),
|
||||||
boundClaims: z.unknown(),
|
boundClaims: z.unknown(),
|
||||||
boundSubject: z.string().nullable().optional(),
|
boundSubject: z.string().nullable().optional(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date(),
|
updatedAt: z.date()
|
||||||
encryptedCaCertificate: zodBuffer.nullable().optional()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TIdentityOidcAuths = z.infer<typeof IdentityOidcAuthsSchema>;
|
export type TIdentityOidcAuths = z.infer<typeof IdentityOidcAuthsSchema>;
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { zodBuffer } from "@app/lib/zod";
|
|
||||||
|
|
||||||
import { TImmutableDBKeys } from "./models";
|
import { TImmutableDBKeys } from "./models";
|
||||||
|
|
||||||
export const LdapConfigsSchema = z.object({
|
export const LdapConfigsSchema = z.object({
|
||||||
@@ -14,25 +12,22 @@ export const LdapConfigsSchema = z.object({
|
|||||||
orgId: z.string().uuid(),
|
orgId: z.string().uuid(),
|
||||||
isActive: z.boolean(),
|
isActive: z.boolean(),
|
||||||
url: z.string(),
|
url: z.string(),
|
||||||
encryptedBindDN: z.string().nullable().optional(),
|
encryptedBindDN: z.string(),
|
||||||
bindDNIV: z.string().nullable().optional(),
|
bindDNIV: z.string(),
|
||||||
bindDNTag: z.string().nullable().optional(),
|
bindDNTag: z.string(),
|
||||||
encryptedBindPass: z.string().nullable().optional(),
|
encryptedBindPass: z.string(),
|
||||||
bindPassIV: z.string().nullable().optional(),
|
bindPassIV: z.string(),
|
||||||
bindPassTag: z.string().nullable().optional(),
|
bindPassTag: z.string(),
|
||||||
searchBase: z.string(),
|
searchBase: z.string(),
|
||||||
encryptedCACert: z.string().nullable().optional(),
|
encryptedCACert: z.string(),
|
||||||
caCertIV: z.string().nullable().optional(),
|
caCertIV: z.string(),
|
||||||
caCertTag: z.string().nullable().optional(),
|
caCertTag: z.string(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date(),
|
updatedAt: z.date(),
|
||||||
groupSearchBase: z.string().default(""),
|
groupSearchBase: z.string().default(""),
|
||||||
groupSearchFilter: z.string().default(""),
|
groupSearchFilter: z.string().default(""),
|
||||||
searchFilter: z.string().default(""),
|
searchFilter: z.string().default(""),
|
||||||
uniqueUserAttribute: z.string().default(""),
|
uniqueUserAttribute: z.string().default("")
|
||||||
encryptedLdapBindDN: zodBuffer,
|
|
||||||
encryptedLdapBindPass: zodBuffer,
|
|
||||||
encryptedLdapCaCertificate: zodBuffer.nullable().optional()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TLdapConfigs = z.infer<typeof LdapConfigsSchema>;
|
export type TLdapConfigs = z.infer<typeof LdapConfigsSchema>;
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { zodBuffer } from "@app/lib/zod";
|
|
||||||
|
|
||||||
import { TImmutableDBKeys } from "./models";
|
import { TImmutableDBKeys } from "./models";
|
||||||
|
|
||||||
export const OidcConfigsSchema = z.object({
|
export const OidcConfigsSchema = z.object({
|
||||||
@@ -17,22 +15,20 @@ export const OidcConfigsSchema = z.object({
|
|||||||
jwksUri: z.string().nullable().optional(),
|
jwksUri: z.string().nullable().optional(),
|
||||||
tokenEndpoint: z.string().nullable().optional(),
|
tokenEndpoint: z.string().nullable().optional(),
|
||||||
userinfoEndpoint: z.string().nullable().optional(),
|
userinfoEndpoint: z.string().nullable().optional(),
|
||||||
encryptedClientId: z.string().nullable().optional(),
|
encryptedClientId: z.string(),
|
||||||
configurationType: z.string(),
|
configurationType: z.string(),
|
||||||
clientIdIV: z.string().nullable().optional(),
|
clientIdIV: z.string(),
|
||||||
clientIdTag: z.string().nullable().optional(),
|
clientIdTag: z.string(),
|
||||||
encryptedClientSecret: z.string().nullable().optional(),
|
encryptedClientSecret: z.string(),
|
||||||
clientSecretIV: z.string().nullable().optional(),
|
clientSecretIV: z.string(),
|
||||||
clientSecretTag: z.string().nullable().optional(),
|
clientSecretTag: z.string(),
|
||||||
allowedEmailDomains: z.string().nullable().optional(),
|
allowedEmailDomains: z.string().nullable().optional(),
|
||||||
isActive: z.boolean(),
|
isActive: z.boolean(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date(),
|
updatedAt: z.date(),
|
||||||
orgId: z.string().uuid(),
|
orgId: z.string().uuid(),
|
||||||
lastUsed: z.date().nullable().optional(),
|
lastUsed: z.date().nullable().optional(),
|
||||||
manageGroupMemberships: z.boolean().default(false),
|
manageGroupMemberships: z.boolean().default(false)
|
||||||
encryptedOidcClientId: zodBuffer,
|
|
||||||
encryptedOidcClientSecret: zodBuffer
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TOidcConfigs = z.infer<typeof OidcConfigsSchema>;
|
export type TOidcConfigs = z.infer<typeof OidcConfigsSchema>;
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { zodBuffer } from "@app/lib/zod";
|
|
||||||
|
|
||||||
import { TImmutableDBKeys } from "./models";
|
import { TImmutableDBKeys } from "./models";
|
||||||
|
|
||||||
export const SamlConfigsSchema = z.object({
|
export const SamlConfigsSchema = z.object({
|
||||||
@@ -25,10 +23,7 @@ export const SamlConfigsSchema = z.object({
|
|||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date(),
|
updatedAt: z.date(),
|
||||||
orgId: z.string().uuid(),
|
orgId: z.string().uuid(),
|
||||||
lastUsed: z.date().nullable().optional(),
|
lastUsed: z.date().nullable().optional()
|
||||||
encryptedSamlEntryPoint: zodBuffer,
|
|
||||||
encryptedSamlIssuer: zodBuffer,
|
|
||||||
encryptedSamlCertificate: zodBuffer
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TSamlConfigs = z.infer<typeof SamlConfigsSchema>;
|
export type TSamlConfigs = z.infer<typeof SamlConfigsSchema>;
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { zodBuffer } from "@app/lib/zod";
|
|
||||||
|
|
||||||
import { TImmutableDBKeys } from "./models";
|
import { TImmutableDBKeys } from "./models";
|
||||||
|
|
||||||
export const SecretRotationsSchema = z.object({
|
export const SecretRotationsSchema = z.object({
|
||||||
@@ -24,8 +22,7 @@ export const SecretRotationsSchema = z.object({
|
|||||||
keyEncoding: z.string().nullable().optional(),
|
keyEncoding: z.string().nullable().optional(),
|
||||||
envId: z.string().uuid(),
|
envId: z.string().uuid(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date(),
|
updatedAt: z.date()
|
||||||
encryptedRotationData: zodBuffer
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TSecretRotations = z.infer<typeof SecretRotationsSchema>;
|
export type TSecretRotations = z.infer<typeof SecretRotationsSchema>;
|
||||||
|
|||||||
@@ -5,14 +5,12 @@
|
|||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { zodBuffer } from "@app/lib/zod";
|
|
||||||
|
|
||||||
import { TImmutableDBKeys } from "./models";
|
import { TImmutableDBKeys } from "./models";
|
||||||
|
|
||||||
export const WebhooksSchema = z.object({
|
export const WebhooksSchema = z.object({
|
||||||
id: z.string().uuid(),
|
id: z.string().uuid(),
|
||||||
secretPath: z.string().default("/"),
|
secretPath: z.string().default("/"),
|
||||||
url: z.string().nullable().optional(),
|
url: z.string(),
|
||||||
lastStatus: z.string().nullable().optional(),
|
lastStatus: z.string().nullable().optional(),
|
||||||
lastRunErrorMessage: z.string().nullable().optional(),
|
lastRunErrorMessage: z.string().nullable().optional(),
|
||||||
isDisabled: z.boolean().default(false),
|
isDisabled: z.boolean().default(false),
|
||||||
@@ -27,9 +25,7 @@ export const WebhooksSchema = z.object({
|
|||||||
urlCipherText: z.string().nullable().optional(),
|
urlCipherText: z.string().nullable().optional(),
|
||||||
urlIV: z.string().nullable().optional(),
|
urlIV: z.string().nullable().optional(),
|
||||||
urlTag: z.string().nullable().optional(),
|
urlTag: z.string().nullable().optional(),
|
||||||
type: z.string().default("general").nullable().optional(),
|
type: z.string().default("general").nullable().optional()
|
||||||
encryptedPassKey: zodBuffer.nullable().optional(),
|
|
||||||
encryptedUrl: zodBuffer
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TWebhooks = z.infer<typeof WebhooksSchema>;
|
export type TWebhooks = z.infer<typeof WebhooksSchema>;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { FastifyRequest } from "fastify";
|
|||||||
import LdapStrategy from "passport-ldapauth";
|
import LdapStrategy from "passport-ldapauth";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { LdapGroupMapsSchema } from "@app/db/schemas";
|
import { LdapConfigsSchema, LdapGroupMapsSchema } from "@app/db/schemas";
|
||||||
import { TLDAPConfig } from "@app/ee/services/ldap-config/ldap-config-types";
|
import { TLDAPConfig } from "@app/ee/services/ldap-config/ldap-config-types";
|
||||||
import { isValidLdapFilter, searchGroups } from "@app/ee/services/ldap-config/ldap-fns";
|
import { isValidLdapFilter, searchGroups } from "@app/ee/services/ldap-config/ldap-fns";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
@@ -22,7 +22,6 @@ import { BadRequestError } from "@app/lib/errors";
|
|||||||
import { logger } from "@app/lib/logger";
|
import { logger } from "@app/lib/logger";
|
||||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
||||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { SanitizedLdapConfigSchema } from "@app/server/routes/sanitizedSchema/directory-config";
|
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
|
|
||||||
export const registerLdapRouter = async (server: FastifyZodProvider) => {
|
export const registerLdapRouter = async (server: FastifyZodProvider) => {
|
||||||
@@ -188,7 +187,7 @@ export const registerLdapRouter = async (server: FastifyZodProvider) => {
|
|||||||
caCert: z.string().trim().default("")
|
caCert: z.string().trim().default("")
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: SanitizedLdapConfigSchema
|
200: LdapConfigsSchema
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
@@ -229,7 +228,7 @@ export const registerLdapRouter = async (server: FastifyZodProvider) => {
|
|||||||
.partial()
|
.partial()
|
||||||
.merge(z.object({ organizationId: z.string() })),
|
.merge(z.object({ organizationId: z.string() })),
|
||||||
response: {
|
response: {
|
||||||
200: SanitizedLdapConfigSchema
|
200: LdapConfigsSchema
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
|
|||||||
@@ -11,28 +11,13 @@ import fastifySession from "@fastify/session";
|
|||||||
import RedisStore from "connect-redis";
|
import RedisStore from "connect-redis";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { OidcConfigsSchema } from "@app/db/schemas";
|
import { OidcConfigsSchema } from "@app/db/schemas/oidc-configs";
|
||||||
import { OIDCConfigurationType } from "@app/ee/services/oidc/oidc-config-types";
|
import { OIDCConfigurationType } from "@app/ee/services/oidc/oidc-config-types";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { authRateLimit, readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
import { authRateLimit, readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
||||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
|
|
||||||
const SanitizedOidcConfigSchema = OidcConfigsSchema.pick({
|
|
||||||
id: true,
|
|
||||||
issuer: true,
|
|
||||||
authorizationEndpoint: true,
|
|
||||||
configurationType: true,
|
|
||||||
discoveryURL: true,
|
|
||||||
jwksUri: true,
|
|
||||||
tokenEndpoint: true,
|
|
||||||
userinfoEndpoint: true,
|
|
||||||
orgId: true,
|
|
||||||
isActive: true,
|
|
||||||
allowedEmailDomains: true,
|
|
||||||
manageGroupMemberships: true
|
|
||||||
});
|
|
||||||
|
|
||||||
export const registerOidcRouter = async (server: FastifyZodProvider) => {
|
export const registerOidcRouter = async (server: FastifyZodProvider) => {
|
||||||
const appCfg = getConfig();
|
const appCfg = getConfig();
|
||||||
const passport = new Authenticator({ key: "oidc", userProperty: "passportUser" });
|
const passport = new Authenticator({ key: "oidc", userProperty: "passportUser" });
|
||||||
@@ -157,7 +142,7 @@ export const registerOidcRouter = async (server: FastifyZodProvider) => {
|
|||||||
orgSlug: z.string().trim()
|
orgSlug: z.string().trim()
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: SanitizedOidcConfigSchema.pick({
|
200: OidcConfigsSchema.pick({
|
||||||
id: true,
|
id: true,
|
||||||
issuer: true,
|
issuer: true,
|
||||||
authorizationEndpoint: true,
|
authorizationEndpoint: true,
|
||||||
@@ -229,7 +214,7 @@ export const registerOidcRouter = async (server: FastifyZodProvider) => {
|
|||||||
.partial()
|
.partial()
|
||||||
.merge(z.object({ orgSlug: z.string() })),
|
.merge(z.object({ orgSlug: z.string() })),
|
||||||
response: {
|
response: {
|
||||||
200: SanitizedOidcConfigSchema.pick({
|
200: OidcConfigsSchema.pick({
|
||||||
id: true,
|
id: true,
|
||||||
issuer: true,
|
issuer: true,
|
||||||
authorizationEndpoint: true,
|
authorizationEndpoint: true,
|
||||||
@@ -342,7 +327,20 @@ export const registerOidcRouter = async (server: FastifyZodProvider) => {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: SanitizedOidcConfigSchema
|
200: OidcConfigsSchema.pick({
|
||||||
|
id: true,
|
||||||
|
issuer: true,
|
||||||
|
authorizationEndpoint: true,
|
||||||
|
configurationType: true,
|
||||||
|
discoveryURL: true,
|
||||||
|
jwksUri: true,
|
||||||
|
tokenEndpoint: true,
|
||||||
|
userinfoEndpoint: true,
|
||||||
|
orgId: true,
|
||||||
|
isActive: true,
|
||||||
|
allowedEmailDomains: true,
|
||||||
|
manageGroupMemberships: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { ProjectTemplates } from "@app/lib/api-docs";
|
|||||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
||||||
import { slugSchema } from "@app/server/lib/schemas";
|
import { slugSchema } from "@app/server/lib/schemas";
|
||||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { UnpackedPermissionSchema } from "@app/server/routes/sanitizedSchema/permission";
|
import { UnpackedPermissionSchema } from "@app/server/routes/santizedSchemas/permission";
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
|
|
||||||
const MAX_JSON_SIZE_LIMIT_IN_BYTES = 32_768;
|
const MAX_JSON_SIZE_LIMIT_IN_BYTES = 32_768;
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ import { MultiSamlStrategy } from "@node-saml/passport-saml";
|
|||||||
import { FastifyRequest } from "fastify";
|
import { FastifyRequest } from "fastify";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { SamlConfigsSchema } from "@app/db/schemas";
|
||||||
import { SamlProviders, TGetSamlCfgDTO } from "@app/ee/services/saml-config/saml-config-types";
|
import { SamlProviders, TGetSamlCfgDTO } from "@app/ee/services/saml-config/saml-config-types";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { BadRequestError } from "@app/lib/errors";
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
import { logger } from "@app/lib/logger";
|
import { logger } from "@app/lib/logger";
|
||||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
||||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { SanitizedSamlConfigSchema } from "@app/server/routes/sanitizedSchema/directory-config";
|
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
|
|
||||||
type TSAMLConfig = {
|
type TSAMLConfig = {
|
||||||
@@ -298,7 +298,7 @@ export const registerSamlRouter = async (server: FastifyZodProvider) => {
|
|||||||
cert: z.string()
|
cert: z.string()
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: SanitizedSamlConfigSchema
|
200: SamlConfigsSchema
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
@@ -333,7 +333,7 @@ export const registerSamlRouter = async (server: FastifyZodProvider) => {
|
|||||||
.partial()
|
.partial()
|
||||||
.merge(z.object({ organizationId: z.string() })),
|
.merge(z.object({ organizationId: z.string() })),
|
||||||
response: {
|
response: {
|
||||||
200: SanitizedSamlConfigSchema
|
200: SamlConfigsSchema
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { alphaNumericNanoId } from "@app/lib/nanoid";
|
|||||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
||||||
import { slugSchema } from "@app/server/lib/schemas";
|
import { slugSchema } from "@app/server/lib/schemas";
|
||||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { SanitizedUserProjectAdditionalPrivilegeSchema } from "@app/server/routes/sanitizedSchema/user-additional-privilege";
|
import { SanitizedUserProjectAdditionalPrivilegeSchema } from "@app/server/routes/santizedSchemas/user-additional-privilege";
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
|
|
||||||
export const registerUserAdditionalPrivilegeRouter = async (server: FastifyZodProvider) => {
|
export const registerUserAdditionalPrivilegeRouter = async (server: FastifyZodProvider) => {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { alphaNumericNanoId } from "@app/lib/nanoid";
|
|||||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
||||||
import { slugSchema } from "@app/server/lib/schemas";
|
import { slugSchema } from "@app/server/lib/schemas";
|
||||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { SanitizedIdentityPrivilegeSchema } from "@app/server/routes/sanitizedSchema/identitiy-additional-privilege";
|
import { SanitizedIdentityPrivilegeSchema } from "@app/server/routes/santizedSchemas/identitiy-additional-privilege";
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
|
|
||||||
export const registerIdentityProjectAdditionalPrivilegeRouter = async (server: FastifyZodProvider) => {
|
export const registerIdentityProjectAdditionalPrivilegeRouter = async (server: FastifyZodProvider) => {
|
||||||
|
|||||||
@@ -37,7 +37,11 @@ export const dynamicSecretLeaseDALFactory = (db: TDbClient) => {
|
|||||||
db.ref("type").withSchema(TableName.DynamicSecret).as("dynType"),
|
db.ref("type").withSchema(TableName.DynamicSecret).as("dynType"),
|
||||||
db.ref("defaultTTL").withSchema(TableName.DynamicSecret).as("dynDefaultTTL"),
|
db.ref("defaultTTL").withSchema(TableName.DynamicSecret).as("dynDefaultTTL"),
|
||||||
db.ref("maxTTL").withSchema(TableName.DynamicSecret).as("dynMaxTTL"),
|
db.ref("maxTTL").withSchema(TableName.DynamicSecret).as("dynMaxTTL"),
|
||||||
db.ref("encryptedInput").withSchema(TableName.DynamicSecret).as("dynEncryptedInput"),
|
db.ref("inputIV").withSchema(TableName.DynamicSecret).as("dynInputIV"),
|
||||||
|
db.ref("inputTag").withSchema(TableName.DynamicSecret).as("dynInputTag"),
|
||||||
|
db.ref("inputCiphertext").withSchema(TableName.DynamicSecret).as("dynInputCiphertext"),
|
||||||
|
db.ref("algorithm").withSchema(TableName.DynamicSecret).as("dynAlgorithm"),
|
||||||
|
db.ref("keyEncoding").withSchema(TableName.DynamicSecret).as("dynKeyEncoding"),
|
||||||
db.ref("folderId").withSchema(TableName.DynamicSecret).as("dynFolderId"),
|
db.ref("folderId").withSchema(TableName.DynamicSecret).as("dynFolderId"),
|
||||||
db.ref("status").withSchema(TableName.DynamicSecret).as("dynStatus"),
|
db.ref("status").withSchema(TableName.DynamicSecret).as("dynStatus"),
|
||||||
db.ref("statusDetails").withSchema(TableName.DynamicSecret).as("dynStatusDetails"),
|
db.ref("statusDetails").withSchema(TableName.DynamicSecret).as("dynStatusDetails"),
|
||||||
@@ -55,7 +59,11 @@ export const dynamicSecretLeaseDALFactory = (db: TDbClient) => {
|
|||||||
type: doc.dynType,
|
type: doc.dynType,
|
||||||
defaultTTL: doc.dynDefaultTTL,
|
defaultTTL: doc.dynDefaultTTL,
|
||||||
maxTTL: doc.dynMaxTTL,
|
maxTTL: doc.dynMaxTTL,
|
||||||
encryptedInput: doc.dynEncryptedInput,
|
inputIV: doc.dynInputIV,
|
||||||
|
inputTag: doc.dynInputTag,
|
||||||
|
inputCiphertext: doc.dynInputCiphertext,
|
||||||
|
algorithm: doc.dynAlgorithm,
|
||||||
|
keyEncoding: doc.dynKeyEncoding,
|
||||||
folderId: doc.dynFolderId,
|
folderId: doc.dynFolderId,
|
||||||
status: doc.dynStatus,
|
status: doc.dynStatus,
|
||||||
statusDetails: doc.dynStatusDetails,
|
statusDetails: doc.dynStatusDetails,
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
|
import { SecretKeyEncoding } from "@app/db/schemas";
|
||||||
import { DisableRotationErrors } from "@app/ee/services/secret-rotation/secret-rotation-queue";
|
import { DisableRotationErrors } from "@app/ee/services/secret-rotation/secret-rotation-queue";
|
||||||
import { NotFoundError } from "@app/lib/errors";
|
import { infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
||||||
import { logger } from "@app/lib/logger";
|
import { logger } from "@app/lib/logger";
|
||||||
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
|
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
|
||||||
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
|
|
||||||
import { KmsDataKey } from "@app/services/kms/kms-types";
|
|
||||||
import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";
|
|
||||||
|
|
||||||
import { TDynamicSecretDALFactory } from "../dynamic-secret/dynamic-secret-dal";
|
import { TDynamicSecretDALFactory } from "../dynamic-secret/dynamic-secret-dal";
|
||||||
import { DynamicSecretStatus } from "../dynamic-secret/dynamic-secret-types";
|
import { DynamicSecretStatus } from "../dynamic-secret/dynamic-secret-types";
|
||||||
@@ -16,8 +14,6 @@ type TDynamicSecretLeaseQueueServiceFactoryDep = {
|
|||||||
dynamicSecretLeaseDAL: Pick<TDynamicSecretLeaseDALFactory, "findById" | "deleteById" | "find" | "updateById">;
|
dynamicSecretLeaseDAL: Pick<TDynamicSecretLeaseDALFactory, "findById" | "deleteById" | "find" | "updateById">;
|
||||||
dynamicSecretDAL: Pick<TDynamicSecretDALFactory, "findById" | "deleteById" | "updateById">;
|
dynamicSecretDAL: Pick<TDynamicSecretDALFactory, "findById" | "deleteById" | "updateById">;
|
||||||
dynamicSecretProviders: Record<DynamicSecretProviders, TDynamicProviderFns>;
|
dynamicSecretProviders: Record<DynamicSecretProviders, TDynamicProviderFns>;
|
||||||
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
|
|
||||||
folderDAL: Pick<TSecretFolderDALFactory, "findById">;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TDynamicSecretLeaseQueueServiceFactory = ReturnType<typeof dynamicSecretLeaseQueueServiceFactory>;
|
export type TDynamicSecretLeaseQueueServiceFactory = ReturnType<typeof dynamicSecretLeaseQueueServiceFactory>;
|
||||||
@@ -26,9 +22,7 @@ export const dynamicSecretLeaseQueueServiceFactory = ({
|
|||||||
queueService,
|
queueService,
|
||||||
dynamicSecretDAL,
|
dynamicSecretDAL,
|
||||||
dynamicSecretProviders,
|
dynamicSecretProviders,
|
||||||
dynamicSecretLeaseDAL,
|
dynamicSecretLeaseDAL
|
||||||
kmsService,
|
|
||||||
folderDAL
|
|
||||||
}: TDynamicSecretLeaseQueueServiceFactoryDep) => {
|
}: TDynamicSecretLeaseQueueServiceFactoryDep) => {
|
||||||
const pruneDynamicSecret = async (dynamicSecretCfgId: string) => {
|
const pruneDynamicSecret = async (dynamicSecretCfgId: string) => {
|
||||||
await queueService.queue(
|
await queueService.queue(
|
||||||
@@ -82,21 +76,15 @@ export const dynamicSecretLeaseQueueServiceFactory = ({
|
|||||||
const dynamicSecretLease = await dynamicSecretLeaseDAL.findById(leaseId);
|
const dynamicSecretLease = await dynamicSecretLeaseDAL.findById(leaseId);
|
||||||
if (!dynamicSecretLease) throw new DisableRotationErrors({ message: "Dynamic secret lease not found" });
|
if (!dynamicSecretLease) throw new DisableRotationErrors({ message: "Dynamic secret lease not found" });
|
||||||
|
|
||||||
const folder = await folderDAL.findById(dynamicSecretLease.dynamicSecret.folderId);
|
|
||||||
if (!folder)
|
|
||||||
throw new NotFoundError({
|
|
||||||
message: `Failed to find folder with ${dynamicSecretLease.dynamicSecret.folderId}`
|
|
||||||
});
|
|
||||||
|
|
||||||
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId: folder.projectId
|
|
||||||
});
|
|
||||||
|
|
||||||
const dynamicSecretCfg = dynamicSecretLease.dynamicSecret;
|
const dynamicSecretCfg = dynamicSecretLease.dynamicSecret;
|
||||||
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
||||||
const decryptedStoredInput = JSON.parse(
|
const decryptedStoredInput = JSON.parse(
|
||||||
secretManagerDecryptor({ cipherTextBlob: dynamicSecretCfg.encryptedInput }).toString()
|
infisicalSymmetricDecrypt({
|
||||||
|
keyEncoding: dynamicSecretCfg.keyEncoding as SecretKeyEncoding,
|
||||||
|
ciphertext: dynamicSecretCfg.inputCiphertext,
|
||||||
|
tag: dynamicSecretCfg.inputTag,
|
||||||
|
iv: dynamicSecretCfg.inputIV
|
||||||
|
})
|
||||||
) as object;
|
) as object;
|
||||||
|
|
||||||
await selectedProvider.revoke(decryptedStoredInput, dynamicSecretLease.externalEntityId);
|
await selectedProvider.revoke(decryptedStoredInput, dynamicSecretLease.externalEntityId);
|
||||||
@@ -112,22 +100,16 @@ export const dynamicSecretLeaseQueueServiceFactory = ({
|
|||||||
if ((dynamicSecretCfg.status as DynamicSecretStatus) !== DynamicSecretStatus.Deleting)
|
if ((dynamicSecretCfg.status as DynamicSecretStatus) !== DynamicSecretStatus.Deleting)
|
||||||
throw new DisableRotationErrors({ message: "Document not deleted" });
|
throw new DisableRotationErrors({ message: "Document not deleted" });
|
||||||
|
|
||||||
const folder = await folderDAL.findById(dynamicSecretCfg.folderId);
|
|
||||||
if (!folder)
|
|
||||||
throw new NotFoundError({
|
|
||||||
message: `Failed to find folder with ${dynamicSecretCfg.folderId}`
|
|
||||||
});
|
|
||||||
|
|
||||||
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId: folder.projectId
|
|
||||||
});
|
|
||||||
|
|
||||||
const dynamicSecretLeases = await dynamicSecretLeaseDAL.find({ dynamicSecretId: dynamicSecretCfgId });
|
const dynamicSecretLeases = await dynamicSecretLeaseDAL.find({ dynamicSecretId: dynamicSecretCfgId });
|
||||||
if (dynamicSecretLeases.length) {
|
if (dynamicSecretLeases.length) {
|
||||||
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
||||||
const decryptedStoredInput = JSON.parse(
|
const decryptedStoredInput = JSON.parse(
|
||||||
secretManagerDecryptor({ cipherTextBlob: dynamicSecretCfg.encryptedInput }).toString()
|
infisicalSymmetricDecrypt({
|
||||||
|
keyEncoding: dynamicSecretCfg.keyEncoding as SecretKeyEncoding,
|
||||||
|
ciphertext: dynamicSecretCfg.inputCiphertext,
|
||||||
|
tag: dynamicSecretCfg.inputTag,
|
||||||
|
iv: dynamicSecretCfg.inputIV
|
||||||
|
})
|
||||||
) as object;
|
) as object;
|
||||||
|
|
||||||
await Promise.all(dynamicSecretLeases.map(({ id }) => unsetLeaseRevocation(id)));
|
await Promise.all(dynamicSecretLeases.map(({ id }) => unsetLeaseRevocation(id)));
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ForbiddenError, subject } from "@casl/ability";
|
import { ForbiddenError, subject } from "@casl/ability";
|
||||||
import ms from "ms";
|
import ms from "ms";
|
||||||
|
|
||||||
import { ActionProjectType } from "@app/db/schemas";
|
import { ActionProjectType, SecretKeyEncoding } from "@app/db/schemas";
|
||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
||||||
import {
|
import {
|
||||||
@@ -9,10 +9,9 @@ import {
|
|||||||
ProjectPermissionSub
|
ProjectPermissionSub
|
||||||
} from "@app/ee/services/permission/project-permission";
|
} from "@app/ee/services/permission/project-permission";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
|
import { infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
||||||
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
import { logger } from "@app/lib/logger";
|
import { logger } from "@app/lib/logger";
|
||||||
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
|
|
||||||
import { KmsDataKey } from "@app/services/kms/kms-types";
|
|
||||||
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
||||||
import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";
|
import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";
|
||||||
|
|
||||||
@@ -38,7 +37,6 @@ type TDynamicSecretLeaseServiceFactoryDep = {
|
|||||||
folderDAL: Pick<TSecretFolderDALFactory, "findBySecretPath">;
|
folderDAL: Pick<TSecretFolderDALFactory, "findBySecretPath">;
|
||||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||||
projectDAL: Pick<TProjectDALFactory, "findProjectBySlug">;
|
projectDAL: Pick<TProjectDALFactory, "findProjectBySlug">;
|
||||||
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TDynamicSecretLeaseServiceFactory = ReturnType<typeof dynamicSecretLeaseServiceFactory>;
|
export type TDynamicSecretLeaseServiceFactory = ReturnType<typeof dynamicSecretLeaseServiceFactory>;
|
||||||
@@ -51,8 +49,7 @@ export const dynamicSecretLeaseServiceFactory = ({
|
|||||||
permissionService,
|
permissionService,
|
||||||
dynamicSecretQueueService,
|
dynamicSecretQueueService,
|
||||||
projectDAL,
|
projectDAL,
|
||||||
licenseService,
|
licenseService
|
||||||
kmsService
|
|
||||||
}: TDynamicSecretLeaseServiceFactoryDep) => {
|
}: TDynamicSecretLeaseServiceFactoryDep) => {
|
||||||
const create = async ({
|
const create = async ({
|
||||||
environmentSlug,
|
environmentSlug,
|
||||||
@@ -107,14 +104,13 @@ export const dynamicSecretLeaseServiceFactory = ({
|
|||||||
throw new BadRequestError({ message: `Max lease limit reached. Limit: ${appCfg.MAX_LEASE_LIMIT}` });
|
throw new BadRequestError({ message: `Max lease limit reached. Limit: ${appCfg.MAX_LEASE_LIMIT}` });
|
||||||
|
|
||||||
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
||||||
|
|
||||||
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId
|
|
||||||
});
|
|
||||||
|
|
||||||
const decryptedStoredInput = JSON.parse(
|
const decryptedStoredInput = JSON.parse(
|
||||||
secretManagerDecryptor({ cipherTextBlob: Buffer.from(dynamicSecretCfg.encryptedInput) }).toString()
|
infisicalSymmetricDecrypt({
|
||||||
|
keyEncoding: dynamicSecretCfg.keyEncoding as SecretKeyEncoding,
|
||||||
|
ciphertext: dynamicSecretCfg.inputCiphertext,
|
||||||
|
tag: dynamicSecretCfg.inputTag,
|
||||||
|
iv: dynamicSecretCfg.inputIV
|
||||||
|
})
|
||||||
) as object;
|
) as object;
|
||||||
|
|
||||||
const selectedTTL = ttl || dynamicSecretCfg.defaultTTL;
|
const selectedTTL = ttl || dynamicSecretCfg.defaultTTL;
|
||||||
@@ -164,11 +160,6 @@ export const dynamicSecretLeaseServiceFactory = ({
|
|||||||
subject(ProjectPermissionSub.DynamicSecrets, { environment: environmentSlug, secretPath: path })
|
subject(ProjectPermissionSub.DynamicSecrets, { environment: environmentSlug, secretPath: path })
|
||||||
);
|
);
|
||||||
|
|
||||||
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId
|
|
||||||
});
|
|
||||||
|
|
||||||
const plan = await licenseService.getPlan(actorOrgId);
|
const plan = await licenseService.getPlan(actorOrgId);
|
||||||
if (!plan?.dynamicSecret) {
|
if (!plan?.dynamicSecret) {
|
||||||
throw new BadRequestError({
|
throw new BadRequestError({
|
||||||
@@ -190,7 +181,12 @@ export const dynamicSecretLeaseServiceFactory = ({
|
|||||||
const dynamicSecretCfg = dynamicSecretLease.dynamicSecret;
|
const dynamicSecretCfg = dynamicSecretLease.dynamicSecret;
|
||||||
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
||||||
const decryptedStoredInput = JSON.parse(
|
const decryptedStoredInput = JSON.parse(
|
||||||
secretManagerDecryptor({ cipherTextBlob: Buffer.from(dynamicSecretCfg.encryptedInput) }).toString()
|
infisicalSymmetricDecrypt({
|
||||||
|
keyEncoding: dynamicSecretCfg.keyEncoding as SecretKeyEncoding,
|
||||||
|
ciphertext: dynamicSecretCfg.inputCiphertext,
|
||||||
|
tag: dynamicSecretCfg.inputTag,
|
||||||
|
iv: dynamicSecretCfg.inputIV
|
||||||
|
})
|
||||||
) as object;
|
) as object;
|
||||||
|
|
||||||
const selectedTTL = ttl || dynamicSecretCfg.defaultTTL;
|
const selectedTTL = ttl || dynamicSecretCfg.defaultTTL;
|
||||||
@@ -244,11 +240,6 @@ export const dynamicSecretLeaseServiceFactory = ({
|
|||||||
subject(ProjectPermissionSub.DynamicSecrets, { environment: environmentSlug, secretPath: path })
|
subject(ProjectPermissionSub.DynamicSecrets, { environment: environmentSlug, secretPath: path })
|
||||||
);
|
);
|
||||||
|
|
||||||
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId
|
|
||||||
});
|
|
||||||
|
|
||||||
const folder = await folderDAL.findBySecretPath(projectId, environmentSlug, path);
|
const folder = await folderDAL.findBySecretPath(projectId, environmentSlug, path);
|
||||||
if (!folder)
|
if (!folder)
|
||||||
throw new NotFoundError({
|
throw new NotFoundError({
|
||||||
@@ -262,7 +253,12 @@ export const dynamicSecretLeaseServiceFactory = ({
|
|||||||
const dynamicSecretCfg = dynamicSecretLease.dynamicSecret;
|
const dynamicSecretCfg = dynamicSecretLease.dynamicSecret;
|
||||||
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
||||||
const decryptedStoredInput = JSON.parse(
|
const decryptedStoredInput = JSON.parse(
|
||||||
secretManagerDecryptor({ cipherTextBlob: Buffer.from(dynamicSecretCfg.encryptedInput) }).toString()
|
infisicalSymmetricDecrypt({
|
||||||
|
keyEncoding: dynamicSecretCfg.keyEncoding as SecretKeyEncoding,
|
||||||
|
ciphertext: dynamicSecretCfg.inputCiphertext,
|
||||||
|
tag: dynamicSecretCfg.inputTag,
|
||||||
|
iv: dynamicSecretCfg.inputIV
|
||||||
|
})
|
||||||
) as object;
|
) as object;
|
||||||
|
|
||||||
const revokeResponse = await selectedProvider
|
const revokeResponse = await selectedProvider
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
import { ForbiddenError, subject } from "@casl/ability";
|
import { ForbiddenError, subject } from "@casl/ability";
|
||||||
|
|
||||||
import { ActionProjectType } from "@app/db/schemas";
|
import { ActionProjectType, SecretKeyEncoding } from "@app/db/schemas";
|
||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
||||||
import {
|
import {
|
||||||
ProjectPermissionDynamicSecretActions,
|
ProjectPermissionDynamicSecretActions,
|
||||||
ProjectPermissionSub
|
ProjectPermissionSub
|
||||||
} from "@app/ee/services/permission/project-permission";
|
} from "@app/ee/services/permission/project-permission";
|
||||||
|
import { infisicalSymmetricDecrypt, infisicalSymmetricEncypt } from "@app/lib/crypto/encryption";
|
||||||
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
import { OrderByDirection, OrgServiceActor } from "@app/lib/types";
|
import { OrderByDirection, OrgServiceActor } from "@app/lib/types";
|
||||||
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
|
|
||||||
import { KmsDataKey } from "@app/services/kms/kms-types";
|
|
||||||
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
||||||
import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";
|
import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";
|
||||||
|
|
||||||
@@ -43,7 +42,6 @@ type TDynamicSecretServiceFactoryDep = {
|
|||||||
folderDAL: Pick<TSecretFolderDALFactory, "findBySecretPath" | "findBySecretPathMultiEnv">;
|
folderDAL: Pick<TSecretFolderDALFactory, "findBySecretPath" | "findBySecretPathMultiEnv">;
|
||||||
projectDAL: Pick<TProjectDALFactory, "findProjectBySlug">;
|
projectDAL: Pick<TProjectDALFactory, "findProjectBySlug">;
|
||||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||||
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TDynamicSecretServiceFactory = ReturnType<typeof dynamicSecretServiceFactory>;
|
export type TDynamicSecretServiceFactory = ReturnType<typeof dynamicSecretServiceFactory>;
|
||||||
@@ -56,8 +54,7 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
dynamicSecretProviders,
|
dynamicSecretProviders,
|
||||||
permissionService,
|
permissionService,
|
||||||
dynamicSecretQueueService,
|
dynamicSecretQueueService,
|
||||||
projectDAL,
|
projectDAL
|
||||||
kmsService
|
|
||||||
}: TDynamicSecretServiceFactoryDep) => {
|
}: TDynamicSecretServiceFactoryDep) => {
|
||||||
const create = async ({
|
const create = async ({
|
||||||
path,
|
path,
|
||||||
@@ -111,15 +108,16 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
const isConnected = await selectedProvider.validateConnection(provider.inputs);
|
const isConnected = await selectedProvider.validateConnection(provider.inputs);
|
||||||
if (!isConnected) throw new BadRequestError({ message: "Provider connection failed" });
|
if (!isConnected) throw new BadRequestError({ message: "Provider connection failed" });
|
||||||
|
|
||||||
const { encryptor: secretManagerEncryptor } = await kmsService.createCipherPairWithDataKey({
|
const encryptedInput = infisicalSymmetricEncypt(JSON.stringify(inputs));
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId
|
|
||||||
});
|
|
||||||
|
|
||||||
const dynamicSecretCfg = await dynamicSecretDAL.create({
|
const dynamicSecretCfg = await dynamicSecretDAL.create({
|
||||||
type: provider.type,
|
type: provider.type,
|
||||||
version: 1,
|
version: 1,
|
||||||
encryptedInput: secretManagerEncryptor({ plainText: Buffer.from(JSON.stringify(inputs)) }).cipherTextBlob,
|
inputIV: encryptedInput.iv,
|
||||||
|
inputTag: encryptedInput.tag,
|
||||||
|
inputCiphertext: encryptedInput.ciphertext,
|
||||||
|
algorithm: encryptedInput.algorithm,
|
||||||
|
keyEncoding: encryptedInput.encoding,
|
||||||
maxTTL,
|
maxTTL,
|
||||||
defaultTTL,
|
defaultTTL,
|
||||||
folderId: folder.id,
|
folderId: folder.id,
|
||||||
@@ -182,15 +180,15 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
if (existingDynamicSecret)
|
if (existingDynamicSecret)
|
||||||
throw new BadRequestError({ message: "Provided dynamic secret already exist under the folder" });
|
throw new BadRequestError({ message: "Provided dynamic secret already exist under the folder" });
|
||||||
}
|
}
|
||||||
const { encryptor: secretManagerEncryptor, decryptor: secretManagerDecryptor } =
|
|
||||||
await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId
|
|
||||||
});
|
|
||||||
|
|
||||||
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
||||||
const decryptedStoredInput = JSON.parse(
|
const decryptedStoredInput = JSON.parse(
|
||||||
secretManagerDecryptor({ cipherTextBlob: dynamicSecretCfg.encryptedInput }).toString()
|
infisicalSymmetricDecrypt({
|
||||||
|
keyEncoding: dynamicSecretCfg.keyEncoding as SecretKeyEncoding,
|
||||||
|
ciphertext: dynamicSecretCfg.inputCiphertext,
|
||||||
|
tag: dynamicSecretCfg.inputTag,
|
||||||
|
iv: dynamicSecretCfg.inputIV
|
||||||
|
})
|
||||||
) as object;
|
) as object;
|
||||||
const newInput = { ...decryptedStoredInput, ...(inputs || {}) };
|
const newInput = { ...decryptedStoredInput, ...(inputs || {}) };
|
||||||
const updatedInput = await selectedProvider.validateProviderInputs(newInput);
|
const updatedInput = await selectedProvider.validateProviderInputs(newInput);
|
||||||
@@ -198,8 +196,13 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
const isConnected = await selectedProvider.validateConnection(newInput);
|
const isConnected = await selectedProvider.validateConnection(newInput);
|
||||||
if (!isConnected) throw new BadRequestError({ message: "Provider connection failed" });
|
if (!isConnected) throw new BadRequestError({ message: "Provider connection failed" });
|
||||||
|
|
||||||
|
const encryptedInput = infisicalSymmetricEncypt(JSON.stringify(updatedInput));
|
||||||
const updatedDynamicCfg = await dynamicSecretDAL.updateById(dynamicSecretCfg.id, {
|
const updatedDynamicCfg = await dynamicSecretDAL.updateById(dynamicSecretCfg.id, {
|
||||||
encryptedInput: secretManagerEncryptor({ plainText: Buffer.from(JSON.stringify(updatedInput)) }).cipherTextBlob,
|
inputIV: encryptedInput.iv,
|
||||||
|
inputTag: encryptedInput.tag,
|
||||||
|
inputCiphertext: encryptedInput.ciphertext,
|
||||||
|
algorithm: encryptedInput.algorithm,
|
||||||
|
keyEncoding: encryptedInput.encoding,
|
||||||
maxTTL,
|
maxTTL,
|
||||||
defaultTTL,
|
defaultTTL,
|
||||||
name: newName ?? name,
|
name: newName ?? name,
|
||||||
@@ -312,13 +315,13 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
if (!dynamicSecretCfg) {
|
if (!dynamicSecretCfg) {
|
||||||
throw new NotFoundError({ message: `Dynamic secret with name '${name} in folder '${path}' not found` });
|
throw new NotFoundError({ message: `Dynamic secret with name '${name} in folder '${path}' not found` });
|
||||||
}
|
}
|
||||||
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId
|
|
||||||
});
|
|
||||||
|
|
||||||
const decryptedStoredInput = JSON.parse(
|
const decryptedStoredInput = JSON.parse(
|
||||||
secretManagerDecryptor({ cipherTextBlob: dynamicSecretCfg.encryptedInput }).toString()
|
infisicalSymmetricDecrypt({
|
||||||
|
keyEncoding: dynamicSecretCfg.keyEncoding as SecretKeyEncoding,
|
||||||
|
ciphertext: dynamicSecretCfg.inputCiphertext,
|
||||||
|
tag: dynamicSecretCfg.inputTag,
|
||||||
|
iv: dynamicSecretCfg.inputIV
|
||||||
|
})
|
||||||
) as object;
|
) as object;
|
||||||
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
const selectedProvider = dynamicSecretProviders[dynamicSecretCfg.type as DynamicSecretProviders];
|
||||||
const providerInputs = (await selectedProvider.validateProviderInputs(decryptedStoredInput)) as object;
|
const providerInputs = (await selectedProvider.validateProviderInputs(decryptedStoredInput)) as object;
|
||||||
|
|||||||
@@ -1,23 +1,25 @@
|
|||||||
import * as pkcs11js from "pkcs11js";
|
import * as pkcs11js from "pkcs11js";
|
||||||
|
|
||||||
import { TEnvConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { logger } from "@app/lib/logger";
|
import { logger } from "@app/lib/logger";
|
||||||
|
|
||||||
import { HsmModule } from "./hsm-types";
|
import { HsmModule } from "./hsm-types";
|
||||||
|
|
||||||
export const initializeHsmModule = (envConfig: Pick<TEnvConfig, "isHsmConfigured" | "HSM_LIB_PATH">) => {
|
export const initializeHsmModule = () => {
|
||||||
|
const appCfg = getConfig();
|
||||||
|
|
||||||
// Create a new instance of PKCS11 module
|
// Create a new instance of PKCS11 module
|
||||||
const pkcs11 = new pkcs11js.PKCS11();
|
const pkcs11 = new pkcs11js.PKCS11();
|
||||||
let isInitialized = false;
|
let isInitialized = false;
|
||||||
|
|
||||||
const initialize = () => {
|
const initialize = () => {
|
||||||
if (!envConfig.isHsmConfigured) {
|
if (!appCfg.isHsmConfigured) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Load the PKCS#11 module
|
// Load the PKCS#11 module
|
||||||
pkcs11.load(envConfig.HSM_LIB_PATH!);
|
pkcs11.load(appCfg.HSM_LIB_PATH!);
|
||||||
|
|
||||||
// Initialize the module
|
// Initialize the module
|
||||||
pkcs11.C_Initialize();
|
pkcs11.C_Initialize();
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import pkcs11js from "pkcs11js";
|
import pkcs11js from "pkcs11js";
|
||||||
|
|
||||||
import { TEnvConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { logger } from "@app/lib/logger";
|
import { logger } from "@app/lib/logger";
|
||||||
|
|
||||||
import { HsmKeyType, HsmModule } from "./hsm-types";
|
import { HsmKeyType, HsmModule } from "./hsm-types";
|
||||||
|
|
||||||
type THsmServiceFactoryDep = {
|
type THsmServiceFactoryDep = {
|
||||||
hsmModule: HsmModule;
|
hsmModule: HsmModule;
|
||||||
envConfig: Pick<TEnvConfig, "HSM_PIN" | "HSM_SLOT" | "HSM_LIB_PATH" | "HSM_KEY_LABEL" | "isHsmConfigured">;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type THsmServiceFactory = ReturnType<typeof hsmServiceFactory>;
|
export type THsmServiceFactory = ReturnType<typeof hsmServiceFactory>;
|
||||||
@@ -16,7 +15,9 @@ type SyncOrAsync<T> = T | Promise<T>;
|
|||||||
type SessionCallback<T> = (session: pkcs11js.Handle) => SyncOrAsync<T>;
|
type SessionCallback<T> = (session: pkcs11js.Handle) => SyncOrAsync<T>;
|
||||||
|
|
||||||
// eslint-disable-next-line no-empty-pattern
|
// eslint-disable-next-line no-empty-pattern
|
||||||
export const hsmServiceFactory = ({ hsmModule: { isInitialized, pkcs11 }, envConfig }: THsmServiceFactoryDep) => {
|
export const hsmServiceFactory = ({ hsmModule: { isInitialized, pkcs11 } }: THsmServiceFactoryDep) => {
|
||||||
|
const appCfg = getConfig();
|
||||||
|
|
||||||
// Constants for buffer structures
|
// Constants for buffer structures
|
||||||
const IV_LENGTH = 16; // Luna HSM typically expects 16-byte IV for cbc
|
const IV_LENGTH = 16; // Luna HSM typically expects 16-byte IV for cbc
|
||||||
const BLOCK_SIZE = 16;
|
const BLOCK_SIZE = 16;
|
||||||
@@ -62,11 +63,11 @@ export const hsmServiceFactory = ({ hsmModule: { isInitialized, pkcs11 }, envCon
|
|||||||
throw new Error("No slots available");
|
throw new Error("No slots available");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (envConfig.HSM_SLOT >= slots.length) {
|
if (appCfg.HSM_SLOT >= slots.length) {
|
||||||
throw new Error(`HSM slot ${envConfig.HSM_SLOT} not found or not initialized`);
|
throw new Error(`HSM slot ${appCfg.HSM_SLOT} not found or not initialized`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const slotId = slots[envConfig.HSM_SLOT];
|
const slotId = slots[appCfg.HSM_SLOT];
|
||||||
|
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
while (Date.now() - startTime < MAX_TIMEOUT) {
|
while (Date.now() - startTime < MAX_TIMEOUT) {
|
||||||
@@ -77,7 +78,7 @@ export const hsmServiceFactory = ({ hsmModule: { isInitialized, pkcs11 }, envCon
|
|||||||
|
|
||||||
// Login
|
// Login
|
||||||
try {
|
try {
|
||||||
pkcs11.C_Login(sessionHandle, pkcs11js.CKU_USER, envConfig.HSM_PIN);
|
pkcs11.C_Login(sessionHandle, pkcs11js.CKU_USER, appCfg.HSM_PIN);
|
||||||
logger.info("HSM: Successfully authenticated");
|
logger.info("HSM: Successfully authenticated");
|
||||||
break;
|
break;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -85,7 +86,7 @@ export const hsmServiceFactory = ({ hsmModule: { isInitialized, pkcs11 }, envCon
|
|||||||
if (error instanceof pkcs11js.Pkcs11Error) {
|
if (error instanceof pkcs11js.Pkcs11Error) {
|
||||||
if (error.code === pkcs11js.CKR_PIN_INCORRECT) {
|
if (error.code === pkcs11js.CKR_PIN_INCORRECT) {
|
||||||
// We throw instantly here to prevent further attempts, because if too many attempts are made, the HSM will potentially wipe all key material
|
// We throw instantly here to prevent further attempts, because if too many attempts are made, the HSM will potentially wipe all key material
|
||||||
logger.error(error, `HSM: Incorrect PIN detected for HSM slot ${envConfig.HSM_SLOT}`);
|
logger.error(error, `HSM: Incorrect PIN detected for HSM slot ${appCfg.HSM_SLOT}`);
|
||||||
throw new Error("HSM: Incorrect HSM Pin detected. Please check the HSM configuration.");
|
throw new Error("HSM: Incorrect HSM Pin detected. Please check the HSM configuration.");
|
||||||
}
|
}
|
||||||
if (error.code === pkcs11js.CKR_USER_ALREADY_LOGGED_IN) {
|
if (error.code === pkcs11js.CKR_USER_ALREADY_LOGGED_IN) {
|
||||||
@@ -132,7 +133,7 @@ export const hsmServiceFactory = ({ hsmModule: { isInitialized, pkcs11 }, envCon
|
|||||||
};
|
};
|
||||||
|
|
||||||
const $findKey = (sessionHandle: pkcs11js.Handle, type: HsmKeyType) => {
|
const $findKey = (sessionHandle: pkcs11js.Handle, type: HsmKeyType) => {
|
||||||
const label = type === HsmKeyType.HMAC ? `${envConfig.HSM_KEY_LABEL}_HMAC` : envConfig.HSM_KEY_LABEL;
|
const label = type === HsmKeyType.HMAC ? `${appCfg.HSM_KEY_LABEL}_HMAC` : appCfg.HSM_KEY_LABEL;
|
||||||
const keyType = type === HsmKeyType.HMAC ? pkcs11js.CKK_GENERIC_SECRET : pkcs11js.CKK_AES;
|
const keyType = type === HsmKeyType.HMAC ? pkcs11js.CKK_GENERIC_SECRET : pkcs11js.CKK_AES;
|
||||||
|
|
||||||
const template = [
|
const template = [
|
||||||
@@ -359,7 +360,7 @@ export const hsmServiceFactory = ({ hsmModule: { isInitialized, pkcs11 }, envCon
|
|||||||
};
|
};
|
||||||
|
|
||||||
const isActive = async () => {
|
const isActive = async () => {
|
||||||
if (!isInitialized || !envConfig.isHsmConfigured) {
|
if (!isInitialized || !appCfg.isHsmConfigured) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,11 +372,11 @@ export const hsmServiceFactory = ({ hsmModule: { isInitialized, pkcs11 }, envCon
|
|||||||
logger.error(err, "HSM: Error testing PKCS#11 module");
|
logger.error(err, "HSM: Error testing PKCS#11 module");
|
||||||
}
|
}
|
||||||
|
|
||||||
return envConfig.isHsmConfigured && isInitialized && pkcs11TestPassed;
|
return appCfg.isHsmConfigured && isInitialized && pkcs11TestPassed;
|
||||||
};
|
};
|
||||||
|
|
||||||
const startService = async () => {
|
const startService = async () => {
|
||||||
if (!envConfig.isHsmConfigured || !pkcs11 || !isInitialized) return;
|
if (!appCfg.isHsmConfigured || !pkcs11 || !isInitialized) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await $withSession(async (sessionHandle) => {
|
await $withSession(async (sessionHandle) => {
|
||||||
@@ -394,7 +395,7 @@ export const hsmServiceFactory = ({ hsmModule: { isInitialized, pkcs11 }, envCon
|
|||||||
{ type: pkcs11js.CKA_CLASS, value: pkcs11js.CKO_SECRET_KEY },
|
{ type: pkcs11js.CKA_CLASS, value: pkcs11js.CKO_SECRET_KEY },
|
||||||
{ type: pkcs11js.CKA_KEY_TYPE, value: pkcs11js.CKK_AES },
|
{ type: pkcs11js.CKA_KEY_TYPE, value: pkcs11js.CKK_AES },
|
||||||
{ type: pkcs11js.CKA_VALUE_LEN, value: AES_KEY_SIZE / 8 },
|
{ type: pkcs11js.CKA_VALUE_LEN, value: AES_KEY_SIZE / 8 },
|
||||||
{ type: pkcs11js.CKA_LABEL, value: envConfig.HSM_KEY_LABEL! },
|
{ type: pkcs11js.CKA_LABEL, value: appCfg.HSM_KEY_LABEL! },
|
||||||
{ type: pkcs11js.CKA_ENCRYPT, value: true }, // Allow encryption
|
{ type: pkcs11js.CKA_ENCRYPT, value: true }, // Allow encryption
|
||||||
{ type: pkcs11js.CKA_DECRYPT, value: true }, // Allow decryption
|
{ type: pkcs11js.CKA_DECRYPT, value: true }, // Allow decryption
|
||||||
...genericAttributes
|
...genericAttributes
|
||||||
@@ -409,7 +410,7 @@ export const hsmServiceFactory = ({ hsmModule: { isInitialized, pkcs11 }, envCon
|
|||||||
keyTemplate
|
keyTemplate
|
||||||
);
|
);
|
||||||
|
|
||||||
logger.info(`HSM: Master key created successfully with label: ${envConfig.HSM_KEY_LABEL}`);
|
logger.info(`HSM: Master key created successfully with label: ${appCfg.HSM_KEY_LABEL}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if HMAC key exists, create if not
|
// Check if HMAC key exists, create if not
|
||||||
@@ -418,7 +419,7 @@ export const hsmServiceFactory = ({ hsmModule: { isInitialized, pkcs11 }, envCon
|
|||||||
{ type: pkcs11js.CKA_CLASS, value: pkcs11js.CKO_SECRET_KEY },
|
{ type: pkcs11js.CKA_CLASS, value: pkcs11js.CKO_SECRET_KEY },
|
||||||
{ type: pkcs11js.CKA_KEY_TYPE, value: pkcs11js.CKK_GENERIC_SECRET },
|
{ type: pkcs11js.CKA_KEY_TYPE, value: pkcs11js.CKK_GENERIC_SECRET },
|
||||||
{ type: pkcs11js.CKA_VALUE_LEN, value: HMAC_KEY_SIZE / 8 }, // 256-bit key
|
{ type: pkcs11js.CKA_VALUE_LEN, value: HMAC_KEY_SIZE / 8 }, // 256-bit key
|
||||||
{ type: pkcs11js.CKA_LABEL, value: `${envConfig.HSM_KEY_LABEL!}_HMAC` },
|
{ type: pkcs11js.CKA_LABEL, value: `${appCfg.HSM_KEY_LABEL!}_HMAC` },
|
||||||
{ type: pkcs11js.CKA_SIGN, value: true }, // Allow signing
|
{ type: pkcs11js.CKA_SIGN, value: true }, // Allow signing
|
||||||
{ type: pkcs11js.CKA_VERIFY, value: true }, // Allow verification
|
{ type: pkcs11js.CKA_VERIFY, value: true }, // Allow verification
|
||||||
...genericAttributes
|
...genericAttributes
|
||||||
@@ -433,7 +434,7 @@ export const hsmServiceFactory = ({ hsmModule: { isInitialized, pkcs11 }, envCon
|
|||||||
hmacKeyTemplate
|
hmacKeyTemplate
|
||||||
);
|
);
|
||||||
|
|
||||||
logger.info(`HSM: HMAC key created successfully with label: ${envConfig.HSM_KEY_LABEL}_HMAC`);
|
logger.info(`HSM: HMAC key created successfully with label: ${appCfg.HSM_KEY_LABEL}_HMAC`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get slot info to check supported mechanisms
|
// Get slot info to check supported mechanisms
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ import ms from "ms";
|
|||||||
import { ActionProjectType, TableName } from "@app/db/schemas";
|
import { ActionProjectType, TableName } from "@app/db/schemas";
|
||||||
import { isAtLeastAsPrivileged } from "@app/lib/casl";
|
import { isAtLeastAsPrivileged } from "@app/lib/casl";
|
||||||
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
import { unpackPermissions } from "@app/server/routes/sanitizedSchema/permission";
|
import { unpackPermissions } from "@app/server/routes/santizedSchemas/permission";
|
||||||
import { ActorType } from "@app/services/auth/auth-type";
|
import { ActorType } from "@app/services/auth/auth-type";
|
||||||
import { TIdentityProjectDALFactory } from "@app/services/identity-project/identity-project-dal";
|
import { TIdentityProjectDALFactory } from "@app/services/identity-project/identity-project-dal";
|
||||||
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ import ms from "ms";
|
|||||||
import { ActionProjectType } from "@app/db/schemas";
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { isAtLeastAsPrivileged } from "@app/lib/casl";
|
import { isAtLeastAsPrivileged } from "@app/lib/casl";
|
||||||
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
import { UnpackedPermissionSchema } from "@app/server/routes/sanitizedSchema/permission";
|
import { UnpackedPermissionSchema } from "@app/server/routes/santizedSchemas/permission";
|
||||||
import { ActorType } from "@app/services/auth/auth-type";
|
import { ActorType } from "@app/services/auth/auth-type";
|
||||||
import { TIdentityProjectDALFactory } from "@app/services/identity-project/identity-project-dal";
|
import { TIdentityProjectDALFactory } from "@app/services/identity-project/identity-project-dal";
|
||||||
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
||||||
|
|||||||
@@ -1,18 +1,25 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
|
|
||||||
import { OrgMembershipStatus, TableName, TLdapConfigsUpdate, TUsers } from "@app/db/schemas";
|
import { OrgMembershipStatus, SecretKeyEncoding, TableName, TLdapConfigsUpdate, TUsers } from "@app/db/schemas";
|
||||||
import { TGroupDALFactory } from "@app/ee/services/group/group-dal";
|
import { TGroupDALFactory } from "@app/ee/services/group/group-dal";
|
||||||
import { addUsersToGroupByUserIds, removeUsersFromGroupByUserIds } from "@app/ee/services/group/group-fns";
|
import { addUsersToGroupByUserIds, removeUsersFromGroupByUserIds } from "@app/ee/services/group/group-fns";
|
||||||
import { TUserGroupMembershipDALFactory } from "@app/ee/services/group/user-group-membership-dal";
|
import { TUserGroupMembershipDALFactory } from "@app/ee/services/group/user-group-membership-dal";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
|
import {
|
||||||
|
decryptSymmetric,
|
||||||
|
encryptSymmetric,
|
||||||
|
generateAsymmetricKeyPair,
|
||||||
|
generateSymmetricKey,
|
||||||
|
infisicalSymmetricDecrypt,
|
||||||
|
infisicalSymmetricEncypt
|
||||||
|
} from "@app/lib/crypto/encryption";
|
||||||
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
import { AuthMethod, AuthTokenType } from "@app/services/auth/auth-type";
|
import { AuthMethod, AuthTokenType } from "@app/services/auth/auth-type";
|
||||||
import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-service";
|
import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-service";
|
||||||
import { TokenType } from "@app/services/auth-token/auth-token-types";
|
import { TokenType } from "@app/services/auth-token/auth-token-types";
|
||||||
import { TGroupProjectDALFactory } from "@app/services/group-project/group-project-dal";
|
import { TGroupProjectDALFactory } from "@app/services/group-project/group-project-dal";
|
||||||
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
|
import { TOrgBotDALFactory } from "@app/services/org/org-bot-dal";
|
||||||
import { KmsDataKey } from "@app/services/kms/kms-types";
|
|
||||||
import { TOrgDALFactory } from "@app/services/org/org-dal";
|
import { TOrgDALFactory } from "@app/services/org/org-dal";
|
||||||
import { getDefaultOrgMembershipRole } from "@app/services/org/org-role-fns";
|
import { getDefaultOrgMembershipRole } from "@app/services/org/org-role-fns";
|
||||||
import { TOrgMembershipDALFactory } from "@app/services/org-membership/org-membership-dal";
|
import { TOrgMembershipDALFactory } from "@app/services/org-membership/org-membership-dal";
|
||||||
@@ -52,6 +59,7 @@ type TLdapConfigServiceFactoryDep = {
|
|||||||
TOrgDALFactory,
|
TOrgDALFactory,
|
||||||
"createMembership" | "updateMembershipById" | "findMembership" | "findOrgById" | "findOne" | "updateById"
|
"createMembership" | "updateMembershipById" | "findMembership" | "findOrgById" | "findOne" | "updateById"
|
||||||
>;
|
>;
|
||||||
|
orgBotDAL: Pick<TOrgBotDALFactory, "findOne" | "create" | "transaction">;
|
||||||
groupDAL: Pick<TGroupDALFactory, "find" | "findOne">;
|
groupDAL: Pick<TGroupDALFactory, "find" | "findOne">;
|
||||||
groupProjectDAL: Pick<TGroupProjectDALFactory, "find">;
|
groupProjectDAL: Pick<TGroupProjectDALFactory, "find">;
|
||||||
projectKeyDAL: Pick<TProjectKeyDALFactory, "find" | "findLatestProjectKey" | "insertMany" | "delete">;
|
projectKeyDAL: Pick<TProjectKeyDALFactory, "find" | "findLatestProjectKey" | "insertMany" | "delete">;
|
||||||
@@ -76,7 +84,6 @@ type TLdapConfigServiceFactoryDep = {
|
|||||||
licenseService: Pick<TLicenseServiceFactory, "getPlan" | "updateSubscriptionOrgMemberCount">;
|
licenseService: Pick<TLicenseServiceFactory, "getPlan" | "updateSubscriptionOrgMemberCount">;
|
||||||
tokenService: Pick<TAuthTokenServiceFactory, "createTokenForUser">;
|
tokenService: Pick<TAuthTokenServiceFactory, "createTokenForUser">;
|
||||||
smtpService: Pick<TSmtpService, "sendMail">;
|
smtpService: Pick<TSmtpService, "sendMail">;
|
||||||
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TLdapConfigServiceFactory = ReturnType<typeof ldapConfigServiceFactory>;
|
export type TLdapConfigServiceFactory = ReturnType<typeof ldapConfigServiceFactory>;
|
||||||
@@ -86,6 +93,7 @@ export const ldapConfigServiceFactory = ({
|
|||||||
ldapGroupMapDAL,
|
ldapGroupMapDAL,
|
||||||
orgDAL,
|
orgDAL,
|
||||||
orgMembershipDAL,
|
orgMembershipDAL,
|
||||||
|
orgBotDAL,
|
||||||
groupDAL,
|
groupDAL,
|
||||||
groupProjectDAL,
|
groupProjectDAL,
|
||||||
projectKeyDAL,
|
projectKeyDAL,
|
||||||
@@ -97,8 +105,7 @@ export const ldapConfigServiceFactory = ({
|
|||||||
permissionService,
|
permissionService,
|
||||||
licenseService,
|
licenseService,
|
||||||
tokenService,
|
tokenService,
|
||||||
smtpService,
|
smtpService
|
||||||
kmsService
|
|
||||||
}: TLdapConfigServiceFactoryDep) => {
|
}: TLdapConfigServiceFactoryDep) => {
|
||||||
const createLdapCfg = async ({
|
const createLdapCfg = async ({
|
||||||
actor,
|
actor,
|
||||||
@@ -126,23 +133,77 @@ export const ldapConfigServiceFactory = ({
|
|||||||
message:
|
message:
|
||||||
"Failed to create LDAP configuration due to plan restriction. Upgrade plan to create LDAP configuration."
|
"Failed to create LDAP configuration due to plan restriction. Upgrade plan to create LDAP configuration."
|
||||||
});
|
});
|
||||||
const { encryptor } = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.Organization,
|
const orgBot = await orgBotDAL.transaction(async (tx) => {
|
||||||
orgId
|
const doc = await orgBotDAL.findOne({ orgId }, tx);
|
||||||
|
if (doc) return doc;
|
||||||
|
|
||||||
|
const { privateKey, publicKey } = generateAsymmetricKeyPair();
|
||||||
|
const key = generateSymmetricKey();
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedPrivateKey,
|
||||||
|
iv: privateKeyIV,
|
||||||
|
tag: privateKeyTag,
|
||||||
|
encoding: privateKeyKeyEncoding,
|
||||||
|
algorithm: privateKeyAlgorithm
|
||||||
|
} = infisicalSymmetricEncypt(privateKey);
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedSymmetricKey,
|
||||||
|
iv: symmetricKeyIV,
|
||||||
|
tag: symmetricKeyTag,
|
||||||
|
encoding: symmetricKeyKeyEncoding,
|
||||||
|
algorithm: symmetricKeyAlgorithm
|
||||||
|
} = infisicalSymmetricEncypt(key);
|
||||||
|
|
||||||
|
return orgBotDAL.create(
|
||||||
|
{
|
||||||
|
name: "Infisical org bot",
|
||||||
|
publicKey,
|
||||||
|
privateKeyIV,
|
||||||
|
encryptedPrivateKey,
|
||||||
|
symmetricKeyIV,
|
||||||
|
symmetricKeyTag,
|
||||||
|
encryptedSymmetricKey,
|
||||||
|
symmetricKeyAlgorithm,
|
||||||
|
orgId,
|
||||||
|
privateKeyTag,
|
||||||
|
privateKeyAlgorithm,
|
||||||
|
privateKeyKeyEncoding,
|
||||||
|
symmetricKeyKeyEncoding
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
|
});
|
||||||
|
|
||||||
|
const { ciphertext: encryptedBindDN, iv: bindDNIV, tag: bindDNTag } = encryptSymmetric(bindDN, key);
|
||||||
|
const { ciphertext: encryptedBindPass, iv: bindPassIV, tag: bindPassTag } = encryptSymmetric(bindPass, key);
|
||||||
|
const { ciphertext: encryptedCACert, iv: caCertIV, tag: caCertTag } = encryptSymmetric(caCert, key);
|
||||||
|
|
||||||
const ldapConfig = await ldapConfigDAL.create({
|
const ldapConfig = await ldapConfigDAL.create({
|
||||||
orgId,
|
orgId,
|
||||||
isActive,
|
isActive,
|
||||||
url,
|
url,
|
||||||
|
encryptedBindDN,
|
||||||
|
bindDNIV,
|
||||||
|
bindDNTag,
|
||||||
|
encryptedBindPass,
|
||||||
|
bindPassIV,
|
||||||
|
bindPassTag,
|
||||||
uniqueUserAttribute,
|
uniqueUserAttribute,
|
||||||
searchBase,
|
searchBase,
|
||||||
searchFilter,
|
searchFilter,
|
||||||
groupSearchBase,
|
groupSearchBase,
|
||||||
groupSearchFilter,
|
groupSearchFilter,
|
||||||
encryptedLdapCaCertificate: encryptor({ plainText: Buffer.from(caCert) }).cipherTextBlob,
|
encryptedCACert,
|
||||||
encryptedLdapBindDN: encryptor({ plainText: Buffer.from(bindDN) }).cipherTextBlob,
|
caCertIV,
|
||||||
encryptedLdapBindPass: encryptor({ plainText: Buffer.from(bindPass) }).cipherTextBlob
|
caCertTag
|
||||||
});
|
});
|
||||||
|
|
||||||
return ldapConfig;
|
return ldapConfig;
|
||||||
@@ -185,21 +246,38 @@ export const ldapConfigServiceFactory = ({
|
|||||||
uniqueUserAttribute
|
uniqueUserAttribute
|
||||||
};
|
};
|
||||||
|
|
||||||
const { encryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.findOne({ orgId });
|
||||||
type: KmsDataKey.Organization,
|
if (!orgBot)
|
||||||
orgId
|
throw new NotFoundError({
|
||||||
|
message: `Organization bot in organization with ID '${orgId}' not found`,
|
||||||
|
name: "OrgBotNotFound"
|
||||||
|
});
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
});
|
});
|
||||||
|
|
||||||
if (bindDN !== undefined) {
|
if (bindDN !== undefined) {
|
||||||
updateQuery.encryptedLdapBindDN = encryptor({ plainText: Buffer.from(bindDN) }).cipherTextBlob;
|
const { ciphertext: encryptedBindDN, iv: bindDNIV, tag: bindDNTag } = encryptSymmetric(bindDN, key);
|
||||||
|
updateQuery.encryptedBindDN = encryptedBindDN;
|
||||||
|
updateQuery.bindDNIV = bindDNIV;
|
||||||
|
updateQuery.bindDNTag = bindDNTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bindPass !== undefined) {
|
if (bindPass !== undefined) {
|
||||||
updateQuery.encryptedLdapBindPass = encryptor({ plainText: Buffer.from(bindPass) }).cipherTextBlob;
|
const { ciphertext: encryptedBindPass, iv: bindPassIV, tag: bindPassTag } = encryptSymmetric(bindPass, key);
|
||||||
|
updateQuery.encryptedBindPass = encryptedBindPass;
|
||||||
|
updateQuery.bindPassIV = bindPassIV;
|
||||||
|
updateQuery.bindPassTag = bindPassTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (caCert !== undefined) {
|
if (caCert !== undefined) {
|
||||||
updateQuery.encryptedLdapCaCertificate = encryptor({ plainText: Buffer.from(caCert) }).cipherTextBlob;
|
const { ciphertext: encryptedCACert, iv: caCertIV, tag: caCertTag } = encryptSymmetric(caCert, key);
|
||||||
|
updateQuery.encryptedCACert = encryptedCACert;
|
||||||
|
updateQuery.caCertIV = caCertIV;
|
||||||
|
updateQuery.caCertTag = caCertTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [ldapConfig] = await ldapConfigDAL.update({ orgId }, updateQuery);
|
const [ldapConfig] = await ldapConfigDAL.update({ orgId }, updateQuery);
|
||||||
@@ -215,24 +293,61 @@ export const ldapConfigServiceFactory = ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const { decryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.findOne({ orgId: ldapConfig.orgId });
|
||||||
type: KmsDataKey.Organization,
|
if (!orgBot) {
|
||||||
orgId: ldapConfig.orgId
|
throw new NotFoundError({
|
||||||
|
message: `Organization bot not found in organization with ID ${ldapConfig.orgId}`,
|
||||||
|
name: "OrgBotNotFound"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
encryptedBindDN,
|
||||||
|
bindDNIV,
|
||||||
|
bindDNTag,
|
||||||
|
encryptedBindPass,
|
||||||
|
bindPassIV,
|
||||||
|
bindPassTag,
|
||||||
|
encryptedCACert,
|
||||||
|
caCertIV,
|
||||||
|
caCertTag
|
||||||
|
} = ldapConfig;
|
||||||
|
|
||||||
let bindDN = "";
|
let bindDN = "";
|
||||||
if (ldapConfig.encryptedLdapBindDN) {
|
if (encryptedBindDN && bindDNIV && bindDNTag) {
|
||||||
bindDN = decryptor({ cipherTextBlob: ldapConfig.encryptedLdapBindDN }).toString();
|
bindDN = decryptSymmetric({
|
||||||
|
ciphertext: encryptedBindDN,
|
||||||
|
key,
|
||||||
|
tag: bindDNTag,
|
||||||
|
iv: bindDNIV
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let bindPass = "";
|
let bindPass = "";
|
||||||
if (ldapConfig.encryptedLdapBindPass) {
|
if (encryptedBindPass && bindPassIV && bindPassTag) {
|
||||||
bindPass = decryptor({ cipherTextBlob: ldapConfig.encryptedLdapBindPass }).toString();
|
bindPass = decryptSymmetric({
|
||||||
|
ciphertext: encryptedBindPass,
|
||||||
|
key,
|
||||||
|
tag: bindPassTag,
|
||||||
|
iv: bindPassIV
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let caCert = "";
|
let caCert = "";
|
||||||
if (ldapConfig.encryptedLdapCaCertificate) {
|
if (encryptedCACert && caCertIV && caCertTag) {
|
||||||
caCert = decryptor({ cipherTextBlob: ldapConfig.encryptedLdapCaCertificate }).toString();
|
caCert = decryptSymmetric({
|
||||||
|
ciphertext: encryptedCACert,
|
||||||
|
key,
|
||||||
|
tag: caCertTag,
|
||||||
|
iv: caCertIV
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ForbiddenError } from "@casl/ability";
|
|||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import { Issuer, Issuer as OpenIdIssuer, Strategy as OpenIdStrategy, TokenSet } from "openid-client";
|
import { Issuer, Issuer as OpenIdIssuer, Strategy as OpenIdStrategy, TokenSet } from "openid-client";
|
||||||
|
|
||||||
import { OrgMembershipStatus, TableName, TUsers } from "@app/db/schemas";
|
import { OrgMembershipStatus, SecretKeyEncoding, TableName, TUsers } from "@app/db/schemas";
|
||||||
import { TOidcConfigsUpdate } from "@app/db/schemas/oidc-configs";
|
import { TOidcConfigsUpdate } from "@app/db/schemas/oidc-configs";
|
||||||
import { TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-service";
|
import { TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-service";
|
||||||
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
||||||
@@ -14,14 +14,21 @@ import { TLicenseServiceFactory } from "@app/ee/services/license/license-service
|
|||||||
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
|
import {
|
||||||
|
decryptSymmetric,
|
||||||
|
encryptSymmetric,
|
||||||
|
generateAsymmetricKeyPair,
|
||||||
|
generateSymmetricKey,
|
||||||
|
infisicalSymmetricDecrypt,
|
||||||
|
infisicalSymmetricEncypt
|
||||||
|
} from "@app/lib/crypto/encryption";
|
||||||
import { BadRequestError, ForbiddenRequestError, NotFoundError, OidcAuthError } from "@app/lib/errors";
|
import { BadRequestError, ForbiddenRequestError, NotFoundError, OidcAuthError } from "@app/lib/errors";
|
||||||
import { OrgServiceActor } from "@app/lib/types";
|
import { OrgServiceActor } from "@app/lib/types";
|
||||||
import { ActorType, AuthMethod, AuthTokenType } from "@app/services/auth/auth-type";
|
import { ActorType, AuthMethod, AuthTokenType } from "@app/services/auth/auth-type";
|
||||||
import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-service";
|
import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-service";
|
||||||
import { TokenType } from "@app/services/auth-token/auth-token-types";
|
import { TokenType } from "@app/services/auth-token/auth-token-types";
|
||||||
import { TGroupProjectDALFactory } from "@app/services/group-project/group-project-dal";
|
import { TGroupProjectDALFactory } from "@app/services/group-project/group-project-dal";
|
||||||
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
|
import { TOrgBotDALFactory } from "@app/services/org/org-bot-dal";
|
||||||
import { KmsDataKey } from "@app/services/kms/kms-types";
|
|
||||||
import { TOrgDALFactory } from "@app/services/org/org-dal";
|
import { TOrgDALFactory } from "@app/services/org/org-dal";
|
||||||
import { getDefaultOrgMembershipRole } from "@app/services/org/org-role-fns";
|
import { getDefaultOrgMembershipRole } from "@app/services/org/org-role-fns";
|
||||||
import { TOrgMembershipDALFactory } from "@app/services/org-membership/org-membership-dal";
|
import { TOrgMembershipDALFactory } from "@app/services/org-membership/org-membership-dal";
|
||||||
@@ -63,6 +70,7 @@ type TOidcConfigServiceFactoryDep = {
|
|||||||
"createMembership" | "updateMembershipById" | "findMembership" | "findOrgById" | "findOne" | "updateById"
|
"createMembership" | "updateMembershipById" | "findMembership" | "findOrgById" | "findOne" | "updateById"
|
||||||
>;
|
>;
|
||||||
orgMembershipDAL: Pick<TOrgMembershipDALFactory, "create">;
|
orgMembershipDAL: Pick<TOrgMembershipDALFactory, "create">;
|
||||||
|
orgBotDAL: Pick<TOrgBotDALFactory, "findOne" | "create" | "transaction">;
|
||||||
licenseService: Pick<TLicenseServiceFactory, "getPlan" | "updateSubscriptionOrgMemberCount">;
|
licenseService: Pick<TLicenseServiceFactory, "getPlan" | "updateSubscriptionOrgMemberCount">;
|
||||||
tokenService: Pick<TAuthTokenServiceFactory, "createTokenForUser">;
|
tokenService: Pick<TAuthTokenServiceFactory, "createTokenForUser">;
|
||||||
smtpService: Pick<TSmtpService, "sendMail" | "verify">;
|
smtpService: Pick<TSmtpService, "sendMail" | "verify">;
|
||||||
@@ -83,7 +91,6 @@ type TOidcConfigServiceFactoryDep = {
|
|||||||
projectDAL: Pick<TProjectDALFactory, "findProjectGhostUser">;
|
projectDAL: Pick<TProjectDALFactory, "findProjectGhostUser">;
|
||||||
projectBotDAL: Pick<TProjectBotDALFactory, "findOne">;
|
projectBotDAL: Pick<TProjectBotDALFactory, "findOne">;
|
||||||
auditLogService: Pick<TAuditLogServiceFactory, "createAuditLog">;
|
auditLogService: Pick<TAuditLogServiceFactory, "createAuditLog">;
|
||||||
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TOidcConfigServiceFactory = ReturnType<typeof oidcConfigServiceFactory>;
|
export type TOidcConfigServiceFactory = ReturnType<typeof oidcConfigServiceFactory>;
|
||||||
@@ -96,6 +103,7 @@ export const oidcConfigServiceFactory = ({
|
|||||||
licenseService,
|
licenseService,
|
||||||
permissionService,
|
permissionService,
|
||||||
tokenService,
|
tokenService,
|
||||||
|
orgBotDAL,
|
||||||
smtpService,
|
smtpService,
|
||||||
oidcConfigDAL,
|
oidcConfigDAL,
|
||||||
userGroupMembershipDAL,
|
userGroupMembershipDAL,
|
||||||
@@ -104,8 +112,7 @@ export const oidcConfigServiceFactory = ({
|
|||||||
projectKeyDAL,
|
projectKeyDAL,
|
||||||
projectDAL,
|
projectDAL,
|
||||||
projectBotDAL,
|
projectBotDAL,
|
||||||
auditLogService,
|
auditLogService
|
||||||
kmsService
|
|
||||||
}: TOidcConfigServiceFactoryDep) => {
|
}: TOidcConfigServiceFactoryDep) => {
|
||||||
const getOidc = async (dto: TGetOidcCfgDTO) => {
|
const getOidc = async (dto: TGetOidcCfgDTO) => {
|
||||||
const org = await orgDAL.findOne({ slug: dto.orgSlug });
|
const org = await orgDAL.findOne({ slug: dto.orgSlug });
|
||||||
@@ -136,19 +143,43 @@ export const oidcConfigServiceFactory = ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const { decryptor } = await kmsService.createCipherPairWithDataKey({
|
// decrypt and return cfg
|
||||||
type: KmsDataKey.Organization,
|
const orgBot = await orgBotDAL.findOne({ orgId: oidcCfg.orgId });
|
||||||
orgId: oidcCfg.orgId
|
if (!orgBot) {
|
||||||
|
throw new NotFoundError({
|
||||||
|
message: `Organization bot for organization with ID '${oidcCfg.orgId}' not found`,
|
||||||
|
name: "OrgBotNotFound"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { encryptedClientId, clientIdIV, clientIdTag, encryptedClientSecret, clientSecretIV, clientSecretTag } =
|
||||||
|
oidcCfg;
|
||||||
|
|
||||||
let clientId = "";
|
let clientId = "";
|
||||||
if (oidcCfg.encryptedOidcClientId) {
|
if (encryptedClientId && clientIdIV && clientIdTag) {
|
||||||
clientId = decryptor({ cipherTextBlob: oidcCfg.encryptedOidcClientId }).toString();
|
clientId = decryptSymmetric({
|
||||||
|
ciphertext: encryptedClientId,
|
||||||
|
key,
|
||||||
|
tag: clientIdTag,
|
||||||
|
iv: clientIdIV
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let clientSecret = "";
|
let clientSecret = "";
|
||||||
if (oidcCfg.encryptedOidcClientSecret) {
|
if (encryptedClientSecret && clientSecretIV && clientSecretTag) {
|
||||||
clientSecret = decryptor({ cipherTextBlob: oidcCfg.encryptedOidcClientSecret }).toString();
|
clientSecret = decryptSymmetric({
|
||||||
|
key,
|
||||||
|
tag: clientSecretTag,
|
||||||
|
iv: clientSecretIV,
|
||||||
|
ciphertext: encryptedClientSecret
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -509,9 +540,11 @@ export const oidcConfigServiceFactory = ({
|
|||||||
);
|
);
|
||||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Sso);
|
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Sso);
|
||||||
|
|
||||||
const { encryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.findOne({ orgId: org.id });
|
||||||
type: KmsDataKey.Organization,
|
if (!orgBot)
|
||||||
orgId: org.id
|
throw new NotFoundError({
|
||||||
|
message: `Organization bot for organization with ID '${org.id}' not found`,
|
||||||
|
name: "OrgBotNotFound"
|
||||||
});
|
});
|
||||||
|
|
||||||
const serverCfg = await getServerCfg();
|
const serverCfg = await getServerCfg();
|
||||||
@@ -525,6 +558,13 @@ export const oidcConfigServiceFactory = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
|
});
|
||||||
|
|
||||||
const updateQuery: TOidcConfigsUpdate = {
|
const updateQuery: TOidcConfigsUpdate = {
|
||||||
allowedEmailDomains,
|
allowedEmailDomains,
|
||||||
configurationType,
|
configurationType,
|
||||||
@@ -540,11 +580,22 @@ export const oidcConfigServiceFactory = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (clientId !== undefined) {
|
if (clientId !== undefined) {
|
||||||
updateQuery.encryptedOidcClientId = encryptor({ plainText: Buffer.from(clientId) }).cipherTextBlob;
|
const { ciphertext: encryptedClientId, iv: clientIdIV, tag: clientIdTag } = encryptSymmetric(clientId, key);
|
||||||
|
updateQuery.encryptedClientId = encryptedClientId;
|
||||||
|
updateQuery.clientIdIV = clientIdIV;
|
||||||
|
updateQuery.clientIdTag = clientIdTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clientSecret !== undefined) {
|
if (clientSecret !== undefined) {
|
||||||
updateQuery.encryptedOidcClientSecret = encryptor({ plainText: Buffer.from(clientSecret) }).cipherTextBlob;
|
const {
|
||||||
|
ciphertext: encryptedClientSecret,
|
||||||
|
iv: clientSecretIV,
|
||||||
|
tag: clientSecretTag
|
||||||
|
} = encryptSymmetric(clientSecret, key);
|
||||||
|
|
||||||
|
updateQuery.encryptedClientSecret = encryptedClientSecret;
|
||||||
|
updateQuery.clientSecretIV = clientSecretIV;
|
||||||
|
updateQuery.clientSecretTag = clientSecretTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [ssoConfig] = await oidcConfigDAL.update({ orgId: org.id }, updateQuery);
|
const [ssoConfig] = await oidcConfigDAL.update({ orgId: org.id }, updateQuery);
|
||||||
@@ -596,11 +647,61 @@ export const oidcConfigServiceFactory = ({
|
|||||||
);
|
);
|
||||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.Sso);
|
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.Sso);
|
||||||
|
|
||||||
const { encryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.transaction(async (tx) => {
|
||||||
type: KmsDataKey.Organization,
|
const doc = await orgBotDAL.findOne({ orgId: org.id }, tx);
|
||||||
orgId: org.id
|
if (doc) return doc;
|
||||||
|
|
||||||
|
const { privateKey, publicKey } = generateAsymmetricKeyPair();
|
||||||
|
const key = generateSymmetricKey();
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedPrivateKey,
|
||||||
|
iv: privateKeyIV,
|
||||||
|
tag: privateKeyTag,
|
||||||
|
encoding: privateKeyKeyEncoding,
|
||||||
|
algorithm: privateKeyAlgorithm
|
||||||
|
} = infisicalSymmetricEncypt(privateKey);
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedSymmetricKey,
|
||||||
|
iv: symmetricKeyIV,
|
||||||
|
tag: symmetricKeyTag,
|
||||||
|
encoding: symmetricKeyKeyEncoding,
|
||||||
|
algorithm: symmetricKeyAlgorithm
|
||||||
|
} = infisicalSymmetricEncypt(key);
|
||||||
|
|
||||||
|
return orgBotDAL.create(
|
||||||
|
{
|
||||||
|
name: "Infisical org bot",
|
||||||
|
publicKey,
|
||||||
|
privateKeyIV,
|
||||||
|
encryptedPrivateKey,
|
||||||
|
symmetricKeyIV,
|
||||||
|
symmetricKeyTag,
|
||||||
|
encryptedSymmetricKey,
|
||||||
|
symmetricKeyAlgorithm,
|
||||||
|
orgId: org.id,
|
||||||
|
privateKeyTag,
|
||||||
|
privateKeyAlgorithm,
|
||||||
|
privateKeyKeyEncoding,
|
||||||
|
symmetricKeyKeyEncoding
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
|
});
|
||||||
|
|
||||||
|
const { ciphertext: encryptedClientId, iv: clientIdIV, tag: clientIdTag } = encryptSymmetric(clientId, key);
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedClientSecret,
|
||||||
|
iv: clientSecretIV,
|
||||||
|
tag: clientSecretTag
|
||||||
|
} = encryptSymmetric(clientSecret, key);
|
||||||
|
|
||||||
const oidcCfg = await oidcConfigDAL.create({
|
const oidcCfg = await oidcConfigDAL.create({
|
||||||
issuer,
|
issuer,
|
||||||
isActive,
|
isActive,
|
||||||
@@ -612,9 +713,13 @@ export const oidcConfigServiceFactory = ({
|
|||||||
tokenEndpoint,
|
tokenEndpoint,
|
||||||
userinfoEndpoint,
|
userinfoEndpoint,
|
||||||
orgId: org.id,
|
orgId: org.id,
|
||||||
manageGroupMemberships,
|
encryptedClientId,
|
||||||
encryptedOidcClientId: encryptor({ plainText: Buffer.from(clientId) }).cipherTextBlob,
|
clientIdIV,
|
||||||
encryptedOidcClientSecret: encryptor({ plainText: Buffer.from(clientSecret) }).cipherTextBlob
|
clientIdTag,
|
||||||
|
encryptedClientSecret,
|
||||||
|
clientSecretIV,
|
||||||
|
clientSecretTag,
|
||||||
|
manageGroupMemberships
|
||||||
});
|
});
|
||||||
|
|
||||||
return oidcCfg;
|
return oidcCfg;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
CASL_ACTION_SCHEMA_NATIVE_ENUM
|
CASL_ACTION_SCHEMA_NATIVE_ENUM
|
||||||
} from "@app/ee/services/permission/permission-schemas";
|
} from "@app/ee/services/permission/permission-schemas";
|
||||||
import { conditionsMatcher, PermissionConditionOperators } from "@app/lib/casl";
|
import { conditionsMatcher, PermissionConditionOperators } from "@app/lib/casl";
|
||||||
import { UnpackedPermissionSchema } from "@app/server/routes/sanitizedSchema/permission";
|
import { UnpackedPermissionSchema } from "@app/server/routes/santizedSchemas/permission";
|
||||||
|
|
||||||
import { PermissionConditionSchema } from "./permission-types";
|
import { PermissionConditionSchema } from "./permission-types";
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
} from "@app/ee/services/project-template/project-template-types";
|
} from "@app/ee/services/project-template/project-template-types";
|
||||||
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
import { OrgServiceActor } from "@app/lib/types";
|
import { OrgServiceActor } from "@app/lib/types";
|
||||||
import { unpackPermissions } from "@app/server/routes/sanitizedSchema/permission";
|
import { unpackPermissions } from "@app/server/routes/santizedSchemas/permission";
|
||||||
import { getPredefinedRoles } from "@app/services/project-role/project-role-fns";
|
import { getPredefinedRoles } from "@app/services/project-role/project-role-fns";
|
||||||
|
|
||||||
import { TProjectTemplateDALFactory } from "./project-template-dal";
|
import { TProjectTemplateDALFactory } from "./project-template-dal";
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|||||||
|
|
||||||
import { TProjectEnvironments } from "@app/db/schemas";
|
import { TProjectEnvironments } from "@app/db/schemas";
|
||||||
import { TProjectPermissionV2Schema } from "@app/ee/services/permission/project-permission";
|
import { TProjectPermissionV2Schema } from "@app/ee/services/permission/project-permission";
|
||||||
import { UnpackedPermissionSchema } from "@app/server/routes/sanitizedSchema/permission";
|
import { UnpackedPermissionSchema } from "@app/server/routes/santizedSchemas/permission";
|
||||||
|
|
||||||
export type TProjectTemplateEnvironment = Pick<TProjectEnvironments, "name" | "slug" | "position">;
|
export type TProjectTemplateEnvironment = Pick<TProjectEnvironments, "name" | "slug" | "position">;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ import ms from "ms";
|
|||||||
import { ActionProjectType, TableName } from "@app/db/schemas";
|
import { ActionProjectType, TableName } from "@app/db/schemas";
|
||||||
import { isAtLeastAsPrivileged } from "@app/lib/casl";
|
import { isAtLeastAsPrivileged } from "@app/lib/casl";
|
||||||
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
import { UnpackedPermissionSchema } from "@app/server/routes/sanitizedSchema/permission";
|
import { UnpackedPermissionSchema } from "@app/server/routes/santizedSchemas/permission";
|
||||||
import { ActorType } from "@app/services/auth/auth-type";
|
import { ActorType } from "@app/services/auth/auth-type";
|
||||||
import { TProjectMembershipDALFactory } from "@app/services/project-membership/project-membership-dal";
|
import { TProjectMembershipDALFactory } from "@app/services/project-membership/project-membership-dal";
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,29 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
|
|
||||||
import { OrgMembershipStatus, TableName, TSamlConfigs, TSamlConfigsUpdate, TUsers } from "@app/db/schemas";
|
import {
|
||||||
|
OrgMembershipStatus,
|
||||||
|
SecretKeyEncoding,
|
||||||
|
TableName,
|
||||||
|
TSamlConfigs,
|
||||||
|
TSamlConfigsUpdate,
|
||||||
|
TUsers
|
||||||
|
} from "@app/db/schemas";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
|
import {
|
||||||
|
decryptSymmetric,
|
||||||
|
encryptSymmetric,
|
||||||
|
generateAsymmetricKeyPair,
|
||||||
|
generateSymmetricKey,
|
||||||
|
infisicalSymmetricDecrypt,
|
||||||
|
infisicalSymmetricEncypt
|
||||||
|
} from "@app/lib/crypto/encryption";
|
||||||
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
import { AuthTokenType } from "@app/services/auth/auth-type";
|
import { AuthTokenType } from "@app/services/auth/auth-type";
|
||||||
import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-service";
|
import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-service";
|
||||||
import { TokenType } from "@app/services/auth-token/auth-token-types";
|
import { TokenType } from "@app/services/auth-token/auth-token-types";
|
||||||
import { TIdentityMetadataDALFactory } from "@app/services/identity/identity-metadata-dal";
|
import { TIdentityMetadataDALFactory } from "@app/services/identity/identity-metadata-dal";
|
||||||
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
|
import { TOrgBotDALFactory } from "@app/services/org/org-bot-dal";
|
||||||
import { KmsDataKey } from "@app/services/kms/kms-types";
|
|
||||||
import { TOrgDALFactory } from "@app/services/org/org-dal";
|
import { TOrgDALFactory } from "@app/services/org/org-dal";
|
||||||
import { getDefaultOrgMembershipRole } from "@app/services/org/org-role-fns";
|
import { getDefaultOrgMembershipRole } from "@app/services/org/org-role-fns";
|
||||||
import { TOrgMembershipDALFactory } from "@app/services/org-membership/org-membership-dal";
|
import { TOrgMembershipDALFactory } from "@app/services/org-membership/org-membership-dal";
|
||||||
@@ -38,19 +52,21 @@ type TSamlConfigServiceFactoryDep = {
|
|||||||
TOrgDALFactory,
|
TOrgDALFactory,
|
||||||
"createMembership" | "updateMembershipById" | "findMembership" | "findOrgById" | "findOne" | "updateById"
|
"createMembership" | "updateMembershipById" | "findMembership" | "findOrgById" | "findOne" | "updateById"
|
||||||
>;
|
>;
|
||||||
|
|
||||||
identityMetadataDAL: Pick<TIdentityMetadataDALFactory, "delete" | "insertMany" | "transaction">;
|
identityMetadataDAL: Pick<TIdentityMetadataDALFactory, "delete" | "insertMany" | "transaction">;
|
||||||
orgMembershipDAL: Pick<TOrgMembershipDALFactory, "create">;
|
orgMembershipDAL: Pick<TOrgMembershipDALFactory, "create">;
|
||||||
|
orgBotDAL: Pick<TOrgBotDALFactory, "findOne" | "create" | "transaction">;
|
||||||
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
|
||||||
licenseService: Pick<TLicenseServiceFactory, "getPlan" | "updateSubscriptionOrgMemberCount">;
|
licenseService: Pick<TLicenseServiceFactory, "getPlan" | "updateSubscriptionOrgMemberCount">;
|
||||||
tokenService: Pick<TAuthTokenServiceFactory, "createTokenForUser">;
|
tokenService: Pick<TAuthTokenServiceFactory, "createTokenForUser">;
|
||||||
smtpService: Pick<TSmtpService, "sendMail">;
|
smtpService: Pick<TSmtpService, "sendMail">;
|
||||||
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TSamlConfigServiceFactory = ReturnType<typeof samlConfigServiceFactory>;
|
export type TSamlConfigServiceFactory = ReturnType<typeof samlConfigServiceFactory>;
|
||||||
|
|
||||||
export const samlConfigServiceFactory = ({
|
export const samlConfigServiceFactory = ({
|
||||||
samlConfigDAL,
|
samlConfigDAL,
|
||||||
|
orgBotDAL,
|
||||||
orgDAL,
|
orgDAL,
|
||||||
orgMembershipDAL,
|
orgMembershipDAL,
|
||||||
userDAL,
|
userDAL,
|
||||||
@@ -59,8 +75,7 @@ export const samlConfigServiceFactory = ({
|
|||||||
licenseService,
|
licenseService,
|
||||||
tokenService,
|
tokenService,
|
||||||
smtpService,
|
smtpService,
|
||||||
identityMetadataDAL,
|
identityMetadataDAL
|
||||||
kmsService
|
|
||||||
}: TSamlConfigServiceFactoryDep) => {
|
}: TSamlConfigServiceFactoryDep) => {
|
||||||
const createSamlCfg = async ({
|
const createSamlCfg = async ({
|
||||||
cert,
|
cert,
|
||||||
@@ -84,18 +99,70 @@ export const samlConfigServiceFactory = ({
|
|||||||
"Failed to create SAML SSO configuration due to plan restriction. Upgrade plan to create SSO configuration."
|
"Failed to create SAML SSO configuration due to plan restriction. Upgrade plan to create SSO configuration."
|
||||||
});
|
});
|
||||||
|
|
||||||
const { encryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.transaction(async (tx) => {
|
||||||
type: KmsDataKey.Organization,
|
const doc = await orgBotDAL.findOne({ orgId }, tx);
|
||||||
orgId
|
if (doc) return doc;
|
||||||
|
|
||||||
|
const { privateKey, publicKey } = generateAsymmetricKeyPair();
|
||||||
|
const key = generateSymmetricKey();
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedPrivateKey,
|
||||||
|
iv: privateKeyIV,
|
||||||
|
tag: privateKeyTag,
|
||||||
|
encoding: privateKeyKeyEncoding,
|
||||||
|
algorithm: privateKeyAlgorithm
|
||||||
|
} = infisicalSymmetricEncypt(privateKey);
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedSymmetricKey,
|
||||||
|
iv: symmetricKeyIV,
|
||||||
|
tag: symmetricKeyTag,
|
||||||
|
encoding: symmetricKeyKeyEncoding,
|
||||||
|
algorithm: symmetricKeyAlgorithm
|
||||||
|
} = infisicalSymmetricEncypt(key);
|
||||||
|
|
||||||
|
return orgBotDAL.create(
|
||||||
|
{
|
||||||
|
name: "Infisical org bot",
|
||||||
|
publicKey,
|
||||||
|
privateKeyIV,
|
||||||
|
encryptedPrivateKey,
|
||||||
|
symmetricKeyIV,
|
||||||
|
symmetricKeyTag,
|
||||||
|
encryptedSymmetricKey,
|
||||||
|
symmetricKeyAlgorithm,
|
||||||
|
orgId,
|
||||||
|
privateKeyTag,
|
||||||
|
privateKeyAlgorithm,
|
||||||
|
privateKeyKeyEncoding,
|
||||||
|
symmetricKeyKeyEncoding
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
|
});
|
||||||
|
|
||||||
|
const { ciphertext: encryptedEntryPoint, iv: entryPointIV, tag: entryPointTag } = encryptSymmetric(entryPoint, key);
|
||||||
|
const { ciphertext: encryptedIssuer, iv: issuerIV, tag: issuerTag } = encryptSymmetric(issuer, key);
|
||||||
|
const { ciphertext: encryptedCert, iv: certIV, tag: certTag } = encryptSymmetric(cert, key);
|
||||||
const samlConfig = await samlConfigDAL.create({
|
const samlConfig = await samlConfigDAL.create({
|
||||||
orgId,
|
orgId,
|
||||||
authProvider,
|
authProvider,
|
||||||
isActive,
|
isActive,
|
||||||
encryptedSamlIssuer: encryptor({ plainText: Buffer.from(issuer) }).cipherTextBlob,
|
encryptedEntryPoint,
|
||||||
encryptedSamlEntryPoint: encryptor({ plainText: Buffer.from(entryPoint) }).cipherTextBlob,
|
entryPointIV,
|
||||||
encryptedSamlCertificate: encryptor({ plainText: Buffer.from(cert) }).cipherTextBlob
|
entryPointTag,
|
||||||
|
encryptedIssuer,
|
||||||
|
issuerIV,
|
||||||
|
issuerTag,
|
||||||
|
encryptedCert,
|
||||||
|
certIV,
|
||||||
|
certTag
|
||||||
});
|
});
|
||||||
|
|
||||||
return samlConfig;
|
return samlConfig;
|
||||||
@@ -123,21 +190,40 @@ export const samlConfigServiceFactory = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const updateQuery: TSamlConfigsUpdate = { authProvider, isActive, lastUsed: null };
|
const updateQuery: TSamlConfigsUpdate = { authProvider, isActive, lastUsed: null };
|
||||||
const { encryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.findOne({ orgId });
|
||||||
type: KmsDataKey.Organization,
|
if (!orgBot)
|
||||||
orgId
|
throw new NotFoundError({
|
||||||
|
message: `Organization bot not found for organization with ID '${orgId}'`,
|
||||||
|
name: "OrgBotNotFound"
|
||||||
|
});
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
});
|
});
|
||||||
|
|
||||||
if (entryPoint !== undefined) {
|
if (entryPoint !== undefined) {
|
||||||
updateQuery.encryptedSamlEntryPoint = encryptor({ plainText: Buffer.from(entryPoint) }).cipherTextBlob;
|
const {
|
||||||
|
ciphertext: encryptedEntryPoint,
|
||||||
|
iv: entryPointIV,
|
||||||
|
tag: entryPointTag
|
||||||
|
} = encryptSymmetric(entryPoint, key);
|
||||||
|
updateQuery.encryptedEntryPoint = encryptedEntryPoint;
|
||||||
|
updateQuery.entryPointIV = entryPointIV;
|
||||||
|
updateQuery.entryPointTag = entryPointTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (issuer !== undefined) {
|
if (issuer !== undefined) {
|
||||||
updateQuery.encryptedSamlIssuer = encryptor({ plainText: Buffer.from(issuer) }).cipherTextBlob;
|
const { ciphertext: encryptedIssuer, iv: issuerIV, tag: issuerTag } = encryptSymmetric(issuer, key);
|
||||||
|
updateQuery.encryptedIssuer = encryptedIssuer;
|
||||||
|
updateQuery.issuerIV = issuerIV;
|
||||||
|
updateQuery.issuerTag = issuerTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cert !== undefined) {
|
if (cert !== undefined) {
|
||||||
updateQuery.encryptedSamlCertificate = encryptor({ plainText: Buffer.from(cert) }).cipherTextBlob;
|
const { ciphertext: encryptedCert, iv: certIV, tag: certTag } = encryptSymmetric(cert, key);
|
||||||
|
updateQuery.encryptedCert = encryptedCert;
|
||||||
|
updateQuery.certIV = certIV;
|
||||||
|
updateQuery.certTag = certTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [ssoConfig] = await samlConfigDAL.update({ orgId }, updateQuery);
|
const [ssoConfig] = await samlConfigDAL.update({ orgId }, updateQuery);
|
||||||
@@ -147,14 +233,14 @@ export const samlConfigServiceFactory = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getSaml = async (dto: TGetSamlCfgDTO) => {
|
const getSaml = async (dto: TGetSamlCfgDTO) => {
|
||||||
let samlConfig: TSamlConfigs | undefined;
|
let ssoConfig: TSamlConfigs | undefined;
|
||||||
if (dto.type === "org") {
|
if (dto.type === "org") {
|
||||||
samlConfig = await samlConfigDAL.findOne({ orgId: dto.orgId });
|
ssoConfig = await samlConfigDAL.findOne({ orgId: dto.orgId });
|
||||||
if (!samlConfig) return;
|
if (!ssoConfig) return;
|
||||||
} else if (dto.type === "orgSlug") {
|
} else if (dto.type === "orgSlug") {
|
||||||
const org = await orgDAL.findOne({ slug: dto.orgSlug });
|
const org = await orgDAL.findOne({ slug: dto.orgSlug });
|
||||||
if (!org) return;
|
if (!org) return;
|
||||||
samlConfig = await samlConfigDAL.findOne({ orgId: org.id });
|
ssoConfig = await samlConfigDAL.findOne({ orgId: org.id });
|
||||||
} else if (dto.type === "ssoId") {
|
} else if (dto.type === "ssoId") {
|
||||||
// TODO:
|
// TODO:
|
||||||
// We made this change because saml config ids were not moved over during the migration
|
// We made this change because saml config ids were not moved over during the migration
|
||||||
@@ -173,51 +259,81 @@ export const samlConfigServiceFactory = ({
|
|||||||
|
|
||||||
const id = UUIDToMongoId[dto.id] ?? dto.id;
|
const id = UUIDToMongoId[dto.id] ?? dto.id;
|
||||||
|
|
||||||
samlConfig = await samlConfigDAL.findById(id);
|
ssoConfig = await samlConfigDAL.findById(id);
|
||||||
}
|
}
|
||||||
if (!samlConfig) throw new NotFoundError({ message: `Failed to find SSO data` });
|
if (!ssoConfig) throw new NotFoundError({ message: `Failed to find SSO data` });
|
||||||
|
|
||||||
// when dto is type id means it's internally used
|
// when dto is type id means it's internally used
|
||||||
if (dto.type === "org") {
|
if (dto.type === "org") {
|
||||||
const { permission } = await permissionService.getOrgPermission(
|
const { permission } = await permissionService.getOrgPermission(
|
||||||
dto.actor,
|
dto.actor,
|
||||||
dto.actorId,
|
dto.actorId,
|
||||||
samlConfig.orgId,
|
ssoConfig.orgId,
|
||||||
dto.actorAuthMethod,
|
dto.actorAuthMethod,
|
||||||
dto.actorOrgId
|
dto.actorOrgId
|
||||||
);
|
);
|
||||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Sso);
|
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Sso);
|
||||||
}
|
}
|
||||||
const { decryptor } = await kmsService.createCipherPairWithDataKey({
|
const {
|
||||||
type: KmsDataKey.Organization,
|
entryPointTag,
|
||||||
orgId: samlConfig.orgId
|
entryPointIV,
|
||||||
|
encryptedEntryPoint,
|
||||||
|
certTag,
|
||||||
|
certIV,
|
||||||
|
encryptedCert,
|
||||||
|
issuerTag,
|
||||||
|
issuerIV,
|
||||||
|
encryptedIssuer
|
||||||
|
} = ssoConfig;
|
||||||
|
|
||||||
|
const orgBot = await orgBotDAL.findOne({ orgId: ssoConfig.orgId });
|
||||||
|
if (!orgBot)
|
||||||
|
throw new NotFoundError({
|
||||||
|
message: `Organization bot not found in organization with ID '${ssoConfig.orgId}'`,
|
||||||
|
name: "OrgBotNotFound"
|
||||||
|
});
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
});
|
});
|
||||||
|
|
||||||
let entryPoint = "";
|
let entryPoint = "";
|
||||||
if (samlConfig.encryptedSamlEntryPoint) {
|
if (encryptedEntryPoint && entryPointIV && entryPointTag) {
|
||||||
entryPoint = decryptor({ cipherTextBlob: samlConfig.encryptedSamlEntryPoint }).toString();
|
entryPoint = decryptSymmetric({
|
||||||
|
ciphertext: encryptedEntryPoint,
|
||||||
|
key,
|
||||||
|
tag: entryPointTag,
|
||||||
|
iv: entryPointIV
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let issuer = "";
|
let issuer = "";
|
||||||
if (samlConfig.encryptedSamlIssuer) {
|
if (encryptedIssuer && issuerTag && issuerIV) {
|
||||||
issuer = decryptor({ cipherTextBlob: samlConfig.encryptedSamlIssuer }).toString();
|
issuer = decryptSymmetric({
|
||||||
|
key,
|
||||||
|
tag: issuerTag,
|
||||||
|
iv: issuerIV,
|
||||||
|
ciphertext: encryptedIssuer
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let cert = "";
|
let cert = "";
|
||||||
if (samlConfig.encryptedSamlCertificate) {
|
if (encryptedCert && certTag && certIV) {
|
||||||
cert = decryptor({ cipherTextBlob: samlConfig.encryptedSamlCertificate }).toString();
|
cert = decryptSymmetric({ key, tag: certTag, iv: certIV, ciphertext: encryptedCert });
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: samlConfig.id,
|
id: ssoConfig.id,
|
||||||
organization: samlConfig.orgId,
|
organization: ssoConfig.orgId,
|
||||||
orgId: samlConfig.orgId,
|
orgId: ssoConfig.orgId,
|
||||||
authProvider: samlConfig.authProvider,
|
authProvider: ssoConfig.authProvider,
|
||||||
isActive: samlConfig.isActive,
|
isActive: ssoConfig.isActive,
|
||||||
entryPoint,
|
entryPoint,
|
||||||
issuer,
|
issuer,
|
||||||
cert,
|
cert,
|
||||||
lastUsed: samlConfig.lastUsed
|
lastUsed: ssoConfig.lastUsed
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+34
-15
@@ -5,9 +5,13 @@ import {
|
|||||||
IAMClient
|
IAMClient
|
||||||
} from "@aws-sdk/client-iam";
|
} from "@aws-sdk/client-iam";
|
||||||
|
|
||||||
import { SecretType } from "@app/db/schemas";
|
import { SecretKeyEncoding, SecretType } from "@app/db/schemas";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { encryptSymmetric128BitHexKeyUTF8 } from "@app/lib/crypto/encryption";
|
import {
|
||||||
|
encryptSymmetric128BitHexKeyUTF8,
|
||||||
|
infisicalSymmetricDecrypt,
|
||||||
|
infisicalSymmetricEncypt
|
||||||
|
} from "@app/lib/crypto/encryption";
|
||||||
import { daysToMillisecond, secondsToMillis } from "@app/lib/dates";
|
import { daysToMillisecond, secondsToMillis } from "@app/lib/dates";
|
||||||
import { NotFoundError } from "@app/lib/errors";
|
import { NotFoundError } from "@app/lib/errors";
|
||||||
import { logger } from "@app/lib/logger";
|
import { logger } from "@app/lib/logger";
|
||||||
@@ -131,15 +135,20 @@ export const secretRotationQueueFactory = ({
|
|||||||
|
|
||||||
// deep copy
|
// deep copy
|
||||||
const provider = JSON.parse(JSON.stringify(rotationProvider)) as TSecretRotationProviderTemplate;
|
const provider = JSON.parse(JSON.stringify(rotationProvider)) as TSecretRotationProviderTemplate;
|
||||||
const { encryptor: secretManagerEncryptor, decryptor: secretManagerDecryptor } =
|
|
||||||
await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId: secretRotation.projectId
|
|
||||||
});
|
|
||||||
|
|
||||||
const decryptedData = secretManagerDecryptor({
|
// now get the encrypted variable values
|
||||||
cipherTextBlob: secretRotation.encryptedRotationData
|
// in includes the inputs, the previous outputs
|
||||||
}).toString();
|
// internal mapping variables etc
|
||||||
|
const { encryptedDataTag, encryptedDataIV, encryptedData, keyEncoding } = secretRotation;
|
||||||
|
if (!encryptedDataTag || !encryptedDataIV || !encryptedData || !keyEncoding) {
|
||||||
|
throw new DisableRotationErrors({ message: "No inputs found" });
|
||||||
|
}
|
||||||
|
const decryptedData = infisicalSymmetricDecrypt({
|
||||||
|
keyEncoding: keyEncoding as SecretKeyEncoding,
|
||||||
|
ciphertext: encryptedData,
|
||||||
|
iv: encryptedDataIV,
|
||||||
|
tag: encryptedDataTag
|
||||||
|
});
|
||||||
|
|
||||||
const variables = JSON.parse(decryptedData) as TSecretRotationEncData;
|
const variables = JSON.parse(decryptedData) as TSecretRotationEncData;
|
||||||
// rotation set cycle
|
// rotation set cycle
|
||||||
@@ -294,9 +303,11 @@ export const secretRotationQueueFactory = ({
|
|||||||
outputs: newCredential.outputs,
|
outputs: newCredential.outputs,
|
||||||
internal: newCredential.internal
|
internal: newCredential.internal
|
||||||
});
|
});
|
||||||
const encryptedRotationData = secretManagerEncryptor({
|
const encVarData = infisicalSymmetricEncypt(JSON.stringify(variables));
|
||||||
plainText: Buffer.from(JSON.stringify(variables))
|
const { encryptor: secretManagerEncryptor } = await kmsService.createCipherPairWithDataKey({
|
||||||
}).cipherTextBlob;
|
type: KmsDataKey.SecretManager,
|
||||||
|
projectId: secretRotation.projectId
|
||||||
|
});
|
||||||
|
|
||||||
const numberOfSecretsRotated = rotationOutputs.length;
|
const numberOfSecretsRotated = rotationOutputs.length;
|
||||||
if (shouldUseSecretV2Bridge) {
|
if (shouldUseSecretV2Bridge) {
|
||||||
@@ -312,7 +323,11 @@ export const secretRotationQueueFactory = ({
|
|||||||
await secretRotationDAL.updateById(
|
await secretRotationDAL.updateById(
|
||||||
rotationId,
|
rotationId,
|
||||||
{
|
{
|
||||||
encryptedRotationData,
|
encryptedData: encVarData.ciphertext,
|
||||||
|
encryptedDataIV: encVarData.iv,
|
||||||
|
encryptedDataTag: encVarData.tag,
|
||||||
|
keyEncoding: encVarData.encoding,
|
||||||
|
algorithm: encVarData.algorithm,
|
||||||
lastRotatedAt: new Date(),
|
lastRotatedAt: new Date(),
|
||||||
statusMessage: "Rotated successfull",
|
statusMessage: "Rotated successfull",
|
||||||
status: "success"
|
status: "success"
|
||||||
@@ -356,7 +371,11 @@ export const secretRotationQueueFactory = ({
|
|||||||
await secretRotationDAL.updateById(
|
await secretRotationDAL.updateById(
|
||||||
rotationId,
|
rotationId,
|
||||||
{
|
{
|
||||||
encryptedRotationData,
|
encryptedData: encVarData.ciphertext,
|
||||||
|
encryptedDataIV: encVarData.iv,
|
||||||
|
encryptedDataTag: encVarData.tag,
|
||||||
|
keyEncoding: encVarData.encoding,
|
||||||
|
algorithm: encVarData.algorithm,
|
||||||
lastRotatedAt: new Date(),
|
lastRotatedAt: new Date(),
|
||||||
statusMessage: "Rotated successfull",
|
statusMessage: "Rotated successfull",
|
||||||
status: "success"
|
status: "success"
|
||||||
|
|||||||
@@ -2,11 +2,9 @@ import { ForbiddenError, subject } from "@casl/ability";
|
|||||||
import Ajv from "ajv";
|
import Ajv from "ajv";
|
||||||
|
|
||||||
import { ActionProjectType, ProjectVersion, TableName } from "@app/db/schemas";
|
import { ActionProjectType, ProjectVersion, TableName } from "@app/db/schemas";
|
||||||
import { decryptSymmetric128BitHexKeyUTF8 } from "@app/lib/crypto/encryption";
|
import { decryptSymmetric128BitHexKeyUTF8, infisicalSymmetricEncypt } from "@app/lib/crypto/encryption";
|
||||||
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
import { TProjectPermission } from "@app/lib/types";
|
import { TProjectPermission } from "@app/lib/types";
|
||||||
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
|
|
||||||
import { KmsDataKey } from "@app/services/kms/kms-types";
|
|
||||||
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
||||||
import { TProjectBotServiceFactory } from "@app/services/project-bot/project-bot-service";
|
import { TProjectBotServiceFactory } from "@app/services/project-bot/project-bot-service";
|
||||||
import { TSecretDALFactory } from "@app/services/secret/secret-dal";
|
import { TSecretDALFactory } from "@app/services/secret/secret-dal";
|
||||||
@@ -32,7 +30,6 @@ type TSecretRotationServiceFactoryDep = {
|
|||||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||||
secretRotationQueue: TSecretRotationQueueFactory;
|
secretRotationQueue: TSecretRotationQueueFactory;
|
||||||
projectBotService: Pick<TProjectBotServiceFactory, "getBotKey">;
|
projectBotService: Pick<TProjectBotServiceFactory, "getBotKey">;
|
||||||
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TSecretRotationServiceFactory = ReturnType<typeof secretRotationServiceFactory>;
|
export type TSecretRotationServiceFactory = ReturnType<typeof secretRotationServiceFactory>;
|
||||||
@@ -47,8 +44,7 @@ export const secretRotationServiceFactory = ({
|
|||||||
folderDAL,
|
folderDAL,
|
||||||
secretDAL,
|
secretDAL,
|
||||||
projectBotService,
|
projectBotService,
|
||||||
secretV2BridgeDAL,
|
secretV2BridgeDAL
|
||||||
kmsService
|
|
||||||
}: TSecretRotationServiceFactoryDep) => {
|
}: TSecretRotationServiceFactoryDep) => {
|
||||||
const getProviderTemplates = async ({
|
const getProviderTemplates = async ({
|
||||||
actor,
|
actor,
|
||||||
@@ -160,11 +156,7 @@ export const secretRotationServiceFactory = ({
|
|||||||
inputs: formattedInputs,
|
inputs: formattedInputs,
|
||||||
creds: []
|
creds: []
|
||||||
};
|
};
|
||||||
const { encryptor: secretManagerEncryptor } = await kmsService.createCipherPairWithDataKey({
|
const encData = infisicalSymmetricEncypt(JSON.stringify(unencryptedData));
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId
|
|
||||||
});
|
|
||||||
|
|
||||||
const secretRotation = await secretRotationDAL.transaction(async (tx) => {
|
const secretRotation = await secretRotationDAL.transaction(async (tx) => {
|
||||||
const doc = await secretRotationDAL.create(
|
const doc = await secretRotationDAL.create(
|
||||||
{
|
{
|
||||||
@@ -172,8 +164,11 @@ export const secretRotationServiceFactory = ({
|
|||||||
secretPath,
|
secretPath,
|
||||||
interval,
|
interval,
|
||||||
envId: folder.envId,
|
envId: folder.envId,
|
||||||
encryptedRotationData: secretManagerEncryptor({ plainText: Buffer.from(JSON.stringify(unencryptedData)) })
|
encryptedDataTag: encData.tag,
|
||||||
.cipherTextBlob
|
encryptedDataIV: encData.iv,
|
||||||
|
encryptedData: encData.ciphertext,
|
||||||
|
algorithm: encData.algorithm,
|
||||||
|
keyEncoding: encData.encoding
|
||||||
},
|
},
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
||||||
// akhilmhdh: I did this, quite strange bug with eslint. Everything do have a type stil has this error
|
|
||||||
import { ForbiddenError, subject } from "@casl/ability";
|
import { ForbiddenError, subject } from "@casl/ability";
|
||||||
|
|
||||||
import { ActionProjectType, TableName, TSecretTagJunctionInsert, TSecretV2TagJunctionInsert } from "@app/db/schemas";
|
import { ActionProjectType, TableName, TSecretTagJunctionInsert, TSecretV2TagJunctionInsert } from "@app/db/schemas";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* eslint-disable no-await-in-loop,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
/* eslint-disable no-await-in-loop */
|
||||||
import { Knex } from "knex";
|
import { Knex } from "knex";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,6 @@ import { Redis } from "ioredis";
|
|||||||
|
|
||||||
import { Redlock, Settings } from "@app/lib/red-lock";
|
import { Redlock, Settings } from "@app/lib/red-lock";
|
||||||
|
|
||||||
export enum PgSqlLock {
|
|
||||||
BootUpMigration = 2023,
|
|
||||||
SuperAdminInit = 2024,
|
|
||||||
KmsRootKeyInit = 2025
|
|
||||||
}
|
|
||||||
|
|
||||||
export type TKeyStoreFactory = ReturnType<typeof keyStoreFactory>;
|
export type TKeyStoreFactory = ReturnType<typeof keyStoreFactory>;
|
||||||
|
|
||||||
// all the key prefixes used must be set here to avoid conflict
|
// all the key prefixes used must be set here to avoid conflict
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
import { Lock } from "@app/lib/red-lock";
|
|
||||||
|
|
||||||
import { TKeyStoreFactory } from "./keystore";
|
|
||||||
|
|
||||||
export const inMemoryKeyStore = (): TKeyStoreFactory => {
|
|
||||||
const store: Record<string, string | number | Buffer> = {};
|
|
||||||
|
|
||||||
return {
|
|
||||||
setItem: async (key, value) => {
|
|
||||||
store[key] = value;
|
|
||||||
return "OK";
|
|
||||||
},
|
|
||||||
setItemWithExpiry: async (key, value) => {
|
|
||||||
store[key] = value;
|
|
||||||
return "OK";
|
|
||||||
},
|
|
||||||
deleteItem: async (key) => {
|
|
||||||
delete store[key];
|
|
||||||
return 1;
|
|
||||||
},
|
|
||||||
getItem: async (key) => {
|
|
||||||
const value = store[key];
|
|
||||||
if (typeof value === "string") {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
incrementBy: async () => {
|
|
||||||
return 1;
|
|
||||||
},
|
|
||||||
acquireLock: () => {
|
|
||||||
return Promise.resolve({
|
|
||||||
release: () => {}
|
|
||||||
}) as Promise<Lock>;
|
|
||||||
},
|
|
||||||
waitTillReady: async () => {}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -258,8 +258,7 @@ const envSchema = z
|
|||||||
SECRET_SCANNING_ORG_WHITELIST: data.SECRET_SCANNING_ORG_WHITELIST?.split(",")
|
SECRET_SCANNING_ORG_WHITELIST: data.SECRET_SCANNING_ORG_WHITELIST?.split(",")
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export type TEnvConfig = Readonly<z.infer<typeof envSchema>>;
|
let envCfg: Readonly<z.infer<typeof envSchema>>;
|
||||||
let envCfg: TEnvConfig;
|
|
||||||
|
|
||||||
export const getConfig = () => envCfg;
|
export const getConfig = () => envCfg;
|
||||||
// cannot import singleton logger directly as it needs config to load various transport
|
// cannot import singleton logger directly as it needs config to load various transport
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ const extractReqId = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initLogger = () => {
|
export const initLogger = async () => {
|
||||||
const cfg = loggerConfig.parse(process.env);
|
const cfg = loggerConfig.parse(process.env);
|
||||||
const targets: pino.TransportMultiOptions["targets"][number][] = [
|
const targets: pino.TransportMultiOptions["targets"][number][] = [
|
||||||
{
|
{
|
||||||
|
|||||||
+36
-30
@@ -2,13 +2,14 @@ import "./lib/telemetry/instrumentation";
|
|||||||
|
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { Redis } from "ioredis";
|
import { Redis } from "ioredis";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
import { initializeHsmModule } from "@app/ee/services/hsm/hsm-fns";
|
import { initializeHsmModule } from "@app/ee/services/hsm/hsm-fns";
|
||||||
|
|
||||||
import { runMigrations } from "./auto-start-migrations";
|
|
||||||
import { initAuditLogDbConnection, initDbConnection } from "./db";
|
import { initAuditLogDbConnection, initDbConnection } from "./db";
|
||||||
import { keyStoreFactory } from "./keystore/keystore";
|
import { keyStoreFactory } from "./keystore/keystore";
|
||||||
import { formatSmtpConfig, initEnvConfig } from "./lib/config/env";
|
import { formatSmtpConfig, initEnvConfig, IS_PACKAGED } from "./lib/config/env";
|
||||||
|
import { isMigrationMode } from "./lib/fn";
|
||||||
import { initLogger } from "./lib/logger";
|
import { initLogger } from "./lib/logger";
|
||||||
import { queueServiceFactory } from "./queue";
|
import { queueServiceFactory } from "./queue";
|
||||||
import { main } from "./server/app";
|
import { main } from "./server/app";
|
||||||
@@ -18,53 +19,58 @@ import { smtpServiceFactory } from "./services/smtp/smtp-service";
|
|||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
const logger = initLogger();
|
const logger = await initLogger();
|
||||||
const envConfig = initEnvConfig(logger);
|
const appCfg = initEnvConfig(logger);
|
||||||
|
|
||||||
const db = initDbConnection({
|
const db = initDbConnection({
|
||||||
dbConnectionUri: envConfig.DB_CONNECTION_URI,
|
dbConnectionUri: appCfg.DB_CONNECTION_URI,
|
||||||
dbRootCert: envConfig.DB_ROOT_CERT,
|
dbRootCert: appCfg.DB_ROOT_CERT,
|
||||||
readReplicas: envConfig.DB_READ_REPLICAS?.map((el) => ({
|
readReplicas: appCfg.DB_READ_REPLICAS?.map((el) => ({
|
||||||
dbRootCert: el.DB_ROOT_CERT,
|
dbRootCert: el.DB_ROOT_CERT,
|
||||||
dbConnectionUri: el.DB_CONNECTION_URI
|
dbConnectionUri: el.DB_CONNECTION_URI
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
|
||||||
const auditLogDb = envConfig.AUDIT_LOGS_DB_CONNECTION_URI
|
const auditLogDb = appCfg.AUDIT_LOGS_DB_CONNECTION_URI
|
||||||
? initAuditLogDbConnection({
|
? initAuditLogDbConnection({
|
||||||
dbConnectionUri: envConfig.AUDIT_LOGS_DB_CONNECTION_URI,
|
dbConnectionUri: appCfg.AUDIT_LOGS_DB_CONNECTION_URI,
|
||||||
dbRootCert: envConfig.AUDIT_LOGS_DB_ROOT_CERT
|
dbRootCert: appCfg.AUDIT_LOGS_DB_ROOT_CERT
|
||||||
})
|
})
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
await runMigrations({ applicationDb: db, auditLogDb, logger });
|
// Case: App is running in packaged mode (binary), and migration mode is enabled.
|
||||||
|
// Run the migrations and exit the process after completion.
|
||||||
|
if (IS_PACKAGED && isMigrationMode()) {
|
||||||
|
try {
|
||||||
|
logger.info("Running Postgres migrations..");
|
||||||
|
await db.migrate.latest({
|
||||||
|
directory: path.join(__dirname, "./db/migrations")
|
||||||
|
});
|
||||||
|
logger.info("Postgres migrations completed");
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(err, "Failed to run migrations");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
const smtp = smtpServiceFactory(formatSmtpConfig());
|
const smtp = smtpServiceFactory(formatSmtpConfig());
|
||||||
|
|
||||||
const queue = queueServiceFactory(envConfig.REDIS_URL, {
|
const queue = queueServiceFactory(appCfg.REDIS_URL, {
|
||||||
dbConnectionUrl: envConfig.DB_CONNECTION_URI,
|
dbConnectionUrl: appCfg.DB_CONNECTION_URI,
|
||||||
dbRootCert: envConfig.DB_ROOT_CERT
|
dbRootCert: appCfg.DB_ROOT_CERT
|
||||||
});
|
});
|
||||||
|
|
||||||
await queue.initialize();
|
await queue.initialize();
|
||||||
|
|
||||||
const keyStore = keyStoreFactory(envConfig.REDIS_URL);
|
const keyStore = keyStoreFactory(appCfg.REDIS_URL);
|
||||||
const redis = new Redis(envConfig.REDIS_URL);
|
const redis = new Redis(appCfg.REDIS_URL);
|
||||||
|
|
||||||
const hsmModule = initializeHsmModule(envConfig);
|
const hsmModule = initializeHsmModule();
|
||||||
hsmModule.initialize();
|
hsmModule.initialize();
|
||||||
|
|
||||||
const server = await main({
|
const server = await main({ db, auditLogDb, hsmModule: hsmModule.getModule(), smtp, logger, queue, keyStore, redis });
|
||||||
db,
|
|
||||||
auditLogDb,
|
|
||||||
hsmModule: hsmModule.getModule(),
|
|
||||||
smtp,
|
|
||||||
logger,
|
|
||||||
queue,
|
|
||||||
keyStore,
|
|
||||||
redis,
|
|
||||||
envConfig
|
|
||||||
});
|
|
||||||
const bootstrap = await bootstrapCheck({ db });
|
const bootstrap = await bootstrapCheck({ db });
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
@@ -84,8 +90,8 @@ const run = async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await server.listen({
|
await server.listen({
|
||||||
port: envConfig.PORT,
|
port: appCfg.PORT,
|
||||||
host: envConfig.HOST,
|
host: appCfg.HOST,
|
||||||
listenTextResolver: (address) => {
|
listenTextResolver: (address) => {
|
||||||
void bootstrap();
|
void bootstrap();
|
||||||
return address;
|
return address;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import { Knex } from "knex";
|
|||||||
|
|
||||||
import { HsmModule } from "@app/ee/services/hsm/hsm-types";
|
import { HsmModule } from "@app/ee/services/hsm/hsm-types";
|
||||||
import { TKeyStoreFactory } from "@app/keystore/keystore";
|
import { TKeyStoreFactory } from "@app/keystore/keystore";
|
||||||
import { getConfig, IS_PACKAGED, TEnvConfig } from "@app/lib/config/env";
|
import { getConfig, IS_PACKAGED } from "@app/lib/config/env";
|
||||||
import { CustomLogger } from "@app/lib/logger/logger";
|
import { CustomLogger } from "@app/lib/logger/logger";
|
||||||
import { alphaNumericNanoId } from "@app/lib/nanoid";
|
import { alphaNumericNanoId } from "@app/lib/nanoid";
|
||||||
import { TQueueServiceFactory } from "@app/queue";
|
import { TQueueServiceFactory } from "@app/queue";
|
||||||
@@ -43,11 +43,10 @@ type TMain = {
|
|||||||
keyStore: TKeyStoreFactory;
|
keyStore: TKeyStoreFactory;
|
||||||
hsmModule: HsmModule;
|
hsmModule: HsmModule;
|
||||||
redis: Redis;
|
redis: Redis;
|
||||||
envConfig: TEnvConfig;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Run the server!
|
// Run the server!
|
||||||
export const main = async ({ db, hsmModule, auditLogDb, smtp, logger, queue, keyStore, redis, envConfig }: TMain) => {
|
export const main = async ({ db, hsmModule, auditLogDb, smtp, logger, queue, keyStore, redis }: TMain) => {
|
||||||
const appCfg = getConfig();
|
const appCfg = getConfig();
|
||||||
|
|
||||||
const server = fastify({
|
const server = fastify({
|
||||||
@@ -128,7 +127,7 @@ export const main = async ({ db, hsmModule, auditLogDb, smtp, logger, queue, key
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
await server.register(registerRoutes, { smtp, queue, db, auditLogDb, keyStore, hsmModule, envConfig });
|
await server.register(registerRoutes, { smtp, queue, db, auditLogDb, keyStore, hsmModule });
|
||||||
|
|
||||||
await server.register(registerServeUI, {
|
await server.register(registerServeUI, {
|
||||||
standaloneMode: appCfg.STANDALONE_MODE || IS_PACKAGED,
|
standaloneMode: appCfg.STANDALONE_MODE || IS_PACKAGED,
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ import { sshCertificateTemplateServiceFactory } from "@app/ee/services/ssh-certi
|
|||||||
import { trustedIpDALFactory } from "@app/ee/services/trusted-ip/trusted-ip-dal";
|
import { trustedIpDALFactory } from "@app/ee/services/trusted-ip/trusted-ip-dal";
|
||||||
import { trustedIpServiceFactory } from "@app/ee/services/trusted-ip/trusted-ip-service";
|
import { trustedIpServiceFactory } from "@app/ee/services/trusted-ip/trusted-ip-service";
|
||||||
import { TKeyStoreFactory } from "@app/keystore/keystore";
|
import { TKeyStoreFactory } from "@app/keystore/keystore";
|
||||||
import { getConfig, TEnvConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { TQueueServiceFactory } from "@app/queue";
|
import { TQueueServiceFactory } from "@app/queue";
|
||||||
import { readLimit } from "@app/server/config/rateLimiter";
|
import { readLimit } from "@app/server/config/rateLimiter";
|
||||||
import { accessTokenQueueServiceFactory } from "@app/services/access-token-queue/access-token-queue";
|
import { accessTokenQueueServiceFactory } from "@app/services/access-token-queue/access-token-queue";
|
||||||
@@ -244,8 +244,7 @@ export const registerRoutes = async (
|
|||||||
hsmModule,
|
hsmModule,
|
||||||
smtp: smtpService,
|
smtp: smtpService,
|
||||||
queue: queueService,
|
queue: queueService,
|
||||||
keyStore,
|
keyStore
|
||||||
envConfig
|
|
||||||
}: {
|
}: {
|
||||||
auditLogDb?: Knex;
|
auditLogDb?: Knex;
|
||||||
db: Knex;
|
db: Knex;
|
||||||
@@ -253,7 +252,6 @@ export const registerRoutes = async (
|
|||||||
smtp: TSmtpService;
|
smtp: TSmtpService;
|
||||||
queue: TQueueServiceFactory;
|
queue: TQueueServiceFactory;
|
||||||
keyStore: TKeyStoreFactory;
|
keyStore: TKeyStoreFactory;
|
||||||
envConfig: TEnvConfig;
|
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
const appCfg = getConfig();
|
const appCfg = getConfig();
|
||||||
@@ -393,8 +391,7 @@ export const registerRoutes = async (
|
|||||||
const licenseService = licenseServiceFactory({ permissionService, orgDAL, licenseDAL, keyStore });
|
const licenseService = licenseServiceFactory({ permissionService, orgDAL, licenseDAL, keyStore });
|
||||||
|
|
||||||
const hsmService = hsmServiceFactory({
|
const hsmService = hsmServiceFactory({
|
||||||
hsmModule,
|
hsmModule
|
||||||
envConfig
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const kmsService = kmsServiceFactory({
|
const kmsService = kmsServiceFactory({
|
||||||
@@ -404,8 +401,7 @@ export const registerRoutes = async (
|
|||||||
internalKmsDAL,
|
internalKmsDAL,
|
||||||
orgDAL,
|
orgDAL,
|
||||||
projectDAL,
|
projectDAL,
|
||||||
hsmService,
|
hsmService
|
||||||
envConfig
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const externalKmsService = externalKmsServiceFactory({
|
const externalKmsService = externalKmsServiceFactory({
|
||||||
@@ -451,6 +447,7 @@ export const registerRoutes = async (
|
|||||||
const samlService = samlConfigServiceFactory({
|
const samlService = samlConfigServiceFactory({
|
||||||
identityMetadataDAL,
|
identityMetadataDAL,
|
||||||
permissionService,
|
permissionService,
|
||||||
|
orgBotDAL,
|
||||||
orgDAL,
|
orgDAL,
|
||||||
orgMembershipDAL,
|
orgMembershipDAL,
|
||||||
userDAL,
|
userDAL,
|
||||||
@@ -458,8 +455,7 @@ export const registerRoutes = async (
|
|||||||
samlConfigDAL,
|
samlConfigDAL,
|
||||||
licenseService,
|
licenseService,
|
||||||
tokenService,
|
tokenService,
|
||||||
smtpService,
|
smtpService
|
||||||
kmsService
|
|
||||||
});
|
});
|
||||||
const groupService = groupServiceFactory({
|
const groupService = groupServiceFactory({
|
||||||
userDAL,
|
userDAL,
|
||||||
@@ -510,6 +506,7 @@ export const registerRoutes = async (
|
|||||||
ldapGroupMapDAL,
|
ldapGroupMapDAL,
|
||||||
orgDAL,
|
orgDAL,
|
||||||
orgMembershipDAL,
|
orgMembershipDAL,
|
||||||
|
orgBotDAL,
|
||||||
groupDAL,
|
groupDAL,
|
||||||
groupProjectDAL,
|
groupProjectDAL,
|
||||||
projectKeyDAL,
|
projectKeyDAL,
|
||||||
@@ -521,8 +518,7 @@ export const registerRoutes = async (
|
|||||||
permissionService,
|
permissionService,
|
||||||
licenseService,
|
licenseService,
|
||||||
tokenService,
|
tokenService,
|
||||||
smtpService,
|
smtpService
|
||||||
kmsService
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const telemetryService = telemetryServiceFactory({
|
const telemetryService = telemetryServiceFactory({
|
||||||
@@ -973,8 +969,7 @@ export const registerRoutes = async (
|
|||||||
permissionService,
|
permissionService,
|
||||||
webhookDAL,
|
webhookDAL,
|
||||||
projectEnvDAL,
|
projectEnvDAL,
|
||||||
projectDAL,
|
projectDAL
|
||||||
kmsService
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const secretTagService = secretTagServiceFactory({ secretTagDAL, permissionService });
|
const secretTagService = secretTagServiceFactory({ secretTagDAL, permissionService });
|
||||||
@@ -1154,8 +1149,7 @@ export const registerRoutes = async (
|
|||||||
secretDAL,
|
secretDAL,
|
||||||
folderDAL,
|
folderDAL,
|
||||||
projectBotService,
|
projectBotService,
|
||||||
secretV2BridgeDAL,
|
secretV2BridgeDAL
|
||||||
kmsService
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const integrationService = integrationServiceFactory({
|
const integrationService = integrationServiceFactory({
|
||||||
@@ -1244,9 +1238,9 @@ export const registerRoutes = async (
|
|||||||
identityKubernetesAuthDAL,
|
identityKubernetesAuthDAL,
|
||||||
identityOrgMembershipDAL,
|
identityOrgMembershipDAL,
|
||||||
identityAccessTokenDAL,
|
identityAccessTokenDAL,
|
||||||
|
orgBotDAL,
|
||||||
permissionService,
|
permissionService,
|
||||||
licenseService,
|
licenseService
|
||||||
kmsService
|
|
||||||
});
|
});
|
||||||
const identityGcpAuthService = identityGcpAuthServiceFactory({
|
const identityGcpAuthService = identityGcpAuthServiceFactory({
|
||||||
identityGcpAuthDAL,
|
identityGcpAuthDAL,
|
||||||
@@ -1278,7 +1272,7 @@ export const registerRoutes = async (
|
|||||||
identityAccessTokenDAL,
|
identityAccessTokenDAL,
|
||||||
permissionService,
|
permissionService,
|
||||||
licenseService,
|
licenseService,
|
||||||
kmsService
|
orgBotDAL
|
||||||
});
|
});
|
||||||
|
|
||||||
const identityJwtAuthService = identityJwtAuthServiceFactory({
|
const identityJwtAuthService = identityJwtAuthServiceFactory({
|
||||||
@@ -1295,9 +1289,7 @@ export const registerRoutes = async (
|
|||||||
queueService,
|
queueService,
|
||||||
dynamicSecretLeaseDAL,
|
dynamicSecretLeaseDAL,
|
||||||
dynamicSecretProviders,
|
dynamicSecretProviders,
|
||||||
dynamicSecretDAL,
|
dynamicSecretDAL
|
||||||
folderDAL,
|
|
||||||
kmsService
|
|
||||||
});
|
});
|
||||||
const dynamicSecretService = dynamicSecretServiceFactory({
|
const dynamicSecretService = dynamicSecretServiceFactory({
|
||||||
projectDAL,
|
projectDAL,
|
||||||
@@ -1307,8 +1299,7 @@ export const registerRoutes = async (
|
|||||||
dynamicSecretProviders,
|
dynamicSecretProviders,
|
||||||
folderDAL,
|
folderDAL,
|
||||||
permissionService,
|
permissionService,
|
||||||
licenseService,
|
licenseService
|
||||||
kmsService
|
|
||||||
});
|
});
|
||||||
const dynamicSecretLeaseService = dynamicSecretLeaseServiceFactory({
|
const dynamicSecretLeaseService = dynamicSecretLeaseServiceFactory({
|
||||||
projectDAL,
|
projectDAL,
|
||||||
@@ -1318,8 +1309,7 @@ export const registerRoutes = async (
|
|||||||
dynamicSecretLeaseDAL,
|
dynamicSecretLeaseDAL,
|
||||||
dynamicSecretProviders,
|
dynamicSecretProviders,
|
||||||
folderDAL,
|
folderDAL,
|
||||||
licenseService,
|
licenseService
|
||||||
kmsService
|
|
||||||
});
|
});
|
||||||
const dailyResourceCleanUp = dailyResourceCleanUpQueueServiceFactory({
|
const dailyResourceCleanUp = dailyResourceCleanUpQueueServiceFactory({
|
||||||
auditLogDAL,
|
auditLogDAL,
|
||||||
@@ -1347,7 +1337,7 @@ export const registerRoutes = async (
|
|||||||
licenseService,
|
licenseService,
|
||||||
tokenService,
|
tokenService,
|
||||||
smtpService,
|
smtpService,
|
||||||
kmsService,
|
orgBotDAL,
|
||||||
permissionService,
|
permissionService,
|
||||||
oidcConfigDAL,
|
oidcConfigDAL,
|
||||||
projectBotDAL,
|
projectBotDAL,
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
import { LdapConfigsSchema, OidcConfigsSchema, SamlConfigsSchema } from "@app/db/schemas";
|
|
||||||
|
|
||||||
export const SanitizedSamlConfigSchema = SamlConfigsSchema.pick({
|
|
||||||
id: true,
|
|
||||||
orgId: true,
|
|
||||||
isActive: true,
|
|
||||||
lastUsed: true,
|
|
||||||
createdAt: true,
|
|
||||||
updatedAt: true,
|
|
||||||
authProvider: true
|
|
||||||
});
|
|
||||||
|
|
||||||
export const SanitizedLdapConfigSchema = LdapConfigsSchema.pick({
|
|
||||||
updatedAt: true,
|
|
||||||
createdAt: true,
|
|
||||||
isActive: true,
|
|
||||||
orgId: true,
|
|
||||||
id: true,
|
|
||||||
url: true,
|
|
||||||
searchBase: true,
|
|
||||||
searchFilter: true,
|
|
||||||
groupSearchBase: true,
|
|
||||||
uniqueUserAttribute: true,
|
|
||||||
groupSearchFilter: true
|
|
||||||
});
|
|
||||||
|
|
||||||
export const SanitizedOidcConfigSchema = OidcConfigsSchema.pick({
|
|
||||||
id: true,
|
|
||||||
orgId: true,
|
|
||||||
isActive: true,
|
|
||||||
createdAt: true,
|
|
||||||
updatedAt: true,
|
|
||||||
lastUsed: true,
|
|
||||||
issuer: true,
|
|
||||||
jwksUri: true,
|
|
||||||
discoveryURL: true,
|
|
||||||
tokenEndpoint: true,
|
|
||||||
userinfoEndpoint: true,
|
|
||||||
configurationType: true,
|
|
||||||
allowedEmailDomains: true,
|
|
||||||
authorizationEndpoint: true
|
|
||||||
});
|
|
||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
} from "@app/db/schemas";
|
} from "@app/db/schemas";
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||||
|
|
||||||
import { UnpackedPermissionSchema } from "./sanitizedSchema/permission";
|
import { UnpackedPermissionSchema } from "./santizedSchemas/permission";
|
||||||
|
|
||||||
// sometimes the return data must be santizied to avoid leaking important values
|
// sometimes the return data must be santizied to avoid leaking important values
|
||||||
// always prefer pick over omit in zod
|
// always prefer pick over omit in zod
|
||||||
@@ -201,11 +201,10 @@ export const SanitizedRoleSchemaV1 = ProjectRolesSchema.extend({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const SanitizedDynamicSecretSchema = DynamicSecretsSchema.omit({
|
export const SanitizedDynamicSecretSchema = DynamicSecretsSchema.omit({
|
||||||
encryptedInput: true,
|
|
||||||
keyEncoding: true,
|
|
||||||
inputCiphertext: true,
|
|
||||||
inputIV: true,
|
inputIV: true,
|
||||||
inputTag: true,
|
inputTag: true,
|
||||||
|
inputCiphertext: true,
|
||||||
|
keyEncoding: true,
|
||||||
algorithm: true
|
algorithm: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,19 +8,13 @@ import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
|||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
import { TIdentityTrustedIp } from "@app/services/identity/identity-types";
|
import { TIdentityTrustedIp } from "@app/services/identity/identity-types";
|
||||||
|
|
||||||
const IdentityKubernetesAuthResponseSchema = IdentityKubernetesAuthsSchema.pick({
|
const IdentityKubernetesAuthResponseSchema = IdentityKubernetesAuthsSchema.omit({
|
||||||
id: true,
|
encryptedCaCert: true,
|
||||||
accessTokenTTL: true,
|
caCertIV: true,
|
||||||
accessTokenMaxTTL: true,
|
caCertTag: true,
|
||||||
accessTokenNumUsesLimit: true,
|
encryptedTokenReviewerJwt: true,
|
||||||
accessTokenTrustedIps: true,
|
tokenReviewerJwtIV: true,
|
||||||
createdAt: true,
|
tokenReviewerJwtTag: true
|
||||||
updatedAt: true,
|
|
||||||
identityId: true,
|
|
||||||
kubernetesHost: true,
|
|
||||||
allowedNamespaces: true,
|
|
||||||
allowedNames: true,
|
|
||||||
allowedAudience: true
|
|
||||||
}).extend({
|
}).extend({
|
||||||
caCert: z.string(),
|
caCert: z.string(),
|
||||||
tokenReviewerJwt: z.string()
|
tokenReviewerJwt: z.string()
|
||||||
|
|||||||
@@ -12,20 +12,10 @@ import {
|
|||||||
validateOidcBoundClaimsField
|
validateOidcBoundClaimsField
|
||||||
} from "@app/services/identity-oidc-auth/identity-oidc-auth-validators";
|
} from "@app/services/identity-oidc-auth/identity-oidc-auth-validators";
|
||||||
|
|
||||||
const IdentityOidcAuthResponseSchema = IdentityOidcAuthsSchema.pick({
|
const IdentityOidcAuthResponseSchema = IdentityOidcAuthsSchema.omit({
|
||||||
id: true,
|
encryptedCaCert: true,
|
||||||
accessTokenTTL: true,
|
caCertIV: true,
|
||||||
accessTokenMaxTTL: true,
|
caCertTag: true
|
||||||
accessTokenNumUsesLimit: true,
|
|
||||||
accessTokenTrustedIps: true,
|
|
||||||
identityId: true,
|
|
||||||
oidcDiscoveryUrl: true,
|
|
||||||
boundIssuer: true,
|
|
||||||
boundAudiences: true,
|
|
||||||
boundClaims: true,
|
|
||||||
boundSubject: true,
|
|
||||||
createdAt: true,
|
|
||||||
updatedAt: true
|
|
||||||
}).extend({
|
}).extend({
|
||||||
caCert: z.string()
|
caCert: z.string()
|
||||||
});
|
});
|
||||||
|
|||||||
+174
-45
@@ -3,21 +3,28 @@ import axios, { AxiosError } from "axios";
|
|||||||
import https from "https";
|
import https from "https";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
|
|
||||||
import { IdentityAuthMethod, TIdentityKubernetesAuthsUpdate } from "@app/db/schemas";
|
import { IdentityAuthMethod, SecretKeyEncoding, TIdentityKubernetesAuthsUpdate } from "@app/db/schemas";
|
||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
||||||
import { isAtLeastAsPrivileged } from "@app/lib/casl";
|
import { isAtLeastAsPrivileged } from "@app/lib/casl";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
|
import {
|
||||||
|
decryptSymmetric,
|
||||||
|
encryptSymmetric,
|
||||||
|
generateAsymmetricKeyPair,
|
||||||
|
generateSymmetricKey,
|
||||||
|
infisicalSymmetricDecrypt,
|
||||||
|
infisicalSymmetricEncypt
|
||||||
|
} from "@app/lib/crypto/encryption";
|
||||||
import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
|
import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
|
||||||
import { extractIPDetails, isValidIpOrCidr } from "@app/lib/ip";
|
import { extractIPDetails, isValidIpOrCidr } from "@app/lib/ip";
|
||||||
|
import { TOrgBotDALFactory } from "@app/services/org/org-bot-dal";
|
||||||
|
|
||||||
import { ActorType, AuthTokenType } from "../auth/auth-type";
|
import { ActorType, AuthTokenType } from "../auth/auth-type";
|
||||||
import { TIdentityOrgDALFactory } from "../identity/identity-org-dal";
|
import { TIdentityOrgDALFactory } from "../identity/identity-org-dal";
|
||||||
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
|
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
|
||||||
import { TIdentityAccessTokenJwtPayload } from "../identity-access-token/identity-access-token-types";
|
import { TIdentityAccessTokenJwtPayload } from "../identity-access-token/identity-access-token-types";
|
||||||
import { TKmsServiceFactory } from "../kms/kms-service";
|
|
||||||
import { KmsDataKey } from "../kms/kms-types";
|
|
||||||
import { TIdentityKubernetesAuthDALFactory } from "./identity-kubernetes-auth-dal";
|
import { TIdentityKubernetesAuthDALFactory } from "./identity-kubernetes-auth-dal";
|
||||||
import { extractK8sUsername } from "./identity-kubernetes-auth-fns";
|
import { extractK8sUsername } from "./identity-kubernetes-auth-fns";
|
||||||
import {
|
import {
|
||||||
@@ -36,9 +43,9 @@ type TIdentityKubernetesAuthServiceFactoryDep = {
|
|||||||
>;
|
>;
|
||||||
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "create" | "delete">;
|
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "create" | "delete">;
|
||||||
identityOrgMembershipDAL: Pick<TIdentityOrgDALFactory, "findOne" | "findById">;
|
identityOrgMembershipDAL: Pick<TIdentityOrgDALFactory, "findOne" | "findById">;
|
||||||
|
orgBotDAL: Pick<TOrgBotDALFactory, "findOne" | "transaction" | "create">;
|
||||||
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
|
||||||
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
|
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
|
||||||
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TIdentityKubernetesAuthServiceFactory = ReturnType<typeof identityKubernetesAuthServiceFactory>;
|
export type TIdentityKubernetesAuthServiceFactory = ReturnType<typeof identityKubernetesAuthServiceFactory>;
|
||||||
@@ -47,9 +54,9 @@ export const identityKubernetesAuthServiceFactory = ({
|
|||||||
identityKubernetesAuthDAL,
|
identityKubernetesAuthDAL,
|
||||||
identityOrgMembershipDAL,
|
identityOrgMembershipDAL,
|
||||||
identityAccessTokenDAL,
|
identityAccessTokenDAL,
|
||||||
|
orgBotDAL,
|
||||||
permissionService,
|
permissionService,
|
||||||
licenseService,
|
licenseService
|
||||||
kmsService
|
|
||||||
}: TIdentityKubernetesAuthServiceFactoryDep) => {
|
}: TIdentityKubernetesAuthServiceFactoryDep) => {
|
||||||
const login = async ({ identityId, jwt: serviceAccountJwt }: TLoginKubernetesAuthDTO) => {
|
const login = async ({ identityId, jwt: serviceAccountJwt }: TLoginKubernetesAuthDTO) => {
|
||||||
const identityKubernetesAuth = await identityKubernetesAuthDAL.findOne({ identityId });
|
const identityKubernetesAuth = await identityKubernetesAuthDAL.findOne({ identityId });
|
||||||
@@ -68,21 +75,42 @@ export const identityKubernetesAuthServiceFactory = ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const { decryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.findOne({ orgId: identityMembershipOrg.orgId });
|
||||||
type: KmsDataKey.Organization,
|
if (!orgBot) {
|
||||||
orgId: identityMembershipOrg.orgId
|
throw new NotFoundError({
|
||||||
|
message: `Organization bot not found for organization with ID ${identityMembershipOrg.orgId}`,
|
||||||
|
name: "OrgBotNotFound"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { encryptedCaCert, caCertIV, caCertTag, encryptedTokenReviewerJwt, tokenReviewerJwtIV, tokenReviewerJwtTag } =
|
||||||
|
identityKubernetesAuth;
|
||||||
|
|
||||||
let caCert = "";
|
let caCert = "";
|
||||||
if (identityKubernetesAuth.encryptedKubernetesCaCertificate) {
|
if (encryptedCaCert && caCertIV && caCertTag) {
|
||||||
caCert = decryptor({ cipherTextBlob: identityKubernetesAuth.encryptedKubernetesCaCertificate }).toString();
|
caCert = decryptSymmetric({
|
||||||
|
ciphertext: encryptedCaCert,
|
||||||
|
iv: caCertIV,
|
||||||
|
tag: caCertTag,
|
||||||
|
key
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let tokenReviewerJwt = "";
|
let tokenReviewerJwt = "";
|
||||||
if (identityKubernetesAuth.encryptedKubernetesTokenReviewerJwt) {
|
if (encryptedTokenReviewerJwt && tokenReviewerJwtIV && tokenReviewerJwtTag) {
|
||||||
tokenReviewerJwt = decryptor({
|
tokenReviewerJwt = decryptSymmetric({
|
||||||
cipherTextBlob: identityKubernetesAuth.encryptedKubernetesTokenReviewerJwt
|
ciphertext: encryptedTokenReviewerJwt,
|
||||||
}).toString();
|
iv: tokenReviewerJwtIV,
|
||||||
|
tag: tokenReviewerJwtTag,
|
||||||
|
key
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data } = await axios
|
const { data } = await axios
|
||||||
@@ -269,25 +297,79 @@ export const identityKubernetesAuthServiceFactory = ({
|
|||||||
return extractIPDetails(accessTokenTrustedIp.ipAddress);
|
return extractIPDetails(accessTokenTrustedIp.ipAddress);
|
||||||
});
|
});
|
||||||
|
|
||||||
const { encryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.transaction(async (tx) => {
|
||||||
type: KmsDataKey.Organization,
|
const doc = await orgBotDAL.findOne({ orgId: identityMembershipOrg.orgId }, tx);
|
||||||
orgId: identityMembershipOrg.orgId
|
if (doc) return doc;
|
||||||
|
|
||||||
|
const { privateKey, publicKey } = generateAsymmetricKeyPair();
|
||||||
|
const key = generateSymmetricKey();
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedPrivateKey,
|
||||||
|
iv: privateKeyIV,
|
||||||
|
tag: privateKeyTag,
|
||||||
|
encoding: privateKeyKeyEncoding,
|
||||||
|
algorithm: privateKeyAlgorithm
|
||||||
|
} = infisicalSymmetricEncypt(privateKey);
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedSymmetricKey,
|
||||||
|
iv: symmetricKeyIV,
|
||||||
|
tag: symmetricKeyTag,
|
||||||
|
encoding: symmetricKeyKeyEncoding,
|
||||||
|
algorithm: symmetricKeyAlgorithm
|
||||||
|
} = infisicalSymmetricEncypt(key);
|
||||||
|
|
||||||
|
return orgBotDAL.create(
|
||||||
|
{
|
||||||
|
name: "Infisical org bot",
|
||||||
|
publicKey,
|
||||||
|
privateKeyIV,
|
||||||
|
encryptedPrivateKey,
|
||||||
|
symmetricKeyIV,
|
||||||
|
symmetricKeyTag,
|
||||||
|
encryptedSymmetricKey,
|
||||||
|
symmetricKeyAlgorithm,
|
||||||
|
orgId: identityMembershipOrg.orgId,
|
||||||
|
privateKeyTag,
|
||||||
|
privateKeyAlgorithm,
|
||||||
|
privateKeyKeyEncoding,
|
||||||
|
symmetricKeyKeyEncoding
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
|
});
|
||||||
|
|
||||||
|
const { ciphertext: encryptedCaCert, iv: caCertIV, tag: caCertTag } = encryptSymmetric(caCert, key);
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedTokenReviewerJwt,
|
||||||
|
iv: tokenReviewerJwtIV,
|
||||||
|
tag: tokenReviewerJwtTag
|
||||||
|
} = encryptSymmetric(tokenReviewerJwt, key);
|
||||||
|
|
||||||
const identityKubernetesAuth = await identityKubernetesAuthDAL.transaction(async (tx) => {
|
const identityKubernetesAuth = await identityKubernetesAuthDAL.transaction(async (tx) => {
|
||||||
const doc = await identityKubernetesAuthDAL.create(
|
const doc = await identityKubernetesAuthDAL.create(
|
||||||
{
|
{
|
||||||
identityId: identityMembershipOrg.identityId,
|
identityId: identityMembershipOrg.identityId,
|
||||||
kubernetesHost,
|
kubernetesHost,
|
||||||
|
encryptedCaCert,
|
||||||
|
caCertIV,
|
||||||
|
caCertTag,
|
||||||
|
encryptedTokenReviewerJwt,
|
||||||
|
tokenReviewerJwtIV,
|
||||||
|
tokenReviewerJwtTag,
|
||||||
allowedNamespaces,
|
allowedNamespaces,
|
||||||
allowedNames,
|
allowedNames,
|
||||||
allowedAudience,
|
allowedAudience,
|
||||||
accessTokenMaxTTL,
|
accessTokenMaxTTL,
|
||||||
accessTokenTTL,
|
accessTokenTTL,
|
||||||
accessTokenNumUsesLimit,
|
accessTokenNumUsesLimit,
|
||||||
accessTokenTrustedIps: JSON.stringify(reformattedAccessTokenTrustedIps),
|
accessTokenTrustedIps: JSON.stringify(reformattedAccessTokenTrustedIps)
|
||||||
encryptedKubernetesTokenReviewerJwt: encryptor({ plainText: Buffer.from(tokenReviewerJwt) }).cipherTextBlob,
|
|
||||||
encryptedKubernetesCaCertificate: encryptor({ plainText: Buffer.from(caCert) }).cipherTextBlob
|
|
||||||
},
|
},
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
@@ -373,33 +455,60 @@ export const identityKubernetesAuthServiceFactory = ({
|
|||||||
: undefined
|
: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
const { encryptor, decryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.findOne({ orgId: identityMembershipOrg.orgId });
|
||||||
type: KmsDataKey.Organization,
|
if (!orgBot) {
|
||||||
orgId: identityMembershipOrg.orgId
|
throw new NotFoundError({
|
||||||
|
message: `Organization bot not found for organization with ID ${identityMembershipOrg.orgId}`,
|
||||||
|
name: "OrgBotNotFound"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
});
|
});
|
||||||
|
|
||||||
if (caCert !== undefined) {
|
if (caCert !== undefined) {
|
||||||
updateQuery.encryptedKubernetesCaCertificate = encryptor({ plainText: Buffer.from(caCert) }).cipherTextBlob;
|
const { ciphertext: encryptedCACert, iv: caCertIV, tag: caCertTag } = encryptSymmetric(caCert, key);
|
||||||
|
updateQuery.encryptedCaCert = encryptedCACert;
|
||||||
|
updateQuery.caCertIV = caCertIV;
|
||||||
|
updateQuery.caCertTag = caCertTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokenReviewerJwt !== undefined) {
|
if (tokenReviewerJwt !== undefined) {
|
||||||
updateQuery.encryptedKubernetesTokenReviewerJwt = encryptor({
|
const {
|
||||||
plainText: Buffer.from(tokenReviewerJwt)
|
ciphertext: encryptedTokenReviewerJwt,
|
||||||
}).cipherTextBlob;
|
iv: tokenReviewerJwtIV,
|
||||||
|
tag: tokenReviewerJwtTag
|
||||||
|
} = encryptSymmetric(tokenReviewerJwt, key);
|
||||||
|
updateQuery.encryptedTokenReviewerJwt = encryptedTokenReviewerJwt;
|
||||||
|
updateQuery.tokenReviewerJwtIV = tokenReviewerJwtIV;
|
||||||
|
updateQuery.tokenReviewerJwtTag = tokenReviewerJwtTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedKubernetesAuth = await identityKubernetesAuthDAL.updateById(identityKubernetesAuth.id, updateQuery);
|
const updatedKubernetesAuth = await identityKubernetesAuthDAL.updateById(identityKubernetesAuth.id, updateQuery);
|
||||||
|
|
||||||
const updatedCACert = updatedKubernetesAuth.encryptedKubernetesCaCertificate
|
const updatedCACert =
|
||||||
? decryptor({
|
updatedKubernetesAuth.encryptedCaCert && updatedKubernetesAuth.caCertIV && updatedKubernetesAuth.caCertTag
|
||||||
cipherTextBlob: updatedKubernetesAuth.encryptedKubernetesCaCertificate
|
? decryptSymmetric({
|
||||||
}).toString()
|
ciphertext: updatedKubernetesAuth.encryptedCaCert,
|
||||||
|
iv: updatedKubernetesAuth.caCertIV,
|
||||||
|
tag: updatedKubernetesAuth.caCertTag,
|
||||||
|
key
|
||||||
|
})
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
const updatedTokenReviewerJwt = updatedKubernetesAuth.encryptedKubernetesTokenReviewerJwt
|
const updatedTokenReviewerJwt =
|
||||||
? decryptor({
|
updatedKubernetesAuth.encryptedTokenReviewerJwt &&
|
||||||
cipherTextBlob: updatedKubernetesAuth.encryptedKubernetesTokenReviewerJwt
|
updatedKubernetesAuth.tokenReviewerJwtIV &&
|
||||||
}).toString()
|
updatedKubernetesAuth.tokenReviewerJwtTag
|
||||||
|
? decryptSymmetric({
|
||||||
|
ciphertext: updatedKubernetesAuth.encryptedTokenReviewerJwt,
|
||||||
|
iv: updatedKubernetesAuth.tokenReviewerJwtIV,
|
||||||
|
tag: updatedKubernetesAuth.tokenReviewerJwtTag,
|
||||||
|
key
|
||||||
|
})
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -436,21 +545,41 @@ export const identityKubernetesAuthServiceFactory = ({
|
|||||||
);
|
);
|
||||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Identity);
|
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Identity);
|
||||||
|
|
||||||
const { decryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.findOne({ orgId: identityMembershipOrg.orgId });
|
||||||
type: KmsDataKey.Organization,
|
if (!orgBot)
|
||||||
orgId: identityMembershipOrg.orgId
|
throw new NotFoundError({
|
||||||
|
message: `Organization bot not found for organization with ID ${identityMembershipOrg.orgId}`,
|
||||||
|
name: "OrgBotNotFound"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
|
});
|
||||||
|
|
||||||
|
const { encryptedCaCert, caCertIV, caCertTag, encryptedTokenReviewerJwt, tokenReviewerJwtIV, tokenReviewerJwtTag } =
|
||||||
|
identityKubernetesAuth;
|
||||||
|
|
||||||
let caCert = "";
|
let caCert = "";
|
||||||
if (identityKubernetesAuth.encryptedKubernetesCaCertificate) {
|
if (encryptedCaCert && caCertIV && caCertTag) {
|
||||||
caCert = decryptor({ cipherTextBlob: identityKubernetesAuth.encryptedKubernetesCaCertificate }).toString();
|
caCert = decryptSymmetric({
|
||||||
|
ciphertext: encryptedCaCert,
|
||||||
|
iv: caCertIV,
|
||||||
|
tag: caCertTag,
|
||||||
|
key
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let tokenReviewerJwt = "";
|
let tokenReviewerJwt = "";
|
||||||
if (identityKubernetesAuth.encryptedKubernetesTokenReviewerJwt) {
|
if (encryptedTokenReviewerJwt && tokenReviewerJwtIV && tokenReviewerJwtTag) {
|
||||||
tokenReviewerJwt = decryptor({
|
tokenReviewerJwt = decryptSymmetric({
|
||||||
cipherTextBlob: identityKubernetesAuth.encryptedKubernetesTokenReviewerJwt
|
ciphertext: encryptedTokenReviewerJwt,
|
||||||
}).toString();
|
iv: tokenReviewerJwtIV,
|
||||||
|
tag: tokenReviewerJwtTag,
|
||||||
|
key
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...identityKubernetesAuth, caCert, tokenReviewerJwt, orgId: identityMembershipOrg.orgId };
|
return { ...identityKubernetesAuth, caCert, tokenReviewerJwt, orgId: identityMembershipOrg.orgId };
|
||||||
|
|||||||
@@ -4,12 +4,20 @@ import https from "https";
|
|||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import { JwksClient } from "jwks-rsa";
|
import { JwksClient } from "jwks-rsa";
|
||||||
|
|
||||||
import { IdentityAuthMethod, TIdentityOidcAuthsUpdate } from "@app/db/schemas";
|
import { IdentityAuthMethod, SecretKeyEncoding, TIdentityOidcAuthsUpdate } from "@app/db/schemas";
|
||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
||||||
import { isAtLeastAsPrivileged } from "@app/lib/casl";
|
import { isAtLeastAsPrivileged } from "@app/lib/casl";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
|
import { generateAsymmetricKeyPair } from "@app/lib/crypto";
|
||||||
|
import {
|
||||||
|
decryptSymmetric,
|
||||||
|
encryptSymmetric,
|
||||||
|
generateSymmetricKey,
|
||||||
|
infisicalSymmetricDecrypt,
|
||||||
|
infisicalSymmetricEncypt
|
||||||
|
} from "@app/lib/crypto/encryption";
|
||||||
import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
|
import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
|
||||||
import { extractIPDetails, isValidIpOrCidr } from "@app/lib/ip";
|
import { extractIPDetails, isValidIpOrCidr } from "@app/lib/ip";
|
||||||
|
|
||||||
@@ -17,8 +25,7 @@ import { ActorType, AuthTokenType } from "../auth/auth-type";
|
|||||||
import { TIdentityOrgDALFactory } from "../identity/identity-org-dal";
|
import { TIdentityOrgDALFactory } from "../identity/identity-org-dal";
|
||||||
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
|
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
|
||||||
import { TIdentityAccessTokenJwtPayload } from "../identity-access-token/identity-access-token-types";
|
import { TIdentityAccessTokenJwtPayload } from "../identity-access-token/identity-access-token-types";
|
||||||
import { TKmsServiceFactory } from "../kms/kms-service";
|
import { TOrgBotDALFactory } from "../org/org-bot-dal";
|
||||||
import { KmsDataKey } from "../kms/kms-types";
|
|
||||||
import { TIdentityOidcAuthDALFactory } from "./identity-oidc-auth-dal";
|
import { TIdentityOidcAuthDALFactory } from "./identity-oidc-auth-dal";
|
||||||
import { doesAudValueMatchOidcPolicy, doesFieldValueMatchOidcPolicy } from "./identity-oidc-auth-fns";
|
import { doesAudValueMatchOidcPolicy, doesFieldValueMatchOidcPolicy } from "./identity-oidc-auth-fns";
|
||||||
import {
|
import {
|
||||||
@@ -35,7 +42,7 @@ type TIdentityOidcAuthServiceFactoryDep = {
|
|||||||
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "create" | "delete">;
|
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "create" | "delete">;
|
||||||
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
|
||||||
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
|
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
|
||||||
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
|
orgBotDAL: Pick<TOrgBotDALFactory, "findOne" | "transaction" | "create">;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TIdentityOidcAuthServiceFactory = ReturnType<typeof identityOidcAuthServiceFactory>;
|
export type TIdentityOidcAuthServiceFactory = ReturnType<typeof identityOidcAuthServiceFactory>;
|
||||||
@@ -46,7 +53,7 @@ export const identityOidcAuthServiceFactory = ({
|
|||||||
permissionService,
|
permissionService,
|
||||||
licenseService,
|
licenseService,
|
||||||
identityAccessTokenDAL,
|
identityAccessTokenDAL,
|
||||||
kmsService
|
orgBotDAL
|
||||||
}: TIdentityOidcAuthServiceFactoryDep) => {
|
}: TIdentityOidcAuthServiceFactoryDep) => {
|
||||||
const login = async ({ identityId, jwt: oidcJwt }: TLoginOidcAuthDTO) => {
|
const login = async ({ identityId, jwt: oidcJwt }: TLoginOidcAuthDTO) => {
|
||||||
const identityOidcAuth = await identityOidcAuthDAL.findOne({ identityId });
|
const identityOidcAuth = await identityOidcAuthDAL.findOne({ identityId });
|
||||||
@@ -63,14 +70,31 @@ export const identityOidcAuthServiceFactory = ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const { decryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.findOne({ orgId: identityMembershipOrg.orgId });
|
||||||
type: KmsDataKey.Organization,
|
if (!orgBot) {
|
||||||
orgId: identityMembershipOrg.orgId
|
throw new NotFoundError({
|
||||||
|
message: `Organization bot not found for organization with ID '${identityMembershipOrg.orgId}'`,
|
||||||
|
name: "OrgBotNotFound"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { encryptedCaCert, caCertIV, caCertTag } = identityOidcAuth;
|
||||||
|
|
||||||
let caCert = "";
|
let caCert = "";
|
||||||
if (identityOidcAuth.encryptedCaCertificate) {
|
if (encryptedCaCert && caCertIV && caCertTag) {
|
||||||
caCert = decryptor({ cipherTextBlob: identityOidcAuth.encryptedCaCertificate }).toString();
|
caCert = decryptSymmetric({
|
||||||
|
ciphertext: encryptedCaCert,
|
||||||
|
iv: caCertIV,
|
||||||
|
tag: caCertTag,
|
||||||
|
key
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestAgent = new https.Agent({ ca: caCert, rejectUnauthorized: !!caCert });
|
const requestAgent = new https.Agent({ ca: caCert, rejectUnauthorized: !!caCert });
|
||||||
@@ -240,17 +264,64 @@ export const identityOidcAuthServiceFactory = ({
|
|||||||
return extractIPDetails(accessTokenTrustedIp.ipAddress);
|
return extractIPDetails(accessTokenTrustedIp.ipAddress);
|
||||||
});
|
});
|
||||||
|
|
||||||
const { encryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.transaction(async (tx) => {
|
||||||
type: KmsDataKey.Organization,
|
const doc = await orgBotDAL.findOne({ orgId: identityMembershipOrg.orgId }, tx);
|
||||||
orgId: identityMembershipOrg.orgId
|
if (doc) return doc;
|
||||||
|
|
||||||
|
const { privateKey, publicKey } = generateAsymmetricKeyPair();
|
||||||
|
const key = generateSymmetricKey();
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedPrivateKey,
|
||||||
|
iv: privateKeyIV,
|
||||||
|
tag: privateKeyTag,
|
||||||
|
encoding: privateKeyKeyEncoding,
|
||||||
|
algorithm: privateKeyAlgorithm
|
||||||
|
} = infisicalSymmetricEncypt(privateKey);
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedSymmetricKey,
|
||||||
|
iv: symmetricKeyIV,
|
||||||
|
tag: symmetricKeyTag,
|
||||||
|
encoding: symmetricKeyKeyEncoding,
|
||||||
|
algorithm: symmetricKeyAlgorithm
|
||||||
|
} = infisicalSymmetricEncypt(key);
|
||||||
|
|
||||||
|
return orgBotDAL.create(
|
||||||
|
{
|
||||||
|
name: "Infisical org bot",
|
||||||
|
publicKey,
|
||||||
|
privateKeyIV,
|
||||||
|
encryptedPrivateKey,
|
||||||
|
symmetricKeyIV,
|
||||||
|
symmetricKeyTag,
|
||||||
|
encryptedSymmetricKey,
|
||||||
|
symmetricKeyAlgorithm,
|
||||||
|
orgId: identityMembershipOrg.orgId,
|
||||||
|
privateKeyTag,
|
||||||
|
privateKeyAlgorithm,
|
||||||
|
privateKeyKeyEncoding,
|
||||||
|
symmetricKeyKeyEncoding
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
|
});
|
||||||
|
|
||||||
|
const { ciphertext: encryptedCaCert, iv: caCertIV, tag: caCertTag } = encryptSymmetric(caCert, key);
|
||||||
|
|
||||||
const identityOidcAuth = await identityOidcAuthDAL.transaction(async (tx) => {
|
const identityOidcAuth = await identityOidcAuthDAL.transaction(async (tx) => {
|
||||||
const doc = await identityOidcAuthDAL.create(
|
const doc = await identityOidcAuthDAL.create(
|
||||||
{
|
{
|
||||||
identityId: identityMembershipOrg.identityId,
|
identityId: identityMembershipOrg.identityId,
|
||||||
oidcDiscoveryUrl,
|
oidcDiscoveryUrl,
|
||||||
encryptedCaCertificate: encryptor({ plainText: Buffer.from(caCert) }).cipherTextBlob,
|
encryptedCaCert,
|
||||||
|
caCertIV,
|
||||||
|
caCertTag,
|
||||||
boundIssuer,
|
boundIssuer,
|
||||||
boundAudiences,
|
boundAudiences,
|
||||||
boundClaims,
|
boundClaims,
|
||||||
@@ -344,18 +415,37 @@ export const identityOidcAuthServiceFactory = ({
|
|||||||
: undefined
|
: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
const { encryptor, decryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.findOne({ orgId: identityMembershipOrg.orgId });
|
||||||
type: KmsDataKey.Organization,
|
if (!orgBot) {
|
||||||
orgId: identityMembershipOrg.orgId
|
throw new NotFoundError({
|
||||||
|
message: `Organization bot not found for organization with ID '${identityMembershipOrg.orgId}'`,
|
||||||
|
name: "OrgBotNotFound"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
});
|
});
|
||||||
|
|
||||||
if (caCert !== undefined) {
|
if (caCert !== undefined) {
|
||||||
updateQuery.encryptedCaCertificate = encryptor({ plainText: Buffer.from(caCert) }).cipherTextBlob;
|
const { ciphertext: encryptedCACert, iv: caCertIV, tag: caCertTag } = encryptSymmetric(caCert, key);
|
||||||
|
updateQuery.encryptedCaCert = encryptedCACert;
|
||||||
|
updateQuery.caCertIV = caCertIV;
|
||||||
|
updateQuery.caCertTag = caCertTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedOidcAuth = await identityOidcAuthDAL.updateById(identityOidcAuth.id, updateQuery);
|
const updatedOidcAuth = await identityOidcAuthDAL.updateById(identityOidcAuth.id, updateQuery);
|
||||||
const updatedCACert = updatedOidcAuth.encryptedCaCertificate
|
const updatedCACert =
|
||||||
? decryptor({ cipherTextBlob: updatedOidcAuth.encryptedCaCertificate }).toString()
|
updatedOidcAuth.encryptedCaCert && updatedOidcAuth.caCertIV && updatedOidcAuth.caCertTag
|
||||||
|
? decryptSymmetric({
|
||||||
|
ciphertext: updatedOidcAuth.encryptedCaCert,
|
||||||
|
iv: updatedOidcAuth.caCertIV,
|
||||||
|
tag: updatedOidcAuth.caCertTag,
|
||||||
|
key
|
||||||
|
})
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -386,14 +476,27 @@ export const identityOidcAuthServiceFactory = ({
|
|||||||
|
|
||||||
const identityOidcAuth = await identityOidcAuthDAL.findOne({ identityId });
|
const identityOidcAuth = await identityOidcAuthDAL.findOne({ identityId });
|
||||||
|
|
||||||
const { decryptor } = await kmsService.createCipherPairWithDataKey({
|
const orgBot = await orgBotDAL.findOne({ orgId: identityMembershipOrg.orgId });
|
||||||
type: KmsDataKey.Organization,
|
if (!orgBot) {
|
||||||
orgId: identityMembershipOrg.orgId
|
throw new NotFoundError({
|
||||||
|
message: `Organization bot not found for organization with ID ${identityMembershipOrg.orgId}`,
|
||||||
|
name: "OrgBotNotFound"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
});
|
});
|
||||||
|
|
||||||
const caCert = identityOidcAuth.encryptedCaCertificate
|
const caCert = decryptSymmetric({
|
||||||
? decryptor({ cipherTextBlob: identityOidcAuth.encryptedCaCertificate }).toString()
|
ciphertext: identityOidcAuth.encryptedCaCert,
|
||||||
: "";
|
iv: identityOidcAuth.caCertIV,
|
||||||
|
tag: identityOidcAuth.caCertTag,
|
||||||
|
key
|
||||||
|
});
|
||||||
|
|
||||||
return { ...identityOidcAuth, orgId: identityMembershipOrg.orgId, caCert };
|
return { ...identityOidcAuth, orgId: identityMembershipOrg.orgId, caCert };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,24 +1,10 @@
|
|||||||
import { TDbClient } from "@app/db";
|
import { TDbClient } from "@app/db";
|
||||||
import { TableName } from "@app/db/schemas";
|
import { TableName } from "@app/db/schemas";
|
||||||
import { DatabaseError } from "@app/lib/errors";
|
|
||||||
import { ormify } from "@app/lib/knex";
|
import { ormify } from "@app/lib/knex";
|
||||||
import { Knex } from "knex";
|
|
||||||
|
|
||||||
export type TKmsRootConfigDALFactory = ReturnType<typeof kmsRootConfigDALFactory>;
|
export type TKmsRootConfigDALFactory = ReturnType<typeof kmsRootConfigDALFactory>;
|
||||||
|
|
||||||
export const kmsRootConfigDALFactory = (db: TDbClient) => {
|
export const kmsRootConfigDALFactory = (db: TDbClient) => {
|
||||||
const kmsOrm = ormify(db, TableName.KmsServerRootConfig);
|
const kmsOrm = ormify(db, TableName.KmsServerRootConfig);
|
||||||
|
return kmsOrm;
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
|
||||||
try {
|
|
||||||
const result = await (tx || db)(TableName.KmsServerRootConfig)
|
|
||||||
.where({ id } as never)
|
|
||||||
.first("*");
|
|
||||||
return result;
|
|
||||||
} catch (error) {
|
|
||||||
throw new DatabaseError({ error, name: "Find by id" });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return { ...kmsOrm, findById };
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import {
|
|||||||
TExternalKmsProviderFns
|
TExternalKmsProviderFns
|
||||||
} from "@app/ee/services/external-kms/providers/model";
|
} from "@app/ee/services/external-kms/providers/model";
|
||||||
import { THsmServiceFactory } from "@app/ee/services/hsm/hsm-service";
|
import { THsmServiceFactory } from "@app/ee/services/hsm/hsm-service";
|
||||||
import { KeyStorePrefixes, PgSqlLock, TKeyStoreFactory } from "@app/keystore/keystore";
|
import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";
|
||||||
import { TEnvConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { randomSecureBytes } from "@app/lib/crypto";
|
import { randomSecureBytes } from "@app/lib/crypto";
|
||||||
import { symmetricCipherService, SymmetricEncryption } from "@app/lib/crypto/cipher";
|
import { symmetricCipherService, SymmetricEncryption } from "@app/lib/crypto/cipher";
|
||||||
import { generateHash } from "@app/lib/crypto/encryption";
|
import { generateHash } from "@app/lib/crypto/encryption";
|
||||||
@@ -44,22 +44,23 @@ type TKmsServiceFactoryDep = {
|
|||||||
kmsDAL: TKmsKeyDALFactory;
|
kmsDAL: TKmsKeyDALFactory;
|
||||||
projectDAL: Pick<TProjectDALFactory, "findById" | "updateById" | "transaction">;
|
projectDAL: Pick<TProjectDALFactory, "findById" | "updateById" | "transaction">;
|
||||||
orgDAL: Pick<TOrgDALFactory, "findById" | "updateById" | "transaction">;
|
orgDAL: Pick<TOrgDALFactory, "findById" | "updateById" | "transaction">;
|
||||||
kmsRootConfigDAL: Pick<TKmsRootConfigDALFactory, "findById" | "create" | "updateById" | "transaction">;
|
kmsRootConfigDAL: Pick<TKmsRootConfigDALFactory, "findById" | "create" | "updateById">;
|
||||||
keyStore: Pick<TKeyStoreFactory, "acquireLock" | "waitTillReady" | "setItemWithExpiry">;
|
keyStore: Pick<TKeyStoreFactory, "acquireLock" | "waitTillReady" | "setItemWithExpiry">;
|
||||||
internalKmsDAL: Pick<TInternalKmsDALFactory, "create">;
|
internalKmsDAL: Pick<TInternalKmsDALFactory, "create">;
|
||||||
hsmService: THsmServiceFactory;
|
hsmService: THsmServiceFactory;
|
||||||
envConfig: Pick<TEnvConfig, "ENCRYPTION_KEY" | "ROOT_ENCRYPTION_KEY">;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TKmsServiceFactory = ReturnType<typeof kmsServiceFactory>;
|
export type TKmsServiceFactory = ReturnType<typeof kmsServiceFactory>;
|
||||||
|
|
||||||
|
const KMS_ROOT_CREATION_WAIT_KEY = "wait_till_ready_kms_root_key";
|
||||||
|
const KMS_ROOT_CREATION_WAIT_TIME = 10;
|
||||||
|
|
||||||
// akhilmhdh: Don't edit this value. This is measured for blob concatination in kms
|
// akhilmhdh: Don't edit this value. This is measured for blob concatination in kms
|
||||||
const KMS_VERSION = "v01";
|
const KMS_VERSION = "v01";
|
||||||
const KMS_VERSION_BLOB_LENGTH = 3;
|
const KMS_VERSION_BLOB_LENGTH = 3;
|
||||||
const KmsSanitizedSchema = KmsKeysSchema.extend({ isExternal: z.boolean() });
|
const KmsSanitizedSchema = KmsKeysSchema.extend({ isExternal: z.boolean() });
|
||||||
|
|
||||||
export const kmsServiceFactory = ({
|
export const kmsServiceFactory = ({
|
||||||
envConfig,
|
|
||||||
kmsDAL,
|
kmsDAL,
|
||||||
kmsRootConfigDAL,
|
kmsRootConfigDAL,
|
||||||
keyStore,
|
keyStore,
|
||||||
@@ -472,8 +473,7 @@ export const kmsServiceFactory = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const kmsDecryptor = await decryptWithKmsKey({
|
const kmsDecryptor = await decryptWithKmsKey({
|
||||||
kmsId: kmsKeyId,
|
kmsId: kmsKeyId
|
||||||
tx: trx
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return kmsDecryptor({
|
return kmsDecryptor({
|
||||||
@@ -635,8 +635,10 @@ export const kmsServiceFactory = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const $getBasicEncryptionKey = () => {
|
const $getBasicEncryptionKey = () => {
|
||||||
const encryptionKey = envConfig.ENCRYPTION_KEY || envConfig.ROOT_ENCRYPTION_KEY;
|
const appCfg = getConfig();
|
||||||
const isBase64 = !envConfig.ENCRYPTION_KEY;
|
|
||||||
|
const encryptionKey = appCfg.ENCRYPTION_KEY || appCfg.ROOT_ENCRYPTION_KEY;
|
||||||
|
const isBase64 = !appCfg.ENCRYPTION_KEY;
|
||||||
if (!encryptionKey)
|
if (!encryptionKey)
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Root encryption key not found for KMS service. Did you set the ENCRYPTION_KEY or ROOT_ENCRYPTION_KEY environment variables?"
|
"Root encryption key not found for KMS service. Did you set the ENCRYPTION_KEY or ROOT_ENCRYPTION_KEY environment variables?"
|
||||||
@@ -872,13 +874,35 @@ export const kmsServiceFactory = ({
|
|||||||
return { id, name, orgId, isExternal };
|
return { id, name, orgId, isExternal };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// akhilmhdh: a copy of this is made in migrations/utils/kms
|
||||||
const startService = async () => {
|
const startService = async () => {
|
||||||
const kmsRootConfig = await kmsRootConfigDAL.transaction(async (tx) => {
|
const lock = await keyStore.acquireLock([`KMS_ROOT_CFG_LOCK`], 3000, { retryCount: 3 }).catch(() => null);
|
||||||
await tx.raw("SELECT pg_advisory_xact_lock(?)", [PgSqlLock.KmsRootKeyInit]);
|
if (!lock) {
|
||||||
// check if KMS root key was already generated and saved in DB
|
await keyStore.waitTillReady({
|
||||||
const existingRootConfig = await kmsRootConfigDAL.findById(KMS_ROOT_CONFIG_UUID);
|
key: KMS_ROOT_CREATION_WAIT_KEY,
|
||||||
if (existingRootConfig) return existingRootConfig;
|
keyCheckCb: (val) => val === "true",
|
||||||
|
waitingCb: () => logger.info("KMS. Waiting for leader to finish creation of KMS Root Key")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if KMS root key was already generated and saved in DB
|
||||||
|
const kmsRootConfig = await kmsRootConfigDAL.findById(KMS_ROOT_CONFIG_UUID);
|
||||||
|
|
||||||
|
// case 1: a root key already exists in the DB
|
||||||
|
if (kmsRootConfig) {
|
||||||
|
if (lock) await lock.release();
|
||||||
|
logger.info(`KMS: Encrypted ROOT Key found from DB. Decrypting. [strategy=${kmsRootConfig.encryptionStrategy}]`);
|
||||||
|
|
||||||
|
const decryptedRootKey = await $decryptRootKey(kmsRootConfig);
|
||||||
|
|
||||||
|
// set the flag so that other instance nodes can start
|
||||||
|
await keyStore.setItemWithExpiry(KMS_ROOT_CREATION_WAIT_KEY, KMS_ROOT_CREATION_WAIT_TIME, "true");
|
||||||
|
logger.info("KMS: Loading ROOT Key into Memory.");
|
||||||
|
ROOT_ENCRYPTION_KEY = decryptedRootKey;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// case 2: no config is found, so we create a new root key with basic encryption
|
||||||
logger.info("KMS: Generating new ROOT Key");
|
logger.info("KMS: Generating new ROOT Key");
|
||||||
const newRootKey = randomSecureBytes(32);
|
const newRootKey = randomSecureBytes(32);
|
||||||
const encryptedRootKey = await $encryptRootKey(newRootKey, RootKeyEncryptionStrategy.Software).catch((err) => {
|
const encryptedRootKey = await $encryptRootKey(newRootKey, RootKeyEncryptionStrategy.Software).catch((err) => {
|
||||||
@@ -886,19 +910,18 @@ export const kmsServiceFactory = ({
|
|||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
const newRootConfig = await kmsRootConfigDAL.create({
|
await kmsRootConfigDAL.create({
|
||||||
// @ts-expect-error id is kept as fixed for idempotence and to avoid race condition
|
// @ts-expect-error id is kept as fixed for idempotence and to avoid race condition
|
||||||
id: KMS_ROOT_CONFIG_UUID,
|
id: KMS_ROOT_CONFIG_UUID,
|
||||||
encryptedRootKey,
|
encryptedRootKey,
|
||||||
encryptionStrategy: RootKeyEncryptionStrategy.Software
|
encryptionStrategy: RootKeyEncryptionStrategy.Software
|
||||||
});
|
});
|
||||||
return newRootConfig;
|
|
||||||
});
|
|
||||||
|
|
||||||
const decryptedRootKey = await $decryptRootKey(kmsRootConfig);
|
// set the flag so that other instance nodes can start
|
||||||
|
await keyStore.setItemWithExpiry(KMS_ROOT_CREATION_WAIT_KEY, KMS_ROOT_CREATION_WAIT_TIME, "true");
|
||||||
logger.info("KMS: Loading ROOT Key into Memory.");
|
logger.info("KMS: Saved and loaded ROOT Key into memory");
|
||||||
ROOT_ENCRYPTION_KEY = decryptedRootKey;
|
if (lock) await lock.release();
|
||||||
|
ROOT_ENCRYPTION_KEY = newRootKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateEncryptionStrategy = async (strategy: RootKeyEncryptionStrategy) => {
|
const updateEncryptionStrategy = async (strategy: RootKeyEncryptionStrategy) => {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
ProjectPermissionSub
|
ProjectPermissionSub
|
||||||
} from "@app/ee/services/permission/project-permission";
|
} from "@app/ee/services/permission/project-permission";
|
||||||
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
import { UnpackedPermissionSchema } from "@app/server/routes/sanitizedSchema/permission";
|
import { UnpackedPermissionSchema } from "@app/server/routes/santizedSchemas/permission";
|
||||||
|
|
||||||
import { ActorAuthMethod } from "../auth/auth-type";
|
import { ActorAuthMethod } from "../auth/auth-type";
|
||||||
import { TIdentityProjectMembershipRoleDALFactory } from "../identity-project/identity-project-membership-role-dal";
|
import { TIdentityProjectMembershipRoleDALFactory } from "../identity-project/identity-project-membership-role-dal";
|
||||||
|
|||||||
@@ -4,17 +4,8 @@ import { ProjectType, TProjectKeys } from "@app/db/schemas";
|
|||||||
import { TProjectPermission } from "@app/lib/types";
|
import { TProjectPermission } from "@app/lib/types";
|
||||||
|
|
||||||
import { ActorAuthMethod, ActorType } from "../auth/auth-type";
|
import { ActorAuthMethod, ActorType } from "../auth/auth-type";
|
||||||
|
import { CaStatus } from "../certificate-authority/certificate-authority-types";
|
||||||
enum KmsType {
|
import { KmsType } from "../kms/kms-types";
|
||||||
External = "external",
|
|
||||||
Internal = "internal"
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CaStatus {
|
|
||||||
ACTIVE = "active",
|
|
||||||
DISABLED = "disabled",
|
|
||||||
PENDING_CERTIFICATE = "pending-certificate"
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum ProjectFilterType {
|
export enum ProjectFilterType {
|
||||||
ID = "id",
|
ID = "id",
|
||||||
|
|||||||
@@ -1488,18 +1488,7 @@ export const secretQueueFactory = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
queueService.start(QueueName.SecretWebhook, async (job) => {
|
queueService.start(QueueName.SecretWebhook, async (job) => {
|
||||||
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
|
await fnTriggerWebhook({ ...job.data, projectEnvDAL, webhookDAL, projectDAL });
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId: job.data.projectId
|
|
||||||
});
|
|
||||||
|
|
||||||
await fnTriggerWebhook({
|
|
||||||
...job.data,
|
|
||||||
projectEnvDAL,
|
|
||||||
webhookDAL,
|
|
||||||
projectDAL,
|
|
||||||
secretManagerDecryptor: (value) => secretManagerDecryptor({ cipherTextBlob: value }).toString()
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import bcrypt from "bcrypt";
|
|||||||
|
|
||||||
import { TSuperAdmin, TSuperAdminUpdate } from "@app/db/schemas";
|
import { TSuperAdmin, TSuperAdminUpdate } from "@app/db/schemas";
|
||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { PgSqlLock, TKeyStoreFactory } from "@app/keystore/keystore";
|
import { TKeyStoreFactory } from "@app/keystore/keystore";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { infisicalSymmetricEncypt } from "@app/lib/crypto/encryption";
|
import { infisicalSymmetricEncypt } from "@app/lib/crypto/encryption";
|
||||||
import { getUserPrivateKey } from "@app/lib/crypto/srp";
|
import { getUserPrivateKey } from "@app/lib/crypto/srp";
|
||||||
@@ -87,10 +87,8 @@ export const superAdminServiceFactory = ({
|
|||||||
|
|
||||||
// reset on initialized
|
// reset on initialized
|
||||||
await keyStore.deleteItem(ADMIN_CONFIG_KEY);
|
await keyStore.deleteItem(ADMIN_CONFIG_KEY);
|
||||||
const serverCfg = await serverCfgDAL.transaction(async (tx) => {
|
const serverCfg = await serverCfgDAL.findById(ADMIN_CONFIG_DB_UUID);
|
||||||
await tx.raw("SELECT pg_advisory_xact_lock(?)", [PgSqlLock.SuperAdminInit]);
|
if (serverCfg) return;
|
||||||
const serverCfgInDB = await serverCfgDAL.findById(ADMIN_CONFIG_DB_UUID);
|
|
||||||
if (serverCfgInDB) return serverCfgInDB;
|
|
||||||
|
|
||||||
const newCfg = await serverCfgDAL.create({
|
const newCfg = await serverCfgDAL.create({
|
||||||
// @ts-expect-error id is kept as fixed for idempotence and to avoid race condition
|
// @ts-expect-error id is kept as fixed for idempotence and to avoid race condition
|
||||||
@@ -100,8 +98,6 @@ export const superAdminServiceFactory = ({
|
|||||||
defaultAuthOrgId: null
|
defaultAuthOrgId: null
|
||||||
});
|
});
|
||||||
return newCfg;
|
return newCfg;
|
||||||
});
|
|
||||||
return serverCfg;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateServerCfg = async (
|
const updateServerCfg = async (
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ import crypto from "node:crypto";
|
|||||||
import { AxiosError } from "axios";
|
import { AxiosError } from "axios";
|
||||||
import picomatch from "picomatch";
|
import picomatch from "picomatch";
|
||||||
|
|
||||||
import { TWebhooks } from "@app/db/schemas";
|
import { SecretKeyEncoding, TWebhooks } from "@app/db/schemas";
|
||||||
import { request } from "@app/lib/config/request";
|
import { request } from "@app/lib/config/request";
|
||||||
|
import { infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
||||||
import { NotFoundError } from "@app/lib/errors";
|
import { NotFoundError } from "@app/lib/errors";
|
||||||
import { logger } from "@app/lib/logger";
|
import { logger } from "@app/lib/logger";
|
||||||
|
|
||||||
@@ -15,14 +16,28 @@ import { WebhookType } from "./webhook-types";
|
|||||||
|
|
||||||
const WEBHOOK_TRIGGER_TIMEOUT = 15 * 1000;
|
const WEBHOOK_TRIGGER_TIMEOUT = 15 * 1000;
|
||||||
|
|
||||||
export const decryptWebhookDetails = (webhook: TWebhooks, decryptor: (value: Buffer) => string) => {
|
export const decryptWebhookDetails = (webhook: TWebhooks) => {
|
||||||
const { encryptedPassKey, encryptedUrl } = webhook;
|
const { keyEncoding, iv, encryptedSecretKey, tag, urlCipherText, urlIV, urlTag, url } = webhook;
|
||||||
|
|
||||||
const decryptedUrl = decryptor(encryptedUrl);
|
|
||||||
|
|
||||||
let decryptedSecretKey = "";
|
let decryptedSecretKey = "";
|
||||||
if (encryptedPassKey) {
|
let decryptedUrl = url;
|
||||||
decryptedSecretKey = decryptor(encryptedPassKey);
|
|
||||||
|
if (encryptedSecretKey) {
|
||||||
|
decryptedSecretKey = infisicalSymmetricDecrypt({
|
||||||
|
keyEncoding: keyEncoding as SecretKeyEncoding,
|
||||||
|
ciphertext: encryptedSecretKey,
|
||||||
|
iv: iv as string,
|
||||||
|
tag: tag as string
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (urlCipherText) {
|
||||||
|
decryptedUrl = infisicalSymmetricDecrypt({
|
||||||
|
keyEncoding: keyEncoding as SecretKeyEncoding,
|
||||||
|
ciphertext: urlCipherText,
|
||||||
|
iv: urlIV as string,
|
||||||
|
tag: urlTag as string
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -31,14 +46,10 @@ export const decryptWebhookDetails = (webhook: TWebhooks, decryptor: (value: Buf
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const triggerWebhookRequest = async (
|
export const triggerWebhookRequest = async (webhook: TWebhooks, data: Record<string, unknown>) => {
|
||||||
webhook: TWebhooks,
|
|
||||||
decryptor: (value: Buffer) => string,
|
|
||||||
data: Record<string, unknown>
|
|
||||||
) => {
|
|
||||||
const headers: Record<string, string> = {};
|
const headers: Record<string, string> = {};
|
||||||
const payload = { ...data, timestamp: Date.now() };
|
const payload = { ...data, timestamp: Date.now() };
|
||||||
const { secretKey, url } = decryptWebhookDetails(webhook, decryptor);
|
const { secretKey, url } = decryptWebhookDetails(webhook);
|
||||||
|
|
||||||
if (secretKey) {
|
if (secretKey) {
|
||||||
const webhookSign = crypto.createHmac("sha256", secretKey).update(JSON.stringify(payload)).digest("hex");
|
const webhookSign = crypto.createHmac("sha256", secretKey).update(JSON.stringify(payload)).digest("hex");
|
||||||
@@ -113,7 +124,6 @@ export type TFnTriggerWebhookDTO = {
|
|||||||
webhookDAL: Pick<TWebhookDALFactory, "findAllWebhooks" | "transaction" | "update" | "bulkUpdate">;
|
webhookDAL: Pick<TWebhookDALFactory, "findAllWebhooks" | "transaction" | "update" | "bulkUpdate">;
|
||||||
projectEnvDAL: Pick<TProjectEnvDALFactory, "findOne">;
|
projectEnvDAL: Pick<TProjectEnvDALFactory, "findOne">;
|
||||||
projectDAL: Pick<TProjectDALFactory, "findById">;
|
projectDAL: Pick<TProjectDALFactory, "findById">;
|
||||||
secretManagerDecryptor: (value: Buffer) => string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// this is reusable function
|
// this is reusable function
|
||||||
@@ -124,8 +134,7 @@ export const fnTriggerWebhook = async ({
|
|||||||
projectId,
|
projectId,
|
||||||
webhookDAL,
|
webhookDAL,
|
||||||
projectEnvDAL,
|
projectEnvDAL,
|
||||||
projectDAL,
|
projectDAL
|
||||||
secretManagerDecryptor
|
|
||||||
}: TFnTriggerWebhookDTO) => {
|
}: TFnTriggerWebhookDTO) => {
|
||||||
const webhooks = await webhookDAL.findAllWebhooks(projectId, environment);
|
const webhooks = await webhookDAL.findAllWebhooks(projectId, environment);
|
||||||
const toBeTriggeredHooks = webhooks.filter(
|
const toBeTriggeredHooks = webhooks.filter(
|
||||||
@@ -139,7 +148,6 @@ export const fnTriggerWebhook = async ({
|
|||||||
toBeTriggeredHooks.map((hook) =>
|
toBeTriggeredHooks.map((hook) =>
|
||||||
triggerWebhookRequest(
|
triggerWebhookRequest(
|
||||||
hook,
|
hook,
|
||||||
secretManagerDecryptor,
|
|
||||||
getWebhookPayload("secrets.modified", {
|
getWebhookPayload("secrets.modified", {
|
||||||
workspaceName: project.name,
|
workspaceName: project.name,
|
||||||
workspaceId: projectId,
|
workspaceId: projectId,
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ import { ForbiddenError } from "@casl/ability";
|
|||||||
import { ActionProjectType, TWebhooksInsert } from "@app/db/schemas";
|
import { ActionProjectType, TWebhooksInsert } from "@app/db/schemas";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||||
|
import { infisicalSymmetricEncypt } from "@app/lib/crypto/encryption";
|
||||||
import { NotFoundError } from "@app/lib/errors";
|
import { NotFoundError } from "@app/lib/errors";
|
||||||
|
|
||||||
import { TKmsServiceFactory } from "../kms/kms-service";
|
|
||||||
import { KmsDataKey } from "../kms/kms-types";
|
|
||||||
import { TProjectDALFactory } from "../project/project-dal";
|
import { TProjectDALFactory } from "../project/project-dal";
|
||||||
import { TProjectEnvDALFactory } from "../project-env/project-env-dal";
|
import { TProjectEnvDALFactory } from "../project-env/project-env-dal";
|
||||||
import { TWebhookDALFactory } from "./webhook-dal";
|
import { TWebhookDALFactory } from "./webhook-dal";
|
||||||
@@ -24,7 +23,6 @@ type TWebhookServiceFactoryDep = {
|
|||||||
projectEnvDAL: TProjectEnvDALFactory;
|
projectEnvDAL: TProjectEnvDALFactory;
|
||||||
projectDAL: Pick<TProjectDALFactory, "findById">;
|
projectDAL: Pick<TProjectDALFactory, "findById">;
|
||||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||||
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TWebhookServiceFactory = ReturnType<typeof webhookServiceFactory>;
|
export type TWebhookServiceFactory = ReturnType<typeof webhookServiceFactory>;
|
||||||
@@ -33,8 +31,7 @@ export const webhookServiceFactory = ({
|
|||||||
webhookDAL,
|
webhookDAL,
|
||||||
projectEnvDAL,
|
projectEnvDAL,
|
||||||
permissionService,
|
permissionService,
|
||||||
projectDAL,
|
projectDAL
|
||||||
kmsService
|
|
||||||
}: TWebhookServiceFactoryDep) => {
|
}: TWebhookServiceFactoryDep) => {
|
||||||
const createWebhook = async ({
|
const createWebhook = async ({
|
||||||
actor,
|
actor,
|
||||||
@@ -63,20 +60,30 @@ export const webhookServiceFactory = ({
|
|||||||
message: `Environment with slug '${environment}' in project with ID '${projectId}' not found`
|
message: `Environment with slug '${environment}' in project with ID '${projectId}' not found`
|
||||||
});
|
});
|
||||||
|
|
||||||
const { encryptor: secretManagerEncryptor } = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId
|
|
||||||
});
|
|
||||||
const insertDoc: TWebhooksInsert = {
|
const insertDoc: TWebhooksInsert = {
|
||||||
|
url: "", // deprecated - we are moving away from plaintext URLs
|
||||||
envId: env.id,
|
envId: env.id,
|
||||||
isDisabled: false,
|
isDisabled: false,
|
||||||
secretPath: secretPath || "/",
|
secretPath: secretPath || "/",
|
||||||
type,
|
type
|
||||||
encryptedUrl: secretManagerEncryptor({ plainText: Buffer.from(webhookUrl) }).cipherTextBlob
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (webhookSecretKey) {
|
if (webhookSecretKey) {
|
||||||
insertDoc.encryptedPassKey = secretManagerEncryptor({ plainText: Buffer.from(webhookSecretKey) }).cipherTextBlob;
|
const { ciphertext, iv, tag, algorithm, encoding } = infisicalSymmetricEncypt(webhookSecretKey);
|
||||||
|
insertDoc.encryptedSecretKey = ciphertext;
|
||||||
|
insertDoc.iv = iv;
|
||||||
|
insertDoc.tag = tag;
|
||||||
|
insertDoc.algorithm = algorithm;
|
||||||
|
insertDoc.keyEncoding = encoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (webhookUrl) {
|
||||||
|
const { ciphertext, iv, tag, algorithm, encoding } = infisicalSymmetricEncypt(webhookUrl);
|
||||||
|
insertDoc.urlCipherText = ciphertext;
|
||||||
|
insertDoc.urlIV = iv;
|
||||||
|
insertDoc.urlTag = tag;
|
||||||
|
insertDoc.algorithm = algorithm;
|
||||||
|
insertDoc.keyEncoding = encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
const webhook = await webhookDAL.create(insertDoc);
|
const webhook = await webhookDAL.create(insertDoc);
|
||||||
@@ -133,17 +140,12 @@ export const webhookServiceFactory = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const project = await projectDAL.findById(webhook.projectId);
|
const project = await projectDAL.findById(webhook.projectId);
|
||||||
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId: project.id
|
|
||||||
});
|
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Webhooks);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Webhooks);
|
||||||
let webhookError: string | undefined;
|
let webhookError: string | undefined;
|
||||||
try {
|
try {
|
||||||
await triggerWebhookRequest(
|
await triggerWebhookRequest(
|
||||||
webhook,
|
webhook,
|
||||||
(value) => secretManagerDecryptor({ cipherTextBlob: value }).toString(),
|
|
||||||
getWebhookPayload("test", {
|
getWebhookPayload("test", {
|
||||||
workspaceName: project.name,
|
workspaceName: project.name,
|
||||||
workspaceId: webhook.projectId,
|
workspaceId: webhook.projectId,
|
||||||
@@ -183,13 +185,8 @@ export const webhookServiceFactory = ({
|
|||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Webhooks);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Webhooks);
|
||||||
|
|
||||||
const webhooks = await webhookDAL.findAllWebhooks(projectId, environment, secretPath);
|
const webhooks = await webhookDAL.findAllWebhooks(projectId, environment, secretPath);
|
||||||
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
|
|
||||||
type: KmsDataKey.SecretManager,
|
|
||||||
projectId
|
|
||||||
});
|
|
||||||
|
|
||||||
return webhooks.map((w) => {
|
return webhooks.map((w) => {
|
||||||
const { url } = decryptWebhookDetails(w, (value) => secretManagerDecryptor({ cipherTextBlob: value }).toString());
|
const { url } = decryptWebhookDetails(w);
|
||||||
return {
|
return {
|
||||||
...w,
|
...w,
|
||||||
url
|
url
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
{
|
{
|
||||||
"ts-node": {
|
"ts-node": {
|
||||||
// Do not forget to `npm i -D tsconfig-paths`
|
// Do not forget to `npm i -D tsconfig-paths`
|
||||||
"require": ["tsconfig-paths/register"],
|
"require": ["tsconfig-paths/register"]
|
||||||
"files": true
|
|
||||||
},
|
},
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "esnext",
|
"target": "esnext",
|
||||||
@@ -20,7 +19,6 @@
|
|||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"moduleResolution": "Node",
|
"moduleResolution": "Node",
|
||||||
"allowSyntheticDefaultImports": true,
|
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
|||||||
@@ -56,6 +56,20 @@ services:
|
|||||||
POSTGRES_USER: infisical
|
POSTGRES_USER: infisical
|
||||||
POSTGRES_DB: infisical-test
|
POSTGRES_DB: infisical-test
|
||||||
|
|
||||||
|
db-migration:
|
||||||
|
container_name: infisical-db-migration
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
build:
|
||||||
|
context: ./backend
|
||||||
|
dockerfile: Dockerfile.dev
|
||||||
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
- DB_CONNECTION_URI=postgres://infisical:infisical@db/infisical?sslmode=disable
|
||||||
|
command: npm run migration:latest
|
||||||
|
volumes:
|
||||||
|
- ./backend/src:/app/src
|
||||||
|
|
||||||
backend:
|
backend:
|
||||||
container_name: infisical-dev-api
|
container_name: infisical-dev-api
|
||||||
build:
|
build:
|
||||||
@@ -66,6 +80,8 @@ services:
|
|||||||
condition: service_started
|
condition: service_started
|
||||||
redis:
|
redis:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
|
db-migration:
|
||||||
|
condition: service_completed_successfully
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
+14
-1
@@ -1,6 +1,18 @@
|
|||||||
version: "3"
|
version: "3"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
db-migration:
|
||||||
|
container_name: infisical-db-migration
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
image: infisical/infisical:latest-postgres
|
||||||
|
env_file: .env
|
||||||
|
command: npm run migration:latest
|
||||||
|
pull_policy: always
|
||||||
|
networks:
|
||||||
|
- infisical
|
||||||
|
|
||||||
backend:
|
backend:
|
||||||
container_name: infisical-backend
|
container_name: infisical-backend
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -9,6 +21,8 @@ services:
|
|||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
|
db-migration:
|
||||||
|
condition: service_completed_successfully
|
||||||
image: infisical/infisical:latest-postgres
|
image: infisical/infisical:latest-postgres
|
||||||
pull_policy: always
|
pull_policy: always
|
||||||
env_file: .env
|
env_file: .env
|
||||||
@@ -56,4 +70,3 @@ volumes:
|
|||||||
|
|
||||||
networks:
|
networks:
|
||||||
infisical:
|
infisical:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user