Skip to content

feat(kms): audit refused key requests and env public key requests - #1583

Merged
kvinwang merged 1 commit into
nextfrom
feat/kms-audit-denied-keys
Nov 15, 2026
Merged

kvinwang merged 1 commit into
nextfrom
feat/kms-audit-denied-keys

Conversation

@kvinwang

@kvinwang kvinwang commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

The KMS audited only released keys (key release on dstack_kms::audit). A refused request appeared as a bare rpc error line without the app that made it, and the env public key RPCs were not audited at all.

  • GetAppKey, SignCert and GetKmsKey (RPC and admin): a refusal is logged as key release denied with listener, operation, app_id, instance_id, remote and error, once the caller's attestation identifies it. Refusals before that (no attestation, an undecodable request, this KMS failing its own self check) have no app to name and keep only the rpc error log.
  • GetAppEnvEncryptPubKey and GetSealedEnvPubKey: every request is logged, as env public key served or env public key refused (with error), with operation, app_id and remote. The app ID length is now checked before the KMS self check, so a malformed one is rejected, unlogged, with app_id must be 20 bytes even when the self check would also fail.

Refactor: ensure_app_boot_allowed is inlined and ensure_kms_allowed takes the boot info, so the caller holds it for the log. Behavior is otherwise unchanged; the diff is mostly re-indentation (best viewed with whitespace hidden).

Testing

cargo test -p dstack-kms --all-features passes (95 tests), as do clippy with the CI flags and cargo fmt --check. With a log subscriber temporarily added to the existing denial tests, each refusal path emits the new line, for example:

WARN dstack_kms::audit: key release denied listener="rpc" operation="app_get_key" app_id=1111…1111 instance_id=9999…9999 remote=None error=App not allowed: Authorization denied: denied
WARN dstack_kms::audit: key release denied listener="admin" operation="kms_export_keys" app_id=1111…1111 instance_id=9999…9999 remote=None error=amd sev-snp key release is not enabled
WARN dstack_kms::audit: key release denied listener="rpc" operation="app_get_cert" app_id=2222…2222 instance_id=UNKNOWN remote=None error=Authorization denied: denied
INFO dstack_kms::audit: env public key served operation="app_sealed_env_pubkey" app_id=1111…1111 remote=None
WARN dstack_kms::audit: env public key refused operation="app_env_encrypt_pubkey" app_id=1111…1111 remote=None error=epoch-aware applications must use GetSealedEnvPubKey

remote=None because the unit tests call the handler directly; over a real listener it carries the client address.

Verified on TDX

Run on the tdxlab TDX host with real TDX CVMs (guest OS dstack 0.6.0), from one local build of #1580, #1582, #1585 and #1587 merged with #1583 and #1588: the official 0.6.3 KMS and gateway images with these binaries (and the gateway's new entrypoint.sh). The KMS ran in a CVM with a local key provider and a webhook auth backend (allow all but one app; this KMS's root epoch 0 registered); haproxy with send-proxy-v2 fronted the guest listeners of the KMS and the gateway.

  • An app the webhook denies got App not allowed: Authorization denied: denied by the test webhook; the KMS logged key release denied with its app_id, instance_id, remote and the error.
  • An allowed app's GetAppKey and SignCert logged key release as before; vmm-cli's env encryption logged env public key served with the app id.

Only released keys were audited, so a request the KMS refused showed up
as a bare rpc error without the app that made it.

Log a refused GetAppKey, SignCert or GetKmsKey to dstack_kms::audit with
the caller's app and instance IDs, remote and error, once its attestation
identifies it; refusals before that have no app to name. Also audit every
GetAppEnvEncryptPubKey and GetSealedEnvPubKey request with its app ID,
which is checked for length first so a bogus one is not logged.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang merged commit d1058c7 into next Nov 15, 2026
18 checks passed
@kvinwang
kvinwang deleted the feat/kms-audit-denied-keys branch November 15, 2026 05:53
kvinwang added a commit that referenced this pull request Nov 16, 2026
tc-kms-kms-007 runs a second candidate KMS with the fixture's keys, the
public listener enabled and proxy_protocol on by default but off on the
admin listener. It checks which listener serves which RPC, that the
PROXY source is the remote in request and audit lines (#1583), and that
the old listener locations are refused.

Signed-off-by: Kevin Wang <wy721@qq.com>
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.

1 participant