-
Notifications
You must be signed in to change notification settings - Fork 82
[Gh 884] IAM policy splitting for requestor IAM policies #1650
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
Merged
dlpzx
merged 35 commits into
data-dot-all:main
from
TejasRGitHub:gh-884-IAM-policy-splitting
Feb 3, 2025
Merged
Changes from 14 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
34ac3e2
Changes for splitting IAM role changes
TejasRGitHub 330dc51
Merge branch 'main' into gh-884-IAM-policy-splitting
44d1205
Sycing latest chanegs from aws dev for iam splitting
TejasRGitHub e131da7
Corrections to unit tests
TejasRGitHub 3087bc6
Service Quota file
TejasRGitHub db36fb0
Adding comments and other changes
TejasRGitHub 6af3c2e
Correcting unit tests and making env chanegs for SES emails to work
TejasRGitHub e072f25
Changes observed during testing
TejasRGitHub d83c805
Adding new file and changes for IAM policy utils
TejasRGitHub b51a428
Corrections
TejasRGitHub fe6c1fe
Adding converter file
TejasRGitHub 2070328
backend linting changes
TejasRGitHub 508f520
Unit test corrections
TejasRGitHub 9d8583d
Correction in share
TejasRGitHub d40faab
Adding comments
TejasRGitHub f78429c
Simplifying interface
TejasRGitHub 7303bba
Fixing few tests
TejasRGitHub 200313b
Linting
TejasRGitHub 0f1d2d8
Merge branch 'main' into gh-884-IAM-policy-splitting
21af992
Change after PR review
TejasRGitHub 73f98b1
Reverting changes made
TejasRGitHub e27b0aa
More changes
TejasRGitHub 8abc4d6
Minor changes
TejasRGitHub 3b4dce2
Removing managed policy from unused gql calls
TejasRGitHub 1f5ec6e
python linting
TejasRGitHub a048fe9
Corrections
TejasRGitHub f48e07f
Naming changes in exceptions
TejasRGitHub 99556b3
Refactoring and corrections
TejasRGitHub 61f616b
Fixing unit tests
TejasRGitHub e84e526
Linting after correcting tests
TejasRGitHub f5825ef
Removing parts not part of this PR
TejasRGitHub 50c906d
Corrections
TejasRGitHub 340d3a2
Merge branch 'main' into gh-884-IAM-policy-splitting
5a29bd1
Merge branch 'main' into gh-884-IAM-policy-splitting
5d283b3
Linting / formatting and fixing tests
TejasRGitHub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import logging | ||
from botocore.exceptions import ClientError | ||
|
||
from .sts import SessionHelper | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class ServiceQuota: | ||
def __init__(self, account_id, region): | ||
session = SessionHelper.remote_session(accountid=account_id, region=region) | ||
self.client = session.client('service-quotas') | ||
|
||
def list_services(self): | ||
try: | ||
log.info('Fetching services list with service codes in aws account') | ||
services_list = [] | ||
paginator = self.client.get_paginator('list_services') | ||
for page in paginator.paginate(): | ||
services_list.extend(page.get('Services')) | ||
return services_list | ||
except ClientError as e: | ||
if e.response['Error']['Code'] == 'AccessDenied': | ||
raise Exception( | ||
f'Data.all Environment Pivot Role does not have permissions to list services for getting service code : {e}' | ||
) | ||
log.error(f'Failed list services and service codes due to: {e}') | ||
return [] | ||
|
||
def list_service_quota(self, service_code): | ||
try: | ||
log.info('Fetching services quota code in aws account') | ||
service_quota_code_list = [] | ||
paginator = self.client.get_paginator('list_service_quotas') | ||
for page in paginator.paginate(ServiceCode=service_code): | ||
service_quota_code_list.extend(page.get('Quotas')) | ||
log.debug(f'Services quota list: {service_quota_code_list}') | ||
return service_quota_code_list | ||
except ClientError as e: | ||
if e.response['Error']['Code'] == 'AccessDenied': | ||
raise Exception(f'Data.all Environment Pivot Role does not have permissions to list quota codes: {e}') | ||
log.error(f'Failed list quota codes to: {e}') | ||
return [] | ||
|
||
def get_service_quota_value(self, service_code, service_quota_code): | ||
try: | ||
log.info( | ||
f'Getting service quota for service code: {service_code} and service quota code: {service_quota_code}' | ||
) | ||
response = self.client.get_service_quota(ServiceCode=service_code, QuotaCode=service_quota_code) | ||
return response['Quota']['Value'] | ||
except ClientError as e: | ||
if e.response['Error']['Code'] == 'AccessDenied': | ||
raise Exception(f'Data.all Environment Pivot Role does not have permissions to list quota codes: {e}') | ||
log.error(f'Failed list quota codes to: {e}') | ||
return None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import Dict, Any | ||
from aws_cdk import aws_iam as iam | ||
|
||
|
||
def convert_from_json_to_iam_policy_statement_with_conditions(iam_policy: Dict[Any, Any]): | ||
return iam.PolicyStatement( | ||
sid=iam_policy.get('Sid'), | ||
effect=iam_policy.get('Effect'), | ||
actions=iam_policy.get('Action'), | ||
resources=iam_policy.get('Resource'), | ||
conditions=iam_policy.get('Condition'), | ||
) | ||
|
||
|
||
def convert_from_json_to_iam_policy_statement(iam_policy: Dict[Any, Any]): | ||
return iam.PolicyStatement( | ||
sid=iam_policy.get('Sid'), | ||
effect=iam_policy.get('Effect'), | ||
actions=iam_policy.get('Action'), | ||
resources=iam_policy.get('Resource'), | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
backend/dataall/core/environment/cdk/pivot_role_core_policies/service_quota.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from dataall.core.environment.cdk.pivot_role_stack import PivotRoleStatementSet | ||
from aws_cdk import aws_iam as iam | ||
|
||
|
||
class ServiceQuotaPivotRole(PivotRoleStatementSet): | ||
""" | ||
Class including all permissions needed by the pivot role to work with AWS Service Quota. | ||
It allows pivot role to: | ||
- List and Get Service Quota details | ||
""" | ||
|
||
def get_statements(self): | ||
statements = [ | ||
# Service Quota - Needed to determine the number of service quotas for managed policies which can be attached | ||
iam.PolicyStatement( | ||
sid='ServiceQuotaListGet', | ||
effect=iam.Effect.ALLOW, | ||
actions=['servicequotas:List*', 'servicequotas:Get*'], | ||
resources=['*'], | ||
TejasRGitHub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
] | ||
return statements |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.