First, set up at least one OAuth2 provider.
-
Google Cloud
-
GitHub
Encode the OAuth2 client credentials with base64 and store them in a .env file.
echo -n '<Your client ID>;<Your client secret>' | base64Create a .env file with the following contents:
JWT_SECRET=<base64-encoded JWT secret>
OAUTH2_GOOGLE=<base64-encoded OAuth2 client credential set>
OAUTH2_GITHUB=<base64-encoded OAuth2 client credential set>Create a config.yaml file for configuring reverse proxies and access control lists (ACL).
proxies:
#! admin
- external_url: "https://grafana.example.com/"
target: "http://grafana:3000/"
- external_url: "https://prometheus.example.com/"
target: "http://prometheus:9090/"
#! internal
- external_url: "https://example.com/api/"
target: "http://app:3000/"
- external_url: "https://api.example.com/"
target: "http://app:3000/"
#! public
- external_url: "https://example.com/"
target: "http://web:80/"
- external_url: "https://www.example.com/"
target: "http://web:80/"
acl:
"https://example.com":
paths:
"/":
- methods: ["GET"]
emails: ["-"] # public
"https://www.example.com":
paths:
"/":
- methods: ["GET"]
emails: ["-"] # public
"https://internal.example.com":
paths:
"/"
- methods: ["*"]
emails: ["*@example.com"]
"https://grafana.example.com/":
paths:
"/"
- methods: ["*"]
emails: ["<your email>"]
"https://prometheus.example.com/":
paths:
"/"
- methods: ["*"]
emails: ["<your email>"]
"https://gallery.example.com/":
paths:
"/"
- methods: ["*"]
emails: ["<your email>"]Create a compose.yaml file to define services.
services:
oauth2rbac:
image: tingtt/oauth2rbac:v1.0.0
command: [
"--port", "80",
"--jwt-secret", "$(JWT_SECRET)",
"-f", "/etc/oauth2rbac/config.yaml",
"--oauth2-client", "github;$(OAUTH2_GITHUB)",
"--oauth2-client", "google;$(OAUTH2_GOOGLE)",
]
ports:
- "80:80"
environment:
- JWT_SECRET=${JWT_SECRET}
- OAUTH2_GOOGLE=${OAUTH2_GOOGLE}
- OAUTH2_GITHUB=${OAUTH2_GITHUB}
volumes:
- ./config.yaml:/etc/oauth2rbac/config.yaml
restart: always
app:
image: example.com/app:latest
ports:
- "3000":"3000"
web:
image: nginx:latest
ports:
- "80":"80"
prometheus:
image: prom/prometheus:latest
ports:
- "9090":"9090"
grafana:
image: grafana/grafana:latest
ports:
- "3000":"3000"Provision certificates
$ mkdir -p tls/example.com/
# Get certificates...
# (e.g. certbot, ca-certificate, etc.)
$ ls
tls.crt tls.keyModify the compose.yaml to enable built-in TLS termination:
services:
oauth2rbac:
image: tingtt/oauth2rbac:v1.0.0
command: [
- "--port", "80",
+ "--port", "443",
"--jwt-secret", "$(JWT_SECRET)",
"-f", "/etc/oauth2rbac/config.yaml",
"--oauth2-client", "github;$(OAUTH2_GITHUB)",
"--oauth2-client", "google;$(OAUTH2_GOOGLE)",
+ "--tls-cert", "/etc/oauth2rbac/tls/example.com/tls.crt;/etc/oauth2rbac/tls/example.com/tls.key",
]
ports:
- - "80:80"
+ - "443:443"
environment:
- JWT_SECRET=${JWT_SECRET}
- OAUTH2_GOOGLE=${OAUTH2_GOOGLE}
- OAUTH2_GITHUB=${OAUTH2_GITHUB}
volumes:
- ./config.yaml:/etc/oauth2rbac/config.yaml
+ - ./tls:/etc/oauth2rbac/tls/example.com
restart: alwaysEnsure the TLS certificate and key are stored in the ./tls directory.