Skip to content

Commit 1db78ea

Browse files
Liubov Dmitrievameta-codesync[bot]
authored andcommitted
[antlir2] Complete fix for file permissions in OCI layer generation
Summary: D88790669 fixed file permissions for metadata-only changes (Contents::Unset branch) but missed files with content changes (Contents::File branch). When D88743755 switched from append_file() to append_data(), both code paths lost automatic permission preservation. This diff applies the same permission preservation logic to the Contents::File branch, completing the fix. The issue was visible in fbcode-buck images where files like /etc/passwd had incorrect permissions (----------). These files went through the Contents::File path since they had content modifications, not just metadata changes. In next diff we will cover the scenario with tests. Test Plan: buck2 test fbcode//mode/dev //antlir/antlir2/antlir2_packager/make_oci_layer:test-file-permissions the previous fix only fixed: ``` liuba ⛅️ ~/fbsource/fbcode [🥭] → buck run 'mode/opt' //atlas/specs/generated/fbsource-scm-tools:devcompute.image.fbsource-scm-tools-podman-run ``` however it didn't for: ``` liuba ⛅️ ~/fbsource/fbcode [🍋] → buck run 'mode/opt' //atlas/specs/generated/fbcode-buck:devcompute.image.fbcode-buck-podman-run ``` Reviewed By: c-ryan747 Differential Revision: D88848270 fbshipit-source-id: 00eb26ba5f6f256eab4fc75a4b7e8435c1bbb3ac
1 parent cfa6ce7 commit 1db78ea

File tree

1 file changed

+9
-1
lines changed
  • antlir/antlir2/antlir2_packager/make_oci_layer/src

1 file changed

+9
-1
lines changed

antlir/antlir2/antlir2_packager/make_oci_layer/src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,18 @@ fn main() -> Result<()> {
276276
// to avoid GNU sparse headers (type 'S' = 83) which some container
277277
// runtimes (podman/skopeo) cannot handle.
278278
// Use the accumulated entry.header which contains metadata from
279-
// change stream operations (Create, Chmod, Chown, etc.)
279+
// change stream operations (Create, Chmod, Chown, etc.), but also
280+
// preserve permissions from filesystem if not already set.
280281
// Seek to beginning in case file handle is not at start
281282
f.rewind()?;
282283
let metadata = f.metadata()?;
284+
// Preserve permissions from filesystem. On Unix, mode() includes
285+
// file type bits, so mask with 0o7777 to get just permission bits.
286+
#[cfg(unix)]
287+
{
288+
use std::os::unix::fs::PermissionsExt;
289+
entry.header.set_mode(metadata.permissions().mode() & 0o7777);
290+
}
283291
entry.header.set_size(metadata.len());
284292
entry.header.set_entry_type(EntryType::Regular);
285293
builder.append_data(&mut entry.header, path, &mut f)?;

0 commit comments

Comments
 (0)