Use SWAG tinyauth include files in the TinyAuth setups
This commit is contained in:
1 parent
fb3db10639
commit
4e8a68c330
26 files changed
+192
-496
No files matched your search
@@ -189,11 +189,15 @@ sudo nano /srv/docker/swag/config/nginx/proxy-confs/tinyauth.subdomain.conf
|
||||
Paste the following configuration:
|
||||
|
||||
```nginx [tinyauth.subdomain.conf]
|
||||
## Version 2023/12/19
|
||||
## Version 2025/07/18
|
||||
# make sure that your tinyauth container is named tinyauth
|
||||
# make sure that your dns has a cname set for tinyauth
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
# listen 443 quic;
|
||||
listen [::]:443 ssl;
|
||||
# listen [::]:443 quic;
|
||||
|
||||
server_name tinyauth.*;
|
||||
|
||||
@@ -202,12 +206,14 @@ server {
|
||||
client_max_body_size 0;
|
||||
|
||||
location / {
|
||||
|
||||
include /config/nginx/proxy.conf;
|
||||
include /config/nginx/resolver.conf;
|
||||
set $upstream_app tinyauth;
|
||||
set $upstream_port 3000;
|
||||
set $upstream_proto http;
|
||||
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
|
||||
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -227,7 +233,7 @@ __If it fails:__ check your firewall rules.
|
||||
::
|
||||
|
||||
## Protecting an app via reverse proxy
|
||||
SWAG doesn't ship a ready-made include file for TinyAuth, so we'll add the forward-auth check directly to the app's own `*.subdomain.conf`. We'll use Dockge as an example.
|
||||
SWAG ships ready-made include files for TinyAuth: `tinyauth-server.conf` (the internal `/tinyauth` check, to include in the `server` block) and `tinyauth-location.conf` (the `auth_request` itself, to include in the `location` block). All that's left is to uncomment two lines in the app's own `*.subdomain.conf`. We'll use Dockge as an example.
|
||||
|
||||
::steps{level="3"}
|
||||
### Open the app's subdomain.conf file
|
||||
@@ -236,11 +242,11 @@ SWAG doesn't ship a ready-made include file for TinyAuth, so we'll add the forwa
|
||||
sudo nano /srv/docker/swag/config/nginx/proxy-confs/dockge.subdomain.conf
|
||||
```
|
||||
|
||||
### Add the forward-auth check
|
||||
### Enable the TinyAuth includes
|
||||
|
||||
Add an internal `/tinyauth` location, and reference it from the app's `location /` block with `auth_request`:
|
||||
Uncomment the `tinyauth-server.conf` include in the `server` block, and the `tinyauth-location.conf` include in the `location /` block:
|
||||
|
||||
```nginx [dockge.subdomain.conf]{9-11,25}
|
||||
```nginx [dockge.subdomain.conf]{11,14}
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
@@ -251,23 +257,10 @@ server {
|
||||
|
||||
client_max_body_size 0;
|
||||
|
||||
location /tinyauth {
|
||||
internal;
|
||||
proxy_pass http://tinyauth:3000/api/auth/nginx;
|
||||
proxy_pass_request_body off;
|
||||
proxy_set_header Content-Length "";
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $http_host;
|
||||
proxy_set_header X-Forwarded-Uri $request_uri;
|
||||
}
|
||||
|
||||
location @tinyauth_login {
|
||||
return 302 https://tinyauth.mydomain.com/login?redirect_uri=$scheme://$http_host$request_uri;
|
||||
}
|
||||
include /config/nginx/tinyauth-server.conf;
|
||||
|
||||
location / {
|
||||
auth_request /tinyauth;
|
||||
error_page 401 = @tinyauth_login;
|
||||
include /config/nginx/tinyauth-location.conf;
|
||||
|
||||
include /config/nginx/proxy.conf;
|
||||
include /config/nginx/resolver.conf;
|
||||
@@ -281,7 +274,7 @@ server {
|
||||
|
||||
::note{to="/serveex/security/tinyauth#exposing-tinyauth-with-swag"}
|
||||
|
||||
The `location /tinyauth` block runs inside SWAG's own container, so SWAG needs to be on TinyAuth's Docker network to reach it by name (`tinyauth` here). This should already be set up from **exposing TinyAuth itself**. If you run into an error, double-check SWAG's compose file still has that network attached.
|
||||
The `/tinyauth` check runs inside SWAG's own container, so SWAG needs to be on TinyAuth's Docker network to reach it by name (`tinyauth` here). This should already be set up from **exposing TinyAuth itself**. If you run into an error, double-check SWAG's compose file still has that network attached. Also make sure the container is named `tinyauth`, since the include files rely on that name.
|
||||
::
|
||||
|
||||
Press :kbd{value="Ctrl+O"}, then :kbd{value="Enter"} to save, and :kbd{value="Ctrl+X"} to exit.
|
||||
@@ -289,7 +282,7 @@ Press :kbd{value="Ctrl+O"}, then :kbd{value="Enter"} to save, and :kbd{value="Ct
|
||||
### Done!
|
||||
::
|
||||
|
||||
That's it! Visiting `https://dockge.mydomain.com` now redirects to TinyAuth first. Repeat this `location /tinyauth` / `auth_request` pattern in any other app's `*.subdomain.conf` to protect it the same way.
|
||||
That's it! Visiting `https://dockge.mydomain.com` now redirects to TinyAuth first, which sends you back once you're logged in. The include also forwards the authenticated user to the app in the `Remote-User`, `Remote-Email`, `Remote-Name` and `Remote-Groups` headers, for apps that can use them. Uncomment the same two lines in any other app's `*.subdomain.conf` to protect it the same way.
|
||||
|
||||
::note
|
||||
|
||||
@@ -299,11 +292,11 @@ Repeat this process for each app you want to protect (unless it has native OIDC
|
||||
## Leaving specific paths public
|
||||
Sometimes you want most of an app locked behind TinyAuth, but a handful of paths left open, for example a public status page, or the API endpoints a mobile app relies on. Unlike Authentik, TinyAuth has no built-in "authenticated paths" setting for this: it's a plain nginx problem, and it's solved with nginx's own location matching.
|
||||
|
||||
A regex `location` block always takes priority over the plain `location /` block, no matter which one appears first in the file. So any path matched by a regex location you define runs its own `proxy_pass`, without ever reaching the `auth_request /tinyauth;` line in `location /`.
|
||||
A regex `location` block always takes priority over the plain `location /` block, no matter which one appears first in the file. So any path matched by a regex location you define runs its own `proxy_pass`, without ever reaching the `include /config/nginx/tinyauth-location.conf;` line in `location /`.
|
||||
|
||||
For example, here's how to leave Uptime-Kuma's public status page and its assets open while protecting everything else. Only `api/status-page` is left public, not all of `/api`, since the rest of Uptime-Kuma's API is meant to stay behind authentication; `/metrics` (Uptime-Kuma's Prometheus endpoint) is left out of the regex entirely for the same reason:
|
||||
|
||||
```nginx [uptime-kuma.subdomain.conf]{9-16}
|
||||
```nginx [uptime-kuma.subdomain.conf]{11-18}
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
@@ -312,6 +305,8 @@ server {
|
||||
|
||||
include /config/nginx/ssl.conf;
|
||||
|
||||
include /config/nginx/tinyauth-server.conf;
|
||||
|
||||
location ~ ^/(status|assets|icon\.svg|api/status-page|upload) {
|
||||
include /config/nginx/proxy.conf;
|
||||
include /config/nginx/resolver.conf;
|
||||
@@ -321,23 +316,8 @@ server {
|
||||
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
|
||||
}
|
||||
|
||||
location /tinyauth {
|
||||
internal;
|
||||
proxy_pass http://tinyauth:3000/api/auth/nginx;
|
||||
proxy_pass_request_body off;
|
||||
proxy_set_header Content-Length "";
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $http_host;
|
||||
proxy_set_header X-Forwarded-Uri $request_uri;
|
||||
}
|
||||
|
||||
location @tinyauth_login {
|
||||
return 302 https://tinyauth.mydomain.com/login?redirect_uri=$scheme://$http_host$request_uri;
|
||||
}
|
||||
|
||||
location / {
|
||||
auth_request /tinyauth;
|
||||
error_page 401 = @tinyauth_login;
|
||||
include /config/nginx/tinyauth-location.conf;
|
||||
|
||||
include /config/nginx/proxy.conf;
|
||||
include /config/nginx/resolver.conf;
|
||||
|
||||
Reference in new issue
Block a user