Skip to content

Commit 874fa08

Browse files
authored
feat: Allow unauthenticated access for webhooks to /events endpoint if needed (#226)
1 parent 858af77 commit 874fa08

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ allow_github_webhooks = true
245245
| [aws_iam_role_policy.ecs_task_access_secrets](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy) | resource |
246246
| [aws_iam_role_policy_attachment.ecs_task_execution](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
247247
| [aws_lb_listener_rule.unauthenticated_access_for_cidr_blocks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_listener_rule) | resource |
248+
| [aws_lb_listener_rule.unauthenticated_access_for_webhook](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_listener_rule) | resource |
248249
| [aws_route53_record.atlantis](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
249250
| [aws_ssm_parameter.atlantis_bitbucket_user_token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
250251
| [aws_ssm_parameter.atlantis_github_user_token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
@@ -279,6 +280,7 @@ allow_github_webhooks = true
279280
| <a name="input_allow_repo_config"></a> [allow\_repo\_config](#input\_allow\_repo\_config) | When true allows the use of atlantis.yaml config files within the source repos. | `string` | `"false"` | no |
280281
| <a name="input_allow_unauthenticated_access"></a> [allow\_unauthenticated\_access](#input\_allow\_unauthenticated\_access) | Whether to create ALB listener rule to allow unauthenticated access for certain CIDR blocks (eg. allow GitHub webhooks to bypass OIDC authentication) | `bool` | `false` | no |
281282
| <a name="input_allow_unauthenticated_access_priority"></a> [allow\_unauthenticated\_access\_priority](#input\_allow\_unauthenticated\_access\_priority) | ALB listener rule priority for allow unauthenticated access rule | `number` | `10` | no |
283+
| <a name="input_allow_unauthenticated_webhook_access_priority"></a> [allow\_unauthenticated\_webhook\_access\_priority](#input\_allow\_unauthenticated\_webhook\_access\_priority) | ALB listener rule priority for allow unauthenticated webhook access rule | `number` | `15` | no |
282284
| <a name="input_atlantis_allowed_repo_names"></a> [atlantis\_allowed\_repo\_names](#input\_atlantis\_allowed\_repo\_names) | Git repositories where webhook should be created | `list(string)` | `[]` | no |
283285
| <a name="input_atlantis_bitbucket_base_url"></a> [atlantis\_bitbucket\_base\_url](#input\_atlantis\_bitbucket\_base\_url) | Base URL of Bitbucket Server, use for Bitbucket on prem (Stash) | `string` | `""` | no |
284286
| <a name="input_atlantis_bitbucket_user"></a> [atlantis\_bitbucket\_user](#input\_atlantis\_bitbucket\_user) | Bitbucket username that is running the Atlantis command | `string` | `""` | no |

main.tf

+19
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,25 @@ resource "aws_lb_listener_rule" "unauthenticated_access_for_cidr_blocks" {
271271
}
272272
}
273273

274+
# Forward action for certain URL paths to bypass authentication (eg. GitHub webhooks)
275+
resource "aws_lb_listener_rule" "unauthenticated_access_for_webhook" {
276+
count = var.allow_unauthenticated_access && var.allow_github_webhooks ? 1 : 0
277+
278+
listener_arn = module.alb.https_listener_arns[0]
279+
priority = var.allow_unauthenticated_webhook_access_priority
280+
281+
action {
282+
type = "forward"
283+
target_group_arn = module.alb.target_group_arns[0]
284+
}
285+
286+
condition {
287+
path_pattern {
288+
values = ["/events"]
289+
}
290+
}
291+
}
292+
274293
################################################################################
275294
# Security groups
276295
################################################################################

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ variable "allow_unauthenticated_access_priority" {
144144
default = 10
145145
}
146146

147+
variable "allow_unauthenticated_webhook_access_priority" {
148+
description = "ALB listener rule priority for allow unauthenticated webhook access rule"
149+
type = number
150+
default = 15
151+
}
152+
147153
variable "allow_github_webhooks" {
148154
description = "Whether to allow access for GitHub webhooks"
149155
type = bool

0 commit comments

Comments
 (0)