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-96: Added Azure 'Storage Auto Growth Enabled' plugin and test cases #584

Merged
merged 6 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 @@ -400,6 +400,7 @@ module.exports = {
'logConnectionsEnabled' : require(__dirname + '/plugins/azure/postgresqlserver/logConnectionsEnabled.js'),
'logCheckpointsEnabled' : require(__dirname + '/plugins/azure/postgresqlserver/logCheckpointsEnabled.js'),
'enforcePostgresSSLConnection' : require(__dirname + '/plugins/azure/postgresqlserver/enforcePostgresSSLConnection.js'),
'storageAutoGrowthEnabled' : require(__dirname + '/plugins/azure/postgresqlserver/storageAutoGrowthEnabled.js'),

'openOracleAutoDataWarehouse' : require(__dirname + '/plugins/azure/networksecuritygroups/openOracleAutoDataWarehouse.js'),
'networkWatcherEnabled' : require(__dirname + '/plugins/azure/networksecuritygroups/networkWatcherEnabled.js'),
Expand Down
54 changes: 54 additions & 0 deletions plugins/azure/postgresqlserver/storageAutoGrowthEnabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const async = require('async');
const helpers = require('../../../helpers/azure');

module.exports = {
title: 'Storage Auto-Growth Enabled',
category: 'PostgreSQL Server',
description: 'Ensures that Storage Auto-Growth feature is enabled for Microsoft Azure PostgreSQL servers.',
more_info: 'Storage auto grow prevents your server from reaching the storage limit and becoming read-only. For servers with 100 GB or less of provisioned storage, the size is increased by 5 GB when the free space is below 10%. For servers with more than 100 GB of provisioned storage, the size is increased by 5% when the free space is below 10 GB.',
recommended_action: 'Modify PostgreSQL servers to enable storage auto-growth feature',
link: 'https://docs.microsoft.com/en-us/azure/postgresql/howto-auto-grow-storage-portal',
apis: ['servers:listPostgres'],

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

async.each(locations.servers, (location, rcb) => {

const listPostgres = helpers.addSource(cache, source,
['servers', 'listPostgres', location]);

if (!listPostgres) return rcb();

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

if (!listPostgres.data.length) {
helpers.addResult(results, 0, 'No existing PostgreSQL Servers found', location);
return rcb();
}

for (let postgresServer of listPostgres.data) {
if (postgresServer.storageProfile &&
postgresServer.storageProfile.storageAutogrow &&
postgresServer.storageProfile.storageAutogrow.toLowerCase() == 'enabled') {
helpers.addResult(results, 0,
'Storage Auto Growth is enabled for PostgreSQL Server', location, postgresServer.id);
} else {
helpers.addResult(results, 2,
'Storage Auto Growth is not enabled for PostgreSQL Server', location, postgresServer.id);
}
}

rcb();
}, function() {
// Global checking goes here
callback(null, results, source);
});
}
};
118 changes: 118 additions & 0 deletions plugins/azure/postgresqlserver/storageAutoGrowthEnabled.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
var expect = require('chai').expect;
var storage = require('./storageAutoGrowthEnabled');

const listPostgres = [
{
'sku': {
'name': 'B_Gen5_1',
'tier': 'Basic',
'family': 'Gen5',
'capacity': 1
},
'location': 'eastus',
'tags': {},
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.DBforPostgreSQL/servers/server1',
'name': 'server1',
'type': 'Microsoft.DBforPostgreSQL/servers',
'administratorLogin': 'Aquaadmin',
'storageProfile': {
'storageMB': 5120,
'backupRetentionDays': 7,
'geoRedundantBackup': 'Disabled',
'storageAutogrow': 'Enabled'
},
'version': '11',
'sslEnforcement': 'Enabled',
'minimalTlsVersion': 'TLSEnforcementDisabled',
'userVisibleState': 'Ready',
'fullyQualifiedDomainName': 'server1.postgres.database.azure.com',
'earliestRestoreDate': '2021-03-10T12:45:13.233+00:00',
'replicationRole': '',
'masterServerId': '',
'byokEnforcement': 'Disabled',
'privateEndpointConnections': [],
'infrastructureEncryption': 'Disabled',
'publicNetworkAccess': 'Enabled'
},
{
'sku': {
'name': 'B_Gen5_1',
'tier': 'Basic',
'family': 'Gen5',
'capacity': 1
},
'location': 'eastus',
'tags': {},
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.DBforPostgreSQL/servers/server1',
'name': 'server1',
'type': 'Microsoft.DBforPostgreSQL/servers',
'administratorLogin': 'Aquaadmin',
'storageProfile': {
'storageMB': 5120,
'backupRetentionDays': 7,
'geoRedundantBackup': 'Disabled',
'storageAutogrow': 'Disabled'
},
'version': '11',
'sslEnforcement': 'Enabled',
'minimalTlsVersion': 'TLSEnforcementDisabled',
'userVisibleState': 'Ready',
'fullyQualifiedDomainName': 'server1.postgres.database.azure.com',
'earliestRestoreDate': '2021-03-10T12:45:13.233+00:00',
'replicationRole': '',
'masterServerId': '',
'byokEnforcement': 'Disabled',
'privateEndpointConnections': [],
'infrastructureEncryption': 'Disabled',
'publicNetworkAccess': 'Enabled'
}
];

const createCache = (listPostgres) => {
return {
servers: {
listPostgres: {
'eastus': {
data: listPostgres
}
}
}
};
};

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

it('should give failing result if storage auto growth is not enabled for postgresql server', function(done) {
const cache = createCache([listPostgres[1]]);
storage.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(2);
expect(results[0].message).to.include('Storage Auto Growth is not enabled for PostgreSQL Server');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give passing result if storage auto growth is enabled for postgresql server', function(done) {
const cache = createCache([listPostgres[0]]);
storage.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('Storage Auto Growth is enabled for PostgreSQL Server');
expect(results[0].region).to.equal('eastus');
done();
});
});
});
});