Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Commit ea4e2ea

Browse files
committed
Set ownership to unpacked entries
Signed-off-by: George Lestaris <[email protected]>
1 parent 853746e commit ea4e2ea

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

image/manifest.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ loop:
184184
if err2 := os.MkdirAll(path, info.Mode()); err2 != nil {
185185
return errors.Wrap(err2, "error creating directory")
186186
}
187+
188+
if os.Getuid() == 0 {
189+
if err2 := os.Chown(path, hdr.Uid, hdr.Gid); err2 != nil {
190+
return errors.Wrap(err2, "error chowing directory")
191+
}
192+
}
187193
}
188194

189195
case tar.TypeReg, tar.TypeRegA:
@@ -192,6 +198,12 @@ loop:
192198
return errors.Wrap(err, "unable to open file")
193199
}
194200

201+
if os.Getuid() == 0 {
202+
if err := os.Chown(path, hdr.Uid, hdr.Gid); err != nil {
203+
return errors.Wrap(err, "error chowing file")
204+
}
205+
}
206+
195207
if _, err := io.Copy(f, tr); err != nil {
196208
f.Close()
197209
return errors.Wrap(err, "unable to copy")
@@ -219,6 +231,13 @@ loop:
219231
if err := os.Symlink(hdr.Linkname, path); err != nil {
220232
return err
221233
}
234+
235+
if os.Getuid() == 0 {
236+
if err := os.Lchown(path, hdr.Uid, hdr.Gid); err != nil {
237+
return errors.Wrap(err, "error chowing symlink")
238+
}
239+
}
240+
222241
case tar.TypeXGlobalHeader:
223242
return nil
224243
}

0 commit comments

Comments
 (0)