Skip to content

feat(grpc): token-based authentication for gRPC requests (#4417) - #2130

Open
DoubleCore wants to merge 2 commits into
dragonflyoss:mainfrom
DoubleCore:issue-4417-jwt
Open

DoubleCore wants to merge 2 commits into
dragonflyoss:mainfrom
DoubleCore:issue-4417-jwt

Conversation

@DoubleCore

Copy link
Copy Markdown

说明

实现 dragonflyoss/dragonfly#4417 的 client 侧 gRPC token 鉴权(JWT / HS256)。
主仓服务端部分在 dragonflyoss/dragonfly#5098。

改动

1. dragonfly-client/src/grpc/interceptor.rs(+525 行)

  • 服务端:校验 authorization: Bearer <token>,验签 + exp / aud(可选),失败返回 Unauthenticated;grpc.health.v1.Health 默认豁免,避免影响 k8s probe
  • 客户端:从配置或文件读取 token 注入每次请求
  • 未配置 token 时保持原有免鉴权行为并打一次 warning,老部署不受影响

2. 配置(dragonfly-client-config)

manager / scheduler / dfdaemon 各加 token、token_file、audience,加载期校验;支持从文件读(便于挂 Secret)。

3. 接线

grpc/{manager,scheduler,dfdaemon_download,dfdaemon_upload,health}.rs 与 dynconfig/{local,remote}.rs 使用该 interceptor。

4. 文档

docs/grpc-jwt-auth.md:claim 结构、配置示例、滚动升级顺序。

验证

cargo test -p dragonfly-client grpc
# running 18 tests ... test result: ok. 18 passed; 0 failed

覆盖:token 注入、过期拒绝、签名篡改、格式错误、文件读取、无 token 开发模式、audience 宽容策略。

注:本分支基于当前 main 重建,剔除了原分支携带的两个 workflow action 版本回退(与本任务无关)。

refs: #4417

Add JWT (HS256) bearer-token authentication to the client's gRPC stack:

- grpc::interceptor: server-side auth interceptor validating bearer tokens
  (expiry, audience, signature), plus a client-side interceptor that injects
  the token from config or a file; health checks stay unauthenticated
- dragonfly-client-config: token/token_file/audience knobs for manager,
  scheduler and dfdaemon gRPC endpoints, with validation at load time
- manager/scheduler/dfdaemon clients and dynconfig use the interceptors;
  when no token is configured the previous unauthenticated behaviour is kept
  and a warning is logged once
- docs/grpc-jwt-auth.md documents the claim layout and rollout

Tests: 18 grpc tests pass (token accepted/rejected, expired, tampered
signature, malformed token, file-based token, no-token dev mode).

Signed-off-by: DoubleCore <851678303@qq.com>
HealthClient::connect needs the tonic transport feature, which this
workspace does not enable, so the test target failed to compile. Construct
the channel via Endpoint::from_shared().connect() and use
HealthClient::new(), matching check_with_interceptor above.

Also restore opentelemetry-semantic-conventions to =0.33.1 and rebuild
Cargo.lock from the base revision; the previous lockfile downgraded
unrelated dependencies.

Verified: cargo check -p dragonfly-client --all-targets (clean);
cargo test -p dragonfly-client --lib grpc::interceptor -> 12 passed, 0 failed.

Signed-off-by: DoubleCore <851678303@qq.com>
@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.88586% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.78%. Comparing base (88fc6da) to head (b90dec0).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
dragonfly-client/src/grpc/interceptor.rs 90.64% 29 Missing ⚠️
dragonfly-client/src/grpc/scheduler.rs 0.00% 18 Missing ⚠️
dragonfly-client/src/grpc/manager.rs 11.76% 15 Missing ⚠️
dragonfly-client/src/grpc/dfdaemon_upload.rs 0.00% 6 Missing ⚠️
dragonfly-client/src/dynconfig/local.rs 85.71% 1 Missing ⚠️
dragonfly-client/src/dynconfig/mod.rs 0.00% 1 Missing ⚠️
dragonfly-client/src/dynconfig/remote.rs 85.71% 1 Missing ⚠️
dragonfly-client/src/grpc/dfdaemon_download.rs 83.33% 1 Missing ⚠️
dragonfly-client/src/grpc/health.rs 90.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2130      +/-   ##
==========================================
+ Coverage   65.76%   65.78%   +0.01%     
==========================================
  Files         102      102              
  Lines       31270    32190     +920     
==========================================
+ Hits        20566    21177     +611     
- Misses      10704    11013     +309     
Files with missing lines Coverage Δ
dragonfly-client-config/src/dfdaemon.rs 98.07% <100.00%> (+0.01%) ⬆️
dragonfly-client/src/dynconfig/local.rs 94.00% <85.71%> (+0.01%) ⬆️
dragonfly-client/src/dynconfig/mod.rs 0.00% <0.00%> (ø)
dragonfly-client/src/dynconfig/remote.rs 78.68% <85.71%> (+0.17%) ⬆️
dragonfly-client/src/grpc/dfdaemon_download.rs 5.39% <83.33%> (+0.12%) ⬆️
dragonfly-client/src/grpc/health.rs 41.55% <90.00%> (+4.05%) ⬆️
dragonfly-client/src/grpc/dfdaemon_upload.rs 0.00% <0.00%> (ø)
dragonfly-client/src/grpc/manager.rs 25.55% <11.76%> (-3.20%) ⬇️
dragonfly-client/src/grpc/scheduler.rs 50.98% <0.00%> (-0.57%) ⬇️
dragonfly-client/src/grpc/interceptor.rs 92.78% <90.64%> (-7.22%) ⬇️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DoubleCore

Copy link
Copy Markdown
Author

Kindly asking a maintainer to add one kind label (enhancement) to this PR.

Classify PR fails only because the label workflow requires exactly one of bug|enhancement|documentation|dependencies; a non-collaborator cannot apply labels.

@DoubleCore

Copy link
Copy Markdown
Author

Closing this PR myself: it duplicates CooooolFrog's #1987, which implements the same gRPC JWT authentication for issue #4417. To avoid wasting maintainer review time on duplicate work, I'm closing this one. The branch remains available in my fork if any incremental changes are needed for #1987.

@DoubleCore DoubleCore closed this Nov 7, 2026
@DoubleCore DoubleCore reopened this Nov 7, 2026
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.

2 participants