-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathdeployment.bicep
268 lines (251 loc) · 6.1 KB
/
deployment.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
// AZ-500 Security Implementation Example
// Purpose: Demonstrates secure infrastructure deployment with multiple security controls
// Parameters
@description('Primary location for all resources')
param location string = resourceGroup().location
@description('Environment name')
@allowed([
'Production'
'Development'
'Test'
])
param environmentName string
@description('IP addresses or ranges that should be allowed through the firewall')
param allowedIPRanges array
@description('Key Vault SKU')
@allowed([
'standard'
'premium'
])
param keyVaultSku string = 'premium'
@minLength(3)
@maxLength(24)
@description('Storage Account name')
param storageAccountName string
@secure()
@description('SQL Server administrator password')
param sqlServerAdminPassword string
// Variables
var networkSecurityGroupName = 'security-nsg'
var virtualNetworkName = 'security-vnet'
var keyVaultName = 'kv-${uniqueString(resourceGroup().id)}'
var logAnalyticsWorkspaceName = 'law-${uniqueString(resourceGroup().id)}'
var applicationInsightsName = 'ai-${uniqueString(resourceGroup().id)}'
// Tags
var commonTags = {
Environment: environmentName
SecurityContact: '[email protected]'
DataClassification: 'Confidential'
ComplianceRequired: 'HIPAA'
}
// Network Security Group
resource nsg 'Microsoft.Network/networkSecurityGroups@2023-05-01' = {
name: networkSecurityGroupName
location: location
tags: commonTags
properties: {
securityRules: [
{
name: 'DenyAllInbound'
properties: {
priority: 4096
direction: 'Inbound'
access: 'Deny'
protocol: '*'
sourceAddressPrefix: '*'
sourcePortRange: '*'
destinationAddressPrefix: '*'
destinationPortRange: '*'
}
}
]
}
}
// Virtual Network with Subnets
resource vnet 'Microsoft.Network/virtualNetworks@2023-05-01' = {
name: virtualNetworkName
location: location
tags: commonTags
properties: {
addressSpace: {
addressPrefixes: [
'10.0.0.0/16'
]
}
subnets: [
{
name: 'ApplicationSubnet'
properties: {
addressPrefix: '10.0.1.0/24'
networkSecurityGroup: {
id: nsg.id
}
serviceEndpoints: [
{
service: 'Microsoft.KeyVault'
}
{
service: 'Microsoft.Storage'
}
{
service: 'Microsoft.Sql'
}
]
}
}
{
name: 'DatabaseSubnet'
properties: {
addressPrefix: '10.0.2.0/24'
delegations: [
{
name: 'sqlDelegation'
properties: {
serviceName: 'Microsoft.Sql/managedInstances'
}
}
]
}
}
]
}
}
// Key Vault with RBAC and Advanced Security
resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' = {
name: keyVaultName
location: location
tags: commonTags
properties: {
tenantId: subscription().tenantId
sku: {
family: 'A'
name: keyVaultSku
}
enableRbacAuthorization: true
enablePurgeProtection: true
enabledForTemplateDeployment: true
enabledForDiskEncryption: true
networkAcls: {
defaultAction: 'Deny'
bypass: 'AzureServices'
ipRules: [for ip in allowedIPRanges: {
value: ip
}]
virtualNetworkRules: [
{
id: '${vnet.id}/subnets/ApplicationSubnet'
}
]
}
}
}
// Storage Account with Security Features
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
name: storageAccountName
location: location
tags: commonTags
sku: {
name: 'Standard_GRS'
}
kind: 'StorageV2'
properties: {
minimumTlsVersion: 'TLS1_2'
supportsHttpsTrafficOnly: true
encryption: {
services: {
blob: {
enabled: true
}
file: {
enabled: true
}
}
keySource: 'Microsoft.Storage'
}
networkAcls: {
defaultAction: 'Deny'
bypass: 'AzureServices'
virtualNetworkRules: [
{
id: '${vnet.id}/subnets/ApplicationSubnet'
action: 'Allow'
}
]
ipRules: [for ip in allowedIPRanges: {
value: ip
action: 'Allow'
}]
}
}
}
// Log Analytics Workspace
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {
name: logAnalyticsWorkspaceName
location: location
tags: commonTags
properties: {
sku: {
name: 'PerGB2018'
}
retentionInDays: 90
features: {
enableLogAccessUsingOnlyResourcePermissions: true
}
}
}
// Application Insights for Security Monitoring
resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
name: applicationInsightsName
location: location
tags: commonTags
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: logAnalytics.id
DisableIpMasking: false
DisableLocalAuth: true
}
}
// Diagnostic Settings for Key Vault
resource keyVaultDiagnostics 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
scope: keyVault
name: 'KeyVaultAudit'
properties: {
workspaceId: logAnalytics.id
logs: [
{
category: 'AuditEvent'
enabled: true
retentionPolicy: {
enabled: true
days: 90
}
}
]
metrics: [
{
category: 'AllMetrics'
enabled: true
retentionPolicy: {
enabled: true
days: 90
}
}
]
}
}
// Role Assignments
resource keyVaultAdminRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(keyVault.id, 'Key Vault Administrator')
scope: keyVault
properties: {
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '00482a5a-887f-4fb3-b363-3b7fe8e74483')
principalType: 'ServicePrincipal'
principalId: 'YOUR-MANAGED-IDENTITY-ID'
}
}
// Outputs
output keyVaultName string = keyVault.name
output storageAccountName string = storageAccount.name
output vnetName string = vnet.name
output logAnalyticsWorkspaceId string = logAnalytics.id