You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by RaghavendraNandagopal <gi...@git.apache.org> on 2014/07/22 22:50:30 UTC
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
GitHub user RaghavendraNandagopal opened a pull request:
https://github.com/apache/incubator-storm/pull/202
STORM-348: Netty SASL Authentication
Hi Bobby,
I have made the changes for the SASL Netty Authentication. Currently the credentials used is with the topology name, but I thought I would be using Kerberos token instead as we agreed I will use randomly generated credentials that are kept in zookeeper. I will try to find it out which method to call or if you can help me out it would be great. In the meantime you can review the changes.
I have tested the changes but didn't create the unit tests. I will create a separate JIRA for unit test and get it done. I am learning Clojure and will get it done soon.
Thanks,
Raghavendra Nandagopal
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/RaghavendraNandagopal/incubator-storm security
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-storm/pull/202.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #202
----
commit 41986445fb89ff77c101fcdd6daccb945160e8a9
Author: Raghavendra Nandagopal <sp...@gmail.com>
Date: 2014-07-22T20:20:54Z
STORM-348: Netty SASL Authentication
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15409160
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/StormServerPipelineFactory.java ---
@@ -33,13 +36,27 @@ public ChannelPipeline getPipeline() throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = Channels.pipeline();
- // Decoder
- pipeline.addLast("decoder", new MessageDecoder());
- // Encoder
- pipeline.addLast("encoder", new MessageEncoder());
- // business logic.
- pipeline.addLast("handler", new StormServerHandler(server));
-
+ boolean isNettyAuth = (Boolean) this.server.storm_conf.get(Config.STORM_MESSAGING_NETTY_AUTHENTICATION);
+ if(isNettyAuth) {
+ // Decoder
+ pipeline.addLast("decoder", new MessageDecoder());
+ // Encoder
+ pipeline.addLast("encoder", new MessageEncoder());
+ // Authenticate: Removed after authentication completes
+ pipeline.addLast("saslServerHandler", new SaslStormServerHandler(server));
+ // Authorize
+ pipeline.addLast("authorizeServerHandler", new SaslStormServerAuthorizeHandler());
+ // business logic.
+ pipeline.addLast("handler", new StormServerHandler(server));
+ } else {
+ // Decoder
+ pipeline.addLast("decoder", new MessageDecoder());
+ // Encoder
+ pipeline.addLast("encoder", new MessageEncoder());
+ // business logic.
+ pipeline.addLast("handler", new StormServerHandler(server));
+ }
+
--- End diff --
Similar here, could we try to combine as much of the if/else blocks together do that the sasl handling is the only thing in the if block.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by RaghavendraNandagopal <gi...@git.apache.org>.
Github user RaghavendraNandagopal commented on the pull request:
https://github.com/apache/incubator-storm/pull/202#issuecomment-50550500
Should I make any changes to fix the configs or will it be taken care.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15408278
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/SaslStormClientHandler.java ---
@@ -0,0 +1,155 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package backtype.storm.messaging.netty;
+
+import java.io.IOException;
+
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelStateEvent;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import backtype.storm.Config;
+
+public class SaslStormClientHandler extends SimpleChannelUpstreamHandler {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SaslStormClientHandler.class);
+ private Client client;
+ long start_time;
+ /** Used for client or server's token to send or receive from each other. */
+ private byte[] token;
+ private String topologyName;
+
+ public SaslStormClientHandler(Client client) throws IOException {
+ this.client = client;
+ start_time = System.currentTimeMillis();
+ getSASLCredentials();
+ }
+
+ @Override
+ public void channelConnected(ChannelHandlerContext ctx,
+ ChannelStateEvent event) {
+ // register the newly established channel
+ Channel channel = ctx.getChannel();
+
+ LOG.info("Connection established from " + channel.getLocalAddress()
+ + " to " + channel.getRemoteAddress());
+
+ try {
+ SaslNettyClient saslNettyClient = SaslNettyClientState.getSaslNettyClient
+ .get(channel);
+
+ if (saslNettyClient == null) {
+ LOG.debug("Creating saslNettyClient now " + "for channel: "
+ + channel);
+ saslNettyClient = new SaslNettyClient(topologyName, token);
+ SaslNettyClientState.getSaslNettyClient.set(channel,
+ saslNettyClient);
+ }
+ channel.write(ControlMessage.SASL_TOKEN_MESSAGE_REQUEST);
+ } catch (Exception e) {
+ LOG.error("Failed to authenticate with server " + "due to error: "
+ + e);
+ }
+ return;
+
+ }
+
+ @Override
+ public void messageReceived(ChannelHandlerContext ctx, MessageEvent event)
+ throws Exception {
+ LOG.debug("send/recv time (ms): {}",
+ (System.currentTimeMillis() - start_time));
+
+ Channel channel = ctx.getChannel();
+
+ // Generate SASL response to server using Channel-local SASL client.
+ SaslNettyClient saslNettyClient = SaslNettyClientState.getSaslNettyClient
+ .get(channel);
+ if (saslNettyClient == null) {
+ throw new Exception("saslNettyClient was unexpectedly "
+ + "null for channel: " + channel);
+ }
+
+ // examine the response message from server
+ if (event.getMessage() instanceof ControlMessage) {
+ ControlMessage msg = (ControlMessage) event.getMessage();
+ if (msg == ControlMessage.SASL_COMPLETE_REQUEST) {
+ LOG.debug("Server has sent us the SaslComplete "
+ + "message. Allowing normal work to proceed.");
+
+ if (!saslNettyClient.isComplete()) {
+ LOG.error("Server returned a Sasl-complete message, "
+ + "but as far as we can tell, we are not authenticated yet.");
+ throw new Exception("Server returned a "
+ + "Sasl-complete message, but as far as "
+ + "we can tell, we are not authenticated yet.");
+ }
+ ctx.getPipeline().remove(this);
+ // We call fireMessageReceived since the client is allowed to
+ // perform this request. The client's request will now proceed
+ // to the next pipeline component namely StormClientHandler.
+ Channels.fireMessageReceived(ctx, msg);
+ return;
+ }
+ }
+ SaslMessageToken saslTokenMessage = (SaslMessageToken) event
+ .getMessage();
+ LOG.debug("Responding to server's token of length: "
+ + saslTokenMessage.getSaslToken().length);
+
+ // Generate SASL response (but we only actually send the response if
+ // it's non-null.
+ byte[] responseToServer = saslNettyClient
+ .saslResponse(saslTokenMessage);
+ if (responseToServer == null) {
+ // If we generate a null response, then authentication has completed
+ // (if not, warn), and return without sending a response back to the
+ // server.
+ LOG.debug("Response to server is null: "
+ + "authentication should now be complete.");
+ if (!saslNettyClient.isComplete()) {
+ LOG.warn("Generated a null response, "
--- End diff --
Do we want to throw an exception in this case? Like we do above.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on the pull request:
https://github.com/apache/incubator-storm/pull/202#issuecomment-50637878
It all looks good I am +1. I'll merge this into the security branch shortly.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by RaghavendraNandagopal <gi...@git.apache.org>.
Github user RaghavendraNandagopal commented on the pull request:
https://github.com/apache/incubator-storm/pull/202#issuecomment-50089308
Hi Bobby,
I have made the changes for SASL credentials to accept zookeeper secret key that is being generated for a given topology.
Also if you need to run it you need to set the configuration parameter for a topology as below.
storm.messaging.netty.authentication=true
Thanks,
Raghavendra Nandagopal
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/incubator-storm/pull/202
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on the pull request:
https://github.com/apache/incubator-storm/pull/202#issuecomment-50550303
I forgot to add that after you update the tests I am +1 for merging this in.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by RaghavendraNandagopal <gi...@git.apache.org>.
Github user RaghavendraNandagopal commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15431022
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/SaslNettyClient.java ---
@@ -0,0 +1,166 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package backtype.storm.messaging.netty;
+
+import java.io.IOException;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.sasl.RealmCallback;
+import javax.security.sasl.RealmChoiceCallback;
+import javax.security.sasl.Sasl;
+import javax.security.sasl.SaslClient;
+import javax.security.sasl.SaslException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implements SASL logic for storm worker client processes.
+ */
+public class SaslNettyClient {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SaslNettyClient.class);
+
+ /**
+ * Used to respond to server's counterpart, SaslServer with SASL tokens
+ * represented as byte arrays.
+ */
+ private SaslClient saslClient;
+
+ /**
+ * Create a SaslNettyClient for authentication with servers.
+ */
+ public SaslNettyClient(String topologyName, byte[] token) {
+ try {
+ LOG.debug("SaslNettyClient: Creating SASL "
+ + SaslUtils.AUTH_DIGEST_MD5
+ + " client to authenticate to server ");
+
+ saslClient = Sasl.createSaslClient(
+ new String[] { SaslUtils.AUTH_DIGEST_MD5 }, null, null,
+ SaslUtils.DEFAULT_REALM, SaslUtils.getSaslProps(),
+ new SaslClientCallbackHandler(topologyName, token));
+
+ } catch (IOException e) {
+ LOG.error("SaslNettyClient: Could not obtain topology token for Netty "
+ + "Client to use to authenticate with a Netty Server.");
+ saslClient = null;
--- End diff --
The createSaslClient() method throws IOException and we just log it and make the saslClient object null which will end up with NPEs. Is there anything that we need to take care?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by RaghavendraNandagopal <gi...@git.apache.org>.
Github user RaghavendraNandagopal commented on the pull request:
https://github.com/apache/incubator-storm/pull/202#issuecomment-50416955
Hi Bobby,
I have made all the changes mentioned above and provided the comments for specific questions.
I will look at the wrap/unwrap functionality within SASL and in the meantime if you can review and provide your comments on the basic SASL functionality.
Thanks,
Raghavendra Nandagopal
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by RaghavendraNandagopal <gi...@git.apache.org>.
Github user RaghavendraNandagopal commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15480490
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/SaslUtils.java ---
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package backtype.storm.messaging.netty;
+
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.security.sasl.Sasl;
+
+import org.apache.commons.codec.binary.Base64;
+
+import backtype.storm.Config;
+
+class SaslUtils {
+ public static final String AUTH_DIGEST_MD5 = "DIGEST-MD5";
+ public static final String DEFAULT_REALM = "default";
+
+ static Map<String, String> getSaslProps() {
+ Map<String, String> props = new HashMap<String, String>();
+ props.put(Sasl.POLICY_NOPLAINTEXT, "true");
+ return props;
+ }
+
+ /**
+ * Encode a password as a base64-encoded char[] array.
+ *
+ * @param password
+ * as a byte array.
+ * @return password as a char array.
+ */
+ static char[] encodePassword(byte[] password) {
+ return new String(Base64.encodeBase64(password),
+ Charset.defaultCharset()).toCharArray();
--- End diff --
Unfortunately, the file.encoding property has to be specified as the JVM starts up; up. The character encoding used by String.getBytes() and the default constructors of InputStreamReader and OutputStreamWriter has been permanently cached.
java -Dfile.encoding=UTF-8
Charset.defaultCharset() will reflect changes to the file.encoding property, but most of the code in the core Java libraries that need to determine the default character encoding do not use this mechanism.
When we are encoding or decoding, we have to query the file.encoding property or Charset.defaultCharset() to find the current default encoding, and use the appropriate method or constructor overload to specify it.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15408724
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/SaslUtils.java ---
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package backtype.storm.messaging.netty;
+
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.security.sasl.Sasl;
+
+import org.apache.commons.codec.binary.Base64;
+
+import backtype.storm.Config;
+
+class SaslUtils {
+ public static final String AUTH_DIGEST_MD5 = "DIGEST-MD5";
+ public static final String DEFAULT_REALM = "default";
+
+ static Map<String, String> getSaslProps() {
+ Map<String, String> props = new HashMap<String, String>();
+ props.put(Sasl.POLICY_NOPLAINTEXT, "true");
+ return props;
+ }
+
+ /**
+ * Encode a password as a base64-encoded char[] array.
+ *
+ * @param password
+ * as a byte array.
+ * @return password as a char array.
+ */
+ static char[] encodePassword(byte[] password) {
+ return new String(Base64.encodeBase64(password),
+ Charset.defaultCharset()).toCharArray();
+ }
+
+ /**
+ * Encode a identifier as a base64-encoded char[] array.
+ *
+ * @param identifier
+ * as a byte array.
+ * @return identifier as a char array.
+ */
+ static String encodeIdentifier(byte[] identifier) {
+ return new String(Base64.encodeBase64(identifier),
+ Charset.defaultCharset());
--- End diff --
UTF-8 here too.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15409108
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/StormClientPipelineFactory.java ---
@@ -32,12 +34,24 @@ public ChannelPipeline getPipeline() throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = Channels.pipeline();
- // Decoder
- pipeline.addLast("decoder", new MessageDecoder());
- // Encoder
- pipeline.addLast("encoder", new MessageEncoder());
- // business logic.
- pipeline.addLast("handler", new StormClientErrorHandler(client.name()));
+ boolean isNettyAuth = (Boolean) this.client.storm_conf.get(Config.STORM_MESSAGING_NETTY_AUTHENTICATION);
+ if(isNettyAuth) {
+ // Decoder
+ pipeline.addLast("decoder", new MessageDecoder());
+ // Encoder
+ pipeline.addLast("encoder", new MessageEncoder());
+ // Authenticate: Removed after authentication completes
+ pipeline.addLast("saslClientHandler", new SaslStormClientHandler(client));
+ // business logic.
+ pipeline.addLast("handler", new StormClientErrorHandler(client.name()));
+ } else {
+ // Decoder
+ pipeline.addLast("decoder", new MessageDecoder());
+ // Encoder
+ pipeline.addLast("encoder", new MessageEncoder());
+ // business logic.
+ pipeline.addLast("handler", new StormClientErrorHandler(client.name()));
+ }
--- End diff --
There is a lot in common between the if and else blocks. Could we try and combine them again, and just have adding the saslClientHandler be in the if block?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15407759
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/SaslStormClientHandler.java ---
@@ -0,0 +1,155 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package backtype.storm.messaging.netty;
+
+import java.io.IOException;
+
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelStateEvent;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import backtype.storm.Config;
+
+public class SaslStormClientHandler extends SimpleChannelUpstreamHandler {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SaslStormClientHandler.class);
+ private Client client;
+ long start_time;
+ /** Used for client or server's token to send or receive from each other. */
+ private byte[] token;
+ private String topologyName;
+
+ public SaslStormClientHandler(Client client) throws IOException {
+ this.client = client;
+ start_time = System.currentTimeMillis();
+ getSASLCredentials();
+ }
+
+ @Override
+ public void channelConnected(ChannelHandlerContext ctx,
+ ChannelStateEvent event) {
+ // register the newly established channel
+ Channel channel = ctx.getChannel();
+
+ LOG.info("Connection established from " + channel.getLocalAddress()
+ + " to " + channel.getRemoteAddress());
+
+ try {
+ SaslNettyClient saslNettyClient = SaslNettyClientState.getSaslNettyClient
+ .get(channel);
+
+ if (saslNettyClient == null) {
+ LOG.debug("Creating saslNettyClient now " + "for channel: "
+ + channel);
+ saslNettyClient = new SaslNettyClient(topologyName, token);
+ SaslNettyClientState.getSaslNettyClient.set(channel,
+ saslNettyClient);
+ }
+ channel.write(ControlMessage.SASL_TOKEN_MESSAGE_REQUEST);
+ } catch (Exception e) {
+ LOG.error("Failed to authenticate with server " + "due to error: "
+ + e);
--- End diff --
can we change this to a ", e" instead of a "+ e" that way we can get the stack trace in the logs too.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by RaghavendraNandagopal <gi...@git.apache.org>.
Github user RaghavendraNandagopal commented on the pull request:
https://github.com/apache/incubator-storm/pull/202#issuecomment-50559191
I have made the changes to the netty_unit_test.clj and netty_integration_test.clj files. Can you please check?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15408174
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/SaslStormClientHandler.java ---
@@ -0,0 +1,155 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package backtype.storm.messaging.netty;
+
+import java.io.IOException;
+
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelStateEvent;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import backtype.storm.Config;
+
+public class SaslStormClientHandler extends SimpleChannelUpstreamHandler {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SaslStormClientHandler.class);
+ private Client client;
+ long start_time;
+ /** Used for client or server's token to send or receive from each other. */
+ private byte[] token;
+ private String topologyName;
+
+ public SaslStormClientHandler(Client client) throws IOException {
+ this.client = client;
+ start_time = System.currentTimeMillis();
+ getSASLCredentials();
+ }
+
+ @Override
+ public void channelConnected(ChannelHandlerContext ctx,
+ ChannelStateEvent event) {
+ // register the newly established channel
+ Channel channel = ctx.getChannel();
+
+ LOG.info("Connection established from " + channel.getLocalAddress()
+ + " to " + channel.getRemoteAddress());
+
+ try {
+ SaslNettyClient saslNettyClient = SaslNettyClientState.getSaslNettyClient
+ .get(channel);
+
+ if (saslNettyClient == null) {
+ LOG.debug("Creating saslNettyClient now " + "for channel: "
+ + channel);
+ saslNettyClient = new SaslNettyClient(topologyName, token);
+ SaslNettyClientState.getSaslNettyClient.set(channel,
+ saslNettyClient);
+ }
+ channel.write(ControlMessage.SASL_TOKEN_MESSAGE_REQUEST);
+ } catch (Exception e) {
+ LOG.error("Failed to authenticate with server " + "due to error: "
+ + e);
+ }
+ return;
+
+ }
+
+ @Override
+ public void messageReceived(ChannelHandlerContext ctx, MessageEvent event)
+ throws Exception {
+ LOG.debug("send/recv time (ms): {}",
+ (System.currentTimeMillis() - start_time));
+
+ Channel channel = ctx.getChannel();
+
+ // Generate SASL response to server using Channel-local SASL client.
+ SaslNettyClient saslNettyClient = SaslNettyClientState.getSaslNettyClient
+ .get(channel);
+ if (saslNettyClient == null) {
+ throw new Exception("saslNettyClient was unexpectedly "
+ + "null for channel: " + channel);
+ }
+
+ // examine the response message from server
+ if (event.getMessage() instanceof ControlMessage) {
+ ControlMessage msg = (ControlMessage) event.getMessage();
+ if (msg == ControlMessage.SASL_COMPLETE_REQUEST) {
+ LOG.debug("Server has sent us the SaslComplete "
+ + "message. Allowing normal work to proceed.");
+
+ if (!saslNettyClient.isComplete()) {
+ LOG.error("Server returned a Sasl-complete message, "
+ + "but as far as we can tell, we are not authenticated yet.");
+ throw new Exception("Server returned a "
+ + "Sasl-complete message, but as far as "
+ + "we can tell, we are not authenticated yet.");
+ }
+ ctx.getPipeline().remove(this);
--- End diff --
Do we want to try and support the wrap/unwrap functionality in SASL? I assume we don't need to at the beginning, but some people have asked for wire encryption and this could be an option.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15409263
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/SaslStormClientHandler.java ---
@@ -0,0 +1,155 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package backtype.storm.messaging.netty;
+
+import java.io.IOException;
+
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelStateEvent;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import backtype.storm.Config;
+
+public class SaslStormClientHandler extends SimpleChannelUpstreamHandler {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SaslStormClientHandler.class);
+ private Client client;
+ long start_time;
+ /** Used for client or server's token to send or receive from each other. */
+ private byte[] token;
+ private String topologyName;
+
+ public SaslStormClientHandler(Client client) throws IOException {
+ this.client = client;
+ start_time = System.currentTimeMillis();
+ getSASLCredentials();
+ }
+
+ @Override
+ public void channelConnected(ChannelHandlerContext ctx,
+ ChannelStateEvent event) {
+ // register the newly established channel
+ Channel channel = ctx.getChannel();
+
+ LOG.info("Connection established from " + channel.getLocalAddress()
+ + " to " + channel.getRemoteAddress());
+
+ try {
+ SaslNettyClient saslNettyClient = SaslNettyClientState.getSaslNettyClient
+ .get(channel);
+
+ if (saslNettyClient == null) {
+ LOG.debug("Creating saslNettyClient now " + "for channel: "
+ + channel);
+ saslNettyClient = new SaslNettyClient(topologyName, token);
+ SaslNettyClientState.getSaslNettyClient.set(channel,
+ saslNettyClient);
+ }
+ channel.write(ControlMessage.SASL_TOKEN_MESSAGE_REQUEST);
+ } catch (Exception e) {
+ LOG.error("Failed to authenticate with server " + "due to error: "
+ + e);
+ }
+ return;
+
+ }
+
+ @Override
+ public void messageReceived(ChannelHandlerContext ctx, MessageEvent event)
+ throws Exception {
+ LOG.debug("send/recv time (ms): {}",
+ (System.currentTimeMillis() - start_time));
+
+ Channel channel = ctx.getChannel();
+
+ // Generate SASL response to server using Channel-local SASL client.
+ SaslNettyClient saslNettyClient = SaslNettyClientState.getSaslNettyClient
+ .get(channel);
+ if (saslNettyClient == null) {
+ throw new Exception("saslNettyClient was unexpectedly "
+ + "null for channel: " + channel);
+ }
+
+ // examine the response message from server
+ if (event.getMessage() instanceof ControlMessage) {
+ ControlMessage msg = (ControlMessage) event.getMessage();
+ if (msg == ControlMessage.SASL_COMPLETE_REQUEST) {
+ LOG.debug("Server has sent us the SaslComplete "
+ + "message. Allowing normal work to proceed.");
+
+ if (!saslNettyClient.isComplete()) {
+ LOG.error("Server returned a Sasl-complete message, "
+ + "but as far as we can tell, we are not authenticated yet.");
+ throw new Exception("Server returned a "
+ + "Sasl-complete message, but as far as "
+ + "we can tell, we are not authenticated yet.");
+ }
+ ctx.getPipeline().remove(this);
--- End diff --
I see now that the encoder/decoder are not SASL aware, so the wrap/unwrap would have to happen at that level, making this a bigger change.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on the pull request:
https://github.com/apache/incubator-storm/pull/202#issuecomment-50170349
I haven't had a chance to test this yet. I only have a few comments most of them are fairly minor.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on the pull request:
https://github.com/apache/incubator-storm/pull/202#issuecomment-50549920
The code looks good. The wrap/unwrap we can save for a later time. I had some very minor merge conflicts and storm-core/test/clj/backtype/storm/messaging/netty_unit_test.clj is failing for me. It looks like it needs to have STORM-MESSAGING-NETTY-AUTHENTICATION false added to all of the configs, as they are unit tests and don't pick up defaults.yaml
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on the pull request:
https://github.com/apache/incubator-storm/pull/202#issuecomment-50558624
```
diff --git a/storm-core/test/clj/backtype/storm/messaging/netty_unit_test.clj b/storm-core/test/clj/backtype/storm/messaging/netty_unit_test.clj
index ea7b8dc..c205dc3 100644
--- a/storm-core/test/clj/backtype/storm/messaging/netty_unit_test.clj
+++ b/storm-core/test/clj/backtype/storm/messaging/netty_unit_test.clj
@@ -32,6 +32,7 @@
STORM-MESSAGING-NETTY-MAX-SLEEP-MS 5000
STORM-MESSAGING-NETTY-SERVER-WORKER-THREADS 1
STORM-MESSAGING-NETTY-CLIENT-WORKER-THREADS 1
+ STORM-MESSAGING-NETTY-AUTHENTICATION false
}
context (TransportFactory/makeContext storm-conf)
server (.bind context nil port)
@@ -54,6 +55,7 @@
STORM-MESSAGING-NETTY-MAX-SLEEP-MS 5000
STORM-MESSAGING-NETTY-SERVER-WORKER-THREADS 1
STORM-MESSAGING-NETTY-CLIENT-WORKER-THREADS 1
+ STORM-MESSAGING-NETTY-AUTHENTICATION false
}
context (TransportFactory/makeContext storm-conf)
server (.bind context nil port)
@@ -76,6 +78,7 @@
STORM-MESSAGING-NETTY-MAX-SLEEP-MS 5000
STORM-MESSAGING-NETTY-SERVER-WORKER-THREADS 1
STORM-MESSAGING-NETTY-CLIENT-WORKER-THREADS 1
+ STORM-MESSAGING-NETTY-AUTHENTICATION false
}
```
is what I had to do to get the tests to pass. Otherwise I was getting NPEs in the tests. If you could update your pull request it makes tracking the changes, a lot cleaner.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15402203
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/Client.java ---
@@ -57,8 +59,10 @@
private int messageBatchSize;
private AtomicLong pendings;
+
+ Map storm_conf;
- MessageBatch messageBatch = null;
+ MessageBatch messageBatch = null;
--- End diff --
Please replace tabs with spaces.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15402272
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/Client.java ---
@@ -57,8 +59,10 @@
private int messageBatchSize;
private AtomicLong pendings;
+
+ Map storm_conf;
- MessageBatch messageBatch = null;
+ MessageBatch messageBatch = null;
--- End diff --
And please mark the new member variables as private they don't appear to need to be protected or package private.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15402428
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/SaslMessageToken.java ---
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package backtype.storm.messaging.netty;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBufferOutputStream;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Send and receive SASL tokens.
+ */
+public class SaslMessageToken {
+ /** Class logger */
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SaslMessageToken.class);
+
+ /** Used for client or server's token to send or receive from each other. */
+ private byte[] token;
+
+ /**
+ * Constructor used for reflection only.
+ */
+ public SaslMessageToken() {
+ }
+
+ /**
+ * Constructor used to send request.
+ *
+ * @param token
+ * the SASL token, generated by a SaslClient or SaslServer.
+ */
+ public SaslMessageToken(byte[] token) {
+ this.token = token;
+ }
+
+ /**
+ * Read accessor for SASL token
+ *
+ * @return saslToken SASL token
+ */
+ public byte[] getSaslToken() {
+ return token;
+ }
+
+ /**
+ * Write accessor for SASL token
+ *
+ * @param token
+ * SASL token
+ */
+ public void setSaslToken(byte[] token) {
+ this.token = token;
+ }
+
+ int encodeLength() {
+ return 2+4+token.length;
+ }
+
+ /**
+ * encode the current SaslToken Message into a channel buffer
+ * SaslTokenMessageRequest is encoded as:
+ * identifier .... short(2) always it is -500
+ * payload length .... int
+ * payload .... byte[]
+ * @throws Exception
+ */
+ ChannelBuffer buffer() throws Exception {
+ ChannelBufferOutputStream bout = new ChannelBufferOutputStream(
--- End diff --
Again it looks like you have a mixture of spaces and tabs here. In general the java files have just had spaces in them. But this is fairly minor for a new file.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15408707
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/SaslUtils.java ---
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package backtype.storm.messaging.netty;
+
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.security.sasl.Sasl;
+
+import org.apache.commons.codec.binary.Base64;
+
+import backtype.storm.Config;
+
+class SaslUtils {
+ public static final String AUTH_DIGEST_MD5 = "DIGEST-MD5";
+ public static final String DEFAULT_REALM = "default";
+
+ static Map<String, String> getSaslProps() {
+ Map<String, String> props = new HashMap<String, String>();
+ props.put(Sasl.POLICY_NOPLAINTEXT, "true");
+ return props;
+ }
+
+ /**
+ * Encode a password as a base64-encoded char[] array.
+ *
+ * @param password
+ * as a byte array.
+ * @return password as a char array.
+ */
+ static char[] encodePassword(byte[] password) {
+ return new String(Base64.encodeBase64(password),
+ Charset.defaultCharset()).toCharArray();
--- End diff --
Can we change this to explicitly be UTF-8. The default charset can change from local to local, although shouldn't really.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-storm pull request: STORM-348: Netty SASL Authentication
Posted by revans2 <gi...@git.apache.org>.
Github user revans2 commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/202#discussion_r15406084
--- Diff: storm-core/src/jvm/backtype/storm/messaging/netty/SaslNettyClient.java ---
@@ -0,0 +1,166 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package backtype.storm.messaging.netty;
+
+import java.io.IOException;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.sasl.RealmCallback;
+import javax.security.sasl.RealmChoiceCallback;
+import javax.security.sasl.Sasl;
+import javax.security.sasl.SaslClient;
+import javax.security.sasl.SaslException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implements SASL logic for storm worker client processes.
+ */
+public class SaslNettyClient {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SaslNettyClient.class);
+
+ /**
+ * Used to respond to server's counterpart, SaslServer with SASL tokens
+ * represented as byte arrays.
+ */
+ private SaslClient saslClient;
+
+ /**
+ * Create a SaslNettyClient for authentication with servers.
+ */
+ public SaslNettyClient(String topologyName, byte[] token) {
+ try {
+ LOG.debug("SaslNettyClient: Creating SASL "
+ + SaslUtils.AUTH_DIGEST_MD5
+ + " client to authenticate to server ");
+
+ saslClient = Sasl.createSaslClient(
+ new String[] { SaslUtils.AUTH_DIGEST_MD5 }, null, null,
+ SaslUtils.DEFAULT_REALM, SaslUtils.getSaslProps(),
+ new SaslClientCallbackHandler(topologyName, token));
+
+ } catch (IOException e) {
+ LOG.error("SaslNettyClient: Could not obtain topology token for Netty "
+ + "Client to use to authenticate with a Netty Server.");
+ saslClient = null;
--- End diff --
I'm not sure we want to fall back to this on an error. Because when we try to connect we will end up with NPEs. Also we don't log the IOException which may make debugging difficult.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---