Adds Vulkan ICD JSON file automatically if available#12818
Adds Vulkan ICD JSON file automatically if available#12818luiscape wants to merge 1 commit intogoogle:masterfrom
Conversation
| for _, relPath := range allConfigs { | ||
| for _, searchPath := range searchPaths { | ||
| hostPath := path.Join(searchPath, relPath) | ||
| content, err := os.ReadFile(hostPath) |
There was a problem hiding this comment.
IIUC, what nvidia-container-toolkit seems to be doing is modifying the OCI spec and adding these mounts to the spec as read-only, so they will be bind-mounted into the container rootfs. We seem to be open-ing these files and writing them directly. Which I think is OK because:
- It is difficult to inject mounts into the spec once we are this far in runsc initialization. Usually only the shim modifies the spec this way.
- These files are likely small config files.
However, reading them from the host like this and pasting them into the container makes me a bit queasy. We should at least ensure that there are no symlinks. For example, a malicious container image can have a rootfs with /etc/vulkan/icd.d/nvidia_icd.json as a symlink to /etc/passwd or something, and the os.WriteFile() below will overwrite some host file (because symlinks will be resolved with host root, not container rootfs).
There was a problem hiding this comment.
Regarding mount vs writing the files, do you want me to attempt a bind-mount? This seemed to be the smallest footprint. Otherwise I can think a bit about hardening this approach.
There was a problem hiding this comment.
Bind mounting is also susceptible to symlink attacks. But when we bind mount into rootfs in the gofer, we take a lot of care of symlinks and ensure that nothing escapes the rootfs into the host. See
Lines 541 to 544 in dc29295
I think a similar symlink-awareness would be nice.
There was a problem hiding this comment.
I am now using resolveSymlinks to add these files. I moved the function to specutils.ResolveSymlinks to make it available everywhere, hence the many file edits. Let me know if this is alright.
23295f9 to
6a3e30a
Compare
6a3e30a to
0d0adf7
Compare
|
Added a few missing config files. This fully replicates the expected behavior from the nvidia container toolkit. |
Fixes: #12752
Attempts to reproduce the behavior of the nvidia container toolkit that injects the Vulkan IDC JSON file automatically. Also adds all other graphics files mimicking the toolkit implementation.
Assisted-by: Claude