SROS2 Lab

[download pdf]

Objective

To find out what a machine on a ROS 2 network can read and send with the default settings, and what changes after turning on SROS2 authentication, encryption, and access control. This is a learning exercise run on hardware owned by the author. It does not describe any real product or deployment.

Environment

ItemDetail
HostPersonal workstation running Docker
ImageOfficial ros:lyrical (ROS 2 Lyrical Luth)
MiddlewareFast DDS (rmw_fastrtps_cpp), pinned so results repeat
SecuritySROS2 (DDS-Security), keystore created with ros2 security
NetworkOne Docker network, rosnet
Containerstalker, listener, capture (tcpdump), attacker
Capture methodtcpdump on UDP, 30 seconds per capture

A working directory and a Dockerfile were created:

mkdir -p lab/sros2/keys lab/sros2/captures
cd lab/sros2
FROM ros:lyrical
ENV RMW_IMPLEMENTATION=rmw_fastrtps_cpp
RUN apt-get update && apt-get install -y --no-install-recommends ros-lyrical-demo-nodes-cpp ros-lyrical-demo-nodes-py ros-lyrical-sros2 tcpdump git openssl && git clone --depth 1 --branch lyrical https://github.com/ros2/sros2.git /opt/sros2 && rm -rf /var/lib/apt/lists/*

The image was then built and the network created:

docker build -t ros-sec-lab .
docker network create rosnet

Procedure

1. Baseline with no security

The talker, which publishes "Hello World" on /chatter, and the listener, which subscribes to it, were started:

docker run --rm -it --name talker --network rosnet ros-sec-lab \
 ros2 run demo_nodes_cpp talker

docker run --rm -it --name listener --network rosnet ros-sec-lab \
 ros2 run demo_nodes_py listener

The talker's traffic was then captured for 30 seconds. The capture container shares the talker's network namespace, so it sees the talker's packets. The capture was searched for the message text, and both the matching lines and the distinct messages were counted:

docker run --rm --network container:talker -v "$PWD/captures:/captures" ros-sec-lab \
 timeout 30 tcpdump -i eth0 -U -w /captures/baseline.pcap udp

strings captures/baseline.pcap | grep "Hello World" | head
strings captures/baseline.pcap | grep -c "Hello World"
strings captures/baseline.pcap | grep -o 'Hello World: [0-9]*' | sort -u | wc -l

Baseline capture

Figure 1. Baseline capture: 91 packets, with the message text readable in the file.

The capture had 91 packets. 29 carried a message in plain text, 29 distinct messages, and the raw line count matched. The other 62 packets appear to be DDS discovery and delivery confirmation traffic. Their sizes fit that, but they were not decoded.

Next, an attacker container was started on the same network with no keys or special access. It listed the topics and published a message:

docker run --rm -it --name attacker --network rosnet ros-sec-lab bash

ros2 topic list --no-daemon --spin-time 3
ros2 topic pub --once /chatter std_msgs/msg/String "{data: 'injected by attacker'}"

Attacker listing topics and publishing

Figure 2. The attacker sees /chatter and publishes to it with no credentials.

Injected message in the listener output

Figure 3. The injected message arrives between Hello World 465 and 466, in the same stream as the real ones.

The listener printed the injected message, and nothing in the message says who sent it.

2. SROS2 enabled

A keystore was created with a certificate authority and one enclave for the talker and one for the listener. An enclave is a security identity: a key, a certificate, and a permissions file.

docker run --rm -v "$PWD/keys:/keys" ros-sec-lab bash -c "cd /keys && ros2 security create_keystore keystore && ros2 security create_enclave keystore /talker_listener/talker && ros2 security create_enclave keystore /talker_listener/listener"

find keys -type f | sort

Keystore files

Figure 4. Files created for the certificate authority and the two enclaves.

The talker and the listener were restarted with security turned on:

docker run --rm -it --name talker --network rosnet -v "$PWD/keys:/keys:ro" \
  -e ROS_SECURITY_KEYSTORE=/keys/keystore -e ROS_SECURITY_ENABLE=true -e ROS_SECURITY_STRATEGY=Enforce \
  ros-sec-lab ros2 run demo_nodes_cpp talker --ros-args --enclave /talker_listener/talker

docker run --rm -it --name listener --network rosnet -v "$PWD/keys:/keys:ro" \
  -e ROS_SECURITY_KEYSTORE=/keys/keystore -e ROS_SECURITY_ENABLE=true -e ROS_SECURITY_STRATEGY=Enforce \
  ros-sec-lab ros2 run demo_nodes_py listener --ros-args --enclave /talker_listener/listener

A few notes:

  • ROS_SECURITY_KEYSTORE points at the keystore folder and ROS_SECURITY_ENABLE=true switches security on.
  • ROS_SECURITY_STRATEGY=Enforce makes a node refuse to start if its own keys or certificates fail to load, so security cannot be silently skipped.
  • The listener still printed the talker's messages, and its first message arrived about a second after it started.

The 30 second capture was repeated and saved as secure.pcap:

docker run --rm --network container:talker -v "$PWD/captures:/captures" ros-sec-lab \
  timeout 30 tcpdump -i eth0 -U -w /captures/secure.pcap udp

strings captures/secure.pcap | grep -c "Hello World"

Secure capture

Figure 5. Secure capture: 110 packets, 0 lines containing the message text.

The attacker was then run again with no keys and the same two commands:

Attacker topic list without /chatter

Figure 6. With no keys, the attacker's topic list does not include /chatter.

Listener unaffected by the attacker

Figure 7. The listener keeps printing with no injected line while the attacker waits for a subscriber.

The topic list showed only /parameter_events and /rosout, which every node creates for itself. The publish command kept printing Waiting for at least 1 matching subscription(s)... with no error.

3. Access control

Before any policy was applied, the listener was started with its topic remapped from /chatter to /not_chatter:

docker run --rm -it --name listener --network rosnet -v "$PWD/keys:/keys:ro" \
  -e ROS_SECURITY_KEYSTORE=/keys/keystore -e ROS_SECURITY_ENABLE=true -e ROS_SECURITY_STRATEGY=Enforce \
  ros-sec-lab ros2 run demo_nodes_py listener --ros-args --enclave /talker_listener/listener \
  --remap chatter:=not_chatter

Remapped listener before the policy

Figure 8. Before the policy, the remapped listener starts and waits. The only output is the line showing it found its enclave.

Permissions were then generated for both nodes from the sample policy in the sros2 repository, and the same remapped listener was run again:

docker run --rm -v "$PWD/keys:/keys" ros-sec-lab bash -c "cd /keys && ros2 security create_permission keystore /talker_listener/talker /opt/sros2/sros2/test/policies/sample.policy.xml && ros2 security create_permission keystore /talker_listener/listener /opt/sros2/sros2/test/policies/sample.policy.xml"

Remapped listener refused after the policy

Figure 9. After the policy, the same remapped listener fails with "rt/not_chatter topic not found in allow rule" and exits.

Finally, the normal talker and listener were restarted with no remap:

Normal listener after the policy

Figure 10. After the policy, the normal listener still hears the talker.

Results

TestBaselineSROS2 enforced
Packets in a 30 second capture91110
Capture lines with the message text290
Size of the once-a-second packet160 bytes388 bytes
Attacker sees /chatterYesNo
Attacker's message reaches the listenerYesNo, publish waits forever
TestBefore policyAfter policy
Listener remapped to /not_chatterStartsRefused with a security error
Normal talker and listenerWorkWork

Analysis

  • Reading traffic. In the baseline the messages were readable in the capture because nothing is encrypted. After SROS2, the message text was not in the capture.
  • Injecting traffic. The baseline attacker could publish because there is no authentication. With SROS2, the certificate authority is the trust anchor. It signs each node's certificate, and a node only accepts another node whose certificate the authority signed. The attacker had no certificate, so it was ignored.
  • Discovery. The governance file in the keystore has discovery protection turned on, which fits the attacker never seeing /chatter.
  • Enforce. Enforce only controls whether a node starts when its own security setup fails. The attacker ran with no security at all, so it was not blocked by Enforce. The secured nodes ignored it.
  • Permissions. The default listener permissions used a wildcard, rt/*, which allows any topic. The sample policy replaced it with specific topics: the listener's own parameter services, chatter, clock, and parameter_events. The rt/ prefix is how ROS topic names are written in DDS. This is least privilege: the listener can do what the demo needs and nothing else.
  • Metadata. Encrypted traffic still shows which addresses and ports are talking, one packet per second, and the packet sizes.
  • Not verified. The larger packet size and the extra packets in the secure capture are likely security overhead and handshake traffic. They were not decoded.

Limitations

  • Key handling. The whole keystore was mounted into every container, including the certificate authority's private key. On a real device each node should hold only its own enclave, and the authority's key should stay offline. Whoever has that key can issue valid identities.
  • Other attack surfaces. This covers only the ROS 2 network layer. Physical access, remote login, cloud services, software updates, and wireless links are separate problems.
  • Scale. Issuing, rotating, and revoking keys for one demo is easy. Doing it for a fleet is the hard part, and it was not tested.
  • One setup. One host, one middleware, one distribution. Other middleware options have their own security configuration.

Conclusion

Default ROS 2 trusts the network, and reading and injecting messages took no credentials. SROS2 added encryption, authentication, and per-node permissions, and each one stopped something different. The weak point moves to key management.

References

Repositories