grant manage_root_agent by stored permission only, not by the name ruth
Permission::default_for and hive-sh4re's MANAGER_AGENT are gone: every agent with no permissions key holds Permission::DEFAULT, ruth included. The agent-name parameters that only fed default_for go with it (permissions::effective, HiveCopy::before_read/after_read and their callers). swarm-controller seeds the grant ruth held by name: at start, a declared ruth whose permissions are unset gets DEFAULT plus manage_root_agent written into her key, once, logged. A set key is never touched. It is a one-shot to delete once every swarm has passed it. The swarm UI setup assistant opens the create form with manage_root_agent checked, so a new ruth is created with the grant. permissions_import no longer adds ruth to the import or splits her default. Docs and help text no longer say ruth holds the grant by default; swarmctl-cli.md regenerated.
This commit is contained in:
parent
9258563f9c
commit
7b5400ecb8
26 changed files with 380 additions and 216 deletions
|
|
@ -34,20 +34,20 @@ pub fn current() -> Vec<Permission> {
|
|||
.read()
|
||||
.unwrap_or_else(PoisonError::into_inner)
|
||||
.clone();
|
||||
current_with(last, Path::new(HIVE_COPY_PATH), &crate::identity::label())
|
||||
current_with(last, Path::new(HIVE_COPY_PATH))
|
||||
}
|
||||
|
||||
/// [`current`] with the last read and the hive's copy given.
|
||||
fn current_with(last: Option<Vec<Permission>>, copy: &Path, agent: &str) -> Vec<Permission> {
|
||||
last.unwrap_or_else(|| HiveCopy::read_at(copy).before_read(agent))
|
||||
fn current_with(last: Option<Vec<Permission>>, copy: &Path) -> Vec<Permission> {
|
||||
last.unwrap_or_else(|| HiveCopy::read_at(copy).before_read())
|
||||
}
|
||||
|
||||
/// What one read of the key leaves the agent holding, judged against the
|
||||
/// hive's copy at `copy`; `None` (keep the last value) when the read failed
|
||||
/// or the bucket did not answer.
|
||||
fn after(agent: &str, copy: &Path, read: Option<Read>) -> Option<Vec<Permission>> {
|
||||
fn after(copy: &Path, read: Option<Read>) -> Option<Vec<Permission>> {
|
||||
match read? {
|
||||
Read::Current(record) => Some(HiveCopy::read_at(copy).after_read(agent, &record)),
|
||||
Read::Current(record) => Some(HiveCopy::read_at(copy).after_read(&record)),
|
||||
Read::NoBucket => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -63,7 +63,7 @@ pub async fn run() {
|
|||
tracing::info!(%agent, "reading swarm permissions from the swarm queue");
|
||||
loop {
|
||||
let read = read_once(&client, &agent).await;
|
||||
if let Some(perms) = after(&agent, Path::new(HIVE_COPY_PATH), read) {
|
||||
if let Some(perms) = after(Path::new(HIVE_COPY_PATH), read) {
|
||||
let mut current = CURRENT.write().unwrap_or_else(PoisonError::into_inner);
|
||||
if current.as_ref() != Some(&perms) {
|
||||
tracing::info!(?perms, "permissions: the swarm's set changed");
|
||||
|
|
@ -107,36 +107,29 @@ mod tests {
|
|||
fn a_read_sets_the_list_or_the_default_and_a_failure_keeps_the_last() {
|
||||
let none = Path::new("/nonexistent/swarm-permissions.json");
|
||||
assert_eq!(
|
||||
after(
|
||||
"atlas",
|
||||
none,
|
||||
Some(record(r#"{"permissions":["web_tools"]}"#))
|
||||
),
|
||||
after(none, Some(record(r#"{"permissions":["web_tools"]}"#))),
|
||||
Some(vec![Permission::WebTools])
|
||||
);
|
||||
assert_eq!(
|
||||
after("atlas", none, Some(record(r#"{"permissions":[]}"#))),
|
||||
after(none, Some(record(r#"{"permissions":[]}"#))),
|
||||
Some(Vec::new())
|
||||
);
|
||||
assert_eq!(
|
||||
after("atlas", none, Some(record("{}"))),
|
||||
after(none, Some(record("{}"))),
|
||||
Some(Permission::DEFAULT.to_vec())
|
||||
);
|
||||
assert_eq!(after("atlas", none, Some(Read::NoBucket)), None);
|
||||
assert_eq!(after("atlas", none, None), None);
|
||||
assert_eq!(after(none, Some(Read::NoBucket)), None);
|
||||
assert_eq!(after(none, None), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn before_the_first_read_the_stored_grant_applies() {
|
||||
let (_dir, path) = copy(r#"{"permissions":["web_tools"]}"#);
|
||||
assert_eq!(
|
||||
current_with(None, &path, "atlas"),
|
||||
vec![Permission::WebTools]
|
||||
);
|
||||
assert_eq!(current_with(None, &path), vec![Permission::WebTools]);
|
||||
let (_dir, path) = copy(r#"{"permissions":[]}"#);
|
||||
assert_eq!(current_with(None, &path, "atlas"), Vec::new());
|
||||
assert_eq!(current_with(None, &path), Vec::new());
|
||||
assert_eq!(
|
||||
current_with(Some(vec![Permission::Meta]), &path, "atlas"),
|
||||
current_with(Some(vec![Permission::Meta]), &path),
|
||||
vec![Permission::Meta],
|
||||
"a read outranks the copy"
|
||||
);
|
||||
|
|
@ -146,17 +139,17 @@ mod tests {
|
|||
fn while_the_import_is_pending_an_unset_key_keeps_the_stored_grant() {
|
||||
let (_dir, path) = copy(r#"{"permissions":["web_tools"],"import_pending":true}"#);
|
||||
assert_eq!(
|
||||
after("atlas", &path, Some(record("{}"))),
|
||||
after(&path, Some(record("{}"))),
|
||||
Some(vec![Permission::WebTools])
|
||||
);
|
||||
assert_eq!(
|
||||
after("atlas", &path, Some(record(r#"{"permissions":["meta"]}"#))),
|
||||
after(&path, Some(record(r#"{"permissions":["meta"]}"#))),
|
||||
Some(vec![Permission::Meta]),
|
||||
"a set key still wins"
|
||||
);
|
||||
let (_dir, path) = copy(r#"{"permissions":["web_tools"]}"#);
|
||||
assert_eq!(
|
||||
after("atlas", &path, Some(record("{}"))),
|
||||
after(&path, Some(record("{}"))),
|
||||
Some(Permission::DEFAULT.to_vec()),
|
||||
"once imported, unset is the default"
|
||||
);
|
||||
|
|
@ -169,13 +162,10 @@ mod tests {
|
|||
let (_dir, path) = copy(r#"{"permissions":["messaging"],"import_pending":true}"#);
|
||||
let mut last = None;
|
||||
for read in [None, Some(Read::NoBucket), None] {
|
||||
if let Some(perms) = after("atlas", &path, read) {
|
||||
if let Some(perms) = after(&path, read) {
|
||||
last = Some(perms);
|
||||
}
|
||||
}
|
||||
assert_eq!(
|
||||
current_with(last, &path, "atlas"),
|
||||
vec![Permission::Messaging]
|
||||
);
|
||||
assert_eq!(current_with(last, &path), vec![Permission::Messaging]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue