diff --git a/swarm-nats-auth/src/policy.rs b/swarm-nats-auth/src/policy.rs index e3234cf36..a1253cba6 100644 --- a/swarm-nats-auth/src/policy.rs +++ b/swarm-nats-auth/src/policy.rs @@ -844,6 +844,14 @@ impl Policy { "$JS.API.CONSUMER.CREATE.{}", swarm_wire::agent_permissions::STREAM )); + // The bash task statuses, listed the same way: the task list calls + // `keys()` for an agent's tasks. Without this subject the create + // request is refused and reaches the client as a timeout, so the list + // timed out every time. + subjects.push(format!( + "$JS.API.CONSUMER.CREATE.{}", + swarm_wire::bash_task::STREAM + )); subjects } } @@ -917,6 +925,18 @@ mod tests { ); } + #[test] + fn the_reader_can_list_the_bash_task_statuses_and_no_other_stream() { + let subjects = policy().reader_subjects(); + let s = swarm_wire::bash_task::STREAM; + // The bare form is what `keys()` needs: its ephemeral consumer has + // no name. + assert!(subjects.contains(&format!("$JS.API.CONSUMER.CREATE.{s}"))); + assert!(!subjects.contains(&format!("$JS.API.CONSUMER.CREATE.{s}.>"))); + assert!(!subjects.contains(&"$JS.API.CONSUMER.CREATE.*".to_owned())); + assert_eq!(s, format!("KV_{}", swarm_wire::bash_task::BUCKET)); + } + #[test] fn no_hive_may_write_another_role_s_agent_status() { // A hive publishes its *own* agents' status under diff --git a/swarm-wire/src/bash_task.rs b/swarm-wire/src/bash_task.rs index cdfc0dd9d..2e6c45023 100644 --- a/swarm-wire/src/bash_task.rs +++ b/swarm-wire/src/bash_task.rs @@ -26,6 +26,9 @@ use crate::TERM_SUBJECT_PREFIX; /// The KV bucket the task statuses are published into. pub const BUCKET: &str = "bash-task-status"; +/// The stream backing [`BUCKET`]. `create_key_value` prefixes `KV_`. +pub const STREAM: &str = "KV_bash-task-status"; + /// How often the writer republishes a `running` status while the task's /// process lives, so a writer that died shows up as stale. pub const HEARTBEAT_S: i64 = 60;