Removes the API_KEYS_ENABLED kill-switch entirely and makes api-keys copyable via
a deterministic re-mint revealed under a password step-up (#557, epic #556).
Part 1 — remove the kill-switch (keys are now always on):
- environment.service.ts: delete isApiKeysEnabled()/getApiKeysEnabledRaw().
- environment.validation.ts: delete the API_KEYS_ENABLED field + decorators
(validation has no forbidNonWhitelisted, so a stray env value is ignored).
- api-key.service.ts: drop OnModuleInit boot-log, the validate kill-switch branch,
and the now-unused EnvironmentService injection.
- api-key.controller.ts: drop assertEnabled() + its call sites and the
EnvironmentService injection.
- .env.example: delete the API_KEYS_ENABLED block.
Part 2 — deterministic mint: apiKeyJwtService gets noTimestamp:true, so the
api-key token carries neither exp nor iat and re-minting the same key is
byte-identical (basis of copyable reveal).
Part 3 — POST /api-keys/reveal { id, password }: JwtAuthGuard +
rejectApiKeyPrincipal (403) + AUTH throttler; step-up via
AuthService.verifyUserCredentials BEFORE any key lookup (401, no oracle);
owner-only even for admin; uniform 404 for absent/revoked/expired/other-owner/
disabled-creator (ForbiddenException from generateApiToken normalized to 404);
re-mint via the existing deterministic path; token never persisted; durable
AuditEvent.API_KEY_REVEALED + structured log without token material.
Part 4 — UI: replace the show-once modal with a per-row Copy action -> password
prompt -> reveal -> clipboard write + toast. The token never enters React state,
localStorage or the query cache (gcTime:0 + reset-after-read, mirroring #506).
i18n en+ru added; immediate-revoke behavior kept.
Tests: server api-key + token.service specs (reveal, deterministic no-exp/no-iat,
byte-identical, kill-switch-removal) and client api-key vitest (copy flow, no-leak,
wrong-password) all green. Mutation-verified: skipping the owner check reds the
non-owner-404 test, skipping step-up reds the wrong-password test, dropping
noTimestamp reds the deterministic/no-iat tests.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Форк не несёт EE-модуль ee/api-key, поэтому api_key-токен сегодня отвергается на
любом /api/*. Вводим core-модуль:
- ApiKeyRepo (kysely): insert/findById/findByCreator/findAllInWorkspace/
softDelete/touchLastUsed, фильтр deleted_at IS NULL.
- ApiKeyService.create — mint-then-insert: сперва uuid7 id, затем чеканка JWT
без exp, затем строка (сбой чеканки → строки нет; потерянный ответ →
осиротевшая строка видна в list и самолечится). Токен отдаётся один раз, в
таблице не хранится.
- ApiKeyService.validate — единый валидатор для jwt.strategy И /mcp. Владелец
истины о сроке/отзыве — строка api_keys, не JWT. Любой определённый негатив
(нет строки / expired / disabled / workspace mismatch / kill-switch off) →
единый bare-401 (анти-enumeration); инфра-ошибка пробрасывается (→5xx), не
маскируется. Без кэша — немедленная ревокация. last_used_at троттлится 1ч,
fire-and-forget.
- REST create/list/revoke: create — self + UserThrottlerGuard; list/revoke —
admin (CASL Manage на API) видит/отзывает все ключи воркспейса, член — только
свои. api_key-принципал отвергается на всех трёх (токен не управляет
токенами — GitHub-PAT-семантика). Аудит API_KEY_CREATED/DELETED + структурный
лог с apiKeyId и IP.
- jwt.strategy: прямой вызов ApiKeyService.validate вместо динамического
EE-require; штампует req.raw.authType='api_key' и apiKeyId для гварда выше.
- Kill-switch API_KEYS_ENABLED: дефолт ON (деплой без переменной не убивает
агентов), строгий парс @IsIn(['true','false']) (=0/=off падают на boot, а не
молча значат «включено»), boot-лог состояния. off → validate deny и
эндпоинты 404.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>