-
Notifications
You must be signed in to change notification settings - Fork 728
vmss linux ssh for local admin enabled #1820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,56 @@ | ||||||||||||||||||||
| var async = require('async'); | ||||||||||||||||||||
| var helpers = require('../../../helpers/azure'); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| module.exports = { | ||||||||||||||||||||
| title: 'VM Scale Set Linux SSH Enabled', | ||||||||||||||||||||
| category: 'Virtual Machine Scale Set', | ||||||||||||||||||||
| domain: 'Compute', | ||||||||||||||||||||
| description: 'Ensures that Azure Virtual Machine scale sets with Linux OS has SSH enabled.', | ||||||||||||||||||||
| more_info: 'SSH is an encrypted connection protocol that allows secure sign-ins over unsecured connections. SSH is the default connection protocol for Linux VMs hosted in Azure.', | ||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. write an advantage of using SSH key. |
||||||||||||||||||||
| link: 'https://learn.microsoft.com/en-us/azure/virtual-machines/linux/ssh-from-windows', | ||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this correct? i think it should be this https://learn.microsoft.com/en-us/azure/virtual-machines/linux/mac-create-ssh-keys |
||||||||||||||||||||
| recommended_action: 'Remove existing scale set and create new with SSH enabled', | ||||||||||||||||||||
| apis: ['virtualMachineScaleSets:listAll'], | ||||||||||||||||||||
|
|
||||||||||||||||||||
| run: function(cache, settings, callback) { | ||||||||||||||||||||
| var results = []; | ||||||||||||||||||||
| var source = {}; | ||||||||||||||||||||
| var locations = helpers.locations(settings.govcloud); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| async.each(locations.vmScaleSet, function(location, rcb) { | ||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have two resources in locations.js vmScaleSet and virtualMachineScaleSets, can you use virtualMachineScaleSets instead making it consistent, and also remove the other from locations file along with its usage |
||||||||||||||||||||
|
|
||||||||||||||||||||
| var vmScaleSets = helpers.addSource(cache, source, ['virtualMachineScaleSets', 'listAll', location]); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (!vmScaleSets) return rcb(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (vmScaleSets.err || !vmScaleSets.data) { | ||||||||||||||||||||
| helpers.addResult(results, 3, 'Unable to query for Virtual Machine Scale Sets: ' + helpers.addError(vmScaleSets), location); | ||||||||||||||||||||
| return rcb(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (!vmScaleSets.data.length) { | ||||||||||||||||||||
| helpers.addResult(results, 0, 'No existing Virtual Machine Scale Sets found', location); | ||||||||||||||||||||
| return rcb(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| for (let scaleSet of vmScaleSets.data) { | ||||||||||||||||||||
| if (!scaleSet.id) continue; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if ((scaleSet.virtualMachineProfile.storageProfile && scaleSet.virtualMachineProfile.storageProfile.osDisk && | ||||||||||||||||||||
| scaleSet.virtualMachineProfile.storageProfile.osDisk.osType && | ||||||||||||||||||||
| scaleSet.virtualMachineProfile.storageProfile.osDisk.osType.toLowerCase() === 'linux')){ | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
Comment on lines
+36
to
+39
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
| if (scaleSet.virtualMachineProfile && scaleSet.virtualMachineProfile.osProfile && | ||||||||||||||||||||
| scaleSet.virtualMachineProfile.osProfile.linuxConfiguration && | ||||||||||||||||||||
| scaleSet.virtualMachineProfile.osProfile.linuxConfiguration.ssh){ | ||||||||||||||||||||
| helpers.addResult(results, 0, 'VM scale set for linux has SSH enabled', location, scaleSet.id); | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| helpers.addResult(results, 2, 'VM scale set for linux does not have SSH enabled', location, scaleSet.id); | ||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. produce the message according to ssh keys |
||||||||||||||||||||
| } | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| continue; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| rcb(); | ||||||||||||||||||||
| }, function() { | ||||||||||||||||||||
| callback(null, results, source); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| }; | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| var expect = require('chai').expect; | ||
| var scaleSetLinuxSSHEnabled = require('./scaleSetLinuxSSHEnabled'); | ||
|
|
||
| const virtualMachineScaleSets = [ | ||
| { | ||
| 'name': 'test-vmss', | ||
| 'id': '/subscriptions/123/resourceGroups/AQUA-RESOURCE-GROUP/providers/Microsoft.Compute/virtualMachineScaleSets/test-vmss', | ||
| 'type': 'Microsoft.Compute/virtualMachineScaleSets', | ||
| "virtualMachineProfile": { | ||
| "osProfile": { | ||
| "linuxConfiguration": { | ||
| "disablePasswordAuthentication": true, | ||
| "ssh": { | ||
| "publicKeys": [ | ||
| { | ||
| "path": "/home/azureuser/.ssh/authorized_keys", | ||
| "keyData": "" | ||
| } | ||
| ] | ||
| }, | ||
| }, | ||
| }, | ||
| "storageProfile": { | ||
| "osDisk": { | ||
| "osType": "Linux", | ||
| }, | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| 'name': 'test-vmss', | ||
| 'id': '/subscriptions/123/resourceGroups/AQUA-RESOURCE-GROUP/providers/Microsoft.Compute/virtualMachineScaleSets/test-vmss', | ||
| 'type': 'Microsoft.Compute/virtualMachineScaleSets', | ||
| "virtualMachineProfile": { | ||
| "osProfile": { | ||
| "linuxConfiguration": { | ||
| "disablePasswordAuthentication": false | ||
| }, | ||
| }, | ||
| "storageProfile": { | ||
| "osDisk": { | ||
| "osType": "Linux", | ||
| }, | ||
| } | ||
| } | ||
| }, | ||
| ]; | ||
|
|
||
| const createCache = (virtualMachineScaleSets) => { | ||
| let machine = {}; | ||
| if (virtualMachineScaleSets) { | ||
| machine['data'] = virtualMachineScaleSets; | ||
| } | ||
| return { | ||
| virtualMachineScaleSets: { | ||
| listAll: { | ||
| 'eastus': machine | ||
| } | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
| describe('scaleSetLinuxSSHEnabled', function() { | ||
| describe('run', function() { | ||
| it('should give passing result if no virtual machine scale sets', function(done) { | ||
| const cache = createCache([]); | ||
| scaleSetLinuxSSHEnabled.run(cache, {}, (err, results) => { | ||
| expect(results.length).to.equal(1); | ||
| expect(results[0].status).to.equal(0); | ||
| expect(results[0].message).to.include('No existing Virtual Machine Scale Sets found'); | ||
| expect(results[0].region).to.equal('eastus'); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should give unknown result if unable to query for virtual machine scale sets', function(done) { | ||
| const cache = createCache(); | ||
| scaleSetLinuxSSHEnabled.run(cache, {}, (err, results) => { | ||
| expect(results.length).to.equal(1); | ||
| expect(results[0].status).to.equal(3); | ||
| expect(results[0].message).to.include('Unable to query for Virtual Machine Scale Sets:'); | ||
| expect(results[0].region).to.equal('eastus'); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should give passing result if VM scale set for linux has SSH enabled', function(done) { | ||
| const cache = createCache([virtualMachineScaleSets[0]]); | ||
| scaleSetLinuxSSHEnabled.run(cache, {}, (err, results) => { | ||
| expect(results.length).to.equal(1); | ||
| expect(results[0].status).to.equal(0); | ||
| expect(results[0].message).to.include('VM scale set for linux has SSH enabled'); | ||
| expect(results[0].region).to.equal('eastus'); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should give failing result if VM scale set for linux does not have SSH enabled', function(done) { | ||
| const cache = createCache([virtualMachineScaleSets[1]]); | ||
| scaleSetLinuxSSHEnabled.run(cache, {}, (err, results) => { | ||
| expect(results.length).to.equal(1); | ||
| expect(results[0].status).to.equal(2); | ||
| expect(results[0].message).to.include('VM scale set for linux does not have SSH enabled'); | ||
| expect(results[0].region).to.equal('eastus'); | ||
| done(); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.