Skip to content

fix(jobs): jobs-launcher authorization without token exchange - #920

Merged
ironcommit merged 1 commit into
mainfrom
AIRCORE-950-jobs-auth
Jul 27, 2026
Merged

fix(jobs): jobs-launcher authorization without token exchange#920
ironcommit merged 1 commit into
mainfrom
AIRCORE-950-jobs-auth

Conversation

@ironcommit

@ironcommit ironcommit commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Fix Kubernetes job log upload auth without service bearer spoofing

Summary

This fixes Kubernetes job log upload and task-side SDK auth when platform auth is enabled but workload token exchange is disabled.

In that configuration, jobs do not receive NMP_WORKLOAD_IDENTITY_TOKEN_FILE, so they cannot exchange a workload identity token for a real access token. The previous fallback sent:

Authorization: Bearer service:jobs

That is not valid auth for the Files OTLP log upload endpoint, so job logs failed with 401 Unauthorized:

failed to send logs to http://nemo-platform-api:8080/apis/files/v2/workspaces/<workspace>/filesets/<fileset>/otlp/v1/logs: 401 Unauthorized

Problem

The failing Kubernetes setup has:

  • auth.enabled=true
  • workload token exchange disabled
  • no workload token file mounted into the job
  • job runtime URLs pointed directly at http://nemo-platform-api:8080
  • job log upload endpoint set to /apis/files/v2/workspaces/{workspace}/filesets/{fileset}/otlp/v1/logs

The jobs launcher correctly detected that no workload token file was configured, but it fell back to a raw service bearer token. That raw bearer shortcut is only supported by the legacy HF-compatible Files path. It is intentionally not supported across normal API endpoints because an external caller that can reach the API directly could spoof a service principal with Authorization: Bearer service:<name>.

The same configuration also exposed a task-side SDK issue: individual tasks should not need to know whether workload token exchange is enabled. Task code should call a single SDK helper and let the SDK/factory layer choose the right auth mechanism.

Root Cause

The no-workload-token path conflated two different auth mechanisms:

  • Real bearer auth: Authorization: Bearer <access-token> from OIDC or workload token exchange.
  • Internal service identity: X-NMP-Principal-Id: service:<name> inside the trusted service boundary.

When workload exchange is disabled, Bearer service:jobs is not a real access token. The Files OTLP endpoint goes through normal middleware auth, so it returned 401.

Solution

Use internal service-principal headers for the no-workload-token fallback, and keep real bearer auth only for real tokens.

Changes included:

  • Jobs launcher log upload:

    • If NMP_WORKLOAD_IDENTITY_TOKEN_FILE is present, exchange the workload token and send Authorization: Bearer <access-token>.
    • If no workload token file is present, send X-NMP-Principal-Id: service:jobs.
    • Rename the fallback log mechanism from service bearer token auth to service principal header auth.
  • Workload auth source:

    • Expose a Headers(ctx) method so token-backed auth and header-backed auth share one exporter path.
  • Task SDK behavior:

    • Centralize the workload-token-vs-service-header decision in nmp.common.sdk_factory.
    • get_task_sdk(as_service=...) now chooses workload identity when NMP_WORKLOAD_IDENTITY_TOKEN_FILE is set.
    • If no workload token file is set, get_task_sdk(as_service=...) uses X-NMP-Principal-Id: service:<name> plus on-behalf-of headers from NMP_PRINCIPAL.
    • Plain task code no longer has to branch on workload token env vars.
  • Plugin SDK provider:

    • Mirror the same task SDK behavior in nemo_platform_plugin.sdk_provider.DefaultSDKProvider so plugin task authors also use one helper.
  • Hello-world workload task:

    • The task now simply calls get_task_sdk(as_service="jobs").

Summary by CodeRabbit

  • New Features
    • Added workload-identity token-file support for platform and task SDK requests, including internal-marker-only headers and streamlined sync/async SDK creation.
    • Added platform endpoint helpers to retrieve SDK-specific HTTP clients for TCP vs UDS endpoints.
  • Bug Fixes
    • Updated OTLP job log authentication to emit per-request header sets; service identity now uses X-NMP-Principal-Id when workload identity isn’t enabled.
  • Tests
    • Expanded workload-identity and OTLP auth middleware coverage across SDK factories, plugins, jobs launcher, and hello-world integration.
  • Documentation
    • Refreshed OTLP exporter option comments to reflect the new header behavior.

@coderabbitai

coderabbitai Bot commented Jul 27, 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

Changes

Workload identity authentication

Layer / File(s) Summary
Plugin SDK workload identity branching
packages/nemo_platform_plugin/src/..., packages/nemo_platform_plugin/tests/...
Task SDK creation detects token-file configuration and omits principal delegation headers.
Common SDK workload identity bootstrap
packages/nmp_common/src/..., packages/nmp_common/tests/sdk_factory/..., packages/nmp_common/tests/test_platform_endpoint.py
Platform and task SDKs bootstrap workload identity, select transport-specific clients, and use exchanged bearer tokens without principal headers.
Launcher multi-header OTLP authentication
services/core/jobs/jobs-launcher/cmd/otel.go, services/core/jobs/jobs-launcher/cmd/workload_auth.go, services/core/jobs/jobs-launcher/cmd/workload_auth_test.go
OTLP transport supports refreshed header maps, including service principal headers instead of service bearer authentication.
Principal-header authorization coverage
packages/nmp_common/tests/auth/test_middleware.py
Middleware tests cover accepted principal headers and rejected raw service bearer tokens.
Task SDK integration
services/hello-world/src/..., services/hello-world/tests/integration/...
The workspace task defaults to get_task_sdk, with integration coverage for factory usage, injected SDKs, and principal-based requests without workload tokens.

Sequence Diagram(s)

sequenceDiagram
  participant Task as Workspace task
  participant Factory as SDK factory
  participant Exchange as Token exchange
  participant Platform as Platform API
  Task->>Factory: get_task_sdk(as_service="jobs")
  Factory->>Exchange: Exchange token-file subject token
  Exchange-->>Factory: Return access token
  Factory->>Platform: Send workspace request with Bearer token
Loading

Suggested reviewers: mckornfield, anastasia-nesterenko, crookedstorm, svvarom

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.80% 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 matches the main change: jobs-launcher auth behavior when token exchange is unavailable.
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 AIRCORE-950-jobs-auth

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


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: 2

🧹 Nitpick comments (1)
packages/nemo_platform_plugin/src/nemo_platform_plugin/sdk_provider.py (1)

170-175: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Class docstring is now inaccurate.

Docstring says the provider only reads NMP_BASE_URL/NMP_PRINCIPAL, but get_task_sdk/get_async_task_sdk now branch entirely on WORKLOAD_IDENTITY_TOKEN_FILE_ENVVAR and drop principal delegation when set. Update the docstring to mention this third config source and the resulting behavior change.

Also applies to: 178-183, 207-212

🤖 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 `@packages/nemo_platform_plugin/src/nemo_platform_plugin/sdk_provider.py`
around lines 170 - 175, Update the provider class docstring to document
WORKLOAD_IDENTITY_TOKEN_FILE_ENVVAR as an additional configuration source: when
set, get_task_sdk and get_async_task_sdk use workload identity instead of
principal delegation. Retain the existing NMP_BASE_URL and NMP_PRINCIPAL
behavior for the non-workload-identity path.
🤖 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 `@packages/nmp_common/src/nmp/common/sdk_factory.py`:
- Around line 307-309: Update the workload-identity shortcut in get_task_sdk()
and get_async_task_sdk() so it does not bypass as_service handling for UDS
endpoints: either restrict the shortcut to endpoint.transport != "uds" or
forward as_service to get_platform_sdk()/get_async_platform_sdk(). Preserve the
existing shortcut behavior for non-UDS transports.
- Around line 277-283: Update the workload-identity bootstrap branches that
construct NeMoPlatform and AsyncNeMoPlatform to pass the resolved HTTP client
via http_client, preserving pooled-client reuse and async _test_http_client
injection; omit it only when the SDK must own the client for token-exchange
setup.

---

Nitpick comments:
In `@packages/nemo_platform_plugin/src/nemo_platform_plugin/sdk_provider.py`:
- Around line 170-175: Update the provider class docstring to document
WORKLOAD_IDENTITY_TOKEN_FILE_ENVVAR as an additional configuration source: when
set, get_task_sdk and get_async_task_sdk use workload identity instead of
principal delegation. Retain the existing NMP_BASE_URL and NMP_PRINCIPAL
behavior for the non-workload-identity path.
🪄 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: a3e8c36e-b055-48ec-af98-953a6512497a

📥 Commits

Reviewing files that changed from the base of the PR and between 579de6b and 442786e.

📒 Files selected for processing (10)
  • packages/nemo_platform_plugin/src/nemo_platform_plugin/sdk_provider.py
  • packages/nemo_platform_plugin/tests/test_sdk_provider.py
  • packages/nmp_common/src/nmp/common/sdk_factory.py
  • packages/nmp_common/tests/auth/test_middleware.py
  • packages/nmp_common/tests/sdk_factory/test_sdk.py
  • services/core/jobs/jobs-launcher/cmd/otel.go
  • services/core/jobs/jobs-launcher/cmd/workload_auth.go
  • services/core/jobs/jobs-launcher/cmd/workload_auth_test.go
  • services/hello-world/src/nmp/hello_world/tasks/workload_workspace_get/run.py
  • services/hello-world/tests/integration/tasks/test_workload_workspace_get_task.py

Comment thread packages/nmp_common/src/nmp/common/sdk_factory.py
Comment thread packages/nmp_common/src/nmp/common/sdk_factory.py Outdated
@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 27341/35089 77.9% 62.2%
Integration Tests 16046/33801 47.5% 19.9%

@ironcommit
ironcommit force-pushed the AIRCORE-950-jobs-auth branch from 442786e to 87c6ea7 Compare July 27, 2026 20:12

@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
`@services/hello-world/tests/integration/tasks/test_workload_workspace_get_task.py`:
- Around line 84-88: Update workspace_response to explicitly reject the obsolete
service Bearer token in the Authorization header, even when the
X-NMP-Principal-Id and X-NMP-Principal-On-Behalf-Of headers are valid; preserve
the existing 401 and 403 responses for invalid principal headers.
🪄 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: ce8d49b3-09d0-4af2-864c-adfe5e49074a

📥 Commits

Reviewing files that changed from the base of the PR and between 442786e and 87c6ea7.

📒 Files selected for processing (10)
  • packages/nemo_platform_plugin/src/nemo_platform_plugin/sdk_provider.py
  • packages/nemo_platform_plugin/tests/test_sdk_provider.py
  • packages/nmp_common/src/nmp/common/sdk_factory.py
  • packages/nmp_common/tests/auth/test_middleware.py
  • packages/nmp_common/tests/sdk_factory/test_sdk.py
  • services/core/jobs/jobs-launcher/cmd/otel.go
  • services/core/jobs/jobs-launcher/cmd/workload_auth.go
  • services/core/jobs/jobs-launcher/cmd/workload_auth_test.go
  • services/hello-world/src/nmp/hello_world/tasks/workload_workspace_get/run.py
  • services/hello-world/tests/integration/tasks/test_workload_workspace_get_task.py
🚧 Files skipped from review as they are similar to previous changes (7)
  • services/hello-world/src/nmp/hello_world/tasks/workload_workspace_get/run.py
  • services/core/jobs/jobs-launcher/cmd/workload_auth_test.go
  • services/core/jobs/jobs-launcher/cmd/workload_auth.go
  • packages/nemo_platform_plugin/src/nemo_platform_plugin/sdk_provider.py
  • packages/nmp_common/src/nmp/common/sdk_factory.py
  • packages/nmp_common/tests/auth/test_middleware.py
  • services/core/jobs/jobs-launcher/cmd/otel.go

Comment thread packages/nmp_common/src/nmp/common/sdk_factory.py Outdated
Comment thread packages/nmp_common/tests/sdk_factory/test_sdk.py
@ironcommit
ironcommit force-pushed the AIRCORE-950-jobs-auth branch 2 times, most recently from 8661b25 to 9071930 Compare July 27, 2026 20:45

@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 `@packages/nmp_common/tests/sdk_factory/test_sdk.py`:
- Around line 225-245: Update
test_get_async_platform_sdk_workload_identity_reuses_test_http_client to set
NMP_PRINCIPAL and assert the SDK client’s internal headers contain the expected
workload-identity credentials while omitting all X-NMP-Principal-* headers. Keep
the existing client-reuse and base URL assertions, and ensure the test
specifically exercises the token-file workload-identity branch rather than the
normal async factory path.
🪄 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: cd948b11-0b3e-400e-ad33-39405d939408

📥 Commits

Reviewing files that changed from the base of the PR and between 87c6ea7 and 9071930.

📒 Files selected for processing (10)
  • packages/nemo_platform_plugin/src/nemo_platform_plugin/sdk_provider.py
  • packages/nemo_platform_plugin/tests/test_sdk_provider.py
  • packages/nmp_common/src/nmp/common/sdk_factory.py
  • packages/nmp_common/tests/auth/test_middleware.py
  • packages/nmp_common/tests/sdk_factory/test_sdk.py
  • services/core/jobs/jobs-launcher/cmd/otel.go
  • services/core/jobs/jobs-launcher/cmd/workload_auth.go
  • services/core/jobs/jobs-launcher/cmd/workload_auth_test.go
  • services/hello-world/src/nmp/hello_world/tasks/workload_workspace_get/run.py
  • services/hello-world/tests/integration/tasks/test_workload_workspace_get_task.py
🚧 Files skipped from review as they are similar to previous changes (7)
  • services/core/jobs/jobs-launcher/cmd/workload_auth.go
  • services/hello-world/src/nmp/hello_world/tasks/workload_workspace_get/run.py
  • packages/nmp_common/src/nmp/common/sdk_factory.py
  • packages/nemo_platform_plugin/src/nemo_platform_plugin/sdk_provider.py
  • packages/nmp_common/tests/auth/test_middleware.py
  • services/core/jobs/jobs-launcher/cmd/workload_auth_test.go
  • services/core/jobs/jobs-launcher/cmd/otel.go

Comment thread packages/nmp_common/tests/sdk_factory/test_sdk.py
@ironcommit
ironcommit force-pushed the AIRCORE-950-jobs-auth branch 2 times, most recently from 698e9e3 to 8c68822 Compare July 27, 2026 21:39

@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.

♻️ Duplicate comments (1)
packages/nmp_common/tests/sdk_factory/test_sdk.py (1)

227-249: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Still doesn't isolate the workload-identity branch.

Marked "Addressed" previously, but this test only asserts client reuse + base_url — both hold true on the normal (non-workload) async factory path too, since _async_http_client_for_endpoint is called in both branches. Set NMP_PRINCIPAL and assert internal headers / absence of X-NMP-Principal-*, as originally requested, so the test actually fails if the workload-identity branch is skipped.

🤖 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 `@packages/nmp_common/tests/sdk_factory/test_sdk.py` around lines 227 - 249,
Update test_get_async_platform_sdk_workload_identity_reuses_test_http_client to
set NMP_PRINCIPAL and assert the SDK’s internal headers reflect workload
identity, including the expected token-derived headers and absence of
X-NMP-Principal-* headers. Retain the existing client-reuse and base_url
assertions so the test specifically distinguishes the workload-identity branch
from the normal async factory path.
🤖 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.

Duplicate comments:
In `@packages/nmp_common/tests/sdk_factory/test_sdk.py`:
- Around line 227-249: Update
test_get_async_platform_sdk_workload_identity_reuses_test_http_client to set
NMP_PRINCIPAL and assert the SDK’s internal headers reflect workload identity,
including the expected token-derived headers and absence of X-NMP-Principal-*
headers. Retain the existing client-reuse and base_url assertions so the test
specifically distinguishes the workload-identity branch from the normal async
factory path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c6c24dda-d97a-4793-b882-3528633e0798

📥 Commits

Reviewing files that changed from the base of the PR and between 698e9e3 and 8c68822.

📒 Files selected for processing (13)
  • packages/nemo_platform_plugin/src/nemo_platform_plugin/client/constants.py
  • packages/nemo_platform_plugin/src/nemo_platform_plugin/sdk_provider.py
  • packages/nemo_platform_plugin/tests/test_sdk_provider.py
  • packages/nmp_common/src/nmp/common/platform_endpoint.py
  • packages/nmp_common/src/nmp/common/sdk_factory.py
  • packages/nmp_common/tests/auth/test_middleware.py
  • packages/nmp_common/tests/sdk_factory/test_sdk.py
  • packages/nmp_common/tests/test_platform_endpoint.py
  • services/core/jobs/jobs-launcher/cmd/otel.go
  • services/core/jobs/jobs-launcher/cmd/workload_auth.go
  • services/core/jobs/jobs-launcher/cmd/workload_auth_test.go
  • services/hello-world/src/nmp/hello_world/tasks/workload_workspace_get/run.py
  • services/hello-world/tests/integration/tasks/test_workload_workspace_get_task.py
🚧 Files skipped from review as they are similar to previous changes (9)
  • services/core/jobs/jobs-launcher/cmd/workload_auth.go
  • packages/nmp_common/src/nmp/common/platform_endpoint.py
  • services/hello-world/src/nmp/hello_world/tasks/workload_workspace_get/run.py
  • packages/nmp_common/tests/test_platform_endpoint.py
  • packages/nemo_platform_plugin/src/nemo_platform_plugin/sdk_provider.py
  • services/core/jobs/jobs-launcher/cmd/workload_auth_test.go
  • packages/nmp_common/src/nmp/common/sdk_factory.py
  • services/core/jobs/jobs-launcher/cmd/otel.go
  • packages/nmp_common/tests/auth/test_middleware.py

@ironcommit
ironcommit added this pull request to the merge queue Jul 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 27, 2026
Signed-off-by: Ryan S <267728323+ironcommit@users.noreply.github.com>
@ironcommit
ironcommit force-pushed the AIRCORE-950-jobs-auth branch from 8c68822 to adbc705 Compare July 27, 2026 22:20
@ironcommit
ironcommit enabled auto-merge July 27, 2026 22:21
@ironcommit
ironcommit added this pull request to the merge queue Jul 27, 2026
Merged via the queue into main with commit d07038b Jul 27, 2026
58 checks passed
@ironcommit
ironcommit deleted the AIRCORE-950-jobs-auth branch July 27, 2026 22:55
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