Skip to content

Write OCI spec atomically in fileSpec.Flush - #2217

Open
ardatas wants to merge 2 commits into
NVIDIA:mainfrom
ardatas:vibe/atomic-spec-flush-77f70e
Open

ardatas wants to merge 2 commits into
NVIDIA:mainfrom
ardatas:vibe/atomic-spec-flush-77f70e

Conversation

@ardatas

@ardatas ardatas commented Nov 13, 2026 •

Copy link
Copy Markdown

Flush() previously truncated the spec file with os.Create before writing, so a failed write (disk full, I/O error) permanently destroyed the container's config.json and left the container unable to start.

Write the spec to a temporary file in the same directory, sync it, preserve the original file mode, and atomically rename it into place. A failed write now leaves the existing file intact.

Adds regression tests covering the success path (contents, mode, no leftover temp files), the failure path (existing file preserved), and flushing without a loaded spec.

Fixes #2203

Issue

Fixes #

Description

Checklist

  • No secrets, sensitive information, or unrelated changes
  • Unit tests passing (make test)
  • Lint checks passing (make lint)
  • Test cases are added for new code paths
  • Commits are signed-off and cryptographically signed

Testing

Flush() previously truncated the spec file with os.Create before
writing, so a failed write (disk full, I/O error) permanently
destroyed the container's config.json and left the container unable
to start.

Write the spec to a temporary file in the same directory, sync it,
preserve the original file mode, and atomically rename it into
place. A failed write now leaves the existing file intact.

Adds regression tests covering the success path (contents, mode,
no leftover temp files), the failure path (existing file preserved),
and flushing without a loaded spec.

Fixes NVIDIA#2203

Signed-off-by: Vibe Nuage Agent <vibe@mistral.ai>

Co-authored-by: ardatas <ardatas@users.noreply.github.com>
@copy-pr-bot

copy-pr-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

The spec file tests deliberately create files with mode 0644 to verify
that Flush preserves the original permissions; gosec G306 flags these
writes, so annotate them like the existing ldconfig tests do.

Signed-off-by: Vibe Nuage Agent <vibe@mistral.ai>

Co-authored-by: ardatas <ardatas@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Critical] Potential data loss in OCI spec Flush() - file truncated before write

2 participants