Skip to content

Commit

Permalink
feat: add aditional note about X-Ray configuration when generated pol…
Browse files Browse the repository at this point in the history
…icy is empty
  • Loading branch information
glicht committed Apr 26, 2018
1 parent 75019fb commit feebd1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/lib/xray-trace-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,12 @@ export function createIAMPolicyDoc(map: ResourceActionMap, functionArn: string)
Resource: val.resources,
};
doc.Statement!.push(stm);
}
}
if(_.isEmpty(doc.Statement)) {
//append more details in the description
// tslint:disable-next-line:max-line-length
doc.Description += ". Note: No access to AWS resources were found for this function. It may be that X-Ray wasn't configured correctly. See: https://github.com/functionalone/aws-least-privilege#x-ray-setup on how to setup X-Ray.";
}
return doc;
}

Expand Down
5 changes: 4 additions & 1 deletion src/test/xray-trace-fetcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ describe('xray fetch tests', function() {

it('createIAMPolicyDoc creates proper policy action', function() {
const map = new ResourceActionMap();
//empty should add a "Note" to the description
let doc = createIAMPolicyDoc(map, "arn:aws:lambda:us-east-1:11223344:function:test");
assert.isTrue(doc.Description!.indexOf("Note: ") > 0);
map.set("arn:aws:s3:::test-bucket/*", new Set(['PutObjectTagging', 'GetObject', 'DeleteObject', 'PutObject']));
map.set("arn:aws:s3:::test-again/*", new Set(['PutObjectTagging', 'GetObject', 'DeleteObject', 'PutObject']));
map.set("arn:aws:dynamodb:us-east-1:*:table/test-it", new Set(['DeleteItem', 'PutItem', 'Scan', 'GetItem']));
const doc = createIAMPolicyDoc(map, "arn:aws:lambda:us-east-1:11223344:function:test");
doc = createIAMPolicyDoc(map, "arn:aws:lambda:us-east-1:11223344:function:test");
assert.isNotEmpty(doc.Statement);
assert.equal(doc.Statement!.length, 2);
assert.isNotEmpty(doc.Statement![0].Action);
Expand Down

0 comments on commit feebd1f

Please sign in to comment.