fix(auth): accept hyphenated agent metadata (#1197)

This commit is contained in:
zhdsmy
2026-06-05 09:06:38 +08:00
committed by GitHub
parent c3c361ad66
commit 4289d30357
2 changed files with 31 additions and 8 deletions
+11 -8
View File
@@ -39,10 +39,7 @@ func (a *authHandler) check(ctx context.Context) (uint64, error) {
return 0, status.Errorf(codes.Unauthenticated, "获取 metaData 失败")
}
var clientSecret string
if value, ok := md["client_secret"]; ok {
clientSecret = strings.TrimSpace(value[0])
}
clientSecret := firstMetadataValue(md, "client-secret", "client_secret")
if clientSecret == "" {
return 0, status.Error(codes.Unauthenticated, "客户端认证失败")
@@ -50,10 +47,7 @@ func (a *authHandler) check(ctx context.Context) (uint64, error) {
ip, _ := ctx.Value(model.CtxKeyRealIP{}).(string)
var clientUUID string
if value, ok := md["client_uuid"]; ok {
clientUUID = value[0]
}
clientUUID := firstMetadataValue(md, "client-uuid", "client_uuid")
if _, err := uuid.ParseUUID(clientUUID); err != nil {
// Keep this counter on the same trigger surface as the
@@ -183,6 +177,15 @@ func (a *authHandler) check(ctx context.Context) (uint64, error) {
return clientID, nil
}
func firstMetadataValue(md metadata.MD, keys ...string) string {
for _, key := range keys {
if value, ok := md[key]; ok && len(value) > 0 {
return strings.TrimSpace(value[0])
}
}
return ""
}
// authorizeAgentForUUID resolves a client UUID to the dashboard's internal
// server ID, ensuring the resolved server is actually owned by the agent
// secret's owner. Previously Check returned the resolved server ID without