Skip to content

Commit 33350a8

Browse files
committed
test(cdi): update CDI scenario expectations for derived policy
Record the behavior of the named scenarios once filesystem access is derived from the selected CDI specs: read-only mounts and library parents are readable, device nodes are writable, and writable mounts, an unsafe library parent, and an NVIDIA MPS directory without noexec are rejected. Add scenarios for the MPS pipe directory with and without noexec. Signed-off-by: Evan Lezar <[email protected]>
1 parent db12abe commit 33350a8

3 files changed

Lines changed: 53 additions & 32 deletions

File tree

‎TESTING.md‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -359,19 +359,21 @@ playbook restores the configuration and restarts the gateway even after test
359359
failure; the CDI fixtures remain part of the environment. Docker must support
360360
CDI. Branch and release feature-test matrices run this suite on Docker.
361361

362-
| Scenario | Injected resource | Asserted today | Expected with PR #4204 |
363-
| --- | --- | --- | --- |
364-
| `mount-under-read-only-baseline` | File at `/usr/share/tmachine-cdi/baseline-read-only-file`, under a directory the sandbox already makes read-only | Read succeeds, write denied. | Unchanged. |
365-
| `read-only-file` | File at `/tmachine-cdi/read-only/file` | Read and write denied. | Read succeeds outside the baseline grants; write fails. |
366-
| `read-only-directory` | Directory at `/tmachine-cdi/read-only/directory` | Reading its marker and creating files denied. | Reading its marker succeeds; write fails. |
367-
| `library-parent` | Marker named `/tmachine-cdi/library/libfixture.so.1` | Read and write denied. | Resolver derives the library parent; the marker is not an actual shared library. |
368-
| `broad-library-parent` | Marker named `/libtmachinefixture.so.1` | Read and write denied. | Launch rejects expansion to `/`. |
369-
| `writable-file` | Writable file at `/tmachine-cdi/writable/file` | Read and write denied. | Launch rejects it even with exact or ancestor write grants. |
370-
| `writable-directory` | Writable directory at `/tmachine-cdi/writable/directory` | Write denied. | Launch rejects it even with exact or ancestor write grants. |
371-
| `omitted-access-file` | Bind without `ro` or `rw` | Read and write denied. | Effective writable access causes launch rejection. |
372-
| `device-node` | Null character device at `/dev/tmachine-cdi-null` | Non-root, write denied. | Non-root read/write succeeds; an exact authored read-only entry fails launch. |
373-
| `device-node-with-gid` | Group-restricted null device at `/dev/tmachine-cdi-group-null` | Non-root with the device's group, write denied. | The generated supplementary GID permits non-root access. |
374-
| `unix-socket` | Echo socket at `/tmachine-cdi/socket/echo.sock` | Sibling file in the host directory is not visible. | Socket communication succeeds without deriving parent filesystem grants. |
362+
| Scenario | Injected resource | Asserted |
363+
| --- | --- | --- |
364+
| `mount-under-read-only-baseline` | File at `/usr/share/tmachine-cdi/baseline-read-only-file`, under a directory the sandbox already makes read-only | Read succeeds, write denied. |
365+
| `read-only-file` | File at `/tmachine-cdi/read-only/file` | Read succeeds from the derived grant; write denied. |
366+
| `read-only-directory` | Directory at `/tmachine-cdi/read-only/directory` | Reading its marker succeeds; creating files denied. |
367+
| `library-parent` | Marker named `/tmachine-cdi/library/libfixture.so.1` | The derived library-parent grant makes it readable; write denied. The marker is not an actual shared library. |
368+
| `broad-library-parent` | Marker named `/libtmachinefixture.so.1` | Launch rejects expansion to `/`. |
369+
| `writable-file` | Writable file at `/tmachine-cdi/writable/file` | Launch rejects the writable mount. |
370+
| `writable-directory` | Writable directory at `/tmachine-cdi/writable/directory` | Launch rejects the writable mount. |
371+
| `omitted-access-file` | Bind without `ro` or `rw` | Launch rejects the effectively writable mount. |
372+
| `mps-pipe-directory` | Directory at `/tmp/nvidia-mps` mounted `nosuid`, `nodev`, `noexec` | Read and write succeed on its contents. |
373+
| `mps-pipe-directory-without-noexec` | The same directory without `noexec` | Launch rejects the mount. |
374+
| `device-node` | Null character device at `/dev/tmachine-cdi-null` | Non-root; write succeeds. |
375+
| `device-node-with-gid` | Group-restricted null device at `/dev/tmachine-cdi-group-null` | Non-root with the device's group; write succeeds. |
376+
| `unix-socket` | Echo socket at `/tmachine-cdi/socket/echo.sock` | Sibling file in the host directory is not visible. |
375377

376378
Every scenario also supplies a spec-level environment marker and a read-only
377379
mount at `/usr/share/tmachine-cdi/common/spec-marker`, allowing checks of
@@ -383,9 +385,8 @@ with positive cases.
383385

384386
The role publishes each scenario's expectations as `scenarios.json` next to the
385387
fixtures. The `scenario_*` tests load them and assert the behavior recorded in
386-
`vars/scenarios.yaml`, which is the sandbox's behavior today. A change that
387-
alters a scenario's behavior, such as #4204 deriving grants from the spec,
388-
updates those values in the same diff. To record the current behavior, run the
388+
`vars/scenarios.yaml`. A change that alters a scenario's behavior updates those
389+
values in the same diff. To record the sandbox's current behavior, run the
389390
tests with `OPENSHELL_CDI_CAPTURE=1` set for the test process; they then print
390391
what each scenario observed instead of asserting.
391392

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

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ cdi_scenarios:
7979
options: [bind, ro]
8080
expect:
8181
checks:
82-
- {type: read, path: /tmachine-cdi/read-only/file, expect: denied}
82+
- {type: contents, path: /tmachine-cdi/read-only/file, expect: tmachine-cdi-read-only-file}
8383
- {type: write, path: /tmachine-cdi/read-only/file, expect: denied}
8484

8585
- name: read-only-directory
@@ -93,7 +93,7 @@ cdi_scenarios:
9393
options: [bind, ro]
9494
expect:
9595
checks:
96-
- {type: read, path: /tmachine-cdi/read-only/directory/marker, expect: denied}
96+
- {type: contents, path: /tmachine-cdi/read-only/directory/marker, expect: tmachine-cdi-read-only-directory/marker}
9797
- {type: write, path: /tmachine-cdi/read-only/directory/marker, expect: denied}
9898
- {type: write, path: /tmachine-cdi/read-only/directory/new-file, expect: denied}
9999

@@ -110,7 +110,7 @@ cdi_scenarios:
110110
options: [bind, ro]
111111
expect:
112112
checks:
113-
- {type: read, path: /tmachine-cdi/library/libfixture.so.1, expect: denied}
113+
- {type: contents, path: /tmachine-cdi/library/libfixture.so.1, expect: tmachine-cdi-libfixture.so.1}
114114
- {type: write, path: /tmachine-cdi/library/libfixture.so.1, expect: denied}
115115

116116
- name: broad-library-parent
@@ -120,9 +120,7 @@ cdi_scenarios:
120120
containerPath: /libtmachinefixture.so.1
121121
options: [bind, ro]
122122
expect:
123-
checks:
124-
- {type: read, path: /libtmachinefixture.so.1, expect: denied}
125-
- {type: write, path: /libtmachinefixture.so.1, expect: denied}
123+
rejected: unsafe
126124

127125
- name: writable-file
128126
fixtures:
@@ -133,9 +131,7 @@ cdi_scenarios:
133131
containerPath: /tmachine-cdi/writable/file
134132
options: [bind, rw]
135133
expect:
136-
checks:
137-
- {type: read, path: /tmachine-cdi/writable/file, expect: denied}
138-
- {type: write, path: /tmachine-cdi/writable/file, expect: denied}
134+
rejected: CDI writable mount
139135

140136
- name: writable-directory
141137
fixtures:
@@ -146,8 +142,7 @@ cdi_scenarios:
146142
containerPath: /tmachine-cdi/writable/directory
147143
options: [bind, rw]
148144
expect:
149-
checks:
150-
- {type: write, path: /tmachine-cdi/writable/directory/probe, expect: denied}
145+
rejected: CDI writable mount
151146

152147
- name: omitted-access-file
153148
edits:
@@ -156,9 +151,7 @@ cdi_scenarios:
156151
containerPath: /tmachine-cdi/writable/omitted-access
157152
options: [bind]
158153
expect:
159-
checks:
160-
- {type: read, path: /tmachine-cdi/writable/omitted-access, expect: denied}
161-
- {type: write, path: /tmachine-cdi/writable/omitted-access, expect: denied}
154+
rejected: CDI writable mount
162155

163156
- name: device-node
164157
edits:
@@ -169,7 +162,32 @@ cdi_scenarios:
169162
expect:
170163
checks:
171164
- {type: non-root}
172-
- {type: write, path: /dev/tmachine-cdi-null, expect: denied}
165+
- {type: write, path: /dev/tmachine-cdi-null, expect: ok}
166+
167+
# NVIDIA MPS clients open pipes under /tmp/nvidia-mps. The fixture uses a
168+
# regular file in place of a pipe so the checks cannot block on open.
169+
- name: mps-pipe-directory
170+
fixtures:
171+
- {path: mps-pipes, type: dir, mode: "0777"}
172+
- {path: mps-pipes/control, type: file, content: "tmachine-cdi-mps-control\n", mode: "0666"}
173+
edits:
174+
mounts:
175+
- hostPath: "{{ cdi_scenario_dir }}/mps-pipes"
176+
containerPath: /tmp/nvidia-mps
177+
options: [nosuid, nodev, rbind, rprivate, noexec]
178+
expect:
179+
checks:
180+
- {type: contents, path: /tmp/nvidia-mps/control, expect: tmachine-cdi-mps-control}
181+
- {type: write, path: /tmp/nvidia-mps/control, expect: ok}
182+
183+
- name: mps-pipe-directory-without-noexec
184+
edits:
185+
mounts:
186+
- hostPath: "{{ cdi_scenario_dir }}/mps-pipes"
187+
containerPath: /tmp/nvidia-mps
188+
options: [nosuid, nodev, rbind, rprivate]
189+
expect:
190+
rejected: CDI IPC directory
173191

174192
# The device is mode 0660 with a group that only `additionalGids` grants.
175193
- name: device-node-with-gid
@@ -188,7 +206,7 @@ cdi_scenarios:
188206
checks:
189207
- {type: non-root}
190208
- {type: group-of, path: /dev/tmachine-cdi-group-null}
191-
- {type: write, path: /dev/tmachine-cdi-group-null, expect: denied}
209+
- {type: write, path: /dev/tmachine-cdi-group-null, expect: ok}
192210

193211
# The echo socket is served by the systemd units installed in scenarios.yaml.
194212
# Its sibling file checks that only the socket path is exposed.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ cdi_scenarios! {
408408
scenario_writable_file => "writable-file",
409409
scenario_writable_directory => "writable-directory",
410410
scenario_omitted_access_file => "omitted-access-file",
411+
scenario_mps_pipe_directory => "mps-pipe-directory",
412+
scenario_mps_pipe_directory_without_noexec => "mps-pipe-directory-without-noexec",
411413
scenario_device_node => "device-node",
412414
scenario_device_node_with_gid => "device-node-with-gid",
413415
scenario_unix_socket => "unix-socket",

0 commit comments

Comments
 (0)