Skip to content

Commit 60bd929

Browse files
authored
fix: updated readme and url maps describing how to redirect http to https (#184)
1 parent c7a6685 commit 60bd929

File tree

3 files changed

+117
-12
lines changed

3 files changed

+117
-12
lines changed

.github/copilot-instructions.md

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,24 @@ This is the Interledger Foundation website, a Drupal 10 CMS deployed on Google C
2525

2626
### Load Balancer Routing
2727

28-
The URL map (`interledger-org`) routes traffic:
28+
**HTTPS Traffic (Port 443):**
29+
30+
The URL map (`interledger-org`) routes HTTPS traffic:
2931
1. `interledger.org``drupal-sites-backend` (VM) for all paths except:
3032
- `/developers``nginx-rewrite-backend` (Cloud Run)
3133
2. `staging.interledger.org``drupal-sites-backend` (VM) for all paths except:
3234
- `/developers``nginx-rewrite-backend` (Cloud Run)
3335
3. `uwa.interledger.org``umami-analytics-backend` (Cloud Run)
3436

37+
**HTTP Traffic (Port 80):**
38+
39+
The HTTP redirect URL map (`interledger-org-http-redirect`) handles all HTTP traffic:
40+
- All HTTP requests receive a 301 permanent redirect to HTTPS
41+
- Preserves the original hostname and path
42+
- Configuration stored in `ci/deploy/http-redirect-urlmap.yaml`
43+
44+
**Key Point**: We maintain TWO separate URL maps - one for HTTPS routing (the main `urlmap.yaml`) and one for HTTP→HTTPS redirect (`http-redirect-urlmap.yaml`). When adding new domains, update BOTH files.
45+
3546
### Database Credentials
3647

3748
**Never hardcode database credentials in settings.php!**
@@ -60,6 +71,8 @@ $databases['default']['default'] = [
6071
- **`ci/Makefile`**: Commands for deploy, backup, restore operations
6172
- **`ci/backupmanager/`**: Go application for backup/restore with Cloud SQL
6273
- **`ci/deploy/`**: Environment-specific configs and load balancer configuration
74+
- **`urlmap.yaml`**: HTTPS URL map configuration (port 443 routing)
75+
- **`http-redirect-urlmap.yaml`**: HTTP redirect URL map (port 80 → HTTPS redirect)
6376
- **`web/`**: Drupal docroot
6477
- **`local/`**: Local development with Docker Compose
6578
- **`.github/workflows/`**: GitHub Actions workflows
@@ -183,25 +196,42 @@ sudo chmod -R 775 /var/www/production/web/sites/default/files/
183196

184197
## URL Map Management
185198

186-
The URL map configuration is stored at `ci/deploy/urlmap.yaml` with read-only fields removed.
199+
We maintain two URL map configurations:
187200

188-
**To modify routing:**
201+
**HTTPS URL Map** (`interledger-org`):
202+
- Stored at `ci/deploy/urlmap.yaml` with read-only fields removed
203+
- Routes HTTPS traffic to appropriate backends
204+
205+
**HTTP Redirect URL Map** (`interledger-org-http-redirect`):
206+
- Stored at `ci/deploy/http-redirect-urlmap.yaml`
207+
- Redirects all HTTP traffic to HTTPS with 301 permanent redirects
208+
209+
**To modify HTTPS routing:**
189210
1. Edit `ci/deploy/urlmap.yaml`
190211
2. Import: `gcloud compute url-maps import interledger-org --source=ci/deploy/urlmap.yaml --quiet`
191212
3. Verify: `gcloud compute url-maps describe interledger-org`
192213

193-
**To update local file:**
214+
**To modify HTTP redirect (when adding new domains):**
215+
1. Edit `ci/deploy/http-redirect-urlmap.yaml`
216+
2. Import: `gcloud compute url-maps import interledger-org-http-redirect --source=ci/deploy/http-redirect-urlmap.yaml --quiet`
217+
3. Verify: `gcloud compute url-maps describe interledger-org-http-redirect`
218+
4. Test: `curl -I http://newdomain.com`
219+
220+
**To update local files:**
194221
```bash
195222
gcloud compute url-maps export interledger-org --destination=ci/deploy/urlmap.yaml
223+
gcloud compute url-maps export interledger-org-http-redirect --destination=ci/deploy/http-redirect-urlmap.yaml
196224
# Remove read-only fields: creationTimestamp, fingerprint, id, kind, selfLink
197225
```
198226

199227
## Common Pitfalls
200228

201-
1. **Certificate Map Entries**: When adding a new domain, remember to create both:
202-
- The certificate: `gcloud certificate-manager certificates create ...`
203-
- The certificate map entry: `gcloud certificate-manager maps entries create ...`
204-
- Map entries take 5-10 minutes to become ACTIVE
229+
1. **HTTP and HTTPS for New Domains**: When adding a new domain, configure BOTH protocols:
230+
- **HTTPS**: Create certificate, certificate map entry, and add to `ci/deploy/urlmap.yaml`
231+
- **HTTP**: Add domain to `ci/deploy/http-redirect-urlmap.yaml` and import the updated config
232+
- Forgetting HTTP redirect means `http://` requests will fail instead of redirecting to `https://`
233+
- Both URL maps share the same IP address (34.111.215.251) but use different forwarding rules and target proxies
234+
- Certificate map entries take 5-10 minutes to become ACTIVE
205235

206236
2. **Database Name in SQL Dumps**: Cloud SQL exports include the source database name. The backupmanager automatically replaces this during restore, but if you manually restore, you must replace all occurrences of the source database name with the target database name.
207237

ci/deploy/README.md

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,35 @@ Client (Browser)
102102
└─ umami-analytics-backend → Cloud Run NEG
103103
```
104104

105+
### HTTP to HTTPS Redirect
106+
107+
All HTTP (port 80) traffic is automatically redirected to HTTPS (port 443) using a separate forwarding rule and URL map:
108+
109+
```
110+
Client (Browser) - HTTP Request
111+
112+
[1] HTTP Forwarding Rule (34.111.215.251:80)
113+
↓ "Incoming HTTP traffic"
114+
115+
[2] Target HTTP Proxy (interledger-org-http-proxy)
116+
117+
[3] HTTP Redirect URL Map (interledger-org-http-redirect)
118+
↓ "301 Permanent Redirect to HTTPS"
119+
120+
Client follows redirect to HTTPS
121+
```
122+
123+
**Components:**
124+
- **Forwarding Rule**: `interledger-org-http` (port 80, same IP as HTTPS)
125+
- **Target HTTP Proxy**: `interledger-org-http-proxy`
126+
- **URL Map**: `interledger-org-http-redirect` (configuration stored in `ci/deploy/http-redirect-urlmap.yaml`)
127+
- **Reserved IP**: `interledger-org-ip` (34.111.215.251)
128+
129+
**Configuration File**: `ci/deploy/http-redirect-urlmap.yaml` defines the redirect behavior:
130+
- All HTTP requests receive a 301 permanent redirect to HTTPS
131+
- Host rules ensure redirects work for all domains (production, staging, www)
132+
- Preserves the original path and query parameters
133+
105134
**Key architectural decisions:**
106135

107136
- **Single Backend for Both Environments**: Both production and staging use `drupal-sites-backend` because a VM instance can only belong to one load-balanced instance group
@@ -198,9 +227,17 @@ gcloud compute operations list \
198227

199228
### Update URL Map
200229

201-
The URL Map defines all routing rules. The current configuration is stored in `ci/deploy/urlmap.yaml`.
230+
The URL Map defines all routing rules. We maintain two URL maps:
231+
232+
1. **HTTPS URL Map** (`interledger-org`): Routes HTTPS traffic to backends
233+
- Configuration: `ci/deploy/urlmap.yaml`
234+
- Handles path-based routing to different backends
202235

203-
#### Make Changes to URL Map
236+
2. **HTTP Redirect URL Map** (`interledger-org-http-redirect`): Redirects HTTP to HTTPS
237+
- Configuration: `ci/deploy/http-redirect-urlmap.yaml`
238+
- Simple redirect for all HTTP traffic
239+
240+
#### Make Changes to HTTPS URL Map
204241

205242
1. **Edit the local file**: Modify `ci/deploy/urlmap.yaml` as needed
206243
- Add/remove hostRules for new domains
@@ -223,10 +260,26 @@ The URL Map defines all routing rules. The current configuration is stored in `c
223260
# Clean up read-only fields manually (creationTimestamp, fingerprint, id, kind, selfLink)
224261
```
225262

263+
#### Make Changes to HTTP Redirect URL Map
264+
265+
1. **Edit the local file**: Modify `ci/deploy/http-redirect-urlmap.yaml` as needed
266+
- Add/remove hostRules for new domains that need HTTP→HTTPS redirect
267+
268+
2. **Import the updated configuration**:
269+
```bash
270+
gcloud compute url-maps import interledger-org-http-redirect --source=ci/deploy/http-redirect-urlmap.yaml --quiet
271+
```
272+
273+
3. **Verify changes**:
274+
```bash
275+
gcloud compute url-maps describe interledger-org-http-redirect
276+
```
277+
226278
**Important Notes**:
227279
- Route rules are evaluated by priority (lower numbers first)
228-
- The local `urlmap.yaml` file has read-only fields removed for easy editing
280+
- The local `urlmap.yaml` files have read-only fields removed for easy editing
229281
- Always test changes before applying to production traffic
282+
- **When adding new domains, update BOTH URL maps** - one for HTTPS routing, one for HTTP redirect
230283

231284
### Add a New Cloud Run Service
232285

@@ -454,10 +507,17 @@ Current backend services in use:
454507

455508
## Files in This Directory
456509

457-
- **`urlmap.yaml`**: Current URL map configuration
510+
- **`urlmap.yaml`**: HTTPS URL map configuration (port 443 routing)
511+
- Routes HTTPS traffic to appropriate backends
458512
- Export latest: `gcloud compute url-maps export interledger-org --destination=ci/deploy/urlmap.yaml`
459513
- Import changes: `gcloud compute url-maps import interledger-org --source=ci/deploy/urlmap.yaml --quiet`
460514
- Read-only fields removed (creationTimestamp, fingerprint, id, kind, selfLink)
515+
516+
- **`http-redirect-urlmap.yaml`**: HTTP redirect URL map configuration (port 80 → HTTPS redirect)
517+
- Redirects all HTTP traffic to HTTPS with 301 permanent redirects
518+
- Export latest: `gcloud compute url-maps export interledger-org-http-redirect --destination=ci/deploy/http-redirect-urlmap.yaml`
519+
- Import changes: `gcloud compute url-maps import interledger-org-http-redirect --source=ci/deploy/http-redirect-urlmap.yaml --quiet`
520+
- **Remember**: When adding new domains, update BOTH this file and `urlmap.yaml`
461521

462522
- **`staging/`**: Staging environment configuration files
463523
- `settings.php`, `htaccess`, `robots.txt`, `cleanup.sh`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: interledger-org-http-redirect
2+
defaultUrlRedirect:
3+
httpsRedirect: true
4+
redirectResponseCode: MOVED_PERMANENTLY_DEFAULT
5+
hostRules:
6+
- hosts:
7+
- interledger.org
8+
- www.interledger.org
9+
- staging.interledger.org
10+
pathMatcher: redirect-matcher
11+
pathMatchers:
12+
- name: redirect-matcher
13+
defaultUrlRedirect:
14+
httpsRedirect: true
15+
redirectResponseCode: MOVED_PERMANENTLY_DEFAULT

0 commit comments

Comments
 (0)