GraphQL userAccessAuthorizedAgents returns an empty list for an admin in admin mode
Summary
Project.userAccessAuthorizedAgents returns an empty list for an instance administrator in admin mode who is not a member of the project. A user with the Developer role on the same project gets the expected list.
The field is authorized with :read_cluster_agent, which an administrator passes, so the query succeeds and returns no data. There is no permission error, so the field looks like it is telling you no agent is authorized.
Steps to reproduce
You need a GitLab Self-Managed instance or a GDK, because admin mode is not available to you on GitLab.com.
-
Create a group
example-groupwith two projects,agent-projectanddeployment-project. -
In
agent-project, create an agent for Kubernetes namedmy-agent, and commit this configuration file to the default branch:# .gitlab/agents/my-agent/config.yaml user_access: access_as: agent: {} projects: - id: example-group/deployment-projectThe push to the default branch registers the user access authorization. You do not have to install
agentkin a cluster, because the bug is in how GitLab resolves the authorization. -
Add a second user as a Developer on
deployment-project. -
Sign in as that Developer and run the query in
/-/graphql-explorer:query { project(fullPath: "example-group/deployment-project") { userAccessAuthorizedAgents { nodes { agent { name project { fullPath } } } } } }my-agentis listed. This confirms the setup works. -
Sign in as an instance administrator who is not a member of
example-group,agent-projectordeployment-project, and enable admin mode. -
Run the same query again.
nodesis empty.
What is the current bug behavior?
The administrator in admin mode gets an empty list:
{ "data": { "project": { "userAccessAuthorizedAgents": { "nodes": [] } } } }What is the expected correct behavior?
The administrator in admin mode gets the same list as the Developer:
{
"data": {
"project": {
"userAccessAuthorizedAgents": {
"nodes": [
{
"agent": {
"name": "my-agent",
"project": { "fullPath": "example-group/agent-project" }
}
}
]
}
}
}
}Output of checks
Reproduced on GitLab 19.3.0-pre. This is not a regression: the two scopes below have had no admin path since they were added.
Possible fixes
Both scopes behind Clusters::Agents::Authorizations::UserAccess::Finder resolve authorizations from membership alone, and neither has an admin path:
ProjectAuthorization.for_userjoinsproject_authorizationsand filters onuser_idGroupAuthorization.for_userbuilds from the user's group memberships
An administrator without an explicit membership matches neither, so the finder returns nothing.
The finder is the right place for the fix. It has six callers, and all six have the same bug, so an administrator in admin mode is also rejected by the KAS user access proxy and by the environment services when setting a cluster agent on an environment.
Fix proposed in !169626 (merged).