Skip to content

Commit 84aa212

Browse files
authored
Merge pull request #274403 from mumian/0506-linter-secure
new linter rule for adminPassword
2 parents 9778ea5 + 3f28579 commit 84aa212

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed

articles/azure-resource-manager/bicep/bicep-config-linter.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ The following example shows the rules that are available for configuration.
121121
"use-resource-symbol-reference": {
122122
"level": "warning"
123123
},
124+
"use-secure-value-for-secure-inputs": {
125+
"level": "error"
126+
},
124127
"use-stable-resource-identifiers": {
125128
"level": "warning"
126129
},
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: Linter rule - adminPassword should be assigned a secure value
3+
description: Linter rule - adminPassword should be assigned a secure value.
4+
ms.topic: conceptual
5+
ms.custom: devx-track-bicep
6+
ms.date: 05/06/2024
7+
---
8+
9+
# Linter rule - adminPassword should be assigned a secure value.
10+
11+
This rule finds the value of the property path `properties.osProfile.adminPassword` for resources of type `Microsoft.Compute/virtualMachines` or `Microsoft.Compute/virtualMachineScaleSets` that doesn't have a secure value.
12+
13+
## Linter rule code
14+
15+
Use the following value in the [Bicep configuration file](bicep-config-linter.md) to customize rule settings:
16+
17+
`use-secure-value-for-secure-inputs`
18+
19+
## Solution
20+
21+
Assign a secure value to the property with the property path `properties.osProfile.adminPassword` for resources of type `Microsoft.Compute/virtualMachines` or `Microsoft.Compute/virtualMachineScaleSets`. Don't use a literal value. Instead, create a parameter with the [`@secure()` decorator](./parameters.md#secure-parameters) for the password and assign it to `adminPassword`.
22+
23+
The following examples fail this test because the `adminPassword` is not a secure value.
24+
25+
```bicep
26+
resource ubuntuVM 'Microsoft.Compute/virtualMachineScaleSets@2023-09-01' = {
27+
name: 'name'
28+
location: 'West US'
29+
properties: {
30+
virtualMachineProfile: {
31+
osProfile: {
32+
adminUsername: 'adminUsername'
33+
adminPassword: 'adminPassword'
34+
}
35+
}
36+
}
37+
}
38+
```
39+
40+
```bicep
41+
resource ubuntuVM 'Microsoft.Compute/virtualMachines@2023-09-01' = {
42+
name: 'name'
43+
location: 'West US'
44+
properties: {
45+
osProfile: {
46+
computerName: 'computerName'
47+
adminUsername: 'adminUsername'
48+
adminPassword: 'adminPassword'
49+
}
50+
}
51+
}
52+
```
53+
54+
```bicep
55+
param adminPassword string
56+
57+
resource ubuntuVM 'Microsoft.Compute/virtualMachines@2023-09-01' = {
58+
name: 'name'
59+
location: 'West US'
60+
properties: {
61+
osProfile: {
62+
computerName: 'computerName'
63+
adminUsername: 'adminUsername'
64+
adminPassword: adminPassword
65+
}
66+
}
67+
}
68+
```
69+
70+
The following example passes this test.
71+
72+
```bicep
73+
@secure()
74+
param adminPassword string
75+
@secure()
76+
param adminUsername string
77+
param location string = resourceGroup().location
78+
79+
resource ubuntuVM 'Microsoft.Compute/virtualMachines@2023-09-01' = {
80+
name: 'name'
81+
location: location
82+
properties: {
83+
osProfile: {
84+
computerName: 'computerName'
85+
adminUsername: adminUsername
86+
adminPassword: adminPassword
87+
}
88+
}
89+
}
90+
```
91+
92+
## Next steps
93+
94+
For more information about the linter, see [Use Bicep linter](./linter.md).

articles/azure-resource-manager/bicep/linter.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Use Bicep linter
33
description: Learn how to use Bicep linter.
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 03/20/2024
6+
ms.date: 05/06/2024
77
---
88

99
# Use Bicep linter
@@ -50,6 +50,7 @@ The default set of linter rules is minimal and taken from [arm-ttk test cases](.
5050
- [use-recent-api-versions](./linter-rule-use-recent-api-versions.md)
5151
- [use-resource-id-functions](./linter-rule-use-resource-id-functions.md)
5252
- [use-resource-symbol-reference](./linter-rule-use-resource-symbol-reference.md)
53+
- [use-secure-value-for-secure-inputs](./linter-rule-use-secure-value-for-secure-inputs.md)
5354
- [use-stable-resource-identifiers](./linter-rule-use-stable-resource-identifier.md)
5455
- [use-stable-vm-image](./linter-rule-use-stable-vm-image.md)
5556

articles/azure-resource-manager/bicep/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@
542542
- name: Use resource symbol reference
543543
displayName: linter
544544
href: linter-rule-use-resource-symbol-reference.md
545+
- name: Use secure value for secure inputs
546+
displayName: linter
547+
href: linter-rule-use-secure-value-for-secure-inputs.md
545548
- name: Use stable resource identifier
546549
displayName: linter
547550
href: linter-rule-use-stable-resource-identifier.md

0 commit comments

Comments
 (0)