Skip to content

fix(auth): Authorize admin CLI network segment creation - #4420

Draft
kfelternv wants to merge 2 commits into
NVIDIA:mainfrom
kfelternv:fix-network-segment-rbac
Draft

fix(auth): Authorize admin CLI network segment creation#4420
kfelternv wants to merge 2 commits into
NVIDIA:mainfrom
kfelternv:fix-network-segment-rbac

Conversation

@kfelternv

Copy link
Copy Markdown
Contributor

Allows nico-admin-cli to call CreateNetworkSegment after the existing --cloud-unsafe-op=admin safeguard by adding the admin principal to the static RBAC rule. This restores the intended admin workflow without changing Machine-a-Tron or site-agent access.

Related issues

Resolves #4341

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

The focused RBAC assertion failed before the rule change and passed afterward against the exact authorization source on Linux.

Additional Notes

Full carbide-api-core tests were not run locally because the available ARM and Linux environments could not link the repository's complete API test target; CI remains required.

Signed-off-by: Kyle Felter <kfelter@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e850167c-7b2f-4b0a-8c02-bdc9a444e457

📥 Commits

Reviewing files that changed from the base of the PR and between 70a64d3 and 923cb20.

📒 Files selected for processing (1)
  • crates/api-core/src/auth/internal_rbac_rules.rs

Summary by CodeRabbit

  • Bug Fixes
    • External administrators using the admin CLI can now create network segments.
    • Added coverage to verify this access behavior.

Walkthrough

CreateNetworkSegment now permits the ForgeAdminCLI principal, and a regression test verifies that nico-admin-cli can invoke the operation.

Changes

Network segment RBAC

Layer / File(s) Summary
Permit admin CLI network segment creation
crates/api-core/src/auth/internal_rbac_rules.rs
Adds ForgeAdminCLI to the CreateNetworkSegment permission rule and tests authorization for the external nico-admin-cli principal.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary authorization fix for admin CLI network segment creation.
Description check ✅ Passed The description directly explains the RBAC change, safeguard behavior, testing, and linked bug.
Linked Issues check ✅ Passed The change addresses issue #4341 by authorizing the guarded admin CLI workflow while preserving existing principals' access.
Out of Scope Changes check ✅ Passed The changes are limited to the relevant static RBAC rule and its focused test, with no unrelated scope identified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@kfelternv

Copy link
Copy Markdown
Contributor Author

What changed

This PR allows the admin CLI certificate principal to create a network segment through the existing guarded command. I exercised the CLI acknowledgment gate, the exact Core authorization path, creation, and readback.

Scenario and setup

I built and deployed revision 923cb203c8e57a423b22df11c2cd868a1a14581d in a clean local Kubernetes environment with Core RBAC enforcement enabled. The client certificate was signed by the API's trusted admin CA and had OU=nico-admin-cli. The test used an unused underlay prefix and a fixed segment ID so creation and readback could be correlated.

Verification

Step 1: Preserve the cloud-unsafe acknowledgment gate

Why this step exists: The authorization change must not bypass the CLI's existing protection for operations that can diverge from the cloud database.

Runnable command:

API_URL=https://nico-api.example.test:1079 \
ROOT_CA_PATH=/etc/nico/ca.crt \
CLIENT_CERT_PATH=/etc/nico/admin-client.crt \
CLIENT_KEY_PATH=/etc/nico/admin-client.key \
nico-admin-cli -f json network-segment create \
  --name pr4420-admin-rbac \
  --id 44200000-0000-4000-8000-000000000001 \
  --segment-type underlay \
  --prefix 10.250.10.0/24 \
  --gateway 10.250.10.1 \
  --reserve-first 2 \
  --mtu 1500

Observed result:

Error:
   0: operation not allowed due to potential inconsistencies with cloud database
command terminated with exit code 1

Why this proves the behavior: The CLI rejected the operation before an acknowledged request could reach the API.

Step 2: Authorize acknowledged admin CLI creation

Why this step exists: This is the changed authorization path: nico-admin-cli must be allowed to invoke CreateNetworkSegment.

Runnable command:

API_URL=https://nico-api.example.test:1079 \
ROOT_CA_PATH=/etc/nico/ca.crt \
CLIENT_CERT_PATH=/etc/nico/admin-client.crt \
CLIENT_KEY_PATH=/etc/nico/admin-client.key \
nico-admin-cli --cloud-unsafe-op=verification-admin -f json \
  network-segment create \
  --name pr4420-admin-rbac \
  --id 44200000-0000-4000-8000-000000000001 \
  --segment-type underlay \
  --prefix 10.250.10.0/24 \
  --gateway 10.250.10.1 \
  --reserve-first 2 \
  --mtu 1500

Observed result (selected fields from the actual JSON response):

{
  "id": "44200000-0000-4000-8000-000000000001",
  "vpc_id": null,
  "name": "pr4420-admin-rbac",
  "subdomain_id": null,
  "mtu": 1500,
  "prefixes": [
    {
      "id": "52829088-445e-49b3-afee-47b8e7614c0a",
      "prefix": "10.250.10.0/24",
      "gateway": "10.250.10.1",
      "reserve_first": 2,
      "free_ip_count": 0,
      "svi_ip": null,
      "free_ip_count_v2": null,
      "free_ip_count_saturated": false
    }
  ],
  "created": "2026-07-30T23:35:57.408955Z",
  "updated": "2026-07-30T23:35:57.408955Z",
  "deleted": null,
  "segment_type": 2,
  "flags": [1],
  "config": {
    "vpc_id": null,
    "subdomain_id": null,
    "mtu": 1500,
    "segment_type": 2,
    "prefixes": [
      {
        "id": "52829088-445e-49b3-afee-47b8e7614c0a",
        "prefix": "10.250.10.0/24",
        "gateway": "10.250.10.1",
        "reserve_first": 2,
        "free_ip_count": 0,
        "svi_ip": null,
        "free_ip_count_v2": null,
        "free_ip_count_saturated": false
      }
    ]
  },
  "version": "V1-T1785454557409047",
  "state": 0
}

Why this proves the behavior: The acknowledged request authenticated as the admin CLI principal, passed Core RBAC, and returned the created segment instead of PermissionDenied.

Step 3: Read back the created segment

Why this step exists: A successful create response must correspond to a persisted segment that is available through the normal CLI read path.

Runnable command:

API_URL=https://nico-api.example.test:1079 \
ROOT_CA_PATH=/etc/nico/ca.crt \
CLIENT_CERT_PATH=/etc/nico/admin-client.crt \
CLIENT_KEY_PATH=/etc/nico/admin-client.key \
nico-admin-cli network-segment show \
  44200000-0000-4000-8000-000000000001

Observed result:

ID        : 44200000-0000-4000-8000-000000000001
NAME      : pr4420-admin-rbac
CREATED   : 2026-07-30T23:35:57.408955Z
UPDATED   : 2026-07-30T23:35:57.408955Z
DELETED   : Not Deleted
STATE     : ready
VPC       : 00000000-0000-0000-0000-000000000000
DOMAIN    : 00000000-0000-0000-0000-000000000000/NA
TYPE      : Underlay
PREFIXES  :
  SN             : 0
  ID             : 52829088-445e-49b3-afee-47b8e7614c0a
  Prefix         : 10.250.10.0/24
  Range          : 10.250.10.0 - 10.250.10.255
  Gateway        : 10.250.10.1
  SVI IP         :
  Reserve First  : 2
  Free IP Count  : 253
STATE HISTORY: (Latest 5 only)
  State          Version                      Time
  provisioning   V1-T1785454557409047      2026-07-30T23:35:57.408955Z
  ready          V2-T1785454560859744      2026-07-30T23:36:00.859671Z

Why this proves the behavior: The normal read path returned the same ID and configuration after the controller advanced the segment to ready.

@kfelternv
kfelternv marked this pull request as ready for review July 30, 2026 23:38
@kfelternv
kfelternv requested a review from a team as a code owner July 30, 2026 23:38
@github-actions

Copy link
Copy Markdown

@kfelternv
kfelternv marked this pull request as draft July 31, 2026 16:50
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.

bug: nico-admin-cli cannot create network segments

1 participant