-
-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for X-Forwarded-Proto header (#665)
Closes #153
- Loading branch information
Showing
10 changed files
with
287 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//go:build tools | ||
// +build tools | ||
|
||
package main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
serve: | ||
api: | ||
port: 6061 | ||
proxy: | ||
port: 6060 | ||
|
||
access_rules: | ||
repositories: | ||
- file://./rules.1.json | ||
|
||
authenticators: | ||
noop: | ||
enabled: true | ||
anonymous: | ||
enabled: true | ||
|
||
authorizers: | ||
allow: | ||
enabled: true | ||
deny: | ||
enabled: true | ||
|
||
mutators: | ||
noop: | ||
enabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[ | ||
{ | ||
"id": "test-rule-http", | ||
"upstream": { | ||
"url": "https://httpbin.org/anything/" | ||
}, | ||
"match": { | ||
"url": "http://127.0.0.1:6060/http", | ||
"methods": [ | ||
"GET" | ||
] | ||
}, | ||
"authenticators": [ | ||
{ | ||
"handler": "noop" | ||
} | ||
], | ||
"authorizer": { | ||
"handler": "allow" | ||
}, | ||
"mutators": [ | ||
{ | ||
"handler": "noop" | ||
} | ||
] | ||
}, | ||
{ | ||
"id": "test-rule-https", | ||
"upstream": { | ||
"url": "https://httpbin.org/anything/" | ||
}, | ||
"match": { | ||
"url": "https://127.0.0.1:6060/https", | ||
"methods": [ | ||
"GET" | ||
] | ||
}, | ||
"authenticators": [ | ||
{ | ||
"handler": "noop" | ||
} | ||
], | ||
"authorizer": { | ||
"handler": "allow" | ||
}, | ||
"mutators": [ | ||
{ | ||
"handler": "noop" | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
waitport() { | ||
i=0 | ||
while ! nc -z localhost "$1" ; do | ||
sleep 1 | ||
if [ $i -gt 10 ]; then | ||
cat ./config.yaml | ||
cat ./oathkeeper.log | ||
exit 1 | ||
fi | ||
i=$((i+1)) | ||
done | ||
} | ||
|
||
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
|
||
export GO111MODULE=on | ||
|
||
(cd ../../; make install) | ||
|
||
run_oathkekeper() { | ||
killall oathkeeper || true | ||
|
||
export OATHKEEPER_PROXY=http://127.0.0.1:6060 | ||
export OATHKEEPER_API=http://127.0.0.1:6061 | ||
|
||
LOG_LEVEL=debug oathkeeper --config ./config.yaml serve >> ./oathkeeper.log 2>&1 & | ||
|
||
waitport 6060 | ||
waitport 6061 | ||
} | ||
|
||
make_request() { | ||
url=$1 | ||
expected_status_code=$2 | ||
shift 2 | ||
|
||
[[ $(curl --silent --output /dev/null -f ${url} -w '%{http_code}' "$@") -eq $expected_status_code ]] | ||
} | ||
|
||
SUCCESS_TEST=() | ||
FAILED_TEST=() | ||
|
||
run_test() { | ||
label=$1 | ||
shift 1 | ||
|
||
result="0" | ||
"$@" || result="1" | ||
|
||
if [[ "$result" -eq "0" ]]; then | ||
SUCCESS_TEST+=("$label") | ||
else | ||
FAILED_TEST+=("$label") | ||
fi | ||
} | ||
|
||
function finish { | ||
cat ./config.yaml | ||
cat ./rules.1.json | ||
cat ./oathkeeper.log | ||
} | ||
trap finish EXIT | ||
|
||
run_oathkekeper | ||
|
||
run_test "Executing request against a HTTP rule -> 200" \ | ||
make_request "http://127.0.0.1:6060/http" 200 | ||
|
||
run_test "Executing request against a HTTP rule with forwrded proto HTTP -> 200" \ | ||
make_request "http://127.0.0.1:6060/http" 200 -H "X-Forwarded-Proto: http" | ||
|
||
run_test "Executing request against a HTTP rule with forwrded proto HTTPS -> 404" \ | ||
make_request "http://127.0.0.1:6060/http" 404 -H "X-Forwarded-Proto: https" | ||
|
||
run_test "Executing request against a HTTPS rule -> 404" \ | ||
make_request "http://127.0.0.1:6060/https" 404 | ||
|
||
run_test "Executing request against a HTTPS rule with forwarded proto HTTP -> 404" \ | ||
make_request "http://127.0.0.1:6060/https" 404 -H "X-Forwarded-Proto: http" | ||
|
||
run_test "Executing request against a HTTPS rule with forwarded proto HTTPS -> 200" \ | ||
make_request "http://127.0.0.1:6060/https" 200 -H "X-Forwarded-Proto: https" | ||
|
||
|
||
echo "PASS: ${#SUCCESS_TEST[@]}" | ||
for value in "${SUCCESS_TEST[@]}" | ||
do | ||
echo "- $value" | ||
done | ||
|
||
if [[ "${#FAILED_TEST[@]}" -gt 0 ]]; then | ||
echo "FAILED: ${#FAILED_TEST[@]}" | ||
for value in "${FAILED_TEST[@]}" | ||
do | ||
echo "- $value" | ||
done | ||
|
||
exit 1 | ||
fi | ||
|
||
kill %1 || true | ||
|
||
trap - EXIT |