Skip to content

Commit

Permalink
[antlir] Make uid/gid required
Browse files Browse the repository at this point in the history
Summary: Making sure I didn't miss a spot.

Test Plan: Signals

Reviewed By: wujj123456

Differential Revision: D66168664

fbshipit-source-id: aecaff71fe1304ae841b678bddec8137a6e6515c
  • Loading branch information
pzmarzly authored and facebook-github-bot committed Nov 21, 2024
1 parent 16b4c70 commit 57681fd
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 151 deletions.
2 changes: 0 additions & 2 deletions antlir/antlir2/antlir2_users/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ use std::fmt::Display;
use std::fmt::Formatter;

pub mod group;
mod next_available;
pub mod passwd;
pub mod shadow;
pub use next_available::NextAvailableId;

#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand Down
120 changes: 0 additions & 120 deletions antlir/antlir2/antlir2_users/src/next_available.rs

This file was deleted.

6 changes: 3 additions & 3 deletions antlir/antlir2/features/group/group.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ load("//antlir/antlir2/features:feature_info.bzl", "ParseTimeFeature", "data_onl

def group_add(
*,
groupname: str | Select,
gid: int | Select | None = None):
gid: int | Select,
groupname: str | Select):
"""
Add a group entry to /etc/group
Expand All @@ -26,7 +26,7 @@ def group_add(

group_rule = data_only_feature_rule(
feature_attrs = {
"gid": attrs.option(attrs.int(), default = None),
"gid": attrs.int(),
"groupname": attrs.string(),
},
feature_type = "group",
Expand Down
12 changes: 1 addition & 11 deletions antlir/antlir2/features/group/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use antlir2_depgraph_if::Requirement;
use antlir2_depgraph_if::Validator;
use antlir2_features::types::GroupName;
use antlir2_users::group::GroupRecord;
use antlir2_users::NextAvailableId;
use antlir2_users::Password;
use anyhow::Context;
use serde::Deserialize;
Expand Down Expand Up @@ -46,16 +45,7 @@ impl antlir2_compile::CompileFeature for Group {
#[tracing::instrument(skip(ctx), ret, err)]
fn compile(&self, ctx: &CompilerContext) -> antlir2_compile::Result<()> {
let mut groups_db = ctx.groups_db()?;
let gid = match self.gid {
Some(gid) => gid.into(),
None => {
let gid = groups_db
.next_available_id()
.context("no more gids available")?;
tracing::trace!("next available gid = {gid}");
gid
}
};
let gid = self.gid.context("gid is required")?.into();
let record = GroupRecord {
name: self.groupname.to_owned().into(),
password: Password::Shadow,
Expand Down
8 changes: 4 additions & 4 deletions antlir/antlir2/features/user/user.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ SHELL_NOLOGIN = "/sbin/nologin"

def user_add(
*,
uid: int | Select,
username: str | Select,
primary_group: str | Select,
home_dir: str | Select,
shell: str | Select = SHELL_NOLOGIN,
uid: int | Select | None = None,
supplementary_groups: list[str | Select] | Select = [],
comment: str | None = None):
"""
Expand Down Expand Up @@ -67,12 +67,12 @@ def user_add(
)

def standard_user(
uid: int,
username: str,
gid: int,
groupname: str,
home_dir: str | None = None,
shell: str = SHELL_BASH,
uid: int | None = None,
gid: int | None = None,
supplementary_groups: list[str] = []):
"""
A convenient function that wraps `group_add`, `user_add`,
Expand Down Expand Up @@ -110,7 +110,7 @@ user_rule = data_only_feature_rule(
"primary_group": attrs.string(),
"shell": attrs.string(),
"supplementary_groups": attrs.list(attrs.string()),
"uid": attrs.option(attrs.int(), default = None),
"uid": attrs.int(),
"username": attrs.string(),
},
feature_type = "user",
Expand Down
12 changes: 1 addition & 11 deletions antlir/antlir2/features/user/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use antlir2_features::types::GroupName;
use antlir2_features::types::PathInLayer;
use antlir2_features::types::UserName;
use antlir2_users::passwd::UserRecord;
use antlir2_users::NextAvailableId;
use antlir2_users::Password;
use anyhow::Context;
use serde::Deserialize;
Expand Down Expand Up @@ -75,16 +74,7 @@ impl antlir2_compile::CompileFeature for User {
#[tracing::instrument(name = "user", skip(ctx), ret, err)]
fn compile(&self, ctx: &CompilerContext) -> antlir2_compile::Result<()> {
let mut user_db = ctx.user_db()?;
let uid = match self.uid {
Some(uid) => uid.into(),
None => {
let uid = user_db
.next_available_id()
.context("no more uids available")?;
tracing::trace!("next available uid = {uid}");
uid
}
};
let uid = self.uid.context("uid is required")?.into();
let record = UserRecord {
name: self.username.clone().into(),
password: Password::Shadow,
Expand Down

0 comments on commit 57681fd

Please sign in to comment.