-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from als-computing/nginx_redirect
NGINX Redirection
- Loading branch information
Showing
10 changed files
with
199 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Example | ||
This example provides an environment where you can test splash_auth with and OIDC auth provider of your choice. | ||
|
||
This has been tested with podman and podman-compose. It has not been tested with docker. | ||
|
||
##Services | ||
### nginx | ||
The services herin use `nginx` to handle proxying and authenticating. | ||
|
||
### splash_auth | ||
Provides service side support for the OIDC Code flow | ||
|
||
### python_server | ||
A simple python server, demonstrating that you can access it if you're logged in, and not if you're not. | ||
|
||
|
||
|
||
## Setup | ||
1. Edit `/examples/.env`, adding `client_id` and `client_secret` for your provider. | ||
2. Edit `users.yml` and `api_keys.yml` adding what you need. | ||
3. cd in to the `exmaples` directory and type `podman-compose up -d` | ||
4. Browse to localhost:8080 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
version: "3.3" | ||
services: | ||
python_server: | ||
image: "python:3.11-slim-buster" | ||
|
||
expose: | ||
- "8081" | ||
command: "python -m http.server 4200" | ||
|
||
nginx: | ||
container_name: nginx | ||
image: nginx | ||
ports: | ||
- 127.0.0.1:8080:80 | ||
volumes: | ||
- ./nginx/nginx.conf:/etc/nginx/nginx.conf | ||
#restart: unless-stopped | ||
logging: | ||
options: | ||
max-size: "1m" | ||
max-file: "3" | ||
networks: | ||
splash_auth_network: | ||
|
||
splash_auth: | ||
container_name: splash_auth | ||
#image: ghcr.io/als-computing/splash_auth:main | ||
build: | ||
context: .. | ||
# command: sleep 99999 | ||
command: uvicorn splash_auth.main:app --proxy-headers --host 0.0.0.0 --port 8000 --log-level=debug --use-colors --reload | ||
environment: | ||
- OAUTH_AUTH_ENDPOINT=https://accounts.google.com/o/oauth2/v2/auth | ||
- OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID} | ||
- OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET} | ||
- OAUTH_REDIRECT_URI=http://localhost:8080/oidc/auth/code | ||
- OAUTH_TOKEN_URI=https://oauth2.googleapis.com/token | ||
- OUATH_JWKS_URI=https://www.googleapis.com/oauth2/v3/certs | ||
- TOKEN_EXP_TIME=172400 | ||
- JWT_SECRET=${JWT_SECRET} | ||
- OUATH_SUCCESS_REDIRECT_URI=http://localhost:8080/ | ||
- OUATH_FAIL_REDIRECT_URI=http://localhost:8080 | ||
- HTTPX_LOG_LEVEL=trace | ||
volumes: | ||
- ../:/app | ||
- ./users.yml:/app/users.yml | ||
- ./api_keys.yml:/app/api_keys.yml | ||
restart: unless-stopped | ||
logging: | ||
options: | ||
max-size: "1m" | ||
max-file: "3" | ||
networks: | ||
splash_auth_network: | ||
networks: | ||
splash_auth_network: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
user nginx; | ||
worker_processes 1; | ||
|
||
error_log /var/log/nginx/error.log warn; | ||
pid /var/run/nginx.pid; | ||
|
||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
|
||
http { | ||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
|
||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
'$status $body_bytes_sent "$http_referer" ' | ||
'"$http_user_agent" "$http_x_forwarded_for"'; | ||
|
||
access_log /var/log/nginx/access.log main; | ||
|
||
sendfile on; | ||
#tcp_nopush on; | ||
|
||
keepalive_timeout 65; | ||
|
||
gzip on; | ||
ssl_session_cache shared:SSL:10m; | ||
ssl_session_timeout 10m; | ||
|
||
underscores_in_headers on; | ||
|
||
server{ | ||
listen 80; | ||
keepalive_timeout 70; | ||
|
||
# All HTTP traffic will be redirected to to the auth server | ||
location / { | ||
auth_request /oauth2/auth; | ||
error_page 401 = /login; | ||
proxy_pass http://python_server:4200; | ||
proxy_buffer_size 8k; | ||
error_page 401 = /oauth2/sign_in; | ||
auth_request_set $user $upstream_http_x_auth_request_user; | ||
auth_request_set $email $upstream_http_x_auth_request_email; | ||
proxy_set_header X-User $user; | ||
proxy_set_header X-Email $email; | ||
proxy_set_header X-Forwarded-Host $http_host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
proxy_set_header X-Auth-Request-Redirect $request_uri; | ||
auth_request_set $auth_cookie $upstream_http_set_cookie; | ||
} | ||
|
||
# This is where the auth_request points, all messages needing auth go to the auth server | ||
# The auth server returns a 200 if the user is authenticated, otherwise a 401 | ||
location = /oauth2/auth { | ||
proxy_pass http://splash_auth:8000/oauth2/auth; | ||
proxy_buffer_size 8k; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Scheme $scheme; | ||
proxy_set_header Content-Length ""; | ||
proxy_set_header X-Auth-Request-Redirect $request_uri; | ||
proxy_pass_request_body off; | ||
} | ||
|
||
|
||
# The login page is unprotected | ||
location /login { | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Scheme $scheme; | ||
proxy_set_header X-Auth-Request-Redirect $request_uri; | ||
proxy_buffer_size 8k; | ||
proxy_pass http://splash_auth:8000/login; | ||
} | ||
|
||
|
||
# For OIDC, the browser is redirected to the auth server to exchange a code | ||
location = /oidc/auth/code { | ||
proxy_pass http://splash_auth:8000/oidc/auth/code; | ||
proxy_buffer_size 8k; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Scheme $scheme; | ||
proxy_set_header Content-Length ""; | ||
proxy_set_header X-Auth-Request-Redirect $request_uri; | ||
proxy_pass_request_body off; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from dataclasses import dataclass | ||
from typing import Dict, List | ||
from typing import List | ||
|
||
import yaml | ||
|
||
|