diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..8be208b --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "golang.go", + "redhat.vscode-yaml", + "ms-kubernetes-tools.vscode-kubernetes-tools" + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6130402 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "F5: Debug authproxy (demo hashes)", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "${workspaceFolder}/cmd/authproxy", + "env": { + "AUTH_PROXY_LISTEN_ADDR": ":8080", + "AUTH_PROXY_TOKEN_HASHES_DIR": "${workspaceFolder}/demo/token-hashes", + "AUTH_PROXY_LOG_LEVEL": "debug" + } + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..3b79a7f --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,47 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Run authproxy (demo hashes)", + "type": "shell", + "command": "go run ./cmd/authproxy", + "options": { + "env": { + "AUTH_PROXY_LISTEN_ADDR": ":8080", + "AUTH_PROXY_TOKEN_HASHES_DIR": "${workspaceFolder}/demo/token-hashes", + "AUTH_PROXY_LOG_LEVEL": "debug" + } + }, + "problemMatcher": [] + }, + { + "label": "Debug authproxy (delve, demo hashes)", + "type": "shell", + "command": "dlv debug ./cmd/authproxy", + "options": { + "env": { + "AUTH_PROXY_LISTEN_ADDR": ":8080", + "AUTH_PROXY_TOKEN_HASHES_DIR": "${workspaceFolder}/demo/token-hashes", + "AUTH_PROXY_LOG_LEVEL": "debug" + } + }, + "problemMatcher": [], + "presentation": { + "reveal": "always", + "panel": "shared" + } + }, + { + "label": "Check authproxy 200 (demo-token-1)", + "type": "shell", + "command": "http_code=$(curl -s -o /dev/null -w \"%{http_code}\" -H \"Authorization: Bearer demo-token-1\" http://localhost:8080/) && if [[ \"$http_code\" == \"200\" ]]; then echo \"OK: expected 200, got $http_code\"; else echo \"FAIL: expected 200, got $http_code\"; exit 1; fi", + "problemMatcher": [] + }, + { + "label": "Check authproxy 401 (wrong token)", + "type": "shell", + "command": "http_code=$(curl -s -o /dev/null -w \"%{http_code}\" -H \"Authorization: Bearer wrong\" http://localhost:8080/) && if [[ \"$http_code\" == \"401\" ]]; then echo \"OK: expected 401, got $http_code\"; else echo \"FAIL: expected 401, got $http_code\"; exit 1; fi", + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index a59be73..28c5ed2 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,43 @@ Kleiner Go-basierter Traefik-ForwardAuth-Microservice, der Bearer-Tokens gegen e Hinweis: Es muss mindestens eine Hash-Quelle (`AUTH_PROXY_TOKEN_HASHES_DIR` oder `AUTH_PROXY_TOKEN_HASHES`) konfiguriert sein. +## Demo-Daten + +Fuer schnelle lokale Tests sind Demo-Hashes im Repo enthalten: + +- Verzeichnis: `demo/token-hashes/` +- Datei `demo-token-1.sha256` entspricht Klartext-Token: `demo-token-1` +- Datei `demo-token-2.sha256` entspricht Klartext-Token: `demo-token-2` + +Die Dateien enthalten nur SHA-256-Hashes und koennen gefahrlos eingecheckt werden. + +## VS Code Tasks (Run + Debug + Checks) + +Im Projekt sind vier Tasks hinterlegt: + +- `Run authproxy (demo hashes)` + - startet den Server mit `go run ./cmd/authproxy` + - nutzt automatisch `AUTH_PROXY_TOKEN_HASHES_DIR=${workspaceFolder}/demo/token-hashes` +- `Debug authproxy (delve, demo hashes)` + - startet den Server im Delve-Debugger (`dlv debug ./cmd/authproxy`) + - nutzt dieselben Demo-ENV-Werte +- `Check authproxy 200 (demo-token-1)` + - prueft per `curl`, dass ein gueltiger Demo-Token den Status `200` liefert +- `Check authproxy 401 (wrong token)` + - prueft per `curl`, dass ein ungueltiger Token den Status `401` liefert + +Starten in VS Code ueber: `Terminal -> Run Task...` + +Zusaetzlich gibt es eine Launch-Konfiguration fuer Breakpoints: + +- `.vscode/launch.json` -> `F5: Debug authproxy (demo hashes)` + +F5-Flow: + +1. Fuer normalen Betrieb den Task `Run authproxy (demo hashes)` starten. +2. Fuer Debugging direkt die Konfiguration `F5: Debug authproxy (demo hashes)` mit `F5` starten (ohne vorherigen Run-Task). +3. Optional die Check-Tasks fuer `200` und `401` ausfuehren. + ## Go Package Registry (Gitea) Dieses Repo ist auf die Gitea Go Package Registry ausgerichtet. @@ -74,7 +111,7 @@ go test ./... -v go vet ./... go build ./cmd/authproxy -AUTH_PROXY_TOKEN_HASHES="," \ +AUTH_PROXY_TOKEN_HASHES_DIR="./demo/token-hashes" \ AUTH_PROXY_LISTEN_ADDR=":8080" \ go run ./cmd/authproxy ``` @@ -88,7 +125,7 @@ echo -n "my-token-1" | sha256sum | awk '{print $1}' Startbeispiel mit Hashes: ```bash -AUTH_PROXY_TOKEN_HASHES="," \ +AUTH_PROXY_TOKEN_HASHES_DIR="./demo/token-hashes" \ AUTH_PROXY_LISTEN_ADDR=":8080" \ go run ./cmd/authproxy ``` @@ -106,7 +143,7 @@ curl -i http://localhost:8080/ curl -i -H "Authorization: Bearer wrong" http://localhost:8080/ # gueltiger Token -> 200 -curl -i -H "Authorization: Bearer my-token-1" http://localhost:8080/ +curl -i -H "Authorization: Bearer demo-token-1" http://localhost:8080/ ``` ## Docker diff --git a/demo/token-hashes/demo-token-1.sha256 b/demo/token-hashes/demo-token-1.sha256 new file mode 100644 index 0000000..474a367 --- /dev/null +++ b/demo/token-hashes/demo-token-1.sha256 @@ -0,0 +1 @@ +65d01b54c870182ca3365564dbc7677a196f72a52f1ec15fdbf2da5efd013345 \ No newline at end of file diff --git a/demo/token-hashes/demo-token-2.sha256 b/demo/token-hashes/demo-token-2.sha256 new file mode 100644 index 0000000..d769583 --- /dev/null +++ b/demo/token-hashes/demo-token-2.sha256 @@ -0,0 +1 @@ +75e2c402bd94ae6120970a34fbb6c85702daf622ba2a9b2a1bcc33ecb06c2ffa \ No newline at end of file