Skip to content
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

implement ROS_IP=localhost behavior for roscpp, and for outbound rospy connections #452

Closed
wants to merge 17 commits into from

Conversation

codebot
Copy link
Contributor

@codebot codebot commented Jun 29, 2014

The wiki doc for ROS_IP: http://wiki.ros.org/ROS/EnvironmentVariables says that setting ROS_IP=localhost will "prevent remote components from being able to talk to your local component." This can be useful in some settings. However, this behavior was previously only implemented for inbound rospy topic connections and services. This pull request implements it for inbound and outbound roscpp connections, and for outbound rospy connections.

@ros-pull-request-builder
Copy link
Member

Test passed.
Refer to this link for build results: http://jenkins.ros.org/job/_pull_request-indigo-ros_comm/36/

@gerkey
Copy link
Contributor

gerkey commented Jun 29, 2014

Anywhere that we check for ROS_IP=='localhost', we should also check for ROS_HOSTNAME=='localhost'. They're used interchangeably (which is confusing, but then it's always been confusing to support two variables for this purpose).

{
// we must verify that the requested connection is to localhost
char our_hostname[256] = {0};
gethostname(our_hostname, sizeof(our_hostname)-1);
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the case where we're asked to connect to a node via one of our own non-loopback IP addresses? E.g., we're in 'localhost' mode and we hear about a publisher at '192.168.1.100', which is our own address? That connection should be allowed. I think that we need to iterate over all of our own IP addresses, plus our hostname (maybe fully-qualified and not?), plus the special cases of 'localhost', '127.*', etc. Basically, we need to match on any host/address string that legitimately matches our machine.

Looking at the Python version, it seems that we need some form of rosgraph.network.is_local_address().

Same for the UDP case below.

@dirk-thomas
Copy link
Member

According to the docs (http://wiki.ros.org/ROS/EnvironmentVariables#ROS_IP.2BAC8-ROS_HOSTNAME) ROS_IP should only be set to an IP address:

Use ROS_IP if you are specifying an IP address, and ROS_HOSTNAME if you are specifying a host name.

So I don't think that setting ROS_IP=localhost is valid. The patch should only check the ROS_HOSTNAME instead.

@codebot
Copy link
Contributor Author

codebot commented Jun 29, 2014

OK thanks for the feedback. I thought that localhost was being treated as a
"magic" IP string in rospy, but I agree it is more logical to implement it
for ROS_HOSTNAME as well (and to check all interface addresses, like rospy
does). I will update the PR to incorporate all of this feedback.
On Jun 29, 2014 11:42 AM, "Dirk Thomas" notifications@github.com wrote:

According to the docs (
http://wiki.ros.org/ROS/EnvironmentVariables#ROS_IP.2BAC8-ROS_HOSTNAME)
ROS_IP should only be set to an IP address:

Use ROS_IP if you are specifying an IP address, and ROS_HOSTNAME if you
are specifying a host name.

So I don't think that setting ROS_IP=localhost is valid. The patch should
only check the ROS_HOSTNAME instead.


Reply to this email directly or view it on GitHub
#452 (comment).

@codebot
Copy link
Contributor Author

codebot commented Jun 29, 2014

not sure what the Jenkins failures mean, but anyway I think that I have incorporated the feedback and it is not quite as ugly as my first attempt. I added a new file, transport.cpp, which factors all of this into one place. The local hostname/addresses are cached in the Transport class and spun through when needed.

@dirk-thomas
Copy link
Member

@ros-pull-request-builder
Copy link
Member

Test passed.
Refer to this link for build results: http://jenkins.ros.org/job/_pull_request-indigo-ros_comm/42/

/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2014, Open Source Robotics Foundation
Copy link
Member

Choose a reason for hiding this comment

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

Open Source Robotics Foundation, Inc.

return true; // hooray
}
ROS_WARN("ROS_HOSTNAME / ROS_IP is set to only allow local connections, so "
"a requested connection to %s is being rejected.", host.c_str());
Copy link
Member

Choose a reason for hiding this comment

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

Please put single quotes around the %s to make it more readable:

.. connection to '%s' is being ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you; these changes are now incorporated into the PR.

On Mon, Jun 30, 2014 at 1:54 PM, Dirk Thomas notifications@github.com
wrote:

In clients/roscpp/src/libros/transport/transport.cpp:

+bool Transport::isHostAllowed(const std::string &host)
+{

  • if (!only_localhost_allowed_)
  • return true; // doesn't matter; we'll connect to anybody
  • if (host.length() >= 4 && host.substr(0, 4) == std::string("127."))
  • return true; // ipv4 localhost
  • // now, loop through the list of valid hostnames and see if we find it
  • for (std::vectorstd::string::iterator it = allowed_hosts_.begin();
  •   it != allowed_hosts_.end(); ++it)
    
  • {
  • if (host == *it)
  •  return true; // hooray
    
  • }
  • ROS_WARN("ROS_HOSTNAME / ROS_IP is set to only allow local connections, so "
  •       "a requested connection to %s is being rejected.", host.c_str());
    

Please put single quotes around the %s to make it more readable:

.. connection to '%s' is being ...


Reply to this email directly or view it on GitHub
https://github.com/ros/ros_comm/pull/452/files#r14375058.

};

}

#endif // ROSCPP_TRANSPORT_H

Copy link
Member

Choose a reason for hiding this comment

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

The file already has a trailing newline. Please remove the additional one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

On Mon, Jun 30, 2014 at 2:25 PM, Dirk Thomas notifications@github.com
wrote:

In clients/roscpp/include/ros/transport/transport.h:

};

}

#endif // ROSCPP_TRANSPORT_H
+

The file already has a trailing newline. Please remove the additional one.


Reply to this email directly or view it on GitHub
https://github.com/ros/ros_comm/pull/452/files#r14376694.

@dirk-thomas
Copy link
Member

@ros-pull-request-builder
Copy link
Member

Test passed.
Refer to this link for build results: http://jenkins.ros.org/job/_pull_request-indigo-ros_comm/47/

if (ros_hostname_env && !strcmp(ros_hostname_env, "localhost"))
only_localhost_allowed_ = true;
else if (ros_ip_env && !strncmp(ros_ip_env, "127.", 4))
only_localhost_allowed_ = true;
Copy link
Member

Choose a reason for hiding this comment

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

This line also needs to work with IPv6 addresses.

@@ -518,6 +518,16 @@ def connect(self, dest_addr, dest_port, endpoint_id, timeout=None):
@type timeout: float
@raise TransportInitError: if unable to create connection
"""
# first make sure that if ROS_IP=localhost, we will not attempt
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, for bother about more details... but the comment should refer to ROS_HOSTNAME.

@dirk-thomas
Copy link
Member

@ros-pull-request-builder
Copy link
Member

Test failed.
Refer to this link for build results: http://jenkins.ros.org/job/_pull_request-indigo-ros_comm/62/

Update: this failure is due to a flaky unit test and I will therefore ignore it and still merge the patch.

@wjwwood
Copy link
Member

wjwwood commented Jul 10, 2014

+1 for Indigo

@dirk-thomas
Copy link
Member

Squashed and merged in 8713a1e

@dirk-thomas
Copy link
Member

@CodeBot9000 Can you please update the documentation in the wiki to clarify the previous behavior as well as the new behavior as of Indigo (and post the link to the wiki changes here)?

@ros-pull-request-builder
Copy link
Member

Test passed.
Refer to this link for build results: http://jenkins.ros.org/job/_pull_request-indigo-ros_comm/66/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants