Skip to content

fix(deployments): restore NIM NGC authentication - #852

Merged
tylersbray merged 5 commits into
mainfrom
fix-nim-ngc-docker-parity/tbray
Jul 23, 2026
Merged

fix(deployments): restore NIM NGC authentication#852
tylersbray merged 5 commits into
mainfrom
fix-nim-ngc-docker-parity/tbray

Conversation

@tylersbray

@tylersbray tylersbray commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • restore platform.ngc_api_key_secret resolution and inject NGC_API_KEY into NIM containers
  • authenticate Docker pulls from nvcr.io with the resolved credential
  • recreate exited one-shot puller containers instead of reusing stale success against an empty volume

This restores Docker NIM parity lost in the deployments-plugin cutover (#705) and addresses both failures reported by the embedding customization workflow.

Test plan

  • uv run --frozen pytest for the affected models compiler/backend and deployments Docker suites (58 passed)
  • uv run pre-commit run -a
  • independent Bugbot review; one valid fallback finding fixed and covered by a regression test

Summary by CodeRabbit

  • New Features
    • Added controller-managed secretRef support for deployment env vars, with request/response-specific schema rules.
    • NGC-aware Docker image pulling with optional authenticated access (when configured).
  • Bug Fixes
    • Improved deployment idempotency for one-shot restart policies, including safer handling of exited/stale containers.
    • Strengthened failure-path cleanup for GPU allocation/release and container startup.
  • Validation
    • Rejects conflicting env-var inputs and unauthorized request-time secret references.
  • Documentation
    • Updated API contracts for request/response container and env-var shapes.

Signed-off-by: Tyler Bray <tbray@nvidia.com>
@tylersbray
tylersbray requested review from a team as code owners July 22, 2026 22:00
@github-actions github-actions Bot added the fix label Jul 22, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds controller-managed NGC secret references, resolves them during deployment execution, emits secret-backed NIM configuration, authenticates NGC Docker pulls, and updates Docker one-shot recreation and GPU cleanup behavior.

Changes

NGC deployment flow

Layer / File(s) Summary
Secret reference contract and API policy
plugins/nemo-deployments/openapi/openapi.yaml, plugins/nemo-deployments/src/nemo_deployments_plugin/entities.py, plugins/nemo-deployments/src/nemo_deployments_plugin/schema.py, plugins/nemo-deployments/src/nemo_deployments_plugin/api/v2/deployment_configs.py, plugins/nemo-deployments/tests/unit/test_deployment_config_secret_refs.py
Adds SecretRef, enforces one environment-variable source, and separates request schemas from persisted container entities.
NGC key resolution
plugins/nemo-deployments/src/nemo_deployments_plugin/secrets.py, plugins/nemo-deployments/src/nemo_deployments_plugin/backends/k8s/backend.py, plugins/nemo-deployments/tests/unit/test_secrets.py, plugins/nemo-deployments/tests/unit/backends/k8s/test_backend.py
Resolves configured NGC secrets from Platform or environment fallback, deep-copies deployment configs, and returns failed backend status on resolution errors.
Model environment propagation
services/core/models/src/nmp/core/models/controllers/backends/deployments_plugin/compiler.py, services/core/models/tests/unit/controllers/backends/deployments_plugin/test_compiler.py, services/core/models/tests/unit/controllers/backends/deployments_plugin/test_nim_compiler.py
Compiles NIM server NGC_API_KEY as a secretRef instead of plaintext while preserving additional environment handling.
Docker pull and recreation behavior
plugins/nemo-deployments/src/nemo_deployments_plugin/backends/docker/backend.py, plugins/nemo-deployments/tests/unit/backends/docker/test_idempotency.py, plugins/nemo-deployments/tests/unit/backends/docker/test_image_pull_auth.py
Adds NGC-authenticated pulls, releases GPUs on failure paths, and recreates exited one-shot containers while retaining running-container status behavior.

Sequence Diagram(s)

sequenceDiagram
  participant ModelCompiler
  participant DeploymentBackend
  participant PlatformSecrets
  participant DockerEngine
  ModelCompiler->>DeploymentBackend: provide secretRef-backed NGC_API_KEY
  DeploymentBackend->>PlatformSecrets: resolve configured secret
  PlatformSecrets-->>DeploymentBackend: return credential
  DeploymentBackend->>DockerEngine: pull NGC image with auth_config
  DockerEngine-->>DeploymentBackend: return pull result
Loading

Possibly related PRs

Suggested labels: test

Suggested reviewers: mckornfield, mikeknep, svvarom, benmccown

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. 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 accurately captures the main change: restoring NIM NGC authentication for deployments.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-nim-ngc-docker-parity/tbray

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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
`@plugins/nemo-deployments/src/nemo_deployments_plugin/backends/docker/backend.py`:
- Around line 132-142: Update the exited one-shot container cleanup in the
backend recreate flow to catch Docker’s APIError from existing.remove, return a
failed BackendStatusUpdate instead of aborting, and preserve normal recreation
when removal succeeds. Add a regression test covering the removal failure and
verifying the failed status is returned.
🪄 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: 5e2379da-be3c-40f1-ac12-d48653c735ca

📥 Commits

Reviewing files that changed from the base of the PR and between 3805213 and f173a7d.

📒 Files selected for processing (11)
  • packages/nemo_platform_plugin/src/nemo_platform_plugin/secrets/ngc.py
  • plugins/nemo-deployments/src/nemo_deployments_plugin/backends/docker/backend.py
  • plugins/nemo-deployments/tests/unit/backends/docker/test_idempotency.py
  • plugins/nemo-deployments/tests/unit/backends/docker/test_image_pull_auth.py
  • services/core/models/src/nmp/core/models/controllers/backends/deployments_plugin/backend.py
  • services/core/models/src/nmp/core/models/controllers/backends/deployments_plugin/compiler.py
  • services/core/models/src/nmp/core/models/controllers/backends/deployments_plugin/ngc.py
  • services/core/models/src/nmp/core/models/controllers/backends/deployments_plugin/nim_compiler.py
  • services/core/models/tests/unit/controllers/backends/deployments_plugin/test_compiler.py
  • services/core/models/tests/unit/controllers/backends/deployments_plugin/test_ngc.py
  • services/core/models/tests/unit/controllers/backends/deployments_plugin/test_nim_compiler.py

Comment thread plugins/nemo-deployments/src/nemo_deployments_plugin/backends/docker/backend.py Outdated
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests N/A N/A N/A
Integration Tests 15920/33544 47.5% 19.9%

@benmccown benmccown left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Flagging one concern with secrets being written to entity store unencrypted. Otherwise LGTM.

Comment thread packages/nemo_platform_plugin/src/nemo_platform_plugin/secrets/ngc.py Outdated
Signed-off-by: Tyler Bray <tbray@nvidia.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 `@plugins/nemo-deployments/openapi/openapi.yaml`:
- Around line 1089-1090: Update the OpenAPI schema path for
CreateDeploymentConfigRequest so secretRef is not accepted as a writable request
property. Split the environment schemas into request and response variants, or
mark secretRef as response-only, while preserving its availability in deployment
responses.

In
`@services/core/models/src/nmp/core/models/controllers/backends/deployments_plugin/compiler.py`:
- Around line 124-128: Update the environment construction around
platform_ngc_secret_ref() to detect when the input values contain NGC_API_KEY
but the secret reference resolves to None, and raise a clear configuration error
instead of omitting the credential. Preserve the existing behavior for valid
secret references and inputs without NGC_API_KEY.
🪄 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: 66a09b26-aed1-4cd9-bf8b-dbea58dad7c3

📥 Commits

Reviewing files that changed from the base of the PR and between f173a7d and 88268f1.

📒 Files selected for processing (14)
  • plugins/nemo-deployments/openapi/openapi.yaml
  • plugins/nemo-deployments/src/nemo_deployments_plugin/api/v2/deployment_configs.py
  • plugins/nemo-deployments/src/nemo_deployments_plugin/backends/docker/backend.py
  • plugins/nemo-deployments/src/nemo_deployments_plugin/backends/k8s/backend.py
  • plugins/nemo-deployments/src/nemo_deployments_plugin/entities.py
  • plugins/nemo-deployments/src/nemo_deployments_plugin/secrets.py
  • plugins/nemo-deployments/tests/unit/backends/docker/test_idempotency.py
  • plugins/nemo-deployments/tests/unit/backends/docker/test_image_pull_auth.py
  • plugins/nemo-deployments/tests/unit/backends/k8s/test_backend.py
  • plugins/nemo-deployments/tests/unit/test_deployment_config_secret_refs.py
  • plugins/nemo-deployments/tests/unit/test_secrets.py
  • services/core/models/src/nmp/core/models/controllers/backends/deployments_plugin/compiler.py
  • services/core/models/tests/unit/controllers/backends/deployments_plugin/test_compiler.py
  • services/core/models/tests/unit/controllers/backends/deployments_plugin/test_nim_compiler.py
💤 Files with no reviewable changes (1)
  • services/core/models/tests/unit/controllers/backends/deployments_plugin/test_nim_compiler.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/nemo-deployments/src/nemo_deployments_plugin/backends/docker/backend.py

Comment thread plugins/nemo-deployments/openapi/openapi.yaml
Use AsyncNeMoPlatform for secret resolution, keep secretRef off the public
create request schema, and fail when an explicit NGC_API_KEY would be dropped.

Signed-off-by: Tyler Bray <tbray@nvidia.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@plugins/nemo-deployments/src/nemo_deployments_plugin/schema.py`:
- Around line 45-51: Update RequestEnvVar’s generated JSON Schema to declare
value and valueFrom as mutually exclusive, using the model’s schema
customization mechanism while preserving validate_single_source as runtime
validation. Ensure schemas reject payloads containing both properties.
🪄 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: ae06ad73-94d0-4b7c-ab22-c8b696ddd310

📥 Commits

Reviewing files that changed from the base of the PR and between 88268f1 and 21a6a92.

📒 Files selected for processing (7)
  • plugins/nemo-deployments/openapi/openapi.yaml
  • plugins/nemo-deployments/src/nemo_deployments_plugin/api/v2/deployment_configs.py
  • plugins/nemo-deployments/src/nemo_deployments_plugin/schema.py
  • plugins/nemo-deployments/src/nemo_deployments_plugin/secrets.py
  • plugins/nemo-deployments/tests/unit/test_deployment_config_secret_refs.py
  • services/core/models/src/nmp/core/models/controllers/backends/deployments_plugin/compiler.py
  • services/core/models/tests/unit/controllers/backends/deployments_plugin/test_compiler.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • services/core/models/tests/unit/controllers/backends/deployments_plugin/test_compiler.py
  • services/core/models/src/nmp/core/models/controllers/backends/deployments_plugin/compiler.py
  • plugins/nemo-deployments/src/nemo_deployments_plugin/secrets.py

Comment thread plugins/nemo-deployments/src/nemo_deployments_plugin/schema.py Outdated
Expose the value/valueFrom mutual-exclusion constraint in the generated
OpenAPI schema so clients cannot send payloads the API rejects.

Signed-off-by: Tyler Bray <tbray@nvidia.com>
Omit unresolved NGC_API_KEY at execution time so mock/local NIM images
can reach READY when the platform secret and env fallback are absent.

Signed-off-by: Tyler Bray <tbray@nvidia.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
plugins/nemo-deployments/tests/unit/test_secrets.py (1)

114-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert that the NotFound path is exercised.

The current assertions also pass if the implementation skips Platform secret access and simply drops the variable. Verify the mocked client was awaited with the expected secret coordinates.

Proposed assertion
     with (
         patch("nemo_deployments_plugin.secrets.client_from_platform", return_value=secrets),
         patch("nemo_deployments_plugin.secrets.get_platform_config", return_value=platform),
     ):
         resolved = await resolve_deployment_config_secrets(MagicMock(), config)
+    secrets.access_secret.assert_awaited_once_with(
+        name="ngc-api-key",
+        workspace="system",
+    )
🤖 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 `@plugins/nemo-deployments/tests/unit/test_secrets.py` around lines 114 - 126,
The test for resolve_deployment_config_secrets must verify that the Platform
secret lookup occurs before handling the NotFound result. Add an assertion on
the mocked secrets.access_secret call confirming it was awaited with the
expected platform and secret coordinates, while preserving the existing resolved
configuration assertions.
🤖 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.

Nitpick comments:
In `@plugins/nemo-deployments/tests/unit/test_secrets.py`:
- Around line 114-126: The test for resolve_deployment_config_secrets must
verify that the Platform secret lookup occurs before handling the NotFound
result. Add an assertion on the mocked secrets.access_secret call confirming it
was awaited with the expected platform and secret coordinates, while preserving
the existing resolved configuration assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 30dbf86d-b1f9-4fe0-b8a3-1bde1e1d8568

📥 Commits

Reviewing files that changed from the base of the PR and between ef7cbce and fc27919.

📒 Files selected for processing (2)
  • plugins/nemo-deployments/src/nemo_deployments_plugin/secrets.py
  • plugins/nemo-deployments/tests/unit/test_secrets.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/nemo-deployments/src/nemo_deployments_plugin/secrets.py

@tylersbray
tylersbray added this pull request to the merge queue Jul 23, 2026
Merged via the queue into main with commit 40a445d Jul 23, 2026
109 of 110 checks passed
@tylersbray
tylersbray deleted the fix-nim-ngc-docker-parity/tbray branch July 23, 2026 17:23
AnuradhaKaruppiah pushed a commit to AnuradhaKaruppiah/nemo-platform that referenced this pull request Jul 24, 2026
* fix(deployments): restore NIM NGC authentication

Signed-off-by: Tyler Bray <tbray@nvidia.com>

* fix(deployments): defer NGC secret resolution

Signed-off-by: Tyler Bray <tbray@nvidia.com>

* fix(deployments): tighten NGC secret request typing

Use AsyncNeMoPlatform for secret resolution, keep secretRef off the public
create request schema, and fail when an explicit NGC_API_KEY would be dropped.

Signed-off-by: Tyler Bray <tbray@nvidia.com>

* fix(deployments): document RequestEnvVar value exclusivity

Expose the value/valueFrom mutual-exclusion constraint in the generated
OpenAPI schema so clients cannot send payloads the API rejects.

Signed-off-by: Tyler Bray <tbray@nvidia.com>

* fix(deployments): allow NIM start without NGC credentials

Omit unresolved NGC_API_KEY at execution time so mock/local NIM images
can reach READY when the platform secret and env fallback are absent.

Signed-off-by: Tyler Bray <tbray@nvidia.com>

---------

Signed-off-by: Tyler Bray <tbray@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants