Skip to content

Commit c06bd5c

Browse files
author
Michael Kania
authored
feat: Support ALB authentication using AWS Cognito (#102)
1 parent e85801e commit c06bd5c

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

README.md

+25-3
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,13 @@ Make sure that both private and public subnets were created in the same set of a
101101
If all provided subnets are public (no NAT gateway) then `ecs_service_assign_public_ip` should be set to `true`.
102102

103103

104-
### Secure Atlantis with ALB Built-in Authentication and Auth0
104+
### Secure Atlantis with ALB Built-in Authentication
105+
106+
#### OpenID Connect (OIDC)
105107

106108
You can use service like [Auth0](https://www.auth0.com) to secure access to Atlantis and require authentication on ALB. To enable this, you need to create Auth0 application and provide correct arguments to Atlantis module. Make sure to update application hostname, client id and client secret:
107109

108-
```
110+
```hcl
109111
alb_authenticate_oidc = {
110112
issuer = "https://youruser.eu.auth0.com/"
111113
token_endpoint = "https://youruser.eu.auth0.com/oauth/token"
@@ -119,9 +121,28 @@ alb_authenticate_oidc = {
119121

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

122-
If you are using GitHub, you may allow it to trigger webhooks without authentication on ALB:
123124

125+
#### AWS Cognito with SAML
126+
127+
The AWS Cognito service allows you to define SAML applications tied to an identity provider (e.g., GSuite). The Atlantis ALB can then be configured to require an authenticated user managed by your identity provider.
128+
129+
To configure AWS Cognito connecting to a GSuite SAML application, you can use the [gsuite-saml-cognito](https://github.com/alloy-commons/alloy-open-source/tree/master/terraform-modules/gsuite-saml-cognito#example-usage) Terraform module.
130+
131+
To enable Cognito authentication on the Atlantis ALB, specify the following arguments containing attributes from your Cognito configuration.
132+
133+
```hcl
134+
alb_authenticate_cognito = {
135+
user_pool_arn = "arn:aws:cognito-idp:us-west-2:1234567890:userpool/us-west-2_aBcDeFG"
136+
cognito_user_pool_client_id = "clientid123"
137+
cognito_user_pool_domain = "sso.your-corp.com"
138+
}
124139
```
140+
141+
#### Allow GitHub Webhooks Unauthenticated Access
142+
143+
If you are using one of the authentication methods above along with managed GitHub (not self-hosted enterprise version), you'll need to allow unauthenticated access to GitHub's Webhook static IPs:
144+
145+
```hcl
125146
allow_unauthenticated_access = true
126147
allow_github_webhooks = true
127148
```
@@ -156,6 +177,7 @@ No requirements.
156177
| Name | Description | Type | Default | Required |
157178
|------|-------------|------|---------|:--------:|
158179
| acm\_certificate\_domain\_name | Route53 domain name to use for ACM certificate. Route53 zone for this domain should be created in advance. Specify if it is different from value in `route53_zone_name` | `string` | `""` | no |
180+
| alb\_authenticate\_cognito | Map of AWS Cognito authentication parameters to protect ALB (eg, using SAML). See https://www.terraform.io/docs/providers/aws/r/lb_listener.html#authenticate-cognito-action | `any` | `{}` | no |
159181
| alb\_authenticate\_oidc | Map of Authenticate OIDC parameters to protect ALB (eg, using Auth0). See https://www.terraform.io/docs/providers/aws/r/lb_listener.html#authenticate-oidc-action | `any` | `{}` | no |
160182
| alb\_ingress\_cidr\_blocks | List of IPv4 CIDR ranges to use on all ingress rules of the ALB. | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
161183
| alb\_log\_bucket\_name | S3 bucket (externally created) for storing load balancer access logs. Required if alb\_logging\_enabled is true. | `string` | `""` | no |

main.tf

+11-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ locals {
2323

2424
secret_webhook_key = local.has_secrets ? var.atlantis_gitlab_user_token != "" ? "ATLANTIS_GITLAB_WEBHOOK_SECRET" : var.atlantis_github_user_token != "" ? "ATLANTIS_GH_WEBHOOK_SECRET" : "ATLANTIS_BITBUCKET_WEBHOOK_SECRET" : "unknown_secret_webhook_key"
2525

26+
# determine if the alb has authentication enabled, otherwise forward the traffic unauthenticated
27+
alb_authenication_method = length(keys(var.alb_authenticate_oidc)) > 0 ? "authenticate-oidc" : length(keys(var.alb_authenticate_cognito)) > 0 ? "authenticate-cognito" : "forward"
28+
2629
# Container definitions
2730
container_definitions = var.custom_container_definitions == "" ? var.atlantis_bitbucket_user_token != "" ? module.container_definition_bitbucket.json : module.container_definition_github_gitlab.json : var.custom_container_definitions
2831

@@ -178,7 +181,7 @@ module "vpc" {
178181
###################
179182
module "alb" {
180183
source = "terraform-aws-modules/alb/aws"
181-
version = "v5.5.0"
184+
version = "v5.6.0"
182185

183186
name = var.name
184187
internal = var.internal
@@ -195,12 +198,13 @@ module "alb" {
195198

196199
https_listeners = [
197200
{
198-
target_group_index = 0
199-
port = 443
200-
protocol = "HTTPS"
201-
certificate_arn = var.certificate_arn == "" ? module.acm.this_acm_certificate_arn : var.certificate_arn
202-
action_type = length(keys(var.alb_authenticate_oidc)) > 0 ? "authenticate-oidc" : "forward"
203-
authenticate_oidc = var.alb_authenticate_oidc
201+
target_group_index = 0
202+
port = 443
203+
protocol = "HTTPS"
204+
certificate_arn = var.certificate_arn == "" ? module.acm.this_acm_certificate_arn : var.certificate_arn
205+
action_type = local.alb_authenication_method
206+
authenticate_oidc = var.alb_authenticate_oidc
207+
authenticate_cognito = var.alb_authenticate_cognito
204208
},
205209
]
206210

variables.tf

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

99+
variable "alb_authenticate_cognito" {
100+
description = "Map of AWS Cognito authentication parameters to protect ALB (eg, using SAML). See https://www.terraform.io/docs/providers/aws/r/lb_listener.html#authenticate-cognito-action"
101+
type = any
102+
default = {}
103+
}
104+
99105
variable "allow_unauthenticated_access" {
100106
description = "Whether to create ALB listener rule to allow unauthenticated access for certain CIDR blocks (eg. allow GitHub webhooks to bypass OIDC authentication)"
101107
type = bool

0 commit comments

Comments
 (0)