Typically, agents are owned by a single project and shared with multiple deployment projects. Project members in the agent owner project can see the list of agents from "Infrastructure > Kubernetes clusters" page, however, project members in deployment projects might not have access to the owner project thus have no idea what agents are available in the project.
Similarly, we recently added a feature to allow users to access agent via user_access keyword. This authentication requires Agent ID, however, project members in the deployment projects might not have access to the owner project thus can't fetch the Agent ID for the authentication. This effectively limits the feature usage to be inside the owner project only.
Proposal
Show shared agents in deployment projects from "Infrastructure > Kubernetes clusters" page. In this page, users see:
Shared agent names, IDs and it's connection status.
Shared by - The agent owner project that allowed the access to the agent(s).
Which keyword is used for sharing, either ci_access, user_access or both.
Permissions in the cluster with the given impersonation. i.e. ClusterRoleBinding or RoleBinding details of the impersonated service account.
Future iteration: View resources in the cluster via Kubernetes Dashboard. (user_access only)
Future iteration: Connect to the Agent via Web Terminal. (user_access only)
One of main purposes in this iteration is to let deployment project see shared agents. To do so, we need to properly fix Agent permission in GitLab side.
We likely use Clusters::Agents::ProjectAuthorization and Clusters::Agents::GroupAuthorization for fetching available agent list.
Introduce read_cluster_agent permission. Stop reusing read_cluster as it technically infers deprecated certificate-based cluster integration.
If you are unsure about the correct group, please do not leave the issue without a group label, and refer to
GitLab's shared responsibility functionality guidelines
for more information on how to triage this kind of issue.
@emilybauman I'll move this to workflowready for design as I'd like your input on the preferred columns. Unfortunately, I removed the proposal from Shinya and now we only have the group level designs from Ali (linked in the description).
@anna_vovchenko - Thanks for putting together the proposals here!
I like option 3, but we could change the badges to be grey (info) and on the right side of the agent name. That being said, is there a good reason or data showing that users may want to have the agents separated out by project and shared? If so, we could look towards something like option 1.
@anna_vovchenko - Now seeing it visualized I actually preferred your proposal. The thing that was throwing me off is green badges are supposed to be used when:
Success: Metadata that communicates success or completion with a positive meaning.
Let me do a bit of digging to see if green and blue are okay colour combos (or we could do blue and grey). I do see we do it in runners, so there might be some flexibility here.
@emilybauman, as an option, we could also not drive much user attention to the agent origin. We can add a small copy to the shared agent as clicking on its name will navigate the user to a different project:
I missed it in my previous screenshots, but we won't be able to show the agent's configuration for the shared agent as easily - we are only getting this configurations list per project.
@anna_vovchenko - I like that idea, we could even use just the dimmed grey badge here to call out shared agents and leave non-shared as is with no badge. It would show the difference quite well, but not overwhelm the page. Thanks for the proposals.
I missed it in my previous screenshots, but we won't be able to show the agent's configuration for the shared agent as easily - we are only getting this configurations list per project.
I think the idea of writing out external project or just some content to call this out should be enough. We can link them to the docs for MVC if anything.
Should we create an issue for that? It looks like #391610 (closed) is closed due to being duplicated, but the linked duplicate issue is #396407 (closed), which doesn't seem to be the same thing. I think we probably need to implement #396407 (closed) first then re-open #391610 (closed).
2. Introduce something like a read_cluster_agent policy that reads the persisted GitLab agent permissions (both from user_access and ci_access), and can be used from the deployment projects
At the moment, I think we don't need to do Allow users to read agent information if they'r... (#391610 - closed) as it's more like a hacky solution as compared to this issue. From data modeling perspective, we should have "shared agents" attributes/models inside the codebase, i.e. a deployment project fetch shared Clusters::Agent without explicitly querying to the agent management project.
Just to make sure I'm understanding this correctly:
Are we going to use the :read_cluster policy for checking access to these new features? (The :read_cluster is connected to the Project, so I think it should be okay.)
#396407 (closed) isn't blocked by anything related to policies, but by the ability to fetched the shared agents, which will be implemented in this issue.
Are we going to use the :read_cluster policy for checking access to these new features? (The :read_cluster is connected to the Project, so I think it should be okay.)
For now, we're going to use :read_cluster policy, but
we would create :read_cluster_agent if it's necessary. This allows us to perform more granular authorization with user.can?(:read_gitlab_agent_for_kubernetes, agent) (i.e. hook AgentPolicy), instead of checking it against user.can?(:read_cluster, agent.project) (i.e. ProjectPolicy). The output of DeclarativePolicy should look like following:
agent_management_project=Project.find()agent_management_project_user=User.find()shared_agent=agent_management_project.cluster_agents.firstagent_deployment_project=Project.find()agent_deployment_project_user=User.find()agent_management_project_user.can?(:read_cluster_agent,agent_management_project)# => trueagent_management_project_user.can?(:read_cluster_agent,shared_agent)# => trueagent_deployment_project_user.can?(:read_cluster_agent,agent_management_project)# => false, because it might contain other agents that are not shared.agent_deployment_project_user.can?(:read_cluster_agent,shared_agent)# => true
#396407 (closed) isn't blocked by anything related to policies, but by the ability to fetched the shared agents, which will be implemented in this issue.
The ability to fetch shared agents should be guarded by policies. So I consider this issue is to do some groundwork that making sure fetch and policy are correctly implemented, so that we don't need to revisit the policy in Allow to Select Agent in Environment setting page (#396407 - closed) and it can simply use existing functionalities, such as finders.