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
Add --chown flag support for ADD/COPY commands for Windows #35521
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,87 @@ | ||
package dockerfile // import "github.com/docker/docker/builder/dockerfile" | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/Microsoft/go-winio" | ||
"github.com/docker/docker/pkg/idtools" | ||
"github.com/docker/docker/pkg/reexec" | ||
"github.com/docker/docker/pkg/system" | ||
"github.com/pkg/errors" | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
var pathBlacklist = map[string]bool{ | ||
"c:\\": true, | ||
"c:\\windows": true, | ||
} | ||
|
||
func fixPermissions(source, destination string, rootIDs idtools.IDPair, overrideSkip bool) error { | ||
// chown is not supported on Windows | ||
return nil | ||
func init() { | ||
reexec.Register("windows-fix-permissions", fixPermissionsReexec) | ||
} | ||
|
||
func fixPermissions(source, destination string, identity idtools.Identity, _ bool) error { | ||
if identity.SID == "" { | ||
return nil | ||
} | ||
|
||
cmd := reexec.Command("windows-fix-permissions", source, destination, identity.SID) | ||
output, err := cmd.CombinedOutput() | ||
|
||
return errors.Wrapf(err, "failed to exec windows-fix-permissions: %s", output) | ||
} | ||
|
||
func fixPermissionsReexec() { | ||
err := fixPermissionsWindows(os.Args[1], os.Args[2], os.Args[3]) | ||
if err != nil { | ||
fmt.Fprint(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func fixPermissionsWindows(source, destination, SID string) error { | ||
|
||
privileges := []string{winio.SeRestorePrivilege, system.SeTakeOwnershipPrivilege} | ||
|
||
err := winio.EnableProcessPrivileges(privileges) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer winio.DisableProcessPrivileges(privileges) | ||
|
||
sid, err := windows.StringToSid(SID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Owners on *nix have read/write/delete/read control and write DAC. | ||
// Add an ACE that grants this to the user/group specified with the | ||
// chown option. Currently Windows is not honoring the owner change, | ||
// however, they are aware of this and it should be fixed at some | ||
// point. | ||
|
||
sddlString := system.SddlAdministratorsLocalSystem | ||
sddlString += "(A;OICI;GRGWGXRCWDSD;;;" + SID + ")" | ||
|
||
securityDescriptor, err := winio.SddlToSecurityDescriptor(sddlString) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var daclPresent uint32 | ||
var daclDefaulted uint32 | ||
var dacl *byte | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style nit; no need to change; generally we group these, i.e.; var (
daclPresent uint32
daclDefaulted uint32
dacl *byte
) |
||
|
||
err = system.GetSecurityDescriptorDacl(&securityDescriptor[0], &daclPresent, &dacl, &daclDefaulted) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here (not a blocker) if err := system.GetSecurityDescriptorDacl(&securityDescriptor[0], &daclPresent, &dacl, &daclDefaulted); err != nil {
return err
} |
||
if err != nil { | ||
return err | ||
} | ||
|
||
return system.SetNamedSecurityInfo(windows.StringToUTF16Ptr(destination), system.SE_FILE_OBJECT, system.OWNER_SECURITY_INFORMATION|system.DACL_SECURITY_INFORMATION, sid, nil, dacl, nil) | ||
} | ||
|
||
func validateCopySourcePath(imageSource *imageMount, origPath, platform string) error { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a more idiomatic way to write these is to scope the err to the
if
;