-
Notifications
You must be signed in to change notification settings - Fork 677
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
antimalware extension installed #1848
Open
abdullahaslam306
wants to merge
7
commits into
aquasecurity:master
Choose a base branch
from
abdullahaslam306:feature/azure-vmss-windows-antimalware-extensions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dfbb699
antimalware extension installed
abdullahaslam306 6cfbd00
Changes
c06df77
linting
alphadev4 9970af7
added rt triggers
alphadev4 3658004
triggers
alphadev4 68dcdae
Merge branch 'master' into feature/azure-vmss-windows-antimalware-ext…
alphadev4 bd884ee
Update exports.js
alphadev4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
plugins/azure/virtualmachinescaleset/vmssWindowsAntiMalwareExtension.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,66 @@ | ||||||
var async = require('async'); | ||||||
|
||||||
var helpers = require('../../../helpers/azure/'); | ||||||
|
||||||
module.exports = { | ||||||
title: 'VMSS Windows AntiMalware Extension', | ||||||
category: 'Virtual Machines', | ||||||
alphadev4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
domain: 'Compute', | ||||||
description: 'Ensures that Virtual Machine Scale Set windows instances have IaaS AntiMalware extension installed.', | ||||||
more_info: 'The VM Scale Set Windows AntiMalware Extension provides real-time protection against viruses, spyware, and other malicious software for virtual machines running on the Windows operating system.', | ||||||
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
|
||||||
recommended_action: 'Modify Virtual Machine Scale Set and install IaaS AntiMalware extension.', | ||||||
link: 'https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/iaas-antimalware-windows', | ||||||
apis: ['virtualMachineScaleSets:listAll'], | ||||||
|
||||||
alphadev4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
run: function(cache, settings, callback) { | ||||||
var results = []; | ||||||
var source = {}; | ||||||
var locations = helpers.locations(settings.govcloud); | ||||||
|
||||||
async.each(locations.virtualMachineScaleSets, function(location, rcb){ | ||||||
var virtualMachineScaleSets = helpers.addSource(cache, source, | ||||||
['virtualMachineScaleSets', 'listAll', location]); | ||||||
|
||||||
if (!virtualMachineScaleSets) return rcb(); | ||||||
|
||||||
if (virtualMachineScaleSets.err || !virtualMachineScaleSets.data) { | ||||||
helpers.addResult(results, 3, 'Unable to query for Virtual Machine Scale Sets: ' + helpers.addError(virtualMachineScaleSets), location); | ||||||
return rcb(); | ||||||
} | ||||||
|
||||||
if (!virtualMachineScaleSets.data.length) { | ||||||
helpers.addResult(results, 0, 'No existing Virtual Machine Scale Sets found', location); | ||||||
return rcb(); | ||||||
} | ||||||
|
||||||
for (let scaleSet of virtualMachineScaleSets.data){ | ||||||
|
||||||
if (!scaleSet.id ||(scaleSet.virtualMachineProfile.storageProfile && scaleSet.virtualMachineProfile.storageProfile.osDisk && | ||||||
scaleSet.virtualMachineProfile.storageProfile.osDisk.osType && | ||||||
scaleSet.virtualMachineProfile.storageProfile.osDisk.osType.toLowerCase() != 'windows')){ | ||||||
continue; | ||||||
} | ||||||
alphadev4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
const scaleSetExtensions = scaleSet.virtualMachineProfile && scaleSet.virtualMachineProfile.extensionProfile && | ||||||
scaleSet.virtualMachineProfile.extensionProfile.extensions | ||||||
? scaleSet.virtualMachineProfile.extensionProfile.extensions | ||||||
: []; | ||||||
|
||||||
if (!scaleSetExtensions.length) { | ||||||
helpers.addResult(results, 2, 'No VMSS Extensions found', location); | ||||||
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. resource id is missing |
||||||
continue; | ||||||
} | ||||||
|
||||||
let found = scaleSetExtensions.find(vmExt => vmExt.name && vmExt.name.toLowerCase() === 'iaasantimalware'); | ||||||
if (found) { | ||||||
helpers.addResult(results, 0, 'Windows Virtual Machine has IaaS Antimalware extension installed', location, scaleSet.id); | ||||||
} else { | ||||||
helpers.addResult(results, 2, 'Windows Virtual Machine does not have IaaS Antimalware extension installed', location, scaleSet.id); | ||||||
} | ||||||
} | ||||||
|
||||||
rcb(); | ||||||
}, function() { | ||||||
callback(null, results, source); | ||||||
}); | ||||||
} | ||||||
}; |
141 changes: 141 additions & 0 deletions
141
plugins/azure/virtualmachinescaleset/vmssWindowsAntiMalwareExtension.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
var expect = require('chai').expect; | ||
var vmssWindowsAntiMalwareExtension = require('./vmssWindowsAntiMalwareExtension'); | ||
|
||
const virtualMachineScaleSets = [ | ||
{ | ||
'name': 'test-vmss', | ||
'id': '/subscriptions/123/resourceGroups/AQUA-RESOURCE-GROUP/providers/Microsoft.Compute/virtualMachineScaleSets/test-vmss', | ||
'type': 'Microsoft.Compute/virtualMachineScaleSets', | ||
'virtualMachineProfile': { | ||
"storageProfile": { | ||
"osDisk": { | ||
"osType": "windows", | ||
}, | ||
}, | ||
'extensionProfile': { | ||
'extensions': [ | ||
{ | ||
'name': 'iaasantimalware', | ||
'properties': { | ||
'autoUpgradeMinorVersion': false, | ||
'publisher': 'Microsoft.ManagedServices', | ||
'type': 'AADSSHLoginForLinux', | ||
'typeHandlerVersion': '1.0', | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
'name': 'test-vmss', | ||
'id': '/subscriptions/123/resourceGroups/AQUA-RESOURCE-GROUP/providers/Microsoft.Compute/virtualMachineScaleSets/test-vmss', | ||
'type': 'Microsoft.Compute/virtualMachineScaleSets', | ||
'virtualMachineProfile': { | ||
"storageProfile": { | ||
"osDisk": { | ||
"osType": "windows", | ||
}, | ||
}, | ||
'extensionProfile': { | ||
'extensions': [ | ||
{ | ||
'name': 'AADLoginForWindows', | ||
'properties': { | ||
'autoUpgradeMinorVersion': false, | ||
'publisher': 'Microsoft.ManagedServices', | ||
'type': 'AADLoginForWindows', | ||
'typeHandlerVersion': '1.0', | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
'name': 'test-vmss', | ||
'id': '/subscriptions/123/resourceGroups/AQUA-RESOURCE-GROUP/providers/Microsoft.Compute/virtualMachineScaleSets/test-vmss', | ||
'type': 'Microsoft.Compute/virtualMachineScaleSets', | ||
'virtualMachineProfile': { | ||
"storageProfile": { | ||
"osDisk": { | ||
"osType": "windows", | ||
}, | ||
}, | ||
'extensionProfile': { | ||
'extensions': [] | ||
} | ||
} | ||
} | ||
]; | ||
|
||
const createCache = (virtualMachineScaleSets) => { | ||
let machine = {}; | ||
if (virtualMachineScaleSets) { | ||
machine['data'] = virtualMachineScaleSets; | ||
} | ||
return { | ||
virtualMachineScaleSets: { | ||
listAll: { | ||
'eastus': machine | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
describe('vmssWindowsAntiMalwareExtension', function() { | ||
describe('run', function() { | ||
it('should give passing result if no virtual machine scale sets', function(done) { | ||
const cache = createCache([]); | ||
vmssWindowsAntiMalwareExtension.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(); | ||
vmssWindowsAntiMalwareExtension.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 windows Virtual Machine Scale Set has anti malware extension installed', function(done) { | ||
const cache = createCache([virtualMachineScaleSets[0]]); | ||
vmssWindowsAntiMalwareExtension.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(0); | ||
expect(results[0].message).to.include('Windows Virtual Machine has IaaS Antimalware extension installed'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
it('should give failing result if Virtual Machine Scale Set does not have anti malware extension installed', function(done) { | ||
const cache = createCache([virtualMachineScaleSets[1]]); | ||
vmssWindowsAntiMalwareExtension.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(2); | ||
expect(results[0].message).to.include('Windows Virtual Machine does not have IaaS Antimalware extension installed'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
it('should give failing result if no extensions installed', function(done) { | ||
const cache = createCache([virtualMachineScaleSets[2]]); | ||
vmssWindowsAntiMalwareExtension.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(2); | ||
expect(results[0].message).to.include('No VMSS Extensions found'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you shorten the filename? maybe rename it to vmssWindowsAntiMalwareExt