Skip to content

Commit 122d341

Browse files
committed
adjust regex logic to catch config errors in AWS proxy
1 parent 4cb621c commit 122d341

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

aws-replicator/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enable: $(wildcard ./build/dist/localstack_extension_aws_replicator-*.tar.gz) #
4949
localstack extensions -v install file://$?
5050

5151
publish: clean-dist venv dist
52-
$(VENV_RUN); cd build; pip install --upgrade twine; twine upload dist/*
52+
$(VENV_RUN); pip install --upgrade twine; twine upload dist/*
5353

5454
clean-dist: clean
5555
rm -rf dist/

aws-replicator/aws_replicator/server/aws_request_forwarder.py

+32-27
Original file line numberDiff line numberDiff line change
@@ -98,33 +98,38 @@ def select_proxy(self, context: RequestContext) -> Optional[ProxyInstance]:
9898
def _request_matches_resource(
9999
self, context: RequestContext, resource_name_pattern: str
100100
) -> bool:
101-
service_name = self._get_canonical_service_name(context.service.service_name)
102-
if service_name == "s3":
103-
bucket_name = context.service_request.get("Bucket") or ""
104-
s3_bucket_arn = arns.s3_bucket_arn(bucket_name)
105-
return bool(re.match(resource_name_pattern, s3_bucket_arn))
106-
if service_name == "sqs":
107-
queue_name = context.service_request.get("QueueName") or ""
108-
queue_url = context.service_request.get("QueueUrl") or ""
109-
queue_name = queue_name or queue_url.split("/")[-1]
110-
candidates = (
111-
queue_name,
112-
queue_url,
113-
sqs_queue_arn(
114-
queue_name, account_id=context.account_id, region_name=context.region
115-
),
116-
)
117-
for candidate in candidates:
118-
if re.match(resource_name_pattern, candidate):
119-
return True
120-
return False
121-
if service_name == "secretsmanager":
122-
secret_id = context.service_request.get("SecretId") or ""
123-
secret_arn = secretsmanager_secret_arn(
124-
secret_id, account_id=context.account_id, region_name=context.region
125-
)
126-
return bool(re.match(resource_name_pattern, secret_arn))
127-
# TODO: add more resource patterns
101+
try:
102+
service_name = self._get_canonical_service_name(context.service.service_name)
103+
if service_name == "s3":
104+
bucket_name = context.service_request.get("Bucket") or ""
105+
s3_bucket_arn = arns.s3_bucket_arn(bucket_name)
106+
return bool(re.match(resource_name_pattern, s3_bucket_arn))
107+
if service_name == "sqs":
108+
queue_name = context.service_request.get("QueueName") or ""
109+
queue_url = context.service_request.get("QueueUrl") or ""
110+
queue_name = queue_name or queue_url.split("/")[-1]
111+
candidates = (
112+
queue_name,
113+
queue_url,
114+
sqs_queue_arn(
115+
queue_name, account_id=context.account_id, region_name=context.region
116+
),
117+
)
118+
for candidate in candidates:
119+
if re.match(resource_name_pattern, candidate):
120+
return True
121+
return False
122+
if service_name == "secretsmanager":
123+
secret_id = context.service_request.get("SecretId") or ""
124+
secret_arn = secretsmanager_secret_arn(
125+
secret_id, account_id=context.account_id, region_name=context.region
126+
)
127+
return bool(re.match(resource_name_pattern, secret_arn))
128+
# TODO: add more resource patterns
129+
except re.error as e:
130+
raise Exception(
131+
"Error evaluating regular expression - please verify proxy configuration"
132+
) from e
128133
return True
129134

130135
def forward_request(self, context: RequestContext, proxy: ProxyInstance) -> requests.Response:

0 commit comments

Comments
 (0)