-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Feature or Bugfix <!-- please choose --> - Feature ### Detail - Enable SageMaker Studio Domain to be deployed in a already provisioned VPC ### Relates - #795 ### Security Please answer the questions below briefly where applicable, or write `N/A`. Based on [OWASP 10](https://owasp.org/Top10/en/). - Does this PR introduce or modify any input fields or queries - this includes fetching data from storage outside the application (e.g. a database, an S3 bucket)? - Is the input sanitized? - What precautions are you taking before deserializing the data you consume? - Is injection prevented by parametrizing queries? - Have you ensured no `eval` or similar functions are used? - Does this PR introduce any functionality or component that requires authorization? - How have you ensured it respects the existing AuthN/AuthZ mechanisms? - Are you logging failed auth attempts? - Are you using or adding any cryptographic features? - Do you use a standard proven implementations? - Are the used keys controlled by the customer? Where are they stored? - Are you introducing any new policies/roles/users? - Have you used the least-privilege principle? How? By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
- Loading branch information
1 parent
5061ecb
commit 94c93d9
Showing
33 changed files
with
1,207 additions
and
253 deletions.
There are no files selected for viewing
This file contains 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,65 @@ | ||
import logging | ||
|
||
from dataall.base.aws.sts import SessionHelper | ||
from botocore.exceptions import ClientError | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class EC2: | ||
|
||
@staticmethod | ||
def get_client(account_id: str, region: str, role=None): | ||
session = SessionHelper.remote_session(accountid=account_id, role=role) | ||
return session.client('ec2', region_name=region) | ||
|
||
@staticmethod | ||
def check_default_vpc_exists(AwsAccountId: str, region: str, role=None): | ||
log.info("Check that default VPC exists..") | ||
client = EC2.get_client(account_id=AwsAccountId, region=region, role=role) | ||
response = client.describe_vpcs( | ||
Filters=[{'Name': 'isDefault', 'Values': ['true']}] | ||
) | ||
vpcs = response['Vpcs'] | ||
log.info(f"Default VPCs response: {vpcs}") | ||
if vpcs: | ||
vpc_id = vpcs[0]['VpcId'] | ||
subnetIds = EC2._get_vpc_subnets(AwsAccountId=AwsAccountId, region=region, vpc_id=vpc_id, role=role) | ||
if subnetIds: | ||
return vpc_id, subnetIds | ||
return False | ||
|
||
@staticmethod | ||
def _get_vpc_subnets(AwsAccountId: str, region: str, vpc_id: str, role=None): | ||
client = EC2.get_client(account_id=AwsAccountId, region=region, role=role) | ||
response = client.describe_subnets( | ||
Filters=[{'Name': 'vpc-id', 'Values': [vpc_id]}] | ||
) | ||
return [subnet['SubnetId'] for subnet in response['Subnets']] | ||
|
||
@staticmethod | ||
def check_vpc_exists(AwsAccountId, region, vpc_id, role=None, subnet_ids=[]): | ||
try: | ||
ec2 = EC2.get_client(account_id=AwsAccountId, region=region, role=role) | ||
response = ec2.describe_vpcs(VpcIds=[vpc_id]) | ||
except ClientError as e: | ||
log.exception(f'VPC Id {vpc_id} Not Found: {e}') | ||
raise Exception(f'VPCNotFound: {vpc_id}') | ||
|
||
try: | ||
if subnet_ids: | ||
response = ec2.describe_subnets( | ||
Filters=[ | ||
{ | ||
'Name': 'vpc-id', | ||
'Values': [vpc_id] | ||
}, | ||
], | ||
SubnetIds=subnet_ids | ||
) | ||
except ClientError as e: | ||
log.exception(f'Subnet Id {subnet_ids} Not Found: {e}') | ||
raise Exception(f'VPCSubnetsNotFound: {subnet_ids}') | ||
|
||
if not subnet_ids or len(response['Subnets']) != len(subnet_ids): | ||
raise Exception(f'Not All Subnets: {subnet_ids} Are Within the Specified VPC Id {vpc_id}') |
This file contains 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 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 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 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 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 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 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 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 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 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.