|
| 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). |
0 commit comments