Skip to content

feat(xtest): cover KAO URI lookup with isolated KM3 - #605

Merged
c-r33d merged 5 commits into
mainfrom
test/kas-uri-from-kao
Sep 17, 2026
Merged

c-r33d merged 5 commits into
mainfrom
test/kas-uri-from-kao

Conversation

@c-r33d

@c-r33d c-r33d commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Add a round-trip test for KAO-based key lookup using a dedicated KM3 with kas_uri_from_kao enabled. Run it with force-platform-supports: kas_uri_from_kao.

Stacked on #604. Uses the action input from opentdf/platform#4057 and covers platform stack opentdf/platform#3951opentdf/platform#4048opentdf/platform#4053opentdf/platform#4056.

Validation: unit, fixture, workflow, lint, and type checks passed. Live round-trip not yet run.

Summary by CodeRabbit

  • New Features

    • Added support for a dedicated third key management service in multi-KAS testing.
    • Extended audit log collection to include the third service.
    • Added validation for retrieving registered keys and handling missing key identifiers.
  • Bug Fixes

    • Improved KAO-enabled key management test execution based on detected platform support.
    • Enhanced verification of alternate key registrations, decryption, and rewrap audit events.

Signed-off-by: Chris Reed <creed@virtru.com>
Signed-off-by: Chris Reed <creed@virtru.com>
@c-r33d
c-r33d requested review from a team as code owners September 16, 2026 13:58
@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 54890b23-e994-4060-9013-f11892519441

📥 Commits

Reviewing files that changed from the base of the PR and between 868014b and 21438e0.

📒 Files selected for processing (4)
  • .github/workflows/xtest.yml
  • xtest/fixtures/kas.py
  • xtest/otdfctl.py
  • xtest/test_abac.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The changes add platform-level feature overrides, update CI to start the dedicated km3 KAS from multikas support, extend km3 fixtures and audit mappings, add registry key lookup, and strengthen alternate KAS decryption assertions.

Changes

Platform-forced KAO testing

Layer / File(s) Summary
Platform feature override
`.xtest/tdfs.py
kas_uri_from_kao is added to platform features. Forced platform supports are parsed separately and merged into PlatformFeatureSet.features.
CI KAO-enabled KAS wiring
.``.github/workflows/xtest.yml``, xtest/fixtures/kas.py, xtest/fixtures/audit.py``
The workflow starts km3 when multikas is supported and passes detected key-management support. km3 URL, registry, log, and audit mappings are added.
Alternate KAS URI decryption validation
.``xtest/otdfctl.py``, xtest/test_abac.py``
Registry key lookup now distinguishes missing keys from command failures. ABAC tests verify the alternate key URI, key ID, plaintext round trip, and rewrap audit event.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Other

Sequence Diagram(s)

sequenceDiagram
  participant GitHubActions
  participant km3KAS
  participant KASFixtures
  participant ABACTest
  participant AuditLogs
  GitHubActions->>km3KAS: start when multikas is supported
  KASFixtures->>km3KAS: create or fetch the km3 registry entry
  ABACTest->>km3KAS: create alternate KAS registration
  ABACTest->>AuditLogs: verify key access and rewrap events
Loading

Suggested reviewers: dmihalcik-virtru

Merge Risk: ⚪ Minimal · up to 21438

No actionable merge-blocking issue remains from the reviewed changes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 6 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding KAO URI lookup coverage with an isolated KM3 key management service.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 6 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit watched km3 wake,
With keys and logs in every flake.
The KAO path now hops along,
Audit trails record the song.
Alternate keys decrypt just right.

Comment @coderabbitai help to get the list of available commands.

c-r33d added a commit that referenced this pull request Sep 16, 2026
Add `force-platform-supports` / `XT_FORCE_PLATFORM_SUPPORTS` so tests
can exercise unreleased platform features. SDK overrides remain
separate.

Base PR for #605; merge this first.

Validation: 29 unit tests, lint, formatting, type checks, and workflow
checks passed.

Signed-off-by: Chris Reed <creed@virtru.com>
Base automatically changed from codex/platform-force-features to main September 16, 2026 15:15
@c-r33d c-r33d changed the title test(xtest): cover KAO URI lookup with isolated KM3 feat(xtest): cover KAO URI lookup with isolated KM3 Sep 16, 2026

@dmihalcik-virtru dmihalcik-virtru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed this across code quality, test coverage, comments, and silent failures. ruff check, ruff format --check, and pyright all pass in xtest/; fixture scopes are legal; and filecmp.cmp(..., shallow=False) is stricter than every neighbour in the file. Nice.

Two test-design questions inline below — both about whether a green run actually means anything. They're yours to call, so I'm raising rather than pushing.

I'm also opening a stacked PR against this branch with the mechanical fixes (km3 reachability probe so a missing km3 skips instead of dying inside an SDK CLI; km3 in otdf-local so there's a local repro path; an audit assertion so the km3 audit plumbing this PR adds is actually load-bearing; and comment/doc fixes).

Three things I checked that turned out fine — no action needed:

  • Adding kas-km3 to the default audit service list is inert. fixtures/audit.py:163-166 guards with if log_path:, so the workflow's || '' is correctly ignored; the ../platform/logs/ fallback only runs when no env var is set and checks log_file.exists(); and the loud FileNotFoundError fires only on a wholly empty dict. Your KAS_KM3_LOG_FILE expression is in fact more careful than the pre-existing km1/km2 lines, which degrade to the bare directory string "../../" when their step is skipped. Worth back-porting your guard to those.
  • The km3 action pin is safe. d16f6d0 is 138 commits ahead of the siblings' 6dd5f64 and 0 behind, so it contains the require_nonce startup-YAML fix. The only thing I'd add is an exit condition on the comment so the divergent pin doesn't quietly outlive its reason.
  • services.kas.kas_uri_from_kao is the right key. Confirmed at test/start-additional-kas/action.yaml:212 in opentdf/platform#4057. That action also sets registered_kas_uri = "http://localhost:" + KAS_PORT, i.e. no /kas suffix — which is exactly what makes this test's premise sound.

Comment thread xtest/test_abac.py Outdated
assert key.kas_uri == alternate_kas.uri != kas_entry_km3.uri
assert key.key.key_id not in {
k.key.key_id for k in otdfctl.kas_registry_keys_list(kas_entry_km3)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This assertion can pass vacuously, which matters more than its size suggests — it is the premise that makes the whole test discriminating.

kas_registry_keys_list (xtest/otdfctl.py:191-195) returns [] in two non-obvious cases: when the CLI exits non-zero with not found in stderr, and when output is empty or null. So a misdirected or broken list call yields an empty set and this passes without having checked anything. It's also near-tautological even when it works — km3-alternate-uri-<sha256[:8]> is freshly minted and unique, so it was never going to collide with km3's key list.

If this one passes for the wrong reason, the green decrypt below proves nothing.

Suggest pairing it with a positive check (which proves the list call works at all) and asserting the stronger invariant:

assert key.key.key_id in {
    k.key.key_id for k in otdfctl.kas_registry_keys_list(alternate_kas)
}
assert otdfctl.kas_registry_keys_list(kas_entry_km3) == []

The second line says the real thing: km3's own registration holds no keys, so a URI-based lookup must miss.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a GetKey check to ensure that the kas registry does not have the same KID as the one being asked for, ensuring that a rewrap failure would occur if the KAS is incorrectly configured.

Comment thread xtest/test_abac.py
elizabethhealy
elizabethhealy previously approved these changes Sep 17, 2026
@sonarqubecloud

Copy link
Copy Markdown

@c-r33d
c-r33d merged commit 18f67c6 into main Sep 17, 2026
30 checks passed
@c-r33d
c-r33d deleted the test/kas-uri-from-kao branch September 17, 2026 18:03
dmihalcik-virtru added a commit that referenced this pull request Sep 18, 2026
Rebased onto main after #605 and #606 landed; the findings those PRs
already addressed are dropped.

- Skip the km3 tests when no km3 is listening, instead of failing with
  connection-refused inside an SDK CLI. The feature gate answers "is the
  override set?", not "does a km3 exist?".
- Add kas-km3 (8787) to otdf-local, with the kas_uri_from_kao setting, the
  5-minute key cache and debug logging its CI step uses, so all three km3
  tests are runnable locally.
- Document that kas_uri_from_kao is forced via XT_FORCE_PLATFORM_SUPPORTS
  (not XT_FORCE_SUPPORTS) and that km3 starts on the PR gate and nightlies
  while every test behind the gate skips.
- Give the divergent km3 action pin an exit condition.
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.

3 participants