You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@impala.apache.org by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org> on 2021/05/13 00:18:03 UTC

[Impala-ASF-CR] [WIP] IMPALA-10489: Implement JWT support

Wenzhe Zhou has uploaded this change for review. ( http://gerrit.cloudera.org:8080/17435


Change subject: [WIP] IMPALA-10489: Implement JWT support
......................................................................

[WIP] IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.
 * Add unit-test for loading JWKS file and verifying JWT token.

 * TODO add more unit tests:
     FE custom cluster test for JWT authentication

Testing:
 - TODO.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/service/impala-server.h
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
11 files changed, 927 insertions(+), 9 deletions(-)



  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/1
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 1
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Joe McDonnell (Code Review)" <ge...@cloudera.org>.
Joe McDonnell has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 18:

(4 comments)

Thanks for getting those tests working! This is looking great. I only have a couple nits. 

I think it would be useful to do a core run with this change with the Address Sanitizer if you haven't already.

I'm going to kick off a precommit run on this just to see if anything crops up.

http://gerrit.cloudera.org:8080/#/c/17435/18/be/src/util/jwt-util-internal.h
File be/src/util/jwt-util-internal.h:

http://gerrit.cloudera.org:8080/#/c/17435/18/be/src/util/jwt-util-internal.h@215
PS18, Line 215:   JWTPublicKeyMap hs_key_map_;
Nit: I think we have a memory leak with these JWTPublicKeyMap types. The JWTPublicKey*'s are allocated with new in CreateJWTPublicKey(), but there isn't any code to free them (the unordered_map doesn't free raw pointers in its destructor).

For our purposes in the Impala daemon, that isn't a big deal, because this lives for the lifetime of the instance anyway. However, our backend tests run with LeakSanitizer when using the ASAN configuration, so I'm thinking this will trip that up. See IMPALA-2746. You can test that quickly by compiling with ASAN and running the jwt-util-test. 

I think it is worth solving the leak. One option is to write a destructor for JsonWebKeySet that frees everything appropriately. The other option is to use unique_ptr rather than a raw pointer in JWTPublicKeyMap. I would lean towards unique_ptr (which I think would involve using emplace rather than insert for the map).


http://gerrit.cloudera.org:8080/#/c/17435/18/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/18/be/src/util/jwt-util.cc@134
PS18, Line 134: kv_map.insert(make_pair(k, v));
Nit: Is there any chance that there could be duplicate k's? unordered_map::insert() will just keep the current entry if we try to insert a key that already exists. This is an edge case for a malformed JWKS. I think what we are doing is reasonable, but I'm wondering if we want to print any sort of warning. Maybe the JSON library already validates this?


http://gerrit.cloudera.org:8080/#/c/17435/18/be/src/util/jwt-util.cc@410
PS18, Line 410: rsa_pub_key_map_.insert(make_pair(key_id, jwk_pub_key));
Nit: Do we need any handling for duplicate key_id's for the same algorithm? unordered_map::insert() will just keep the current entry, but it can return whether it actually inserted an entry into the map. This is an edge case for malformed JWKS files, but do we want to print some kind of warning?


http://gerrit.cloudera.org:8080/#/c/17435/18/be/src/util/jwt-util.cc@448
PS18, Line 448: jwks_.get()->Init
Nit: unique_ptr behaves just like a regular pointer for ordinary code. It implements the -> operator, so you don't need to call .get() to fetch the pointer. You can do jwks_->Init(jwks_file_path) directly. Similarly, unique_ptr implements the == operators, so you can compare a unique_ptr directly with nullptr (i.e. jwks_ == nullptr) without calling .get().

So, for style reasons, use a unique_ptr just like a regular pointer (i.e. without .get()), unless it is really necessary. Please apply this across the board.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 18
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Wed, 07 Jul 2021 22:57:29 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 19:

Build started: https://jenkins.impala.io/job/gerrit-verify-dryrun/7280/ DRY_RUN=false


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 19
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 08 Jul 2021 17:02:52 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 6:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/8763/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 6
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Comment-Date: Thu, 20 May 2021 22:09:15 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Joe McDonnell (Code Review)" <ge...@cloudera.org>.
Joe McDonnell has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 12:

This would be easier to review if we stick to the original level of functionality (i.e. RSA only). The non-RSA algorithms are useful, but I would rather review them as a follow-on patch.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 12
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Wed, 23 Jun 2021 20:02:23 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 8:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/17435/6/be/src/transport/THttpServer.cpp
File be/src/transport/THttpServer.cpp:

http://gerrit.cloudera.org:8080/#/c/17435/6/be/src/transport/THttpServer.cpp@286
PS6, Line 286:       resetAuthState();
             :       returnUnauthorized();
             :       throw TTransportException("HTTP auth failed.");
             :     }
             :   }
             : 
             :   if (!authorized && use_jwt_token_ && !auth_value_.empty()
             :       && auth_value_.find('.') != string::npos) {
             :     // Check Authorization header with the Bearer authentication scheme as:
             :     // Authorization: Bearer <token>
             :     // A well-formed JWT consists of three concatenated Base64url-encoded strings,
             :     // se
> Thanks for capturing this case. SAML2 token is base64 encoded XML and shoul
Discussed with Vihang. SAML Bearer token is generated by Impala code after the SAML auth flow is completed. Technically we could generate a JWT instead of our current implementation of the token at the end of SAML flow. Since Impala supports multiple auth mechanism in parallel, in theory we can have SAML and JWT configured simultaneously. So it's better to fall back to JWT verification after SAML verification fails.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 8
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Sat, 22 May 2021 01:01:53 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Joe McDonnell (Code Review)" <ge...@cloudera.org>.
Joe McDonnell has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 11:

Thanks for adding the other algorithms and cleaning this up. I'm making my way through.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 11
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Tue, 22 Jun 2021 22:41:13 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 13:

(3 comments)

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.h
File be/src/util/jwt-util.h:

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.h@113
PS13, Line 113:   /// Opaque types for storing the pointer to JWT decoded token. This allows us to
              :   /// avoid including header file jwt-cpp/jwt.h.
              :   struct JWTDecodedTokenPtr;
              :   JWTDecodedTokenPtr* decoded_token_;
> The other thought is that jwt-util.h is not included in any other header fi
The unique_ptr is working with custom deleter and put deleter "operator()" function in jwt-util.cc. 

I perfer not to include jwt.h in jwt-util.h to avoid spreading the header inclusions. One reason is jwt.h is too big. Another reason is that picojson/picojson.h, which is included by jwt.h, defines __STDC_FORMAT_MACROS without checking if it's already defined. This causes build failure. The work around is to undef__STDC_FORMAT_MACROS before including jwt.h in .cc file as below:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreserved-id-macro"
// picojson/picojson.h which is included by jwt-cpp/jwt.h defines __STDC_FORMAT_MACROS
// without checking if it's already defined so un-define the micro here to avoid
// re-definition error. Also need to hide warning "macro name is a reserved identifier".
#ifdef __STDC_FORMAT_MACROS
#undef __STDC_FORMAT_MACROS
#endif
#include <jwt-cpp/jwt.h>
#pragma clang diagnostic pop


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@290
PS9, Line 290:  rapidjson::FileReadStream stream(jwks_file, readBuffer, sizeof(readBuffer));
             :   Document jwks_doc;
             :   jwks_doc.ParseStream(stream);
             :   fclose(jwks_file);
             :   if (jwks_doc.HasParseError()) {
             :     return Status(
             :         TErrorCode::JWKS_PARSE_ERROR, GetParseError_En(jwks_doc.GetParseError()));
             :   }
             :   if (!jwks_doc.IsObject()) {
             :     return Status(TErrorCode::JWKS_PARSE_ERROR, "root element must be a JSON Object");
             :   }
             :   if (!jwks_doc.HasMember("keys")) {
             :     return Status(TErrorCode::JWKS_PARSE_ERROR, "keys is required");
             :   }
             : 
> For this review, I would like the piece that folds the JWTVerifier and JWKS
There is an unordered_map in jwt::virifier class. The map is used to save claims, like "iss", etc. Before calling jwt::virifier::verify() function, we could call jwt::virifier::with_issuer(issuer) to set issuer from JWT. This function seems not thread safe. If requests with different issuers could overwrite each other.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@290
PS9, Line 290:  rapidjson::FileReadStream stream(jwks_file, readBuffer, sizeof(readBuffer));
             :   Document jwks_doc;
             :   jwks_doc.ParseStream(stream);
             :   fclose(jwks_file);
             :   if (jwks_doc.HasParseError()) {
             :     return Status(
             :         TErrorCode::JWKS_PARSE_ERROR, GetParseError_En(jwks_doc.GetParseError()));
             :   }
             :   if (!jwks_doc.IsObject()) {
             :     return Status(TErrorCode::JWKS_PARSE_ERROR, "root element must be a JSON Object");
             :   }
             :   if (!jwks_doc.HasMember("keys")) {
             :     return Status(TErrorCode::JWKS_PARSE_ERROR, "keys is required");
             :   }
             : 
> https://stackoverflow.com/a/17950450 - this shows a way to use deleters tha
I defined the custom deleter in the same way and it's working.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 13
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 24 Jun 2021 22:07:25 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 19:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/9050/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 19
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 08 Jul 2021 02:02:43 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#9). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/service/impala-server.h
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
M fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
M fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
A testdata/jwt/jwks_rs256.json
22 files changed, 1,502 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/9
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 9
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 10:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/8932/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 10
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Wed, 16 Jun 2021 01:30:34 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] [WIP] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#3). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: [WIP] IMPALA-10489: Implement JWT support
......................................................................

[WIP] IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added unit-tests for loading JWKS file and verifying JWT token.

TODO:
  Add more unit tests, including FE custom cluster test for JWT
  authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/service/impala-server.h
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
16 files changed, 1,157 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/3
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 3
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#19). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with public key in JWKS.
 * Get the username out of the payload of JWT token.
 * Support following JSON Web Algorithms (JWA):
   HS256, HS384, HS512, RS256, RS384, RS512.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchain.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/auth-provider.h
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-internal.h
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
A fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
A fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
M fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
M fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
A testdata/jwt/jwks_rs256.json
25 files changed, 2,464 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/19
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 19
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 18: Verified+1


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 18
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 08 Jul 2021 05:28:15 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 13:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/8987/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 13
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Wed, 23 Jun 2021 22:25:47 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Joe McDonnell (Code Review)" <ge...@cloudera.org>.
Joe McDonnell has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 13:

(3 comments)

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.h
File be/src/util/jwt-util.h:

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.h@113
PS13, Line 113:   /// Opaque types for storing the pointer to JWT decoded token. This allows us to
              :   /// avoid including header file jwt-cpp/jwt.h.
              :   struct JWTDecodedTokenPtr;
              :   JWTDecodedTokenPtr* decoded_token_;
> The unique_ptr is working with custom deleter and put deleter "operator()" 
I'm glad that is working. It is better to hide the jwt.h.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@290
PS9, Line 290:  rapidjson::FileReadStream stream(jwks_file, readBuffer, sizeof(readBuffer));
             :   Document jwks_doc;
             :   jwks_doc.ParseStream(stream);
             :   fclose(jwks_file);
             :   if (jwks_doc.HasParseError()) {
             :     return Status(
             :         TErrorCode::JWKS_PARSE_ERROR, GetParseError_En(jwks_doc.GetParseError()));
             :   }
             :   if (!jwks_doc.IsObject()) {
             :     return Status(TErrorCode::JWKS_PARSE_ERROR, "root element must be a JSON Object");
             :   }
             :   if (!jwks_doc.HasMember("keys")) {
             :     return Status(TErrorCode::JWKS_PARSE_ERROR, "keys is required");
             :   }
             : 
> There is an unordered_map in jwt::virifier class. The map is used to save c
I added a separate comment at the location where we are doing issuer verification.

My basic thought is that any verification that we want to do requires known values from outside of any particular JWT, and those known values should be known at startup (for now).

The with_issuer() method is asking for the known-good value for the issuer, which shouldn't come from the JWT itself.

https://github.com/Thalhammer/jwt-cpp/blob/master/tests/TokenTest.cpp#L383


http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.cc@414
PS13, Line 414:     string issuer = decoded_token_->decoded_jwt_->get_issuer();
              :     verifier.with_issuer(issuer);
I think this piece of code may be a no-op.

A verifier is comparing a JWT to known values. The with_issuer and other with_* methods are providing known values.

Here were passing in the JWT's issuer value to the with_issuer, which I think means that the verify() method would compare this specified value to the JWT's issuer.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 13
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 24 Jun 2021 22:33:16 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#10). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/auth-provider.h
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/service/impala-server.h
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
A fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
A fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
A testdata/jwt/jwks_rs256.json
23 files changed, 1,852 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/10
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 10
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] [WIP] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: [WIP] IMPALA-10489: Implement JWT support
......................................................................


Patch Set 1:

Build Failed 

https://jenkins.impala.io/job/gerrit-code-review-checks/8712/ : Initial code review checks failed. See linked job for details on the failure.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 1
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Comment-Date: Thu, 13 May 2021 00:27:59 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Joe McDonnell (Code Review)" <ge...@cloudera.org>.
Joe McDonnell has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 13:

(4 comments)

Thanks for working on this, I wrote a big long comment that I wanted to let you think on.

I'm thinking about which items I want addressed in this patch and which can be addressed in followups.

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/rpc/authentication.cc
File be/src/rpc/authentication.cc:

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/rpc/authentication.cc@155
PS13, Line 155: DEFINE_bool(jwt_extract_username, true, "When true, extract username from JWT payload.");
              : // This specifies the custom claim in the JWT that contains the "username" for the
              : // session.
              : DEFINE_string(jwt_custom_claim_username, "username", "Custom claim 'username'");
Is there a use case where you have JWT authentication, but you don't get the username from the JWT?

If we aren't sure there is a use case, we could leave the verification in AuthManager::Init() without the jwt_extract_username. This is something we can always support later once someone specifically needs it.


http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.h
File be/src/util/jwt-util.h:

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.h@113
PS13, Line 113:   /// Opaque types for storing the pointer to JWT decoded token. This allows us to
              :   /// avoid including header file jwt-cpp/jwt.h.
              :   struct JWTDecodedTokenPtr;
              :   JWTDecodedTokenPtr* decoded_token_;
The current form is a pointer to a struct that contains a unique_ptr to the JWT type. Since unique_ptr doesn't need a complete type, an alternative would have a unique_ptr to an opaque struct:

struct JWTType;
unique_ptr<JWTType> decoded_token_;

Then, JWTType in the .cc file is just a struct that contains a single field:

// Modern C++ syntax that is similar to a typedef
using DecodedJWT = jwt::decoded_jwt<jwt::picojson_traits>;

struct JWTType {
  JWTType(const DecodedJWT& decoded_jwt)
   : decoded_jwt_(decoded_jwt)

  DecodedJWT decoded_jwt_;
}

That should remove a layer of pointers. (I haven't actually tried this, so YMMV.)

Alternatively, use a unique_ptr here rather than a plain pointer, which would save you the delete code.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@290
PS9, Line 290:  rapidjson::FileReadStream stream(jwks_file, readBuffer, sizeof(readBuffer));
             :   Document jwks_doc;
             :   jwks_doc.ParseStream(stream);
             :   fclose(jwks_file);
             :   if (jwks_doc.HasParseError()) {
             :     return Status(
             :         TErrorCode::JWKS_PARSE_ERROR, GetParseError_En(jwks_doc.GetParseError()));
             :   }
             :   if (!jwks_doc.IsObject()) {
             :     return Status(TErrorCode::JWKS_PARSE_ERROR, "root element must be a JSON Object");
             :   }
             :   if (!jwks_doc.HasMember("keys")) {
             :     return Status(TErrorCode::JWKS_PARSE_ERROR, "keys is required");
             :   }
             : 
> Changed code to create one verifier.
The thing I'm thinking about is caching the verifier so that it is initialized
once at startup and used for the lifetime of the daemon. At startup, when we've
read the JWKS, we know everything that we will need to know to construct all
of the verifiers. The verifiers are stateless, so you can use them for as many
JWTs as you want.

I'm going to put a full description of a bunch of different
things here, though this isn't really in context. I have no idea if the formatting is going to work out.

Suppose you had a single JWTHelper that exposed an interface somewhat like
the JWTVerifier, except that it is stateless and there is one for the entire
daemon. It would have a Decode function, a Verify function, and accessor
functions to get information out of the JWT.

class JWTHelper {
   Status Decode(string jwt);

   Status Verify(JWKS *jwks);

   ...

}

To make it stateless, it can't store the JWT in its body, so we would need some
way to return the JWT and not have it tied to the lifetime of the JWTHelper.
The JWT would be passed into Verify(). In other words, it would need to be something like:

class JWTHelper {
   struct JWT;
   static Status Decode(string jwt, unique_ptr<JWT>& jwt_out);

   Status Verify(const JWT& jwt, JWKS* jwks);

   ...
}

We don't need a full definition for the JWT struct in the header file, because unique_ptr
behaves like other pointers and doesn't need to know the size/layout of what it is pointing
to. (Same thing with references.) Verify() takes a const reference because it has no real
interest in the ownership of the JWT.

The JWTHelper is at the instance level and so is the JWKS, so you could merge them
to hide the implementation details of the JWKS. The client of this interface doesn't care
about how the server got its keys. It just cares that JWTs can be verified. Init() gets
called at startup:

class JWTHelper {
    Status Init(string jwks_filename);

    struct JWT;
    static Status Decode(string jwt, unique_ptr<JWT>& jwt_out);
    Status Verify(const JWT& jwt);

   ... methods to access JWT fields as needed ...
}

This hides the details from the authentication code.

For the verifier single initialization, Init() will produce some data structure that contains verifiers used
for Verify(). This may require separating verification of the signature from verification of other things. One way to do that is for each JWK to be a class that has a Verify() method:

class JWTPublicKey {
  public:
    Status Verify(const JWT& jwt);

    // Construct a JWK from the raw args for a JWK from a JWKS, works for any
    // algorithm (calls the right constructor under the covers).
    static Status InitJWKPublicKeyFromArgs(input args, unique_ptr<JWTPublicKey>& jwk_out);
}

// Exact classes is flexible, but the idea is that they
// are algorithm specific and inherit from JWTPublicKey. They would
// encapsulate the algorithm-specific details so that JWTHelper
// can deal with JWTPublicKey types without thinking about algorithms.
// Hopefully, keeping the algorithm stuff out of JWTHelper makes it easier to add new algorithms.
class RSA256JWTPublicKey : public JWTPublicKey {
  public:
    // Init function initializes the verifier from
    // the key info.
    Status Init(args);

    Status Verify(const JWT& jwt) override {
       // contents similar to existing VerifyJWTSignature
       // except tuned for one algorithm.
       // required to work correctly even if the JWT has a
       // different algorithm.
       if (jwt.algorithm != alg_) return Status("wrong alg");
       verifier_.verify(jwt);
    }

private:
   string alg_;
   verifier_type verifier_;
}

JWTHelper could organize these in a single JWTPublicKeyMap without regard for algorithms and then use it in JWTHelper::Verify().

unordered_map<string, JWTPublicKey> key_map_;

Status Verify(const JWT& jwt) {
   if (jwt.key_id specified) {
     auto key_map_it = key_map_.find(jwt.key_id);
     if (key_map_it != key_map_.end()) {
        return key_map_it->second.Verify(jwt);
     } else {
        return Status("no matching entry");
     }
   } else {
     Status status;
     for (auto const& jwk_pair : key_map_) {
        status = jwk_pair.second.Verify(jwt);
        if (status.ok()) return status;
     }
     return status;
   }
}

I hope this gives a good sketch of what I was thinking with keeping the verifier long term.


http://gerrit.cloudera.org:8080/#/c/17435/13/fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
File fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java:

http://gerrit.cloudera.org:8080/#/c/17435/13/fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java@60
PS13, Line 60:    String uri =
             :         String.format("ldap://localhost:%s", serverRule.getLdapServer().getPort());
             :     String dn = "cn=#UID,ou=Users,dc=myorg,dc=com";
             :     String ldapArgs = String.format("--enable_ldap_auth --ldap_uri='%s' "
             :             + "--ldap_bind_pattern='%s' --ldap_passwords_in_clear_ok %s ",
             :         uri, dn, extraArgs);
This JWT test is still enabling LDAP. I'm interested in also having a JWT test that uses JWT without LDAP. I think a version of this test with the LDAP pieces stripped out should do what we want.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 13
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 24 Jun 2021 02:31:54 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#17). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with public key in JWKS.
 * Get the username out of the payload of JWT token.
 * Support following JSON Web algorithms (JWA):
   HS256, HS384, HS512, RS256, RS384, RS512.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchain.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/auth-provider.h
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-internal.h
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
A fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
A fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
M fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
M fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
A testdata/jwt/jwks_rs256.json
25 files changed, 2,511 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/17
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 17
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 6:

(5 comments)

http://gerrit.cloudera.org:8080/#/c/17435/6/be/src/rpc/authentication.cc
File be/src/rpc/authentication.cc:

http://gerrit.cloudera.org:8080/#/c/17435/6/be/src/rpc/authentication.cc@135
PS6, Line 135: DEFINE_bool_hidden(saml2_allow_without_tls_debug_only, false,
             :     "When this configuration is set to true, Impala allows SAML2 authentication "
             :     "on unsecure channel. This should be only enabled for development / testing.");
> I think we should have a similar parameter for JWTs, because JWTs are only 
Done


http://gerrit.cloudera.org:8080/#/c/17435/6/be/src/rpc/authentication.cc@155
PS6, Line 155: // Authorization type for JWT token based authorization in HTTP header, for example
             : // "Authorization: Bearer <token>", or “Authorization: Bearer;token: <token_string>”.
             : DEFINE_string(
             :     jwt_auth_type, "Bearer", "Authorization type for JWT token based authorization");
             : // JWT token identifier in HTTP header. for example “token=<token_string>”.
             : DEFINE_string(jwt_token_identifier, "token", "JWT token identifier");
> We definitely want to support this standard authorization header:
I saw following statement in design doc "SSO Token based authentication in CDW": "This token is then used in the JDBC URL with authentication type set to “auth=token” and “token=<TOKEN_VALUE>” (exact semantics are TBD Action: for hive/impala teams)". I was thinking we got to support different formats. Did a search, it's standard to set JWT auth as "Authorization: Bearer <token>".
Removed jwt_auth_type and jwt_token_identifier.


http://gerrit.cloudera.org:8080/#/c/17435/6/be/src/rpc/authentication.cc@568
PS6, Line 568:   // Create a cookie to return.
             :   connection_context->return_headers.push_back(
             :       Substitute("Set-Cookie: $0", GenerateCookie(username, hash)));
> I'm wondering if we really need to exchange the JWT for a cookie. We defini
Agree, it's common to JWT with each request.
When discussed with Naveen last time, it's not clear if JWT will accompany each request. I will confirm with him.


http://gerrit.cloudera.org:8080/#/c/17435/6/be/src/transport/THttpServer.cpp
File be/src/transport/THttpServer.cpp:

http://gerrit.cloudera.org:8080/#/c/17435/6/be/src/transport/THttpServer.cpp@170
PS6, Line 170: #if 0
             :   } else if (use_jwt_token_
             :       && THRIFT_strncasecmp(header, FLAGS_jwt_token_identifier.c_str(), sz) == 0
             :       && THRIFT_strncasecmp(
             :              auth_value_.c_str(), FLAGS_jwt_auth_type.c_str(), auth_value_.length())
             :           == 0) {
             :     // JWT token in HTTP header as “Authorization=Bearer;token=<token_string>”
             :     jwt_token_ = string(value);
             : #endif
> If this code isn't needed, let's remove it.
Done


http://gerrit.cloudera.org:8080/#/c/17435/6/be/src/transport/THttpServer.cpp@286
PS6, Line 286:       if (got_bearer_auth) {
             :         fallback_to_other_auths = false;
             :         // Final SAML message in browser mode, check bearer and replace it with a cookie.
             :         DCHECK(wrapped_request_ != nullptr);
             :         wrapped_request_->headers["Authorization"] = auth_value_;
             :         if (callbacks_.validate_saml2_bearer_fn()) {
             :           // During EE tests it makes things easier to return 401-Unauthorized here.
             :           // This hack can be removed once there is a Python client that
             :           // supports SAML (IMPALA-10496).
             :           if (!FLAGS_saml2_ee_test_mode) authorized = true;
             :           if (metrics_enabled_) http_metrics_->total_saml_auth_success_->Increment(1);
             :         }
> One complication is that both SAML and JWT use the "Authorization Bearer <t
Thanks for capturing this case. SAML2 token is base64 encoded XML and should not has period so we can use period to distinguish them. Ran core test, don't see any SAML unit-test broken.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 6
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Fri, 21 May 2021 18:38:14 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 19:

(4 comments)

http://gerrit.cloudera.org:8080/#/c/17435/18/be/src/util/jwt-util-internal.h
File be/src/util/jwt-util-internal.h:

http://gerrit.cloudera.org:8080/#/c/17435/18/be/src/util/jwt-util-internal.h@215
PS18, Line 215:   /// kty (key type): oct.
> Nit: I think we have a memory leak with these JWTPublicKeyMap types. The JW
fixed by replacing the raw pointer with unique_ptr. Built BE test with ASAN and passed jwt-util-test.


http://gerrit.cloudera.org:8080/#/c/17435/18/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/18/be/src/util/jwt-util.cc@134
PS18, Line 134: if (kv_map.find(k) == kv_map.en
> Nit: Is there any chance that there could be duplicate k's? unordered_map::
Fixed by print warning log message.


http://gerrit.cloudera.org:8080/#/c/17435/18/be/src/util/jwt-util.cc@410
PS18, Line 410: if (hs_key_map_.find(key_id) == hs_key_map_.end()) {
> Nit: Do we need any handling for duplicate key_id's for the same algorithm?
fixed by print warning log message if there is duplicate key id. Also changed raw pointer to unique_ptr for the map.


http://gerrit.cloudera.org:8080/#/c/17435/18/be/src/util/jwt-util.cc@448
PS18, Line 448: const DecodedJWT&
> Nit: unique_ptr behaves just like a regular pointer for ordinary code. It i
Fixed.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 19
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 08 Jul 2021 01:42:35 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 8:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/8770/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 8
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Fri, 21 May 2021 20:03:20 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 11:

Build Failed 

https://jenkins.impala.io/job/gerrit-code-review-checks/8975/ : Initial code review checks failed. See linked job for details on the failure.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 11
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Tue, 22 Jun 2021 22:07:44 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has submitted this change and it was merged. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with public key in JWKS.
 * Get the username out of the payload of JWT token.
 * Support following JSON Web Algorithms (JWA):
   HS256, HS384, HS512, RS256, RS384, RS512.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchain.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Reviewed-on: http://gerrit.cloudera.org:8080/17435
Reviewed-by: Joe McDonnell <jo...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/auth-provider.h
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-internal.h
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
A fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
A fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
M fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
M fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
A testdata/jwt/jwks_rs256.json
25 files changed, 2,464 insertions(+), 26 deletions(-)

Approvals:
  Joe McDonnell: Looks good to me, approved
  Impala Public Jenkins: Verified

-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 20
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 16:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/9014/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 16
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Fri, 25 Jun 2021 23:29:45 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#16). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with public key in JWKS.
 * Get the username out of the payload of JWT token.
 * Support following JSON Web algorithms (JWA):
   HS256, HS384, HS512, RS256, RS384, RS512.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchain.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/auth-provider.h
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-internal.h
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
A fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
A fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
A testdata/jwt/jwks_rs256.json
23 files changed, 2,396 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/16
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 16
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 13:

(4 comments)

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/rpc/authentication.cc
File be/src/rpc/authentication.cc:

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/rpc/authentication.cc@155
PS13, Line 155: DEFINE_bool(jwt_extract_username, true, "When true, extract username from JWT payload.");
              : // This specifies the custom claim in the JWT that contains the "username" for the
              : // session.
              : DEFINE_string(jwt_custom_claim_username, "username", "Custom claim 'username'");
> Is there a use case where you have JWT authentication, but you don't get th
Will remove jwt_extract_username.


http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.h
File be/src/util/jwt-util.h:

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.h@113
PS13, Line 113:   /// Opaque types for storing the pointer to JWT decoded token. This allows us to
              :   /// avoid including header file jwt-cpp/jwt.h.
              :   struct JWTDecodedTokenPtr;
              :   JWTDecodedTokenPtr* decoded_token_;
> The current form is a pointer to a struct that contains a unique_ptr to the
It's good suggestion to remove a layer of pointer. But we cannot define decoded_token_ as unique_ptr in the class which point to an opaque type. Got incomplete type compiling error when JWTVerifier object is destroyed in authentication.cc:

/home/wzhou/projects/Impala-0430/Impala/be/src/util/jwt-util.h:94:7:   required from here
/home/wzhou/projects/Impala-0430/Impala/toolchain/toolchain-packages-gcc7.5.0/gcc-7.5.0/include/c++/7.5.0/bits/unique_ptr.h:76:22: error: invalid application of ‘sizeof’ to incomplete type ‘impala::JWTVerifier::JWTDecodedToken’
  static_assert(sizeof(_Tp)>0


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@290
PS9, Line 290:  rapidjson::FileReadStream stream(jwks_file, readBuffer, sizeof(readBuffer));
             :   Document jwks_doc;
             :   jwks_doc.ParseStream(stream);
             :   fclose(jwks_file);
             :   if (jwks_doc.HasParseError()) {
             :     return Status(
             :         TErrorCode::JWKS_PARSE_ERROR, GetParseError_En(jwks_doc.GetParseError()));
             :   }
             :   if (!jwks_doc.IsObject()) {
             :     return Status(TErrorCode::JWKS_PARSE_ERROR, "root element must be a JSON Object");
             :   }
             :   if (!jwks_doc.HasMember("keys")) {
             :     return Status(TErrorCode::JWKS_PARSE_ERROR, "keys is required");
             :   }
             : 
> The thing I'm thinking about is caching the verifier so that it is initiali
Thanks for the detail design of classes. I will try to re-organize code in your design. 
But I am not sure if the verifier of jwt-cpp is thread safe since we could receive concurrent requests with same key-id.


http://gerrit.cloudera.org:8080/#/c/17435/13/fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
File fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java:

http://gerrit.cloudera.org:8080/#/c/17435/13/fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java@60
PS13, Line 60:    String uri =
             :         String.format("ldap://localhost:%s", serverRule.getLdapServer().getPort());
             :     String dn = "cn=#UID,ou=Users,dc=myorg,dc=com";
             :     String ldapArgs = String.format("--enable_ldap_auth --ldap_uri='%s' "
             :             + "--ldap_bind_pattern='%s' --ldap_passwords_in_clear_ok %s ",
             :         uri, dn, extraArgs);
> This JWT test is still enabling LDAP. I'm interested in also having a JWT t
Tried to remove ldapArgs and call StartImpalaCluster() with extraArgs. But StartImpalaCluster() failed.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 13
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 24 Jun 2021 07:28:56 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 14:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/9009/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 14
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Fri, 25 Jun 2021 15:27:50 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] [WIP] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: [WIP] IMPALA-10489: Implement JWT support
......................................................................


Patch Set 3:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/8720/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 3
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Comment-Date: Fri, 14 May 2021 23:49:46 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#12). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.
 * Support following JSON Web algorithms (JWA):
   HS256, HS384, HS512, ES256, ES384, ES512, RS256, RS384, RS512.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/auth-provider.h
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/service/impala-server.h
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
A fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
A fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
A testdata/jwt/jwks_rs256.json
23 files changed, 2,492 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/12
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 12
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Joe McDonnell (Code Review)" <ge...@cloudera.org>.
Joe McDonnell has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 9:

(21 comments)

I have made a first full pass over this.

I think this provides a level of functionality that will allow us to develop the client side like Impyla and others. There are pieces of functionality that can be expanded in later changes (more than RSA algorithms, support more JWKS options, etc). Looking at the RFCs, we may be requiring fields that are optional, etc.

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/rpc/authentication.cc
File be/src/rpc/authentication.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/rpc/authentication.cc@156
PS9, Line 156: DEFINE_string(jwt_custom_claim_username
Do we have any code that would validate this value? (i.e. it should not be the empty string)


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/rpc/authentication.cc@156
PS9, Line 156: "Custom claim 'username'"
Nit: I would expand on this description to note that this specifies the custom claim in the JWT that contains the username for the session.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/rpc/authentication.cc@1432
PS9, Line 1432:     if (use_saml) {
              :       SecureAuthProvider* sap = NULL;
              :       external_http_auth_provider_.reset(sap = new SecureAuthProvider(false));
              :       sap->InitSaml();
              :       LOG(INFO) <<
              :           "External communication is authenticated for hs2-http protocol with SAML2 SSO";
              :     } else {
              :       LOG(INFO) << "External communication is not authenticated for hs2-http protocol";
              :     }
I think we want to be able to have JWT as the only authentication method (without LDAP or anything else), which means that this code needs to detect JWT support and use SecureAuthProvider() like it does for SAML.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/transport/THttpServer.cpp
File be/src/transport/THttpServer.cpp:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/transport/THttpServer.cpp@278
PS9, Line 278:         } else if (use_jwt_token_
             :             && stripped_bearer_auth_token.find('.') != string::npos) {
             :           // Since Impala supports multiple auth mechanism in parallel, falls back to JWT.
             :           if (callbacks_.jwt_token_auth_fn(stripped_bearer_auth_token)) {
             :             authorized = true;
             :             if (metrics_enabled_) {
             :               http_metrics_->total_jwt_token_auth_success_->Increment(1);
             :             }
             :           }
The other way to do this is to move the below JWT auth section above this "if (!authorized && has_saml_)" section. The JWT section would always fall through to the SAML section if it fails.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc
File be/src/util/jwt-util-test.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc@145
PS9, Line 145:   // Delete this temporary file
             :   void Delete();
If this isn't used directly, then you can make it private.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc@149
PS9, Line 149: const char* Filename() const { return name_.c_str(); }
Since JsonWebKeySet::Init() takes the filename in as a "const std::string&", this can return a "const std::string&".


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc@169
PS9, Line 169: NULL
Nit: Use nullptr rather than NULL for new code.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc@224
PS9, Line 224:   TempTestDataFile* jwks_file = new TempTestDataFile(
             :       "{"
             :       "  \"keys\": ["
             :       "    {"
             :       "      \"use\": \"sig\","
             :       "      \"kty\": \"RSA\","
             :       "      \"alg\": \"RS256\","
             :       "      \"n\": \"sttddbg-_yjXzcFpbMJB1fIFam9lQBeXWbTqzJwbuFbspHMsRowa8FaPw\","
             :       "      \"e\": \"AQAB\""
             :       "    }"
             :       "  ]"
             :       "}");
             :   JsonWebKeySet* jwks = new JsonWebKeySet();
Here and elsewhere in this file, use smart pointers / std::unique_ptr wherever possible rather than new/delete pairs.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc@348
PS9, Line 348: TEST(JwtUtilTest, VerifyJwtRS512) {
             :   // Sign JWT token with RS512.
             :   TempTestDataFile jwks_file(Substitute(jwks_file_format, kid_1, "RS512", rsa512_pub_key,
             :       kid_2, "RS512", rsa512_pub_key_invalid));
             :   JsonWebKeySet* jwks = new JsonWebKeySet();
             :   Status status = jwks->Init(jwks_file.Filename());
             :   ASSERT_TRUE(status.ok());
             :   ASSERT_EQ(2, jwks->GetKeyNum());
             : 
             :   const JsonWebKey* key1 = jwks->LookupKey(kid_1);
             :   ASSERT_TRUE(key1 != nullptr);
             :   ASSERT_EQ(ADD_PUB_KEY_HEADER_FOOTER(rsa512_pub_key), key1->key_value_);
             : 
             :   // Create a JWT token and sign it with RS512.
             :   string priv_key = ADD_RSA_PRIV_KEY_HEADER_FOOTER(rsa512_priv_key);
             :   string pub_key = ADD_PUB_KEY_HEADER_FOOTER(rsa512_pub_key);
             :   auto token = jwt::create()
             :                    .set_issuer("auth0")
             :                    .set_type("JWS")
             :                    .set_algorithm("RS512")
             :                    .set_key_id(kid_1)
             :                    .set_payload_claim("username", picojson::value("impala"))
             :                    .sign(jwt::algorithm::rs512(pub_key, priv_key, "", ""));
             : 
             :   // Verify the JWT token with our wrapper API which use public key retrieved from JWKS,
             :   // and read username from the token.
             :   string username;
             :   status = VerifyJWTTokenExtractUsername(token, jwks, "username", username);
             :   ASSERT_TRUE(status.ok());
             :   ASSERT_EQ("impala", username);
             : 
             :   delete jwks;
             : }
For completeness, let's also add a similar case with RS384


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc@456
PS9, Line 456:   ASSERT_TRUE(status.ok());
When checking that status is ok, use ASSERT_OK/EXPECT_OK from testutil/gtest-util.h. That will print the not-OK status if it fails. Please go through this file and fix all the locations like this.

(The ASSERT_FALSE(status.ok()) doesn't need to change, because there isn't any interesting detail about an OK status.)


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@103
PS9, Line 103:     if (!keys.IsArray()) {
             :       return Status(TErrorCode::JWKS_PARSE_ERROR,
             :           Substitute(
             :               "'keys' must be of type Array but is a '$0'", NameOfTypeOfJsonValue(keys)));
             :     }
Should we add an additional check that the array has non-zero Size()?


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@131
PS9, Line 131:     for (Value::ConstMemberIterator member = json_key.MemberBegin();
             :          member != json_key.MemberEnd(); ++member) {
For this for loop, you might just insert all the values into an unordered_map and put the actual logic for interpreting the values below the for loop.

Everything is a string, so there aren't typing issues. We are doing this once at startup, so this isn't very performance sensitive.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@133
PS9, Line 133:      if (strcmp("use", member->name.GetString()) == 0) {
             :         RETURN_IF_ERROR(ReadKeyProperty("use", json_key, &key_use, /*required*/ false));
Do we care about what "use" is set to? Do we want to require any specific value?


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@146
PS9, Line 146: else if (strcmp("n", member->name.GetString()) == 0) {
             :         found_kvalue = true;
             :         RETURN_IF_ERROR(ReadKeyProperty("n", json_key, &key_value));
             :         if (key_value.empty()) {
             :           return Status("'n' property must be a non-empty string");
             :         }
This works for RSA. Other encryption types like elliptic curve require other parameters. When we support that, I'm guessing we can just add the others here and then do the validation of the combinations down at the if (!found_kid || !found_kvalue) condition below.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@204
PS9, Line 204: NULL
Use "nullptr" in new code rather than NULL


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@249
PS9, Line 249: VerifyJWTTokenExtractUsername
From a style point of view, I think I would split up this function. I would do something like:
1. Define a type for the decoded JWT token
2. Have one function that parses the JSON into that JWT token type
3. Have a function that verifies the JWT. I think I would have a Verify() function on the JWKS structure (maybe that calls down to a Verify() function on the individual JWK).
4. A final function that reads the username (or just leave this in the JWTTokenAuth() function).


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@282
PS9, Line 282:       if (strncasecmp(algorithm.c_str(), jwk->algorithm_.c_str(), algorithm.length())
             :           != 0) {
To be careful, compare the lengths as well to make sure this isn't just matching a prefix (or somehow algorithm.length() == 0).


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@290
PS9, Line 290:      if (strncasecmp(algorithm.c_str(), "rs256", algorithm.length()) == 0) {
             :         jwt::verify()
             :             .allow_algorithm(jwt::algorithm::rs256(jwk->key_value_, "", "", ""))
             :             .with_issuer(issuer)
             :             .verify(decoded_token);
             :       } else if (strncasecmp(algorithm.c_str(), "rs384", algorithm.length()) == 0) {
             :         jwt::verify()
             :             .allow_algorithm(jwt::algorithm::rs384(jwk->key_value_, "", "", ""))
             :             .with_issuer(issuer)
             :             .verify(decoded_token);
             :       } else if (strncasecmp(algorithm.c_str(), "rs512", algorithm.length()) == 0) {
             :         jwt::verify()
             :             .allow_algorithm(jwt::algorithm::rs512(jwk->key_value_, "", "", ""))
             :             .with_issuer(issuer)
             :             .verify(decoded_token);
One performance thing we may want to do is to construct the verifier once per JWK and then just use it to call verify on each new JWT. That doesn't need to happen in this change, but it may have a performance impact.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@312
PS9, Line 312:     // Get value of custom claim 'username' from the token payload.
             :     if (decoded_token.has_payload_claim(jwt_custom_claim_username)) {
             :       // Assume the claim data type of 'username' is string.
             :       username.assign(
             :           decoded_token.get_payload_claim(jwt_custom_claim_username).to_json().to_str());
             :     }
What happens if the username claim is not present? Should we return an error here? Similarly, what if the username is the empty string?


http://gerrit.cloudera.org:8080/#/c/17435/9/fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
File fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java:

http://gerrit.cloudera.org:8080/#/c/17435/9/fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java@421
PS9, Line 421:   /**
             :    * Tests if sessions are authenticated by verifying the JWT token for connections
             :    * to the HTTP hiveserver2 endpoint.
             :    * Since we don't have Java version of JWT library, we use pre-calculated JWT token
             :    * and JWKS. The token and JWK set used in this test case were generated by using
             :    * BE unit-test function JwtUtilTest::VerifyJwtRS256.
             :    */
             :   @Test
             :   public void testHiveserver2JwtAuth() throws Exception {
             :     String jwksFilename =
             :         new File(System.getenv("IMPALA_HOME"), "testdata/jwt/jwks_rs256.json").getPath();
             :     setUp(String.format(
             :         "--jwt_token_auth=true --jwt_validate_signature=true --jwks_file_path=%s "
             :             + "--jwt_allow_without_tls=true",
             :         jwksFilename));
             :     verifyMetrics(0, 0);
             :     THttpClient transport = new THttpClient("http://localhost:28000");
             :     Map<String, String> headers = new HashMap<String, String>();
             : 
             :     // Case 1: Authenticate with valid JWT Token in HTTP header.
             :     String jwtToken =
             :         "eyJhbGciOiJSUzI1NiIsImtpZCI6InB1YmxpYzpjNDI0YjY3Yi1mZTI4LTQ1ZDctYjAxNS1m"
             :         + "NzlkYTUwYjViMjEiLCJ0eXAiOiJKV1MifQ.eyJpc3MiOiJhdXRoMCIsInVzZXJuYW1lIjoia"
             :         + "W1wYWxhIn0.OW5H2SClLlsotsCarTHYEbqlbRh43LFwOyo9WubpNTwE7hTuJDsnFoVrvHiWI"
             :         + "02W69TZNat7DYcC86A_ogLMfNXagHjlMFJaRnvG5Ekag8NRuZNJmHVqfX-qr6x7_8mpOdU55"
             :         + "4kc200pqbpYLhhuK4Qf7oT7y9mOrtNrUKGDCZ0Q2y_mizlbY6SMg4RWqSz0RQwJbRgXIWSgc"
             :         + "bZd0GbD_MQQ8x7WRE4nluU-5Fl4N2Wo8T9fNTuxALPiuVeIczO25b5n4fryfKasSgaZfmk0C"
             :         + "oOJzqbtmQxqiK9QNSJAiH2kaqMwLNgAdgn8fbd-lB1RAEGeyPH8Px8ipqcKsPk0bg";
             :     headers.put("Authorization", "Bearer " + jwtToken);
             :     headers.put("X-Forwarded-For", "127.0.0.1");
             :     transport.setCustomHeaders(headers);
             :     transport.open();
             :     TCLIService.Iface client = new TCLIService.Client(new TBinaryProtocol(transport));
             : 
             :     // Open a session which will get username 'impala' from JWT token and use it as
             :     // login user.
             :     TOpenSessionReq openReq = new TOpenSessionReq();
             :     TOpenSessionResp openResp = client.OpenSession(openReq);
             :     // One successful authentication.
             :     verifyMetrics(0, 0);
             :     verifyJwtAuthMetrics(1, 0);
             :     // Running a query should succeed.
             :     TOperationHandle operationHandle = execAndFetch(
             :         client, openResp.getSessionHandle(), "select logged_in_user()", "impala");
             :     // Two more successful authentications - for the Exec() and the Fetch().
             :     verifyMetrics(0, 0);
             :     verifyJwtAuthMetrics(3, 0);
             : 
             :     // case 2: Authenticate fails with invalid JWT token which does not have signature.
             :     String invalidJwtToken =
             :         "eyJhbGciOiJSUzI1NiIsImtpZCI6InB1YmxpYzpjNDI0YjY3Yi1mZTI4LTQ1ZDctYjAxNS1m"
             :         + "NzlkYTUwYjViMjEiLCJ0eXAiOiJKV1MifQ.eyJpc3MiOiJhdXRoMCIsInVzZXJuYW1lIjoia"
             :         + "W1wYWxhIn0.";
             :     headers.put("Authorization", "Bearer " + invalidJwtToken);
             :     headers.put("X-Forwarded-For", "127.0.0.1");
             :     transport.setCustomHeaders(headers);
             :     try {
             :       openResp = client.OpenSession(openReq);
             :       fail("Exception exception.");
             :     } catch (Exception e) {
             :       verifyJwtAuthMetrics(3, 1);
             :       assertEquals(e.getMessage(), "HTTP Response code: 401");
             :     }
             :   }
These new test cases are testing LDAP + JWT. LdapHS2Test::setUp() includes LDAP auth settings. I think that we primarily want to test JWT on its own. So, I would like to split this off to a new test .java file that uses only the JWT startup options.

The history of the LDAP frontend tests is that Java had an LDAP library that made this testing easy. That is the main reason these are not our usual Python custom cluster tests. If it is possible to make this a Python custom cluster test, that would be preferable, but I'm also ok with splitting that off to another code change. The Python custom cluster test might be easier when impyla has support for JWTs.


http://gerrit.cloudera.org:8080/#/c/17435/9/fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
File fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java:

http://gerrit.cloudera.org:8080/#/c/17435/9/fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java@276
PS9, Line 276:   /**
             :    * Tests if sessions are authenticated by verifying the JWT token for connections
             :    * to the Web Server.
             :    * Since we don't have Java version of JWT library, we use pre-calculated JWT token
             :    * and JWKS. The token and JWK set used in this test case were generated by using
             :    * BE unit-test function JwtUtilTest::VerifyJwtRS256.
             :    */
             :   @Test
             :   public void testWebserverJwtAuth() throws Exception {
             :     String jwksFilename =
             :         new File(System.getenv("IMPALA_HOME"), "testdata/jwt/jwks_rs256.json").getPath();
             :     setUp(String.format(
             :               "--jwt_token_auth=true --jwt_validate_signature=true --jwks_file_path=%s "
             :                   + "--jwt_allow_without_tls=true",
             :               jwksFilename),
             :         "");
             : 
             :     // Case 1: Authenticate with valid JWT Token in HTTP header.
             :     String jwtToken =
             :         "eyJhbGciOiJSUzI1NiIsImtpZCI6InB1YmxpYzpjNDI0YjY3Yi1mZTI4LTQ1ZDctYjAxNS1m"
             :         + "NzlkYTUwYjViMjEiLCJ0eXAiOiJKV1MifQ.eyJpc3MiOiJhdXRoMCIsInVzZXJuYW1lIjoia"
             :         + "W1wYWxhIn0.OW5H2SClLlsotsCarTHYEbqlbRh43LFwOyo9WubpNTwE7hTuJDsnFoVrvHiWI"
             :         + "02W69TZNat7DYcC86A_ogLMfNXagHjlMFJaRnvG5Ekag8NRuZNJmHVqfX-qr6x7_8mpOdU55"
             :         + "4kc200pqbpYLhhuK4Qf7oT7y9mOrtNrUKGDCZ0Q2y_mizlbY6SMg4RWqSz0RQwJbRgXIWSgc"
             :         + "bZd0GbD_MQQ8x7WRE4nluU-5Fl4N2Wo8T9fNTuxALPiuVeIczO25b5n4fryfKasSgaZfmk0C"
             :         + "oOJzqbtmQxqiK9QNSJAiH2kaqMwLNgAdgn8fbd-lB1RAEGeyPH8Px8ipqcKsPk0bg";
             :     attemptConnection("Bearer " + jwtToken, "127.0.0.1");
             :     verifyJwtAuthMetrics(Range.closed(1L, 1L), zero);
             : 
             :     // Case 2: Failed with invalid JWT Token.
             :     String invalidJwtToken =
             :         "eyJhbGciOiJSUzI1NiIsImtpZCI6InB1YmxpYzpjNDI0YjY3Yi1mZTI4LTQ1ZDctYjAxNS1m"
             :         + "NzlkYTUwYjViMjEiLCJ0eXAiOiJKV1MifQ.eyJpc3MiOiJhdXRoMCIsInVzZXJuYW1lIjoia"
             :         + "W1wYWxhIn0.";
             :     try {
             :       attemptConnection("Bearer " + invalidJwtToken, "127.0.0.1");
             :     } catch (IOException e) {
             :       assertTrue(e.getMessage().contains("Server returned HTTP response code: 401"));
             :     }
             :     verifyJwtAuthMetrics(Range.closed(1L, 1L), Range.closed(1L, 1L));
             :   }
Same comment as on the other Java LDAP test file. It would be nice to split this off to test without the LDAP startup flags.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 9
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Wed, 02 Jun 2021 21:20:40 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 7:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/8769/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 7
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Fri, 21 May 2021 19:22:42 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 18:

Build started: https://jenkins.impala.io/job/gerrit-verify-dryrun/7279/ DRY_RUN=true


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 18
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Wed, 07 Jul 2021 23:13:13 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Joe McDonnell (Code Review)" <ge...@cloudera.org>.
Joe McDonnell has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 9:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@133
PS9, Line 133:      if (strcmp("use", member->name.GetString()) == 0) {
             :         RETURN_IF_ERROR(ReadKeyProperty("use", json_key, &key_use, /*required*/ false));
> Do we care about what "use" is set to? Do we want to require any specific v
It sounds like this is optional, so maybe we don't need to require a specific value.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 9
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Wed, 02 Jun 2021 21:24:37 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Joe McDonnell (Code Review)" <ge...@cloudera.org>.
Joe McDonnell has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 13:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.h
File be/src/util/jwt-util.h:

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.h@113
PS13, Line 113:   /// Opaque types for storing the pointer to JWT decoded token. This allows us to
              :   /// avoid including header file jwt-cpp/jwt.h.
              :   struct JWTDecodedTokenPtr;
              :   JWTDecodedTokenPtr* decoded_token_;
> I think one sticking point when doing this is that the destructor for JWTVe
The other thought is that jwt-util.h is not included in any other header file, so if this included jwt.h, it isn't spreading very far. It's great to avoid spreading the header inclusions, but hiding them also comes with a cost. In this case, it would probably be fine to leak jwt.h, because this isn't included in very many locations (5 cc files, I think?).



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 13
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 24 Jun 2021 19:30:00 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 4:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/8724/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 4
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Comment-Date: Mon, 17 May 2021 00:43:39 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 12:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/8976/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 12
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Tue, 22 Jun 2021 23:50:23 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#7). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/service/impala-server.h
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
M fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
M fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
A testdata/jwt/jwks_rs256.json
22 files changed, 1,493 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/7
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 7
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#13). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.
 * Support following JSON Web algorithms (JWA):
   RS256, RS384, RS512.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/auth-provider.h
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/service/impala-server.h
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
A fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
A fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
A testdata/jwt/jwks_rs256.json
23 files changed, 1,989 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/13
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 13
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 15:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/9010/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 15
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Fri, 25 Jun 2021 16:46:21 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 18:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/9034/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 18
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Tue, 06 Jul 2021 03:39:55 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 11:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@146
PS9, Line 146: return "Null";
             :       case rapidjson::kFalseType:
             :       case rapidjson::kTrueType:
             :         return "Bool";
             :       case rapidjson::kObjectType:
             :         r
> Right, added comments for other algorithms.
Reorganized code and add other algorithms - HS256, HS384, HS512, EC256, EC384 and EC512.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 11
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Tue, 22 Jun 2021 22:06:43 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Joe McDonnell (Code Review)" <ge...@cloudera.org>.
Joe McDonnell has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 19: Code-Review+2

This looks good to me. Thanks for the hard work!


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 19
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 08 Jul 2021 02:05:11 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 17:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/9030/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 17
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 01 Jul 2021 19:41:57 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#11). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.
 * Support following JSON Web algorithms (JWA):
   HS256, HS384, HS512, ES256, ES384, ES512, RS256, RS384, RS512.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/auth-provider.h
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/service/impala-server.h
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
A fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
A fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
A testdata/jwt/jwks_rs256.json
23 files changed, 2,486 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/11
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 11
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#8). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/service/impala-server.h
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
M fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
M fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
A testdata/jwt/jwks_rs256.json
22 files changed, 1,494 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/8
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 8
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] [WIP] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#2). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: [WIP] IMPALA-10489: Implement JWT support
......................................................................

[WIP] IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch updated bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and updated makefiles to add jwt-cpp/include in
the include path.

Added unit-test for loading JWKS file and verifying JWT token.

TODO:
  Add more unit tests, including FE custom cluster test for JWT
  authentication.
  Convert public key format between JWK and PEM.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/service/impala-server.h
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
16 files changed, 977 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/2
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 2
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 11:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@146
PS9, Line 146: return "Null";
             :       case rapidjson::kFalseType:
             :       case rapidjson::kTrueType:
             :         return "Bool";
             :       case rapidjson::kObjectType:
             :         r
> Reorganized code and add other algorithms - HS256, HS384, HS512, EC256, EC3
Typo: ES256, ES384 and ES512



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 11
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Tue, 22 Jun 2021 22:09:19 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 15:

(16 comments)

http://gerrit.cloudera.org:8080/#/c/17435/15//COMMIT_MSG
Commit Message:

http://gerrit.cloudera.org:8080/#/c/17435/15//COMMIT_MSG@12
PS15, Line 12: puclic
> Nit: public
fixed


http://gerrit.cloudera.org:8080/#/c/17435/15//COMMIT_MSG@19
PS15, Line 19: toolchian
> Nit: toolchain
fixed


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/rpc/authentication.cc
File be/src/rpc/authentication.cc:

http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/rpc/authentication.cc@1363
PS15, Line 1363: Custom claim 'username' in JWT has not been specified.
> Nit: Let's be clear about what startup parameter needs to change. Something
fixed


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-internal.h
File be/src/util/jwt-util-internal.h:

http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-internal.h@157
PS15, Line 157: consist
> Nit: conveys
fixed


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-internal.h@171
PS15, Line 171: Wek
> Nit: Web
fixed


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-internal.h@176
PS15, Line 176: AddRSAPublicbKey
> Nit: Should this be "AddRSAPublicKey" (minus the b)?
fixed


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-internal.h@185
PS15, Line 185:   /// Return number of keys for each family of algorithms.
              :   int GetHSKeyNum() { return hs_key_map_.size(); }
              :   /// Return number of keys for RSA.
              :   int GetRSAPublicKeyNum() { return rsa_pub_key_map_.size(); }
              : 
              :   /// Return all keys for HS.
              :   const JWTPublicKeyMap* GetAllHSKeys() { return &hs_key_map_; }
              :   /// Return all keys for RSA.
              :   const JWTPublicKeyMap* GetAllRSAPublicKeys() { return &rsa_pub_key_map_; }
              : 
              :   /// Return TRUE if there is no key.
              :   bool IsEmpty() { return hs_key_map_.empty() && rsa_pub_key_map_.empty(); }
> Nit: For these methods, they don't modify the object, so you can declare th
Fixed.


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-test.cc
File be/src/util/jwt-util-test.cc:

http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-test.cc@698
PS15, Line 698: JWTHelper* jwt_helper = JWTHelper::GetInstance();
> Multiple tests are invoked in a single run of the test executable, so the s
fixed.


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.h
File be/src/util/jwt-util.h:

http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.h@55
PS15, Line 55:   /// Load JWKS from a JSON file. Returns an error if problems were encountered.
             :   Status Init(const std::string& jwks_file_path);
> Since we are primarily using the JWTHelper as a static standalone object, w
fixed.


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.h@58
PS15, Line 58:   /// Decode the given JWT token. The decoding result is stored in decoded_token_.
             :   /// Return Status::OK if the decoding is successful.
             :   Status Decode(const std::string& token, UniqueJWTDecodedToken& decoded_token_out);
> I think this doesn't need anything from the JWTHelper, so it can be declare
fixed


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.h@62
PS15, Line 62:   /// Verify the token's signature with the given JWKS. The token should be already
             :   /// decoded by calling Decode().
             :   /// Return Status::OK if the verification is successful.
             :   Status Verify(const JWTDecodedToken* decoded_token);
> Nit: It would be good to declare this method const.
fixed


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.h@67
PS15, Line 67:   /// Extract custom claim "Username" from from the payload of the decoded JWT token.
             :   /// Return Status::OK if the extraction is successful.
             :   Status GetCustomClaimUsername(const JWTDecodedToken* decoded_token,
             :       const std::string& custom_claim_username, std::string& username);
> I think this doesn't need anything from JWTHelper, so it can be declared st
fixed


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.h@72
PS15, Line 72:   /// This function is only called by unit-test.
             :   JsonWebKeySet* GetJWKS() { return jwks_.get(); }
> It would be good to declare this method const.
fixed


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.cc@487
PS15, Line 487:     // string issuer = decoded_token->decoded_jwt_.get_issuer();
              :     // verifier.with_issuer(issuer);
> Nit: Remove unused code
fixed


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.cc@520
PS15, Line 520:         if (jwks_.get()->GetRSAPublicKeyNum() == 0) {
              :           return Status(
              :               TErrorCode::JWT_VERIFY_FAILED, "Verification failed, no matching key");
              :         }
> Nit: Another way of doing this is to get the key_map in the various if bran
fixed


http://gerrit.cloudera.org:8080/#/c/17435/15/cmake_modules/FindJwtCpp.cmake
File cmake_modules/FindJwtCpp.cmake:

http://gerrit.cloudera.org:8080/#/c/17435/15/cmake_modules/FindJwtCpp.cmake@30
PS15, Line 30:   message(FATA_ERROR "jwt-cpp headers NOT found.")
> FATA_ERROR should be FATAL_ERROR
fixed



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 15
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Fri, 25 Jun 2021 23:00:44 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 9:

(22 comments)

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/rpc/authentication.cc
File be/src/rpc/authentication.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/rpc/authentication.cc@156
PS9, Line 156: DEFINE_string(jwt_custom_claim_username
> Do we have any code that would validate this value? (i.e. it should not be 
Add code to validate this value in AuthManager::Init().


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/rpc/authentication.cc@156
PS9, Line 156: "Custom claim 'username'"
> Nit: I would expand on this description to note that this specifies the cus
Updated iy.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/rpc/authentication.cc@1432
PS9, Line 1432:     if (use_saml) {
              :       SecureAuthProvider* sap = NULL;
              :       external_http_auth_provider_.reset(sap = new SecureAuthProvider(false));
              :       sap->InitSaml();
              :       LOG(INFO) <<
              :           "External communication is authenticated for hs2-http protocol with SAML2 SSO";
              :     } else {
              :       LOG(INFO) << "External communication is not authenticated for hs2-http protocol";
              :     }
> I think we want to be able to have JWT as the only authentication method (w
Added code as suggested.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/transport/THttpServer.cpp
File be/src/transport/THttpServer.cpp:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/transport/THttpServer.cpp@278
PS9, Line 278:         } else if (use_jwt_token_
             :             && stripped_bearer_auth_token.find('.') != string::npos) {
             :           // Since Impala supports multiple auth mechanism in parallel, falls back to JWT.
             :           if (callbacks_.jwt_token_auth_fn(stripped_bearer_auth_token)) {
             :             authorized = true;
             :             if (metrics_enabled_) {
             :               http_metrics_->total_jwt_token_auth_success_->Increment(1);
             :             }
             :           }
> The other way to do this is to move the below JWT auth section above this "
Yes, this is more clean. Fixed as suggested.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc
File be/src/util/jwt-util-test.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc@145
PS9, Line 145:   // Delete this temporary file
             :   void Delete();
> If this isn't used directly, then you can make it private.
Fixed.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc@149
PS9, Line 149: const char* Filename() const { return name_.c_str(); }
> Since JsonWebKeySet::Init() takes the filename in as a "const std::string&"
fixed.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc@169
PS9, Line 169: NULL
> Nit: Use nullptr rather than NULL for new code.
fixed.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc@224
PS9, Line 224:   TempTestDataFile* jwks_file = new TempTestDataFile(
             :       "{"
             :       "  \"keys\": ["
             :       "    {"
             :       "      \"use\": \"sig\","
             :       "      \"kty\": \"RSA\","
             :       "      \"alg\": \"RS256\","
             :       "      \"n\": \"sttddbg-_yjXzcFpbMJB1fIFam9lQBeXWbTqzJwbuFbspHMsRowa8FaPw\","
             :       "      \"e\": \"AQAB\""
             :       "    }"
             :       "  ]"
             :       "}");
             :   JsonWebKeySet* jwks = new JsonWebKeySet();
> Here and elsewhere in this file, use smart pointers / std::unique_ptr where
Fixed.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc@348
PS9, Line 348: TEST(JwtUtilTest, VerifyJwtRS512) {
             :   // Sign JWT token with RS512.
             :   TempTestDataFile jwks_file(Substitute(jwks_file_format, kid_1, "RS512", rsa512_pub_key,
             :       kid_2, "RS512", rsa512_pub_key_invalid));
             :   JsonWebKeySet* jwks = new JsonWebKeySet();
             :   Status status = jwks->Init(jwks_file.Filename());
             :   ASSERT_TRUE(status.ok());
             :   ASSERT_EQ(2, jwks->GetKeyNum());
             : 
             :   const JsonWebKey* key1 = jwks->LookupKey(kid_1);
             :   ASSERT_TRUE(key1 != nullptr);
             :   ASSERT_EQ(ADD_PUB_KEY_HEADER_FOOTER(rsa512_pub_key), key1->key_value_);
             : 
             :   // Create a JWT token and sign it with RS512.
             :   string priv_key = ADD_RSA_PRIV_KEY_HEADER_FOOTER(rsa512_priv_key);
             :   string pub_key = ADD_PUB_KEY_HEADER_FOOTER(rsa512_pub_key);
             :   auto token = jwt::create()
             :                    .set_issuer("auth0")
             :                    .set_type("JWS")
             :                    .set_algorithm("RS512")
             :                    .set_key_id(kid_1)
             :                    .set_payload_claim("username", picojson::value("impala"))
             :                    .sign(jwt::algorithm::rs512(pub_key, priv_key, "", ""));
             : 
             :   // Verify the JWT token with our wrapper API which use public key retrieved from JWKS,
             :   // and read username from the token.
             :   string username;
             :   status = VerifyJWTTokenExtractUsername(token, jwks, "username", username);
             :   ASSERT_TRUE(status.ok());
             :   ASSERT_EQ("impala", username);
             : 
             :   delete jwks;
             : }
> For completeness, let's also add a similar case with RS384
Added test case for RS384.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util-test.cc@456
PS9, Line 456:   ASSERT_TRUE(status.ok());
> When checking that status is ok, use ASSERT_OK/EXPECT_OK from testutil/gtes
Fixed as suggested


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@103
PS9, Line 103:     if (!keys.IsArray()) {
             :       return Status(TErrorCode::JWKS_PARSE_ERROR,
             :           Substitute(
             :               "'keys' must be of type Array but is a '$0'", NameOfTypeOfJsonValue(keys)));
             :     }
> Should we add an additional check that the array has non-zero Size()?
Done


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@131
PS9, Line 131:     for (Value::ConstMemberIterator member = json_key.MemberBegin();
             :          member != json_key.MemberEnd(); ++member) {
> For this for loop, you might just insert all the values into an unordered_m
Done


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@133
PS9, Line 133:      if (strcmp("use", member->name.GetString()) == 0) {
             :         RETURN_IF_ERROR(ReadKeyProperty("use", json_key, &key_use, /*required*/ false));
> It sounds like this is optional, so maybe we don't need to require a specif
Right, it's optional. We don't need to save it.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@133
PS9, Line 133:      if (strcmp("use", member->name.GetString()) == 0) {
             :         RETURN_IF_ERROR(ReadKeyProperty("use", json_key, &key_use, /*required*/ false));
> Do we care about what "use" is set to? Do we want to require any specific v
No, remove it.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@146
PS9, Line 146: else if (strcmp("n", member->name.GetString()) == 0) {
             :         found_kvalue = true;
             :         RETURN_IF_ERROR(ReadKeyProperty("n", json_key, &key_value));
             :         if (key_value.empty()) {
             :           return Status("'n' property must be a non-empty string");
             :         }
> This works for RSA. Other encryption types like elliptic curve require othe
Right, added comments for other algorithms.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@204
PS9, Line 204: NULL
> Use "nullptr" in new code rather than NULL
fixed


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@249
PS9, Line 249: VerifyJWTTokenExtractUsername
> From a style point of view, I think I would split up this function. I would
Added a class with the suggested member functions.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@282
PS9, Line 282:       if (strncasecmp(algorithm.c_str(), jwk->algorithm_.c_str(), algorithm.length())
             :           != 0) {
> To be careful, compare the lengths as well to make sure this isn't just mat
Done


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@290
PS9, Line 290:      if (strncasecmp(algorithm.c_str(), "rs256", algorithm.length()) == 0) {
             :         jwt::verify()
             :             .allow_algorithm(jwt::algorithm::rs256(jwk->key_value_, "", "", ""))
             :             .with_issuer(issuer)
             :             .verify(decoded_token);
             :       } else if (strncasecmp(algorithm.c_str(), "rs384", algorithm.length()) == 0) {
             :         jwt::verify()
             :             .allow_algorithm(jwt::algorithm::rs384(jwk->key_value_, "", "", ""))
             :             .with_issuer(issuer)
             :             .verify(decoded_token);
             :       } else if (strncasecmp(algorithm.c_str(), "rs512", algorithm.length()) == 0) {
             :         jwt::verify()
             :             .allow_algorithm(jwt::algorithm::rs512(jwk->key_value_, "", "", ""))
             :             .with_issuer(issuer)
             :             .verify(decoded_token);
> One performance thing we may want to do is to construct the verifier once p
Changed code to create one verifier.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@312
PS9, Line 312:     // Get value of custom claim 'username' from the token payload.
             :     if (decoded_token.has_payload_claim(jwt_custom_claim_username)) {
             :       // Assume the claim data type of 'username' is string.
             :       username.assign(
             :           decoded_token.get_payload_claim(jwt_custom_claim_username).to_json().to_str());
             :     }
> What happens if the username claim is not present? Should we return an erro
Changed code to return error.


http://gerrit.cloudera.org:8080/#/c/17435/9/fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
File fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java:

http://gerrit.cloudera.org:8080/#/c/17435/9/fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java@421
PS9, Line 421:   /**
             :    * Tests if sessions are authenticated by verifying the JWT token for connections
             :    * to the HTTP hiveserver2 endpoint.
             :    * Since we don't have Java version of JWT library, we use pre-calculated JWT token
             :    * and JWKS. The token and JWK set used in this test case were generated by using
             :    * BE unit-test function JwtUtilTest::VerifyJwtRS256.
             :    */
             :   @Test
             :   public void testHiveserver2JwtAuth() throws Exception {
             :     String jwksFilename =
             :         new File(System.getenv("IMPALA_HOME"), "testdata/jwt/jwks_rs256.json").getPath();
             :     setUp(String.format(
             :         "--jwt_token_auth=true --jwt_validate_signature=true --jwks_file_path=%s "
             :             + "--jwt_allow_without_tls=true",
             :         jwksFilename));
             :     verifyMetrics(0, 0);
             :     THttpClient transport = new THttpClient("http://localhost:28000");
             :     Map<String, String> headers = new HashMap<String, String>();
             : 
             :     // Case 1: Authenticate with valid JWT Token in HTTP header.
             :     String jwtToken =
             :         "eyJhbGciOiJSUzI1NiIsImtpZCI6InB1YmxpYzpjNDI0YjY3Yi1mZTI4LTQ1ZDctYjAxNS1m"
             :         + "NzlkYTUwYjViMjEiLCJ0eXAiOiJKV1MifQ.eyJpc3MiOiJhdXRoMCIsInVzZXJuYW1lIjoia"
             :         + "W1wYWxhIn0.OW5H2SClLlsotsCarTHYEbqlbRh43LFwOyo9WubpNTwE7hTuJDsnFoVrvHiWI"
             :         + "02W69TZNat7DYcC86A_ogLMfNXagHjlMFJaRnvG5Ekag8NRuZNJmHVqfX-qr6x7_8mpOdU55"
             :         + "4kc200pqbpYLhhuK4Qf7oT7y9mOrtNrUKGDCZ0Q2y_mizlbY6SMg4RWqSz0RQwJbRgXIWSgc"
             :         + "bZd0GbD_MQQ8x7WRE4nluU-5Fl4N2Wo8T9fNTuxALPiuVeIczO25b5n4fryfKasSgaZfmk0C"
             :         + "oOJzqbtmQxqiK9QNSJAiH2kaqMwLNgAdgn8fbd-lB1RAEGeyPH8Px8ipqcKsPk0bg";
             :     headers.put("Authorization", "Bearer " + jwtToken);
             :     headers.put("X-Forwarded-For", "127.0.0.1");
             :     transport.setCustomHeaders(headers);
             :     transport.open();
             :     TCLIService.Iface client = new TCLIService.Client(new TBinaryProtocol(transport));
             : 
             :     // Open a session which will get username 'impala' from JWT token and use it as
             :     // login user.
             :     TOpenSessionReq openReq = new TOpenSessionReq();
             :     TOpenSessionResp openResp = client.OpenSession(openReq);
             :     // One successful authentication.
             :     verifyMetrics(0, 0);
             :     verifyJwtAuthMetrics(1, 0);
             :     // Running a query should succeed.
             :     TOperationHandle operationHandle = execAndFetch(
             :         client, openResp.getSessionHandle(), "select logged_in_user()", "impala");
             :     // Two more successful authentications - for the Exec() and the Fetch().
             :     verifyMetrics(0, 0);
             :     verifyJwtAuthMetrics(3, 0);
             : 
             :     // case 2: Authenticate fails with invalid JWT token which does not have signature.
             :     String invalidJwtToken =
             :         "eyJhbGciOiJSUzI1NiIsImtpZCI6InB1YmxpYzpjNDI0YjY3Yi1mZTI4LTQ1ZDctYjAxNS1m"
             :         + "NzlkYTUwYjViMjEiLCJ0eXAiOiJKV1MifQ.eyJpc3MiOiJhdXRoMCIsInVzZXJuYW1lIjoia"
             :         + "W1wYWxhIn0.";
             :     headers.put("Authorization", "Bearer " + invalidJwtToken);
             :     headers.put("X-Forwarded-For", "127.0.0.1");
             :     transport.setCustomHeaders(headers);
             :     try {
             :       openResp = client.OpenSession(openReq);
             :       fail("Exception exception.");
             :     } catch (Exception e) {
             :       verifyJwtAuthMetrics(3, 1);
             :       assertEquals(e.getMessage(), "HTTP Response code: 401");
             :     }
             :   }
> These new test cases are testing LDAP + JWT. LdapHS2Test::setUp() includes 
Tried to add tests in Python custom cluster tests, but did not work. I will use LDAP library and move the JWT test cases as new Java file. Will try Python custom cluster later.


http://gerrit.cloudera.org:8080/#/c/17435/9/fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
File fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java:

http://gerrit.cloudera.org:8080/#/c/17435/9/fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java@276
PS9, Line 276:   /**
             :    * Tests if sessions are authenticated by verifying the JWT token for connections
             :    * to the Web Server.
             :    * Since we don't have Java version of JWT library, we use pre-calculated JWT token
             :    * and JWKS. The token and JWK set used in this test case were generated by using
             :    * BE unit-test function JwtUtilTest::VerifyJwtRS256.
             :    */
             :   @Test
             :   public void testWebserverJwtAuth() throws Exception {
             :     String jwksFilename =
             :         new File(System.getenv("IMPALA_HOME"), "testdata/jwt/jwks_rs256.json").getPath();
             :     setUp(String.format(
             :               "--jwt_token_auth=true --jwt_validate_signature=true --jwks_file_path=%s "
             :                   + "--jwt_allow_without_tls=true",
             :               jwksFilename),
             :         "");
             : 
             :     // Case 1: Authenticate with valid JWT Token in HTTP header.
             :     String jwtToken =
             :         "eyJhbGciOiJSUzI1NiIsImtpZCI6InB1YmxpYzpjNDI0YjY3Yi1mZTI4LTQ1ZDctYjAxNS1m"
             :         + "NzlkYTUwYjViMjEiLCJ0eXAiOiJKV1MifQ.eyJpc3MiOiJhdXRoMCIsInVzZXJuYW1lIjoia"
             :         + "W1wYWxhIn0.OW5H2SClLlsotsCarTHYEbqlbRh43LFwOyo9WubpNTwE7hTuJDsnFoVrvHiWI"
             :         + "02W69TZNat7DYcC86A_ogLMfNXagHjlMFJaRnvG5Ekag8NRuZNJmHVqfX-qr6x7_8mpOdU55"
             :         + "4kc200pqbpYLhhuK4Qf7oT7y9mOrtNrUKGDCZ0Q2y_mizlbY6SMg4RWqSz0RQwJbRgXIWSgc"
             :         + "bZd0GbD_MQQ8x7WRE4nluU-5Fl4N2Wo8T9fNTuxALPiuVeIczO25b5n4fryfKasSgaZfmk0C"
             :         + "oOJzqbtmQxqiK9QNSJAiH2kaqMwLNgAdgn8fbd-lB1RAEGeyPH8Px8ipqcKsPk0bg";
             :     attemptConnection("Bearer " + jwtToken, "127.0.0.1");
             :     verifyJwtAuthMetrics(Range.closed(1L, 1L), zero);
             : 
             :     // Case 2: Failed with invalid JWT Token.
             :     String invalidJwtToken =
             :         "eyJhbGciOiJSUzI1NiIsImtpZCI6InB1YmxpYzpjNDI0YjY3Yi1mZTI4LTQ1ZDctYjAxNS1m"
             :         + "NzlkYTUwYjViMjEiLCJ0eXAiOiJKV1MifQ.eyJpc3MiOiJhdXRoMCIsInVzZXJuYW1lIjoia"
             :         + "W1wYWxhIn0.";
             :     try {
             :       attemptConnection("Bearer " + invalidJwtToken, "127.0.0.1");
             :     } catch (IOException e) {
             :       assertTrue(e.getMessage().contains("Server returned HTTP response code: 401"));
             :     }
             :     verifyJwtAuthMetrics(Range.closed(1L, 1L), Range.closed(1L, 1L));
             :   }
> Same comment as on the other Java LDAP test file. It would be nice to split
Tried to add tests in Python custom cluster tests, but did not work. I will use LDAP library and move the JWT test cases as new Java file.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 9
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Wed, 16 Jun 2021 01:03:06 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#14). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.
 * Support following JSON Web algorithms (JWA):
   HS256, HS384, HS512, RS256, RS384, RS512.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/auth-provider.h
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-internal.h
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
A fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
A fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
A testdata/jwt/jwks_rs256.json
23 files changed, 2,341 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/14
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 14
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 19: Verified+1


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 19
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 08 Jul 2021 23:10:31 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#4). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/service/impala-server.h
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
M fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
A testdata/jwt/jwks_rs256.json
19 files changed, 1,305 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/4
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 4
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#5). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/service/impala-server.h
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
M fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
M fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
A testdata/jwt/jwks_rs256.json
22 files changed, 1,478 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/5
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 5
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>

[Impala-ASF-CR] [WIP] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: [WIP] IMPALA-10489: Implement JWT support
......................................................................


Patch Set 2:

Build Failed 

https://jenkins.impala.io/job/gerrit-code-review-checks/8717/ : Initial code review checks failed. See linked job for details on the failure.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 2
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Comment-Date: Fri, 14 May 2021 07:03:17 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#18). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with public key in JWKS.
 * Get the username out of the payload of JWT token.
 * Support following JSON Web Algorithms (JWA):
   HS256, HS384, HS512, RS256, RS384, RS512.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchain.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/auth-provider.h
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-internal.h
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
A fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
A fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
M fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
M fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
A testdata/jwt/jwks_rs256.json
25 files changed, 2,451 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/18
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 18
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#15). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.
 * Support following JSON Web algorithms (JWA):
   HS256, HS384, HS512, RS256, RS384, RS512.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/auth-provider.h
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-internal.h
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
A fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
A fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
A testdata/jwt/jwks_rs256.json
23 files changed, 2,349 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/15
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 15
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Joe McDonnell (Code Review)" <ge...@cloudera.org>.
Joe McDonnell has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 9:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@290
PS9, Line 290:      if (strncasecmp(algorithm.c_str(), "rs256", algorithm.length()) == 0) {
             :         jwt::verify()
             :             .allow_algorithm(jwt::algorithm::rs256(jwk->key_value_, "", "", ""))
             :             .with_issuer(issuer)
             :             .verify(decoded_token);
             :       } else if (strncasecmp(algorithm.c_str(), "rs384", algorithm.length()) == 0) {
             :         jwt::verify()
             :             .allow_algorithm(jwt::algorithm::rs384(jwk->key_value_, "", "", ""))
             :             .with_issuer(issuer)
             :             .verify(decoded_token);
             :       } else if (strncasecmp(algorithm.c_str(), "rs512", algorithm.length()) == 0) {
             :         jwt::verify()
             :             .allow_algorithm(jwt::algorithm::rs512(jwk->key_value_, "", "", ""))
             :             .with_issuer(issuer)
             :             .verify(decoded_token);
> For this review, I would like the piece that folds the JWTVerifier and JWKS
https://stackoverflow.com/a/17950450 - this shows a way to use deleters that makes it easier to use incomplete types



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 9
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 24 Jun 2021 19:38:17 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 5:

Build Successful 

https://jenkins.impala.io/job/gerrit-code-review-checks/8742/ : Initial code review checks passed. Use gerrit-verify-dryrun-external or gerrit-verify-dryrun to run full precommit tests.


-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 5
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Comment-Date: Tue, 18 May 2021 16:57:50 +0000
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Impala Public Jenkins (Code Review)" <ge...@cloudera.org>.
Impala Public Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 7:

(3 comments)

http://gerrit.cloudera.org:8080/#/c/17435/7/fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
File fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java:

http://gerrit.cloudera.org:8080/#/c/17435/7/fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java@433
PS7, Line 433:         "--jwt_token_auth=true --jwt_validate_signature=true --jwks_file_path=%s --jwt_allow_without_tls=true",
line too long (111 > 90)


http://gerrit.cloudera.org:8080/#/c/17435/7/fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java@494
PS7, Line 494:         "--jwt_token_auth=true --jwt_validate_signature=false --jwt_allow_without_tls=true");
line too long (93 > 90)


http://gerrit.cloudera.org:8080/#/c/17435/7/fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
File fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java:

http://gerrit.cloudera.org:8080/#/c/17435/7/fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java@289
PS7, Line 289:             "--jwt_token_auth=true --jwt_validate_signature=true --jwks_file_path=%s --jwt_allow_without_tls=true",
line too long (115 > 90)



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 7
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Fri, 21 May 2021 19:02:50 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Joe McDonnell (Code Review)" <ge...@cloudera.org>.
Joe McDonnell has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 13:

(2 comments)

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.h
File be/src/util/jwt-util.h:

http://gerrit.cloudera.org:8080/#/c/17435/13/be/src/util/jwt-util.h@113
PS13, Line 113:   /// Opaque types for storing the pointer to JWT decoded token. This allows us to
              :   /// avoid including header file jwt-cpp/jwt.h.
              :   struct JWTDecodedTokenPtr;
              :   JWTDecodedTokenPtr* decoded_token_;
> It's good suggestion to remove a layer of pointer. But we cannot define dec
I think one sticking point when doing this is that the destructor for JWTVerifier needs to be declared in the .h and defined in the .cc file (like you are doing now).

https://stackoverflow.com/questions/13414652/forward-declaration-with-unique-ptr

If it still doesn't work, then we don't need to worry about it for now.


http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/9/be/src/util/jwt-util.cc@290
PS9, Line 290:  rapidjson::FileReadStream stream(jwks_file, readBuffer, sizeof(readBuffer));
             :   Document jwks_doc;
             :   jwks_doc.ParseStream(stream);
             :   fclose(jwks_file);
             :   if (jwks_doc.HasParseError()) {
             :     return Status(
             :         TErrorCode::JWKS_PARSE_ERROR, GetParseError_En(jwks_doc.GetParseError()));
             :   }
             :   if (!jwks_doc.IsObject()) {
             :     return Status(TErrorCode::JWKS_PARSE_ERROR, "root element must be a JSON Object");
             :   }
             :   if (!jwks_doc.HasMember("keys")) {
             :     return Status(TErrorCode::JWKS_PARSE_ERROR, "keys is required");
             :   }
             : 
> Thanks for the detail design of classes. I will try to re-organize code in 
For this review, I would like the piece that folds the JWTVerifier and JWKS into one thing like I described.

To do that while hiding jwt.h, you will need an opaque type. The way I described in my answer won't really work. One way to do that is via code like this:
https://github.com/apache/impala/blob/master/be/src/util/cache/cache.h#L86-L111

The other pieces that I described (like caching the verifier and separating algorithms into different key classes) are things that I'm willing to push out to the change that adds the other algorithms (but are welcome here).

The verify() definition in jwt.h is const:
https://github.com/Thalhammer/jwt-cpp/blob/master/include/jwt-cpp/jwt.h#L2749
That means the verify() method can't modify the underlying verifier object as part of the call. So, I believe it is thread safe.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 13
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Thu, 24 Jun 2021 19:20:55 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Joe McDonnell (Code Review)" <ge...@cloudera.org>.
Joe McDonnell has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 15:

(17 comments)

This is looking great. My comments are only nits.

The only concern I have is that we do want JWT to work without LDAP, so getting a test for that working would be useful.

http://gerrit.cloudera.org:8080/#/c/17435/15//COMMIT_MSG
Commit Message:

http://gerrit.cloudera.org:8080/#/c/17435/15//COMMIT_MSG@12
PS15, Line 12: puclic
Nit: public


http://gerrit.cloudera.org:8080/#/c/17435/15//COMMIT_MSG@19
PS15, Line 19: toolchian
Nit: toolchain


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/rpc/authentication.cc
File be/src/rpc/authentication.cc:

http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/rpc/authentication.cc@1363
PS15, Line 1363: Custom claim 'username' in JWT has not been specified.
Nit: Let's be clear about what startup parameter needs to change. Something like:
JWT authentication requires jwt_custom_claim_username to be specified.


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-internal.h
File be/src/util/jwt-util-internal.h:

http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-internal.h@157
PS15, Line 157: consist
Nit: conveys


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-internal.h@171
PS15, Line 171: Wek
Nit: Web


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-internal.h@176
PS15, Line 176: AddRSAPublicbKey
Nit: Should this be "AddRSAPublicKey" (minus the b)?


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-internal.h@185
PS15, Line 185:   /// Return number of keys for each family of algorithms.
              :   int GetHSKeyNum() { return hs_key_map_.size(); }
              :   /// Return number of keys for RSA.
              :   int GetRSAPublicKeyNum() { return rsa_pub_key_map_.size(); }
              : 
              :   /// Return all keys for HS.
              :   const JWTPublicKeyMap* GetAllHSKeys() { return &hs_key_map_; }
              :   /// Return all keys for RSA.
              :   const JWTPublicKeyMap* GetAllRSAPublicKeys() { return &rsa_pub_key_map_; }
              : 
              :   /// Return TRUE if there is no key.
              :   bool IsEmpty() { return hs_key_map_.empty() && rsa_pub_key_map_.empty(); }
Nit: For these methods, they don't modify the object, so you can declare the methods const:

int GetHSKeyNum() const { return hs_key_map_.size(); }

I don't think it changes much for our purposes, but it is good housekeeping.


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-test.cc
File be/src/util/jwt-util-test.cc:

http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util-test.cc@698
PS15, Line 698: JWTHelper* jwt_helper = JWTHelper::GetInstance();
Multiple tests are invoked in a single run of the test executable, so the static objects can outlive the tests. Throughout this file, I think we're better off if we avoid using a static JWTHelper. Most of the tests are doing an Init() call anyway, so having a local JWTHelper variable should be the same.


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.h
File be/src/util/jwt-util.h:

http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.h@55
PS15, Line 55:   /// Load JWKS from a JSON file. Returns an error if problems were encountered.
             :   Status Init(const std::string& jwks_file_path);
Since we are primarily using the JWTHelper as a static standalone object, we may want to add some checks to make sure this is initialized before we start trying to use it. 

For example, is is legitimate to call Verify() on a JWTHelper that has not yet called Init()? I think we're probably better off saying that this is not legitimate. So, maybe add an "initialized_" boolean variable and DCHECK that it is true in Verify().


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.h@58
PS15, Line 58:   /// Decode the given JWT token. The decoding result is stored in decoded_token_.
             :   /// Return Status::OK if the decoding is successful.
             :   Status Decode(const std::string& token, UniqueJWTDecodedToken& decoded_token_out);
I think this doesn't need anything from the JWTHelper, so it can be declared static.


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.h@62
PS15, Line 62:   /// Verify the token's signature with the given JWKS. The token should be already
             :   /// decoded by calling Decode().
             :   /// Return Status::OK if the verification is successful.
             :   Status Verify(const JWTDecodedToken* decoded_token);
Nit: It would be good to declare this method const.


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.h@67
PS15, Line 67:   /// Extract custom claim "Username" from from the payload of the decoded JWT token.
             :   /// Return Status::OK if the extraction is successful.
             :   Status GetCustomClaimUsername(const JWTDecodedToken* decoded_token,
             :       const std::string& custom_claim_username, std::string& username);
I think this doesn't need anything from JWTHelper, so it can be declared static.


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.h@72
PS15, Line 72:   /// This function is only called by unit-test.
             :   JsonWebKeySet* GetJWKS() { return jwks_.get(); }
It would be good to declare this method const.


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.cc
File be/src/util/jwt-util.cc:

http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.cc@487
PS15, Line 487:     // string issuer = decoded_token->decoded_jwt_.get_issuer();
              :     // verifier.with_issuer(issuer);
Nit: Remove unused code


http://gerrit.cloudera.org:8080/#/c/17435/15/be/src/util/jwt-util.cc@520
PS15, Line 520:         if (jwks_.get()->GetRSAPublicKeyNum() == 0) {
              :           return Status(
              :               TErrorCode::JWT_VERIFY_FAILED, "Verification failed, no matching key");
              :         }
Nit: Another way of doing this is to get the key_map in the various if branches, and then do one size() check before iterating:

key_map = nullptr;
if (algorithm matches hs) {
   key_map = HS key map;
} else if (algorithm matches rs) {
   key_map = RS key map;
} else {
   return Status();
}
if (key_map->size() == 0) {
   return Status("no matching key");
}
for (auto& key : *key_map)
...


http://gerrit.cloudera.org:8080/#/c/17435/15/cmake_modules/FindJwtCpp.cmake
File cmake_modules/FindJwtCpp.cmake:

http://gerrit.cloudera.org:8080/#/c/17435/15/cmake_modules/FindJwtCpp.cmake@30
PS15, Line 30:   message(FATA_ERROR "jwt-cpp headers NOT found.")
FATA_ERROR should be FATAL_ERROR


http://gerrit.cloudera.org:8080/#/c/17435/13/fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
File fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java:

http://gerrit.cloudera.org:8080/#/c/17435/13/fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java@60
PS13, Line 60:    String uri =
             :         String.format("ldap://localhost:%s", serverRule.getLdapServer().getPort());
             :     String dn = "cn=#UID,ou=Users,dc=myorg,dc=com";
             :     String ldapArgs = String.format("--enable_ldap_auth --ldap_uri='%s' "
             :             + "--ldap_bind_pattern='%s' --ldap_passwords_in_clear_ok %s ",
             :         uri, dn, extraArgs);
> Tried to remove ldapArgs and call StartImpalaCluster() with extraArgs. But 
Hmmm, that's odd. My thought is that the JWT functionality is going to be primarily used without LDAP, so we want Impala to be able to start with the JWT args and without LDAP args.

I can't tell whether there is something special about these Java custom cluster tests. Does bin/start-impala-cluster.py work with impalad_args set to the right JWT args?



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 15
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Fri, 25 Jun 2021 19:31:04 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has posted comments on this change. ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................


Patch Set 16:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/17435/13/fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
File fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java:

http://gerrit.cloudera.org:8080/#/c/17435/13/fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java@60
PS13, Line 60:    String uri =
             :         String.format("ldap://localhost:%s", serverRule.getLdapServer().getPort());
             :     String dn = "cn=#UID,ou=Users,dc=myorg,dc=com";
             :     String ldapArgs = String.format("--enable_ldap_auth --ldap_uri='%s' "
             :             + "--ldap_bind_pattern='%s' --ldap_passwords_in_clear_ok %s ",
             :         uri, dn, extraArgs);
> Hmmm, that's odd. My thought is that the JWT functionality is going to be p
I will debug the cause.



-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 16
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>
Gerrit-Reviewer: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Comment-Date: Fri, 25 Jun 2021 23:13:57 +0000
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-10489: Implement JWT support

Posted by "Wenzhe Zhou (Code Review)" <ge...@cloudera.org>.
Wenzhe Zhou has uploaded a new patch set (#6). ( http://gerrit.cloudera.org:8080/17435 )

Change subject: IMPALA-10489: Implement JWT support
......................................................................

IMPALA-10489: Implement JWT support

This patch added JWT support with following functionality:
 * Load and parse JWKS from pre-installed JSON file.
 * Read the JWT token from the HTTP Header.
 * Verify the JWT's signature with puclic key in JWKS.
 * Get the username out of the payload of JWT token.

We use third party library jwt-cpp to verify JWT token. jwt-cpp is a
headers only C++ library. It was added to native-toolchain.
This patch modified bootstrap_toolchian.py to download jwt-cpp from
toolchain s3 bucket, and modified makefiles to add jwt-cpp/include
in the include path.

Added BE unit-tests for loading JWKS file and verifying JWT token.
Also added FE custom cluster test for JWT authentication.

Testing:
 - Passed core run.

Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
---
M CMakeLists.txt
M be/CMakeLists.txt
M be/src/rpc/authentication.cc
M be/src/service/impala-server.cc
M be/src/service/impala-server.h
M be/src/transport/THttpServer.cpp
M be/src/transport/THttpServer.h
M be/src/util/CMakeLists.txt
A be/src/util/jwt-util-test.cc
A be/src/util/jwt-util.cc
A be/src/util/jwt-util.h
M be/src/util/webserver.cc
M be/src/util/webserver.h
M bin/bootstrap_toolchain.py
M bin/impala-config.sh
M bin/rat_exclude_files.txt
A cmake_modules/FindJwtCpp.cmake
M common/thrift/generate_error_codes.py
M common/thrift/metrics.json
M fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
M fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
A testdata/jwt/jwks_rs256.json
22 files changed, 1,476 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/35/17435/6
-- 
To view, visit http://gerrit.cloudera.org:8080/17435
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6b71fa854c9ddc8ca882878853395e1eb866143c
Gerrit-Change-Number: 17435
Gerrit-PatchSet: 6
Gerrit-Owner: Wenzhe Zhou <wz...@cloudera.com>
Gerrit-Reviewer: Andrew Sherman <as...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <im...@cloudera.com>
Gerrit-Reviewer: Joe McDonnell <jo...@cloudera.com>