Skip to content

docs: add guidance on safely extracting layers - #244

Open
ericcurtin wants to merge 1 commit into
modelpack:mainfrom
ericcurtin:docs/safe-layer-extraction
Open

ericcurtin wants to merge 1 commit into
modelpack:mainfrom
ericcurtin:docs/safe-layer-extraction

Conversation

@ericcurtin

Copy link
Copy Markdown
Contributor

Description

Adds an "Extracting Layers" subsection to docs/spec.md with 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-examples and go test ./... pass. markdownlint and typos were not run locally.

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>
@ericcurtin

Copy link
Copy Markdown
Contributor Author

Could a maintainer add the documentation label so Classify PR passes? Thanks.

@ericcurtin

Copy link
Copy Markdown
Contributor Author

@chlins @aftersnow PTAL when you get a chance, and could one of you add the documentation label so Classify PR passes? Thank you!

@aftersnow aftersnow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/spec.md
**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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/spec.md

**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)).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread docs/spec.md
**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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@aftersnow aftersnow added the documentation Improvements or additions to documentation label Dec 5, 2026 — with ChatGPT Codex Connector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants