How can we implement security for agent pools in Azure Devops - azure-devops

How can we restrict access to agent pools for certain groups in azure devops. As of now everyone has the access to agent pool . I need to manage that access. Any one please help

In the Azure DevOps agent pool, We can configure different permissions by updating user roles. Such as configure the agent permissions to restrict user or group access the agent pool.
Steps:
Open org setting-> agent pools->select agent pool->click the tab Security->remove the user or permission group
Result: the user or group member cannot access the agent pool.
Please refer the doc Security of agent pools and About security roles for more details.

Related

What is the "User" role in Azure Agent Pools?

In the documentation page Create and manage agent pools, there's a table listing the different security roles related that are available for agent pools.
It's divided to "Roles on an agent pool in project settings" and "Roles on an agent pool in organization settings".
In the "Roles on an agent pool in project settings", there's a role "User":
Members of this role can use the project agent pool when authoring pipelines.
I can't understand what this means.
First, it's not very clear what it means to "Author a pipeline".
Let's assume that it means creating a build definition. If so, then in order to "author" a pipeline a user must be in the "Build Administrators" group, and the "Build Administrators" group is automatically assigned a "Administrator" role on each agent pool in the project:
Turns out so, that if you have the permissions to author a pipeline (again, assuming that it means creating a build definition), you're automatically assigned an "Administrator" role on that agent pool.
Can someone explain?
Author a pipeline means that when creating a pipeline you could use this agent with the user role on the agent pool in project settings. For example, when you first run a yaml pipeline using this agent, you need to have user permission to permit it:
In order to create a pipeline, users do not need to be in "Build Administrator". Give user Edit build pipeline and Queue builds permission by setting pipeline permission in Pipeline >> Manage security button. Then user can create pipelines and save any changes to a build pipeline, including configuration variables, triggers, repositories, and retention policy. Please refer to Pipeline permissions reference.
Thanks to #JaneMa-MSFT, I realized that I can allow the user to create pipelines without being a member of the "Build Administrators" - one easy way is to assign it as a member of the "Contributors" group, which by default has permissions to create pipelines, so it is a possibility to be able to "author" a pipeline, and yet not have "User" role on the agent pool.
So what I found out is, that it doesn't really matter who "authored" the pipeline - i.e. created it. The effect of being a "User" on that agent pool (in the project level) is the ability to permit the pipeline to use that agent pool. By the way - if that agent pool is marked as "Grant access permissions to all pipelines" - this role doesn't have any meaning for that pipeline!

How to grant a service principal permissions to run Get-AzADServicePrincipal?

I want to get information about a service principal in an Azure PowerShell task in my DevOps pipeline using Get-AzADServicePrincipal but I get this error.
[Authorization_RequestDenied] : Insufficient privileges to complete the operation
The DevOps service principal has Contributor rights in the subscription.
I have created a custom role but unsure as to what permissions to assign to it so that I can run the command in my pipelines. My user account is Subscription Owner.
This error usually occurs when you do not have permission to read service principals, maybe Directory.Read.All or Application.Read.All are not being enabled. Please provide the service connection to those permissions by granting admin consent.
To enable that, go through the following steps:
Go to Azure Portal -> Azure Active Directory -> App Registrations -> Your DevOps resource -> API Permissions
Now, click on Grant Admin Consent and it will change the status to
granted (Green) .
After performing all these, redeploy the DevOps Pipeline and run Get-AzADServicePrincipal to get the information about service principal.
If still it does not work, assign Directory Readers and Application Administrator roles to service principal of DevOps pipeline.
References:
Service Principal considerations when using Azure DevOps to manage
RBAC on Azure Resource Groups | by Andrew Kelleher | Azure
Architects | Medium
Azure: permissions to list service principals - Stack Overflow

Getting an error when trying to create an agent pool

I am trying to create a new agent but getting below error.
Any idea what is causing the issue?
this error means you dont have enough permissions to perform that action. you need agent pool administrator permissions to create pools
As the Microsoft documents describes as below. Please follow the steps here to check if you have the proper administrator permission to register an agent.
To register an agent, you need to be a member of the administrator role in the agent pool. In addition, you must be a local administrator on the server in order to configure the agent.
You can also try using a Person Access Token with agent pools read&manage scope to register your agent.

Any way to limit which pools can contribute to an Artifact feed?

Given an Azure Artifacts Feed named 'deployables' (available to the Organization as a whole) and two Azure Pipelines agent pools (named 'Corporate' and 'Testing').
Is there a way to give the Corporate agent pool contributor access to the 'deployables' Artifacts feed but not to the 'Testing' pool?
Is there a way to give the Corporate agent pool contributor access to
the 'deployables' Artifacts feed but not to the 'Testing' pool?
I'm afraid Azure Devops does not provide the direct feature that agent pool can be limited to access Artifacts.
But as workaround, you can through specify the permission of user/group to achieve this indirectly. For instance, there is a group A which have access permission of Artifacts Feed 'deployables'. Give this group the access permission of 'Corporate' pool, BUT denyied in 'Testing' pool.

Access denied. Needs Use permissions for pool Default to perform the action

I get following error when trying to save a release pipeline on Azure dev. What exact permissions do I need to ask from my administrator?
Access denied. <<user id>> needs Use permissions for pool Default to perform the action. For more information, contact the Azure DevOps Server administrator.
I found granting Admin to a pool very confusing (and time-consuming to resolve) but I think I can explain how I got it to work for my org. This is a further explanation, based upon what #Leo Lui-MSFT said, as that was not quite clear enough for me.
My problem: I wanted to give a user access to update a pool that the user had not created (ie, was not an Owner).
Attempted solution: Making the user Admin on the pool did not let the user do that.
Successful solution: I had to go to https://dev.azure.com/my-org/_settings/agentpools > Security > Add . I then added the user and assigned the Admin role.
This has the side effect of giving the user Admin on every pool in the org (which was not what I wanted to do). If this is not your desire then go into the pool you do not wish to grant Admin access to, set Inheritance off and then remove the user from that pool.
This feels wrong, to me. I should have been able to make a user an Admin of a single pool without granting org-wide Admin over all pools.
Also as all pools seem to be created with Inheritance defaulted to true then to remove that user as an Admin from all other pools could be time-consuming and when more pools are created then I would need to remember to turn inheritance off.
That is my experience. If I have missed something please let me know.
What exact permissions do I need to ask from my administrator?
You need ask the User permissions from administrator.
When we go to Project Settings->Agent pools->The Agent Name->Security:
Check the document Security of agent pools for some more details.
Roles are also defined on each organization agent pool, and
memberships in these roles govern what operations you can perform on
an agent pool.
The All agent pools node in the Agent pools tab is used to control the
security of all project agent pools in a project. Role memberships for
individual project agent pools are automatically inherited from those
of the 'All agent pools' node. By default, the following groups are
added to the Administrator role of 'All agent pools': Build
Administrators, Release Administrators, Project Administrators.
So, you should ask User permissions from your administrator, or add your account to one of the groups mentioned above, then try it again.
I used -e AZP_POOL=XXX parameter when docker run to solve the same issue, even my account is an administrator.
Check if you are entering the pool name correctly. If you pressed 'Enter' to keep the default name for the pool, it does not work, you need to specify the correct name for the agent pool
I had similar problem with a Pipeline:
Error: Access Denied: 0000000d-0000-8888-8000-000000000000 needs the following permission(s) on the resource /Organizations to perform this action: Read Organization resources
I created again service connections and change this in the pipeline:
I think this user was delete from active directory.
(I realize this question is regarding DevOps but DevOps Server / TFS may have different interface but encounter the same issue)
In TFS or DevOps Server, you have to be added to Team Foundation Administrators group through TFS Admin Console only. To do that:
Access Team Foundation Server Administration Console via Server > Application Tier > Group Membership > Team Foundation Administrators > Properties > Add user.
You should have an organization level access to get rid of the error message you are getting.
If you've created the organization you will be the owner of the organization, you should have all the admin access to do whatever your pipeline need.
otherwise, Select the organization -> Go to organization settings -> agent pool [left plane] -> security [right top] -> add a new user with your name with admin role
Try the same with project level settings.