Skip to content

Commit 87835cb

Browse files
committed
feat: add configurations for local TLS
1 parent 1e62285 commit 87835cb

10 files changed

Lines changed: 197 additions & 1 deletion

File tree

certs/snakeoil.crt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDazCCAlOgAwIBAgIUSup+N3PQMdK7N17zAjEDsy76/h8wDQYJKoZIhvcNAQEL
3+
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
4+
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMjA4MTcxODUyNTFaFw0yMzA4
5+
MTcxODUyNTFaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw
6+
HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggEiMA0GCSqGSIb3DQEB
7+
AQUAA4IBDwAwggEKAoIBAQDOGerIzu+AfOEKhIgr//G+/DI8MKCk8NN+B/7jcar1
8+
7V376R/ZXvRikEyGOAe/pmEnjDQoI+3jL8S2hE3/1GT9mzPUXgvWBKewTeuuLRJp
9+
VXZud8BNUHrnnJ0HrZ0bzam4SRSS8cjkxX5fRnOHt9lebpvX6SdZGilYiTiyRFF+
10+
cWxBXcUNtleYVE64WX5XYQlZ5ky1VphXikQPuR94ueGCg1AYiq5hy9CjoREs3GD3
11+
gqUU5WPH4hoi7dkis+88lvaRrXNM+GL1a4q1JGqyMlng+xqfsej7r5D2MCItS81a
12+
jnYZaYLNCD1F6/QRd/VNUKgsmEPrIr+bHnLbM6JtnG+1AgMBAAGjUzBRMB0GA1Ud
13+
DgQWBBTDmrBsPUW9brDp+AIGiLajfJCoLjAfBgNVHSMEGDAWgBTDmrBsPUW9brDp
14+
+AIGiLajfJCoLjAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAs
15+
5sd9XXHr3rbgEvVyAapYlCG9H6q51d5CP4NP/kjSO5T/pKx1nAv/a1N2tjAoB0q8
16+
LQHIoPu1lYphLIukCKL1z7RanyG7KY1nKdVP4Od2fkwxXTiZsJaMRCBgFcMxLMzO
17+
fo/xTldP2pXCZGUECIkIFk/BCswHqchnbaNvzsZqSzPzTvvLhJ2MmdU6db0X4YLS
18+
NDv4LBLiraE6ovbGOO5CpN7QOEYF7mrKg8ptN66lNGyioSD1+XNVkbS2zkQUPa50
19+
f+RFcHj6IzNErKnTUARs4wQ1y0mf4GLwK/Fte/oUdyvhCrB3MrM0ovy9dYq8GuWJ
20+
Wq0Ystan3d1BHas3KJh4
21+
-----END CERTIFICATE-----

certs/snakeoil.key

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDOGerIzu+AfOEK
3+
hIgr//G+/DI8MKCk8NN+B/7jcar17V376R/ZXvRikEyGOAe/pmEnjDQoI+3jL8S2
4+
hE3/1GT9mzPUXgvWBKewTeuuLRJpVXZud8BNUHrnnJ0HrZ0bzam4SRSS8cjkxX5f
5+
RnOHt9lebpvX6SdZGilYiTiyRFF+cWxBXcUNtleYVE64WX5XYQlZ5ky1VphXikQP
6+
uR94ueGCg1AYiq5hy9CjoREs3GD3gqUU5WPH4hoi7dkis+88lvaRrXNM+GL1a4q1
7+
JGqyMlng+xqfsej7r5D2MCItS81ajnYZaYLNCD1F6/QRd/VNUKgsmEPrIr+bHnLb
8+
M6JtnG+1AgMBAAECggEACLx8gUqUSGQCvglkJElTG/9gucBt7s/uhxcbrNRypL4N
9+
D9KP8QzfWxY2yDGz0mHhGGYPB+yN9uVdd0cgb0m3hjB//+6EnevQl96VsOpkL2ba
10+
AFC/LAfPTeYLmfm4ASe0nAUtBBWPqHLeqnc4Cna2lhQmMv7FFjfPrNsUNipDMhLV
11+
N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wefFCQSK8D7P0oG
27+
K85oJaYqz32qAjQQQ4HGX39W
28+
-----END PRIVATE KEY-----

compose/2.4.6/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ services:
2121
- MAGENTO2_UPSTREAM_PORT=9000
2222
- NGINX_PORT=8000
2323
- NGINX_TLS_PORT=8443
24+
- MAGENTO_TLS_CERT=snakeoil.crt
25+
- MAGENTO_TLS_KEY=snakeoil.key
2426
ports:
2527
- "80:8000"
2628
- "443:8443"

compose/2.4.7/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ services:
2121
- MAGENTO2_UPSTREAM_PORT=9000
2222
- NGINX_PORT=8000
2323
- NGINX_TLS_PORT=8443
24+
- MAGENTO_TLS_CERT=snakeoil.crt
25+
- MAGENTO_TLS_KEY=snakeoil.key
2426
ports:
2527
- "80:8000"
2628
- "443:8443"

compose/2.4.8/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ services:
2121
- MAGENTO2_UPSTREAM_PORT=9000
2222
- NGINX_PORT=8000
2323
- NGINX_TLS_PORT=8443
24+
- MAGENTO_TLS_CERT=snakeoil.crt
25+
- MAGENTO_TLS_KEY=snakeoil.key
2426
ports:
2527
- "80:8000"
2628
- "443:8443"

compose/2.4.9/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ services:
2121
- MAGENTO2_UPSTREAM_PORT=9000
2222
- NGINX_PORT=8000
2323
- NGINX_TLS_PORT=8443
24+
- MAGENTO_TLS_CERT=snakeoil.crt
25+
- MAGENTO_TLS_KEY=snakeoil.key
2426
ports:
2527
- "80:8000"
2628
- "443:8443"

docker-compose.overrides.yml.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ services:
99
- MAGE_ROOT_DIR=/workspace
1010
volumes:
1111
- ../:/workspace:cached
12-
- ./magento2-devcontainer/nginx:/etc/nginx/templates
12+
- ./magento2-devcontainer/nginx/default:/etc/nginx/templates

docs/tls.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# TLS Configuration
2+
3+
> **Note:** This configuration is only relevant when running devcontainers locally. If you're using GitHub Codespaces, HTTPS is handled automatically and you can skip this setup.
4+
5+
When working locally, it's important to consider the end-user experience. To mimic production as closely as possible for debugging purposes, you can setup a local TLS certificate. This devcontainer supports optional TLS (HTTPS) for local development.
6+
7+
## Configuration Options
8+
9+
Two nginx configurations are provided:
10+
11+
| Directory | Description |
12+
| ---------------- | --------------------------------- |
13+
| `nginx/default/` | HTTP only (port 80) |
14+
| `nginx/tls/` | HTTP (port 80) + HTTPS (port 443) |
15+
16+
## Enabling TLS
17+
18+
To enable TLS, modify your `docker-compose.overrides.yml` to:
19+
20+
1. Mount the TLS nginx config (as opposed to the default config)
21+
2. Mount your certificates directory
22+
3. Set the certificate filenames
23+
24+
```yaml
25+
services:
26+
nginx:
27+
environment:
28+
- MAGENTO_TLS_CERT=magento2.test.pem
29+
- MAGENTO_TLS_KEY=magento2.test-key.pem
30+
volumes:
31+
- ./magento2-devcontainer/nginx/tls:/etc/nginx/templates
32+
- ./certs:/etc/nginx/certs
33+
```
34+
35+
## Certificates
36+
37+
### Using Default Snakeoil Certificates
38+
39+
Default self-signed certificates are included in `magento2-devcontainer/certs/`:
40+
41+
- `snakeoil.crt`
42+
- `snakeoil.key`
43+
44+
These work out of the box but will trigger browser security warnings.
45+
46+
```yaml
47+
services:
48+
nginx:
49+
environment:
50+
- MAGENTO_TLS_CERT=snakeoil.crt
51+
- MAGENTO_TLS_KEY=snakeoil.key
52+
volumes:
53+
- ./magento2-devcontainer/nginx/tls:/etc/nginx/templates
54+
- ./magento2-devcontainer/certs:/etc/nginx/certs
55+
```
56+
57+
### Using mkcert (Recommended)
58+
59+
[mkcert](https://github.com/FiloSottile/mkcert) generates locally-trusted certificates that work without browser warnings.
60+
61+
1. Install mkcert on your system:
62+
63+
```bash
64+
# macOS
65+
brew install mkcert
66+
67+
# Linux
68+
sudo apt install mkcert
69+
# or
70+
sudo pacman -S mkcert
71+
72+
# Windows
73+
choco install mkcert
74+
```
75+
76+
2. Install the local CA (this registers mkcert's root certificate with your system):
77+
78+
```bash
79+
mkcert -install
80+
```
81+
82+
3. Generate certificates for your domain and place them in the certs directory:
83+
84+
```bash
85+
YOUR_TEST_DOMAIN=magento2.test
86+
mkdir -p .devcontainer/magento2/certs
87+
cd .devcontainer/magento2/certs
88+
mkcert -key-file $YOUR_TEST_DOMAIN-key.pem -cert-file $YOUR_TEST_DOMAIN.pem $YOUR_TEST_DOMAIN
89+
```
90+
91+
4. Update your `docker-compose.overrides.yml` with the cert filenames as shown above.
92+
93+
At this point, you should have a working TLS cert covering the `$YOUR_TEST_DOMAIN` domain.
94+
95+
## Environment Variables
96+
97+
| Variable | Default | Description |
98+
| ------------------ | -------------- | -------------------------------------------- |
99+
| `MAGENTO_TLS_CERT` | `snakeoil.crt` | Certificate filename in `/etc/nginx/certs` |
100+
| `MAGENTO_TLS_KEY` | `snakeoil.key` | Private key filename in `/etc/nginx/certs` |
101+
102+
## Troubleshooting
103+
104+
### Browser still shows certificate warnings with mkcert
105+
106+
Make sure you ran `mkcert -install` before generating the certificates. If you generated certs first, delete them and regenerate after running the install command.
107+
108+
### Certificate not found errors
109+
110+
Verify that:
111+
112+
- The certs directory is mounted to `/etc/nginx/certs`
113+
- The `MAGENTO_TLS_CERT` and `MAGENTO_TLS_KEY` environment variables match the actual filenames in your certs directory

nginx/tls/default.conf.template

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## This nginx configuration should serve as an example for a production configuration of nginx.
2+
## Do note that this configuration only serves non-encrypted connections. This is intentional;
3+
## traffic within the DMZ should not need to be encrypted unless absolutely required.
4+
5+
upstream fastcgi_backend {
6+
server ${MAGENTO2_UPSTREAM}:${MAGENTO2_UPSTREAM_PORT};
7+
}
8+
9+
server {
10+
listen ${NGINX_PORT};
11+
12+
set $MAGE_ROOT ${MAGE_ROOT_DIR};
13+
14+
include ${MAGE_ROOT_DIR}/nginx[.]conf*;
15+
}
16+
17+
server {
18+
listen ${NGINX_TLS_PORT} ssl;
19+
20+
ssl_certificate /etc/nginx/certs/${MAGENTO_TLS_CERT};
21+
ssl_certificate_key /etc/nginx/certs/${MAGENTO_TLS_KEY};
22+
23+
set $MAGE_ROOT ${MAGE_ROOT_DIR};
24+
25+
include ${MAGE_ROOT_DIR}/nginx[.]conf*;
26+
}

0 commit comments

Comments
 (0)