Skip to content

Commit

Permalink
Validate SecretsManager secret policy document size (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdpauw committed Aug 25, 2024
1 parent 8613834 commit ef00e04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/policy/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export class PolicyDocument {
if (policyType === PolicyType.S3 && doc.length > 20*1024) {
errors.push(`The size of an S3 bucket policy document (${doc.length}) should not exceed 20kB.`);
}
if (policyType === PolicyType.SecretsManager && doc.length > 20*1024) {
errors.push(`The size of a SecretsManager secret policy document (${doc.length}) should not exceed 20kB.`);
}
}
return errors;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/policy/policy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,22 @@ describe('#PolicyDocument', function() {
]);
});
});

describe('SecretsManager secret policy document longer than 20kB', function() {
const policy = new PolicyDocument();
for (let i = 1; i < 154; i++) {
policy.addStatements(new Statement({
sid: '' + i,
principals: [new RolePrincipal('123456789000', 'a_role')],
actions: ['action'],
resources: ['resource'],
}));
}
it('should be invalid', function() {
const errors = policy.validate(PolicyType.SecretsManager);
expect(errors).to.deep.equal([
'The size of a SecretsManager secret policy document (20585) should not exceed 20kB.',
]);
});
});
});

0 comments on commit ef00e04

Please sign in to comment.