go auth_error ai_generated true

rpc错误:代码=权限被拒绝 描述=用户无权访问此资源

rpc error: code = PermissionDenied desc = user does not have permission to access this resource

ID: go/grpc-permission-denied-role

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

版本兼容性

版本状态引入弃用备注
1.22 active
1.23 active

根因分析

经过身份验证的用户缺少请求RPC所需的角色或权限,由服务器端授权逻辑强制执行。

English

The authenticated user lacks the required role or permissions for the requested RPC, as enforced by server-side authorization logic.

generic

解决方案

  1. 90% 成功率 Request elevated permissions from the admin and use a new token.
    token := getAdminToken() // obtain token with required role
    md := metadata.Pairs("authorization", "Bearer "+token)
    ctx := metadata.NewOutgoingContext(context.Background(), md)
  2. 85% 成功率 Use a service account with necessary roles if available.
    // Configure gRPC with service account credentials
    conn, _ := grpc.Dial(target, grpc.WithPerRPCCredentials(oauth.NewServiceAccountTokenSource("path/to/key.json", "scope")))

无效尝试

常见但无效的做法:

  1. Re-authenticating with the same credentials. 100% 失败

    Same user, same permissions; still denied.

  2. Using a different RPC with the same user. 80% 失败

    Permission issue is user-specific, not method-specific.