lab7: app security, Argon2id, mTLS, OpenBao client, least-privilege worker
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import { Injectable, Logger, OnApplicationBootstrap } from '@nestjs/common';
|
||||
import {
|
||||
Inject,
|
||||
Injectable,
|
||||
Logger,
|
||||
OnApplicationBootstrap,
|
||||
Optional,
|
||||
} from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import type { Channel, ConsumeMessage } from 'amqplib';
|
||||
import {
|
||||
@@ -9,9 +15,9 @@ import {
|
||||
type Span,
|
||||
} from '@opentelemetry/api';
|
||||
import { createHash } from 'node:crypto';
|
||||
import os from 'node:os';
|
||||
import type { AttachmentRow } from '../attachments/attachment.js';
|
||||
import type { AppConfig } from '../config/app-config.schema.js';
|
||||
import { resolveInstanceId } from '../config/instance-id.js';
|
||||
import { ObjectStorage } from '../storage/object-storage.js';
|
||||
import { retryDelayMs } from '../jobs/backoff.js';
|
||||
import { BrokerClient } from '../jobs/broker.client.js';
|
||||
@@ -91,7 +97,7 @@ function sha256(data: Buffer): string {
|
||||
@Injectable()
|
||||
export class JobProcessor implements OnApplicationBootstrap {
|
||||
private readonly logger = new Logger(JobProcessor.name);
|
||||
private readonly workerId = process.env.INSTANCE_ID ?? os.hostname();
|
||||
private readonly workerId: string;
|
||||
private readonly maxPixels: number;
|
||||
private readonly timeoutSeconds: number;
|
||||
private readonly leaseSeconds: number;
|
||||
@@ -105,11 +111,12 @@ export class JobProcessor implements OnApplicationBootstrap {
|
||||
private readonly config: ConfigService<AppConfig>,
|
||||
private readonly broker: BrokerClient,
|
||||
private readonly jobs: JobsRepository,
|
||||
private readonly relay: OutboxRelay,
|
||||
@Optional() @Inject(OutboxRelay) private readonly relay: OutboxRelay | undefined,
|
||||
private readonly faults: FaultInjector,
|
||||
private readonly storage: ObjectStorage,
|
||||
private readonly metrics: MetricsService,
|
||||
) {
|
||||
this.workerId = resolveInstanceId(config, 'wrk');
|
||||
this.maxPixels = config.getOrThrow('MAX_IMAGE_PIXELS');
|
||||
this.timeoutSeconds = config.getOrThrow('JOB_TIMEOUT_SECONDS');
|
||||
this.leaseSeconds = config.getOrThrow('JOB_LEASE_SECONDS');
|
||||
@@ -432,7 +439,7 @@ export class JobProcessor implements OnApplicationBootstrap {
|
||||
delay,
|
||||
);
|
||||
this.metrics.increment(`worker.jobs.${outcome}`);
|
||||
if (outcome === 'retry') this.relay.kick();
|
||||
if (outcome === 'retry') this.relay?.kick();
|
||||
this.safeAck(channel, message);
|
||||
if (outcome === 'retry' || outcome === 'failed')
|
||||
await this.cleanupAttemptObjects(job, null);
|
||||
|
||||
Reference in New Issue
Block a user