Skip to content

Commit 798fcfe

Browse files
committed
Add integration tests for authorization
Added integration tests for the authorization functionality of the Zenoh transport. The tests cover scenarios for both authorized and unauthorized clients, ensuring that the authorization mechanism works as expected. The tests also verify that the access control configuration is correctly applied, and that clients can only publish and subscribe to topics they are authorized to access.
1 parent 21dc2cc commit 798fcfe

9 files changed

Lines changed: 414 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 75 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ zenoh = { version = "1.5.0" }
4545
chrono = "0.4.41"
4646
clap = { version = "4.5.40", features = ["derive"] }
4747
serde_json = "1.0.128"
48+
serial_test = { version = "3.2.0" }
4849
test-case = { version = "3.3" }
4950
tokio = { version = "1.45.1", default-features = false, features = ["rt-multi-thread", "signal"] }
5051
tracing-subscriber = "0.3.19"

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ Covers:
7878
### Authentication & Authorization
7979
`uman~auth-configuration~1`
8080

81-
The transport provided by this crate can be configured with credentials that the transport will provide to the Zenoh router during connection establishment. A [_username_ and _password_](https://zenoh.io/docs/manual/user-password/) can be specified in the Zenoh config file that is passed into the `UPTransportZenoh::new` function to create a new transport instance.
81+
The transport provided by this crate can be configured with credentials that the transport will provide to the Zenoh router during connection establishment. A [_username_ and _password_](https://zenoh.io/docs/manual/user-password/) can be specified in the Zenoh config file that is passed into the `UPTransportZenohBuilder::with_config_file` function.
8282

83-
Access to resources can be configured in the Zenoh config file by means of [Access Control Lists](https://zenoh.io/docs/manual/access-control/).
83+
Access to resources can be configured in the Zenoh (peer's or router's) config file by means of [Access Control Lists](https://zenoh.io/docs/manual/access-control/).
84+
The [authorization integration tests](./tests/authorization.rs) illustrate, how ACLs can be used to restrict a client's authority to put and subscribe to messages using corresponding rule sets.
8485

8586
Covers:
86-
- `req~utransport-send-error-permission-denied~2`
87+
- `req~utransport-send-prevent-address-spoofing~1`
88+
- `req~utransport-registerlistener-prevent-unauthorized-access~1`
8789

8890
### Maximum number of listeners
8991
`uman~max-listeners-configuration~1`
@@ -116,15 +118,16 @@ Needs: impl, itest
116118

117119
In general, uProtocol entities are only allowed to send messages on their own behalf. Certain specific uEntities acting as a uProtocol Streamer also need to send messages _on behalf of_ other uEntities in order to fulfill their original purpose of routing messages hence and forth between different transports. Making these authoritzation decisions requires the (proven) establishment of an _identity_ and its _authorities_.
118120

119-
The Zenoh transport delegates all authorization decisions to the Zenoh router that the transport is configured to connect to. For this purpose, the transport supports configuration of credentials which are being used during connection establishment. The Zenoh router uses the provided credentials to establish the client's identity and its associated authorities. Whenever the uEntity sends a message via the router or registers a subscriber for a key pattern, the router verifies, if the client is authorized to publish using the key or receive messages matching the key pattern.
121+
The Zenoh transport delegates all authorization decisions to the Zenoh router (or peer) that the transport is configured to connect to. For this purpose, the transport supports configuration of credentials which are being used during connection establishment. The Zenoh router uses the provided credentials to establish the client's identity and its associated authorities. Whenever the uEntity sends a message via the router or registers a subscriber for a key pattern, the router verifies that the client is authorized to publish using the key or receive messages matching the key pattern.
120122

121123
Rationale:
122124
The Zenoh transport is implemented as a library that is linked to the (custom) code that implements a uEntity's functionality. It is therefore not feasible to perform the authentication and authoritzation within the transport library code, because uEntities can not be forced to actually utilize one of uProtocol's transport libraries but may instead chooose to implement the binding to the transport protocol themselves.
123125

124126
Covers:
125-
- `req~utransport-send-error-permission-denied~2`
127+
- `req~utransport-send-prevent-address-spoofing~1`
128+
- `req~utransport-registerlistener-prevent-unauthorized-access~1`
126129

127-
Needs: impl, utest
130+
Needs: itest
128131

129132
## Change Log
130133

src/utransport.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use async_trait::async_trait;
1515
use bytes::Bytes;
1616
use protobuf::Message;
1717
use std::sync::Arc;
18-
use tracing::{debug, error};
18+
use tracing::{debug, error, trace};
1919
use up_rust::{
2020
ComparableListener, UAttributes, UAttributesValidators, UCode, UListener, UMessage, UPriority,
2121
UStatus, UTransport, UUri,
@@ -125,6 +125,7 @@ impl UPTransportZenoh {
125125
// [impl->dsn~up-transport-zenoh-attributes-mapping~1]
126126
.attachment(attachment)
127127
.await
128+
.inspect(|()| trace!("putting message with key: {zenoh_key}"))
128129
.map_err(|e| {
129130
UStatus::fail_with_code(
130131
UCode::INTERNAL,

0 commit comments

Comments
 (0)