Skip to content

Commit 72ecb5f

Browse files
authored
Switch to one Participant per Context (#515)
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
1 parent 73948da commit 72ecb5f

30 files changed

+1315
-666
lines changed

rcl/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ set(${PROJECT_NAME}_sources
3737
src/rcl/client.c
3838
src/rcl/common.c
3939
src/rcl/context.c
40+
src/rcl/domain_id.c
4041
src/rcl/event.c
4142
src/rcl/expand_topic_name.c
4243
src/rcl/graph.c
@@ -53,13 +54,14 @@ set(${PROJECT_NAME}_sources
5354
src/rcl/publisher.c
5455
src/rcl/remap.c
5556
src/rcl/rmw_implementation_identifier_check.c
57+
src/rcl/security.c
5658
src/rcl/service.c
5759
src/rcl/subscription.c
5860
src/rcl/time.c
5961
src/rcl/timer.c
62+
src/rcl/validate_security_context_name.c
6063
src/rcl/validate_topic_name.c
6164
src/rcl/wait.c
62-
src/rcl/security_directory.c
6365
)
6466

6567
add_library(${PROJECT_NAME} ${${PROJECT_NAME}_sources})

rcl/include/rcl/arguments.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef struct rcl_arguments_t
4242
#define RCL_PARAM_FILE_FLAG "--params-file"
4343
#define RCL_REMAP_FLAG "--remap"
4444
#define RCL_SHORT_REMAP_FLAG "-r"
45+
#define RCL_SECURITY_CONTEXT_FLAG "--security-context"
4546
#define RCL_LOG_LEVEL_FLAG "--log-level"
4647
#define RCL_EXTERNAL_LOG_CONFIG_FLAG "--log-config-file"
4748
// To be prefixed with --enable- or --disable-

rcl/include/rcl/domain_id.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2019 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef RCL__DOMAIN_ID_H_
16+
#define RCL__DOMAIN_ID_H_
17+
18+
#ifdef __cplusplus
19+
extern "C"
20+
{
21+
#endif
22+
23+
#include <stddef.h>
24+
25+
#include "rcl/types.h"
26+
#include "rcl/visibility_control.h"
27+
#include "rmw/domain_id.h"
28+
29+
#define RCL_DEFAULT_DOMAIN_ID RMW_DEFAULT_DOMAIN_ID
30+
31+
extern const char * const RCL_DOMAIN_ID_ENV_VAR;
32+
33+
/// Determine the default domain ID, based on the environment.
34+
/**
35+
* \param[out] domain_id Must not be NULL.
36+
* \returns RCL_RET_INVALID_ARGUMENT if an argument is invalid, or,
37+
* \returns RCL_RET_ERROR in case of an unexpected error, or,
38+
* \returns RCL_RET_OK.
39+
*/
40+
RCL_PUBLIC
41+
rcl_ret_t
42+
rcl_get_default_domain_id(size_t * domain_id);
43+
44+
#ifdef __cplusplus
45+
}
46+
#endif
47+
48+
#endif // RCL__DOMAIN_ID_H_

rcl/include/rcl/graph.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ rcl_names_and_types_fini(rcl_names_and_types_t * names_and_types);
429429
* \param[out] node_names struct storing discovered node names
430430
* \param[out] node_namesspaces struct storing discovered node namespaces
431431
* \return `RCL_RET_OK` if the query was successful, or
432+
* \return `RCL_RET_BAD_ALLOC` if an error occurred while allocating memory, or
432433
* \return `RCL_RET_ERROR` if an unspecified error occurs.
433434
*/
434435
RCL_PUBLIC
@@ -440,6 +441,39 @@ rcl_get_node_names(
440441
rcutils_string_array_t * node_names,
441442
rcutils_string_array_t * node_namespaces);
442443

444+
/// Return a list of available nodes in the ROS graph, including their security context names.
445+
/**
446+
* An \ref rcl_get_node_names equivalent, but including in its output the security context
447+
* name the node is using.
448+
*
449+
* <hr>
450+
* Attribute | Adherence
451+
* ------------------ | -------------
452+
* Allocates Memory | Yes
453+
* Thread-Safe | No
454+
* Uses Atomics | No
455+
* Lock-Free | Maybe [1]
456+
* <i>[1] RMW implementation in use may need to protect the data structure with a lock</i>
457+
*
458+
* \param[in] node the handle to the node being used to query the ROS graph
459+
* \param[in] allocator used to control allocation and deallocation of names
460+
* \param[out] node_names struct storing discovered node names
461+
* \param[out] node_namesspaces struct storing discovered node namespaces
462+
* \param[out] security_contexts struct storing discovered node security contexts
463+
* \return `RCL_RET_OK` if the query was successful, or
464+
* \return `RCL_RET_BAD_ALLOC` if an error occurred while allocating memory, or
465+
* \return `RCL_RET_ERROR` if an unspecified error occurs.
466+
*/
467+
RCL_PUBLIC
468+
RCL_WARN_UNUSED
469+
rcl_ret_t
470+
rcl_get_node_names_with_security_contexts(
471+
const rcl_node_t * node,
472+
rcl_allocator_t allocator,
473+
rcutils_string_array_t * node_names,
474+
rcutils_string_array_t * node_namespaces,
475+
rcutils_string_array_t * security_contexts);
476+
443477
/// Return the number of publishers on a given topic.
444478
/**
445479
* The `node` parameter must point to a valid node.

rcl/include/rcl/localhost.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@ extern "C"
2222

2323
#include "rcl/types.h"
2424
#include "rcl/visibility_control.h"
25+
#include "rmw/localhost.h"
2526

2627
extern const char * const RCL_LOCALHOST_ENV_VAR;
2728

2829
/// Determine if the user wants to communicate using loopback only.
2930
/**
30-
* Checks if localhost should be used for network communication checking ROS_LOCALHOST_ONLY env
31-
* variable
32-
* \returns true if ROS_LOCALHOST_ONLY is set and is 1, false otherwise.
31+
* Checks if localhost should be used for network communication based on environment.
32+
*
33+
* \param[out] localhost_only Must not be NULL.
34+
* \returns RCL_RET_INVALID_ARGUMENT if an argument is invalid, or
35+
* \returns RCL_RET_ERROR if an unexpected error happened, or
36+
* \returns RCL_RET_OK.
3337
*/
3438
RCL_PUBLIC
35-
bool
36-
rcl_localhost_only();
39+
rcl_ret_t
40+
rcl_get_localhost_only(rmw_localhost_only_t * localhost_only);
3741

3842
#ifdef __cplusplus
3943
}

rcl/include/rcl/node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ rcl_node_get_options(const rcl_node_t * node);
336336
* This function returns the ROS domain ID that the node is in.
337337
*
338338
* This function should be used to determine what `domain_id` was used rather
339-
* than checking the domin_id field in the node options, because if
339+
* than checking the domain_id field in the node options, because if
340340
* `RCL_NODE_OPTIONS_DEFAULT_DOMAIN_ID` is used when creating the node then
341341
* it is not changed after creation, but this function will return the actual
342342
* `domain_id` used.

rcl/include/rcl/node_options.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ extern "C"
2323
#include "rcl/allocator.h"
2424
#include "rcl/arguments.h"
2525

26+
#include "rcl/domain_id.h"
27+
2628
/// Constant which indicates that the default domain id should be used.
27-
#define RCL_NODE_OPTIONS_DEFAULT_DOMAIN_ID SIZE_MAX
29+
#define RCL_NODE_OPTIONS_DEFAULT_DOMAIN_ID RCL_DEFAULT_DOMAIN_ID
2830

2931
/// Structure which encapsulates the options for creating a rcl_node_t.
3032
typedef struct rcl_node_options_t

rcl/include/rcl/security.h

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright 2018-2020 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef RCL__SECURITY_H_
16+
#define RCL__SECURITY_H_
17+
18+
#ifdef __cplusplus
19+
extern "C"
20+
{
21+
#endif
22+
23+
#include <stdbool.h>
24+
25+
#include "rcl/allocator.h"
26+
#include "rcl/types.h"
27+
#include "rcl/visibility_control.h"
28+
#include "rmw/security_options.h"
29+
30+
#ifndef ROS_SECURITY_DIRECTORY_OVERRIDE
31+
# define ROS_SECURITY_DIRECTORY_OVERRIDE "ROS_SECURITY_DIRECTORY_OVERRIDE"
32+
#endif
33+
34+
#ifndef ROS_SECURITY_ROOT_DIRECTORY_VAR_NAME
35+
# define ROS_SECURITY_ROOT_DIRECTORY_VAR_NAME "ROS_SECURITY_ROOT_DIRECTORY"
36+
#endif
37+
38+
#ifndef ROS_SECURITY_STRATEGY_VAR_NAME
39+
# define ROS_SECURITY_STRATEGY_VAR_NAME "ROS_SECURITY_STRATEGY"
40+
#endif
41+
42+
#ifndef ROS_SECURITY_ENABLE_VAR_NAME
43+
# define ROS_SECURITY_ENABLE_VAR_NAME "ROS_SECURITY_ENABLE"
44+
#endif
45+
46+
/// Initialize security options from values in the environment variables and given names.
47+
/**
48+
* Initialize the given security options based on the environment.
49+
* For more details:
50+
* \sa rcl_security_enabled
51+
* \sa rcl_get_enforcement_policy
52+
* \sa rcl_get_secure_root
53+
*
54+
* \param[in] name name used to find the securiy root path.
55+
* \param[in] allocator used to do allocations.
56+
* \param[out] security_options security options that will be configured according to
57+
* the environment.
58+
*/
59+
RCL_PUBLIC
60+
rcl_ret_t
61+
rcl_get_security_options_from_environment(
62+
const char * name,
63+
const rcutils_allocator_t * allocator,
64+
rmw_security_options_t * security_options);
65+
66+
/// Check if security has to be used, according to the environment.
67+
/**
68+
* If `ROS_SECURITY_ENABLE` environment variable is set to "true", `use_security` will be set to
69+
* true.
70+
*
71+
* \param[out] use_security Must not be NULL.
72+
* \returns RCL_RET_INVALID_ARGUMENT if an argument is not valid, or
73+
* \returns RCL_RET_ERROR if an unexpected error happened, or
74+
* \returns RCL_RET_OK.
75+
*/
76+
RCL_PUBLIC
77+
rcl_ret_t
78+
rcl_security_enabled(bool * use_security);
79+
80+
/// Get security enforcement policy from the environment.
81+
/**
82+
* Sets `policy` based on the value of `ROS_SECURITY_STRATEGY` environment variable.
83+
* If `ROS_SECURITY_STRATEGY` is "Enforce", `policy` will be `RMW_SECURITY_ENFORCEMENT_ENFORCE`.
84+
* If not, `policy` will be `RMW_SECURITY_ENFORCEMENT_PERMISSIVE`.
85+
*
86+
* \param[out] policy Must not be NULL.
87+
* \returns RCL_RET_INVALID_ARGUMENT if an argument is not valid, or
88+
* \returns RCL_RET_ERROR if an unexpected error happened, or
89+
* \returns RCL_RET_OK.
90+
*/
91+
RCL_PUBLIC
92+
rcl_ret_t
93+
rcl_get_enforcement_policy(rmw_security_enforcement_policy_t * policy);
94+
95+
/// Return the secure root given a security context name.
96+
/**
97+
* Return the security directory associated with the security context name.
98+
*
99+
* The value of the environment variable `ROS_SECURITY_ROOT_DIRECTORY` is used as a root.
100+
* The specific directory to be used, is found from that root using the `name` passed.
101+
* E.g. for a context named "/a/b/c" and root "/r", the secure root path will be
102+
* "/r/a/b/c", where the delimiter "/" is native for target file system (e.g. "\\" for _WIN32).
103+
*
104+
* However, this expansion can be overridden by setting the secure directory override environment
105+
* (`ROS_SECURITY_DIRECTORY_OVERRIDE`) variable, allowing users to explicitly specify the exact secure
106+
* root directory to be utilized.
107+
* Such an override is useful for applications where the security context is non-deterministic
108+
* before runtime, or when testing and using additional tools that may not otherwise be easily
109+
* provisioned.
110+
*
111+
* \param[in] name validated name (a single token)
112+
* \param[in] allocator the allocator to use for allocation
113+
* \returns Machine specific (absolute) secure root path or NULL on failure.
114+
* Returned pointer must be deallocated by the caller of this function
115+
*/
116+
RCL_PUBLIC
117+
char *
118+
rcl_get_secure_root(const char * name, const rcl_allocator_t * allocator);
119+
120+
#ifdef __cplusplus
121+
}
122+
#endif
123+
124+
#endif // RCL__SECURITY_H_

rcl/include/rcl/security_directory.h

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)