-
Notifications
You must be signed in to change notification settings - Fork 0
AzDoGitPermission
The AzDoGitPermission DSC resource is used to manage permissions on Git repositories within an Azure DevOps project. It allows you to define and enforce the desired state of permissions assigned to groups or users for specific repositories or repository paths, including whether permissions are inherited from parent scopes.
AzDoGitPermission [string] #ResourceName
{
ProjectName = [String] $ProjectName
[ RepositoryName = [String] $RepositoryName ]
[ isInherited = [Boolean] $isInherited ]
[ Permissions = [Hashtable[]] $Permissions ]
[ Ensure = [String] {'Present', 'Absent'} ]
[ DependsOn = [String[]] ]
[ PsDscRunAsCredential = [PSCredential] ]
}- ProjectName [String] - The name of the Azure DevOps project. This is the unique identifier for the project in which the Git permissions are managed.
-
RepositoryName [String] - The name of the Git repository within the project. If not specified, permissions apply to all repositories in the project. Default is
$null. -
isInherited [Boolean] - Specifies whether the permissions are inherited from the parent project or repository scope. Default is
$true. When set to$false, only explicitly assigned permissions apply. -
Permissions [Hashtable[]] - An array of hashtables specifying the Git repository permissions to be assigned. Each hashtable should contain:
-
Permission- The name of the Git permission (e.g., 'Read', 'Contribute', 'ForcePush', 'CreateBranch', 'CreateTag', 'Administer') -
Allow- Boolean value indicating whether the permission is allowed -
Deny- Boolean value indicating whether the permission is explicitly denied
-
-
Ensure [String] - Desired state of the resource:
-
'Present'- (default) Repository permissions should exist -
'Absent'- Repository permissions should be removed
-
-
DependsOn [String[]] - Dependencies on other resources. Use this to control the order of resource execution.
-
PsDscRunAsCredential [PSCredential] - Credentials to run this resource under.
The resource returns the following properties:
- ProjectName - The name of the project
- RepositoryName - The name of the repository (if specified)
- isInherited - Whether permissions are inherited
- Permissions - The current Git permissions assigned
- Ensure - Current state ('Present' or 'Absent')
Configuration ConfigureRepositoryRead {
Import-DscResource -ModuleName 'AzureDevOpsDscNative'
Node localhost {
AzDoGitPermission 'AllReposRead' {
ProjectName = 'MyProject'
RepositoryName = $null
isInherited = $false
Permissions = @(
@{
Permission = 'Read'
Allow = $true
}
)
Ensure = 'Present'
}
}
}
ConfigureRepositoryRead
Start-DscConfiguration -Path ./ConfigureRepositoryRead -Wait -VerboseConfiguration ConfigureRepositoryContribute {
Import-DscResource -ModuleName 'AzureDevOpsDscNative'
Node localhost {
AzDoGitPermission 'MainRepoContribute' {
ProjectName = 'MyProject'
RepositoryName = 'MainRepository'
isInherited = $false
Permissions = @(
@{
Permission = 'Read'
Allow = $true
},
@{
Permission = 'Contribute'
Allow = $true
},
@{
Permission = 'CreateBranch'
Allow = $true
}
)
Ensure = 'Present'
}
}
}
ConfigureRepositoryContribute
Start-DscConfiguration -Path ./ConfigureRepositoryContribute -Wait -VerboseConfiguration ConfigureAdvancedRepositoryPermissions {
Import-DscResource -ModuleName 'AzureDevOpsDscNative'
Node localhost {
AzDoGitPermission 'DevelopmentRepoAdvanced' {
ProjectName = 'MyProject'
RepositoryName = 'DevelopmentRepository'
isInherited = $false
Permissions = @(
@{
Permission = 'Read'
Allow = $true
},
@{
Permission = 'Contribute'
Allow = $true
},
@{
Permission = 'ForcePush'
Allow = $false
},
@{
Permission = 'Administer'
Allow = $false
},
@{
Permission = 'CreateTag'
Allow = $true
}
)
Ensure = 'Present'
}
}
}
ConfigureAdvancedRepositoryPermissions
Start-DscConfiguration -Path ./ConfigureAdvancedRepositoryPermissions -Wait -Verbose# Get current Git repository permissions
$properties = @{
ProjectName = 'MyProject'
RepositoryName = 'MainRepository'
}
$result = Invoke-DscResource -Name 'AzDoGitPermission' `
-Method Get `
-Property $properties `
-ModuleName 'AzureDevOpsDscNative'
$result | Select-Object ProjectName, RepositoryName, isInherited, Permissions
# Set new permissions
$setProperties = @{
ProjectName = 'MyProject'
RepositoryName = 'MainRepository'
isInherited = $false
Permissions = @(
@{ Permission = 'Read'; Allow = $true },
@{ Permission = 'Contribute'; Allow = $true }
)
Ensure = 'Present'
}
Invoke-DscResource -Name 'AzDoGitPermission' `
-Method Set `
-Property $setProperties `
-ModuleName 'AzureDevOpsDscNative'- When
RepositoryNameis not specified ($null), permissions apply to all Git repositories in the project - When
RepositoryNameis specified, permissions apply only to that specific repository - Repository names are case-sensitive and must match exactly
- Read - Allows users to clone and pull from the repository
- Contribute - Allows users to push commits to the repository
- ForcePush - Allows users to force push changes (bypass merge restrictions)
- CreateBranch - Allows users to create new branches
- CreateTag - Allows users to create tags
- DeleteRepository - Allows deletion of the entire repository
- Administer - Provides full administrative control over the repository
- Permissions set at the project level cascade to all repositories unless explicitly overridden
- Repository-level permissions override project-level permissions
- Branch-level permissions can provide additional granularity
Cause: The specified repository name does not exist in the project.
Solution:
# Verify the repository name exists in the project
# Check in Azure DevOps Repos section
# Ensure you are using the exact repository name (case-sensitive)Cause: The specified permission name is not a valid Git permission.
Solution:
# Use valid Git permissions:
# Read, Contribute, ForcePush, CreateBranch, CreateTag, DeleteRepository, AdministerCause: The resource manages permissions at the repository level, not individual file paths.
Solution:
- Use Azure DevOps branch policies and protection rules for path-specific access control
- Configure repository-wide permissions using this resource
- Consider multiple repositories if different teams need different access levels
- AzDoGitRepository - Create and manage Git repositories
- AzDoProjectPermission - Manage project-level permissions
- AzDoProjectGroup - Manage project groups and their membership
- AzDoSecurityNamespacePermission - Manage custom security namespace permissions