lab7: app security, Argon2id, mTLS, OpenBao client, least-privilege worker
This commit is contained in:
+22
-7
@@ -5,24 +5,35 @@ import { ConfigService } from '@nestjs/config';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import http from 'node:http';
|
||||
import type { AppConfig } from './config/app-config.schema.js';
|
||||
import { resolveInstanceId } from './config/instance-id.js';
|
||||
import { BrokerClient } from './jobs/broker.client.js';
|
||||
import { RuntimeSecretsStore } from './openbao/runtime-secrets.service.js';
|
||||
import { registerBootstrappedSecurity } from './security/security.module.js';
|
||||
import { TlsMaterialManager } from './security/tls-material.js';
|
||||
import { appLogger } from './telemetry/logger.js';
|
||||
import { attachTelemetryTls, shutdownTelemetry } from './telemetry/sdk.js';
|
||||
import { JobProcessor } from './worker/job-processor.service.js';
|
||||
import { WorkerModule } from './worker/worker.module.js';
|
||||
import { appLogger } from './telemetry/logger.js';
|
||||
import { shutdownTelemetry } from './telemetry/sdk.js';
|
||||
|
||||
const DRAIN_MS = 30_000;
|
||||
|
||||
async function bootstrap(): Promise<void> {
|
||||
const tlsMaterial = TlsMaterialManager.initFromEnv('worker');
|
||||
attachTelemetryTls(tlsMaterial);
|
||||
const secretsStore = await RuntimeSecretsStore.bootstrap(
|
||||
'worker',
|
||||
tlsMaterial,
|
||||
);
|
||||
registerBootstrappedSecurity(tlsMaterial, secretsStore);
|
||||
|
||||
const app = await NestFactory.createApplicationContext(WorkerModule, {
|
||||
// Verbosity comes from LOG_LEVEL (default INFO, the former
|
||||
// error/warn/log set).
|
||||
logger: appLogger,
|
||||
});
|
||||
const config = app.get(ConfigService<AppConfig>);
|
||||
const broker = app.get(BrokerClient);
|
||||
const processor = app.get(JobProcessor);
|
||||
const logger = new Logger('worker');
|
||||
const workerId = resolveInstanceId(config, 'wrk');
|
||||
|
||||
const server = http.createServer((request, response) => {
|
||||
if (request.method === 'GET' && request.url === '/health') {
|
||||
@@ -47,9 +58,13 @@ async function bootstrap(): Promise<void> {
|
||||
resolve,
|
||||
),
|
||||
);
|
||||
logger.log(
|
||||
`worker ready: id=${process.env.INSTANCE_ID ?? process.env.HOSTNAME ?? 'worker'}`,
|
||||
);
|
||||
logger.log(`worker ready: id=${workerId}`);
|
||||
|
||||
// Live reload client certificates, CRL, and OpenBao secrets on SIGHUP.
|
||||
process.on('SIGHUP', () => {
|
||||
tlsMaterial.reload('sighup');
|
||||
void secretsStore.refreshNow('sighup');
|
||||
});
|
||||
|
||||
let shuttingDown = false;
|
||||
const shutdown = async (signal: string): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user