Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repair: add sequoia subcommand that can migrate build users to the new 351+ UID range #1143

Merged
merged 15 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/action/base/add_user_to_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Create an operating system level user in the given group
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
#[serde(tag = "action_name", rename = "add_user_to_group")]
pub struct AddUserToGroup {
name: String,
uid: u32,
groupname: String,
gid: u32,
pub(crate) name: String,
pub(crate) uid: u32,
pub(crate) groupname: String,
pub(crate) gid: u32,
}

impl AddUserToGroup {
Expand Down
53 changes: 28 additions & 25 deletions src/action/base/create_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Create an operating system level user in the given group
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
#[serde(tag = "action_name", rename = "create_user")]
pub struct CreateUser {
name: String,
uid: u32,
groupname: String,
gid: u32,
pub(crate) name: String,
pub(crate) uid: u32,
pub(crate) groupname: String,
pub(crate) gid: u32,
comment: String,
}

Expand All @@ -29,6 +29,7 @@ impl CreateUser {
groupname: String,
gid: u32,
comment: String,
check_completed: bool,
) -> Result<StatefulAction<Self>, ActionError> {
let this = Self {
name: name.clone(),
Expand All @@ -50,29 +51,31 @@ impl CreateUser {
},
}

// Ensure user does not exists
if let Some(user) = User::from_name(name.as_str())
.map_err(|e| ActionErrorKind::GettingUserId(name.clone(), e))
.map_err(Self::error)?
{
if user.uid.as_raw() != uid {
return Err(Self::error(ActionErrorKind::UserUidMismatch(
name.clone(),
user.uid.as_raw(),
uid,
)));
}
if check_completed {
// Ensure user does not exist
if let Some(user) = User::from_name(name.as_str())
.map_err(|e| ActionErrorKind::GettingUserId(name.clone(), e))
.map_err(Self::error)?
{
if user.uid.as_raw() != uid {
return Err(Self::error(ActionErrorKind::UserUidMismatch(
name.clone(),
user.uid.as_raw(),
uid,
)));
}

if user.gid.as_raw() != gid {
return Err(Self::error(ActionErrorKind::UserGidMismatch(
name.clone(),
user.gid.as_raw(),
gid,
)));
}
if user.gid.as_raw() != gid {
return Err(Self::error(ActionErrorKind::UserGidMismatch(
name.clone(),
user.gid.as_raw(),
gid,
)));
}

tracing::debug!("Creating user `{}` already complete", this.name);
return Ok(StatefulAction::completed(this));
tracing::debug!("Creating user `{}` already complete", this.name);
return Ok(StatefulAction::completed(this));
}
}

Ok(StatefulAction::uncompleted(this))
Expand Down
17 changes: 9 additions & 8 deletions src/action/common/create_users_and_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use tracing::{span, Span};
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
#[serde(tag = "action_name", rename = "create_users_and_group")]
pub struct CreateUsersAndGroups {
nix_build_user_count: u32,
nix_build_group_name: String,
nix_build_group_id: u32,
nix_build_user_prefix: String,
nix_build_user_id_base: u32,
create_group: StatefulAction<CreateGroup>,
create_users: Vec<StatefulAction<CreateUser>>,
add_users_to_groups: Vec<StatefulAction<AddUserToGroup>>,
pub(crate) nix_build_group_name: String,
pub(crate) nix_build_group_id: u32,
pub(crate) nix_build_user_count: u32,
pub(crate) nix_build_user_prefix: String,
pub(crate) nix_build_user_id_base: u32,
pub(crate) create_group: StatefulAction<CreateGroup>,
pub(crate) create_users: Vec<StatefulAction<CreateUser>>,
pub(crate) add_users_to_groups: Vec<StatefulAction<AddUserToGroup>>,
}

impl CreateUsersAndGroups {
Expand All @@ -37,6 +37,7 @@ impl CreateUsersAndGroups {
settings.nix_build_group_name.clone(),
settings.nix_build_group_id,
format!("Nix build user {index}"),
true,
)
.await
.map_err(Self::error)?,
Expand Down
2 changes: 1 addition & 1 deletion src/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl ActionDescription {
}

/// A 'tag' name an action has that corresponds to the one we serialize in [`typetag]`
pub struct ActionTag(&'static str);
pub struct ActionTag(pub &'static str);

impl std::fmt::Display for ActionTag {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down
Loading
Loading