team-ljyzipelo

공개

그룹과 보조 그룹의 NSS 소스 검사를 보완함

작성자
시로사키 하나
작성 시각
커밋
2c401d6031d76f48ab70c07abd02022ae8b24618
부모
fdecd3a
이 시점의 파일 보기

변경된 파일 2개

+125-16
수정experiments/rust-archive-worker/src/filesystem.rs+38-14
@@ -237,25 +237,49 @@ mod platform {
237237 let Ok(policy) = std::fs::read_to_string("/etc/nsswitch.conf") else {
238238 return false;
239239 };
240삭제: let mut sources = policy.lines().filter_map(|line| {
240추가: let mut databases = [None, None, None];
241추가: for line in policy.lines() {
241242 let line = line.split('#').next().unwrap_or_default();
242삭제: let (database, sources) = line.split_once(':')?;
243삭제: (database.trim() == "passwd").then_some(sources)
244삭제: });
245삭제: let Some(source) = sources.next() else {
243추가: let Some((database, sources)) = line.split_once(':') else {
244추가: continue;
245추가: };
246추가: let index = match database.trim() {
247추가: "passwd" => 0,
248추가: "group" => 1,
249추가: "initgroups" => 2,
250추가: _ => continue,
251추가: };
252추가: if databases[index]
253추가: .replace(sources.split_whitespace().collect::<Vec<_>>())
254추가: .is_some()
255추가: {
256추가: return false;
257추가: }
258추가: }
259추가: let [Some(passwd), Some(group), initgroups] = databases else {
246260 return false;
247261 };
248삭제: let source: Vec<_> = source.split_whitespace().collect();
249삭제: if sources.next().is_some()
250삭제: || !matches!(
262추가: let mut has_systemd = false;
263추가: let mut has_sss = false;
264추가: // initgroups가 생략되어도 기본값인 group 소스를 검사함.
265추가: for source in [Some(passwd), Some(group), initgroups]
266추가: .into_iter()
267추가: .flatten()
268추가: {
269추가: if !matches!(
251270 source.as_slice(),
252271 ["files"] | ["files", "systemd"] | ["files", "sss"] | ["files", "systemd", "sss"]
272추가: ) {
273추가: return false;
274추가: }
275추가: has_systemd |= source.contains(&"systemd");
276추가: has_sss |= source.contains(&"sss");
277추가: }
278추가: if has_sss
279추가: && !sss_is_unused(
280추가: Path::new("/var/lib/sss/pipes/nss"),
281추가: Path::new("/var/lib/sss/mc"),
253282 )
254삭제: || (source.contains(&"sss")
255삭제: && !sss_is_unused(
256삭제: Path::new("/var/lib/sss/pipes/nss"),
257삭제: Path::new("/var/lib/sss/mc"),
258삭제: ))
259283 {
260284 return false;
261285 }
@@ -288,7 +312,7 @@ mod platform {
288312 let Some(current_name) = current_name else {
289313 return false;
290314 };
291삭제: !source.contains(&"systemd")
315추가: !has_systemd
292316 || crate::systemd_userdb::group_is_private(
293317 gid,
294318 current_uid,
수정tests/rust-archive-worker/private_group.rs+87-2
@@ -10,6 +10,10 @@ pub(super) fn check_extraction(case: &str, safe: bool) {
1010}
1111
1212fn run_case(case: &str, safe: bool, extraction: bool) {
13추가: run_case_with_policy(case, safe, extraction, None);
14추가: }
15추가:
16추가: fn run_case_with_policy(case: &str, safe: bool, extraction: bool, policy: Option<&str>) {
1317 let scratch = Scratch::new();
1418 let output = scratch.0.join("output");
1519 fs::create_dir(&output).unwrap();
@@ -64,8 +68,13 @@ fn run_case(case: &str, safe: bool, extraction: bool) {
6468 }
6569 _ => "# fixture\npasswd: files # local accounts\n",
6670 };
71추가: let nss = if case == "missing-policy" {
72추가: nss.to_owned()
73추가: } else {
74추가: format!("{nss}group: files\n")
75추가: };
6776 let nss_path = scratch.0.join("nsswitch.conf");
68삭제: fs::write(&nss_path, nss).unwrap();
77추가: fs::write(&nss_path, policy.unwrap_or(&nss)).unwrap();
6978 if case == "nss-unavailable" {
7079 fs::remove_file(&nss_path).unwrap();
7180 }
@@ -125,7 +134,7 @@ fn run_case(case: &str, safe: bool, extraction: bool) {
125134 .unwrap();
126135 assert!(
127136 result.status.success(),
128삭제: "{case}: {} {}",
137추가: "{case} policy={policy:?}: {} {}",
129138 String::from_utf8_lossy(&result.stdout),
130139 String::from_utf8_lossy(&result.stderr)
131140 );
@@ -255,6 +264,82 @@ fn private_group_checks_varlink_records_and_completion() {
255264 }
256265}
257266
267추가: #[test]
268추가: fn private_group_checks_systemd_in_group_and_initgroups_policies() {
269추가: for policy in [
270추가: "passwd: files\ngroup: files systemd\n",
271추가: "passwd: files\ngroup: files systemd\ninitgroups: files\n",
272추가: "passwd: files\ngroup: files\ninitgroups: files systemd\n",
273추가: ] {
274추가: for case in ["systemd-personal", "systemd-unrelated"] {
275추가: run_case_with_policy(case, true, true, Some(policy));
276추가: }
277추가: for case in [
278추가: "systemd-dynamic-shared",
279추가: "systemd-group-member",
280추가: "systemd-membership-member",
281추가: "systemd-user-member",
282추가: "systemd-partial-error",
283추가: "userdb-d0",
284추가: ] {
285추가: run_case_with_policy(case, false, true, Some(policy));
286추가: }
287추가: }
288추가: }
289추가:
290추가: #[test]
291추가: fn private_group_checks_sss_in_group_and_initgroups_policies() {
292추가: for policy in [
293추가: "passwd: files\ngroup: files sss\n",
294추가: "passwd: files\ngroup: files sss\ninitgroups: files\n",
295추가: "passwd: files\ngroup: files\ninitgroups: files sss\n",
296추가: ] {
297추가: run_case_with_policy("sss-empty", true, true, Some(policy));
298추가: for case in [
299추가: "sss-socket",
300추가: "sss-passwd-cache",
301추가: "sss-group-cache",
302추가: "sss-initgr-cache",
303추가: "sss-probe-error",
304추가: ] {
305추가: run_case_with_policy(case, false, true, Some(policy));
306추가: }
307추가: }
308추가: }
309추가:
310추가: #[test]
311추가: fn private_group_rejects_incomplete_group_and_initgroups_policies() {
312추가: for policy in [
313추가: "passwd: files\n",
314추가: "passwd: files\ngroup: files\ngroup: files\n",
315추가: "passwd: files\ngroup: files\ninitgroups: files\ninitgroups: files\n",
316추가: ] {
317추가: run_case_with_policy("personal", false, true, Some(policy));
318추가: }
319추가: for source in [
320추가: "",
321추가: "files ldap",
322추가: "files winbind",
323추가: "files unknown",
324추가: "files [SUCCESS=return] systemd",
325추가: "files systemd [UNAVAIL=continue]",
326추가: "files files",
327추가: ] {
328추가: for policy in [
329추가: format!("passwd: files\ngroup: {source}\n"),
330추가: format!("passwd: files\ngroup: files\ninitgroups: {source}\n"),
331추가: ] {
332추가: run_case_with_policy("personal", false, true, Some(&policy));
333추가: }
334추가: }
335추가: run_case_with_policy(
336추가: "personal",
337추가: true,
338추가: true,
339추가: Some("passwd: files\ngroup: files\ninitgroups: files # local groups\n"),
340추가: );
341추가: }
342추가:
258343#[test]
259344fn private_group_rejects_consumed_systemd_record_on_erange() {
260345 // NSS 버퍼 재시도 대신 완전한 varlink 레코드를 직접 검사함.