crossRegionReferences: permissions issues when more than 2 regions involved
Describe the bug
For AWS folks, on support Case ID 12371550421 as well.
I am deploying a cdk app, that will have stacks in three regions.. us-east-1, ap-southeast-1 and ap-southeast-2.
Please refer to lines 19, 33, 43, 70, 97 where crossRegionReferneces is configured.
The code synths ok. I was trying to deploy a single stack.
cdk deploy --profile swamp2 CloudwanCore --no-rollback
This deployment fails. with the following error.
3:33:40 PM | CREATE_FAILED | Custom::CrossRegionExportWriter | ExportsWriterapsou...D/Resource/Default
Received response status [FAILED] from custom resource. Message returned: AccessDeniedException: User: arn:aws:sts::8xxxxxxxxxxxx2:assumed-role/CloudwanCore-CustomCrossRegionExportWriterCustomRe-1XQZYS73KR20U/CloudwanCore-CustomCrossRegionExportWriterCustom
Re-I8K1IChjqYs9 is not authorized to perform: ssm:ListTagsForResource on resource: arn:aws:ssm:ap-southeast-1:8xxxxxxxxxxxx2:parameter/cdk/exports/regionThisEgress/CloudwanCoreuseast1FnGetAttCoreNetworkPolicyTableC5E1C9A8ArnA512AC64 because no identity-base
d policy allows the ssm:ListTagsForResource action
at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:52:27)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:686:14)
at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.
On investigation, ( which required me to look at the Cloudformation ), ( attached ) I have determined that this creates two Custom REsources.. at line 1711, ExportsWriterapsoutheast2235C849A8E92266D and at line 1810, ExportsWriterapsoutheast1E04AEC0D56A4ECF1.
Both of the custom resources point to the same lambda. ( line 1783 ) which has a role ( line 1738 ) which has inline policy that only allows acess to
"Resource": "arn:aws:ssm:ap-southeast-2:847997321372:parameter/cdk/exports/*",
Since this stack needs access to both southeast-1 and southeast-2 this is never going to work..
This appears to be a bug.
When i follwo through, to the Lambdas that back these custom resources, and there respective roles, I discover that both of the lambdas point
Expected Behavior
the lambdas role behind the Custom Resource should have permissiosn to reach all the regions as required..
Current Behavior
The lambdas role has been restricted to a single role.
Reproduction Steps
Run the app that was attached below.
Possible Solution
Unsure at this point. Looking to see if i can find the root cause in the source.
Additional Information/Context
No response
CDK CLI Version
2.69.0
Framework Version
No response
Node.js Version
16.6.1
OS
AL2
Language
Typescript
Language Version
No response
Other information
I believe this line needs to be made region aware: https://github.com/aws/aws-cdk/blob/b6f7f390e663cc69b618c43af52ec771ddfc2f41/packages/@aws-cdk/core/lib/custom-resource-provider/cross-region-export-providers/export-writer-provider.ts#L62
can we get a sense of if this can be fixed, and when... Need to be able to determine if I need to take a different approach or not.
I think changing how policy statements are added to the writer (like this) will work, but I'm not sure how to actually reproduce the issue. The attached code has references to code that isn't provided.
related to https://github.com/aws/aws-cdk/issues/24464
I tried to cook up a simple self-contained example to reproduce the issue. However, the code works without errors. So either I'm missing something, or this issue has been fixed in aws-cdk already.
To proof or disproof the second option, I tried downgrading my cdk-libs (first to 2.70.0, secondly to 2.64.0) but still wasn't able to reproduce this. Which hints to the first option, that I'm missing some crucial element.
The idea, as far as I know, was that this breaks if there are cross-region references towards two different regions in the same stack, which is what I'm doing here.
Here's my code, maybe someone else could tweak it to reproduce the issue:
#!/usr/bin/env python3
import os
from typing import List
import aws_cdk as cdk
from aws_cdk import Stack
from aws_cdk import aws_ec2 as ec2
from aws_cdk import aws_elasticloadbalancingv2 as elb
from aws_cdk import aws_globalaccelerator as globalaccelerator
from aws_cdk import aws_globalaccelerator_endpoints as globalaccelerator_endpoints
from constructs import Construct
class Nlb(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
self.env = kwargs["env"]
self.vpc = ec2.Vpc(self, "vpc")
self.nlb = elb.NetworkLoadBalancer(
self, "nlb", vpc=self.vpc, internet_facing=True
)
class Ga(Stack):
def __init__(
self, scope: Construct, construct_id: str, env, nlbs: List[Nlb]
) -> None:
super().__init__(scope, construct_id, env=env, cross_region_references=True)
self.accelerator = globalaccelerator.Accelerator(
self,
id=f"ga",
accelerator_name="ga",
enabled=True,
)
self.listener = self.accelerator.add_listener(
"listener",
protocol=globalaccelerator.ConnectionProtocol.TCP,
port_ranges=[globalaccelerator.PortRange(from_port=80)],
)
for nlb in nlbs:
epgroup = globalaccelerator.EndpointGroup(
self,
f"ep_group_{nlb.env.region}",
listener=self.listener,
region=nlb.env.region,
traffic_dial_percentage=100,
)
epgroup.add_endpoint(
globalaccelerator_endpoints.ApplicationLoadBalancerEndpoint(
load_balancer=nlb.nlb
)
)
app = cdk.App()
nlbEuw2 = Nlb(
app, "Euw2", env=cdk.Environment(account="030614601540", region="eu-west-2")
)
nlbEuw3 = Nlb(
app, "Euw3", env=cdk.Environment(account="030614601540", region="eu-west-3")
)
ga = Ga(
app,
"Ga",
env=cdk.Environment(account="030614601540", region="us-west-2"),
nlbs=[nlbEuw2, nlbEuw3],
)
app.synth()
I'm going to close this so we can track this issue through #24464
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.