Skip to content

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

naveenkoppula
Copy link

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:

Initial Push for IAM_ROLE_NOT_USED
@naveenkoppula
Copy link
Author

Re-open IAM_ROLE_NOT_USED

@naveenkoppula naveenkoppula reopened this Mar 4, 2020
"SourceRuntime": "python3.6-lib",
"CodeKey": "IAM_ROLE_NOT_USED.zip",
"InputParameters": "{\"DaysBeforeUnused\": 90}",
"OptionalParameters": "{}",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put as empty here

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant:
"OptionalParameters": "{\"DaysBeforeUnused\": \"\"}",

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@naveenkoppula naveenkoppula requested a review from jongogogo March 4, 2020 12:23


import json

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra breaks

Copy link

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

Copy link
Owner

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

Copy link
Owner

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

Copy link
Owner

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:
Copy link
Owner

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.

Copy link

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)."))
Copy link
Owner

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_)

Copy link

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):
Copy link
Owner

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.

Copy link

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test evaluate parameter separately.

Copy link

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": "{}",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant:
"OptionalParameters": "{\"DaysBeforeUnused\": \"\"}",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants