Skip to content

Commit 0465794

Browse files
Give API ECS role API Gateway permissions (#6416)
## Summary Gives API ECS service permissions to hit API Gateway internal API ## Changes proposed - New IAM policy attached to API ECS role ## Context for reviewers This PR provides the API ECS service the required permissions to hit the [internal API for API gateway](https://docs.aws.amazon.com/apigateway/latest/api/API_Operations.html) ## Validation steps This will be tested manually once the API code side PR is merged. We'll use an inline policy so it won't require this to be merged for it to work
1 parent e25a211 commit 0465794

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

infra/modules/service/access_control.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,31 @@ data "aws_iam_policy_document" "email_access" {
138138
}
139139
}
140140

141+
data "aws_iam_policy_document" "api_gateway_access" {
142+
count = var.enable_api_gateway ? 1 : 0
143+
144+
# Only allows running the GET /apikeys request
145+
statement {
146+
sid = "AllowGetApiKeys"
147+
actions = ["apigateway:GET"]
148+
resources = [
149+
# Must be wildcarded for this to work. Someone using a dev key in prod would not work
150+
# because the dev key's usage plan doesn't allow it to access other env's gateways
151+
"arn:aws:apigateway:${data.aws_region.current.name}::/apikeys/*", # GetApiKey
152+
]
153+
}
154+
155+
# Only allows running the POST /apikeys request
156+
statement {
157+
sid = "AllowImportApiKeys"
158+
actions = ["apigateway:POST"]
159+
resources = [
160+
# Must be wildcarded for this to work. Someone using a dev key in prod would not work
161+
# because the dev key's usage plan doesn't allow it to access other env's gateways
162+
"arn:aws:apigateway:${data.aws_region.current.name}::/apikeys", # ImportApiKeys
163+
]
164+
}
165+
}
141166

142167
resource "aws_iam_role_policy" "task_executor" {
143168
name = "${var.service_name}-task-executor-role-policy"
@@ -150,6 +175,12 @@ resource "aws_iam_policy" "runtime_logs" {
150175
policy = data.aws_iam_policy_document.runtime_logs.json
151176
}
152177

178+
resource "aws_iam_policy" "api_gateway_access" {
179+
count = var.enable_api_gateway ? 1 : 0
180+
name = "${var.service_name}-api-gateway-access-role-policy"
181+
policy = data.aws_iam_policy_document.api_gateway_access[0].json
182+
}
183+
153184
resource "aws_iam_policy" "email_access" {
154185
count = length(var.pinpoint_app_id) > 0 ? 1 : 0
155186
name = "${var.service_name}-email-access-role-policy"
@@ -174,3 +205,10 @@ resource "aws_iam_role_policy_attachment" "email_access" {
174205
role = aws_iam_role.app_service.name
175206
policy_arn = aws_iam_policy.email_access[0].arn
176207
}
208+
209+
resource "aws_iam_role_policy_attachment" "api_gateway_access" {
210+
count = var.enable_api_gateway ? 1 : 0
211+
212+
role = aws_iam_role.app_service.name
213+
policy_arn = aws_iam_policy.api_gateway_access[0].arn
214+
}

0 commit comments

Comments
 (0)