Skip to content

Commit 455fb68

Browse files
committed
test(cdi): check the standard sbin paths in CDI workloads
Add a scenario whose spec narrows PATH to directories without sbin and a path-has check, and expect the standard sbin directories to be appended for the workload. Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent 8486c7b commit 455fb68

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

‎TESTING.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ CDI. Branch and release feature-test matrices run this suite on Docker.
371371
| `omitted-access-file` | Bind without `ro` or `rw` | Launch rejects the effectively writable mount. |
372372
| `mps-pipe-directory` | Directory at `/tmp/nvidia-mps` mounted `nosuid`, `nodev`, `noexec` | Read and write succeed on its contents. |
373373
| `mps-pipe-directory-without-noexec` | The same directory without `noexec` | Launch rejects the mount. |
374+
| `sbin-path` | Spec environment edit narrowing `PATH` to `/usr/local/bin:/usr/bin:/bin` | The standard sbin directories are appended to the workload's `PATH`. |
374375
| `device-node` | Null character device at `/dev/tmachine-cdi-null` | Non-root; write succeeds. |
375376
| `device-node-with-gid` | Group-restricted null device at `/dev/tmachine-cdi-group-null` | Non-root with the device's group; write succeeds. |
376377
| `unix-socket` | Echo socket at `/tmachine-cdi/socket/echo.sock` | Sibling file in the host directory is not visible. |

‎tests/ansible/roles/cdi_fixtures/vars/scenarios.yaml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
# {type: non-root, expect} whether the workload is not uid 0 (true)
3131
# {type: group-of, path, expect} whether the workload's groups include
3232
# path's group (true)
33+
# {type: path-has, dir, expect} whether dir is an entry of PATH (true)
3334
cdi_scenario_dir: "{{ cdi_fixture_root }}/scenarios"
3435

3536
# Edits applied by every case, to check that spec and device edits merge. The
@@ -164,6 +165,19 @@ cdi_scenarios:
164165
- {type: non-root}
165166
- {type: write, path: /dev/tmachine-cdi-null, expect: ok}
166167

168+
# The spec narrows PATH to directories without sbin. The standard sbin
169+
# directories are appended for workloads of CDI sandboxes, where tools such
170+
# as ldconfig and nvidia-smi can live.
171+
- name: sbin-path
172+
edits:
173+
env:
174+
- PATH=/usr/local/bin:/usr/bin:/bin
175+
expect:
176+
checks:
177+
- {type: path-has, dir: /usr/local/sbin, expect: true}
178+
- {type: path-has, dir: /usr/sbin, expect: true}
179+
- {type: path-has, dir: /sbin, expect: true}
180+
167181
# NVIDIA MPS clients open pipes under /tmp/nvidia-mps. The fixture uses a
168182
# regular file in place of a pipe so the checks cannot block on open.
169183
- name: mps-pipe-directory

‎tests/suites/features/cdi/tests/injection.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ enum Check {
6161
NonRoot { expect: bool },
6262
/// Whether the workload's groups include the group that owns `path`.
6363
HasGroupOf { path: String, expect: bool },
64+
/// Whether a directory is an entry of the workload's `PATH`.
65+
PathHas { dir: String, expect: bool },
6466
}
6567

6668
impl Check {
@@ -130,6 +132,10 @@ impl Check {
130132
path: text("path")?,
131133
expect: flag("expect")?,
132134
}),
135+
Some("path-has") => Ok(Self::PathHas {
136+
dir: text("dir")?,
137+
expect: flag("expect")?,
138+
}),
133139
other => Err(format!("unknown check type {other:?} in {value}")),
134140
}
135141
}
@@ -143,6 +149,7 @@ impl Check {
143149
Self::Write { path, .. } => format!("write:{path}"),
144150
Self::NonRoot { .. } => "non-root".to_string(),
145151
Self::HasGroupOf { path, .. } => format!("group-of:{path}"),
152+
Self::PathHas { dir, .. } => format!("path-has:{dir}"),
146153
}
147154
}
148155

@@ -167,6 +174,9 @@ impl Check {
167174
Self::HasGroupOf { path, .. } => format!(
168175
r#"set -- $(ls -ln '{path}' 2>/dev/null); case " $(id -G) " in *" $4 "*) printf ok ;; *) printf missing-group ;; esac"#
169176
),
177+
Self::PathHas { dir, .. } => format!(
178+
r#"case ":$PATH:" in *:'{dir}':*) printf ok ;; *) printf absent ;; esac"#
179+
),
170180
}
171181
}
172182

@@ -184,6 +194,7 @@ impl Check {
184194
Self::HasGroupOf { expect, .. } => {
185195
if *expect { "ok" } else { "missing-group" }.to_string()
186196
}
197+
Self::PathHas { expect, .. } => if *expect { "ok" } else { "absent" }.to_string(),
187198
}
188199
}
189200
}
@@ -410,6 +421,7 @@ cdi_scenarios! {
410421
scenario_omitted_access_file => "omitted-access-file",
411422
scenario_mps_pipe_directory => "mps-pipe-directory",
412423
scenario_mps_pipe_directory_without_noexec => "mps-pipe-directory-without-noexec",
424+
scenario_sbin_path => "sbin-path",
413425
scenario_device_node => "device-node",
414426
scenario_device_node_with_gid => "device-node-with-gid",
415427
scenario_unix_socket => "unix-socket",
@@ -467,6 +479,14 @@ mod probe {
467479
path: path.to_string(),
468480
expect: true,
469481
},
482+
Check::PathHas {
483+
dir: "/bin".to_string(),
484+
expect: true,
485+
},
486+
Check::PathHas {
487+
dir: "/no/such/directory".to_string(),
488+
expect: false,
489+
},
470490
];
471491
let stdout = run_probe(&checks);
472492
let observed = parse_observations(&stdout);

0 commit comments

Comments
 (0)