[BUG] Chart's kagent-api RemoteMCPServer never discovers tools under server.auth.mode: trusted-proxy (401 on initialize)

Đang mở
#3,506 2 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go, helm, kubernetes

Hướng nghiên cứu

Start with go/core/internal/service/tool/mcp.go and go/core/internal/httpserver/auth/proxy_authn.go, then inspect helm/kagent/templates/toolserver-api.yaml and the service account authentication configuration. Trace how control-plane discovery authenticates to the controller's own MCP endpoint and confirm the intended credential and audience. Done means kagent-api is accepted and discovers its tools in trusted-proxy mode without a user token.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

📋 Prerequisites
  • I have searched the existing issues to avoid creating a duplicate
  • By submitting this issue, you agree to follow our Code of Conduct
  • I am using the latest version of the software
  • I have tried to clear cache/cookies or used incognito mode (if ui-related)
  • I can consistently reproduce this issue
🎯 Affected Service(s)

Controller Service

🚦 Impact/Severity

Minor inconvenience

🐛 Bug Description

With config.server.auth.mode: trusted-proxy, the controller can't discover the tools on its own MCP endpoint. The Helm chart creates the RemoteMCPServer kagent-api (helm/kagent/templates/toolserver-api.yaml), and that object stays Accepted=False with reason DiscoveryFailed. The sessions, checkpoints and sandboxes tools never show up, so agents can't use them.

The controller authenticates /mcp with ProxyAuthenticator. That authenticator rejects any request without exactly one Authorization: Bearer <JWT> header (go/core/internal/httpserver/auth/proxy_authn.go:28-36). Discovery comes from the controller itself, through RuntimeMCPClient.connect (go/core/internal/service/tool/mcp.go:124). The only headers it sends are the ones the RemoteMCPServer resolves (server.ResolveHeaders, line 138), and the chart's kagent-api server defines none. connect also explicitly refuses actorJwt for control-plane calls (line 130). So the call reaches the controller with no credential and gets a 401.

Enabling config.server.auth.serviceAccount (the ServiceAccountProvider, audience kagent-invocation) doesn't help, because the discovery client never sends a service account token.

My guess is that this went unnoticed because trusted-proxy was only wired end to end recently (#2968). Before that the controller always ran unsecure, so self-discovery never had to authenticate.

🔄 Steps To Reproduce

Reproduced on 2026-11-03 on a local kind cluster, from a clean checkout of main at e3b80793, using the repository's own dev targets.

  1. Create the cluster and install kagent with Substrate and the dev database. The default auth mode is insecure.
    git clone https://github.com/kagent-dev/kagent && cd kagent
    make create-kind-cluster
    make build kagent-cli-deploy
    
  2. Confirm that kagent-api discovers its tools in the default mode:
    kubectl --context kind-kagent -n kagent get remotemcpserver kagent-api \
      -o jsonpath='{.status.conditions[?(@.type=="Accepted")].message}{"\n"}'
    # Discovered 19 MCP tools
    
  3. Switch the controller to trusted-proxy. grpcReflection is only needed for the optional grpcurl check in step 6.
    helm --kube-context kind-kagent -n kagent upgrade kagent "dist/kagent-$(git describe --tags --always).tgz" \
      --reuse-values \
      --set config.server.auth.mode=trusted-proxy \
      --set config.server.auth.userIdClaim=email \
      --set config.server.grpcReflection=true --wait
    kubectl --context kind-kagent -n kagent rollout status deploy/kagent-controller
    
  4. Force a fresh discovery, so the status doesn't still come from the insecure run. The reconciler watches label changes.
    kubectl --context kind-kagent -n kagent label remotemcpserver kagent-api repro="$(date +%s)" --overwrite
    
  5. Read the status and the controller logs:
    kubectl --context kind-kagent -n kagent get remotemcpserver kagent-api \
      -o jsonpath='{range .status.conditions[*]}{.type}={.status} {.reason}: {.message}{"\n"}{end}'
    # Accepted=False DiscoveryFailed: Failed to connect to MCP server: failed to connect MCP client: calling "initialize": sending "initialize": Unauthorized
    kubectl --context kind-kagent -n kagent logs deploy/kagent-controller | grep -m1 'Reconciler error'
    
  6. (Optional) A signed-in user calling a kagent-api tool through the API fails the same way. Under trusted-proxy the controller reads the token's email claim without verifying the signature, so an unsigned test token works:
    b64() { printf '%s' "$1" | base64 | tr '+/' '-_' | tr -d '='; }
    TOKEN="$(b64 '{"alg":"HS256","typ":"JWT"}').$(b64 '{"email":"[email protected]"}').dGVzdA"
    kubectl --context kind-kagent -n kagent run grpcurl --rm -i --restart=Never --image=fullstorydev/grpcurl:v1.9.3 -- \
      -plaintext -H "authorization: Bearer $TOKEN" \
      -d '{"server":{"ref":{"namespace":"kagent","name":"kagent-api"},"group_kind":"RemoteMCPServer.api.kagent.dev"},"tool_name":"list_agents"}' \
      kagent-controller.kagent.svc.cluster.local:8083 kagent.api.v1.ToolService/CallMCPAppTool
    # ERROR: Code: Internal  Message: internal server error
    
    Setting config.server.auth.mode=insecure again and repeating step 4 brings back Accepted=True with 19 tools.
🤔 Expected Behavior

kagent-api is Accepted=True and its tools are discovered, the same as with mode: insecure. The controller's calls to its own endpoint authenticate with a credential the controller can verify, without a user token and without needing an authenticating proxy in front of the controller.

📱 Actual Behavior

The RemoteMCPServer status:

Accepted=False reason=DiscoveryFailed
message: Failed to connect to MCP server: failed to connect MCP client: calling "initialize": sending "initialize": Unauthorized

The controller logs Reconciler error for RemoteMCPServer kagent/kagent-api, retrying with backoff.

💻 Environment
  • Kubernetes version: 1.37
  • Kubernetes provider: AWS (EKS)
  • Application version: kagent 1.0.0-rc1 (chart and images). The code involved is unchanged on main at 3b28b6b7.
  • Agent Substrate 1.0.0-rc1
  • Also reproduced on kind (Kubernetes 1.35, make create-kind-cluster) from main at e3b80793, with the steps above.
🔍 Additional Context
  • Did this work before? On 1.0.0-alpha17 with the same values, kagent-api discovered its tools. That release never actually applied trusted-proxy (#2968), so it wasn't really a working configuration.
  • Workarounds:
    • mode: insecure makes discovery work, but it gives up per-user identity, so it isn't usable for us.
    • Putting a static Authorization header on the RemoteMCPServer through headersFrom would mean minting a long-lived token. Under trusted-proxy that token would be an unverified user JWT. We don't want either.
  • Possible fix, for maintainers to confirm: for control-plane MCP calls to the controller's own endpoint, RuntimeMCPClient could attach a projected service account token with audience kagent-invocation, and the existing ServiceAccountProvider would verify it. The chart would then enable server.auth.serviceAccount whenever mode is trusted-proxy, or the controller would always trust its own service account. I'm happy to work through the approach here or in #kagent-dev before opening a PR.
📋 Logs
$ kubectl -n kagent get remotemcpserver kagent-api
NAME         PROTOCOL          URL                                                          ACCEPTED
kagent-api   STREAMABLE_HTTP   http://kagent-controller.kagent.svc.cluster.local:8083/mcp   False
🙋 Are you willing to contribute?
  • I am willing to submit a PR to fix this issue
Ngôn ngữ chính
Go
Star
4.5k
Fork
937
Merge trung bình
1 ngày 10 giờ
Pull request đã merge (30 ngày)
150

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của kagent-dev/kagent

Tất cả issue của kagent-dev/kagent

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.