Skip to content

Commit 1041336

Browse files
committed
adjust permissions for lambda
1 parent 55ccf5d commit 1041336

File tree

6 files changed

+22
-17
lines changed

6 files changed

+22
-17
lines changed
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
declare namespace NodeJS {
2+
export interface ProcessEnv {
3+
ENVIRONMENT: string;
4+
EVENT_BUS_NAME: string;
5+
PARAMETER_GITHUB_APP_WEBHOOK_SECRET: string;
6+
PARAMETER_RUNNER_MATCHER_CONFIG_PATH: string;
7+
REPOSITORY_ALLOW_LIST: string;
8+
RUNNER_LABELS: string;
9+
ALLOWED_EVENTS: string;
10+
SQS_WORKFLOW_JOB_QUEUE: string;
11+
}
12+
}

modules/webhook/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
> This module is treated as internal module, breaking changes will not trigger a major release bump.
44
5-
This module creates an API gateway endpoint and lambda function to handle GitHub App webhook events.
5+
Th module can be deployed in two modes. Direct messages, are delivered directly to the runner queues. EventBridge messages are delivered to an EventBridge bus and then dispatched to the runner queues.
66

77
## Lambda Function
88

9-
The Lambda function is written in [TypeScript](https://www.typescriptlang.org/) and requires Node 12.x and yarn. Sources are located in [./lambdas/webhook].
9+
The Lambda function is written in [TypeScript](https://www.typescriptlang.org/) and requires Node and yarn. Sources are located in [./lambdas/webhook]. Check see `lambda.ts` for the different handler functions available.
1010

1111
### Install
1212

modules/webhook/direct/webhook.tf

+1-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ resource "aws_iam_role_policy" "webhook_ssm" {
137137
role = aws_iam_role.webhook_lambda.name
138138

139139
policy = templatefile("${path.module}/../policies/lambda-ssm.json", {
140-
github_app_webhook_secret_arn = var.config.github_app_parameters.webhook_secret.arn,
141-
parameter_runner_matcher_config_arn = var.config.ssm_parameter_runner_matcher_config.arn
140+
resource_arns = jsonencode([var.config.github_app_parameters.webhook_secret.arn, var.config.ssm_parameter_runner_matcher_config.arn])
142141
})
143142
}
144143

modules/webhook/eventbridge/dispatcher.tf

+5-7
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ resource "aws_lambda_function" "dispatcher" {
4343
POWERTOOLS_TRACE_ENABLED = var.config.tracing_config.mode != null ? true : false
4444
POWERTOOLS_TRACER_CAPTURE_HTTPS_REQUESTS = var.config.tracing_config.capture_http_requests
4545
POWERTOOLS_TRACER_CAPTURE_ERROR = var.config.tracing_config.capture_error
46-
PARAMETER_GITHUB_APP_WEBHOOK_SECRET = var.config.github_app_parameters.webhook_secret.name
47-
REPOSITORY_ALLOW_LIST = jsonencode(var.config.repository_white_list)
48-
SQS_WORKFLOW_JOB_QUEUE = try(var.config.sqs_workflow_job_queue.id, null)
49-
PARAMETER_GITHUB_APP_WEBHOOK_SECRET = var.config.github_app_parameters.webhook_secret.name
50-
PARAMETER_RUNNER_MATCHER_CONFIG_PATH = var.config.ssm_parameter_runner_matcher_config.name
46+
# Parameters required for lambda configuration
47+
PARAMETER_RUNNER_MATCHER_CONFIG_PATH = var.config.ssm_parameter_runner_matcher_config.name
48+
REPOSITORY_ALLOW_LIST = jsonencode(var.config.repository_white_list)
49+
SQS_WORKFLOW_JOB_QUEUE = try(var.config.sqs_workflow_job_queue.id, null)
5150
} : k => v if v != null
5251
}
5352
}
@@ -126,8 +125,7 @@ resource "aws_iam_role_policy" "dispatcher_ssm" {
126125
role = aws_iam_role.dispatcher_lambda.name
127126

128127
policy = templatefile("${path.module}/../policies/lambda-ssm.json", {
129-
github_app_webhook_secret_arn = var.config.github_app_parameters.webhook_secret.arn,
130-
parameter_runner_matcher_config_arn = var.config.ssm_parameter_runner_matcher_config.arn
128+
resource_arns = jsonencode([var.config.ssm_parameter_runner_matcher_config.arn])
131129
})
132130
}
133131

modules/webhook/eventbridge/webhook.tf

+1-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ resource "aws_iam_role_policy" "webhook_ssm" {
121121
role = aws_iam_role.webhook_lambda.name
122122

123123
policy = templatefile("${path.module}/../policies/lambda-ssm.json", {
124-
github_app_webhook_secret_arn = var.config.github_app_parameters.webhook_secret.arn,
125-
parameter_runner_matcher_config_arn = var.config.ssm_parameter_runner_matcher_config.arn
124+
resource_arns = jsonencode([var.config.github_app_parameters.webhook_secret.arn])
126125
})
127126
}
128127

modules/webhook/policies/lambda-ssm.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
{
55
"Effect": "Allow",
66
"Action": ["ssm:GetParameter"],
7-
"Resource": [
8-
"${github_app_webhook_secret_arn}",
9-
"${parameter_runner_matcher_config_arn}"
10-
]
7+
"Resource": ${resource_arns}
118
}
129
]
1310
}

0 commit comments

Comments
 (0)