Repository navigation
docs: add guidance on safely extracting layers - #244
ericcurtin wants to merge 1 commit into
Conversation
The spec describes how to pack layers but not how a consumer must unpack an untrusted layer. Add guidance covering path traversal, links, special files, permissions, compression, raw layers and atomicity. Signed-off-by: Eric Curtin <eric.curtin@docker.com>
|
Could a maintainer add the |
|
@chlins @aftersnow PTAL when you get a chance, and could one of you add the |
aftersnow
left a comment
There was a problem hiding this comment.
I support adding extraction guidance, especially the requirement to keep writes within the model root. I’m requesting three changes before merge so consumers can enforce that boundary while respecting deployment permissions and handling existing artifacts consistently.
| **File permissions:** | ||
|
|
||
| - Consumers SHOULD NOT apply setuid, setgid or sticky bits, and SHOULD NOT apply the `uid` and `gid` of the archive. | ||
| - Extracting regular files with mode `0755` if the archive sets any executable bit and `0644` otherwise is RECOMMENDED. Setting the mode explicitly, rather than relying on the process `umask`, keeps the result readable by other users. |
There was a problem hiding this comment.
Applying 0644 explicitly to a weights file archived as 0600 would make it readable by other users who can traverse the output directory, even when the operator set umask 077. Please drop the fixed 0644/0755 recommendation and require consumers to honor the deployment’s permission policy, including a restrictive umask. A shared model cache can opt into broader access explicitly.
|
|
||
| **Raw layers:** | ||
|
|
||
| - For `.raw` layers there is no archive: the blob is the file itself. Its destination, relative to the model root, is given by the `org.cncf.model.filepath` annotation (see [Layer Annotation Keys](./annotations.md#layer-annotation-keys)). |
There was a problem hiding this comment.
Layer annotations are optional in the current manifest spec. What should a consumer do with a .raw layer that omits org.cncf.model.filepath? The llmman implementation cited in the PR also checks org.opencontainers.image.title when the ModelPack key is absent. For this change, please make the wording conditional and require consumers to validate any annotation-derived destination before writing. If a single naming or fallback rule is needed across consumers, please propose it separately and describe how it handles existing artifacts. Current manifest spec · llmman path lookup
| **Entry names:** | ||
|
|
||
| - Tar entry names are relative to the model root directory into which the layer is extracted. A leading `./` and a trailing `/` are ignored, and an entry that then names the model root itself is ignored. | ||
| - A consumer MUST reject the layer, rather than silently skip the entry, if an entry name is absolute, or contains a `..` component, an empty component (such as `a//b`), a `.` component (other than the leading `./`), a backslash, or a colon (such as a drive letter prefix). In short, anything that could be written outside the model root MUST fail the layer. |
There was a problem hiding this comment.
checkpoints/epoch:10.bin is a valid relative filename on Linux. This MUST would require a Linux consumer to reject the entire layer even when it can safely extract that file under the model root. Please keep root containment mandatory and allow consumers to reject names they cannot safely represent on the target filesystem. If ModelPack needs a portable filename grammar, please define the corresponding packager rules and explain how consumers should handle archives produced under the current spec.
Description
Adds an "Extracting Layers" subsection to
docs/spec.mdwith consumer guidance for unpacking ModelPack layers.Related Issue
None open for this. Happy to open one, or to adjust the wording or the MUST vs SHOULD levels per the maintainers' preference. This is docs only, with no schema or Go change.
Motivation and Context
The spec only says how to pack layers. Every consumer (runtimes, CSI drivers, loaders) has to unpack untrusted tar archives, and each one has to work out path traversal, link, special file, permission, compression and atomicity rules on its own.
The guidance is taken from the behaviour of the hardened layer unpacker in llmman (https://github.com/llmmanorg/llmman,
src/modelpack/layers.rs), which is used by its Kubernetes CSI driver and resolver.Testing
make validate-examplesandgo test ./...pass. markdownlint and typos were not run locally.