Skip to content

fix: create a dedicated AWS-XKS user and grant permissions for him - #1107

Open
Manuthor wants to merge 9 commits into
developfrom
fix/xks_permissions
Open

fix: create a dedicated AWS-XKS user and grant permissions for him#1107
Manuthor wants to merge 9 commits into
developfrom
fix/xks_permissions

Conversation

@Manuthor

@Manuthor Manuthor commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Closes #1093

Note

Introduce reserved AWS_XKS_SERVICE_USER identity for XKS operations and grants

  • Adds a reserved KMS identity [aws-xks-service] used as a least-privilege delegate for all XKS encrypt, decrypt, metadata, and key-creation operations, replacing caller-ARN authorization
  • Keys remain owned by default_username; CreateKey grants the reserved identity exactly Encrypt, Decrypt, and GetAttributes, rejects non-XKS symmetric-key ID collisions, and is idempotent
  • Startup migration in start_kms_server.rs finds aws-xks-tagged legacy keys and grants the reserved identity its three permissions using each key's actual owner
  • All authentication middlewares (session, mTLS, JWT, SPIRE, OIDC, Auth Verifier) reject the reserved identity as an externally authenticated user; configuration validation fails when the reserved identity is set as default_username or a crypto-officer user
  • Behavioral Change: XKS operations no longer authorize using the awsPrincipalArn from request metadata; the ARN is now audit-only. Existing XKS keys created under a previous default_username receive the reserved-identity grants at next startup. The reserved identity string [aws-xks-service] is now prohibited in default_username and crypto_officer.users when XKS is enabled.

Macroscope summarized 38908c1.

@Manuthor
Manuthor force-pushed the fix/xks_permissions branch from a140315 to 12fd9fd Compare September 3, 2026 09:37
Comment thread crate/server/src/routes/aws_xks/README.md
Comment thread crate/server/src/routes/aws_xks/mod.rs
Comment thread crate/server/src/start_kms_server.rs
@Manuthor
Manuthor force-pushed the fix/xks_permissions branch from 12fd9fd to fcc7978 Compare September 3, 2026 09:56
Comment thread crate/server/src/routes/aws_xks/mod.rs
Comment thread crate/server/src/routes/aws_xks/mod.rs
Manuthor added a commit that referenced this pull request Sep 3, 2026
…WS XKS authorization

Addresses 5 review findings on PR #1107 (also confirmed independently by
/threat-model analysis), all rooted in the fact that nothing enforced the
invariant that AWS_XKS_SERVICE_USER cannot collide with, or be granted
through, any other reachable identity/configuration:

1. CreateKey idempotent-collision path only checked object_type ==
   SymmetricKey before granting AWS_XKS_SERVICE_USER Encrypt/Decrypt/
   GetAttributes, letting a signed XKS CreateKey request adopt an
   arbitrary pre-existing non-XKS symmetric key. Now also requires the
   aws-xks tag; otherwise fails closed. (CWE-863/CWE-284)

2. Externally-derived identities (OIDC JWT email/sub, Auth Verifier JWT,
   mTLS certificate CN, SPIRE SVID, UI session/OIDC login) were never
   checked against the reserved AWS_XKS_SERVICE_USER string, so a
   client-controlled identity equal to "[aws-xks-service]" could
   authenticate as the XKS delegate on the normal KMIP/REST surface.
   Added a single `reject_reserved_aws_xks_identity` guard invoked at
   every such construction site. (CWE-290)

3. `crypto_officer.users` containing AWS_XKS_SERVICE_USER would grant it
   full Crypto Officer rights, defeating the least-privilege design.
   Server startup now rejects this configuration when AWS XKS is
   enabled. (CWE-269)

4. `default_username == AWS_XKS_SERVICE_USER` made every CreateKey fail
   permanently (self-grant rejected by grant_access). Server startup now
   rejects this configuration when AWS XKS is enabled. (CWE-20)

5. The startup migration for legacy aws-xks keys only granted access on
   behalf of the *current* default_username, silently stranding keys
   created under a previously-configured default_username after a
   rotation. The migration now resolves and grants on behalf of each
   key's actual persisted owner. (CWE-284)

All changes verified: `cargo build -p cosmian_kms_server`, full
`cargo test -p cosmian_kms_server --lib` (397 passed, 0 failed), and
`cargo clippy -p cosmian_kms_server --all-targets --all-features -- -D
warnings` (zero warnings).
Comment thread crate/server/src/start_kms_server.rs Outdated
Manuthor added a commit that referenced this pull request Sep 3, 2026
…ration

Previously, if retrieve_object() failed for a tagged aws-xks key during
migrate_aws_xks_key_access, the error was logged and the key was skipped,
allowing server startup to succeed while that key remained unusable
through XKS (missing the AWS_XKS_SERVICE_USER grant) until a later
successful migration attempt.

Propagate the error via '?' so startup fails fast on a database read
failure instead of silently completing an incomplete migration.

Addresses PR review comment (macroscopeapp) on commit 64b5699:
#1107 (comment)
Manuthor added a commit that referenced this pull request Sep 3, 2026
…WS XKS authorization

Addresses 5 review findings on PR #1107 (also confirmed independently by
/threat-model analysis), all rooted in the fact that nothing enforced the
invariant that AWS_XKS_SERVICE_USER cannot collide with, or be granted
through, any other reachable identity/configuration:

1. CreateKey idempotent-collision path only checked object_type ==
   SymmetricKey before granting AWS_XKS_SERVICE_USER Encrypt/Decrypt/
   GetAttributes, letting a signed XKS CreateKey request adopt an
   arbitrary pre-existing non-XKS symmetric key. Now also requires the
   aws-xks tag; otherwise fails closed. (CWE-863/CWE-284)

2. Externally-derived identities (OIDC JWT email/sub, Auth Verifier JWT,
   mTLS certificate CN, SPIRE SVID, UI session/OIDC login) were never
   checked against the reserved AWS_XKS_SERVICE_USER string, so a
   client-controlled identity equal to "[aws-xks-service]" could
   authenticate as the XKS delegate on the normal KMIP/REST surface.
   Added a single `reject_reserved_aws_xks_identity` guard invoked at
   every such construction site. (CWE-290)

3. `crypto_officer.users` containing AWS_XKS_SERVICE_USER would grant it
   full Crypto Officer rights, defeating the least-privilege design.
   Server startup now rejects this configuration when AWS XKS is
   enabled. (CWE-269)

4. `default_username == AWS_XKS_SERVICE_USER` made every CreateKey fail
   permanently (self-grant rejected by grant_access). Server startup now
   rejects this configuration when AWS XKS is enabled. (CWE-20)

5. The startup migration for legacy aws-xks keys only granted access on
   behalf of the *current* default_username, silently stranding keys
   created under a previously-configured default_username after a
   rotation. The migration now resolves and grants on behalf of each
   key's actual persisted owner. (CWE-284)

All changes verified: `cargo build -p cosmian_kms_server`, full
`cargo test -p cosmian_kms_server --lib` (397 passed, 0 failed), and
`cargo clippy -p cosmian_kms_server --all-targets --all-features -- -D
warnings` (zero warnings).
Manuthor added a commit that referenced this pull request Sep 3, 2026
…ration

Previously, if retrieve_object() failed for a tagged aws-xks key during
migrate_aws_xks_key_access, the error was logged and the key was skipped,
allowing server startup to succeed while that key remained unusable
through XKS (missing the AWS_XKS_SERVICE_USER grant) until a later
successful migration attempt.

Propagate the error via '?' so startup fails fast on a database read
failure instead of silently completing an incomplete migration.

Addresses PR review comment (macroscopeapp) on commit 64b5699:
#1107 (comment)
@Manuthor
Manuthor force-pushed the fix/xks_permissions branch from 8cd2ea3 to 943a224 Compare September 3, 2026 15:19
Manuthor added a commit that referenced this pull request Sep 3, 2026
…WS XKS authorization

Addresses 5 review findings on PR #1107 (also confirmed independently by
/threat-model analysis), all rooted in the fact that nothing enforced the
invariant that AWS_XKS_SERVICE_USER cannot collide with, or be granted
through, any other reachable identity/configuration:

1. CreateKey idempotent-collision path only checked object_type ==
   SymmetricKey before granting AWS_XKS_SERVICE_USER Encrypt/Decrypt/
   GetAttributes, letting a signed XKS CreateKey request adopt an
   arbitrary pre-existing non-XKS symmetric key. Now also requires the
   aws-xks tag; otherwise fails closed. (CWE-863/CWE-284)

2. Externally-derived identities (OIDC JWT email/sub, Auth Verifier JWT,
   mTLS certificate CN, SPIRE SVID, UI session/OIDC login) were never
   checked against the reserved AWS_XKS_SERVICE_USER string, so a
   client-controlled identity equal to "[aws-xks-service]" could
   authenticate as the XKS delegate on the normal KMIP/REST surface.
   Added a single `reject_reserved_aws_xks_identity` guard invoked at
   every such construction site. (CWE-290)

3. `crypto_officer.users` containing AWS_XKS_SERVICE_USER would grant it
   full Crypto Officer rights, defeating the least-privilege design.
   Server startup now rejects this configuration when AWS XKS is
   enabled. (CWE-269)

4. `default_username == AWS_XKS_SERVICE_USER` made every CreateKey fail
   permanently (self-grant rejected by grant_access). Server startup now
   rejects this configuration when AWS XKS is enabled. (CWE-20)

5. The startup migration for legacy aws-xks keys only granted access on
   behalf of the *current* default_username, silently stranding keys
   created under a previously-configured default_username after a
   rotation. The migration now resolves and grants on behalf of each
   key's actual persisted owner. (CWE-284)

All changes verified: `cargo build -p cosmian_kms_server`, full
`cargo test -p cosmian_kms_server --lib` (397 passed, 0 failed), and
`cargo clippy -p cosmian_kms_server --all-targets --all-features -- -D
warnings` (zero warnings).
Manuthor added a commit that referenced this pull request Sep 3, 2026
…ration

Previously, if retrieve_object() failed for a tagged aws-xks key during
migrate_aws_xks_key_access, the error was logged and the key was skipped,
allowing server startup to succeed while that key remained unusable
through XKS (missing the AWS_XKS_SERVICE_USER grant) until a later
successful migration attempt.

Propagate the error via '?' so startup fails fast on a database read
failure instead of silently completing an incomplete migration.

Addresses PR review comment (macroscopeapp) on commit 64b5699:
#1107 (comment)
@Manuthor
Manuthor force-pushed the fix/xks_permissions branch from 943a224 to 7cb4fd0 Compare September 3, 2026 20:41
Comment thread crate/server/src/routes/ui_auth.rs Outdated
Manuthor added a commit that referenced this pull request Sep 4, 2026
…WS XKS authorization

Addresses 5 review findings on PR #1107 (also confirmed independently by
/threat-model analysis), all rooted in the fact that nothing enforced the
invariant that AWS_XKS_SERVICE_USER cannot collide with, or be granted
through, any other reachable identity/configuration:

1. CreateKey idempotent-collision path only checked object_type ==
   SymmetricKey before granting AWS_XKS_SERVICE_USER Encrypt/Decrypt/
   GetAttributes, letting a signed XKS CreateKey request adopt an
   arbitrary pre-existing non-XKS symmetric key. Now also requires the
   aws-xks tag; otherwise fails closed. (CWE-863/CWE-284)

2. Externally-derived identities (OIDC JWT email/sub, Auth Verifier JWT,
   mTLS certificate CN, SPIRE SVID, UI session/OIDC login) were never
   checked against the reserved AWS_XKS_SERVICE_USER string, so a
   client-controlled identity equal to "[aws-xks-service]" could
   authenticate as the XKS delegate on the normal KMIP/REST surface.
   Added a single `reject_reserved_aws_xks_identity` guard invoked at
   every such construction site. (CWE-290)

3. `crypto_officer.users` containing AWS_XKS_SERVICE_USER would grant it
   full Crypto Officer rights, defeating the least-privilege design.
   Server startup now rejects this configuration when AWS XKS is
   enabled. (CWE-269)

4. `default_username == AWS_XKS_SERVICE_USER` made every CreateKey fail
   permanently (self-grant rejected by grant_access). Server startup now
   rejects this configuration when AWS XKS is enabled. (CWE-20)

5. The startup migration for legacy aws-xks keys only granted access on
   behalf of the *current* default_username, silently stranding keys
   created under a previously-configured default_username after a
   rotation. The migration now resolves and grants on behalf of each
   key's actual persisted owner. (CWE-284)

All changes verified: `cargo build -p cosmian_kms_server`, full
`cargo test -p cosmian_kms_server --lib` (397 passed, 0 failed), and
`cargo clippy -p cosmian_kms_server --all-targets --all-features -- -D
warnings` (zero warnings).
Manuthor added a commit that referenced this pull request Sep 4, 2026
…ration

Previously, if retrieve_object() failed for a tagged aws-xks key during
migrate_aws_xks_key_access, the error was logged and the key was skipped,
allowing server startup to succeed while that key remained unusable
through XKS (missing the AWS_XKS_SERVICE_USER grant) until a later
successful migration attempt.

Propagate the error via '?' so startup fails fast on a database read
failure instead of silently completing an incomplete migration.

Addresses PR review comment (macroscopeapp) on commit 64b5699:
#1107 (comment)
@Manuthor
Manuthor force-pushed the fix/xks_permissions branch from b7ed3e7 to e747f3b Compare September 4, 2026 04:58
…WS XKS authorization

Addresses 5 review findings on PR #1107 (also confirmed independently by
/threat-model analysis), all rooted in the fact that nothing enforced the
invariant that AWS_XKS_SERVICE_USER cannot collide with, or be granted
through, any other reachable identity/configuration:

1. CreateKey idempotent-collision path only checked object_type ==
   SymmetricKey before granting AWS_XKS_SERVICE_USER Encrypt/Decrypt/
   GetAttributes, letting a signed XKS CreateKey request adopt an
   arbitrary pre-existing non-XKS symmetric key. Now also requires the
   aws-xks tag; otherwise fails closed. (CWE-863/CWE-284)

2. Externally-derived identities (OIDC JWT email/sub, Auth Verifier JWT,
   mTLS certificate CN, SPIRE SVID, UI session/OIDC login) were never
   checked against the reserved AWS_XKS_SERVICE_USER string, so a
   client-controlled identity equal to "[aws-xks-service]" could
   authenticate as the XKS delegate on the normal KMIP/REST surface.
   Added a single `reject_reserved_aws_xks_identity` guard invoked at
   every such construction site. (CWE-290)

3. `crypto_officer.users` containing AWS_XKS_SERVICE_USER would grant it
   full Crypto Officer rights, defeating the least-privilege design.
   Server startup now rejects this configuration when AWS XKS is
   enabled. (CWE-269)

4. `default_username == AWS_XKS_SERVICE_USER` made every CreateKey fail
   permanently (self-grant rejected by grant_access). Server startup now
   rejects this configuration when AWS XKS is enabled. (CWE-20)

5. The startup migration for legacy aws-xks keys only granted access on
   behalf of the *current* default_username, silently stranding keys
   created under a previously-configured default_username after a
   rotation. The migration now resolves and grants on behalf of each
   key's actual persisted owner. (CWE-284)

All changes verified: `cargo build -p cosmian_kms_server`, full
`cargo test -p cosmian_kms_server --lib` (397 passed, 0 failed), and
`cargo clippy -p cosmian_kms_server --all-targets --all-features -- -D
warnings` (zero warnings).
…ration

Previously, if retrieve_object() failed for a tagged aws-xks key during
migrate_aws_xks_key_access, the error was logged and the key was skipped,
allowing server startup to succeed while that key remained unusable
through XKS (missing the AWS_XKS_SERVICE_USER grant) until a later
successful migration attempt.

Propagate the error via '?' so startup fails fast on a database read
failure instead of silently completing an incomplete migration.

Addresses PR review comment (macroscopeapp) on commit 64b5699:
#1107 (comment)
GET /ocsp/{encoded_request} decoded the base64url path segment with the
padded URL_SAFE engine, which rejects any input missing '=' padding.
RFC 6960 Appendix A does not mandate padding, and several real clients
(including openssl ocsp, used by this project's own black-box OCSP
test suite) emit unpadded base64url, so well-formed GET requests were
being rejected with a spurious 422 instead of returning the expected
signed OCSP response.

Switch to a custom base64 engine with DecodePaddingMode::Indifferent,
which accepts both padded and unpadded input on decode.

Also reorders an import in crate/crypto/src/openssl/ocsp.rs to satisfy
nightly rustfmt (pre-existing drift, unrelated to the fix above but
required by the pre-commit hook to land it).
eviden.com (Proteccio HSM vendor page) currently returns 503 Service
Unavailable to automated crawlers, blocking the lychee pre-commit hook
for every commit — including ones that never touch documentation.
Excluded following the same precedent already used for other sites
that return 5xx to bots (docs.fortinet.com, www.ibm.com, etc.).
@Manuthor
Manuthor force-pushed the fix/xks_permissions branch from a4583bc to bb8dab8 Compare September 4, 2026 14:13
let xks_service_user = UserId::from(AWS_XKS_SERVICE_USER);
let granted = kms_server
.database
.list_user_operations_on_object(&uid, &xks_service_user, false)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High src/start_kms_server.rs:286

The migration can skip the durable [aws-xks-service] grant and leave XKS operations dependent on a wildcard grant. Because false includes inherited permissions in granted, a key with all three operations granted to * is treated as migrated; revoking that wildcard grant then breaks XKS access. Query direct permissions with no_inherited_access = true so the explicit service grant is created.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @crate/server/src/start_kms_server.rs around line 286:

The migration can skip the durable `[aws-xks-service]` grant and leave XKS operations dependent on a wildcard grant. Because `false` includes inherited permissions in `granted`, a key with all three operations granted to `*` is treated as migrated; revoking that wildcard grant then breaks XKS access. Query direct permissions with `no_inherited_access = true` so the explicit service grant is created.

validate_aws_xks_reserved_identity_config(&kms_server.params)?;
// Grant the reserved XKS service identity usage on XKS keys created by earlier
// versions. See `migrate_aws_xks_key_access`.
migrate_aws_xks_key_access(&kms_server).await?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium src/start_kms_server.rs:1100

prepare_kms_server blocks HTTP server construction and binding until migrate_aws_xks_key_access finishes. Because the migration has no durable completion marker and scans every tagged key serially on each restart, installations with many XKS keys incur an unbounded repeated startup delay; move it to a bounded/background migration or persist completion state.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @crate/server/src/start_kms_server.rs around line 1100:

`prepare_kms_server` blocks HTTP server construction and binding until `migrate_aws_xks_key_access` finishes. Because the migration has no durable completion marker and scans every tagged key serially on each restart, installations with many XKS keys incur an unbounded repeated startup delay; move it to a bounded/background migration or persist completion state.

Unit tests added for UserId::try_new use assert!(...is_err()) and
.expect() on Result, which are idiomatic in test code but denied
workspace-wide (clippy::expect_used, clippy::assertions_on_result_states).
Allow both on the test module, following the existing precedent in
crate/interfaces/src/object_handle.rs.
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.

XKS Proxy ACL Limits Key Usage to Creator

1 participant