Skip to content

Commit 46ef8ef

Browse files
committed
ACL: For Writes, perform all ACL checks before any *write* begins
1 parent 18979fe commit 46ef8ef

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

rs-matter/src/data_model/core.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ use crate::{
2828
// TODO: For now...
2929
static SUBS_ID: AtomicU32 = AtomicU32::new(1);
3030

31+
/// The Maximum number of expanded writer request per transaction
32+
///
33+
/// The write requests are first wildcard-expanded, and these many number of
34+
/// write requests per-transaction will be supported.
35+
pub const MAX_WRITE_ATTRS_IN_ONE_TRANS: usize = 7;
36+
3137
pub struct DataModel<T>(T);
3238

3339
impl<T> DataModel<T> {
@@ -93,8 +99,21 @@ impl<T> DataModel<T> {
9399
ref mut driver,
94100
} => {
95101
let accessor = driver.accessor()?;
96-
97-
for item in metadata.node().write(req, &accessor) {
102+
// The spec expects that a single write request like DeleteList + AddItem
103+
// should cause all ACLs of that fabric to be deleted and the new one to be added (Case 1).
104+
//
105+
// This is in conflict with the immediate-effect expectation of ACL: an ACL
106+
// write should instantaneously update the ACL so that immediate next WriteAttribute
107+
// *in the same WriteRequest* should see that effect (Case 2).
108+
//
109+
// As with the C++ SDK, here we do all the ACLs checks first, before any write begins.
110+
// Thus we support the Case1 by doing this. It does come at the cost of maintaining an
111+
// additional list of expanded write requests as we start processing those.
112+
let node = metadata.node();
113+
let write_attrs: heapless::Vec<_, MAX_WRITE_ATTRS_IN_ONE_TRANS> =
114+
node.write(req, &accessor).collect();
115+
116+
for item in write_attrs {
98117
AttrDataEncoder::handle_write(&item, &self.0, &mut driver.writer()?)
99118
.await?;
100119
}

rs-matter/tests/data_model/acl_and_dataver.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,18 @@ fn insufficient_perms_write() {
371371
);
372372
}
373373

374+
/// Disabling this test as it conflicts with another part of the spec.
375+
///
376+
/// The spec expects that a single write request like DeleteList + AddItem
377+
/// should cause all ACLs of that fabric to be deleted and the new one to be added
378+
///
379+
/// This is in conflict with the immediate-effect expectation of ACL: an ACL
380+
/// write should instantaneously update the ACL so that immediate next WriteAttribute
381+
/// *in the same WriteRequest* should see that effect.
382+
///
383+
/// This test validates the immediate effect expectation of ACL, but that is disabled
384+
/// since ecosystems routinely send DeleteList+AddItem, so we support that over this.
385+
#[ignore]
374386
#[test]
375387
/// Ensure that a write to the ACL attribute instantaneously grants permission
376388
/// Here we have 2 ACLs, the first (basic_acl) allows access only to the ACL cluster

0 commit comments

Comments
 (0)