go auth_error ai_generated true

rpc 错误:代码 = Unauthenticated 描述 = 缺少凭据

rpc error: code = Unauthenticated desc = missing credentials

ID: go/grpc-unauthenticated-missing-credentials

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2024-11-20首次发现

版本兼容性

版本状态引入弃用备注
1.56.x active
1.57.x active

根因分析

客户端未在请求元数据中提供任何身份验证凭据。

English

The client did not provide any authentication credentials in the request metadata.

generic

解决方案

  1. 100% 成功率
    md := metadata.Pairs("authorization", "Bearer mytoken"); ctx := metadata.NewOutgoingContext(context.Background(), md)
  2. 90% 成功率
    creds := credentials.NewClientTLSFromCert(nil, ""); conn, err := grpc.Dial(address, grpc.WithTransportCredentials(creds))
  3. 85% 成功率
    interceptor := func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { ctx = metadata.AppendToOutgoingContext(ctx, "authorization", "Bearer mytoken"); return invoker(ctx, method, req, reply, cc, opts...) }

无效尝试

常见但无效的做法:

  1. Sending an empty token or user/pass. 90% 失败

    Server still sees no valid credentials.

  2. Removing auth checks. 80% 失败

    Security risk.

  3. Not adding any metadata. 100% 失败

    Same error will occur.