Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a custom role for accessing batch account #20

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions deploy/infra/groups/orchestration.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ module uami '../modules/managed.identity.user.bicep' = {
}
}

module batchAccountCustomRole '../modules/batch.account.custom.role.bicep' = {
name: '${namingPrefix}-batch-account-custom-role'
scope: subscription()
params: {
batchAccountName: toLower(batchAccountNameVar)
}
}

module batchAccount '../modules/batch.account.bicep' = {
name: '${namingPrefix}-batch-account'
params: {
Expand All @@ -175,6 +183,7 @@ module batchAccount '../modules/batch.account.bicep' = {
poolAllocationMode: batchAccountPoolAllocationMode
publicNetworkAccess: batchAccountPublicNetworkAccess
keyVaultName: keyvaultNameVar
assignRoleToUserManagedIdentity: batchAccountCustomRole.outputs.batchAccountCustomRoleName
}
dependsOn: [
uami
Expand Down
4 changes: 2 additions & 2 deletions deploy/infra/modules/batch.account.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ var role = {
}

resource assignRole 'Microsoft.Authorization/roleAssignments@2020-10-01-preview' = {
name: guid(batchAccount.id, userManagedIdentityPrincipalId, role[toLower(assignRoleToUserManagedIdentity)])
name: guid(batchAccount.id, userManagedIdentityPrincipalId, assignRoleToUserManagedIdentity)
scope: batchAccount
properties: {
principalId: userManagedIdentityPrincipalId
roleDefinitionId: role[toLower(assignRoleToUserManagedIdentity)]
roleDefinitionId: assignRoleToUserManagedIdentity
}
}

Expand Down
37 changes: 37 additions & 0 deletions deploy/infra/modules/batch.account.custom.role.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

targetScope = 'subscription'

param batchAccountName string
param allowedActions array = [
'Microsoft.Batch/batchAccounts/pools/write'
'Microsoft.Batch/batchAccounts/pools/read'
'Microsoft.Batch/batchAccounts/pools/delete'
'Microsoft.Batch/batchAccounts/read'
'Microsoft.Batch/batchAccounts/listKeys/action'
]
param allowedDataActions array = [
'Microsoft.Batch/batchAccounts/jobSchedules/write'
'Microsoft.Batch/batchAccounts/jobSchedules/delete'
'Microsoft.Batch/batchAccounts/jobSchedules/read'
'Microsoft.Batch/batchAccounts/jobs/write'
'Microsoft.Batch/batchAccounts/jobs/delete'
'Microsoft.Batch/batchAccounts/jobs/read'
]
param deniedActions array = []
param deniedDataActions array = []

module batchAccountCustomRole './custom.role.bicep' = {
name: 'custom-role-for-${batchAccountName}'
params: {
roleName: 'custom-role-for-${batchAccountName}'
roleDescription: 'Custom Role for Accessing Batch Accounts'
allowedActions: allowedActions
allowedDataActions: allowedDataActions
deniedActions: deniedActions
deniedDataActions: deniedDataActions
}
}

output batchAccountCustomRoleName string = batchAccountCustomRole.outputs.customRoleID
33 changes: 33 additions & 0 deletions deploy/infra/modules/custom.role.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

targetScope = 'subscription'

param roleName string
param roleDescription string = ''
param allowedActions array = []
param allowedDataActions array = []
param deniedActions array = []
param deniedDataActions array = []

resource customRole 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' = {
name: guid(roleName)
properties: {
description: roleDescription
assignableScopes: [
subscription().id
]
permissions: [
{
actions: allowedActions
dataActions: allowedDataActions
notActions: deniedActions
notDataActions: deniedDataActions
}
]
roleName: roleName
type: 'CustomRole'
}
}

output customRoleID string = customRole.id