Skip to content

sec: Support Laminar API key injection to prevent credential leaks - #2813

Closed
simonrosenberg wants to merge 7 commits into
mainfrom
feat/laminar-header-auth
Closed

simonrosenberg wants to merge 7 commits into
mainfrom
feat/laminar-header-auth

Conversation

@simonrosenberg

Copy link
Copy Markdown
Member

Summary

This PR adds support for secure Laminar credential injection, eliminating the need to forward LMNR_PROJECT_API_KEY as an environment variable. This prevents credentials from leaking into logged payloads.

Problem

Currently, LMNR_PROJECT_API_KEY is forwarded to remote workspaces via the forward_env mechanism, causing it to:

  • Appear in workspace initialization payloads (logged to Datadog)
  • Leak into runtime API request logs (/start endpoint)
  • Expose in evaluation artifact logs

The root cause: Laminar SDK reads credentials from os.environ[], which gets serialized into logged data structures.

Solution

Added laminar_api_key field to all workspace implementations (APIRemoteWorkspace, DockerWorkspace, ApptainerWorkspace) to inject credentials directly without using environment variables.

Key design:

  • Credentials passed as constructor parameters, not read from environment
  • Workspace injects into container environment at runtime (just before execution)
  • SDK initialization accepts optional api_key parameter for programmatic injection
  • Backward compatible: environment variables still work if provided
  • Warnings logged if LMNR_PROJECT_API_KEY found in forward_env list

Changes

openhands-workspace/openhands/workspace/

  • remote_api/workspace.py: Add laminar_api_key field, inject at /start payload build
  • docker/workspace.py: Add laminar_api_key field, inject via -e flags in docker run
  • apptainer/workspace.py: Add laminar_api_key field, inject via --env flags

openhands-sdk/openhands/sdk/observability/

  • laminar.py:
    • maybe_init_laminar(api_key=None): Accept optional API key parameter
    • should_enable_observability(api_key=None): Enable when api_key provided
    • _is_otel_backend_laminar(api_key=None): Recognize backend from api_key

Benefits

✅ Security: Credentials never in environment dict (not logged)
✅ Backward Compatible: Env vars still work, just not recommended
✅ Clean: Leverages Laminar's native Bearer token auth
✅ Observable: Warning logs if old pattern detected
✅ Minimal: ~50 lines of code, focused change

Test Plan

  • Verify workspace initialization payloads don't contain LMNR_PROJECT_API_KEY
  • Confirm Laminar tracing still works end-to-end
  • Check Datadog logs don't expose credentials
  • Test with environment variable (backward compatibility)
  • Test with laminar_api_key parameter (new approach)
  • Verify warning logged if LMNR_PROJECT_API_KEY in forward_env

Related


🤖 Generated with Claude Code

Debug Agent and others added 7 commits April 1, 2026 19:53
SWE-bench base images often ship with NVM-managed old Node.js versions
(v8–v14) that already have `npm` in PATH. The previous conditional
install (`if ! command -v npm`) would skip Node 22, causing ACP packages
(claude-agent-acp, codex-acp, gemini-cli) to be installed into the old
Node.js where they crash with SyntaxError on modern ES module syntax.

Remove the conditional and always install Node 22 from nodesource so ACP
subprocess servers can start reliably regardless of the base image.

Fixes: OpenHands/runtime-api#458

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Instead of replacing the system Node.js with nodesource, download a
Node 22 binary tarball to /opt/acp-node/ and install ACP packages there.
Wrapper scripts in /usr/local/bin/ prepend the ACP Node to PATH only
for the ACP subprocess, so the repo's own Node.js (needed for test
suites) stays untouched.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…al leaks

Adds 'laminar_api_key' field to workspace implementations to enable secure
credential transport without exposing LMNR_PROJECT_API_KEY via environment
variables. This prevents credential leaks in logged payloads.

**Changes:**
- **openhands-workspace/**: Add laminar_api_key field to:
  - APIRemoteWorkspace (remote runtime)
  - DockerWorkspace (Docker containers)
  - ApptainerWorkspace (Apptainer/Singularity)

  Environment variable handling skips LMNR_PROJECT_API_KEY when in forward_env
  list and injects it from the laminar_api_key field instead.

- **openhands-sdk/observability/laminar.py**: Update to:
  - Accept optional api_key parameter in maybe_init_laminar()
  - Update should_enable_observability() and _is_otel_backend_laminar()
    to accept and handle optional api_key parameter
  - Allows programmatic credential injection without environment variables

**Benefits:**
- Credentials not logged in workspace payloads
- Not exposed in Datadog logs
- Leverages Laminar's native Bearer token authentication
- Backward compatible (env var still works if provided)
- Prevents logging warnings if LMNR_PROJECT_API_KEY in forward_env

**Issue:** OpenHands/evaluation#388

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@simonrosenberg

Copy link
Copy Markdown
Member Author

Closing in favor of #2814, which is a clean implementation created from main without unrelated changes.

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.

1 participant