refactor(jwt): gate signing-key auto-rotation cron on SIGNING_KEY_ROTATION_DAYS (#20866)
Only register the JWT signing-key rotation cron when `SIGNING_KEY_ROTATION_DAYS` is set, and move that variable to Advanced Settings.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
|
||||
import { Command, CommandRunner } from 'nest-commander';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { MarketplaceCatalogSyncCronCommand } from 'src/engine/core-modules/application/application-marketplace/crons/commands/marketplace-catalog-sync.cron.command';
|
||||
import { StaleRegistrationCleanupCronCommand } from 'src/engine/core-modules/application/application-oauth/stale-registration-cleanup/commands/stale-registration-cleanup.cron.command';
|
||||
@@ -10,6 +11,7 @@ import { EventLogCleanupCronCommand } from 'src/engine/core-modules/event-logs/c
|
||||
import { RotateSigningKeysCronCommand } from 'src/engine/core-modules/jwt/crons/commands/rotate-signing-keys.cron.command';
|
||||
import { CronTriggerCronCommand } from 'src/engine/core-modules/logic-function/logic-function-trigger/triggers/cron/cron-trigger.cron.command';
|
||||
import { CheckPublicDomainsValidRecordsCronCommand } from 'src/engine/core-modules/public-domain/crons/commands/check-public-domains-valid-records.cron.command';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
import { CheckCustomDomainValidRecordsCronCommand } from 'src/engine/core-modules/workspace/crons/commands/check-custom-domain-valid-records.cron.command';
|
||||
import { TrashCleanupCronCommand } from 'src/engine/trash-cleanup/commands/trash-cleanup.cron.command';
|
||||
import { CleanOnboardingWorkspacesCronCommand } from 'src/engine/workspace-manager/workspace-cleaner/commands/clean-onboarding-workspaces.cron.command';
|
||||
@@ -62,6 +64,7 @@ export class CronRegisterAllCommand extends CommandRunner {
|
||||
private readonly marketplaceCatalogSyncCronCommand: MarketplaceCatalogSyncCronCommand,
|
||||
private readonly applicationVersionCheckCronCommand: ApplicationVersionCheckCronCommand,
|
||||
private readonly staleRegistrationCleanupCronCommand: StaleRegistrationCleanupCronCommand,
|
||||
private readonly twentyConfigService: TwentyConfigService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@@ -69,6 +72,10 @@ export class CronRegisterAllCommand extends CommandRunner {
|
||||
async run(): Promise<void> {
|
||||
this.logger.log('Registering all background sync cron jobs...');
|
||||
|
||||
const isSigningKeyAutoRotationEnabled = isDefined(
|
||||
this.twentyConfigService.get('SIGNING_KEY_ROTATION_DAYS'),
|
||||
);
|
||||
|
||||
const allCommands = [
|
||||
{
|
||||
name: 'MessagingMessagesImport',
|
||||
@@ -161,6 +168,7 @@ export class CronRegisterAllCommand extends CommandRunner {
|
||||
{
|
||||
name: 'RotateSigningKeys',
|
||||
command: this.rotateSigningKeysCronCommand,
|
||||
isEnabled: isSigningKeyAutoRotationEnabled,
|
||||
},
|
||||
{
|
||||
name: 'StaleRegistrationCleanup',
|
||||
@@ -172,8 +180,15 @@ export class CronRegisterAllCommand extends CommandRunner {
|
||||
let failureCount = 0;
|
||||
const failures: string[] = [];
|
||||
const successes: string[] = [];
|
||||
const skipped: string[] = [];
|
||||
|
||||
for (const { name, command, isEnabled = true } of allCommands) {
|
||||
if (!isEnabled) {
|
||||
this.logger.log(`Skipping ${name} cron job (disabled by config)`);
|
||||
skipped.push(name);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const { name, command } of allCommands) {
|
||||
try {
|
||||
this.logger.log(`Registering ${name} cron job...`);
|
||||
await command.run();
|
||||
@@ -188,7 +203,7 @@ export class CronRegisterAllCommand extends CommandRunner {
|
||||
}
|
||||
|
||||
this.logger.log(
|
||||
`Cron job registration completed: ${successCount} successful, ${failureCount} failed`,
|
||||
`Cron job registration completed: ${successCount} successful, ${failureCount} failed, ${skipped.length} skipped`,
|
||||
);
|
||||
|
||||
if (failures.length > 0) {
|
||||
@@ -198,5 +213,9 @@ export class CronRegisterAllCommand extends CommandRunner {
|
||||
if (successCount > 0) {
|
||||
this.logger.log(`Successful commands: ${successes.join(', ')}`);
|
||||
}
|
||||
|
||||
if (skipped.length > 0) {
|
||||
this.logger.log(`Skipped commands: ${skipped.join(', ')}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user