-
Notifications
You must be signed in to change notification settings - Fork 695
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
backup vault role level access #1593
Open
abdullahaslam306
wants to merge
4
commits into
aquasecurity:master
Choose a base branch
from
abdullahaslam306:feature/SAAS-14741-aws-ensure-backup-vaults-are-accessed-through-roles
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,81 @@ | ||
var async = require('async'); | ||
var helpers = require('../../../helpers/aws'); | ||
|
||
module.exports = { | ||
title: 'Backup Vault Role Access', | ||
category: 'Backup', | ||
domain: 'Storage', | ||
description: 'Ensure that AWS Backup vaults are accessed through roles.', | ||
more_info: 'As a security best practice and to adhere to compliance standards, ensure only role level access is allowed on a Backup vault.', | ||
recommended_action: 'Modify access policy and give only role level access to backup vault.', | ||
link: 'https://docs.aws.amazon.com/aws-backup/latest/devguide/creating-a-vault-access-policy.html', | ||
apis: ['Backup:listBackupVaults', 'Backup:getBackupVaultAccessPolicy'], | ||
|
||
run: function(cache, settings, callback) { | ||
var results = []; | ||
var source = {}; | ||
var regions = helpers.regions(settings); | ||
|
||
async.each(regions.backup, function(region, rcb){ | ||
var listBackupVaults = helpers.addSource(cache, source, | ||
['backup', 'listBackupVaults', region]); | ||
|
||
if (!listBackupVaults) return rcb(); | ||
|
||
if (listBackupVaults.err || !listBackupVaults.data) { | ||
helpers.addResult(results, 3, | ||
`Unable to query for Backup vault list: ${helpers.addError(listBackupVaults)}`, region); | ||
return rcb(); | ||
} | ||
|
||
if (!listBackupVaults.data.length) { | ||
helpers.addResult(results, 0, 'No Backup vaults found', region); | ||
return rcb(); | ||
} | ||
|
||
for (let vault of listBackupVaults.data){ | ||
if (!vault.BackupVaultArn || !vault.BackupVaultName) continue; | ||
|
||
let resource = vault.BackupVaultArn; | ||
|
||
let getBackupVaultAccessPolicy = helpers.addSource(cache, source, | ||
['backup', 'getBackupVaultAccessPolicy', region, vault.BackupVaultName]); | ||
|
||
if (!getBackupVaultAccessPolicy || getBackupVaultAccessPolicy.err || !getBackupVaultAccessPolicy.data || !getBackupVaultAccessPolicy.data.Policy) { | ||
helpers.addResult(results, 3, `Unable to get Backup vault access policy: ${helpers.addError(getBackupVaultAccessPolicy)}`, region, resource); | ||
continue; | ||
} | ||
|
||
var statements = helpers.normalizePolicyDocument(getBackupVaultAccessPolicy.data.Policy); | ||
|
||
if (!statements || !statements.length) { | ||
helpers.addResult(results, 0, | ||
'The Backup Vault policy does not have trust relationship statements', | ||
region, resource); | ||
continue; | ||
} | ||
|
||
let roleAccess = true; | ||
for (var statement of statements) { | ||
var principalEval = helpers.globalPrincipal(statement.Principal); | ||
if (principalEval && statement.Effect.toUpperCase() === 'ALLOW') { | ||
roleAccess = false; | ||
break; | ||
} | ||
|
||
} | ||
|
||
if (!roleAccess) { | ||
helpers.addResult(results, 2, | ||
'Backup Vault does not have role level access only' , region, resource); | ||
} else { | ||
helpers.addResult(results, 0, | ||
'Backup Vault have role level access only', region, resource); | ||
} | ||
} | ||
rcb(); | ||
}, function(){ | ||
callback(null, results, source); | ||
}); | ||
} | ||
}; |
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,135 @@ | ||
var expect = require('chai').expect; | ||
const backupVaultRoleAccess = require('./backupVaultRoleAccess'); | ||
|
||
const listBackupVaults = [ | ||
{ | ||
"BackupVaultName": "test", | ||
"BackupVaultArn": "arn:aws:backup:us-east-1:000011112222:backup-vault:test", | ||
"CreationDate": "2021-11-26T17:05:36.477000+05:00", | ||
"EncryptionKeyArn": "arn:aws:kms:us-east-1:000011112222:key/228d6374-d201-428d-b084-842fc7b2d148", | ||
"CreatorRequestId": "Default", | ||
"NumberOfRecoveryPoints": 0 | ||
}, | ||
{ | ||
"BackupVaultName": "test", | ||
"BackupVaultArn": "arn:aws:backup:us-east-1:000011112222:backup-vault:test", | ||
"CreationDate": "2022-01-21T23:05:24.095000+05:00", | ||
"EncryptionKeyArn": "arn:aws:kms:us-east-1:000011112222:key/ad013a33-b01d-4d88-ac97-127399c18b3e", | ||
"CreatorRequestId": "967e0cd4-59c5-471c-8d4d-582a9ee27433", | ||
"NumberOfRecoveryPoints": 0 | ||
} | ||
]; | ||
|
||
|
||
const getBackupVaultAccessPolicy =[ | ||
{ | ||
"BackupVaultName": "test", | ||
"BackupVaultArn": "arn:aws:backup:us-east-1:000011112222:backup-vault:test", | ||
"Policy": { | ||
"Version":"2012-10-17", | ||
"Statement":[ | ||
{ | ||
"Effect": 'Allow', | ||
"Principal": 'arn:aws:iam::112233445566:role/MyRole', | ||
"Action": [ 'backup:DeleteRecoveryPoint' ], | ||
"Resource": [ '*' ] | ||
}, | ||
], | ||
} | ||
} , | ||
{ | ||
"BackupVaultName": "test", | ||
"BackupVaultArn": "arn:aws:backup:us-east-1:000011112222:backup-vault:test", | ||
"Policy": { | ||
"Version":"2012-10-17", | ||
"Statement":[ | ||
{ | ||
"Effect": 'Allow', | ||
"Principal": '*', | ||
"Action": [ 'backup:CopyIntoBackupVault' ], | ||
"Resource": [ '*' ], | ||
}, | ||
], | ||
} | ||
} | ||
]; | ||
|
||
const createCache = (listBackupVaults, getBackupVaultAccessPolicy, listBackupVaultsErr, getBackupVaultAccessPolicyErr) => { | ||
let name = (listBackupVaults && listBackupVaults.length) ? listBackupVaults[0].BackupVaultName : null; | ||
return { | ||
backup: { | ||
listBackupVaults: { | ||
'us-east-1': { | ||
data: listBackupVaults, | ||
err: listBackupVaultsErr | ||
} | ||
}, | ||
getBackupVaultAccessPolicy: { | ||
'us-east-1': { | ||
[name]: { | ||
data: getBackupVaultAccessPolicy, | ||
err: getBackupVaultAccessPolicyErr | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
|
||
describe('backupVaultRoleAccess', function () { | ||
describe('run', function () { | ||
it('should PASS if Backup Vault have role level access only', function (done) { | ||
const cache = createCache([listBackupVaults[1]], getBackupVaultAccessPolicy[0]); | ||
backupVaultRoleAccess.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(0); | ||
expect(results[0].region).to.equal('us-east-1'); | ||
expect(results[0].message).to.include('Backup Vault have role level access only') | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should FAIL if Backup Vault does not have role level access only', function (done) { | ||
const cache = createCache([listBackupVaults[0]], getBackupVaultAccessPolicy[1] ); | ||
backupVaultRoleAccess.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(2); | ||
expect(results[0].region).to.equal('us-east-1'); | ||
expect(results[0].message).to.include('Backup Vault does not have role level access only') | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should PASS if no Backup vault list found', function (done) { | ||
const cache = createCache([]); | ||
backupVaultRoleAccess.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(0); | ||
expect(results[0].region).to.equal('us-east-1'); | ||
expect(results[0].message).to.include('No Backup vaults found') | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should UNKNOWN if Unable to query for Backup vault list', function (done) { | ||
const cache = createCache(null, { message: 'Unable to query for Backup vault list' }); | ||
backupVaultRoleAccess.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 Backup vault list') | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should UNKNOWN if Unable to get Backup vault policy', function (done) { | ||
const cache = createCache([listBackupVaults[0]], null, null, { message: 'Unable to get Backup vault policy' }); | ||
backupVaultRoleAccess.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 get Backup vault policy') | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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.
why does it have to be global principal?