mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-04-19 20:18:16 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 134befe72f | |||
| fdcb253072 |
@@ -1,82 +0,0 @@
|
|||||||
name: Proxy Integration Tests
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
build:
|
|
||||||
type: boolean
|
|
||||||
description: Build from current tag before running tests
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
determine-tag:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
outputs:
|
|
||||||
version: ${{ steps.metadata.outputs.VERSION }}
|
|
||||||
commit_hash: ${{ steps.metadata.outputs.COMMIT_HASH }}
|
|
||||||
build_timestamp: ${{ steps.metadata.outputs.BUILD_TIMESTAMP }}
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Determine metadata
|
|
||||||
id: metadata
|
|
||||||
run: |
|
|
||||||
# Generate static metadata
|
|
||||||
echo "COMMIT_HASH=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "BUILD_TIMESTAMP=$(date '+%Y-%m-%dT%H:%M:%S')" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
# Determine version
|
|
||||||
if [ "${{ inputs.build }}" == "true" ]; then
|
|
||||||
echo "VERSION=development" >> "$GITHUB_OUTPUT"
|
|
||||||
else
|
|
||||||
echo "VERSION=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
integration:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: determine-tag
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: "1.25.0"
|
|
||||||
|
|
||||||
- name: Initialize submodules
|
|
||||||
run: |
|
|
||||||
git submodule init
|
|
||||||
git submodule update
|
|
||||||
|
|
||||||
- name: Apply patches
|
|
||||||
run: |
|
|
||||||
git apply --directory paerser/ patches/nested_maps.diff
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
if: ${{ inputs.build == 'true' }}
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
if: ${{ inputs.build == 'true' }}
|
|
||||||
with:
|
|
||||||
platforms: linux/amd64
|
|
||||||
tags: ghcr.io/${{ github.repository_owner }}/tinyauth:${{ needs.determine-tag.outputs.version }}
|
|
||||||
outputs: type=image,push=false
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
build-args: |
|
|
||||||
VERSION=${{ needs.determine-tag.outputs.version }}
|
|
||||||
COMMIT_HASH=${{ needs.determine-tag.outputs.commit_hash }}
|
|
||||||
BUILD_TIMESTAMP=${{ needs.determine-tag.outputs.build_timestamp }}
|
|
||||||
|
|
||||||
- name: Set tinyauth version
|
|
||||||
run: |
|
|
||||||
sed -i "s/TINYAUTH_VERSION=.*/TINYAUTH_VERSION=${{ needs.determine-tag.outputs.version }}/" integration/.env
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
run: make integration
|
|
||||||
@@ -15,6 +15,8 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: nightly
|
||||||
|
|
||||||
- name: Generate metadata
|
- name: Generate metadata
|
||||||
id: metadata
|
id: metadata
|
||||||
|
|||||||
@@ -81,11 +81,5 @@ sql:
|
|||||||
sqlc generate
|
sqlc generate
|
||||||
|
|
||||||
# Go gen
|
# Go gen
|
||||||
.PHONY: generate
|
|
||||||
generate:
|
generate:
|
||||||
go run ./gen
|
go run ./gen
|
||||||
|
|
||||||
# Proxy integration tests
|
|
||||||
.PHONY: integration
|
|
||||||
integration:
|
|
||||||
go run ./integration -- --log=false
|
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
# Nginx configuration
|
|
||||||
NGINX_VERSION=1.29
|
|
||||||
|
|
||||||
# Whoami configuration
|
|
||||||
WHOAMI_VERSION=latest
|
|
||||||
|
|
||||||
# Traefik configuration
|
|
||||||
TRAEFIK_VERSION=v3.6
|
|
||||||
TINYAUTH_HOST=tinyauth.127.0.0.1.sslip.io
|
|
||||||
WHOAMI_HOST=whoami.127.0.0.1.sslip.io
|
|
||||||
|
|
||||||
# Envoy configuration
|
|
||||||
ENVOY_VERSION=v1.33-latest
|
|
||||||
|
|
||||||
# Tinyauth configuration
|
|
||||||
TINYAUTH_VERSION=latest
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
appUrl: http://tinyauth.127.0.0.1.sslip.io
|
|
||||||
|
|
||||||
auth:
|
|
||||||
users: test:$2a$10$eG88kFow83l5YRSlTSL2o.sZimjxFHrpiKdaSUZqpLBGX7Y2.4PZG
|
|
||||||
|
|
||||||
log:
|
|
||||||
json: true
|
|
||||||
level: trace
|
|
||||||
|
|
||||||
apps:
|
|
||||||
whoami:
|
|
||||||
config:
|
|
||||||
domain: whoami.127.0.0.1.sslip.io
|
|
||||||
path:
|
|
||||||
allow: /allow
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
services:
|
|
||||||
envoy:
|
|
||||||
image: envoyproxy/envoy:${ENVOY_VERSION}
|
|
||||||
ports:
|
|
||||||
- 80:80
|
|
||||||
volumes:
|
|
||||||
- ./envoy.yml:/etc/envoy/envoy.yaml:ro
|
|
||||||
|
|
||||||
whoami:
|
|
||||||
image: traefik/whoami:${WHOAMI_VERSION}
|
|
||||||
|
|
||||||
tinyauth:
|
|
||||||
image: ghcr.io/steveiliop56/tinyauth:${TINYAUTH_VERSION}
|
|
||||||
command: --experimental.configfile=/data/config.yml
|
|
||||||
volumes:
|
|
||||||
- ./config.yml:/data/config.yml:ro
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
services:
|
|
||||||
nginx:
|
|
||||||
image: nginx:${NGINX_VERSION}
|
|
||||||
ports:
|
|
||||||
- 80:80
|
|
||||||
volumes:
|
|
||||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
|
||||||
|
|
||||||
whoami:
|
|
||||||
image: traefik/whoami:${WHOAMI_VERSION}
|
|
||||||
|
|
||||||
tinyauth:
|
|
||||||
image: ghcr.io/steveiliop56/tinyauth:${TINYAUTH_VERSION}
|
|
||||||
command: --experimental.configfile=/data/config.yml
|
|
||||||
volumes:
|
|
||||||
- ./config.yml:/data/config.yml:ro
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
services:
|
|
||||||
traefik:
|
|
||||||
image: traefik:${TRAEFIK_VERSION}
|
|
||||||
command: |
|
|
||||||
--api.insecure=true
|
|
||||||
--providers.docker
|
|
||||||
--entryPoints.web.address=:80
|
|
||||||
ports:
|
|
||||||
- 80:80
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
|
|
||||||
whoami:
|
|
||||||
image: traefik/whoami:${WHOAMI_VERSION}
|
|
||||||
labels:
|
|
||||||
traefik.enable: true
|
|
||||||
traefik.http.routers.whoami.rule: Host(`${WHOAMI_HOST}`)
|
|
||||||
traefik.http.routers.whoami.middlewares: tinyauth
|
|
||||||
|
|
||||||
tinyauth:
|
|
||||||
image: ghcr.io/steveiliop56/tinyauth:${TINYAUTH_VERSION}
|
|
||||||
command: --experimental.configfile=/data/config.yml
|
|
||||||
volumes:
|
|
||||||
- ./config.yml:/data/config.yml:ro
|
|
||||||
labels:
|
|
||||||
traefik.enable: true
|
|
||||||
traefik.http.routers.tinyauth.rule: Host(`${TINYAUTH_HOST}`)
|
|
||||||
traefik.http.middlewares.tinyauth.forwardauth.address: http://tinyauth:3000/api/auth/traefik
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
static_resources:
|
|
||||||
listeners:
|
|
||||||
- name: "listener_http"
|
|
||||||
address:
|
|
||||||
socket_address:
|
|
||||||
address: "0.0.0.0"
|
|
||||||
port_value: 80
|
|
||||||
filter_chains:
|
|
||||||
- filters:
|
|
||||||
- name: "envoy.filters.network.http_connection_manager"
|
|
||||||
typed_config:
|
|
||||||
"@type": "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"
|
|
||||||
stat_prefix: "ingress_http"
|
|
||||||
use_remote_address: true
|
|
||||||
skip_xff_append: false
|
|
||||||
route_config:
|
|
||||||
name: "local_route"
|
|
||||||
virtual_hosts:
|
|
||||||
- name: "whoami_service"
|
|
||||||
domains: ["whoami.127.0.0.1.sslip.io"]
|
|
||||||
routes:
|
|
||||||
- match:
|
|
||||||
prefix: "/"
|
|
||||||
route:
|
|
||||||
cluster: "whoami"
|
|
||||||
- name: "tinyauth_service"
|
|
||||||
domains: ["tinyauth.127.0.0.1.sslip.io"]
|
|
||||||
typed_per_filter_config:
|
|
||||||
envoy.filters.http.ext_authz:
|
|
||||||
"@type": "type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute"
|
|
||||||
disabled: true
|
|
||||||
routes:
|
|
||||||
- match:
|
|
||||||
prefix: "/"
|
|
||||||
route:
|
|
||||||
cluster: "tinyauth"
|
|
||||||
http_filters:
|
|
||||||
- name: "envoy.filters.http.ext_authz"
|
|
||||||
typed_config:
|
|
||||||
"@type": "type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthz"
|
|
||||||
transport_api_version: "v3"
|
|
||||||
http_service:
|
|
||||||
path_prefix: "/api/auth/envoy?path="
|
|
||||||
server_uri:
|
|
||||||
uri: "tinyauth:3000"
|
|
||||||
cluster: "tinyauth"
|
|
||||||
timeout: "0.25s"
|
|
||||||
authorization_request:
|
|
||||||
allowed_headers:
|
|
||||||
patterns:
|
|
||||||
- exact: "authorization"
|
|
||||||
- exact: "accept"
|
|
||||||
- exact: "cookie"
|
|
||||||
headers_to_add:
|
|
||||||
- key: "x-forwarded-proto"
|
|
||||||
value: "%REQ(:SCHEME)%"
|
|
||||||
- key: "x-forwarded-host"
|
|
||||||
value: "%REQ(:AUTHORITY)%"
|
|
||||||
- key: "x-forwarded-uri"
|
|
||||||
value: "%REQ(:PATH)%"
|
|
||||||
authorization_response:
|
|
||||||
allowed_upstream_headers:
|
|
||||||
patterns:
|
|
||||||
- prefix: "remote-"
|
|
||||||
allowed_client_headers:
|
|
||||||
patterns:
|
|
||||||
- exact: "set-cookie"
|
|
||||||
- exact: "location"
|
|
||||||
allowed_client_headers_on_success:
|
|
||||||
patterns:
|
|
||||||
- exact: "set-cookie"
|
|
||||||
- exact: "location"
|
|
||||||
failure_mode_allow: false
|
|
||||||
- name: "envoy.filters.http.router"
|
|
||||||
typed_config:
|
|
||||||
"@type": "type.googleapis.com/envoy.extensions.filters.http.router.v3.Router"
|
|
||||||
clusters:
|
|
||||||
- name: "whoami"
|
|
||||||
connect_timeout: "0.25s"
|
|
||||||
type: "logical_dns"
|
|
||||||
dns_lookup_family: "v4_only"
|
|
||||||
lb_policy: "round_robin"
|
|
||||||
load_assignment:
|
|
||||||
cluster_name: "whoami"
|
|
||||||
endpoints:
|
|
||||||
- lb_endpoints:
|
|
||||||
- endpoint:
|
|
||||||
address:
|
|
||||||
socket_address:
|
|
||||||
address: "whoami"
|
|
||||||
port_value: 80
|
|
||||||
- name: "tinyauth"
|
|
||||||
connect_timeout: "0.25s"
|
|
||||||
type: "logical_dns"
|
|
||||||
dns_lookup_family: "v4_only"
|
|
||||||
lb_policy: "round_robin"
|
|
||||||
load_assignment:
|
|
||||||
cluster_name: "tinyauth"
|
|
||||||
endpoints:
|
|
||||||
- lb_endpoints:
|
|
||||||
- endpoint:
|
|
||||||
address:
|
|
||||||
socket_address:
|
|
||||||
address: "tinyauth"
|
|
||||||
port_value: 3000
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func testUnauthorized(client *http.Client) error {
|
|
||||||
req, err := http.NewRequest("GET", WhoamiURL, nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// nginx and envoy will throw us at the frontend
|
|
||||||
if resp.StatusCode != http.StatusUnauthorized && !strings.Contains(string(body), "<div id=\"root\"></div>") {
|
|
||||||
return fmt.Errorf("expected status code %d or to to contain '<div id=\"root\"></div>', got %d", http.StatusUnauthorized, resp.StatusCode)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testLoggedIn(client *http.Client) error {
|
|
||||||
req, err := http.NewRequest("GET", WhoamiURL, nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
req.SetBasicAuth(DefaultUsername, DefaultPassword)
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
return fmt.Errorf("expected status code %d, got %d", http.StatusOK, resp.StatusCode)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testACLAllowed(client *http.Client) error {
|
|
||||||
req, err := http.NewRequest("GET", WhoamiURL+"/allow", nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
return fmt.Errorf("expected status code %d, got %d", http.StatusOK, resp.StatusCode)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,191 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"log/slog"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ProxiesToTest = []string{"traefik", "nginx", "envoy"}
|
|
||||||
|
|
||||||
const (
|
|
||||||
EnvFile = ".env"
|
|
||||||
ConfigFile = "config.yml"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
TinyauthURL = "http://tinyauth.127.0.0.1.sslip.io"
|
|
||||||
WhoamiURL = "http://whoami.127.0.0.1.sslip.io"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
DefaultUsername = "test"
|
|
||||||
DefaultPassword = "password"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
logFlag := flag.Bool("log", false, "enable stack logging")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
rootFolder, err := os.Getwd()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("fail", "error", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
slog.Info("root folder", "folder", rootFolder)
|
|
||||||
|
|
||||||
integrationRoot := rootFolder
|
|
||||||
|
|
||||||
if _, err := os.Stat(path.Join(rootFolder, ".git")); err != nil {
|
|
||||||
if !errors.Is(err, os.ErrNotExist) {
|
|
||||||
slog.Error("fail", "error", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
integrationRoot = path.Join(rootFolder, "integration")
|
|
||||||
}
|
|
||||||
|
|
||||||
slog.Info("integration root", "folder", integrationRoot)
|
|
||||||
|
|
||||||
for _, proxy := range ProxiesToTest {
|
|
||||||
slog.Info("begin", "proxy", proxy)
|
|
||||||
compose := fmt.Sprintf("docker-compose.%s.yml", proxy)
|
|
||||||
if _, err := os.Stat(path.Join(integrationRoot, compose)); err != nil {
|
|
||||||
slog.Error("fail", "proxy", proxy, "error", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
if err := createInstanceAndRunTests(compose, *logFlag, proxy, integrationRoot); err != nil {
|
|
||||||
slog.Error("fail", "proxy", proxy, "error", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
slog.Info("end", "proxy", proxy)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func runTests(client *http.Client, name string) error {
|
|
||||||
if err := testUnauthorized(client); err != nil {
|
|
||||||
slog.Error("fail unauthorized test", "name", name)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
slog.Info("unauthorized test passed", "name", name)
|
|
||||||
|
|
||||||
if err := testLoggedIn(client); err != nil {
|
|
||||||
slog.Error("fail logged in test", "name", name)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
slog.Info("logged in test passed", "name", name)
|
|
||||||
|
|
||||||
if err := testACLAllowed(client); err != nil {
|
|
||||||
slog.Error("fail acl test", "name", name)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
slog.Info("acl test passed", "name", name)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func createInstanceAndRunTests(compose string, log bool, name string, integrationDir string) error {
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
composeFile := path.Join(integrationDir, compose)
|
|
||||||
envFile := path.Join(integrationDir, EnvFile)
|
|
||||||
cmdArgs := []string{"compose", "-f", composeFile, "--env-file", envFile, "up", "--build", "--force-recreate", "--remove-orphans"}
|
|
||||||
cmd := exec.CommandContext(ctx, "docker", cmdArgs...)
|
|
||||||
|
|
||||||
if log {
|
|
||||||
setupCmdLogging(cmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
cmd.Process.Signal(os.Interrupt)
|
|
||||||
cmd.Wait()
|
|
||||||
}()
|
|
||||||
|
|
||||||
slog.Info("instance created", "name", name)
|
|
||||||
|
|
||||||
if err := waitForHealthy(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
slog.Info("instance healthy", "name", name)
|
|
||||||
|
|
||||||
client := &http.Client{}
|
|
||||||
|
|
||||||
if err := runTests(client, name); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
slog.Info("tests passed", "name", name)
|
|
||||||
|
|
||||||
cmd.Process.Signal(os.Interrupt)
|
|
||||||
|
|
||||||
if err := cmd.Wait(); cmd.ProcessState.ExitCode() != 130 && err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupCmdLogging(cmd *exec.Cmd) {
|
|
||||||
stdout, _ := cmd.StdoutPipe()
|
|
||||||
stderr, _ := cmd.StderrPipe()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
scanner := bufio.NewScanner(stdout)
|
|
||||||
for scanner.Scan() {
|
|
||||||
slog.Info("docker out", "stdout", scanner.Text())
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
scanner := bufio.NewScanner(stderr)
|
|
||||||
for scanner.Scan() {
|
|
||||||
slog.Error("docker out", "stderr", scanner.Text())
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func waitForHealthy() error {
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
ticker := time.NewTicker(10 * time.Second)
|
|
||||||
client := http.Client{}
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return errors.New("tinyauth not healthy after 5 minutes")
|
|
||||||
case <-ticker.C:
|
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", TinyauthURL+"/api/healthz", nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
res, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if res.StatusCode == http.StatusOK {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
server {
|
|
||||||
listen 80;
|
|
||||||
listen [::]:80;
|
|
||||||
|
|
||||||
server_name tinyauth.127.0.0.1.sslip.io;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://tinyauth:3000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
listen [::]:80;
|
|
||||||
|
|
||||||
server_name whoami.127.0.0.1.sslip.io;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://whoami;
|
|
||||||
auth_request /tinyauth;
|
|
||||||
error_page 401 = @tinyauth_login;
|
|
||||||
}
|
|
||||||
|
|
||||||
location /tinyauth {
|
|
||||||
internal;
|
|
||||||
proxy_pass http://tinyauth:3000/api/auth/nginx;
|
|
||||||
proxy_set_header x-original-url $scheme://$http_host$request_uri;
|
|
||||||
proxy_set_header x-forwarded-proto $scheme;
|
|
||||||
proxy_set_header x-forwarded-host $host;
|
|
||||||
proxy_set_header x-forwarded-uri $request_uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
location @tinyauth_login {
|
|
||||||
return 302 http://tinyauth.127.0.0.1.sslip.io/login?redirect_uri=$scheme://$http_host$request_uri;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -27,6 +27,8 @@ const (
|
|||||||
|
|
||||||
var BrowserUserAgentRegex = regexp.MustCompile("Chrome|Gecko|AppleWebKit|Opera|Edge")
|
var BrowserUserAgentRegex = regexp.MustCompile("Chrome|Gecko|AppleWebKit|Opera|Edge")
|
||||||
|
|
||||||
|
var SupportedProxies = []string{"nginx", "traefik", "caddy", "envoy"}
|
||||||
|
|
||||||
type Proxy struct {
|
type Proxy struct {
|
||||||
Proxy string `uri:"proxy" binding:"required"`
|
Proxy string `uri:"proxy" binding:"required"`
|
||||||
}
|
}
|
||||||
@@ -364,17 +366,7 @@ func (controller *ProxyController) getAuthRequestContext(c *gin.Context) (ProxyC
|
|||||||
}
|
}
|
||||||
|
|
||||||
host := url.Host
|
host := url.Host
|
||||||
|
|
||||||
if strings.TrimSpace(host) == "" {
|
|
||||||
return ProxyContext{}, errors.New("host not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
proto := url.Scheme
|
proto := url.Scheme
|
||||||
|
|
||||||
if strings.TrimSpace(proto) == "" {
|
|
||||||
return ProxyContext{}, errors.New("proto not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
path := url.Path
|
path := url.Path
|
||||||
method := c.Request.Method
|
method := c.Request.Method
|
||||||
|
|
||||||
@@ -396,11 +388,7 @@ func (controller *ProxyController) getExtAuthzContext(c *gin.Context) (ProxyCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
// It sets the host to the original host, not the forwarded host
|
// It sets the host to the original host, not the forwarded host
|
||||||
host := c.Request.Host
|
host := c.Request.URL.Host
|
||||||
|
|
||||||
if strings.TrimSpace(host) == "" {
|
|
||||||
return ProxyContext{}, errors.New("host not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
// We get the path from the query string
|
// We get the path from the query string
|
||||||
path := c.Query("path")
|
path := c.Query("path")
|
||||||
@@ -419,14 +407,14 @@ func (controller *ProxyController) getExtAuthzContext(c *gin.Context) (ProxyCont
|
|||||||
|
|
||||||
func (controller *ProxyController) determineAuthModules(proxy string) []AuthModuleType {
|
func (controller *ProxyController) determineAuthModules(proxy string) []AuthModuleType {
|
||||||
switch proxy {
|
switch proxy {
|
||||||
case "traefik", "caddy":
|
case "traefik":
|
||||||
return []AuthModuleType{ForwardAuth}
|
return []AuthModuleType{ForwardAuth}
|
||||||
case "envoy":
|
case "envoy":
|
||||||
return []AuthModuleType{ExtAuthz, ForwardAuth}
|
return []AuthModuleType{ExtAuthz, ForwardAuth}
|
||||||
case "nginx":
|
case "nginx":
|
||||||
return []AuthModuleType{AuthRequest, ForwardAuth}
|
return []AuthModuleType{AuthRequest, ForwardAuth}
|
||||||
default:
|
default:
|
||||||
return []AuthModuleType{}
|
return []AuthModuleType{ForwardAuth}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,11 +452,9 @@ func (controller *ProxyController) getProxyContext(c *gin.Context) (ProxyContext
|
|||||||
|
|
||||||
tlog.App.Debug().Msgf("Proxy: %v", req.Proxy)
|
tlog.App.Debug().Msgf("Proxy: %v", req.Proxy)
|
||||||
|
|
||||||
authModules := controller.determineAuthModules(req.Proxy)
|
tlog.App.Trace().Interface("headers", c.Request.Header).Msg("Request headers")
|
||||||
|
|
||||||
if len(authModules) == 0 {
|
authModules := controller.determineAuthModules(req.Proxy)
|
||||||
return ProxyContext{}, fmt.Errorf("no auth modules supported for proxy: %v", req.Proxy)
|
|
||||||
}
|
|
||||||
|
|
||||||
var ctx ProxyContext
|
var ctx ProxyContext
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package controller_test
|
package controller_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -10,26 +9,21 @@ import (
|
|||||||
"github.com/steveiliop56/tinyauth/internal/controller"
|
"github.com/steveiliop56/tinyauth/internal/controller"
|
||||||
"github.com/steveiliop56/tinyauth/internal/repository"
|
"github.com/steveiliop56/tinyauth/internal/repository"
|
||||||
"github.com/steveiliop56/tinyauth/internal/service"
|
"github.com/steveiliop56/tinyauth/internal/service"
|
||||||
|
"github.com/steveiliop56/tinyauth/internal/utils/tlog"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var loggedInCtx = config.UserContext{
|
func setupProxyController(t *testing.T, middlewares *[]gin.HandlerFunc) (*gin.Engine, *httptest.ResponseRecorder, *service.AuthService) {
|
||||||
Username: "test",
|
tlog.NewSimpleLogger().Init()
|
||||||
Name: "Test",
|
|
||||||
Email: "test@example.com",
|
|
||||||
IsLoggedIn: true,
|
|
||||||
Provider: "local",
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupProxyController(t *testing.T, middlewares []gin.HandlerFunc) (*gin.Engine, *httptest.ResponseRecorder) {
|
|
||||||
// Setup
|
// Setup
|
||||||
gin.SetMode(gin.TestMode)
|
gin.SetMode(gin.TestMode)
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
|
|
||||||
if len(middlewares) > 0 {
|
if middlewares != nil {
|
||||||
for _, m := range middlewares {
|
for _, m := range *middlewares {
|
||||||
router.Use(m)
|
router.Use(m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,13 +48,7 @@ func setupProxyController(t *testing.T, middlewares []gin.HandlerFunc) (*gin.Eng
|
|||||||
assert.NilError(t, dockerService.Init())
|
assert.NilError(t, dockerService.Init())
|
||||||
|
|
||||||
// Access controls
|
// Access controls
|
||||||
accessControlsService := service.NewAccessControlsService(dockerService, map[string]config.App{
|
accessControlsService := service.NewAccessControlsService(dockerService, map[string]config.App{})
|
||||||
"whoami": {
|
|
||||||
Path: config.AppPath{
|
|
||||||
Allow: "/allow",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
assert.NilError(t, accessControlsService.Init())
|
assert.NilError(t, accessControlsService.Init())
|
||||||
|
|
||||||
@@ -89,214 +77,107 @@ func setupProxyController(t *testing.T, middlewares []gin.HandlerFunc) (*gin.Eng
|
|||||||
|
|
||||||
// Controller
|
// Controller
|
||||||
ctrl := controller.NewProxyController(controller.ProxyControllerConfig{
|
ctrl := controller.NewProxyController(controller.ProxyControllerConfig{
|
||||||
AppURL: "http://tinyauth.example.com",
|
AppURL: "http://localhost:8080",
|
||||||
}, group, accessControlsService, authService)
|
}, group, accessControlsService, authService)
|
||||||
ctrl.SetupRoutes()
|
ctrl.SetupRoutes()
|
||||||
|
|
||||||
return router, recorder
|
return router, recorder, authService
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Needs tests for context middleware
|
// TODO: Needs tests for context middleware
|
||||||
|
|
||||||
func TestProxyHandler(t *testing.T) {
|
func TestProxyHandler(t *testing.T) {
|
||||||
// Test logged out user traefik/caddy (forward_auth)
|
// Setup
|
||||||
router, recorder := setupProxyController(t, nil)
|
router, recorder, _ := setupProxyController(t, nil)
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/api/auth/traefik", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
req.Header.Set("x-forwarded-host", "whoami.example.com")
|
|
||||||
req.Header.Set("x-forwarded-proto", "http")
|
|
||||||
req.Header.Set("x-forwarded-uri", "/")
|
|
||||||
|
|
||||||
|
// Test invalid proxy
|
||||||
|
req := httptest.NewRequest("GET", "/api/auth/invalidproxy", nil)
|
||||||
router.ServeHTTP(recorder, req)
|
router.ServeHTTP(recorder, req)
|
||||||
assert.Equal(t, recorder.Code, http.StatusUnauthorized)
|
|
||||||
|
|
||||||
// Test logged out user nginx (auth_request)
|
assert.Equal(t, 400, recorder.Code)
|
||||||
router, recorder = setupProxyController(t, nil)
|
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/nginx", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
req.Header.Set("x-original-url", "http://whoami.example.com/")
|
|
||||||
|
|
||||||
|
// Test invalid method for non-envoy proxy
|
||||||
|
recorder = httptest.NewRecorder()
|
||||||
|
req = httptest.NewRequest("POST", "/api/auth/traefik", nil)
|
||||||
router.ServeHTTP(recorder, req)
|
router.ServeHTTP(recorder, req)
|
||||||
assert.Equal(t, recorder.Code, http.StatusUnauthorized)
|
|
||||||
|
|
||||||
// Test logged out user envoy (ext_authz)
|
assert.Equal(t, 405, recorder.Code)
|
||||||
router, recorder = setupProxyController(t, nil)
|
assert.Equal(t, "GET", recorder.Header().Get("Allow"))
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/envoy?path=/", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
req.Host = "whoami.example.com"
|
|
||||||
req.Header.Set("x-forwarded-proto", "http")
|
|
||||||
|
|
||||||
|
// Test logged out user (traefik/caddy)
|
||||||
|
recorder = httptest.NewRecorder()
|
||||||
|
req = httptest.NewRequest("GET", "/api/auth/traefik", nil)
|
||||||
|
req.Header.Set("X-Forwarded-Proto", "https")
|
||||||
|
req.Header.Set("X-Forwarded-Host", "example.com")
|
||||||
|
req.Header.Set("X-Forwarded-Uri", "/somepath")
|
||||||
|
req.Header.Set("Accept", "text/html")
|
||||||
router.ServeHTTP(recorder, req)
|
router.ServeHTTP(recorder, req)
|
||||||
assert.Equal(t, recorder.Code, http.StatusUnauthorized)
|
|
||||||
|
|
||||||
// Test logged in user traefik/caddy (forward_auth)
|
assert.Equal(t, 307, recorder.Code)
|
||||||
router, recorder = setupProxyController(t, []gin.HandlerFunc{
|
assert.Equal(t, "http://localhost:8080/login?redirect_uri=https%3A%2F%2Fexample.com%2Fsomepath", recorder.Header().Get("Location"))
|
||||||
|
|
||||||
|
// Test logged out user (envoy - POST method)
|
||||||
|
recorder = httptest.NewRecorder()
|
||||||
|
req = httptest.NewRequest("POST", "/api/auth/envoy", nil)
|
||||||
|
req.Header.Set("X-Forwarded-Proto", "https")
|
||||||
|
req.Header.Set("X-Forwarded-Host", "example.com")
|
||||||
|
req.Header.Set("X-Forwarded-Uri", "/somepath")
|
||||||
|
req.Header.Set("Accept", "text/html")
|
||||||
|
router.ServeHTTP(recorder, req)
|
||||||
|
|
||||||
|
assert.Equal(t, 307, recorder.Code)
|
||||||
|
assert.Equal(t, "http://localhost:8080/login?redirect_uri=https%3A%2F%2Fexample.com%2Fsomepath", recorder.Header().Get("Location"))
|
||||||
|
|
||||||
|
// Test logged out user (envoy - DELETE method)
|
||||||
|
recorder = httptest.NewRecorder()
|
||||||
|
req = httptest.NewRequest("DELETE", "/api/auth/envoy", nil)
|
||||||
|
req.Header.Set("X-Forwarded-Proto", "https")
|
||||||
|
req.Header.Set("X-Forwarded-Host", "example.com")
|
||||||
|
req.Header.Set("X-Forwarded-Uri", "/somepath")
|
||||||
|
req.Header.Set("Accept", "text/html")
|
||||||
|
router.ServeHTTP(recorder, req)
|
||||||
|
|
||||||
|
assert.Equal(t, 307, recorder.Code)
|
||||||
|
assert.Equal(t, "http://localhost:8080/login?redirect_uri=https%3A%2F%2Fexample.com%2Fsomepath", recorder.Header().Get("Location"))
|
||||||
|
|
||||||
|
// Test logged out user (nginx)
|
||||||
|
recorder = httptest.NewRecorder()
|
||||||
|
req = httptest.NewRequest("GET", "/api/auth/nginx", nil)
|
||||||
|
req.Header.Set("X-Forwarded-Proto", "https")
|
||||||
|
req.Header.Set("X-Forwarded-Host", "example.com")
|
||||||
|
// we won't set X-Forwarded-Uri to test that the controller can work without it
|
||||||
|
router.ServeHTTP(recorder, req)
|
||||||
|
|
||||||
|
assert.Equal(t, 401, recorder.Code)
|
||||||
|
|
||||||
|
// Test logged in user
|
||||||
|
router, recorder, _ = setupProxyController(t, &[]gin.HandlerFunc{
|
||||||
func(c *gin.Context) {
|
func(c *gin.Context) {
|
||||||
c.Set("context", &loggedInCtx)
|
c.Set("context", &config.UserContext{
|
||||||
|
Username: "testuser",
|
||||||
|
Name: "testuser",
|
||||||
|
Email: "testuser@example.com",
|
||||||
|
IsLoggedIn: true,
|
||||||
|
OAuth: false,
|
||||||
|
Provider: "local",
|
||||||
|
TotpPending: false,
|
||||||
|
OAuthGroups: "",
|
||||||
|
TotpEnabled: false,
|
||||||
|
})
|
||||||
c.Next()
|
c.Next()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/traefik", nil)
|
req = httptest.NewRequest("GET", "/api/auth/traefik", nil)
|
||||||
assert.NilError(t, err)
|
req.Header.Set("X-Forwarded-Proto", "https")
|
||||||
|
req.Header.Set("X-Forwarded-Host", "example.com")
|
||||||
req.Header.Set("x-forwarded-host", "whoami.example.com")
|
req.Header.Set("X-Original-Uri", "/somepath") // Test with original URI for kubernetes ingress
|
||||||
req.Header.Set("x-forwarded-proto", "http")
|
req.Header.Set("Accept", "text/html")
|
||||||
req.Header.Set("x-forwarded-uri", "/")
|
|
||||||
|
|
||||||
router.ServeHTTP(recorder, req)
|
router.ServeHTTP(recorder, req)
|
||||||
assert.Equal(t, recorder.Code, http.StatusOK)
|
assert.Equal(t, 200, recorder.Code)
|
||||||
|
|
||||||
// Test logged in user nginx (auth_request)
|
assert.Equal(t, "testuser", recorder.Header().Get("Remote-User"))
|
||||||
router, recorder = setupProxyController(t, []gin.HandlerFunc{
|
assert.Equal(t, "testuser", recorder.Header().Get("Remote-Name"))
|
||||||
func(c *gin.Context) {
|
assert.Equal(t, "testuser@example.com", recorder.Header().Get("Remote-Email"))
|
||||||
c.Set("context", &loggedInCtx)
|
|
||||||
c.Next()
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/nginx", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
req.Header.Set("x-original-url", "http://whoami.example.com/")
|
|
||||||
|
|
||||||
router.ServeHTTP(recorder, req)
|
|
||||||
assert.Equal(t, recorder.Code, http.StatusOK)
|
|
||||||
|
|
||||||
// Test logged in user envoy (ext_authz)
|
|
||||||
router, recorder = setupProxyController(t, []gin.HandlerFunc{
|
|
||||||
func(c *gin.Context) {
|
|
||||||
c.Set("context", &loggedInCtx)
|
|
||||||
c.Next()
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/envoy?path=/", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
req.Host = "whoami.example.com"
|
|
||||||
req.Header.Set("x-forwarded-proto", "http")
|
|
||||||
|
|
||||||
router.ServeHTTP(recorder, req)
|
|
||||||
assert.Equal(t, recorder.Code, http.StatusOK)
|
|
||||||
|
|
||||||
// Test ACL allow caddy/traefik (forward_auth)
|
|
||||||
router, recorder = setupProxyController(t, nil)
|
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/traefik", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
req.Header.Set("x-forwarded-host", "whoami.example.com")
|
|
||||||
req.Header.Set("x-forwarded-proto", "http")
|
|
||||||
req.Header.Set("x-forwarded-uri", "/allow")
|
|
||||||
|
|
||||||
router.ServeHTTP(recorder, req)
|
|
||||||
assert.Equal(t, recorder.Code, http.StatusOK)
|
|
||||||
|
|
||||||
// Test ACL allow nginx
|
|
||||||
router, recorder = setupProxyController(t, nil)
|
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/nginx", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
req.Header.Set("x-original-url", "http://whoami.example.com/allow")
|
|
||||||
|
|
||||||
router.ServeHTTP(recorder, req)
|
|
||||||
assert.Equal(t, recorder.Code, http.StatusOK)
|
|
||||||
|
|
||||||
// Test ACL allow envoy
|
|
||||||
router, recorder = setupProxyController(t, nil)
|
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/envoy?path=/allow", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
req.Host = "whoami.example.com"
|
|
||||||
req.Header.Set("x-forwarded-proto", "http")
|
|
||||||
|
|
||||||
router.ServeHTTP(recorder, req)
|
|
||||||
assert.Equal(t, recorder.Code, http.StatusOK)
|
|
||||||
|
|
||||||
// Test traefik/caddy (forward_auth) without required headers
|
|
||||||
router, recorder = setupProxyController(t, nil)
|
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/traefik", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
router.ServeHTTP(recorder, req)
|
|
||||||
assert.Equal(t, recorder.Code, http.StatusBadRequest)
|
|
||||||
|
|
||||||
// Test nginx (forward_auth) without required headers
|
|
||||||
router, recorder = setupProxyController(t, nil)
|
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/nginx", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
router.ServeHTTP(recorder, req)
|
|
||||||
assert.Equal(t, recorder.Code, http.StatusBadRequest)
|
|
||||||
|
|
||||||
// Test envoy (forward_auth) without required headers
|
|
||||||
router, recorder = setupProxyController(t, nil)
|
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/envoy", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
router.ServeHTTP(recorder, req)
|
|
||||||
assert.Equal(t, recorder.Code, http.StatusBadRequest)
|
|
||||||
|
|
||||||
// Test nginx (auth_request) with forward_auth fallback with ACLs
|
|
||||||
router, recorder = setupProxyController(t, nil)
|
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/nginx", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
req.Header.Set("x-forwarded-host", "whoami.example.com")
|
|
||||||
req.Header.Set("x-forwarded-proto", "http")
|
|
||||||
req.Header.Set("x-forwarded-uri", "/allow")
|
|
||||||
|
|
||||||
router.ServeHTTP(recorder, req)
|
|
||||||
assert.Equal(t, recorder.Code, http.StatusOK)
|
|
||||||
|
|
||||||
// Test envoy (ext_authz) with forward_auth fallback with ACLs
|
|
||||||
router, recorder = setupProxyController(t, nil)
|
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/envoy", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
req.Header.Set("x-forwarded-host", "whoami.example.com")
|
|
||||||
req.Header.Set("x-forwarded-proto", "http")
|
|
||||||
req.Header.Set("x-forwarded-uri", "/allow")
|
|
||||||
|
|
||||||
router.ServeHTTP(recorder, req)
|
|
||||||
assert.Equal(t, recorder.Code, http.StatusOK)
|
|
||||||
|
|
||||||
// Test envoy (ext_authz) with empty path
|
|
||||||
router, recorder = setupProxyController(t, nil)
|
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/envoy", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
req.Host = "whoami.example.com"
|
|
||||||
req.Header.Set("x-forwarded-proto", "http")
|
|
||||||
|
|
||||||
router.ServeHTTP(recorder, req)
|
|
||||||
assert.Equal(t, recorder.Code, http.StatusUnauthorized)
|
|
||||||
|
|
||||||
// Ensure forward_auth fallback works with path (should ignore)
|
|
||||||
router, recorder = setupProxyController(t, nil)
|
|
||||||
|
|
||||||
req, err = http.NewRequest("GET", "/api/auth/traefik?path=/allow", nil)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
req.Header.Set("x-forwarded-proto", "http")
|
|
||||||
req.Header.Set("x-forwarded-host", "whoami.example.com")
|
|
||||||
req.Header.Set("x-forwarded-uri", "/allow")
|
|
||||||
|
|
||||||
router.ServeHTTP(recorder, req)
|
|
||||||
assert.Equal(t, recorder.Code, http.StatusOK)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user