forked from aquasecurity/cloudsploit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request aquasecurity#1187 from sadeed12345/SAAS-4491
SAAS-4491: Added Enhanced Metadata Collection Enabled Plugin
- Loading branch information
Showing
7 changed files
with
181 additions
and
2 deletions.
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
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
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
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
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
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,58 @@ | ||
var async = require('async'); | ||
var helpers = require('../../../helpers/aws'); | ||
|
||
module.exports = { | ||
title: 'Enhanced Metadata Collection Enabled', | ||
category: 'Image Builder', | ||
domain: 'Compute', | ||
severity: 'LOW', | ||
description: 'Ensure that enhanced metadata collection is enabled for image pipelines.', | ||
more_info: 'EC2 Image Builder is a fully managed AWS service that makes it easier to automate the creation, management, and deployment of customized, secure, and up-to-date server images that are pre-installed and pre-configured with software and settings to meet specific IT standards.', | ||
link: 'https://docs.aws.amazon.com/imagebuilder/latest/userguide/start-build-image-pipeline.html', | ||
recommended_action: 'Enable enhanced metadata collection for image pipeline.', | ||
apis: ['Imagebuilder:listImagePipelines'], | ||
|
||
run: function(cache, settings, callback) { | ||
var results = []; | ||
var source = {}; | ||
var regions = helpers.regions(settings); | ||
async.each(regions.imagebuilder, function(region, rcb){ | ||
var listImagePipelines = helpers.addSource(cache, source, | ||
['imagebuilder', 'listImagePipelines', region]); | ||
|
||
if (!listImagePipelines) return rcb(); | ||
|
||
if (listImagePipelines.err || !listImagePipelines.data) { | ||
helpers.addResult(results, 3, | ||
'Unable to list image pipeline: ' + helpers.addError(listImagePipelines), region); | ||
return rcb(); | ||
} | ||
|
||
if (!listImagePipelines.data.length) { | ||
helpers.addResult(results, 0, | ||
'No Image Builder image pipelines found', region); | ||
return rcb(); | ||
} | ||
|
||
for (let image of listImagePipelines.data) { | ||
if (!image.arn) continue; | ||
|
||
let resource = image.arn; | ||
|
||
if (image.enhancedImageMetadataEnabled) { | ||
helpers.addResult(results, 0, | ||
'Image pipeline has enhanced metadata collection enabled', | ||
region, resource); | ||
} else { | ||
helpers.addResult(results, 2, | ||
'Image pipeline does not have enhanced metadata collection enabled', | ||
region, resource); | ||
} | ||
} | ||
|
||
rcb(); | ||
}, function(){ | ||
callback(null, results, source); | ||
}); | ||
} | ||
}; |
109 changes: 109 additions & 0 deletions
109
plugins/aws/imagebuilder/enhancedMetadataEnabled.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,109 @@ | ||
var expect = require('chai').expect;; | ||
var enhancedMetadataEnabled = require('./enhancedMetadataEnabled'); | ||
|
||
const listImagePipelines = [ | ||
{ | ||
"arn": "arn:aws:imagebuilder:us-east-1:000011112222:image-pipeline/akhtar-img-pipeline", | ||
"name": "akhtar-img-pipeline", | ||
"platform": "Linux", | ||
"enhancedImageMetadataEnabled": true, | ||
"imageRecipeArn": "arn:aws:imagebuilder:us-east-1:000011112222:image-recipe/akhtar-img-rc/1.0.0", | ||
"infrastructureConfigurationArn": "arn:aws:imagebuilder:us-east-1:000011112222:infrastructure-configuration/akhtar-img-pipeline-914d5fdf-45db-4231-ae0e-991c39f9e594", | ||
"distributionConfigurationArn": "arn:aws:imagebuilder:us-east-1:000011112222:distribution-configuration/akhtar-img-pipeline-914d5fdf-45db-4231-ae0e-991c39f9e594", | ||
"imageTestsConfiguration": { | ||
"imageTestsEnabled": true, | ||
"timeoutMinutes": 720 | ||
}, | ||
"status": "ENABLED", | ||
"dateCreated": "2022-03-08T11:20:43.395Z", | ||
"dateUpdated": "2022-03-08T11:20:43.395Z", | ||
"tags": {} | ||
}, | ||
{ | ||
"arn": "arn:aws:imagebuilder:us-east-1:000011112222:image-pipeline/akhtar-img-pipeline", | ||
"name": "akhtar-img-pipeline", | ||
"platform": "Linux", | ||
"enhancedImageMetadataEnabled": false, | ||
"imageRecipeArn": "arn:aws:imagebuilder:us-east-1:000011112222:image-recipe/akhtar-img-rc/1.0.0", | ||
"infrastructureConfigurationArn": "arn:aws:imagebuilder:us-east-1:000011112222:infrastructure-configuration/akhtar-img-pipeline-914d5fdf-45db-4231-ae0e-991c39f9e594", | ||
"distributionConfigurationArn": "arn:aws:imagebuilder:us-east-1:000011112222:distribution-configuration/akhtar-img-pipeline-914d5fdf-45db-4231-ae0e-991c39f9e594", | ||
"imageTestsConfiguration": { | ||
"imageTestsEnabled": true, | ||
"timeoutMinutes": 720 | ||
}, | ||
"status": "ENABLED", | ||
"dateCreated": "2022-03-08T11:20:43.395Z", | ||
"dateUpdated": "2022-03-08T11:20:43.395Z", | ||
"tags": {} | ||
} | ||
]; | ||
|
||
const createCache = (images) => { | ||
return { | ||
imagebuilder: { | ||
listImagePipelines: { | ||
"us-east-1": { | ||
data: images | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
const createNullCache = () => { | ||
return { | ||
imagebuilder: { | ||
listImagePipelines: { | ||
"us-east-1": { | ||
data: null | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
describe('enhancedMetadataEnabled', () => { | ||
describe('run', () => { | ||
it('should PASS if Image pipeline has enhanced metadata collection enabled', () => { | ||
const cache = createCache([listImagePipelines[0]]); | ||
enhancedMetadataEnabled.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(0); | ||
expect(results[0].message).to.include('Image pipeline has enhanced metadata collection enabled'); | ||
expect(results[0].region).to.equal('us-east-1'); | ||
}) | ||
}); | ||
it('should FAIL if Image pipeline does not have enhanced metadata collection enabled', () => { | ||
const cache = createCache([listImagePipelines[1]]); | ||
enhancedMetadataEnabled.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(2); | ||
expect(results[0].message).to.include('Image pipeline does not have enhanced metadata collection enabled'); | ||
expect(results[0].region).to.equal('us-east-1'); | ||
}) | ||
}); | ||
it('should PASS if No image pipeline list found', () => { | ||
const cache = createCache([]); | ||
enhancedMetadataEnabled.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(0); | ||
expect(results[0].message).to.include('No Image Builder image pipelines found'); | ||
expect(results[0].region).to.equal('us-east-1'); | ||
}) | ||
}); | ||
it('should UNKNOWN if Unable to list image pipeline', () => { | ||
const cache = createNullCache(); | ||
enhancedMetadataEnabled.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 list image pipeline'); | ||
expect(results[0].region).to.equal('us-east-1'); | ||
}) | ||
}); | ||
it('should not return anything if list image pipeline response is not found', () => { | ||
enhancedMetadataEnabled.run({}, {}, (err, results) => { | ||
expect(results.length).to.equal(0); | ||
}) | ||
}); | ||
}); | ||
}); |