Elffuss BraidHub

utopia-ia/elffuss-braid public

hubproto: a verify:<glob> right, for tokens that only post verdicts

Right gains Verify(glob), read and written as verify:<glob> under the
rules of land:, and becomes non_exhaustive, so that a right added later
asks every match outside the crate for a wildcard arm. The error of a
right that does not parse names the new one. A scope holding verify:main
gives no landing in may_land, and one with a right a braid cannot read is
left out without changing what the other scopes give.
Changeset373d85f62fd57813ca8ed57689a622b0c04500c6e11e11d4bcaae3753df86016
AuthorKikoCis <KikoCis@users.noreply.github.com> · 2026-10-22 16:52 +02:00
CommitterKikoCis <KikoCis@users.noreply.github.com> · 2026-10-22 16:52 +02:00
Parents86bd0ef83e2c

Browse the files at this changeset

3 files changed

modified crates/cli/src/hub/request.rs +23 −0
@@ -2119,6 +2119,29 @@
21192119 assert_eq!(prefix_on(&elsewhere, &target, &info("admin"), "fix"), None);
21202120 let main_only = me(&[("ada/demo", &["write", "land:main"])]);
21212121 assert_eq!(prefix_on(&main_only, &target, &info("write"), "fix"), None);
2122+ // The token of a CI job, which posts verdicts, lands nowhere.
2123+ let verdicts = me(&[("ada/demo", &["read", "verify:main"])]);
2124+ assert_eq!(prefix_on(&verdicts, &target, &info("write"), "fix"), None);
2125+ // Beside a scope that lands it takes nothing away. Nor does a scope
2126+ // with a right this braid cannot read, as a braid older than
2127+ // `verify:` rights reads one: that scope is left out, and the
2128+ // others count.
2129+ let both = me(&[
2130+ ("ada/demo", &["read", "verify:main"]),
2131+ ("ada/demo", &["write", "land:request/*"]),
2132+ ]);
2133+ assert_eq!(
2134+ prefix_on(&both, &target, &info("write"), "fix").as_deref(),
2135+ Some("request/")
2136+ );
2137+ let unread = me(&[
2138+ ("ada/demo", &["read", "someday:main"]),
2139+ ("ada/demo", &["write", "land:request/*"]),
2140+ ]);
2141+ assert_eq!(
2142+ prefix_on(&unread, &target, &info("write"), "fix").as_deref(),
2143+ Some("request/")
2144+ );
21222145 }
21232146
21242147 /// A request read off a connection: its `Idempotency-Key` and its body.
modified crates/hubproto/src/api.rs +2 −1
@@ -173,7 +173,8 @@
173173 pub struct Scope {
174174 /// `owner/name`, `owner/*`, or `*`.
175175 pub repo: String,
176- /// `read`, `write`, `land:<glob>`, `admin`.
176+ /// `read`, `interact`, `write`, `land:<glob>`, `verify:<glob>`, `admin`
177+ /// (see [`crate::scope`]).
177178 pub rights: Vec<String>,
178179 }
179180
modified crates/hubproto/src/scope.rs +77 −15
@@ -3,13 +3,23 @@
33
44 //! Token scopes: which repositories a token reaches, and what it may do
55 //! there. A scope's `repo` is `owner/name`, `owner/*` or `*`; a right is
6-//! `read`, `interact`, `write`, `land:<ref glob>` or `admin`.
6+//! `read`, `interact`, `write`, `land:<ref glob>`, `verify:<ref glob>` or
7+//! `admin`.
78 //!
89 //! `write` includes `read`, and `admin` includes both. `interact` covers the
910 //! social writes (stars, watching, following, issues, comments, reviews and
1011 //! forks) on what the account may read; `write` and `admin` include it, and
1112 //! it gives no read of its own. A `land:<glob>` right lets a token land on
1213 //! the refs its glob matches, and only together with `write`.
14+//!
15+//! A `verify:<glob>` right lets a token post verdicts on the branches its
16+//! glob matches (section 25), and nothing else: it counts only where the
17+//! token's account may write, and only on a token that reads the repository
18+//! but holds no `write`, `admin`, `land:` or `interact` there, so that the
19+//! token of a CI job can say how its tests went and do nothing more.
20+//!
21+//! [`Right`] may gain rights: a client keeps a scope it cannot read out of
22+//! what it decides, as [`ParsedScope::parse`] refuses it whole.
1323
1424 use std::fmt;
1525
@@ -23,15 +33,18 @@
2333 #[error("{0:?} is not a repository pattern: expected \"owner/name\", \"owner/*\" or \"*\"")]
2434 Repo(String),
2535 /// A right that does not exist.
26- #[error("{0:?} is not a right: expected read, interact, write, admin or land:<ref glob>")]
36+ #[error(
37+ "{0:?} is not a right: expected read, interact, write, admin, land:<ref glob> or verify:<ref glob>"
38+ )]
2739 Right(String),
2840 /// A scope without rights.
2941 #[error("the scope for {0:?} grants no right")]
3042 NoRights(String),
3143 }
3244
33-/// One right of a scope.
45+/// One right of a scope. More may come: a `match` on it ends with `_`.
3446 #[derive(Clone, Debug, PartialEq, Eq, Hash)]
47+#[non_exhaustive]
3548 pub enum Right {
3649 /// Every `GET` and `HEAD`, `lacks`, `missing` and the ref watch.
3750 Read,
@@ -46,27 +59,38 @@
4659 /// Landing on the refs the glob matches (see
4760 /// [`glob_matches`](crate::names::glob_matches)), with `write`.
4861 Land(String),
62+ /// Posting verdicts on the branches the glob matches (section 25),
63+ /// where the account may write, on a token that holds nothing more
64+ /// there than `read`.
65+ Verify(String),
66+}
67+
68+/// The glob of a `land:` or `verify:` right: not empty, at most 4,096
69+/// bytes, and without control characters.
70+fn glob(text: &str) -> Option<String> {
71+ (!text.is_empty() && text.len() <= 4096 && !text.chars().any(char::is_control))
72+ .then(|| text.to_owned())
4973 }
5074
5175 impl Right {
52- /// Reads `read`, `interact`, `write`, `admin` or `land:<glob>`. A glob
53- /// is not empty and holds no control character.
76+ /// Reads `read`, `interact`, `write`, `admin`, `land:<glob>` or
77+ /// `verify:<glob>`. A glob is not empty and holds no control character.
5478 pub fn parse(text: &str) -> Result<Right, ScopeError> {
79+ let refused = || ScopeError::Right(text.to_owned());
5580 match text {
5681 "read" => Ok(Right::Read),
5782 "interact" => Ok(Right::Interact),
5883 "write" => Ok(Right::Write),
5984 "admin" => Ok(Right::Admin),
60- _ => match text.strip_prefix("land:") {
61- Some(glob)
62- if !glob.is_empty()
63- && glob.len() <= 4096
64- && !glob.chars().any(char::is_control) =>
65- {
66- Ok(Right::Land(glob.to_owned()))
85+ _ => {
86+ if let Some(rest) = text.strip_prefix("land:") {
87+ glob(rest).map(Right::Land).ok_or_else(refused)
88+ } else if let Some(rest) = text.strip_prefix("verify:") {
89+ glob(rest).map(Right::Verify).ok_or_else(refused)
90+ } else {
91+ Err(refused())
6792 }
68- _ => Err(ScopeError::Right(text.to_owned())),
69- },
93+ }
7094 }
7195 }
7296 }
@@ -79,6 +103,7 @@
79103 Right::Write => f.write_str("write"),
80104 Right::Admin => f.write_str("admin"),
81105 Right::Land(glob) => write!(f, "land:{glob}"),
106+ Right::Verify(glob) => write!(f, "verify:{glob}"),
82107 }
83108 }
84109 }
@@ -183,6 +208,8 @@
183208 ("admin", Right::Admin),
184209 ("land:*", Right::Land("*".into())),
185210 ("land:release/*", Right::Land("release/*".into())),
211+ ("verify:main", Right::Verify("main".into())),
212+ ("verify:*", Right::Verify("*".into())),
186213 ] {
187214 assert_eq!(Right::parse(text), Ok(right.clone()));
188215 assert_eq!(right.to_string(), text);
@@ -196,9 +223,27 @@
196223 "land",
197224 "push",
198225 "land:a\nb",
226+ "verify:",
227+ "verify",
228+ "VERIFY:main",
229+ "Verify:main",
230+ "verify:a\nb",
199231 ] {
200- assert!(Right::parse(bad).is_err(), "{bad:?}");
232+ assert_eq!(
233+ Right::parse(bad),
234+ Err(ScopeError::Right(bad.to_owned())),
235+ "{bad:?}"
236+ );
201237 }
238+ let long = format!("verify:{}", "a".repeat(4096));
239+ assert!(Right::parse(&long).is_ok());
240+ assert!(Right::parse(&format!("{long}a")).is_err());
241+ // The error names every right there is.
242+ let said = ScopeError::Right("push".into()).to_string();
243+ assert!(
244+ said.contains("land:<ref glob>") && said.contains("verify:<ref glob>"),
245+ "{said}"
246+ );
202247 }
203248
204249 #[test]
@@ -236,5 +281,22 @@
236281 ParsedScope::parse(&empty),
237282 Err(ScopeError::NoRights("*".into()))
238283 );
284+ // The scope of a CI job's token: it reads, and posts verdicts.
285+ let ci = Scope {
286+ repo: "ada/demo".into(),
287+ rights: vec!["read".into(), "verify:main".into()],
288+ };
289+ let parsed = ParsedScope::parse(&ci).unwrap();
290+ assert_eq!(parsed.rights, [Right::Read, Right::Verify("main".into())]);
291+ assert_eq!(parsed.to_scope(), ci);
292+ // A right this crate cannot read refuses its scope whole.
293+ let later = Scope {
294+ repo: "ada/demo".into(),
295+ rights: vec!["read".into(), "someday:main".into()],
296+ };
297+ assert_eq!(
298+ ParsedScope::parse(&later),
299+ Err(ScopeError::Right("someday:main".into()))
300+ );
239301 }
240302 }