Skip to content
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

EN-1912: add service control policy support #384

Merged
merged 2 commits into from
May 26, 2023
Merged

EN-1912: add service control policy support #384

merged 2 commits into from
May 26, 2023

Conversation

JonathanLoscalzo
Copy link
Contributor

@JonathanLoscalzo JonathanLoscalzo commented May 4, 2023

What changed?

  • apply: support service control policies files, tags and targets
  • import: import service control policies with tags and targets
  • detect: cloudformation files changes:
    • force event-bus, rules and sqs to be at us-east-1 region (cloudtrail is not crossregional)

How was it tested?

If it was manually verified, list the instructions for your reviewers to follow.

  • Unit Tests
  • Functional Tests
  • Manually Verified
    • Tag
    • Untag
    • Create Policy
    • Delete Policy (and its variations)
    • Update Policy (expire statements, update statements, modify name or description)
    • Attach Target
    • Detach Target
    • Detect Before changes (take care the actor at if actor != identity_arn:)

@codecov
Copy link

codecov bot commented May 4, 2023

Codecov Report

Patch coverage: 76.89% and project coverage change: -9.66 ⚠️

Comparison is base (b9d1aa9) 85.20% compared to head (5432eaf) 75.54%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #384      +/-   ##
==========================================
- Coverage   85.20%   75.54%   -9.66%     
==========================================
  Files          98      102       +4     
  Lines       10731    11372     +641     
==========================================
- Hits         9143     8591     -552     
- Misses       1588     2781    +1193     
Flag Coverage Δ
functional_tests ?
functional_tests_config_discovery ?
unit_tests 75.54% <76.89%> (+0.25%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
iambic/core/template_generation.py 84.67% <ø> (-3.35%) ⬇️
iambic/main.py 50.49% <0.00%> (ø)
iambic/plugins/v0_1_0/aws/handlers.py 30.05% <42.55%> (-25.81%) ⬇️
iambic/plugins/v0_1_0/aws/models.py 59.79% <43.47%> (-26.65%) ⬇️
...bic/plugins/v0_1_0/aws/organizations/scp/models.py 62.30% <62.30%> (ø)
iambic/plugins/v0_1_0/aws/iambic_plugin.py 75.71% <75.00%> (-5.77%) ⬇️
...0_1_0/aws/organizations/scp/template_generation.py 95.23% <95.23%> (ø)
...mbic/plugins/v0_1_0/aws/organizations/scp/utils.py 96.39% <96.39%> (ø)
iambic/core/models.py 82.32% <100.00%> (-7.89%) ⬇️
iambic/core/utils.py 82.51% <100.00%> (-4.82%) ⬇️
... and 3 more

... and 39 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@JonathanLoscalzo JonathanLoscalzo force-pushed the task/ner-1912 branch 9 times, most recently from b01ba37 to 093b13e Compare May 17, 2023 13:32
@JonathanLoscalzo JonathanLoscalzo force-pushed the task/ner-1912 branch 6 times, most recently from 81917c6 to c29e9c4 Compare May 19, 2023 21:25
@JonathanLoscalzo JonathanLoscalzo changed the title EN-1912: adding SCP WIP EN-1912: add service control policy support May 19, 2023
@JonathanLoscalzo JonathanLoscalzo self-assigned this May 19, 2023
@JonathanLoscalzo JonathanLoscalzo marked this pull request as ready for review May 19, 2023 21:34
iambic/config/wizard.py Outdated Show resolved Hide resolved
iambic/plugins/v0_1_0/aws/models.py Outdated Show resolved Hide resolved
iambic/plugins/v0_1_0/aws/handlers.py Outdated Show resolved Hide resolved
organization_account: bool = Field(
False, description="if this is an organization account"
)
organization: Optional[AWSOrganization] = Field(
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not a blocker but at some point it may be worth circling back and removing organization and aws_config to prevent accidental circular refs.

We could do something like adding the additional required org attributes to the AWSAccount object and have some type of org directory on the org AWSAccount. We're currently doing something similar with CloudUMI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed the problem is you are not able to know if your account should be used to execute any operation over aws-organizations. You need the config to parse the account names to id's.

@@ -1875,7 +1876,9 @@ def configuration_wizard_change_detection_setup(self, aws_org: AWSOrganization):

role_name = IAMBIC_SPOKE_ROLE_NAME
hub_account_id = self.hub_account_id
sqs_arn = f"arn:aws:sqs:{self.aws_default_region}:{hub_account_id}:IAMbicChangeDetectionQueue{IAMBIC_CHANGE_DETECTION_SUFFIX}"
# cloudtrail is not cross-region, so we need to use us-east-1
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'll need to check if SSO messages are duplicated or if we're going to need a dedicated queue for SSO.

It may just require a ticket and not need to worry about fixing in this PR.

@Will-NOQ
Copy link
Collaborator

It'd also be worth adding some functional tests to this PR to check the typical CRUD scenarios with multiple SCPs on the org.

Copy link
Collaborator

@Will-NOQ Will-NOQ left a comment

Choose a reason for hiding this comment

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

Left some notes but nothing huge. Nice stuff!

return self.statement.sid

@staticmethod
def parse_raw_policy(resource_raw) -> "PolicyDocument":
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a big deal but classmethod is a better fit here

]


@retry(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a big deal but legacy_paginated_search, paginated_search, and boto_crud_call already have a retry with backoff on recoverable errors. It's really just throttling limit right now but if you're hitting an exception in these functions that aren't SCP specific the handling should really go there.


await asyncio.gather(*targets_tasks)

log.info(f"Deleting policy {policyId}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

It may be worth changing a lot of these logging messages to debug to reduce the noise a user will see when they're running it locally. I've def be guilty of using info instead of debug in here but I've been trying to go back and adjust.

return tasks, response


@retry(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this function will encounter a recoverable exception

return response


@retry(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this function will encounter a recoverable exception

return tasks, response


@retry(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this function will encounter a recoverable exception

return tasks, response


@retry(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this function will encounter a recoverable exception

@castrapel
Copy link
Contributor

castrapel commented May 26, 2023

@Will-NOQ - Unfortunately all of these need retry operators because AWS Orgs has ridiculously low rate limits (I saw TooManyRequestsException too easily, it was super brittle), A lot of ConcurrentModificationException errors (even though our modifications often are not being performed in parallel), and some other issues. Some discussions around this in Slack:

https://noqglobal.slack.com/archives/C02HF22G4MU/p1685030515330609?thread_ts=1685029944.899119&cid=C02HF22G4MU

https://noqglobal.slack.com/archives/C02HF22G4MU/p1685029944899119

Copy link
Contributor

@castrapel castrapel left a comment

Choose a reason for hiding this comment

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

LGTM!

@castrapel castrapel merged commit e055c6a into main May 26, 2023
4 checks passed
@castrapel castrapel deleted the task/ner-1912 branch May 26, 2023 20:37
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.

None yet

3 participants