Port/nautobot rbac group mapping#24
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (9)
🚧 Files skipped from review as they are similar to previous changes (9)
📝 WalkthroughWalkthroughThis PR introduces JWT-driven group-mapping RBAC for Nautobot: a new ChangesJWT-driven Group Mapping RBAC
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Adds nv_config_manager_auth.rbac, which reads a YAML group-mapping file on every JWT login to reconcile Django Group membership and per-action ObjectPermissions (with optional constraints and is_superuser shortcut) against the JWT roles claim. Group lifecycle is operator-managed by default; NV_CONFIG_MANAGER_AUTO_CREATE_GROUPS opts into auto-creation. _sync_superuser_status now decouples mapping-enabled from per-user-match so revocation/demotion runs even with an empty or failed-to-parse mapping (fail-closed). Helm renders the mapping into a directory-mounted ConfigMap with a pod-template checksum. Signed-off-by: Davesh Mathur <daveshm@nvidia.com>
Adds values-local-azure-sso.yaml as a generic, scrubbed example: all tenant/client IDs, secrets, internal hostnames, and cluster contexts are replaced with <placeholder>s. Shows how to exercise the nautobot.rbac.groupMapping path against a real Entra ID OIDC provider on a local kind cluster. Signed-off-by: Davesh Mathur <daveshm@nvidia.com>
91ca8ad to
3b934e2
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 `@deploy/helm/templates/_nautobot-configmap-data.tpl`:
- Around line 79-90: The group-mapping ConfigMap and mounts are being rendered
unconditionally so nv_config_manager_auth.rbac (mapping_is_configured() /
DEFAULT_MAPPING_PATH) treats RBAC as configured even when
Values.nautobot.rbac.groupMapping is empty; update
deploy/helm/templates/nautobot.yaml to wrap the ConfigMap, volume, and
volumeMount blocks with a guard that checks for the presence of the key (e.g.,
{{ if hasKey .Values.nautobot.rbac "groupMapping" }} ) so an absent key means
“unconfigured”, and update deploy/helm/values.yaml to remove the default
groupMapping: [] (or set it to null) so the chart will not render the
ConfigMap/mount unless the operator explicitly provides groupMapping.
In `@deploy/helm/values.yaml`:
- Line 2454: The default empty array for groupMapping causes unintended
revoke-all behavior; change the default in values.yaml from "groupMapping: []"
to either remove the key or set "groupMapping: null" (or comment it out) and
update the Helm templates (the ConfigMap/volume creation in nautobot.yaml that
mounts the RBAC file) to be conditional on groupMapping being defined and
non-null so the ConfigMap is only created when the user explicitly configures
groupMapping (this preserves the documented semantics that null/omitted means
"do not touch", while an explicit [] still triggers the revoke-all behavior).
🪄 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: 7557663c-2858-4da0-8809-605501b8542b
📒 Files selected for processing (9)
components/nautobot/nv_config_manager_auth/jwt_authentication.pycomponents/nautobot/nv_config_manager_auth/rbac.pycomponents/nautobot/tests/conftest.pycomponents/nautobot/tests/test_jwt_authentication.pycomponents/nautobot/tests/test_rbac.pydeploy/helm/templates/_nautobot-configmap-data.tpldeploy/helm/templates/nautobot.yamldeploy/helm/values-local-azure-sso.yamldeploy/helm/values.yaml
| # status__name: "Active" | ||
| # - name: "nv-config-manager-admins" | ||
| # is_superuser: true | ||
| groupMapping: [] |
There was a problem hiding this comment.
Change default to null or remove the key to avoid unintended revocation.
The default value groupMapping: [] combined with the unconditional ConfigMap creation in nautobot.yaml means the RBAC feature is configured-but-empty by default. From the test context (test_jwt_authentication.py:717-733), an empty configured mapping triggers the "explicit revoke-everyone idiom"—users are removed from all managed groups and permissions on their next JWT login.
This is inconsistent with superuserGroups (line 2383), where [] means "feature disabled, don't touch existing privileges" per the documentation on lines 2374-2383.
Recommended fix: Change the default to:
# groupMapping: [] # commented out, or
groupMapping: nullCombined with conditionalizing the ConfigMap/volume creation (flagged in earlier comment), this ensures:
- Unconfigured (key not set or null): no ConfigMap, no file, rbac sees unconfigured, no sync runs
- Configured to []: ConfigMap created with
groups: [], rbac sees configured+empty, revoke-all runs - Configured to [...]: ConfigMap created with content, rbac syncs as expected
As per the earlier comment, the ConfigMap/volume definitions must also be wrapped in a condition to respect this default.
🤖 Prompt for 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.
In `@deploy/helm/values.yaml` at line 2454, The default empty array for
groupMapping causes unintended revoke-all behavior; change the default in
values.yaml from "groupMapping: []" to either remove the key or set
"groupMapping: null" (or comment it out) and update the Helm templates (the
ConfigMap/volume creation in nautobot.yaml that mounts the RBAC file) to be
conditional on groupMapping being defined and non-null so the ConfigMap is only
created when the user explicitly configures groupMapping (this preserves the
documented semantics that null/omitted means "do not touch", while an explicit
[] still triggers the revoke-all behavior).
Description
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:
Checklist
CONTRIBUTING.md.docs screenshots, or Helm/rendered outputs.
Summary by CodeRabbit