Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Merge remote-tracking branch 'origin/main' into misc/metrics-observability

Sheen Capadngana6137f267d1d
diff --cc .env.example
index 044613856e,3fcb0523a9..402cb79cba
--- a/.env.example
+++ b/.env.example
@@@ -68,10 -74,9 +74,17 @@@ CAPTCHA_SECRET
NEXT_PUBLIC_CAPTCHA_SITE_KEY=
+OTEL_TELEMETRY_COLLECTION_ENABLED=
+OTEL_EXPORT_TYPE=
+OTEL_EXPORT_OTLP_ENDPOINT=
+OTEL_OTLP_PUSH_INTERVAL=
+
+OTEL_COLLECTOR_BASIC_AUTH_USERNAME=
+OTEL_COLLECTOR_BASIC_AUTH_PASSWORD=
++
+ PLAIN_API_KEY=
+ PLAIN_WISH_LABEL_IDS=
+
+ SSL_CLIENT_CERTIFICATE_HEADER_KEY=
+
+ ENABLE_MSSQL_SECRET_ROTATION_ENCRYPT=true
diff --cc backend/package.json
index b7945356cf,1aa6caf6a7..9a3663b1d7
--- a/backend/package.json
+++ b/backend/package.json
@@@ -84,18 -134,17 +134,25 @@@
"@fastify/swagger": "^8.14.0",
"@fastify/swagger-ui": "^2.1.0",
"@node-saml/passport-saml": "^4.0.4",
+ "@octokit/auth-app": "^7.1.1",
+ "@octokit/plugin-retry": "^5.0.5",
"@octokit/rest": "^20.0.2",
"@octokit/webhooks-types": "^7.3.1",
+ "@opentelemetry/api": "^1.8.0",
+ "@opentelemetry/auto-instrumentations-node": "^0.46.1",
+ "@opentelemetry/exporter-metrics-otlp-proto": "^0.51.1",
+ "@opentelemetry/exporter-prometheus": "^0.51.1",
+ "@opentelemetry/instrumentation": "^0.51.1",
+ "@opentelemetry/resources": "^1.24.1",
+ "@opentelemetry/sdk-metrics": "^1.24.1",
+ "@opentelemetry/semantic-conventions": "^1.24.1",
+ "@peculiar/asn1-schema": "^2.3.8",
+ "@peculiar/x509": "^1.12.1",
"@serdnam/pino-cloudwatch-transport": "^1.0.4",
- "@sindresorhus/slugify": "^2.2.1",
+ "@sindresorhus/slugify": "1.1.0",
+ "@slack/oauth": "^3.0.1",
+ "@slack/web-api": "^7.3.4",
+ "@team-plain/typescript-sdk": "^4.6.1",
"@ucast/mongo2js": "^1.3.4",
"ajv": "^8.12.0",
"argon2": "^0.31.2",
diff --cc backend/src/lib/config/env.ts
index 76defa597c,72e0c0d058..74a88a73cd
--- a/backend/src/lib/config/env.ts
+++ b/backend/src/lib/config/env.ts
@@@ -124,15 -157,31 +157,40 @@@ const envSchema =
INFISICAL_CLOUD: zodStrBool.default("false"),
MAINTENANCE_MODE: zodStrBool.default("false"),
CAPTCHA_SECRET: zpStr(z.string().optional()),
++
++ // TELEMETRY
+ OTEL_TELEMETRY_COLLECTION_ENABLED: zodStrBool.default("false"),
+ OTEL_EXPORT_OTLP_ENDPOINT: zpStr(z.string().optional()),
+ OTEL_OTLP_PUSH_INTERVAL: z.coerce.number().default(30000),
+ OTEL_COLLECTOR_BASIC_AUTH_USERNAME: zpStr(z.string().optional()),
+ OTEL_COLLECTOR_BASIC_AUTH_PASSWORD: zpStr(z.string().optional()),
- OTEL_EXPORT_TYPE: z.enum(["prometheus", "otlp"]).optional()
++ OTEL_EXPORT_TYPE: z.enum(["prometheus", "otlp"]).optional(),
++
+ PLAIN_API_KEY: zpStr(z.string().optional()),
+ PLAIN_WISH_LABEL_IDS: zpStr(z.string().optional()),
+ DISABLE_AUDIT_LOG_GENERATION: zodStrBool.default("false"),
+ SSL_CLIENT_CERTIFICATE_HEADER_KEY: zpStr(z.string().optional()).default("x-ssl-client-cert"),
+ WORKFLOW_SLACK_CLIENT_ID: zpStr(z.string().optional()),
+ WORKFLOW_SLACK_CLIENT_SECRET: zpStr(z.string().optional()),
+ ENABLE_MSSQL_SECRET_ROTATION_ENCRYPT: zodStrBool.default("true"),
+
+ // 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,
+
+ DB_READ_REPLICAS: data.DB_READ_REPLICAS
+ ? databaseReadReplicaSchema.parse(JSON.parse(data.DB_READ_REPLICAS))
+ : undefined,
isCloud: Boolean(data.LICENSE_SERVER_KEY),
isSmtpConfigured: Boolean(data.SMTP_HOST),
isRedisConfigured: Boolean(data.REDIS_URL),
diff --cc backend/src/main.ts
index c0b9b24c5e,f8adea33f8..e47adcd90c
--- a/backend/src/main.ts
+++ b/backend/src/main.ts
@@@ -1,10 -1,13 +1,14 @@@
import dotenv from "dotenv";
+ import path from "path";
- import { initDbConnection } from "./db";
+ import { initializeHsmModule } from "@app/ee/services/hsm/hsm-fns";
+
+ import { initAuditLogDbConnection, initDbConnection } from "./db";
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 { initTelemetryInstrumentation } from "./lib/telemetry/instrumentation";
import { queueServiceFactory } from "./queue";
import { main } from "./server/app";
import { bootstrapCheck } from "./server/boot-strap-check";
@@@ -14,22 -18,39 +19,50 @@@ dotenv.config()
const run = async () => {
const logger = await initLogger();
const appCfg = initEnvConfig(logger);
+
+ if (appCfg.OTEL_TELEMETRY_COLLECTION_ENABLED) {
+ await initTelemetryInstrumentation({
+ otlpURL: appCfg.OTEL_EXPORT_OTLP_ENDPOINT,
+ otlpUser: appCfg.OTEL_COLLECTOR_BASIC_AUTH_USERNAME,
+ otlpPassword: appCfg.OTEL_COLLECTOR_BASIC_AUTH_PASSWORD,
+ otlpPushInterval: appCfg.OTEL_OTLP_PUSH_INTERVAL,
+ exportType: appCfg.OTEL_EXPORT_TYPE
+ });
+ }
+
const db = initDbConnection({
dbConnectionUri: appCfg.DB_CONNECTION_URI,
- dbRootCert: appCfg.DB_ROOT_CERT
+ dbRootCert: appCfg.DB_ROOT_CERT,
+ readReplicas: appCfg.DB_READ_REPLICAS?.map((el) => ({
+ dbRootCert: el.DB_ROOT_CERT,
+ dbConnectionUri: el.DB_CONNECTION_URI
+ }))
});
+ const auditLogDb = appCfg.AUDIT_LOGS_DB_CONNECTION_URI
+ ? initAuditLogDbConnection({
+ dbConnectionUri: appCfg.AUDIT_LOGS_DB_CONNECTION_URI,
+ dbRootCert: appCfg.AUDIT_LOGS_DB_ROOT_CERT
+ })
+ : undefined;
+
+ // 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 queue = queueServiceFactory(appCfg.REDIS_URL);
const keyStore = keyStoreFactory(appCfg.REDIS_URL);
diff --cc backend/src/server/app.ts
index 4e41826eae,6484860ea7..cf7dd622a7
--- a/backend/src/server/app.ts
+++ b/backend/src/server/app.ts
@@@ -20,7 -21,7 +21,8 @@@ import { TQueueServiceFactory } from "@
import { TSmtpService } from "@app/services/smtp/smtp-service";
import { globalRateLimiterCfg } from "./config/rateLimiter";
+ import { addErrorsToResponseSchemas } from "./plugins/add-errors-to-response-schemas";
+import { apiMetrics } from "./plugins/api-metrics";
import { fastifyErrHandler } from "./plugins/error-handler";
import { registerExternalNextjs } from "./plugins/external-nextjs";
import { serializerCompiler, validatorCompiler, ZodTypeProvider } from "./plugins/fastify-zod";