|
1 | 1 | ---
|
2 | 2 | severity: Important
|
3 | 3 | pillar: Security
|
4 |
| -category: Identity and access management |
| 4 | +category: SE:08 Hardening resources |
5 | 5 | resource: Virtual Machine
|
6 | 6 | online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.VM.PublicKey/
|
7 | 7 | ---
|
8 | 8 |
|
9 |
| -# Use public keys for Linux |
| 9 | +# VM password-based authentication is enabled |
10 | 10 |
|
11 | 11 | ## SYNOPSIS
|
12 | 12 |
|
13 | 13 | Linux virtual machines should use public keys.
|
14 | 14 |
|
15 | 15 | ## DESCRIPTION
|
16 | 16 |
|
17 |
| -Linux virtual machines support either password or public key based authentication for the default administrator account. |
| 17 | +Linux virtual machines should have password authentication disabled to help with eliminating password-based attacks. |
18 | 18 |
|
19 | 19 | ## RECOMMENDATION
|
20 | 20 |
|
21 |
| -Consider using public key based authentication instead of passwords. |
| 21 | +Consider disabling password-based authentication on Linux virtual machines and instead use public keys. |
| 22 | + |
| 23 | +## EXAMPLES |
| 24 | + |
| 25 | +### Configure with Azure template |
| 26 | + |
| 27 | +To deploy virtual machines that pass this rule: |
| 28 | + |
| 29 | +- Set the `properties.osProfile.linuxConfiguration.disablePasswordAuthentication` property to `true`. |
| 30 | + |
| 31 | +For example: |
| 32 | + |
| 33 | +```json |
| 34 | +{ |
| 35 | + "type": "Microsoft.Compute/virtualMachines", |
| 36 | + "apiVersion": "2024-03-01", |
| 37 | + "name": "[parameters('name')]", |
| 38 | + "location": "[parameters('location')]", |
| 39 | + "identity": { |
| 40 | + "type": "SystemAssigned" |
| 41 | + }, |
| 42 | + "properties": { |
| 43 | + "hardwareProfile": { |
| 44 | + "vmSize": "Standard_D8d_v5" |
| 45 | + }, |
| 46 | + "osProfile": { |
| 47 | + "computerName": "[parameters('name')]", |
| 48 | + "adminUsername": "[parameters('adminUsername')]", |
| 49 | + "linuxConfiguration": { |
| 50 | + "disablePasswordAuthentication": true |
| 51 | + } |
| 52 | + }, |
| 53 | + "storageProfile": { |
| 54 | + "imageReference": { |
| 55 | + "publisher": "MicrosoftCblMariner", |
| 56 | + "offer": "Cbl-Mariner", |
| 57 | + "sku": "cbl-mariner-2-gen2", |
| 58 | + "version": "latest" |
| 59 | + }, |
| 60 | + "osDisk": { |
| 61 | + "name": "[format('{0}-disk0', parameters('name'))]", |
| 62 | + "caching": "ReadWrite", |
| 63 | + "createOption": "FromImage", |
| 64 | + "managedDisk": { |
| 65 | + "storageAccountType": "Premium_LRS" |
| 66 | + } |
| 67 | + } |
| 68 | + }, |
| 69 | + "networkProfile": { |
| 70 | + "networkInterfaces": [ |
| 71 | + { |
| 72 | + "id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('nicName'))]" |
| 73 | + } |
| 74 | + ] |
| 75 | + } |
| 76 | + }, |
| 77 | + "zones": [ |
| 78 | + "1" |
| 79 | + ], |
| 80 | + "dependsOn": [ |
| 81 | + "[resourceId('Microsoft.Network/networkInterfaces', parameters('nicName'))]" |
| 82 | + ] |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +### Configure with Bicep |
| 87 | + |
| 88 | +To deploy virtual machines that pass this rule: |
| 89 | + |
| 90 | +- Set the `properties.osProfile.linuxConfiguration.disablePasswordAuthentication` property to `true`. |
| 91 | + |
| 92 | +For example: |
| 93 | + |
| 94 | +```bicep |
| 95 | +resource linux 'Microsoft.Compute/virtualMachines@2024-03-01' = { |
| 96 | + name: name |
| 97 | + location: location |
| 98 | + identity: { |
| 99 | + type: 'SystemAssigned' |
| 100 | + } |
| 101 | + properties: { |
| 102 | + hardwareProfile: { |
| 103 | + vmSize: 'Standard_D8d_v5' |
| 104 | + } |
| 105 | + osProfile: { |
| 106 | + computerName: name |
| 107 | + adminUsername: adminUsername |
| 108 | + linuxConfiguration: { |
| 109 | + disablePasswordAuthentication: true |
| 110 | + } |
| 111 | + } |
| 112 | + storageProfile: { |
| 113 | + imageReference: { |
| 114 | + publisher: 'MicrosoftCblMariner' |
| 115 | + offer: 'Cbl-Mariner' |
| 116 | + sku: 'cbl-mariner-2-gen2' |
| 117 | + version: 'latest' |
| 118 | + } |
| 119 | + osDisk: { |
| 120 | + name: '${name}-disk0' |
| 121 | + caching: 'ReadWrite' |
| 122 | + createOption: 'FromImage' |
| 123 | + managedDisk: { |
| 124 | + storageAccountType: 'Premium_LRS' |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | + networkProfile: { |
| 129 | + networkInterfaces: [ |
| 130 | + { |
| 131 | + id: nic.id |
| 132 | + } |
| 133 | + ] |
| 134 | + } |
| 135 | + } |
| 136 | + zones: [ |
| 137 | + '1' |
| 138 | + ] |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +## LINKS |
| 143 | + |
| 144 | +- [SE:08 Hardening resources](https://learn.microsoft.com/azure/well-architected/security/harden-resources) |
| 145 | +- [Azure security baseline for Linux Virtual Machines](https://learn.microsoft.com/security/benchmark/azure/baselines/virtual-machines-linux-security-baseline) |
| 146 | +- [Detailed steps: Create and manage SSH keys for authentication to a Linux VM in Azure](https://learn.microsoft.com/azure/virtual-machines/linux/create-ssh-keys-detailed) |
| 147 | +- [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.compute/virtualmachines) |
0 commit comments