fix(auth): match SPIFFE prefixes on path-segment boundaries#22
Conversation
📝 WalkthroughWalkthroughReplaces naive SPIFFE prefix matching with boundary-aware semantics (exact match or prefix + "/") in documentation and in ChangesSPIFFE Prefix Matching Boundary Fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
8af260e to
7df8982
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/nv_config_manager/common/auth.py`:
- Around line 150-152: The docstring for SpiffeConfig claims that matched
callers get a tracking group "spiffe:<workload_name>" but the implementation in
identity_from_spiffe currently only adds "all" and the mapped groups from
group_prefixes; to fix, either update identity_from_spiffe to also append the
tracking group "spiffe:<workload_name>" (construct workload_name from the
caller's SPIFFE ID path segment and add f"spiffe:{workload_name}" to the
returned groups) or update the SpiffeConfig docstring to remove the mention of
the tracking group so it matches the current behavior; locate SpiffeConfig and
the identity_from_spiffe function to make the corresponding change so contract
and implementation align.
In `@src/tests/common/test_auth.py`:
- Around line 1200-1243: The test test_layered_prefixes_add_both_roles is only
exercising the exact-match branch for the narrower prefix; change the SVID
subject passed to _mock_spiffe_request (the sub= argument) to be a descendant
path (e.g. "spiffe://cluster.local/ns/nv-config-manager/render/worker") instead
of the exact "…/render" so the code path that matches via prefix + "/" is
executed and ensures layered roles accumulate; keep the rest of the call (aud,
token/mock_jwk handling, and assertions on data["groups"]) unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 4eb33851-624d-4f85-92b8-68fdc94fa2a3
📒 Files selected for processing (2)
src/nv_config_manager/common/auth.pysrc/tests/common/test_auth.py
7df8982 to
c10a6b0
Compare
|
/ok to test c10a6b0 |
1 similar comment
|
/ok to test c10a6b0 |
A naive startswith() match let a sibling identity (e.g. spiffe://td/ns/nv-config-manager-admin) inherit the role mapped to a shorter prefix (spiffe://td/ns/nv-config-manager). Match now requires an exact prefix or a '/' boundary, so roles only apply along hierarchical SPIFFE path segments. Adds sibling/exact/layered regression tests. Signed-off-by: Davesh Mathur <daveshm@nvidia.com>
identity_from_spiffe() only adds "all" plus configured mapped groups; it never emits a spiffe:<workload_name> tracking group. Drop that claim from the SpiffeConfig docstring and INI example so the contract matches the implementation and operators are not misled. Signed-off-by: Davesh Mathur <daveshm@nvidia.com>
de6b5d0 to
7fe3cf1
Compare
The layered-prefix regression matched the narrow prefix exactly, so it never proved that roles still accumulate when a narrow prefix is hit via the ``prefix + "/"`` boundary. Push the SVID one segment deeper (.../render/sa/api) so both mapped prefixes match through the descendant branch. Addresses CodeRabbit review feedback on #22. Signed-off-by: Davesh Mathur <daveshm@nvidia.com>
A naive startswith() match let a sibling identity (e.g. spiffe://td/ns/nv-config-manager-admin) inherit the role mapped to a shorter prefix (spiffe://td/ns/nv-config-manager). Match now requires an exact prefix or a '/' boundary, so roles only apply along hierarchical SPIFFE path segments. Adds sibling/exact/layered regression tests.
Description
/-delimited), preventing sibling identities from inheriting a shorter prefix's role.SpiffeConfigdocstring and INI example with the implementation: removed the unimplementedspiffe:<workload_name>tracking-group claim, sinceidentity_from_spiffe()only adds"all"plus configured mapped groups.Validation
The kind integration test is manual due to taking ~30 min to complete. When the PR is ready for review,
run Actions -> Kind Integration -> Run workflow against the copy-pr-bot generated
pull-request/<PR_NUMBER>branch. Use the defaulttest_pathfor the full suite,or narrow it only while debugging.
Passing Kind Integration run:
https://github.com/NVIDIA/nv-config-manager/actions/runs/28549893053
Checklist
CONTRIBUTING.md.docs screenshots, or Helm/rendered outputs.
Summary by CodeRabbit
Bug Fixes
Tests