Skip to content

fix(kas): accept spec-compliant policy bindings - #4223

Merged
pflynn-virtru merged 1 commit into
mainfrom
fix/policy-binding-backcompat
Oct 15, 2026
Merged

pflynn-virtru merged 1 commit into
mainfrom
fix/policy-binding-backcompat

Conversation

@pflynn-virtru

@pflynn-virtru pflynn-virtru commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

KAS now accepts both Base64(HMAC) (spec) and legacy Base64(hex(HMAC)). Service-only; no output changes.

Fixes the raw-binding path broken since #2095, which compared an untrimmed 33-byte buffer against the 32-byte HMAC, so no released KAS accepted the spec form.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Corrected handling of policy-binding hashes in both standard and legacy formats, reducing errors when validating rewrap requests.
    • Malformed policy-binding values now receive a clear bad-request response, while processing continues for other requests.

The spec defines the policy binding as Base64(HMAC), but no released KAS
can decode that form. #2095 added a dual-accept branch and it has never
worked: base64.DecodedLen over-allocates, so a 44-character binding
decodes 32 bytes into a 33-byte buffer. Only the hex branch replaced that
buffer with a right-sized slice; the raw branch passed the untrimmed 33
bytes to VerifyBinding, which compares with hmac.Equal -- length
sensitive, so it always failed.

Extract decodePolicyBinding, trimmed to the bytes actually decoded, and
use it on the rewrap path. Legacy hex stays accepted indefinitely; TDFs
are archival.

This only widens what KAS accepts and changes no output, so it is safe to
deploy on its own. It is a prerequisite for fixing the SDK writer, which
is deliberately left for a follow-up: nothing may emit raw bindings until
a KAS that can read them is deployed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Paul Flynn <pflynn-virtru@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: e42866c9-4010-45f3-b9df-3833c02ca52f
📥 Commits

Reviewing files that changed from the base of the PR and between beba549 and cae7caa.

📒 Files selected for processing: 2
  • service/kas/access/rewrap.go
  • service/kas/access/rewrap_test.go

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

📝 Walkthrough

The change adds a policy-binding decoder that supports raw HMAC bytes and legacy hexadecimal values. Rewrap verification uses the decoder and records a per-KAO bad request error when decoding fails. Tests cover both encodings, invalid Base64, and decoded output length.

Changes: Policy-binding decoding

Layer / File(s) Summary
Decode and verify policy bindings
service/kas/access/rewrap.go, service/kas/access/rewrap_test.go
A new helper decodes Base64 policy bindings and decodes 64-byte results as hexadecimal when valid. Rewrap verification records a per-KAO bad request error on decode failure and continues processing. Tests cover raw HMAC bytes, legacy hexadecimal values, invalid Base64, and exact decoded length.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: dmihalcik-virtru

Merge Risk: ⚪ Minimal · up to cae7c

The supported binding formats and reported regression are covered; no identified issue prevents merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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: KAS now accepts spec-compliant policy bindings while preserving legacy support.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 checks each encoded byte,
Raw HMACs decode just right.
Old hex paths still pass the test,
Bad input gets a clear request.
Then onward hops each KAO,
While carrots wait below.

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

@github-actions github-actions Bot added comp:sdk A software development kit, including library, for client applications and inter-service communicati comp:kas Key Access Server size/m labels Oct 14, 2026
@pflynn-virtru
pflynn-virtru force-pushed the fix/policy-binding-backcompat branch from d73c7fa to cae7caa Compare October 14, 2026 19:04
@pflynn-virtru pflynn-virtru changed the title fix(core): backwards-compatible spec-compliant policy bindings fix(kas): accept spec-compliant policy bindings Oct 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 247.686469ms
Throughput 403.74 requests/second

TDF3 Benchmark Results

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 27.884015912s
Average Latency 278.324873ms
Throughput 179.31 requests/second

@pflynn-virtru
pflynn-virtru marked this pull request as ready for review October 14, 2026 19:07
@pflynn-virtru
pflynn-virtru requested review from a team as code owners October 14, 2026 19:07
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 356.290517ms
Throughput 280.67 requests/second

TDF3 Benchmark Results

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 40.067344293s
Average Latency 399.85585ms
Throughput 124.79 requests/second

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • otdfctl
  • sdk
  • service
  • lib/fixtures
  • tests-bdd

See the workflow run for details.

pflynn-virtru added a commit to opentdf/tests that referenced this pull request Oct 14, 2026
The point is to show that a real KAS -- the current release and main --
rejects an on-spec policy binding. A force-only gate skipped exactly
those cells, so drop it. The test fails until a platform carrying
opentdf/platform#4223 is under test.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Paul Flynn <pflynn-virtru@users.noreply.github.com>
@pflynn-virtru
pflynn-virtru added this pull request to the merge queue Oct 15, 2026
Merged via the queue into main with commit d937028 Oct 15, 2026
50 checks passed
@pflynn-virtru
pflynn-virtru deleted the fix/policy-binding-backcompat branch October 15, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:kas Key Access Server comp:sdk A software development kit, including library, for client applications and inter-service communicati size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants