Skip to content

Commit a38f774

Browse files
author
ravenolf
committed
add white listing of repositories
Signed-off-by: ravenolf <[email protected]>
1 parent 744d977 commit a38f774

File tree

6 files changed

+27
-0
lines changed

6 files changed

+27
-0
lines changed

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module "webhook" {
4949

5050
role_path = var.role_path
5151
role_permissions_boundary = var.role_permissions_boundary
52+
repository_white_list = var.webhook_repository_white_list
5253
}
5354

5455
module "runners" {

modules/webhook/lambdas/webhook/src/webhook/handler.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('handler', () => {
1414
let originalError: Console['error'];
1515

1616
beforeEach(() => {
17+
process.env.REPOSITORY_WHITE_LIST = '[]';
1718
process.env.GITHUB_APP_WEBHOOK_SECRET = 'TEST_SECRET';
1819
originalError = console.error;
1920
console.error = jest.fn();
@@ -71,4 +72,5 @@ describe('handler', () => {
7172
expect(resp).toBe(200);
7273
expect(sendActionRequest).not.toBeCalled();
7374
});
75+
7476
});

modules/webhook/lambdas/webhook/src/webhook/handler.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ export const handle = async (headers: IncomingHttpHeaders, payload: any): Promis
4040

4141
if (githubEvent === 'check_run') {
4242
const body = JSON.parse(payload) as CheckRunEvent;
43+
44+
const repositoryWhiteListEnv = process.env.REPOSITORY_WHITE_LIST as string || "[]";
45+
const repositoryWhiteList = JSON.parse(repositoryWhiteListEnv) as Array<string>;
46+
47+
if (repositoryWhiteList.length > 0) {
48+
const repositoryFullName = body.repository.full_name;
49+
if (!repositoryWhiteList.includes(repositoryFullName)) {
50+
console.error(`Received event from unauthorized repository ${repositoryFullName}`);
51+
return 500;
52+
}
53+
}
54+
4355
let installationId = body.installation?.id;
4456
if (installationId == null) {
4557
installationId = 0;

modules/webhook/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,8 @@ variable "webhook_lambda_s3_object_version" {
7979
default = null
8080
}
8181

82+
variable "webhook_repository_white_list" {
83+
description = "List of repositories allowed to use the github app"
84+
type = list(string)
85+
default = []
86+
}

modules/webhook/webhook.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ resource "aws_lambda_function" "webhook" {
4444
KMS_KEY_ID = var.encryption.kms_key_id
4545
GITHUB_APP_WEBHOOK_SECRET = local.github_app_webhook_secret
4646
SQS_URL_WEBHOOK = var.sqs_build_queue.id
47+
REPOSITORY_WHITE_LIST = jsonencode(var.webhook_repository_white_list)
4748
}
4849
}
4950

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,9 @@ variable "instance_types" {
360360
type = set(string)
361361
default = null
362362
}
363+
364+
variable "repository_white_list" {
365+
description = "List of repositories allowed to use the github app"
366+
type = list(string)
367+
default = []
368+
}

0 commit comments

Comments
 (0)