-
Notifications
You must be signed in to change notification settings - Fork 10
IAM_ROLE_NOT_USED #5
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
base: master
Are you sure you want to change the base?
Conversation
Initial Push for IAM_ROLE_NOT_USED
Re-open IAM_ROLE_NOT_USED |
"SourceRuntime": "python3.6-lib", | ||
"CodeKey": "IAM_ROLE_NOT_USED.zip", | ||
"InputParameters": "{\"DaysBeforeUnused\": 90}", | ||
"OptionalParameters": "{}", |
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.
Put as empty here
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.
I meant:
"OptionalParameters": "{\"DaysBeforeUnused\": \"\"}",
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.
Done
|
||
|
||
import json | ||
|
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.
remove extra breaks
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.
Done
import json | ||
|
||
from datetime import datetime, timezone | ||
|
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.
remove extra breaks
from datetime import datetime, timezone | ||
|
||
from rdklib import Evaluator, Evaluation, ConfigRule, ComplianceType, InvalidParametersError | ||
|
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.
remove extra breaks
RESOURCE_TYPE = 'AWS::IAM::Role' | ||
PAGE_SIZE = 20 | ||
DEFAULT_DAYS = 90 | ||
|
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.
remove extra breaks
return evaluations | ||
|
||
def evaluate_parameters(self, rule_parameters): | ||
if 'DaysBeforeUnused' not in rule_parameters: |
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.
No, you stated it is optional. You should not make it mandatory.
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.
Modified according to the comment.
else: | ||
evaluations.append(Evaluation(ComplianceType.NON_COMPLIANT, | ||
username, RESOURCE_TYPE, | ||
annotation="Ensure that no AWS IAM Role is unused and make an action if unused (e.g. delete the user).")) |
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.
Annotation should be focusing on explaning the situation, to help on resolution.
"This AWS IAM Role has not been used within the last {} day(s)".format(_rule_param_)
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.
Changed the annotation message.
@patch.object(CLIENT_FACTORY, 'build_client', MagicMock(side_effect=mock_get_client)) | ||
class ComplianceTest(unittest.TestCase): | ||
|
||
def test_compliance(self): |
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.
need to follow the naming convention.
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.
Done
|
||
def test_compliance(self): | ||
rule_parameters = {"DaysBeforeUnused": "90"} | ||
rule_parameters = RULE.evaluate_parameters(rule_parameters) |
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.
test evaluate parameter separately.
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.
Added another testcase for evaluating rule parameters
"SourceRuntime": "python3.6-lib", | ||
"CodeKey": "IAM_ROLE_NOT_USED.zip", | ||
"InputParameters": "{\"DaysBeforeUnused\": 90}", | ||
"OptionalParameters": "{}", |
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.
I meant:
"OptionalParameters": "{\"DaysBeforeUnused\": \"\"}",
Initial Push for IAM_ROLE_NOT_USED
I confirm these files are made available under CC0 1.0 Universal (https://creativecommons.org/publicdomain/zero/1.0/legalcode)
Issue #, if available:
Description of changes: