Skip to content

Add JWT for internal communication#19706

Merged
tdcmeehan merged 1 commit intoprestodb:masterfrom
nmahadevuni:internal_communication_auth_fix
Jun 22, 2023
Merged

Add JWT for internal communication#19706
tdcmeehan merged 1 commit intoprestodb:masterfrom
nmahadevuni:internal_communication_auth_fix

Conversation

@nmahadevuni
Copy link
Member

@nmahadevuni nmahadevuni commented May 19, 2023

Supports JWT for authentication of internal requests. This is required for secure internal communication, especially when used in conjunction with external
user authentication such as PASSWORD, LDAP etc

Cherry-pick of trinodb/trino#2032 Cherry-pick of trinodb/trino#2093 Cherry-pick of trinodb/trino#2202 Cherry-pick of trinodb/trino#11944

Test plan -

== RELEASE NOTES ==

General Changes
* Add support for internal authentication using JWT. Can be configured using configs "internal-communication.jwt.enabled=[true/false]" and "internal-communication.shared-secret=<shared-secret-value>"

@nmahadevuni nmahadevuni requested a review from a team as a code owner May 19, 2023 09:51
@nmahadevuni nmahadevuni requested a review from presto-oss May 19, 2023 09:51
@nmahadevuni nmahadevuni force-pushed the internal_communication_auth_fix branch 3 times, most recently from 55c39ef to 7cf685a Compare May 20, 2023 12:55
@nmahadevuni nmahadevuni changed the title [WIP]: Add JWT for internal communication Add JWT for internal communication May 20, 2023
Copy link
Contributor

@tdcmeehan tdcmeehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add documentation of this new configuration parameter in internal-communication.rst? Also I think this warrants release notes.

@tdcmeehan
Copy link
Contributor

CC some Meta folks as I think this may require some config properties updates in Meta clusters. @ajaygeorge @amitkdutta @neeradsomanchi

@ethanyzhang
Copy link
Contributor

Hi @skairali, please also review this PR. Thanks!

@amitkdutta
Copy link
Contributor

A noob question. What's the value of internal-communication.shared-secret, and is it always used when https is enabled? CC: @neeradsomanchi @pranjalssh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isRequiredSharedSecretSet() contains !isHttpsRequired() so this exception message doesn't match with that. Do we need to set this for http or https?

@nmahadevuni
Copy link
Member Author

A noob question. What's the value of internal-communication.shared-secret, and is it always used when https is enabled? CC: @neeradsomanchi @pranjalssh

It can be any value. A large random value is generally recommended. The same value should be added to all nodes' config properties. With this PR, it will become mandatory to use shared secret when HTTPS is enabled(which is the case when external authentication is used or for secure internal communication). The nodes will fail to start if shared secret is not set when HTTPS is used. I will add documentation change soon.

@amitkdutta
Copy link
Contributor

A noob question. What's the value of internal-communication.shared-secret, and is it always used when https is enabled? CC: @neeradsomanchi @pranjalssh

It can be any value. A large random value is generally recommended. The same value should be added to all nodes' config properties. With this PR, it will become mandatory to use shared secret when HTTPS is enabled(which is the case when external authentication is used or for secure internal communication). The nodes will fail to start if shared secret is not set when HTTPS is used. I will add documentation change soon.

@nmahadevuni
It might be useful to make it optional initially. We need to figure out how to deploy it. We also need to pass this secret in native worker. Currently it takes following properties:

https://github.com/prestodb/presto/blob/master/presto-native-execution/presto_cpp/main/http/HttpServer.cpp#L112C11-L117

In wangle::SSLContextConfig
https://github.com/facebook/wangle/blob/main/wangle/ssl/SSLContextConfig.h#L53-L56

I see they have following properties

    std::string certPath;
    std::string keyPath;
    std::string passwordPath;
    bool isBuffer{false};

Is this shared secret maps to passworkdPath?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global AuthenticationFilter(part of the airlift module) was bound in the HttpServerModule. We had to enhance this AuthenticationFilter to use the new InternalAuthenticationManager. So I copied over the HttpServerModule to presto and bind the new AuthenticationFilter here.

Copy link
Contributor

@ajaygeorge ajaygeorge May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't had a chance to read through the entire code, so I maybe completely off here :) .
If binding in a new filter is the concern, can't we do something similar to what ranger module did for wiring in RangerBasicAuthHttpRequestFilter

httpClientBinder(binder).bindHttpClient("ranger", ForRangerInfo.class)
.withConfigDefaults(config -> config.setAuthenticationEnabled(false))
.withFilter(RangerBasicAuthHttpRequestFilter.class);
}

Copy link
Member Author

@nmahadevuni nmahadevuni May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did something similar, added below line of code in ServerSecurityModule to bind the new filter, but it didn't take effect.
newSetBinder(binder, Filter.class, TheServlet.class).addBinding() .to(AuthenticationFilter.class).in(Scopes.SINGLETON);

There is a HttpServerBinder too, but that doesn't have any method to bind Filter class.

@nmahadevuni
Copy link
Member Author

A noob question. What's the value of internal-communication.shared-secret, and is it always used when https is enabled? CC: @neeradsomanchi @pranjalssh

It can be any value. A large random value is generally recommended. The same value should be added to all nodes' config properties. With this PR, it will become mandatory to use shared secret when HTTPS is enabled(which is the case when external authentication is used or for secure internal communication). The nodes will fail to start if shared secret is not set when HTTPS is used. I will add documentation change soon.

@nmahadevuni It might be useful to make it optional initially. We need to figure out how to deploy it. We also need to pass this secret in native worker. Currently it takes following properties:

https://github.com/prestodb/presto/blob/master/presto-native-execution/presto_cpp/main/http/HttpServer.cpp#L112C11-L117

In wangle::SSLContextConfig https://github.com/facebook/wangle/blob/main/wangle/ssl/SSLContextConfig.h#L53-L56

I see they have following properties

    std::string certPath;
    std::string keyPath;
    std::string passwordPath;
    bool isBuffer{false};

Is this shared secret maps to passworkdPath?

passwordPath is not shared secret. JWT is a new kind of authentication which kind of overrides the certificate based authentication. I will try to make this optional.

@nmahadevuni nmahadevuni force-pushed the internal_communication_auth_fix branch 2 times, most recently from 62550c2 to 3c5f1fd Compare May 26, 2023 04:38
Copy link
Member

@skairali skairali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems working in my testing

@tdcmeehan
Copy link
Contributor

Please add a release note

@nmahadevuni
Copy link
Member Author

Please add a release note

@tdcmeehan Added a release note. Please review.

@tdcmeehan
Copy link
Contributor

Will merge tomorrow unless there's any more objections CC: @ajaygeorge @pranjalssh @amitkdutta

@ajaygeorge ajaygeorge requested a review from zacw7 June 15, 2023 17:44
Copy link
Member

@zacw7 zacw7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the change. I don't see issues % a couple nits. Will let the experts make the call.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this variable used anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Will remove it.

Comment on lines +300 to +303
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there method used anywhere? Also I'm not sure if this is the right place as I couldn't find similar usage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this method is annotated with AssertTrue, so it will be checked at server startup. Keeping it.

@wanglinsong wanglinsong mentioned this pull request Jul 27, 2023
28 tasks
czentgr added a commit to czentgr/presto that referenced this pull request Oct 4, 2023
Adding creation and verification of a JWT signed using HMAC SHA-256.
The JWT is used for authentication of internal communication.
On the Java side PR prestodb#19706 added authentication for internal
communication using a JWT token signed with HMAC SHA-256.

Adding this comment enables Prestissimo to to be configured
to verify internal communication requests, e.g from a Java
coordinator.

New system configuration options:
 - internal-communication.jwt.enabled=[true/false]
 - internal-communication.shared-secret=<shared-secret-value>
 - internal-communication.jwt.expiration-seconds=<value in seconds>

A new external dependency jet-cpp from the https://github.com/Thalhammer/jwt-cpp
repo is added to a new setup-adapter.sh script for Prestissimo.
In the dependency directory run
"<path to presto-native-execution>/scripts/setup-adapter.sh jwt" to install it
The jwt-cpp project handles the creation/parsing/verification of the JWT.

A new build options are added to the build environment:
PRESTO_ENABLE_JWT - default off, if on adds jet creation and verification capability,
 turned on during the pipeline build.
majetideepak pushed a commit that referenced this pull request Oct 4, 2023
Adding creation and verification of a JWT signed using HMAC SHA-256.
The JWT is used for authentication of internal communication.
On the Java side PR #19706 added authentication for internal
communication using a JWT token signed with HMAC SHA-256.

Adding this comment enables Prestissimo to to be configured
to verify internal communication requests, e.g from a Java
coordinator.

New system configuration options:
 - internal-communication.jwt.enabled=[true/false]
 - internal-communication.shared-secret=<shared-secret-value>
 - internal-communication.jwt.expiration-seconds=<value in seconds>

A new external dependency jet-cpp from the https://github.com/Thalhammer/jwt-cpp
repo is added to a new setup-adapter.sh script for Prestissimo.
In the dependency directory run
"<path to presto-native-execution>/scripts/setup-adapter.sh jwt" to install it
The jwt-cpp project handles the creation/parsing/verification of the JWT.

A new build options are added to the build environment:
PRESTO_ENABLE_JWT - default off, if on adds jet creation and verification capability,
 turned on during the pipeline build.
wypb pushed a commit to wypb/presto that referenced this pull request Dec 22, 2023
Adding creation and verification of a JWT signed using HMAC SHA-256.
The JWT is used for authentication of internal communication.
On the Java side PR prestodb#19706 added authentication for internal
communication using a JWT token signed with HMAC SHA-256.

Adding this comment enables Prestissimo to to be configured
to verify internal communication requests, e.g from a Java
coordinator.

New system configuration options:
 - internal-communication.jwt.enabled=[true/false]
 - internal-communication.shared-secret=<shared-secret-value>
 - internal-communication.jwt.expiration-seconds=<value in seconds>

A new external dependency jet-cpp from the https://github.com/Thalhammer/jwt-cpp
repo is added to a new setup-adapter.sh script for Prestissimo.
In the dependency directory run
"<path to presto-native-execution>/scripts/setup-adapter.sh jwt" to install it
The jwt-cpp project handles the creation/parsing/verification of the JWT.

A new build options are added to the build environment:
PRESTO_ENABLE_JWT - default off, if on adds jet creation and verification capability,
 turned on during the pipeline build.
kaikalur pushed a commit to kaikalur/presto that referenced this pull request Mar 14, 2024
Adding creation and verification of a JWT signed using HMAC SHA-256.
The JWT is used for authentication of internal communication.
On the Java side PR prestodb#19706 added authentication for internal
communication using a JWT token signed with HMAC SHA-256.

Adding this comment enables Prestissimo to to be configured
to verify internal communication requests, e.g from a Java
coordinator.

New system configuration options:
 - internal-communication.jwt.enabled=[true/false]
 - internal-communication.shared-secret=<shared-secret-value>
 - internal-communication.jwt.expiration-seconds=<value in seconds>

A new external dependency jet-cpp from the https://github.com/Thalhammer/jwt-cpp
repo is added to a new setup-adapter.sh script for Prestissimo.
In the dependency directory run
"<path to presto-native-execution>/scripts/setup-adapter.sh jwt" to install it
The jwt-cpp project handles the creation/parsing/verification of the JWT.

A new build options are added to the build environment:
PRESTO_ENABLE_JWT - default off, if on adds jet creation and verification capability,
 turned on during the pipeline build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When we enable internal communication TLS and custom AUTH together presto is failing

8 participants