Access Denied problems in Azure DevOps pipeline - azure

We have created an Azure Virtual machine scale set agent pool and started the pipeline in the agent pool. We faced Access Denied problems in the jobs due to the tasks not running in the admin mode (CMD, PowerShell, and Final builder) on the VMSS instance. We need to run these tasks in admin mode in the Agent pool.
We couldn’t run an console application too with admin privileges in the VM.
Please provide any suggestions to resolve this issues.
VMSS Agent Pool:
Pipeline:
Access Denied Issue:

After you setup the scale set agent pool in Azure DevOps, it will use machinename\azdevops to run the pipeline task(can validate with 'whoami' in the task as below):
Remote to the target Scale set VM, the user is "Administrator" by default, the account has administrator permission.
I can create a file with the account in pipeline.
We couldn’t run an console application too with admin privileges in the VM.
If you cannot run the application with admin permission directly on VM, suspect it could be blocked the policy which should come from VMSS policy not DevOps.
It's recommended to create a new VMSS, and use it for DevOps agent for a check.

Related

Service Principal with Contributor role cannot access the resource and cannot see the resource with "az resource list"

I have an Azure subscription with ACR and App Configuration services.
I am implementing a pipeline that access Azure through DevOps Service Connection that has Contributor role for both resources. However, using Az Client task pipeline cannot see or access those resources.
If I execute "az resources list" I don't see those resources even though Service Connection has access to them.
I have the same setup working on my personal subscription. What am I missing?
Tried to reproduce same scenario in my personal subscription and it worked with the same level of access for Service Connection.
Also it works in PowerShell console with a user account with the same permissions.

Azure CLI not found in Jenkins

I have install azure cli plugins in jenkins after that i setup Azure Service Principal and got Successfully verified the Microsoft Azure Service Principal after that i create a new job and added az version to check az is installed or not in it and got failed error below is the screenshot of that error
Note:- My Jenkins is having v2.332.1 and installed in AKS Cluster as a Helm chat my jenkins is running
Here is the screenshot of plugin installed
Here is the my job new create in freestylejob
Please help out with this issue
You need to install azure cli in the Jenkins Host as well.
from
https://plugins.jenkins.io/azure-cli/ - Prerequisites
To use this plugin, first you need to have an Azure Service Principal
in your Jenkins instance.
1.Create an Azure Service Principal through Azure CLI or Azure portal.
2.Open Jenkins dashboard, go to Credentials, add a new Microsoft Azure Service Principal with the credential information you just created.
3.Install Azure CLI in the Jenkins Host
from your description, I can see you have 1,2 steps completed and possibly 3 is missing.

Azure DevOps Pipeline - Pushing to Azure Container Registry - Permission error

I have created an Azure Container Registry.
I have an Azure DevOps project.
I have created an Azure DevOps Pipeline using the wizard so
that it uses the standard template to build and push a Docker image.
When validating the Pipeline the following error is thrown:
Failed to set Azure permission 'RoleAssignmentId: ****' for the service principal '****' on subscription ID '****': error code: Forbidden, inner error code: AuthorizationFailed, inner error message The client '****' with object id '****' does not have authorization to perform action 'Microsoft.Authorization/roleAssignments/write' over scope '/subscriptions/****/resourceGroups/****/providers/Microsoft.ContainerRegistry/registries/****/providers/Microsoft.Authorization/roleAssignments/****' or the scope is invalid. If access was recently granted, please refresh your credentials. Ensure that the user has 'Owner' or 'User Access Administrator' permissions on the Subscription.
What configuration could I be missing? The documentation for this is all very sparse and written as though it should all just work.
Thanks
You need to add AcrPull permission to service principal you used here. Please got to you ACR and add it.
Here you have id of you service principal:
Failed to set Azure permission 'RoleAssignmentId: ' for the service principal ''
Also please check also networking on ACR if it blocks you or not.
To build and push your Docker image in Azure pipeline, you need follow the steps below:
Navigate to Project Settings > Service connections to create a Docker Registry service connection that can connect to your ACR.
In the pipeline, add the Docker task to build and push your Docker image to ACR.
Yours service principal on service connection is missing permissions link to documentation https://learn.microsoft.com/en-us/azure/container-registry/container-registry-roles?tabs=azure-cli. You can use custom role or build like contributor on resource group level. Example of custom role and allowed actions "Microsoft.ContainerRegistry/registries/push/write",

How to create Azure Devops service connection using system.accesstoken in a script

I want to create a "Service Connection" using system.accesstoken of Azure devops instead of using "PAT" of the user.
what are the permissions that should be given to system.accesstoken to create a service connection.
I tried giving all the access to "Project Collection Build Service ({OrgName})", "{Project Name} Build Service ({Org Name})" identities. But it did not work.
You need to define role on service connection security tab for Project Collection Build Service (account):

Unable to access keyvault from Azure DevOps from a different resource description

I'm attempting to build out my DevOps pipeline to deploy a DataFactory, Databricks Notebooks & Azure Data Warehouse,
I have my resource subscriptions setup for both Dev and Prod. deploying to Prod is more tricky than it seems.
my keyvault has GET/LIST Permissions for both Secret & Keys for the Target DataFactory.
https://learn.microsoft.com/en-us/azure/data-factory/continuous-integration-deployment
I have used the above guide to setup my target data factory in prod - and it is stood up correctly with all the connection strings setup and keyvault permissions set.
but I am stuck on this portion :
Grant permissions to the Azure Pipelines agent The Azure Key Vault
task may fail with an Access Denied error if the proper permissions
aren't present. Download the logs for the release, and locate the .ps1
file with the command to give permissions to the Azure Pipelines
agent. You can run the command directly, or you can copy the principal
ID from the file and add the access policy manually in the Azure
portal. Get and List are the minimum permissions required.
when I deploy my release I get the following error on the KeyVault task :
The specified Azure service connection needs to have Get, List secret management permissions on the selected key vault. To set these permissions, download the ProvisionKeyVaultPermissions.ps1 script from build/release logs and execute it, or set them from the Azure portal
I've added this power shell script ProvisionKeyVaultPermissions.ps1 to my repo and added it to my task but it just runs forever ? unsure if I'm missing something here.
hope this is clear/ please ask for any additional info.
I wonder if it's the DevOps service connection that's missing the permissions.
You can check access policies for the vault from the console. You should see your service connection as an APPLICATION; it needs the GET and LIST privileges as the document your following says. My understanding is that these are privileges for the account that's deploying your code, rather than the account that will run your code.

Resources