Skip to content
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

feature/AKD-118: Added Azure 'DDoS Standard Protection Enabled' plugin and test cases #588

Merged
merged 7 commits into from
Mar 26, 2021
1 change: 1 addition & 0 deletions exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ module.exports = {
'queueServiceAllAccessAcl' : require(__dirname + '/plugins/azure/queueservice/queueServiceAllAccessAcl.js'),

'multipleSubnets' : require(__dirname + '/plugins/azure/virtualnetworks/multipleSubnets.js'),
'ddosStandardProtectionEnabled' : require(__dirname + '/plugins/azure/virtualnetworks/ddosStandardProtectionEnabled.js'),

'vmInstanceLimit' : require(__dirname + '/plugins/azure/virtualmachines/vmInstanceLimit.js'),
'classicInstances' : require(__dirname + '/plugins/azure/virtualmachines/classicInstances.js'),
Expand Down
49 changes: 49 additions & 0 deletions plugins/azure/virtualnetworks/ddosStandardProtectionEnabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const async = require('async');
const helpers = require('../../../helpers/azure');

module.exports = {
title: 'DDoS Standard Protection Enabled',
category: 'Virtual Networks',
description: 'Ensures that DDoS Standard Protection is enabled for Microsoft Azure Virtual Networks',
giorod3 marked this conversation as resolved.
Show resolved Hide resolved
more_info: 'DDoS Protection Standard offers enhanced Distributed Denial-of-Service (DDoS) mitigation capabilities via adaptive tuning, attack alert notifications, and telemetry to protect against the impacts of large DDoS attacks for all the protected resources available within your Azure Virtual Networks.',
recommended_action: 'Enable DDoS protection for virtual networks',
link: 'https://azure.microsoft.com/en-us/blog/azure-ddos-protection-for-virtual-networks-generally-available/',
apis: ['virtualNetworks:listAll'],

run: function(cache, settings, callback) {
const results = [];
const source = {};
const locations = helpers.locations(settings.govcloud);

async.each(locations.virtualNetworks, (location, rcb) => {
var virtualNetworks = helpers.addSource(cache, source,
['virtualNetworks', 'listAll', location]);

if (!virtualNetworks) return rcb();

if (virtualNetworks.err || !virtualNetworks.data) {
helpers.addResult(results, 3, 'Unable to query for Virtual Networks: ' + helpers.addError(virtualNetworks), location);
return rcb();
}

if (!virtualNetworks.data.length) {
helpers.addResult(results, 0, 'No existing Virtual Networks found', location);
giorod3 marked this conversation as resolved.
Show resolved Hide resolved
}

virtualNetworks.data.forEach(virtualNetwork => {
if (virtualNetwork.enableDdosProtection) {
helpers.addResult(results, 0,
'DDoS Standard Protection is enabled for Microsoft Azure Virtual Network', location, virtualNetwork.id);
} else {
helpers.addResult(results, 2,
'DDoS Standard Protection is not enabled for Microsoft Azure Virtual Network', location, virtualNetwork.id);
}
});

rcb();
}, function() {
// Global checking goes here
callback(null, results, source);
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
var expect = require('chai').expect;
var ddosStandardProtectionEnabled = require('./ddosStandardProtectionEnabled');

const virtualNetworks = [
{
"name": 'test-vnet',
"id": '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Network/virtualNetworks/test-vnet',
"type": 'Microsoft.Network/virtualNetworks',
"location": 'eastus',
"provisioningState": 'Succeeded',
"virtualNetworkPeerings": [],
"enableDdosProtection": true
},
{
"name": 'test-vnet',
"id": '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Network/virtualNetworks/test-vnet',
"type": 'Microsoft.Network/virtualNetworks',
"location": 'eastus',
"provisioningState": 'Succeeded',
"virtualNetworkPeerings": [],
"enableDdosProtection": false
}
];

const createCache = (virtualNetworks) => {
return {
virtualNetworks: {
listAll: {
'eastus': {
data: virtualNetworks
}
}
}
};
};

const createErrorCache = () => {
return {
virtualNetworks: {
listAll: {
'eastus': {}
}
}
};
};

describe('ddosStandardProtectionEnabled', function() {
describe('run', function() {
it('should give passing result if no virtual networks', function(done) {
const cache = createCache([]);
ddosStandardProtectionEnabled.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 Networks found');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give failing result if DDoS standard protection is not enabled for virtual network', function(done) {
const cache = createCache([virtualNetworks[1]]);
ddosStandardProtectionEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(2);
expect(results[0].message).to.include('DDoS Standard Protection is not enabled for Microsoft Azure Virtual Network');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give unknown result if Unable to query for Virtual Networks', function(done) {
const cache = createErrorCache();
ddosStandardProtectionEnabled.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 Networks:');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give passing result if DDoS standard protection is enabled for virtual network', function(done) {
const cache = createCache([virtualNetworks[0]]);
ddosStandardProtectionEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('DDoS Standard Protection is enabled for Microsoft Azure Virtual Network');
expect(results[0].region).to.equal('eastus');
done();
});
});
});
});