Skip to content

Commit f235c19

Browse files
authored
Handle External ID SSM v1.6.1> (#630)
### Feature or Bugfix <!-- please choose --> - Bugfix ### Detail - As part of v1.6 Data.All moved away from storing the externalID as a rotated secret in Secret Manager and instead placed the external ID in SSM Parameter Store. - In the current implementation in v1.6.1 we check if the secret exists and the ssm parameter does not and if these conditions are met the secret value is retrieved and a new ssm parameter is set with the same externalID - The problem with the above is CDK uses dynamic references to resolve the secret value (meaning in the first upgrade deployment we set ssm parameter as ref to secret value and delete secret, in 2nd and so one deployments it will fail with `Secrets Manager can't find the specified secret.`) - Alternatively we can not use the CDK bootstrap role, such as the look up role, and boto3 SDK commands to retrieve the secret value during `synth` because IAM permissions out of the box do not allow said actions - This would theoretically be a way to overcome the dynamic reference issue mentioned above - This PR reverts to a more straightforward approach where we create a new SSM Parameter if one does not exist already for the external ID and does not reference the previously created secret externalID - NOTE: In order to keep the same externalID and prevent additional manual work to update the pivotRole's using this value one would have to - retain the current externalID in Secret Manager (named `dataall-externalId-{envname}`) from version <= 1.5X - Run the upgrade to v1.6.1 - Replace the newly created SSM (parameter named `/dataall/{envname}/pivotRole/externalId"`) with the original value for external ID By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent f0a932f commit f235c19

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

deploy/stacks/param_store_stack.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def __init__(
115115
)
116116

117117
def _get_external_id_value(envname, account_id, region):
118-
"""For first deployments it returns False,
119-
for existing deployments it returns the ssm parameter value generated in the first deployment
120-
for prior to V1.5.1 upgrades it returns the secret from secrets manager
118+
"""
119+
For first deployments and upgrades from <=V1.5.6 to >=v1.6 - returns False and a new ssm parameter created,
120+
For existing >=v1.6 deployments - returns the ssm parameter value generated in the first deployment
121121
"""
122122
cdk_look_up_role = 'arn:aws:iam::{}:role/cdk-hnb659fds-lookup-role-{}-{}'.format(account_id, account_id, region)
123123
base_session = boto3.Session()
@@ -130,29 +130,21 @@ def _get_external_id_value(envname, account_id, region):
130130
region_name=region,
131131
endpoint_url=f"https://sts.{region}.amazonaws.com"
132132
)
133-
response = sts.assume_role(**assume_role_dict)
134-
session = boto3.Session(
135-
aws_access_key_id=response['Credentials']['AccessKeyId'],
136-
aws_secret_access_key=response['Credentials']['SecretAccessKey'],
137-
aws_session_token=response['Credentials']['SessionToken'],
138-
)
139-
140-
secret_id = f"dataall-externalId-{envname}"
141133
parameter_path = f"/dataall/{envname}/pivotRole/externalId"
134+
142135
try:
136+
response = sts.assume_role(**assume_role_dict)
137+
session = boto3.Session(
138+
aws_access_key_id=response['Credentials']['AccessKeyId'],
139+
aws_secret_access_key=response['Credentials']['SecretAccessKey'],
140+
aws_session_token=response['Credentials']['SessionToken'],
141+
)
143142
ssm_client = session.client('ssm', region_name=region)
144143
parameter_value = ssm_client.get_parameter(Name=parameter_path)['Parameter']['Value']
145144
return parameter_value
146145
except:
147-
try:
148-
secrets_client = session.client('secretsmanager', region_name=region)
149-
if secrets_client.describe_secret(SecretId=secret_id):
150-
secret_value = SecretValue.secrets_manager(secret_id).unsafe_unwrap()
151-
else:
152-
raise Exception
153-
return secret_value
154-
except:
155-
return False
146+
return False
147+
156148

157149
def _generate_external_id():
158150
allowed_chars = string.ascii_uppercase + string.ascii_lowercase + string.digits

0 commit comments

Comments
 (0)