Skip to content

Commit

Permalink
OCI - Cloud Guard Enabled Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mehakseedat63 committed Jul 17, 2022
1 parent 034998e commit c1883ed
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 1 deletion.
9 changes: 9 additions & 0 deletions collectors/oracle/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ var calls = {
filterConfig: [true]
}
},
cloudguardConfiguration: {
get: {
api: 'cloudguard',
filterKey: ['compartmentId'],
filterValue: ['compartmentId'],
restVersion: '/20200131',
}
},
group: {
list: {
api: 'iam',
Expand Down Expand Up @@ -379,6 +387,7 @@ var postcalls = {
limit: 900
}
},

waasPolicy: {
get: {
api: 'waas',
Expand Down
3 changes: 3 additions & 0 deletions exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,9 @@ module.exports = {
'okePrivateEndpoint' : require(__dirname + '/plugins/oracle/oke/okePrivateEndpoint.js'),
'okeSecretsEncrypted' : require(__dirname + '/plugins/oracle/oke/okeSecretsEncrypted.js'),
'okeSecurityGroups' : require(__dirname + '/plugins/oracle/oke/okeSecurityGroups.js'),

'cloudguardEnabled' : require(__dirname + '/plugins/oracle/cloudguard/cloudguardEnabled.js'),

},
google: {
'excessiveFirewallRules' : require(__dirname + '/plugins/google/vpcnetwork/excessiveFirewallRules.js'),
Expand Down
3 changes: 2 additions & 1 deletion helpers/oracle/regions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ module.exports = {
customerSecretKey: ['default'],
vault: regions,
keys: regions,
cluster: regions
cluster: regions,
cloudguardConfiguration: ['default']
};
10 changes: 10 additions & 0 deletions other_modules/oci/services.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
}
}
},
"cloudguard": {
"cloudguardConfiguration": {
"get": {
"allowedQueryStrings": ["compartmentId"],
"method": "GET",
"path": "configuration",
"endpoint": "cloudguard-cp-api.{{region}}.oci.oraclecloud.com"
}
}
},
"oke": {
"cluster": {
"list": {
Expand Down
40 changes: 40 additions & 0 deletions plugins/oracle/cloudguard/cloudguardEnabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var helpers = require('../../../helpers/oracle');

module.exports = {
title: 'Cloud Guard Enabled',
category: 'Cloud Guard',
domain: 'Management and Governance',
description: 'Ensure Cloud Guard is enabled in the root compartment of the tenancy.',
more_info: 'Cloud Guard detects misconfigured resources and insecure activity within a tenancy and provides security administrators with the visibility to resolve these issues. Upon detection, Cloud Guard can suggest, assist, or take corrective actions to mitigate these issues.',
recommended_action: 'Cloud Guard should be enabled in the root compartment of your tenancy.',
link: 'https://docs.oracle.com/en-us/iaas/cloud-guard/using/index.htm',
apis: ['cloudguardConfiguration:get'],

run: function(cache, settings, callback) {
var results = [];
var source = {};
var region = helpers.objectFirstKey(cache['regionSubscription']['list']);

if (helpers.checkRegionSubscription(cache, source, results, region)) {

var config = helpers.addSource(cache, source,
['cloudguardConfiguration', 'get', region]);

if (!config) return callback(null, results, source);

if (config.err) {
helpers.addResult(results, 3,
'Unable to query for cloud guard configuration: ' + helpers.addError(config), region);
return callback(null, results, source);
}
if (config.data && Object.keys(config.data).length && config.data.status && config.data.status === 'ENABLED') {
helpers.addResult(results, 0,
'Cloud Guard is enabled in the root compartment of the tenancy.', region);
} else {
helpers.addResult(results, 2,
'Cloud Guard is not enabled in the root compartment of the tenancy.', region);
}
}
callback(null, results, source);
}
};
104 changes: 104 additions & 0 deletions plugins/oracle/cloudguard/cloudguardEnabled.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
var expect = require('chai').expect;
var plugin = require('./cloudguardEnabled');

const createCache = (err, data) => {
return {
regionSubscription: {
"list": {
"us-ashburn-1": {
"data": [
{
"regionKey": "IAD",
"regionName": "us-ashburn-1",
"status": "READY",
"isHomeRegion": true
},
{
"regionKey": "LHR",
"regionName": "uk-london-1",
"status": "READY",
"isHomeRegion": false
},
{
"regionKey": "PHX",
"regionName": "us-phoenix-1",
"status": "READY",
"isHomeRegion": false
}
]
}
}
},

cloudguardConfiguration: {
get: {
'us-ashburn-1': {
err: err,
data: data
}
}
}
}
};

describe('cloudguardEnabled', function () {
describe('run', function () {
it('should give unknown result if a configuration error is passed or no data is present', function (done) {
const callback = (err, results) => {
expect(results.length).to.be.above(0)
expect(results[0].status).to.equal(3)
expect(results[0].message).to.include('Unable to query for cloud guard configuration')
expect(results[0].region).to.equal('us-ashburn-1')
done()
};

const cache = createCache(
['error'],
null,
);

plugin.run(cache, {}, callback);
})

it('should give passing result cloud guard is enabled in the root compartment of the tenancy', function (done) {
const callback = (err, results) => {
expect(results.length).to.be.above(0)
expect(results[0].status).to.equal(0)
expect(results[0].message).to.include('is enabled')
expect(results[0].region).to.equal('us-ashburn-1')
done()
};

const cache = createCache(
null,
{
reportingRegion: 'us-ashburn-1',
status: 'ENABLED',
selfManageResources: false
}
);

plugin.run(cache, {}, callback);
})
it('should give failing result if cloud guard is not enabled in the root compartment of the tenancy', function (done) {
const callback = (err, results) => {
expect(results.length).to.be.above(0)
expect(results[0].status).to.equal(2)
expect(results[0].message).to.include('is not enabled')
expect(results[0].region).to.equal('us-ashburn-1')
done()
};

const cache = createCache(
null,
{
reportingRegion: 'us-ashburn-1',
status: 'DISABLED',
selfManageResources: false
}
);

plugin.run(cache, {}, callback);
})
})
})

0 comments on commit c1883ed

Please sign in to comment.