Skip to content

fix(sandbox): handle bearer authentication for E2B gateways - #5880

Open
xixi-box wants to merge 1 commit into
Tencent:mainfrom
xixi-box:fix/issue-5874-032c67f-937e654f
Open

xixi-box wants to merge 1 commit into
Tencent:mainfrom
xixi-box:fix/issue-5874-032c67f-937e654f

Conversation

@xixi-box

Copy link
Copy Markdown
Contributor

Fixes #5874

Description

The E2B connection wizard can fail with a 401 saying the authorization header is missing. The Go E2B SDK sends the configured key in X-API-Key. E2B-compatible gateways that require bearer authentication can reject that request even when the key itself is valid.

Keep X-API-Key as the default. When the configured control plane explicitly returns the missing-header 401, retry once with the same key as Authorization: Bearer. The shared E2B transport applies the fallback to connection checks, template discovery, and lifecycle requests. Existing API-key endpoints still authenticate in one request, and ordinary invalid-key errors still reach the caller.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📚 Documentation update
  • 🎨 Refactor
  • ⚡ Performance improvement
  • 🧪 Test
  • 🔧 Configuration / Build / CI

Related Issue

Fixes #5874

Testing

Tests: go test -count=1 -v ./internal/handler -run '^TestSandboxConnectionCheckE2BControlPlaneAuth$'.
Result: go test -count=1 -v ./internal/handler -run '^TestSandboxConnectionCheckE2BControlPlaneAuth$': base exit 1 with the reproduced 401 and a failed OK assertion; patched exit 0 with all three cases passing.
Result: go test -count=1 ./internal/sandbox ./internal/handler -run 'Test(E2B|SandboxConnectionCheckConfig|SandboxCheckReason|.*RemoteTemplate)' -skip '^TestE2BRemoteClient(ControlPlaneBearerFallback|DoesNotRetryBearerOutsideControlPlane)$': existing tests passed before the production fix. The initial broader-regex run overlapped a test-only edit and failed to compile the handler; the clean rerun passed both packages.
Result: go test -count=1 ./internal/sandbox/... ./internal/handler: all five packages passed on the final patch.
Result: go test -count=1 ./internal/application/service -run '^Test(QueryTemplates|SanitizeSandboxConfig)': passed.
Result: node --test frontend/src/components/SandboxConfigEditorDrawer.template.test.mjs frontend/src/components/SandboxConfigEditorDrawer.network.test.mjs: 16 passed.
Result: /tmp/oss5874-lint/golangci-lint-2.12.2-linux-amd64/golangci-lint run --new-from-patch=/tmp/oss5874-lint/changes.patch ./internal/sandbox ./internal/handler: final exit 0, 0 issues.
Regression coverage: internal/handler/sandbox_check_test.go.

The regression uses a local HTTP gateway fixture. The reporter's live deployment and the full repository gate were outside the verification scope.

Checklist

  • git diff --check origin/main...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages/components pass
  • Diff-scoped lint passes where applicable (for Go: golangci-lint run --new-from-rev=origin/main ./...)
  • Full-repository checks were run, or any unrelated/environment-dependent failures are documented above
  • Self-reviewed the code
  • Added/updated tests covering the change
  • Updated related documentation (README, website-docs/, Swagger annotations, etc.)
  • Breaking changes are clearly called out in the description above

Screenshots / Recordings

Backend authentication change.

Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com>

This branch has not been deployed

No deployments
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]: 配置E2B沙箱出错

1 participant