Skip to content

Commit 65905c8

Browse files
add $ Security Webots and Topic-Statics-Tutorial (#5358)
Signed-off-by: Nils-Christian Iseke <[email protected]> Signed-off-by: Christophe Bedard <[email protected]> Co-authored-by: Christophe Bedard <[email protected]>
1 parent b3d8114 commit 65905c8

File tree

8 files changed

+212
-219
lines changed

8 files changed

+212
-219
lines changed

source/Tutorials/Advanced/Security/Access-Controls.rst

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ Modify ``permissions.xml``
3737

3838
Begin by making a backup of your permissions files, and open ``permissions.xml`` for editing:
3939

40-
.. code-block:: bash
40+
.. code-block:: console
4141
42-
cd ~/sros2_demo/demo_keystore/enclaves/talker_listener/talker
43-
mv permissions.p7s permissions.p7s~
44-
mv permissions.xml permissions.xml~
45-
vi permissions.xml
42+
$ cd ~/sros2_demo/demo_keystore/enclaves/talker_listener/talker
43+
$ mv permissions.p7s permissions.p7s~
44+
$ mv permissions.xml permissions.xml~
45+
$ vi permissions.xml
4646
4747
We will be modifying the ``<allow_rule>`` for ``<publish>`` and ``<subscribe>``.
4848
The topics in this XML file use the DDS naming format, not the ROS name.
@@ -113,9 +113,9 @@ This next command creates the new S/MIME signed policy file ``permissions.p7s``
113113
The file must be signed with the Permissions CA certificate, **which requires access to the Permission CA private key**.
114114
If the private key has been protected, additional steps may be required to unlock and use it according to your security plan.
115115

116-
.. code-block:: bash
116+
.. code-block:: console
117117
118-
openssl smime -sign -text -in permissions.xml -out permissions.p7s \
118+
$ openssl smime -sign -text -in permissions.xml -out permissions.p7s \
119119
--signer permissions_ca.cert.pem \
120120
-inkey ~/sros2_demo/demo_keystore/private/permissions_ca.key.pem
121121
@@ -125,15 +125,15 @@ Launch the node
125125

126126
With the updated permissions in place, we can launch the node successfully using the same command used in prior tutorials:
127127

128-
.. code-block:: bash
128+
.. code-block:: console
129129
130-
ros2 run demo_nodes_cpp talker --ros-args --enclave /talker_listener/talker
130+
$ ros2 run demo_nodes_cpp talker --ros-args --enclave /talker_listener/talker
131131
132132
However, attempting to remap the ``chatter`` topic prevents the node from launching (note that this requires the ``ROS_SECURITY_STRATEGY`` set to ``Enforce``).
133133

134-
.. code-block:: bash
134+
.. code-block:: console
135135
136-
ros2 run demo_nodes_cpp talker --ros-args --enclave /talker_listener/talker \
136+
$ ros2 run demo_nodes_cpp talker --ros-args --enclave /talker_listener/talker \
137137
--remap chatter:=not_chatter
138138
139139
@@ -146,39 +146,39 @@ Let's creates a policy for both the ``talker`` and the ``listener`` to only use
146146

147147
Begin by downloading the ``sros2`` repository with the sample policy files:
148148

149-
.. code-block:: bash
149+
.. code-block:: console
150150
151-
git clone https://github.com/ros2/sros2.git /tmp/sros2
151+
$ git clone https://github.com/ros2/sros2.git /tmp/sros2
152152
153153
Then use the ``create_permission`` verb while pointing to the sample policy to generate the XML permission files:
154154

155-
.. code-block:: bash
155+
.. code-block:: console
156156
157-
ros2 security create_permission demo_keystore \
157+
$ ros2 security create_permission demo_keystore \
158158
/talker_listener/talker \
159159
/tmp/sros2/sros2/test/policies/sample.policy.xml
160-
ros2 security create_permission demo_keystore \
160+
$ ros2 security create_permission demo_keystore \
161161
/talker_listener/listener \
162162
/tmp/sros2/sros2/test/policies/sample.policy.xml
163163
164164
These permission files allow nodes to only publish or subscribe to the ``chatter`` topic, and enable communications required for parameters.
165165

166166
In one terminal with security enabled as in previous security tutorials, run the ``talker`` demo program:
167167

168-
.. code-block:: bash
168+
.. code-block:: console
169169
170-
ros2 run demo_nodes_cpp talker --ros-args -e /talker_listener/talker
170+
$ ros2 run demo_nodes_cpp talker --ros-args -e /talker_listener/talker
171171
172172
In another terminal do the same with the ``listener`` program:
173173

174-
.. code-block:: bash
174+
.. code-block:: console
175175
176-
ros2 run demo_nodes_py listener --ros-args -e /talker_listener/listener
176+
$ ros2 run demo_nodes_py listener --ros-args -e /talker_listener/listener
177177
178178
At this point, your ``talker`` and ``listener`` nodes will be communicating securely using explicit access control lists.
179179
However, the following attempt for the ``listener`` node to subscribe to a topic other than ``chatter`` will fail:
180180

181-
.. code-block:: bash
181+
.. code-block:: console
182182
183-
ros2 run demo_nodes_py listener --ros-args --enclave /talker_listener/listener \
183+
$ ros2 run demo_nodes_py listener --ros-args --enclave /talker_listener/listener \
184184
--remap chatter:=not_chatter

source/Tutorials/Advanced/Security/Deployment-Guidelines.rst

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,26 @@ Starting from the image, three containers will be created with the aim of:
9999
In this example, the local host serves as the organization's system.
100100
Let us start by creating a workspace folder:
101101

102-
.. code-block:: bash
102+
.. code-block:: console
103103
104-
mkdir ~/security_gd_tutorial
105-
cd ~/security_gd_tutorial
104+
$ mkdir ~/security_gd_tutorial
105+
$ cd ~/security_gd_tutorial
106106
107107
Generating the Docker Image
108108
^^^^^^^^^^^^^^^^^^^^^^^^^^^
109109

110110
In order to build a new docker image, a Dockerfile is required.
111-
The one proposed for this tutorial can be retrieved with the following command:
111+
To download the Dockerfile proposed for this tutorial, run:
112112

113-
.. code-block:: bash
113+
.. code-block:: console
114114
115-
# Download the Dockerfile
116-
wget https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Security/resources/deployment_gd/Dockerfile
115+
$ wget https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Security/resources/deployment_gd/Dockerfile
117116
118117
Now, build the docker image with the command:
119118

120-
.. code-block:: bash
119+
.. code-block:: console
121120
122-
# Build the base image
123-
docker build -t ros2_security/deployment_tutorial --build-arg ROS_DISTRO={DISTRO} .
121+
$ docker build -t ros2_security/deployment_tutorial --build-arg ROS_DISTRO={DISTRO} .
124122
125123
Understanding the compose file
126124
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -137,20 +135,18 @@ In this tutorial, three services are defined within the configuration:
137135

138136
The compose configuration yaml file can be downloaded with:
139137

140-
.. code-block:: bash
138+
.. code-block:: console
141139
142-
# Download the compose file
143-
wget https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Security/resources/deployment_gd/compose.deployment.yaml
140+
$ wget https://raw.githubusercontent.com/ros2/ros2_documentation/{DISTRO}/source/Tutorials/Advanced/Security/resources/deployment_gd/compose.deployment.yaml
144141
145142
Running the example
146143
-------------------
147144

148-
In the same working directory ``~/security_gd_tutorial``, run:
145+
In the same working directory ``~/security_gd_tutorial``, to start the example run:
149146

150-
.. code-block:: bash
147+
.. code-block:: console
151148
152-
# Start the example
153-
docker compose -f compose.deployment.yaml up
149+
$ docker compose -f compose.deployment.yaml up
154150
155151
This should result in the following output:
156152

@@ -162,19 +158,22 @@ This should result in the following output:
162158
Examining the containers
163159
^^^^^^^^^^^^^^^^^^^^^^^^
164160

165-
While having the containers running that simulate the two remote devices for this tutorial, attach to each of them by opening two different terminals and enter:
161+
While having the containers running that simulate the two remote devices for this tutorial, attach to each of them by opening two different terminals.
162+
In the first terminal, run:
166163

167-
.. code-block:: bash
164+
.. code-block:: console
168165
169-
# Terminal 1
170-
docker exec -it tutorial-listener-1 bash
171-
cd keystore
172-
tree
166+
$ docker exec -it tutorial-listener-1 bash
167+
$ cd keystore
168+
$ tree
173169
174-
# Terminal 2
175-
docker exec -it tutorial-talker-1 bash
176-
cd keystore
177-
tree
170+
In the second terminal, run:
171+
172+
.. code-block:: console
173+
174+
$ docker exec -it tutorial-talker-1 bash
175+
$ cd keystore
176+
$ tree
178177
179178
A similar output to the one depicted below should be obtained:
180179

source/Tutorials/Advanced/Security/Examine-Traffic.rst

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ Install ``tcpdump``
4646
Begin in a new terminal window by installing `tcpdump <https://www.tcpdump.org/manpages/tcpdump.1.html>`_, a command-line tool for capturing and displaying network traffic.
4747
Although this tutorial describes ``tcpdump`` commands, you can also use `Wireshark <https://www.wireshark.org/>`_, a similar graphical tool for capturing and analyzing traffic.
4848

49-
.. code-block:: bash
49+
.. code-block:: console
5050
51-
sudo apt update
52-
sudo apt install tcpdump
51+
$ sudo apt update
52+
$ sudo apt install tcpdump
5353
5454
Run following commands on a single machine through multiple ``ssh`` sessions.
5555

@@ -58,17 +58,19 @@ Start the talker and listener
5858

5959
Start both the talker and the listener again, each in its own terminal.
6060
The security environment variables are not set so security is not enabled for these sessions.
61+
In one terminal run:
6162

62-
.. code-block:: bash
63+
.. code-block:: console
6364
64-
# Disable ROS Security for both terminals
65-
unset ROS_SECURITY_ENABLE
65+
$ unset ROS_SECURITY_ENABLE
66+
$ ros2 run demo_nodes_cpp talker --ros-args --enclave /talker_listener/talker
6667
67-
# In terminal 1:
68-
ros2 run demo_nodes_cpp talker --ros-args --enclave /talker_listener/talker
68+
In another terminal run:
6969

70-
# In terminal 2:
71-
ros2 run demo_nodes_cpp listener --ros-args --enclave /talker_listener/listener
70+
.. code-block:: console
71+
72+
$ unset ROS_SECURITY_ENABLE
73+
$ ros2 run demo_nodes_cpp listener --ros-args --enclave /talker_listener/listener
7274
7375
7476
Display unencrypted discovery packets
@@ -79,12 +81,9 @@ You need to use ``sudo`` since reading raw network traffic is a privileged opera
7981

8082
The command below uses the ``-X`` option to print packet contents, the ``-i`` option to listen for packets on any interface, and captures only `UDP <https://en.wikipedia.org/wiki/User_Datagram_Protocol>`_ port 7400 traffic.
8183

82-
.. code-block:: bash
83-
84-
sudo tcpdump -X -i any udp port 7400
85-
86-
You should see packets like the following::
84+
.. code-block:: console
8785
86+
$ sudo tcpdump -X -i any udp port 7400
8887
20:18:04.400770 IP 8_xterm.46392 > 239.255.0.1.7400: UDP, length 252
8988
0x0000: 4500 0118 d48b 4000 0111 7399 c0a8 8007 [email protected].....
9089
0x0010: efff 0001 b538 1ce8 0104 31c6 5254 5053 .....8....1.RTPS
@@ -109,14 +108,12 @@ Some other features of a typical discovery packet:
109108
Display unencrypted data packets
110109
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111110

112-
Use ``tcpdump`` to capture non-discovery RTPS packets by filtering on UDP ports above 7400:
111+
Use ``tcpdump`` to capture non-discovery RTPS packets by filtering on UDP ports above 7400.
112+
You will see few different types of packets, but watch for something like the following which is obviously data being sent from a talker to a listener:
113113

114-
.. code-block:: bash
115-
116-
sudo tcpdump -i any -X udp portrange 7401-7500
117-
118-
You will see few different types of packets, but watch for something like the following which is obviously data being sent from a talker to a listener::
114+
.. code-block:: console
119115
116+
$ sudo tcpdump -i any -X udp portrange 7401-7500
120117
20:49:17.927303 IP localhost.46392 > localhost.7415: UDP, length 84
121118
0x0000: 4500 0070 5b53 4000 4011 e127 7f00 0001 E..p[S@.@..'....
122119
0x0010: 7f00 0001 b538 1cf7 005c fe6f 5254 5053 .....8...\.oRTPS
@@ -138,32 +135,34 @@ Enable encryption
138135
Stop both the talker and the listener nodes.
139136
Enable encryption for both by setting the security environment variables and run them again.
140137

141-
.. code-block:: bash
138+
In terminal 1:
142139

143-
# In terminal 1:
144-
export ROS_SECURITY_KEYSTORE=~/sros2_demo/demo_keystore
145-
export ROS_SECURITY_ENABLE=true
146-
export ROS_SECURITY_STRATEGY=Enforce
147-
ros2 run demo_nodes_cpp talker --ros-args --enclave /talker_listener/talker
140+
.. code-block:: console
148141
149-
# In terminal 2:
150-
export ROS_SECURITY_KEYSTORE=~/sros2_demo/demo_keystore
151-
export ROS_SECURITY_ENABLE=true
152-
export ROS_SECURITY_STRATEGY=Enforce
153-
ros2 run demo_nodes_cpp listener --ros-args --enclave /talker_listener/listener
142+
$ export ROS_SECURITY_KEYSTORE=~/sros2_demo/demo_keystore
143+
$ export ROS_SECURITY_ENABLE=true
144+
$ export ROS_SECURITY_STRATEGY=Enforce
145+
$ ros2 run demo_nodes_cpp talker --ros-args --enclave /talker_listener/talker
154146
147+
In terminal 2:
155148

156-
Display encrypted discovery packets
157-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149+
.. code-block:: console
150+
151+
$ export ROS_SECURITY_KEYSTORE=~/sros2_demo/demo_keystore
152+
$ export ROS_SECURITY_ENABLE=true
153+
$ export ROS_SECURITY_STRATEGY=Enforce
154+
$ ros2 run demo_nodes_cpp listener --ros-args --enclave /talker_listener/listener
158155
159-
Run the same ``tcpdump`` command used earlier to examine the output of discovery traffic with encryption enabled:
160156
161-
.. code-block:: bash
157+
Display encrypted discovery packets
158+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
162159

163-
sudo tcpdump -X -i any udp port 7400
160+
Run the same ``tcpdump`` command used earlier to examine the output of discovery traffic with encryption enabled
161+
The typical discovery packet looks somewhat like the following:
164162

165-
The typical discovery packet looks somewhat like the following::
163+
.. code-block:: console
166164
165+
$ sudo tcpdump -X -i any udp port 7400
167166
21:09:07.336617 IP 8_xterm.60409 > 239.255.0.1.7400: UDP, length 596
168167
0x0000: 4500 0270 c2f6 4000 0111 83d6 c0a8 8007 E..p..@.........
169168
0x0010: efff 0001 ebf9 1ce8 025c 331e 5254 5053 .........\3.RTPS
@@ -192,14 +191,12 @@ Take a look at the excellent paper `Network Reconnaissance and Vulnerability Exc
192191
Display encrypted data packets
193192
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
194193

195-
Now use ``tcpdump`` to capture data packets:
196-
197-
.. code-block:: bash
198-
199-
sudo tcpdump -i any -X udp portrange 7401-7500
194+
Now use ``tcpdump`` to capture data packets.
195+
A typical data packet looks like the following:
200196

201-
A typical data packet looks like the following::
197+
.. code-block:: console
202198
199+
$ sudo tcpdump -i any -X udp portrange 7401-7500
203200
21:18:14.531102 IP localhost.54869 > localhost.7415: UDP, length 328
204201
0x0000: 4500 0164 bb42 4000 4011 8044 7f00 0001 E..d.B@[email protected]....
205202
0x0010: 7f00 0001 d655 1cf7 0150 ff63 5254 5053 .....U...P.cRTPS

0 commit comments

Comments
 (0)