Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Extracting image as non-root fails on directory permissions #21350

Merged
merged 1 commit into from Oct 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/oc/cli/image/extract/extract.go
Expand Up @@ -354,6 +354,8 @@ func (o *Options) Run() error {
}
if o.RemovePermissions {
alter = append(alter, removePermissions{})
} else if !preserveOwnership {
alter = append(alter, writableDirectories{})
}

var byEntry TarEntryFunc = o.TarEntryCallback
Expand Down Expand Up @@ -512,6 +514,16 @@ func (_ removePermissions) Alter(hdr *tar.Header) (bool, error) {
return true, nil
}

type writableDirectories struct{}

func (_ writableDirectories) Alter(hdr *tar.Header) (bool, error) {
switch hdr.Typeflag {
case tar.TypeDir:
hdr.Mode = int64(os.FileMode(0600) | os.FileMode(hdr.Mode))
}
return true, nil
}

type copyFromDirectory struct {
From string
}
Expand Down