-
Notifications
You must be signed in to change notification settings - Fork 1
/
azPolicy-softdelete.bicep
141 lines (132 loc) · 4.16 KB
/
azPolicy-softdelete.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
targetScope = 'subscription'
param location string = deployment().location
@allowed(['blob','container'])
param softDeleteType string = 'blob'
var softDeleteTypeMap = {
blob: 'deleteRetentionPolicy'
container: 'containerDeleteRetentionPolicy'
}
var softDeleteTypeAlias = softDeleteTypeMap[softDeleteType]
resource azpDefEnableSoft 'Microsoft.Authorization/policyDefinitions@2021-06-01' = {
name: 'storage-${softDeleteType}-soft-delete-mustbe-enabled'
scope: subscription()
properties: {
description: 'Storage ${softDeleteType} soft delete must be enabled'
displayName: 'Storage -${softDeleteType} soft delete must be enabled'
mode: 'All'
metadata: {
category: 'Storage'
version: '1.0.0'
}
policyType: 'Custom'
policyRule: {
if: {
allOf: [
{
anyOf: [
{
field: 'type'
equals: 'Microsoft.Storage/storageAccounts/blobServices'
}
{
field: 'type'
equals: 'Microsoft.Storage/storageAccounts'
}
]
}
{
field: 'Microsoft.Storage/storageAccounts/blobServices/${softDeleteTypeAlias}.enabled'
equals: false
}
]
}
then: {
effect: 'deny'
}
}
}
}
resource azpDefSoft365 'Microsoft.Authorization/policyDefinitions@2021-06-01' = {
name: 'storage-${softDeleteType}-soft-delete-365-days'
scope: subscription()
properties: {
description: 'Storage ${softDeleteType} soft delete should be 365 days'
displayName: 'Storage ${softDeleteType} soft delete should be 365 days'
mode: 'All'
metadata: {
category: 'Storage'
version: '1.0.0'
}
policyType: 'Custom'
policyRule: {
if: {
allOf: [
{
field: 'type'
equals: 'Microsoft.Storage/storageAccounts/blobServices'
}
{
anyOf: [
{
field: 'Microsoft.Storage/storageAccounts/blobServices/${softDeleteTypeAlias}.enabled'
notEquals: true
}
{
field: 'Microsoft.Storage/storageAccounts/blobServices/${softDeleteTypeAlias}.days'
notEquals: 365
}
]
}
]
}
then: {
effect: 'modify'
details : {
conflictEffect: 'deny'
roleDefinitionIds: [
'/providers/microsoft.authorization/roleDefinitions/17d1049b-9a84-46fb-8f53-869881c3d3ab'
]
operations: [
{
operation: 'addOrReplace'
field: 'Microsoft.Storage/storageAccounts/blobServices/${softDeleteTypeAlias}.enabled'
value: true
}
{
operation: 'addOrReplace'
field: 'Microsoft.Storage/storageAccounts/blobServices/${softDeleteTypeAlias}.days'
value: 365
}
]
}
}
}
}
}
@description('The assignment is what binds the Policy Definition to a scope for enforcement')
resource azdAssignSoftEnable 'Microsoft.Authorization/policyAssignments@2022-06-01' = {
name: 'storage-${softDeleteType}-soft-delete-enabled'
location: location
scope: subscription()
properties: {
policyDefinitionId: azpDefEnableSoft.id
enforcementMode: 'Default'
displayName: 'storage-soft-delete-enabled'
description: 'storage-soft-delete-enabled'
}
}
@description('The assignment is what binds the Policy Definition to a scope for enforcement')
resource azdAssignSoft365 'Microsoft.Authorization/policyAssignments@2022-06-01' = {
name: 'storage-${softDeleteType}-soft-delete-365'
location: location
scope: subscription()
properties: {
policyDefinitionId: azpDefSoft365.id
enforcementMode: 'Default'
displayName: 'storage-${softDeleteType}-soft-delete-365'
description: 'storage-${softDeleteType}-soft-delete-365'
}
identity: { //An identity is required as the policy definition uses the MODIFY effect. The role in the defintion will be assigned to this identity during the creation of the assignment
type: 'SystemAssigned'
}
}