Skip to content

Commit 23c5932

Browse files
snehilzsOlivierHecartsashacmcfuzzypixelzMallets
authored
Added Access Control for Network Interface (#683)
* Code move * Code move * Use RoutingContext type * Structs split * Renaming * Visibility * Move ingress/egress filters out of pubsub * Make hat abstract * Abstract missing close_face fn * Duplicate hat * Move Primitives * Move link_id into HatFace * Change face initialization * Interceptors * Interceptor types renaming * Rename RoutingContext * Add RoutingContext and LoggerInterceptor * Interceptors can access the Config at construction * Split linkstate and p2p peer hats * Simplify HatTrait init function * Hats cleanup * Reintroduce routes precomputation * Improve routes precomputation * Reintroduce matching pulls precomputation * Perf improvements * Perf improvements * Remove files wrongly reintroduced by merge * Fix complete_n build * Remove useless checks * Fix OAM handling * Remove commented code * Simplified routes computation hats api * Move matching pulls computation out of hats * Fix query routes update * Fix copy-paste error * Renaming * Add missing query routes deactivations * Refactor code * Improve perfromances * WIP: added pep pdp points * WIP:added interceptor code and PEP logic * WIP:added datastructures for policy and PDP logic * WIP:first basic acl prototype * WIP:first acl prototype * WIP:first acl prototype * WIP:ACL phase 1 * WIP:ACL phase 1 * WIP:Modified ACL for attributes * WIP:Modified ACL for attributes * WIP:Cleaned code * WIP:merging code * WIP:adding config conditions * WIP:merging with DS * WIP:moved rules into config file * WIP:moved rules into config file * WIP:merging changes * Revert "WIP:merging changes" This reverts commit 50c9f0e. * WIP:merging new changes * WIP:merging new changes * WIP:ACL with networkinterface * WIP:ACL with networkinterface * WIP:ACL with networkinterface * WIP:ACL with networkinterface * WIP:Added multi-interface funcionality * WIP: Improved code design for ACL * WIP: Modified for new config style * WIP: Modified for new config style * WIP: Added changes for default behaviour * WIP: Added changes for default behaviour * WIP: Added changes for default behaviour * WIP: Cleaning code * WIP: Config changes after discussion * WIP: Config changes after discussion * WIP: Adding Queryable * WIP: Adding key-expr caching * Cleaning config file * made review changes * made review changes * adding review changes for logs and removing bool values * adding review changes * adding actions for both ingress and egress * adding ingress and egress flow * cleaning code * adding tests * cleaning policy code * acl tests for queryable * replaced nested Vec with structs * fixed queryable test issue * fixed cache downcast error * fixed interface issue in tests * move acl config out of transport * move acl config out of transport * clean tests code * clean tests code * clean config file * clean config file * clean code * resolve conflicts * resolve conflicts issues * refactor code * refactor code * refactor code * refactor code for review changes * refactor code for review changes * fix acl tests issue * fix acl tests issue * fix acl tests issue * fix acl tests issue * fix acl tests issue * resolve merge conflicts * Update DEFAULT_CONFIG.json5 Co-authored-by: Alexander <[email protected]> * change acl to access_control for clarity * fix: Remove sync-lockfiles workflow (#925) * modify actions values in config file * remove [ACCESS LOG] string from the logs * Remove [ACCESS LOG] from logging * rework access control logging * Add ingress/egress logs * add interface name in access logs * Fix log level * Add missing header * Add missing header files --------- Co-authored-by: OlivierHecart <[email protected]> Co-authored-by: Alexander <[email protected]> Co-authored-by: Mahmoud Mazouz <[email protected]> Co-authored-by: Luca Cominardi <[email protected]>
1 parent 3537ee6 commit 23c5932

15 files changed

+1337
-21
lines changed

Cargo.lock

Lines changed: 6 additions & 5 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,4 @@ debug = false # If you want debug symbol in release mode, set the env variab
219219
lto = "fat"
220220
codegen-units = 1
221221
opt-level = 3
222-
panic = "abort"
222+
panic = "abort"

DEFAULT_CONFIG.json5

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,30 @@
175175
// ],
176176
// },
177177
// ],
178-
178+
// /// configure access control (ACL) rules
179+
// access_control: {
180+
// ///[true/false] acl will be activated only if this is set to true
181+
// "enabled": false,
182+
// ///[deny/allow] default permission is deny (even if this is left empty or not specified)
183+
// "default_permission": "deny",
184+
// ///rule set for permissions allowing or denying access to key-expressions
185+
// "rules":
186+
// [
187+
// {
188+
// "actions": [
189+
// "put", "get", "declare_subscriber", "declare_queryable"
190+
// ],
191+
// "flows":["egress","ingress"],
192+
// "permission": "allow",
193+
// "key_exprs": [
194+
// "test/demo"
195+
// ],
196+
// "interfaces": [
197+
// "lo0"
198+
// ]
199+
// },
200+
// ]
201+
//},
179202
/// Configure internal transport parameters
180203
transport: {
181204
unicast: {
@@ -318,7 +341,6 @@
318341
shared_memory: {
319342
enabled: false,
320343
},
321-
/// Access control configuration
322344
auth: {
323345
/// The configuration of authentification.
324346
/// A password implies a username is required.

commons/zenoh-config/src/defaults.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@ impl Default for SharedMemoryConf {
221221
}
222222
}
223223

224+
impl Default for AclConfig {
225+
fn default() -> Self {
226+
Self {
227+
enabled: false,
228+
default_permission: Permission::Deny,
229+
rules: None,
230+
}
231+
}
232+
}
233+
224234
pub const DEFAULT_CONNECT_TIMEOUT_MS: ModeDependentValue<i64> =
225235
ModeDependentValue::Dependent(ModeValues {
226236
client: Some(0),

commons/zenoh-config/src/lib.rs

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ impl Zeroize for SecretString {
7373

7474
pub type SecretValue = Secret<SecretString>;
7575

76-
#[derive(Debug, Deserialize, Serialize, Clone)]
76+
#[derive(Debug, Deserialize, Serialize, Clone, Copy)]
7777
#[serde(rename_all = "lowercase")]
78-
pub enum DownsamplingFlow {
78+
pub enum InterceptorFlow {
7979
Egress,
8080
Ingress,
8181
}
@@ -97,7 +97,48 @@ pub struct DownsamplingItemConf {
9797
/// A list of interfaces to which the downsampling will be applied.
9898
pub rules: Vec<DownsamplingRuleConf>,
9999
/// Downsampling flow direction: egress, ingress
100-
pub flow: DownsamplingFlow,
100+
pub flow: InterceptorFlow,
101+
}
102+
103+
#[derive(Serialize, Debug, Deserialize, Clone)]
104+
pub struct AclConfigRules {
105+
pub interfaces: Vec<String>,
106+
pub key_exprs: Vec<String>,
107+
pub actions: Vec<Action>,
108+
pub flows: Vec<InterceptorFlow>,
109+
pub permission: Permission,
110+
}
111+
112+
#[derive(Clone, Serialize, Debug, Deserialize)]
113+
pub struct PolicyRule {
114+
pub subject: Subject,
115+
pub key_expr: String,
116+
pub action: Action,
117+
pub permission: Permission,
118+
pub flow: InterceptorFlow,
119+
}
120+
121+
#[derive(Serialize, Debug, Deserialize, Eq, PartialEq, Hash, Clone)]
122+
#[serde(untagged)]
123+
#[serde(rename_all = "snake_case")]
124+
pub enum Subject {
125+
Interface(String),
126+
}
127+
128+
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Eq, Hash, PartialEq)]
129+
#[serde(rename_all = "snake_case")]
130+
pub enum Action {
131+
Put,
132+
DeclareSubscriber,
133+
Get,
134+
DeclareQueryable,
135+
}
136+
137+
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Eq, Hash, PartialEq)]
138+
#[serde(rename_all = "lowercase")]
139+
pub enum Permission {
140+
Allow,
141+
Deny,
101142
}
102143

103144
pub trait ConfigValidator: Send + Sync {
@@ -431,6 +472,7 @@ validated_struct::validator! {
431472
known_keys_file: Option<String>,
432473
},
433474
},
475+
434476
},
435477
/// Configuration of the admin space.
436478
pub adminspace: #[derive(Default)]
@@ -456,6 +498,13 @@ validated_struct::validator! {
456498
/// Configuration of the downsampling.
457499
downsampling: Vec<DownsamplingItemConf>,
458500

501+
///Configuration of the access control (ACL)
502+
pub access_control: AclConfig {
503+
pub enabled: bool,
504+
pub default_permission: Permission,
505+
pub rules: Option<Vec<AclConfigRules>>
506+
},
507+
459508
/// A list of directories where plugins may be searched for if no `__path__` was specified for them.
460509
/// The executable's current directory will be added to the search paths.
461510
plugins_search_dirs: Vec<String>, // TODO (low-prio): Switch this String to a PathBuf? (applies to other paths in the config as well)

zenoh/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ transport_tls = ["zenoh-transport/transport_tls"]
4848
transport_udp = ["zenoh-transport/transport_udp"]
4949
transport_unixsock-stream = ["zenoh-transport/transport_unixsock-stream"]
5050
transport_ws = ["zenoh-transport/transport_ws"]
51-
transport_vsock= ["zenoh-transport/transport_vsock"]
51+
transport_vsock = ["zenoh-transport/transport_vsock"]
5252
unstable = []
5353
default = [
5454
"auth_pubkey",
@@ -66,6 +66,7 @@ default = [
6666
[dependencies]
6767
tokio = { workspace = true, features = ["rt", "macros", "time"] }
6868
tokio-util = { workspace = true }
69+
ahash = { workspace = true }
6970
async-trait = { workspace = true }
7071
base64 = { workspace = true }
7172
const_format = { workspace = true }

0 commit comments

Comments
 (0)