Skip to content

feat(sse): manage KMS key lifecycle from the key list - #328

Merged
overtrue merged 1 commit into
rustfs:mainfrom
AndrewGanzha:feature/kms-key-lifecycle
Nov 30, 2026
Merged

overtrue merged 1 commit into
rustfs:mainfrom
AndrewGanzha:feature/kms-key-lifecycle

Conversation

@AndrewGanzha

Copy link
Copy Markdown
Contributor

Description

Part B1 of #320. The Console could create, inspect and delete KMS keys, but offered no way to enable, disable or rotate one, even though the server exposes all three endpoints. Key rows now offer them next to the existing deletion flow — as buttons on the mobile cards and as menu items in the desktop table.

Behaviour:

  • Wire contract (rustfs/rustfs, rustfs/src/admin/handlers/kms_key_lifecycle.rs): POST /kms/keys/{enable,disable,rotate} with { key_id }, returning { success, message, key_id, key_metadata }. hooks/use-sse.ts gains enableKey, disableKey, rotateKey; types/kms.ts gains the request/response types.
  • Permission recheck on confirm. Each action rechecks its own IAM action — kms:EnableKey, kms:DisableKey, kms:RotateKey — through the same confirmation dialog deletion already used, so a stale key list cannot mutate a key the caller may no longer be allowed to touch. The dialog's action and permission now come from one KEY_ACTION_PERMISSIONS map instead of hardcoding kms:DeleteKey.
  • The default SSE key guard stays where it belongs. Enable, disable and rotate are safe for the default key, so only deletion still compares the key against config_summary.default_key_id — previously any non-cancel action did.
  • Capability-aware. Enable/Disable are offered when capabilities.enable_disable is not false, Rotate when capabilities.rotate is not false. An absent capability matrix leaves all three available, because absence means "the server did not say", not "the backend refuses" — the same rule the page already follows for the rekey card.
  • State-aware. Enable appears for a key reported as Disabled, Disable for a usable key, and Rotate is hidden for keys pending deletion. Note the server's naming: the key listing calls a usable key Active, while lifecycle responses call the same state Enabled, so both are treated as enabled (rustfs/rustfs kms_key_lifecycle.rs returns key_state: "Enabled", GET /kms/keys returns status: "Active").
  • Strings for the new actions, dialog titles, descriptions and success messages are translated in all 15 locales; Enable/Disable reuse the existing translations.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test improvements
  • Security fix

Testing

  • Unit tests added/updated
  • Manual testing completed

Unit tests:

  • tests/hooks/use-sse.test.ts mounts the real useSSE hook with a stubbed API client and pins the exact endpoint and body of all three calls.
  • tests/lib/management-permission-controls.test.ts mounts the page and asserts: confirming Disable rechecks kms:DisableKey and calls the hook; confirming Enable rechecks kms:EnableKey and never kms:DeleteKey; capabilities {enable_disable: false, rotate: false} hide both actions; an absent matrix keeps them available; a key reported as Active offers Disable and not Enable; a key pending deletion is not offered Rotate.

Manual verification against a real server:

  • RustFS 1.0.x running with Local KMS: the listing reports Active, so Disable is offered; after disabling, the row reports Disabled and offers Enable. Local declares rotate: false, and Rotate is correctly absent from the menu.
  • RustFS with Vault Transit (rotate: true): the row offers View Details / Disable / Rotate. Confirming Rotate through the dialog rotated the key on the server — its version went from 1 to 2.
pnpm install --frozen-lockfile
pnpm type-check      # clean
pnpm lint            # clean
pnpm format:check    # clean
pnpm test:run        # 1329 tests, 0 failures

Checklist

  • Code follows the project's style guidelines
  • Self-review completed
  • TypeScript types are properly defined
  • All commit messages are in English (Conventional Commits)
  • All existing tests pass
  • No new dependencies added, or they are justified

Related Issues

Part of #320 (Part B, item 1 — key lifecycle). Backup/restore, key metadata and the remaining parity endpoints are still open.

Screenshots (if applicable)

Key list actions, 420 px mobile layout (the desktop table carries the same items in its Actions menu):

  1. Vault Transit backend — View Details / Disable / Rotate / Schedule Deletion.
  2. Local backend, usable key — Disable visible, Rotate absent because that backend reports rotate: false.
  3. Same key disabled — Enable replaces Disable.
  4. Rotate confirmation dialog.

Screenshots attached below.

Additional Notes

  • Rotate is only rendered where the backend supports it, so a reviewer testing against Local KMS will not see that action at all. That is the intended gating, not a missing wiring; Vault Transit and AWS report rotate: true.
  • A backend that rejects a lifecycle call anyway (for example a 501 when a capability was reported optimistically) surfaces the server's own message through the existing error path, and the dialog closes with the key list reloaded.
  • The two-stage deletion flow, its typed confirmation and the schedule/cancel/force-delete behaviour are untouched.

The Console could create, inspect and delete KMS keys but offered no way to
enable, disable or rotate one, even though the server exposes all three
endpoints (rustfs#320, Part B1). Key rows now offer them next to the
existing deletion flow, on both the mobile cards and the desktop menu.

Each action rechecks its own IAM action when confirmed (kms:EnableKey,
kms:DisableKey, kms:RotateKey) through the confirmation dialog deletion
already used, so a stale list cannot mutate a key the caller may not touch.
The recheck also keeps the default-SSE-key guard where it belongs: enable,
disable and rotate are safe for the default key, so only deletion compares
against it.

Visibility follows the server's capability matrix instead of assuming every
backend can do everything: Enable and Disable are offered when
`enable_disable` is not false and Rotate when `rotate` is not false, while an
absent matrix leaves them available because absence means the server did not
say, not that the backend refuses. Enable appears for a key the server
reports as Disabled, Disable for a usable key — the listing calls that
"Active" while lifecycle responses call it "Enabled", so both count — and
Rotate is hidden for keys pending deletion.

Wire contract: POST /kms/keys/{enable,disable,rotate} with `{ key_id }`,
per rustfs/rustfs `rustfs/src/admin/handlers/kms_key_lifecycle.rs`.
@AndrewGanzha

Copy link
Copy Markdown
Contributor Author
image image image

@overtrue overtrue left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on the KMS key lifecycle management changes.

Summary of Review

  1. Types & API Client (types/kms.ts, hooks/use-sse.ts):
    • KmsKeyLifecycleRequest, KmsKeyLifecycleResponse, and rotateKey / enableKey / disableKey follow the existing mutation patterns and endpoint conventions (/kms/keys/rotate, /kms/keys/enable, /kms/keys/disable).
  2. SSE Page Lifecycle Controls & Permissions (app/(dashboard)/sse/page.tsx):
    • KEY_ACTION_PERMISSIONS maps each confirmed action to its exact IAM permission (kms:EnableKey, kms:DisableKey, kms:RotateKey), and handleConfirmKeyAction rechecks the matching permission before calling the API.
    • Default-key deletion protection is properly scoped to scheduleDelete and forceDelete, leaving enable, disable, and rotate available for the default key.
    • getKeyLifecycleActions gates visibility on capabilities?.enable_disable !== false and capabilities?.rotate !== false (keeping omitted capability flags available) and handles both "Enabled" / "Active" and "Disabled" / "PendingDeletion" states.
    • Error paths (response.success === false and thrown errors) close the confirmation dialog and reconcile state without leaving stale locks.
    • Minor non-blocking note: rotate visibility checks !isKeyPendingDeletion(key.status) && !isKeyDisabled(key.status), which would also render Rotate for states such as "PendingImport" or "Unavailable" if a backend ever emits them, though handleConfirmKeyAction still surfaces backend rejections cleanly.
  3. i18n & Tests (i18n/locales/*.json, tests/hooks/use-sse.test.ts, tests/lib/management-permission-controls.test.ts):
    • All 14 locale files include consistent translations for the new UI strings.
    • Unit and permission-control tests directly cover endpoint payloads, permission rechecks, capability gating, "Active" status normalization, and hiding Rotate on PendingDeletion. All 10 CI checks are green.

@overtrue
overtrue merged commit 93dee66 into rustfs:main Nov 30, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants