Struct AdminCredentials

Source
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

Source

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()?,
    )],
)?;
Source

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:

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.

Source

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:

§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.

Source

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:

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.

Source

pub fn get_iteration(&self) -> u32

Returns the iteration.

Source

pub fn get_backup_passphrase(&self) -> &str

Returns the backup passphrase.

Source

pub fn get_unlock_passphrase(&self) -> &str

Returns the unlock passphrase.

Source

pub fn get_administrators(&self) -> &[FullCredentials]

Returns the list of administrators.

Source

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.

Source

pub fn get_namespace_administrators(&self) -> &[FullCredentials]

Returns the list of namespace administrators.

Source

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

Source§

fn clone(&self) -> AdminCredentials

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AdminCredentials

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AdminCredentials

Source§

fn default() -> AdminCredentials

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for AdminCredentials

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for AdminCredentials

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T