Skip to content

fix(scheduler): authenticate node snapshot pulls with X-API-Key - #552

Open
Pangjiping wants to merge 1 commit into
kvcache-ai:mainfrom
Pangjiping:fix/scheduler-snapshot-pull-api-key
Open

Pangjiping wants to merge 1 commit into
kvcache-ai:mainfrom
Pangjiping:fix/scheduler-snapshot-pull-api-key

Conversation

@Pangjiping

Copy link
Copy Markdown

What

Send X-API-Key instead of X-Admin-Token when the HA scheduler pulls GET /nodes during post-election state recovery (sync-node-snapshots), and align the HA E2E stubnode, unit tests, and HA documentation with the runtime's actual X-API-Key contract.

Why

Deployed Rust runtime nodes authenticate every protected control-plane endpoint — including GET /nodes — exclusively with X-API-Key (src/api/impls/auth.rs, enforced by scripts/tests/e2e/suites/08_auth.sh and noted in docs/src/stoplight-elements.html).

NewAdminSnapshotFetcher (services/scheduler/internal/node_snapshot.go) previously sent X-Admin-Token, and services/scheduler/e2e/stubnode/main.go mirrored X-Admin-Token in the Kind HA E2E double. As a result, E2E passed against stubnode while every real failover against Rust runtime nodes failed sync-node-snapshots with 401 Unauthorized, forcing the new leader to wait for periodic gRPC heartbeats before observing node state.

Compared with widening the Rust auth middleware to accept a second header alias (#500), switching the scheduler client to X-API-Key keeps the single-header control-plane security boundary intact (matching services/gateway, 08_auth.sh, and proxy header scrubbing) with a minimal, surgical diff.

Related issue

Closes #450

Scope and non-goals

  • In scope:
    • NewAdminSnapshotFetcher (services/scheduler/internal/node_snapshot.go) sends X-API-Key.
    • stubnode (services/scheduler/e2e/stubnode/main.go) checks X-API-Key so scheduler-ha-e2e validates the same header real Rust nodes require.
    • Unit tests (services/scheduler/internal/node_snapshot_test.go) verify X-API-Key is sent and X-Admin-Token is absent.
    • Comments and HA docs (services/shared/config/config.go, services/README.md, deploy/k8s/overlays/ha/README.md) updated to reference X-API-Key.
  • Non-goals:
    • No changes to Rust runtime authentication (src/api/impls/auth.rs) or the upstream E2B-compatible src/api/openapi.yml schema (already normalized to ApiKeyAuth in the rendered API reference via docs/src/stoplight-elements.html).
    • No configuration key or environment variable renames (scheduler.node_admin_api_key / SCHEDULER_NODE_ADMIN_API_KEY remain unchanged).

Design and behavior changes

  • Post-acquisition GET {node.Endpoint}/nodes requests now set X-API-Key: <node_admin_api_key> when node_admin_api_key is non-empty, matching src/api/impls/auth.rs (require_auth and ApiKeyAuthHeader).
  • Redirect blocking (http.ErrUseLastResponse), 5s timeout, 1 MiB body limit, node-ID matching, and freshness guards are unchanged.

Compatibility and operations

  • Public API or generated protocol: N/A (runtime nodes already require X-API-Key on GET /nodes).
  • Configuration or defaults: N/A (scheduler.node_admin_api_key and SCHEDULER_NODE_ADMIN_API_KEY are unchanged and continue to carry AENV_API_KEY).
  • Snapshot manifest, artifact layout, or storage format: N/A.
  • Upgrade and rollback: Drop-in fix for agentenv-scheduler; rolling back reverts to 401 on sync-node-snapshots with automatic fallback to 5s heartbeats.
  • Host requirements, permissions, ports, or dependencies: N/A.

Validation

  • make fmt
  • make clippy
  • make test-unit
  • Relevant Rust integration tests
  • make -C services test (required when services/ changes; see macOS note below)
  • Generated clients/server regenerated with the documented make target
  • Documentation updated
  • Benchmarks or performance comparison completed

Commands and results:

make -C services build
make -C services/gateway test
# ok  agentenv/services/gateway/cmd
# ok  agentenv/services/gateway/internal

make -C services/scheduler test
# ok  agentenv/services/scheduler/cmd
# ok  agentenv/services/scheduler/internal

cd services && go test ./shared/...
# ok  agentenv/services/shared/config

cd services && go test -v ./scheduler/internal -run TestAdminSnapshotFetcher
# PASS: TestAdminSnapshotFetcherAssemblesHeartbeatShape
# PASS: TestAdminSnapshotFetcherParityFields
# PASS: TestAdminSnapshotFetcherAuthFailure
# PASS: TestAdminSnapshotFetcherSendsXAPIKeyHeaderOnly
# PASS: TestAdminSnapshotFetcherHeartbeatIngestCompatibility

cd services && go build -o /dev/null ./scheduler/e2e/stubnode
make -C services fmt-check
make -C services vet

Skipped checks and reasons:

  • Rust targets (make fmt, make clippy, make test-unit) and OpenAPI codegen: No Rust files or OpenAPI schemas were modified; local validation ran on macOS (where services/compose TestLoadMatchesDockerCompose has a /var vs. /private/var Docker Desktop symlink path difference unrelated to scheduler, covered on Linux in services-ci and scheduler-ha-e2e).

Risks and reviewer notes

  • Key files: services/scheduler/internal/node_snapshot.go and services/scheduler/e2e/stubnode/main.go.
  • stubnode is updated in lockstep so the scheduler-ha-e2e Kind workflow exercises the exact X-API-Key header expected by aenv-server.

Checklist

  • The PR contains one coherent change and no unrelated formatting or refactoring.
  • New behavior is covered by tests, or I explained why testing is impractical.
  • Logs and examples contain no credentials, tokens, or private registry information.
  • I did not manually edit generated code without updating its source and regenerating it.

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s).

@yingdi-shan
yingdi-shan requested a review from guozy18 November 25, 2026 01:48

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.

Admin authentication header differs between OpenAPI and server implementation

1 participant