traefik-plugin-manual-access-control(TPMAC) is a traefik plugin that provides manual access control for services behind traefik.
First, run TPMAC service, below is an example with docker compose, and assuming tpmac.home.your-domain.com
is the domain you want to use.
version: '3'
services:
traefik-plugin-manual-access-control:
image: ghcr.io/iloahz/traefik-plugin-manual-access-control:main
restart: always
environment:
- IP2LOCATION_API_KEY=some_key_1
- JWT_SECRET=some_key_2
networks:
- traefik-network
labels:
- traefik.enable=true
- traefik.http.routers.tpmac.rule=Host(`tpmac.home.your-domain.com`)
- traefik.http.routers.tpmac.tls=true
- traefik.http.routers.tpmac.tls.certresolver=letsencrypt-cloudflare
networks:
traefik-network:
external: true
You can get free api key from https://www.ip2location.io/
openssl rand -base64 32
you will get something like
z8fXgwQIc/wT2zs4ct5C8RCFJ1lxrSwIxjTLvJP3yuI=
Add the following to traefik.yml
and restart traefik.
experimental:
plugins:
traefik-plugin-manual-access-control:
moduleName: github.com/iloahz/traefik-plugin-manual-access-control
version: v0.1.7
You can follow the instructions on traefik plugin page.
If you are using traefik with docker compose labels, an example would be:
labels:
- traefik.http.middlewares.my-traefik-plugin-manual-access-control.plugin.traefik-plugin-manual-access-control.Server=https://tpmac.home.your-domain.com
- traefik.http.routers.chatgpt-next-web.middlewares=my-traefik-plugin-manual-access-control
This step is optional.
When step #2 is successful, you should see TPMAC plugin enabled in traefik http middlewares page.
TPMAC uses JWT in cookie to control access, jwt is used to identify client only, consent is managed in TPMAC service.
sequenceDiagramparticipant A as Serviceparticipant B as TPMAC serviceparticipant C as TPMAC pluginparticipant D as Traefikparticipant E as Clientrect rgba(255,165,0,0.2)Note right of C: 1st requestE->>D: requestD->>C: requestC->>B: generate tokenB->>C: jwtC->>D: 403, jwt in cookieD->>E: 403, jwt in cookieendB->>B: admin allows accessrect rgba(50,205,50,0.2)Note right of C: 2nd requestE->>D: request, jwt in cookieD->>C: request, jwt in cookieC->>B: validate tokenB->>C: validC->>A: requestA->>C: responseC->>D: responseD->>E: responseend
Access control is "who can access what", compared to the comprehensive model of AWS IAM, TPMAC uses a simplified model to make it more convenient for homelab users.
In common sense, "who" is one particular friend, but how do we identify this user could be tricky, especially when we want to avoid complicated configs for homelab admin and authentication for friends.
A proxy of "who" is the device that the user is using, but unfortunately, it's not easy to identify a device, at least not in http layer, and since we want to build a general solution that works for all services, modifying the service is not an option.
Identifying "who" is the most important part of access control, TPMAC uses JWT to identify "who", and the JWT is stored in cookie.
"What" is very simple in TPMAC, it's a service behind traefik, and identified by the host
only.
TBA