Job Access Tokens || Authorize REST API calls to access resources in ADO using Job Access Tokens

 Author: Akhil M Anil || DevOps Engineer


For applications that interface with Azure DevOps Services, you must authenticate to gain access to resources like REST APIs. There are different ways to authenticate our applications with Azure DevOps Services. In this article we will use job access token/system access token (SYS_TOKEN) to authenticate into Azure DevOps.

A job access token is a security token that is dynamically generated by Azure Pipelines for each job at run time. The agent on which the job is running uses the job access token in order to access these resources in Azure DevOps. It is fully possible to use System Access Tokens and eliminate the need for PATs in ADO pipeline for authorize the REST API calls to ADO. Furthermore, there is no need to save any credentials to files on disc and the System Access Tokens can be leveraged transiently as environment variables scoped to a specific job.

The token's permissions are derived from

  1. job authorization scope
  2. the permissions you set on project or collection build service account.

Job authorization scope

You can set the job authorization scope to be collection or project.By setting the scope to collection, you choose to let pipelines access all repositories in the collection or organization. By setting the scope to project, you choose to restrict access to only those repositories that are in the same project as the pipeline.

Job authorization scope can be set for the entire Azure DevOps organization or for a specific project

  • To set job authorization scope at the organization level for all projects, choose Organization settings > Pipelines > Settings.
  • To set job authorization scope for a specific project, choose Project settings > Pipelines > Settings.
Enable one or more of the following settings. Enabling these settings are recommended, as it enhances security for your pipelines.
  • Limit job authorization scope to current project for non-release pipelines- This setting applies to YAML pipelines and classic build pipelines and does not apply to classic release pipelines.
  • Limit job authorization scope to current project for release pipelines- This setting applies to classic release pipelines only.

ADO Pipeline Usage of System Access Token

Yaml Code

Python file code

Experimental Connecting to ADO and List all the pipelines

Find source code here: System Access Token
azure-pipelines.yml


pipeline.py


Connect me via:

References: 

Comments

Popular posts from this blog

Configure an Azure DevOps self-hosted Windows agent in Docker

Install Java silently using powershell in Azure Windows VM

List of Repositories - Authorize Rest API calls using Job Access Token