v2.31.0-dev19 35467d7

aws-alb.md RawHistoryFolder

AWS Application Load Balancer (ALB) Setup

This guide covers deploying Gordon behind AWS Application Load Balancer for TLS termination.

Overview

AWS ALB is a Layer 7 load balancer that:

  • Terminates TLS connections
  • Forwards requests to your EC2 instances or ECS containers
  • Automatically scales with traffic
  • Sets X-Forwarded-For header with the client's real IP

Architecture

Client → ALB (HTTPS/443) → Gordon (HTTP/80) → Containers
              ↓
         TLS terminated
         X-Forwarded-For set

Understanding VPC CIDR

A VPC (Virtual Private Cloud) is your isolated network in AWS. Every VPC has a CIDR (Classless Inter-Domain Routing) block—the private IP range used by resources in that VPC.

ALB connects to Gordon from within your VPC, so Gordon sees the ALB's private IP, not the client's public IP. The client IP is passed via X-Forwarded-For.

To find your VPC CIDR:

  1. Go to AWS Console → VPC → Your VPCs
  2. Find the IPv4 CIDR column
  3. Common values: 10.0.0.0/16, 172.31.0.0/16

Gordon Configuration

[api.rate_limit]
enabled = true
# Trust your VPC CIDR so Gordon reads X-Forwarded-For from ALB
trusted_proxies = ["10.0.0.0/16"]  # Replace with your VPC CIDR

Multiple VPCs or Subnets

If Gordon receives traffic from multiple VPCs (e.g., via VPC peering):

[api.rate_limit]
trusted_proxies = [
    "10.0.0.0/16",   # Production VPC
    "10.1.0.0/16",   # Staging VPC
]

ALB Configuration

Target Group Settings

When creating your ALB target group:

Setting Value
Target type instance or ip
Protocol HTTP
Port 80 (or your Gordon port)
Health check path /health or /v2/

Client IP Preservation

ALB automatically sets X-Forwarded-For. No special configuration needed for HTTP targets.

For NLB (Network Load Balancer) with TCP, you may need to enable Proxy Protocol v2:

# Kubernetes annotation for AWS Load Balancer Controller
service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*"

Verifying the Setup

  1. Make a request through the ALB
  2. Check Gordon logs for the client IP:
# Should show real client IP, not ALB IP
journalctl -u gordon | grep "client_ip"

If you see the ALB's private IP (e.g., 10.0.x.x) instead of the client's public IP, check that:

  • trusted_proxies includes your VPC CIDR
  • ALB is forwarding X-Forwarded-For (default behavior)

Security Groups

Ensure your security groups allow:

Source Destination Port Purpose
0.0.0.0/0 ALB 443 HTTPS from internet
ALB SG Gordon SG 80 ALB to Gordon

Terraform Example

resource "aws_lb" "gordon" {
  name               = "gordon-alb"
  internal           = false
  load_balancer_type = "application"
  security_groups    = [aws_security_group.alb.id]
  subnets            = var.public_subnets
}

resource "aws_lb_listener" "https" {
  load_balancer_arn = aws_lb.gordon.arn
  port              = "443"
  protocol          = "HTTPS"
  ssl_policy        = "ELBSecurityPolicy-TLS13-1-2-2021-06"
  certificate_arn   = var.certificate_arn

  default_action {
    type             = "forward"
    target_group_arn = aws_lb_target_group.gordon.arn
  }
}

resource "aws_lb_target_group" "gordon" {
  name     = "gordon-tg"
  port     = 80
  protocol = "HTTP"
  vpc_id   = var.vpc_id

  health_check {
    path                = "/v2/"
    healthy_threshold   = 2
    unhealthy_threshold = 10
  }
}

Troubleshooting

All requests show the same IP

Symptom: Rate limiting doesn't work, logs show ALB IP for all requests.

Cause: trusted_proxies doesn't include ALB's IP range.

Fix: Add your VPC CIDR to trusted_proxies.

502 Bad Gateway

Symptom: ALB returns 502 errors.

Cause: Gordon health check failing or not listening.

Fix: Verify Gordon is running and health check path is correct.

source
1# AWS Application Load Balancer (ALB) Setup
2
3This guide covers deploying Gordon behind AWS Application Load Balancer for TLS termination.
4
5## Overview
6
7AWS ALB is a Layer 7 load balancer that:
8- Terminates TLS connections
9- Forwards requests to your EC2 instances or ECS containers
10- Automatically scales with traffic
11- Sets `X-Forwarded-For` header with the client's real IP
12
13## Architecture
14
15```
16Client → ALB (HTTPS/443) → Gordon (HTTP/80) → Containers
17              ↓
18         TLS terminated
19         X-Forwarded-For set
20```
21
22## Understanding VPC CIDR
23
24A **VPC** (Virtual Private Cloud) is your isolated network in AWS. Every VPC has a **CIDR** (Classless Inter-Domain Routing) block—the private IP range used by resources in that VPC.
25
26ALB connects to Gordon from within your VPC, so Gordon sees the ALB's private IP, not the client's public IP. The client IP is passed via `X-Forwarded-For`.
27
28**To find your VPC CIDR:**
29
301. Go to AWS Console → VPC → Your VPCs
312. Find the **IPv4 CIDR** column
323. Common values: `10.0.0.0/16`, `172.31.0.0/16`
33
34## Gordon Configuration
35
36```toml
37[api.rate_limit]
38enabled = true
39# Trust your VPC CIDR so Gordon reads X-Forwarded-For from ALB
40trusted_proxies = ["10.0.0.0/16"]  # Replace with your VPC CIDR
41```
42
43### Multiple VPCs or Subnets
44
45If Gordon receives traffic from multiple VPCs (e.g., via VPC peering):
46
47```toml
48[api.rate_limit]
49trusted_proxies = [
50    "10.0.0.0/16",   # Production VPC
51    "10.1.0.0/16",   # Staging VPC
52]
53```
54
55## ALB Configuration
56
57### Target Group Settings
58
59When creating your ALB target group:
60
61| Setting | Value |
62|---------|-------|
63| Target type | `instance` or `ip` |
64| Protocol | HTTP |
65| Port | 80 (or your Gordon port) |
66| Health check path | `/health` or `/v2/` |
67
68### Client IP Preservation
69
70ALB automatically sets `X-Forwarded-For`. No special configuration needed for HTTP targets.
71
72For **NLB** (Network Load Balancer) with TCP, you may need to enable Proxy Protocol v2:
73
74```yaml
75# Kubernetes annotation for AWS Load Balancer Controller
76service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*"
77```
78
79## Verifying the Setup
80
811. Make a request through the ALB
822. Check Gordon logs for the client IP:
83
84```bash
85# Should show real client IP, not ALB IP
86journalctl -u gordon | grep "client_ip"
87```
88
89If you see the ALB's private IP (e.g., `10.0.x.x`) instead of the client's public IP, check that:
90- `trusted_proxies` includes your VPC CIDR
91- ALB is forwarding `X-Forwarded-For` (default behavior)
92
93## Security Groups
94
95Ensure your security groups allow:
96
97| Source | Destination | Port | Purpose |
98|--------|-------------|------|---------|
99| `0.0.0.0/0` | ALB | 443 | HTTPS from internet |
100| ALB SG | Gordon SG | 80 | ALB to Gordon |
101
102## Terraform Example
103
104```hcl
105resource "aws_lb" "gordon" {
106  name               = "gordon-alb"
107  internal           = false
108  load_balancer_type = "application"
109  security_groups    = [aws_security_group.alb.id]
110  subnets            = var.public_subnets
111}
112
113resource "aws_lb_listener" "https" {
114  load_balancer_arn = aws_lb.gordon.arn
115  port              = "443"
116  protocol          = "HTTPS"
117  ssl_policy        = "ELBSecurityPolicy-TLS13-1-2-2021-06"
118  certificate_arn   = var.certificate_arn
119
120  default_action {
121    type             = "forward"
122    target_group_arn = aws_lb_target_group.gordon.arn
123  }
124}
125
126resource "aws_lb_target_group" "gordon" {
127  name     = "gordon-tg"
128  port     = 80
129  protocol = "HTTP"
130  vpc_id   = var.vpc_id
131
132  health_check {
133    path                = "/v2/"
134    healthy_threshold   = 2
135    unhealthy_threshold = 10
136  }
137}
138```
139
140## Troubleshooting
141
142### All requests show the same IP
143
144**Symptom:** Rate limiting doesn't work, logs show ALB IP for all requests.
145
146**Cause:** `trusted_proxies` doesn't include ALB's IP range.
147
148**Fix:** Add your VPC CIDR to `trusted_proxies`.
149
150### 502 Bad Gateway
151
152**Symptom:** ALB returns 502 errors.
153
154**Cause:** Gordon health check failing or not listening.
155
156**Fix:** Verify Gordon is running and health check path is correct.
157
158## Related
159
160- [Rate Limiting Configuration](../../docs/config/rate-limiting.md)
161- [Running Gordon in a Container](./running-in-container.md)

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close