Add VS Code configuration files and demo token hashes for local testing
Build and Test / verify (push) Successful in 34s
Build and Push Container Image / build-and-push-image (push) Successful in 1m35s
Build and Test / verify (push) Successful in 34s
Build and Push Container Image / build-and-push-image (push) Successful in 1m35s
This commit is contained in:
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"golang.go",
|
||||
"redhat.vscode-yaml",
|
||||
"ms-kubernetes-tools.vscode-kubernetes-tools"
|
||||
]
|
||||
}
|
||||
Vendored
+17
@@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Vendored
+47
@@ -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": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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="<sha256-hash-1>,<sha256-hash-2>" \
|
||||
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="<sha256-hash-1>,<sha256-hash-2>" \
|
||||
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
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
65d01b54c870182ca3365564dbc7677a196f72a52f1ec15fdbf2da5efd013345
|
||||
@@ -0,0 +1 @@
|
||||
75e2c402bd94ae6120970a34fbb6c85702daf622ba2a9b2a1bcc33ecb06c2ffa
|
||||
Reference in New Issue
Block a user