-
Notifications
You must be signed in to change notification settings - Fork 7.3k
ZOOKEEPER-1112: Add support for C client for SASL authentication #1054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…apache#1 This first patch implements the zookeeper sasl operations, extends the zkServer.sh test script with the ability to start a sasl enabled server and adds a test that checks the initial DIGEST-MD5 response. It introduces no external requirements but provides zoo_sasl/zoo_asasl functions that allow applications (or the addon from patch apache#2) to communicate with the sasl server backend. Patch apache#2 will add a simple api for sasl authentication, patch apache#3 includes a sasl enabled command line client. (Forward-ported from https://reviews.apache.org/r/2252/ by Damien Diederen.)
8986320
to
4fb8f97
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something we should have soon!
Thank you
I am not a C expert so I can't tell much about that part.
I left one comment for the java part and for the zkServer.sh script
zookeeper-server/src/main/java/org/apache/zookeeper/util/SecurityUtils.java
Outdated
Show resolved
Hide resolved
4fb8f97
to
8d884e4
Compare
The explicit QOP setting had been added with a comment specifying that Sasl.QOP="auth" was not set by the 1.6 JRE. More recent JREs, such as 1.8, properly set QOP to "auth" by default, and both Cyrus SASL and Perl's Authen::SASL have been verified to be okay with it. The patch also included 'auth-conf' and 'auth-int' in the preferences list; the reason for that is unclear. It also seems incorrect, as the wire protocol does not provide checksums nor encryption. (The plan is to carry everything over TLS anyway; perhaps QOP should be set to that triple when TLS is active?) apache#1054 (comment)
…apache#2 2nd patch * provides a simple api for sasl authentication (zoo_sasl_init, zoo_sasl_connect, zoo_sasl_authenticate) * requires libsasl2 (and plugins) * autoconf/make configuration * test for digest-md5 authentication * extended configuration for digest-md5 sasl server required by sasl2 (Forward-ported from https://reviews.apache.org/r/2315/ by Damien Diederen.)
…apache#3 3rd patch * includes a sasl-enabled cli as additional make artifacts When using the test configuration as in tests/jaas.digest.server.conf you can login via: cli_sasl_st -u super -h zk-sasl-md5 -m DIGEST-MD5 hostlist and password 'test'. If you set up Kerberos 5 on the server side and have a valid ticket its just: cli_sasl_st -m GSSAPI hostlist (Forward-ported from ticket attachment ZOOKEEPER-1112_3.patch by Damien Diederen.)
The explicit QOP setting had been added with a comment specifying that Sasl.QOP="auth" was not set by the 1.6 JRE. More recent JREs, such as 1.8, properly set QOP to "auth" by default, and both Cyrus SASL and Perl's Authen::SASL have been verified to be okay with it. The patch also included 'auth-conf' and 'auth-int' in the preferences list; the reason for that is unclear. It also seems incorrect, as the wire protocol does not provide checksums nor encryption. (The plan is to carry everything over TLS anyway; perhaps QOP should be set to that triple when TLS is active?) apache#1054 (comment)
The Cyrus SASL library expects us to pass type-punned pointers!
…a file This patch adds a -f <FILE> flag to the SASL test client. When used, the client extracts the first line of <FILE> (without newline) when a password is requested. E.g.: cli_sasl_st -u super -f super.secret -h zk-sasl-md5 -m DIGEST-MD5 hostlist
…tion The 'sasl_completion_ctx' structure cannot be freed directly after queuing the SASL request, as the data is not copied and the callback otherwise causes an use-after-free. It turns out we don't really need to allocate a new data structure, anyway: the only pointer which has to make it through is the SASL zoo_sasl_conn_t, and it has such a lifetime which makes it okay to store in the completion's data field.
(Forward-ported by Damien Diederen from a patch of Charles-Henri de Boysson's. All mistakes are mine.)
8d884e4
to
5889b65
Compare
Hi @eolivelli, I have respun this series once more with a number of improvements and cleanups—including a patch from @ceache. Could you suggest somebody to "ping" for a review of the C code? (Also: don't hesitate to let me know if you would like me to split this PR in three: 1/ fundamental ZK API, 2/ Cyrus SASL binding, and 3/ SASL client example.) |
As mentioned in #1054 (comment) : There is a `sleep 3` statement in `zkServer.sh restart`. I am unable to unearth the history of that particular line, but I believe part—if not all—of that sleep should be part of `zkServer.sh stop`. I frequently observe `FAILED TO START` errors in the C test suite; the logs consistently show that those are caused by `java.net.BindException: Address already in use`. Adding a simple `sleep 1` before `echo STOPPED` "fixes" it for me. As noted in the commit message, the `sleep` is far from optimal, an adaptive mechanism would be better—but I do not want to make the first iteration too complicated. Author: Damien Diederen <dd@crosstwine.com> Reviewers: Enrico Olivelli <eolivelli@apache.org>, Norbert Kalmar <nkalmar@apache.org> Closes #1055 from ztzg/ZOOKEEPER-3510-zkserver-stop-delay
As mentioned in #1054 (comment) : There is a `sleep 3` statement in `zkServer.sh restart`. I am unable to unearth the history of that particular line, but I believe part—if not all—of that sleep should be part of `zkServer.sh stop`. I frequently observe `FAILED TO START` errors in the C test suite; the logs consistently show that those are caused by `java.net. 8000 BindException: Address already in use`. Adding a simple `sleep 1` before `echo STOPPED` "fixes" it for me. As noted in the commit message, the `sleep` is far from optimal, an adaptive mechanism would be better—but I do not want to make the first iteration too complicated. Author: Damien Diederen <dd@crosstwine.com> Reviewers: Enrico Olivelli <eolivelli@apache.org>, Norbert Kalmar <nkalmar@apache.org> Closes #1055 from ztzg/ZOOKEEPER-3510-zkserver-stop-delay (cherry picked from commit 942213d) Signed-off-by: Norbert Kalmar <nkalmar@apache.org>
The explicit QOP setting had been added with a comment specifying that Sasl.QOP="auth" was not set by the 1.6 JRE. More recent JREs, such as 1.8, properly set QOP to "auth" by default, and both Cyrus SASL and Perl's Authen::SASL have been verified to be okay with it. The patch also included 'auth-conf' and 'auth-int' in the preferences list; the reason for that is unclear. It also seems incorrect, as the wire protocol does not provide checksums nor encryption. (The plan is to carry everything over TLS anyway; perhaps QOP should be set to that triple when TLS is active?) apache#1054 (comment)
As mentioned in apache#1054 (comment) : There is a `sleep 3` statement in `zkServer.sh restart`. I am unable to unearth the history of that particular line, but I believe part—if not all—of that sleep should be part of `zkServer.sh stop`. I frequently observe `FAILED TO START` errors in the C test suite; the logs consistently show that those are caused by `java.net.BindException: Address already in use`. Adding a simple `sleep 1` before `echo STOPPED` "fixes" it for me. As noted in the commit message, the `sleep` is far from optimal, an adaptive mechanism would be better—but I do not want to make the first iteration too complicated. Author: Damien Diederen <dd@crosstwine.com> Reviewers: Enrico Olivelli <eolivelli@apache.org>, Norbert Kalmar <nkalmar@apache.org> Closes apache#1055 from ztzg/ZOOKEEPER-3510-zkserver-stop-delay
The explicit QOP setting had been added with a comment specifying that Sasl.QOP="auth" was not set by the 1.6 JRE. More recent JREs, such as 1.8, properly set QOP to "auth" by default, and both Cyrus SASL and Perl's Authen::SASL have been verified to be okay with it. The patch also included 'auth-conf' and 'auth-int' in the preferences list; the reason for that is unclear. It also seems incorrect, as the wire protocol does not provide checksums nor encryption. (The plan is to carry everything over TLS anyway; perhaps QOP should be set to that triple when TLS is active?) apache#1054 (comment)
Greetings, all, I am withdrawing this pull request for now. We had to rework the mechanism to enable automatic SASL authentication on reconnect without "abusing" the global watcher. I have a proof of concept, and intend to submit a cleaned-up new patch after further testing. (No ETA, though, as I am currently focused on other topics. Holler up if there is interest and I am too slow.) Thanks, -D |
…ibrary This is a "respin" of #1054, which I withdrew due to some annoying shortcomings. This changeset allows C clients to use SASL to authenticate with the ZooKeeper server. It is loosely based on patches #1 and #2 by Tom Klonikowski, at https://reviews.apache.org/r/2252/, but the result has been extensively reworked to follow the semantics of the Java client: * No SASL operations are exposed through the API; * The configuration is provided, and stored, at "handle init time"; * SASL authentication is automatically performed after each (re)connect. It introduces an optional dependency on the Cyrus SASL library, which can either be autodetected (default) or configured using the `--without-sasl`/`--with-sasl[=DIR]` flags, or -DWITH_CYRUS_SASL for CMake/Windows. `TestServerRequireClientSASLAuth.cc` has been renamed to `TestSASLAuth.cc`, and a test has been added which successfully (re)authenticates using the `DIGEST-MD5` mechanism. The code has also been used to successfully authenticate clients via `GSSAPI`/Kerberos. This commit also adds SASL support to the `cli.c` client. Co-authored-by: Tom Klonikowski <klonik_tinformatik.haw-hamburg.de> Author: Damien Diederen <dd@crosstwine.com> Reviewers: Mate Szalay-Beko <szalay.beko.mate@gmail.com>, Norbert Kalmar <nkalmar@apache.org> Closes #1134 from ztzg/ZOOKEEPER-1112-c-client-sasl-support-v2
…ibrary This is a "respin" of apache#1054, which I withdrew due to some annoying shortcomings. This changeset allows C clients to use SASL to authenticate with the ZooKeeper server. It is loosely based on patches #1 and #2 by Tom Klonikowski, at https://reviews.apache.org/r/2252/, but the result has been extensively reworked to follow the semantics of the Java client: * No SASL operations are exposed through the API; * The configuration is provided, and stored, at "handle init time"; * SASL authentication is automatically performed after each (re)connect. It introduces an optional dependency on the Cyrus SASL library, which can either be autodetected (default) or configured using the `--without-sasl`/`--with-sasl[=DIR]` flags, or -DWITH_CYRUS_SASL for CMake/Windows. `TestServerRequireClientSASLAuth.cc` has been renamed to `TestSASLAuth.cc`, and a test has been added which successfully (re)authenticates using the `DIGEST-MD5` mechanism. The code has also been used to successfully authenticate clients via `GSSAPI`/Kerberos. This commit also adds SASL support to the `cli.c` client. Co-authored-by: Tom Klonikowski <klonik_tinformatik.haw-hamburg.de> Author: Damien Diederen <dd@crosstwine.com> Reviewers: Mate Szalay-Beko <szalay.beko.mate@gmail.com>, Norbert Kalmar <nkalmar@apache.org> Closes apache#1134 from ztzg/ZOOKEEPER-1112-c-client-sasl-support-v2
As mentioned in apache#1054 (comment) : There is a `sleep 3` statement in `zkServer.sh restart`. I am unable to unearth the history of that particular line, but I believe part—if not all—of that sleep should be part of `zkServer.sh stop`. I frequently observe `FAILED TO START` errors in the C test suite; the logs consistently show that those are caused by `java.net.BindException: Address already in use`. Adding a simple `sleep 1` before `echo STOPPED` "fixes" it for me. As noted in the commit message, the `sleep` is far from optimal, an adaptive mechanism would be better—but I do not want to make the first iteration too complicated. Author: Damien Diederen <dd@crosstwine.com> Reviewers: Enrico Olivelli <eolivelli@apache.org>, Norbert Kalmar <nkalmar@apache.org> Closes apache#1055 from ztzg/ZOOKEEPER-3510-zkserver-stop-delay
…ibrary This is a "respin" of apache#1054, which I withdrew due to some annoying shortcomings. This changeset allows C clients to use SASL to authenticate with the ZooKeeper server. It is loosely based on patches #1 and #2 by Tom Klonikowski, at https://reviews.apache.org/r/2252/, but the result has been extensively reworked to follow the semantics of the Java client: * No SASL operations are exposed through the API; * The configuration is provided, and stored, at "handle init time"; * SASL authentication is automatically performed after each (re)connect. It introduces an optional dependency on the Cyrus SASL library, which can either be autodetected (default) or configured using the `--without-sasl`/`--with-sasl[=DIR]` flags, or -DWITH_CYRUS_SASL for CMake/Windows. `TestServerRequireClientSASLAuth.cc` has been renamed to `TestSASLAuth.cc`, and a test has been added which successfully (re)authenticates using the `DIGEST-MD5` mechanism. The code has also been used to successfully authenticate clients via `GSSAPI`/Kerberos. This commit also adds SASL support to the `cli.c` client. Co-authored-by: Tom Klonikowski <klonik_tinformatik.haw-hamburg.de> Author: Damien Diederen <dd@crosstwine.com> Reviewers: Mate Szalay-Beko <szalay.beko.mate@gmail.com>, Norbert Kalmar <nkalmar@apache.org> Closes apache#1134 from ztzg/ZOOKEEPER-1112-c-client-sasl-support-v2
As mentioned in apache#1054 (comment) : There is a `sleep 3` statement in `zkServer.sh restart`. I am unable to unearth the history of that particular line, but I believe part—if not all—of that sleep should be part of `zkServer.sh stop`. I frequently observe `FAILED TO START` errors in the C test suite; the logs consistently show that those are caused by `java.net.BindException: Address already in use`. Adding a simple `sleep 1` before `echo STOPPED` "fixes" it for me. As noted in the commit message, the `sleep` is far from optimal, an adaptive mechanism would be better—but I do not want to make the first iteration too complicated. Author: Damien Diederen <dd@crosstwine.com> Reviewers: Enrico Olivelli <eolivelli@apache.org>, Norbert Kalmar <nkalmar@apache.org> Closes apache#1055 from ztzg/ZOOKEEPER-3510-zkserver-stop-delay
…ibrary This is a "respin" of apache#1054, which I withdrew due to some annoying shortcomings. This changeset allows C clients to use SASL to authenticate with the ZooKeeper server. It is loosely based on patches #1 and #2 by Tom Klonikowski, at https://reviews.apache.org/r/2252/, but the result has been extensively reworked to follow the semantics of the Java client: * No SASL operations are exposed through the API; * The configuration is provided, and stored, at "handle init time"; * SASL authentication is automatically performed after each (re)connect. It introduces an optional dependency on the Cyrus SASL library, which can either be autodetected (default) or configured using the `--without-sasl`/`--with-sasl[=DIR]` flags, or -DWITH_CYRUS_SASL for CMake/Windows. `TestServerRequireClientSASLAuth.cc` has been renamed to `TestSASLAuth.cc`, and a test has been added which successfully (re)authenticates using the `DIGEST-MD5` mechanism. The code has also been used to successfully authenticate clients via `GSSAPI`/Kerberos. This commit also adds SASL support to the `cli.c` client. Co-authored-by: Tom Klonikowski <klonik_tinformatik.haw-hamburg.de> Author: Damien Diederen <dd@crosstwine.com> Reviewers: Mate Szalay-Beko <szalay.beko.mate@gmail.com>, Norbert Kalmar <nkalmar@apache.org> Closes apache#1134 from ztzg/ZOOKEEPER-1112-c-client-sasl-support-v2
As mentioned in apache#1054 (comment) : There is a `sleep 3` statement in `zkServer.sh restart`. I am unable to unearth the history of that particular line, but I believe part—if not all—of that sleep should be part of `zkServer.sh stop`. I frequently observe `FAILED TO START` errors in the C test suite; the logs consistently show that those are caused by `java.net.BindException: Address already in use`. Adding a simple `sleep 1` before `echo STOPPED` "fixes" it for me. As noted in the commit message, the `sleep` is far from optimal, an adaptive mechanism would be better—but I do not want to make the first iteration too complicated. Author: Damien Diederen <dd@crosstwine.com> Reviewers: Enrico Olivelli <eolivelli@apache.org>, Norbert Kalmar <nkalmar@apache.org> Closes apache#1055 from ztzg/ZOOKEEPER-3510-zkserver-stop-delay
…ibrary This is a " 6D40 respin" of apache#1054, which I withdrew due to some annoying shortcomings. This changeset allows C clients to use SASL to authenticate with the ZooKeeper server. It is loosely based on patches #1 and #2 by Tom Klonikowski, at https://reviews.apache.org/r/2252/, but the result has been extensively reworked to follow the semantics of the Java client: * No SASL operations are exposed through the API; * The configuration is provided, and stored, at "handle init time"; * SASL authentication is automatically performed after each (re)connect. It introduces an optional dependency on the Cyrus SASL library, which can either be autodetected (default) or configured using the `--without-sasl`/`--with-sasl[=DIR]` flags, or -DWITH_CYRUS_SASL for CMake/Windows. `TestServerRequireClientSASLAuth.cc` has been renamed to `TestSASLAuth.cc`, and a test has been added which successfully (re)authenticates using the `DIGEST-MD5` mechanism. The code has also been used to successfully authenticate clients via `GSSAPI`/Kerberos. This commit also adds SASL support to the `cli.c` client. Co-authored-by: Tom Klonikowski <klonik_tinformatik.haw-hamburg.de> Author: Damien Diederen <dd@crosstwine.com> Reviewers: Mate Szalay-Beko <szalay.beko.mate@gmail.com>, Norbert Kalmar <nkalmar@apache.org> Closes apache#1134 from ztzg/ZOOKEEPER-1112-c-client-sasl-support-v2
This is a forward-port of Tom Klonikowski's (@kloni) ZOOKEEPER-1112 patches on top of the current
master
branch.It stays close to the original patches, and only adds a number of commits on top:
Open questions:
The patches add an optional dependency on the Cyrus SASL library.
Eric Yang wrote:
Who should take care of this? Is there an established procedure?
Tom Klonikowski wrote:
What do you think?
Should
cli_sasl_{st,mt}
be folded back intocli_{st,mt}
?The existing tests as well as the added SASL tests pass in
st
andmt
modes. Bothcli_sasl_*
utilities have been tested against aDIGEST-MD5
server; I intend to test them against a GSSAPI one in the near future.