pub struct AdminCredentials {
iteration: u32,
backup_passphrase: Passphrase,
unlock_passphrase: Passphrase,
administrators: Vec<FullCredentials>,
namespace_administrators: Vec<FullCredentials>,
}
Expand description
Administrative credentials.
Tracks the following credentials and passphrases:
- the backup passphrase of the backend,
- the unlock passphrase of the backend,
- the top-level administrator credentials of the backend,
- the namespace administrator credentials of the backend.
§Note
The unlock and backup passphrase must be at least 10 characters long. The passphrases of top-level and namespace administrator accounts must be at least 10 characters long. The list of top-level administrator credentials must include an account with the username “admin”.
Fields§
§iteration: u32
§backup_passphrase: Passphrase
§unlock_passphrase: Passphrase
§administrators: Vec<FullCredentials>
§namespace_administrators: Vec<FullCredentials>
Implementations§
Source§impl AdminCredentials
impl AdminCredentials
Sourcepub fn new(
iteration: u32,
backup_passphrase: Passphrase,
unlock_passphrase: Passphrase,
administrators: Vec<FullCredentials>,
namespace_administrators: Vec<FullCredentials>,
) -> Result<Self, Error>
pub fn new( iteration: u32, backup_passphrase: Passphrase, unlock_passphrase: Passphrase, administrators: Vec<FullCredentials>, namespace_administrators: Vec<FullCredentials>, ) -> Result<Self, Error>
Creates a new AdminCredentials
instance.
§Examples
use nethsm::FullCredentials;
use signstar_config::admin_credentials::AdminCredentials;
let creds = AdminCredentials::new(
1,
"backup-passphrase".parse()?,
"unlock-passphrase".parse()?,
vec![FullCredentials::new(
"admin".parse()?,
"admin-passphrase".parse()?,
)],
vec![FullCredentials::new(
"ns1~admin".parse()?,
"ns1-admin-passphrase".parse()?,
)],
)?;
Sourcepub fn load(
secrets_handling: AdministrativeSecretHandling,
) -> Result<Self, Error>
pub fn load( secrets_handling: AdministrativeSecretHandling, ) -> Result<Self, Error>
Loads an AdminCredentials
from the default file location.
Depending on secrets_handling
, the file path and contents differ:
AdministrativeSecretHandling::Plaintext
: the file path is defined byget_plaintext_credentials_file
and the contents are plaintext,AdministrativeSecretHandling::SystemdCreds
: the file path is defined byget_systemd_creds_credentials_file
and the contents are systemd-creds encrypted.
Delegates to AdminCredentials::load_from_file
, providing the specific file path and the
selected secrets_handling
.
§Examples
use nethsm_config::AdministrativeSecretHandling;
use signstar_config::admin_credentials::AdminCredentials;
// load plaintext credentials from default location
let plaintext_admin_creds = AdminCredentials::load(AdministrativeSecretHandling::Plaintext)?;
// load systemd-creds encrypted credentials from default location
let systemd_creds_admin_creds =
AdminCredentials::load(AdministrativeSecretHandling::SystemdCreds)?;
§Errors
Returns an error if AdminCredentials::load_from_file
fails.
§Panics
This function panics when providing AdministrativeSecretHandling::ShamirsSecretSharing
as secrets_handling
.
Sourcepub fn load_from_file(
path: impl AsRef<Path>,
secrets_handling: AdministrativeSecretHandling,
) -> Result<Self, Error>
pub fn load_from_file( path: impl AsRef<Path>, secrets_handling: AdministrativeSecretHandling, ) -> Result<Self, Error>
Loads an AdminCredentials
instance from file.
Depending on path
and secrets_handling
, the behavior of this function differs:
- If
secrets_handling
is set toAdministrativeSecretHandling::Plaintext
the contents atpath
are considered to be plaintext. - If
secrets_handling
is set toAdministrativeSecretHandling::SystemdCreds
the contents atpath
are considered to be systemd-creds encrypted.
§Examples
use std::io::Write;
use nethsm_config::AdministrativeSecretHandling;
use signstar_config::admin_credentials::AdminCredentials;
let admin_creds = r#"iteration = 1
backup_passphrase = "backup-passphrase"
unlock_passphrase = "unlock-passphrase"
[[administrators]]
name = "admin"
passphrase = "admin-passphrase"
[[namespace_administrators]]
name = "ns1~admin"
passphrase = "ns1-admin-passphrase"
"#;
let mut tempfile = tempfile::NamedTempFile::new()?;
write!(tempfile.as_file_mut(), "{admin_creds}");
assert!(
AdminCredentials::load_from_file(tempfile.path(), AdministrativeSecretHandling::Plaintext)
.is_ok()
);
§Errors
Returns an error if
- the function is called by a system user that is not root,
- the file at
path
does not exist, - the file at
path
is not a file, - the file at
path
is considered as plaintext but can not be loaded, - the file at
path
is considered as systemd-creds encrypted but can not be decrypted, - or the file at
path
is considered as systemd-creds encrypted but can not be loaded after decryption.
§Panics
This function panics when providing AdministrativeSecretHandling::ShamirsSecretSharing
as secrets_handling
.
Sourcepub fn store(
&self,
secrets_handling: AdministrativeSecretHandling,
) -> Result<(), Error>
pub fn store( &self, secrets_handling: AdministrativeSecretHandling, ) -> Result<(), Error>
Stores the AdminCredentials
as a file in the default location.
Depending on secrets_handling
, the file path and contents differ:
AdministrativeSecretHandling::Plaintext
: the file path is defined byget_plaintext_credentials_file
and the contents are plaintext,AdministrativeSecretHandling::SystemdCreds
: the file path is defined byget_systemd_creds_credentials_file
and the contents are systemd-creds encrypted.
Automatically creates the directory in which the administrative credentials are created.
After storing the AdminCredentials
as file, its file permissions and ownership are
adjusted so that it is only accessible by root.
§Examples
use nethsm::FullCredentials;
use nethsm_config::AdministrativeSecretHandling;
use signstar_config::admin_credentials::AdminCredentials;
let creds = AdminCredentials::new(
1,
"backup-passphrase".parse()?,
"unlock-passphrase".parse()?,
vec![FullCredentials::new(
"admin".parse()?,
"admin-passphrase".parse()?,
)],
vec![FullCredentials::new(
"ns1~admin".parse()?,
"ns1-admin-passphrase".parse()?,
)],
)?;
// store as plaintext file
creds.store(AdministrativeSecretHandling::Plaintext)?;
// store as systemd-creds encrypted file
creds.store(AdministrativeSecretHandling::SystemdCreds)?;
§Errors
Returns an error if
- the function is called by a system user that is not root,
- the directory for administrative credentials cannot be created,
self
cannot be turned into its TOML representation,- the systemd-creds command is not found,
- systemd-creds fails to encrypt the TOML representation of
self
, - the target file can not be created,
- the plaintext or systemd-creds encrypted data can not be written to file,
- or the ownership or permissions of the target file can not be adjusted.
§Panics
This function panics when providing AdministrativeSecretHandling::ShamirsSecretSharing
as secrets_handling
.
Sourcepub fn get_iteration(&self) -> u32
pub fn get_iteration(&self) -> u32
Returns the iteration.
Sourcepub fn get_backup_passphrase(&self) -> &str
pub fn get_backup_passphrase(&self) -> &str
Returns the backup passphrase.
Sourcepub fn get_unlock_passphrase(&self) -> &str
pub fn get_unlock_passphrase(&self) -> &str
Returns the unlock passphrase.
Sourcepub fn get_administrators(&self) -> &[FullCredentials]
pub fn get_administrators(&self) -> &[FullCredentials]
Returns the list of administrators.
Sourcepub fn get_default_administrator(&self) -> Result<&FullCredentials, Error>
pub fn get_default_administrator(&self) -> Result<&FullCredentials, Error>
Returns the default system-wide administrator “admin”.
§Errors
Returns an error if no administrative account with the system-wide [UserId
] “admin” is
found.
Sourcepub fn get_namespace_administrators(&self) -> &[FullCredentials]
pub fn get_namespace_administrators(&self) -> &[FullCredentials]
Returns the list of namespace administrators.
Sourcefn validate(&self) -> Result<(), Error>
fn validate(&self) -> Result<(), Error>
Validates the AdminCredentials
.
§Errors
Returns an error if
- there is no top-level administrator user,
- the default top-level administrator user (with the name “admin”) is missing,
- a user passphrase is too short,
- the backup passphrase is too short,
- or the unlock passphrase is too short.
Trait Implementations§
Source§impl Clone for AdminCredentials
impl Clone for AdminCredentials
Source§fn clone(&self) -> AdminCredentials
fn clone(&self) -> AdminCredentials
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for AdminCredentials
impl Debug for AdminCredentials
Source§impl Default for AdminCredentials
impl Default for AdminCredentials
Source§fn default() -> AdminCredentials
fn default() -> AdminCredentials
Source§impl<'de> Deserialize<'de> for AdminCredentials
impl<'de> Deserialize<'de> for AdminCredentials
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for AdminCredentials
impl RefUnwindSafe for AdminCredentials
impl Send for AdminCredentials
impl Sync for AdminCredentials
impl Unpin for AdminCredentials
impl UnwindSafe for AdminCredentials
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more