disable a destroyed agent's identity entity and delete its login role
This commit is contained in:
parent
db924d9e77
commit
299b922039
1 changed files with 528 additions and 9 deletions
|
|
@ -91,6 +91,20 @@ pub(crate) trait AccessStore {
|
|||
fn rename_entity(&self, id: &str, name: &str)
|
||||
-> impl Future<Output = Result<(), Error>> + Send;
|
||||
|
||||
/// As [`SecretStore::set_entity_disabled`].
|
||||
fn set_entity_disabled(
|
||||
&self,
|
||||
name: &str,
|
||||
disabled: bool,
|
||||
) -> impl Future<Output = Result<(), Error>> + Send;
|
||||
|
||||
/// As [`SecretStore::delete_cert_role`].
|
||||
fn delete_cert_role(
|
||||
&self,
|
||||
mount: &str,
|
||||
name: &str,
|
||||
) -> impl Future<Output = Result<(), Error>> + Send;
|
||||
|
||||
/// As [`SecretStore::create_entity_alias`].
|
||||
fn create_entity_alias(
|
||||
&self,
|
||||
|
|
@ -160,6 +174,14 @@ impl AccessStore for SecretStore {
|
|||
) -> Result<(), Error> {
|
||||
SecretStore::create_entity_alias(self, alias_name, mount_accessor, entity_id).await
|
||||
}
|
||||
|
||||
async fn set_entity_disabled(&self, name: &str, disabled: bool) -> Result<(), Error> {
|
||||
SecretStore::set_entity_disabled(self, name, disabled).await
|
||||
}
|
||||
|
||||
async fn delete_cert_role(&self, mount: &str, name: &str) -> Result<(), Error> {
|
||||
SecretStore::delete_cert_role(self, mount, name).await
|
||||
}
|
||||
}
|
||||
|
||||
/// A store that records what it is asked to do, for tests of the order and the
|
||||
|
|
@ -204,6 +226,10 @@ pub(crate) mod fake {
|
|||
/// The entity that owns each alias, as `(id, name)`.
|
||||
alias_owner: Option<(String, String)>,
|
||||
entities: Mutex<Vec<String>>,
|
||||
/// The entities, by name, whose `disabled` flag is set.
|
||||
disabled: Mutex<std::collections::BTreeSet<String>>,
|
||||
/// The calls, by verb, that are refused.
|
||||
refused: Vec<&'static str>,
|
||||
calls: Mutex<Vec<String>>,
|
||||
}
|
||||
|
||||
|
|
@ -261,6 +287,32 @@ pub(crate) mod fake {
|
|||
self
|
||||
}
|
||||
|
||||
/// A store that already holds the entity `name`.
|
||||
pub(crate) fn with_entity(self, name: &str) -> Self {
|
||||
self.entities
|
||||
.lock()
|
||||
.expect("not poisoned")
|
||||
.push(name.to_owned());
|
||||
self
|
||||
}
|
||||
|
||||
/// A store that refuses to set an entity's `disabled` flag.
|
||||
pub(crate) fn refusing_disable(mut self) -> Self {
|
||||
self.refused.push("set_entity_disabled");
|
||||
self
|
||||
}
|
||||
|
||||
/// A store that refuses to delete a cert-auth role.
|
||||
pub(crate) fn refusing_role_delete(mut self) -> Self {
|
||||
self.refused.push("delete_cert_role");
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether the entity `name` is disabled now.
|
||||
pub(crate) fn is_disabled(&self, name: &str) -> bool {
|
||||
self.disabled.lock().expect("not poisoned").contains(name)
|
||||
}
|
||||
|
||||
/// The role `name` as the store holds it now.
|
||||
pub(crate) fn role(&self, name: &str) -> Option<FakeRole> {
|
||||
self.roles.lock().expect("not poisoned").get(name).cloned()
|
||||
|
|
@ -403,5 +455,28 @@ pub(crate) mod fake {
|
|||
self.log(format!("create_entity_alias {alias_name}"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_entity_disabled(&self, name: &str, disabled: bool) -> Result<(), Error> {
|
||||
self.log(format!("set_entity_disabled {name} {disabled}"));
|
||||
if self.refused.contains(&"set_entity_disabled") {
|
||||
return Err(Self::denied());
|
||||
}
|
||||
let mut flagged = self.disabled.lock().expect("not poisoned");
|
||||
if disabled {
|
||||
flagged.insert(name.to_owned());
|
||||
} else {
|
||||
flagged.remove(name);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_cert_role(&self, _mount: &str, name: &str) -> Result<(), Error> {
|
||||
self.log(format!("delete_cert_role {name}"));
|
||||
if self.refused.contains(&"delete_cert_role") {
|
||||
return Err(Self::denied());
|
||||
}
|
||||
self.roles.lock().expect("not poisoned").remove(name);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue