-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Authenticate an exchanged token #2070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
istio-testing
merged 12 commits into
istio:release-1.1
from
lei-tang:merge-authn-exchanged-token-release-1.1
Dec 21, 2018
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e3f0b66
Authenticate an exchanged token
lei-tang a27974f
Change issuer name and jwt-authn output with key being original issuer
lei-tang 68be7c1
Revised the code based on the discussion
lei-tang 586c9ee
Address review comments and add a test
lei-tang c7931e3
Address new review comments
lei-tang 8315ce4
Add integration tests and address review comments
lei-tang ef1629f
Fix a flaky test and address new review comments
lei-tang 7dfb399
Small grammar fixes
lei-tang 8026dba
Revise the function of finding the token header
lei-tang e2ddef6
Use case-insensitive compare for the header name
lei-tang 32ebbb6
Change the name of a variable
lei-tang a505e9d
Revise log statements
lei-tang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -27,6 +27,10 @@ namespace AuthN { | |
| namespace { | ||
| // The JWT audience key name | ||
| static const std::string kJwtAudienceKey = "aud"; | ||
| // The JWT issuer key name | ||
| static const std::string kJwtIssuerKey = "iss"; | ||
| // The key name for the APToken original claims | ||
| static const std::string kAPTokenOriginalPayload = "original_claims"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we change the name to avoid "APToken", or explain in the comment that this is exchanged token?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
|
||
| // Extract JWT claim as a string list. | ||
| // This function only extracts string and string list claims. | ||
|
|
@@ -100,6 +104,34 @@ bool AuthnUtils::ProcessJwtPayload(const std::string& payload_str, | |
| return true; | ||
| } | ||
|
|
||
| bool AuthnUtils::ExtractOriginalPayload(const std::string& token, | ||
| std::string* original_payload) { | ||
| Envoy::Json::ObjectSharedPtr json_obj; | ||
| try { | ||
| json_obj = Json::Factory::loadFromString(token); | ||
| } catch (...) { | ||
| return false; | ||
| } | ||
|
|
||
| if (json_obj->hasObject(kAPTokenOriginalPayload) == false) { | ||
| return false; | ||
| } | ||
|
|
||
| Envoy::Json::ObjectSharedPtr original_payload_obj; | ||
| try { | ||
| auto original_payload_obj = json_obj->getObject(kAPTokenOriginalPayload); | ||
| *original_payload = original_payload_obj->asJsonString(); | ||
| ENVOY_LOG(debug, "{}: the original payload in APToken is {}", __FUNCTION__, | ||
| *original_payload); | ||
| } catch (...) { | ||
| ENVOY_LOG(debug, "{}: original_payload in APToken is of invalid format.", | ||
| __FUNCTION__); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| bool AuthnUtils::MatchString(const char* const str, | ||
| const iaapi::StringMatch& match) { | ||
| if (str == nullptr) { | ||
|
|
||
This file contains hidden or 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 hidden or 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 @@ | ||
| eyJhbGciOiJSUzI1NiIsImtpZCI6IkRIRmJwb0lVcXJZOHQyenBBMnFYZkNtcjVWTzVaRXI0UnpIVV8tZW52dlEiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJleGFtcGxlLWF1ZGllbmNlIiwiZW1haWwiOiJmb29AZ29vZ2xlLmNvbSIsImV4cCI6NDY5ODM2MTUwOCwiaWF0IjoxNTQ0NzYxNTA4LCJpc3MiOiJodHRwczovL2V4YW1wbGUudG9rZW5fc2VydmljZS5jb20iLCJpc3Rpb19hdHRyaWJ1dGVzIjpbeyJzb3VyY2UuaXAiOiIxMjcuMC4wLjEifV0sImtleTEiOlsidmFsMiIsInZhbDMiXSwib3JpZ2luYWxfY2xhaW1zIjp7ImVtYWlsIjoidXNlckBleGFtcGxlLmNvbSIsImlzcyI6Imh0dHBzOi8vYWNjb3VudHMuZXhhbXBsZS5jb20iLCJzdWIiOiJleGFtcGxlLXN1YmplY3QifSwic3ViIjoiaHR0cHM6Ly9hY2NvdW50cy5leGFtcGxlLmNvbS8xMjM0NTU2Nzg5MCJ9.mLm9Gmcd748anwybiPxGPEuYgJBChqoHkVOvRhQN-H9jMqVKyF-7ynud1CJp5n72VeMB1FzvKAV0ErzSyWQc0iofQywG6whYXP6zL-Oc0igUrLDvzb6PuBDkbWOcZrvHkHM4tIYAkF4j880GqMWEP3gGrykziIEY9g4povquCFSdkLjjyol2-Ge_6MFdayYoeWLLOaMP7tHiPTm_ajioQ4jcz5whBWu3DZWx4IuU5UIBYlHG_miJZv5zmwwQ60T1_p_sW7zkABJgDhCvu6cHh6g-hZdQvZbATFwMfN8VDzttTjRG8wuLlkQ1TTOCx5PDv-_gHfQfRWt8Z94HrIJPuQ |
This file contains hidden or 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,118 @@ | ||
| { | ||
| "admin": { | ||
| "access_log_path": "/dev/stdout", | ||
| "address": { | ||
| "socket_address": { | ||
| "address": "0.0.0.0", | ||
| "port_value": 9001 | ||
| } | ||
| } | ||
| }, | ||
| "static_resources": { | ||
| "clusters": [ | ||
| { | ||
| "name": "service1", | ||
| "connect_timeout": "5s", | ||
| "type": "STATIC", | ||
| "hosts": [ | ||
| { | ||
| "socket_address": { | ||
| "address": "0.0.0.0", | ||
| "port_value": 8080 | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "listeners": [ | ||
| { | ||
| "name": "server", | ||
| "address": { | ||
| "socket_address": { | ||
| "address": "0.0.0.0", | ||
| "port_value": 9090 | ||
| } | ||
| }, | ||
| "filter_chains": [ | ||
| { | ||
| "filters": [ | ||
| { | ||
| "name": "envoy.http_connection_manager", | ||
| "config": { | ||
| "codec_type": "AUTO", | ||
| "stat_prefix": "inbound_http", | ||
| "access_log": [ | ||
| { | ||
| "name": "envoy.file_access_log", | ||
| "config": { | ||
| "path": "/tmp/envoy-access.log" | ||
| } | ||
| } | ||
| ], | ||
| "http_filters": [ | ||
| { | ||
| "name": "jwt-auth", | ||
| "config": { | ||
| "rules": [ | ||
| { | ||
| "issuer": "https://example.token_service.com", | ||
| "local_jwks": { | ||
| "inline_string": "{ \"keys\":[ {\"e\":\"AQAB\",\"kid\":\"DHFbpoIUqrY8t2zpA2qXfCmr5VO5ZEr4RzHU_-envvQ\",\"kty\":\"RSA\",\"n\":\"xAE7eB6qugXyCAG3yhh7pkDkT65pHymX-P7KfIupjf59vsdo91bSP9C8H07pSAGQO1MV_xFj9VswgsCg4R6otmg5PV2He95lZdHtOcU5DXIg_pbhLdKXbi66GlVeK6ABZOUW3WYtnNHD-91gVuoeJT_DwtGGcp4ignkgXfkiEm4sw-4sfb4qdt5oLbyVpmW6x9cfa7vs2WTfURiCrBoUqgBo_-4WTiULmmHSGZHOjzwa8WtrtOQGsAFjIbno85jp6MnGGGZPYZbDAa_b3y5u-YpW7ypZrvD8BgtKVjgtQgZhLAGezMt0ua3DRrWnKqTZ0BJ_EyxOGuHJrLsn00fnMQ\"}]}", | ||
| }, | ||
| "from_headers": [{"name": "ingress-authorization"}], | ||
| "forward_payload_header": "test-jwt-payload-output" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "name":"istio_authn", | ||
| "config":{ | ||
| "policy":{ | ||
| "origins":[ | ||
| { | ||
| "jwt":{ | ||
| "issuer":"https://example.token_service.com", | ||
| "jwt_headers":["ingress-authorization"] | ||
| } | ||
| } | ||
| ], | ||
| "principal_binding":1 | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "name": "envoy.router" | ||
| } | ||
| ], | ||
| "route_config": { | ||
| "name": "backend", | ||
| "virtual_hosts": [ | ||
| { | ||
| "name": "backend", | ||
| "domains": [ | ||
| "*" | ||
| ], | ||
| "routes": [ | ||
| { | ||
| "match": { | ||
| "prefix": "/" | ||
| }, | ||
| "route": { | ||
| "cluster": "service1", | ||
| "timeout": "0s" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } |
This file contains hidden or 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,18 @@ | ||
| This is a guide of sending an example exchanged token to | ||
| the jwt-authn filter and the Istio authn filter, and observing | ||
| that the example backend echoes back the request when | ||
| the authentication succeeds. | ||
|
|
||
| 1. Open a terminal, go to the root directory of the istio-proxy repository. | ||
| Start the example backend: | ||
| go run test/backend/echo/echo.go | ||
|
|
||
| 2. Build the Istio proxy and run the proxy with the config for authenticating | ||
| an example exchanged token. | ||
| bazel build //src/envoy:envoy | ||
| bazel-bin/src/envoy/envoy -l debug -c src/envoy/http/jwt_auth/sample/APToken/aptoken-envoy.conf | ||
|
|
||
| 3. Open a terminal, go to the root directory of the istio-proxy repository. | ||
| Send a request with the example exchanged token. | ||
| export token=$(cat src/envoy/http/jwt_auth/sample/APToken/APToken-example1.jwt) | ||
| curl --header "ingress-authorization:$token" http://localhost:9090/echo -d "hello world" |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just return this condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.