Skip to content

Commit 057f945

Browse files
authored
feat: Added support for unauthenticated access (eg, Github webhook) (#123)
1 parent 37f3a4a commit 057f945

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ alb_authenticate_oidc = {
119119

120120
Read more in [this post](https://medium.com/@sandrinodm/securing-your-applications-with-aws-alb-built-in-authentication-and-auth0-310ad84c8595).
121121

122+
If you are using GitHub, you may allow it to trigger webhooks without authentication on ALB:
123+
124+
```
125+
allow_unauthenticated_access = true
126+
allow_github_webhooks = true
127+
```
128+
122129
## Notes
123130

124131
1. AWS Route53 zone is not created by this module, so zone specified as a value in `route53_zone_name` should be created before using this module. Check documentation for [aws_route53_zone](https://www.terraform.io/docs/providers/aws/r/route53_zone.html).
@@ -154,7 +161,10 @@ No requirements.
154161
| alb\_log\_bucket\_name | S3 bucket (externally created) for storing load balancer access logs. Required if alb\_logging\_enabled is true. | `string` | `""` | no |
155162
| alb\_log\_location\_prefix | S3 prefix within the log\_bucket\_name under which logs are stored. | `string` | `""` | no |
156163
| alb\_logging\_enabled | Controls if the ALB will log requests to S3. | `bool` | `false` | no |
164+
| allow\_github\_webhooks | Whether to allow access for GitHub webhooks | `bool` | `false` | no |
157165
| allow\_repo\_config | When true allows the use of atlantis.yaml config files within the source repos. | `string` | `"false"` | no |
166+
| 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 |
167+
| allow\_unauthenticated\_access\_priority | ALB listener rule priority for allow unauthenticated access rule | `number` | `10` | no |
158168
| atlantis\_allowed\_repo\_names | Git repositories where webhook should be created | `list(string)` | `[]` | no |
159169
| atlantis\_bitbucket\_base\_url | Base URL of Bitbucket Server, use for Bitbucket on prem (Stash) | `string` | `""` | no |
160170
| atlantis\_bitbucket\_user | Bitbucket username that is running the Atlantis command | `string` | `""` | no |
@@ -189,6 +199,7 @@ No requirements.
189199
| ecs\_service\_desired\_count | The number of instances of the task definition to place and keep running | `number` | `1` | no |
190200
| ecs\_task\_cpu | The number of cpu units used by the task | `number` | `256` | no |
191201
| ecs\_task\_memory | The amount (in MiB) of memory used by the task | `number` | `512` | no |
202+
| github\_webhooks\_cidr\_blocks | List of CIDR blocks used by GitHub webhooks | `list(string)` | <pre>[<br> "140.82.112.0/20",<br> "185.199.108.0/22",<br> "192.30.252.0/22"<br>]</pre> | no |
192203
| internal | Whether the load balancer is internal or external | `bool` | `false` | no |
193204
| name | Name to use on all resources created (VPC, ALB, etc) | `string` | `"atlantis"` | no |
194205
| policies\_arn | A list of the ARN of the policies you want to apply | `list(string)` | <pre>[<br> "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"<br>]</pre> | no |
@@ -203,6 +214,7 @@ No requirements.
203214
| tags | A map of tags to use on all resources | `map(string)` | `{}` | no |
204215
| vpc\_id | ID of an existing VPC where resources will be created | `string` | `""` | no |
205216
| webhook\_ssm\_parameter\_name | Name of SSM parameter to keep webhook secret | `string` | `"/atlantis/webhook/secret"` | no |
217+
| whitelist\_unauthenticated\_cidr\_blocks | List of allowed CIDR blocks to bypass authentication | `list(string)` | `[]` | no |
206218

207219
## Outputs
208220

main.tf

+19
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,25 @@ module "alb" {
230230
tags = local.tags
231231
}
232232

233+
# Forward action for certain CIDR blocks to bypass authentication (eg. GitHub webhooks)
234+
resource "aws_lb_listener_rule" "unauthenticated_access_for_cidr_blocks" {
235+
count = var.allow_unauthenticated_access ? 1 : 0
236+
237+
listener_arn = module.alb.https_listener_arns[0]
238+
priority = var.allow_unauthenticated_access_priority
239+
240+
action {
241+
type = "forward"
242+
target_group_arn = module.alb.target_group_arns[0]
243+
}
244+
245+
condition {
246+
source_ip {
247+
values = sort(compact(concat(var.allow_github_webhooks ? var.github_webhooks_cidr_blocks : [], var.whitelist_unauthenticated_cidr_blocks)))
248+
}
249+
}
250+
}
251+
233252
###################
234253
# Security groups
235254
###################

variables.tf

+30
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,36 @@ variable "alb_authenticate_oidc" {
9696
default = {}
9797
}
9898

99+
variable "allow_unauthenticated_access" {
100+
description = "Whether to create ALB listener rule to allow unauthenticated access for certain CIDR blocks (eg. allow GitHub webhooks to bypass OIDC authentication)"
101+
type = bool
102+
default = false
103+
}
104+
105+
variable "allow_unauthenticated_access_priority" {
106+
description = "ALB listener rule priority for allow unauthenticated access rule"
107+
type = number
108+
default = 10
109+
}
110+
111+
variable "allow_github_webhooks" {
112+
description = "Whether to allow access for GitHub webhooks"
113+
type = bool
114+
default = false
115+
}
116+
117+
variable "github_webhooks_cidr_blocks" {
118+
description = "List of CIDR blocks used by GitHub webhooks" # This is hardcoded to avoid dependency on github provider. Source: https://api.github.com/meta
119+
type = list(string)
120+
default = ["140.82.112.0/20", "185.199.108.0/22", "192.30.252.0/22"]
121+
}
122+
123+
variable "whitelist_unauthenticated_cidr_blocks" {
124+
description = "List of allowed CIDR blocks to bypass authentication"
125+
type = list(string)
126+
default = []
127+
}
128+
99129
# ACM
100130
variable "certificate_arn" {
101131
description = "ARN of certificate issued by AWS ACM. If empty, a new ACM certificate will be created and validated using Route53 DNS"

0 commit comments

Comments
 (0)