PSRule.Rules.AzureDevOps Token Permissions

December 24, 2023 ยท View on GitHub

Details on how to configure token permissions

PSRule.Rules.AzureDevOps requires a personal access token with the appropriate permissions to export data from Azure DevOps. When running PSRule.Rules.AzureDevOps you can choose 3 different token types:

  • FullAccess: Allows for full access to Azure DevOps, use with caution
  • FineGrained: Allows for fine-grained access to Azure DevOps, this is the recommended token type
  • ReadOnly: Allows for read-only access to Azure DevOps

FullAccess TokenType

The FullAccess token type is the most permissive and allows for maximum rule coverage. This token type is recommended for use with PSRule.Rules.AzureDevOps but should be used with caution. Check your organization's security policies before using this token type.

The FullAccess token type can be created in Azure DevOps by following these steps:

  1. Navigate to your Azure DevOps organization
  2. Select the User Settings option from the top right menu
  3. Select the Personal access tokens option from the menu
  4. Click the New Token button
  5. Enter a name for the token
  6. Select the Full access scope
  7. Click the Create button
  8. Copy the token value and store it in a secure location
  9. Use the token value in your pipeline

FineGrained TokenType

The FineGrained token type is the recommended token type for use with PSRule.Rules.AzureDevOps. This token type allows for fine-grained access to Azure DevOps and is the most secure token type that allows for near-maximum rule coverage while still offering a detailed overview of the required permissions.

The FineGrained token type can be created in Azure DevOps by following these steps:

  1. Navigate to your Azure DevOps organization
  2. Select the User Settings option from the top right menu
  3. Select the Personal access tokens option from the menu
  4. Click the New Token button
  5. Enter a name for the token
  6. Select the Custom defined scope
  7. Select Read for all scopes that have a Read option
  8. Select Read & Manage for all scopes that have a Read & Manage option
  9. Do not select any other scopes
  10. Click the Create button
  11. Copy the token value and store it in a secure location
  12. Use the token value in your pipeline

ReadOnly TokenType

The ReadOnly token type is the most restrictive and allows for read-only access to Azure DevOps. This token type is recommended for use with PSRule.Rules.AzureDevOps when your security policies do not allow for the use of the FullAccess or FineGrained token types.

The ReadOnly token type can be created in Azure DevOps by following these steps:

  1. Navigate to your Azure DevOps organization
  2. Select the User Settings option from the top right menu
  3. Select the Personal access tokens option from the menu
  4. Click the New Token button
  5. Enter a name for the token
  6. Select the Custom defined scope
  7. Select Read for all scopes that have a Read option
  8. Do not select any other scopes
  9. Click the Create button
  10. Copy the token value and store it in a secure location
  11. Use the token value in your pipeline

Token Scopes for module functions

The following table lists the token scopes that are required for each command.

Rule FunctionAPI(s)VersionMethodScope(s)PAT CategoryPAT Name
Get-AzDevOpsProjectprojects6.0GETvso.profileUser ProfileRead
vso.projectProject and TeamRead
Get-AzDevOpsPipelinespipelines6.0-preview.1GETvso.buildBuildRead
pipelines/{pipelineid}6.0-preview.1GETvso.buildBuildRead
Get-AzDevOpsPipelineAclsaccesscontrollists/{securityid}6.0GETvso.security_manageSecurityManage
Get-AzDevOpsPipelineYamlpipelines/{pipelineid}/runs5.1-previewPOSTvso.buildBuildRead
pipelines/{pipelineid}7.1-preview.1GETvso.buildBuildRead
git/repositories/{repositoryid}/items6.0GETvso.codeCodeRead
Get-AzDevOpsEnvironmentspipelines/environments6.0-preview.1GETvso.environment_manageAgent PoolsRead and Manage
vso.buildBuildRead
pipelines/checks/configurations7.2-preview.1GETvso.buildBuildRead
Get-AzDevOpsReleaseDefinitionsrelease/definitions7.2-preview.4GETvso.releaseReleaseRead
Get-AzDevOpsReleaseDefinitionAclsaccesscontrollists/{securityid}6.0GETvso.security_manageSecurityManage
Get-AzDevOpsPipelinesSettingsbuild/generalsettings7.1-preview.1GETvso.projectBuildRead
Get-AzDevOpsReposgit/repositories6.0GETvso.codeCodeRead
Get-AzDevOpsBranchPolicypolicy/configurations6.0GETvso.codeCodeRead
Get-AzDevOpsRepositoryPipelinePermissionspipelines/pipelinePermissions/repositoryGETvso.buildBuildRead
Get-AzDevOpsRepositoryAclsaccesscontrollists/{securityid}6.0GETvso.security_manageSecurityManage
Test-AzDevOpsFileExistsgit/repositories/{repositoryid}/items6.0GETvso.codeCodeRead
Get-AzDevOpsRepositoryGhasContribution/HierarchyQuery5.0-preview.1POSTtbctbcFullACcess
Get-AzDevOpsArmServiceConnectionsserviceendpoint/endpoints6.0-preview.4GETvso.serviceendpointService ConnectionsRead
Get-AzDevOpsArmServiceConnectionChecksbipelines/checks/configurations7.2-preview.1GETvso.buildBuildRead
Get-AzDevOpsVariableGroupsdistributed task/variablegroups7.2-preview.2GETvso.variablegroups_readVariable GroupsRead

Token Scopes for rules

The following table lists the token scopes that are required for each rule.

RuleMinimum TokenType
Azure.DevOps.Pipelines.Core.UseYamlDefinitionReadOnly
Azure.DevOps.Pipelines.Core.InheritedPermissionsFineGrained
Azure.DevOps.Pipelines.Core.NoPlainTextSecretsReadOnly
Azure.DevOps.Pipelines.PipelineYaml.AgentPoolVersionNotLatestReadOnly
Azure.DevOps.Pipelines.PipelineYaml.StepDisplayNameReadOnly
Azure.DevOps.Pipelines.Environments.DescriptionFineGrained
Azure.DevOps.Pipelines.Environments.ProductionBranchLimitFineGrained
Azure.DevOps.Pipelines.Environments.ProductionCheckProtectionFineGrained
Azure.DevOps.Pipelines.Environments.ProductionHumanApprovalFineGrained
Azure.DevOps.Pipelines.Releases.Definition.ProductionApprovalReadOnly
Azure.DevOps.Pipelines.Releases.Definition.SelfApprovalReadOnly
Azure.DevOps.Pipelines.Releases.Definition.InheritedPermissionsFineGrained
Azure.DevOps.Pipelines.Releases.Definition.NoPlainTextSecretsReadOnly
Azure.DevOps.Pipelines.Settings.LimitSetVariablesAtQueueTimeReadOnly
Azure.DevOps.Pipelines.Settings.LimitJobAuthorizationScopeReadOnly
Azure.DevOps.Pipelines.Settings.LimitJobAuthorizationScopeForReleasePipelinesReadOnly
Azure.DevOps.Pipelines.Settings.LimitJobAuthorizationScopeForYamlPipelinesReadOnly
Azure.DevOps.Pipelines.Settings.RequireCommentForPullRequestFromForkReadOnly
Azure.DevOps.Pipelines.Settings.RestrictSecretsForPullRequestFromForkReadOnly
Azure.DevOps.Pipelines.Settings.SanitizeShellTaskArgumentsReadOnly
Azure.DevOps.Repos.BranchPolicyAllowSelfApprovalReadOnly
Azure.DevOps.Repos.BranchPolicyCommentResolutionReadOnly
Azure.DevOps.Repos.BranchPolicyEnforceLinkedWorkItemsReadOnly
Azure.DevOps.Repos.BranchPolicyIsEnabledReadOnly
Azure.DevOps.Repos.BranchPolicyMergeStrategyReadOnly
Azure.DevOps.Repos.BranchPolicyMinimumReviewersReadOnly
Azure.DevOps.Repos.BranchPolicyRequireBuildReadOnly
Azure.DevOps.Repos.BranchPolicyResetVotesReadOnly
Azure.DevOps.Repos.HasBranchPolicyReadOnly
Azure.DevOps.Repos.LicenseReadOnly
Azure.DevOps.Repos.ReadmeReadOnly
Azure.DevOps.Repos.GitHubAdvancedSecurityEnabledFullAccess
Azure.DevOps.Repos.GitHubAdvancedSecurityBlockPushesFullAccess
Azure.DevOps.Repos.InheritedPermissionsFineGrained
Azure.DevOps.ServiceConnections.ClassicAzureReadOnly
Azure.DevOps.ServiceConnections.DescriptionReadOnly
Azure.DevOps.ServiceConnections.GitHubPATReadOnly
Azure.DevOps.ServiceConnections.ProductionBranchLimitReadOnly
Azure.DevOps.ServiceConnections.ProductionCheckProtectionReadOnly
Azure.DevOps.ServiceConnections.ProductionHumanApprovalReadOnly
Azure.DevOps.ServiceConnections.ScopeReadOnly
Azure.DevOps.ServiceConnections.WorkloadIdentityFederationReadOnly
Azure.DevOps.Tasks.VariableGroup.DescriptionReadOnly
Azure.DevOps.Tasks.VariableGroup.NoKeyVaultNoSecretsReadOnly
Azure.DevOps.Tasks.VariableGroup.NoPlainTextSecretsReadOnly