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

fix: acquire privileges to access special files on windows #4994

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exporter/tar/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (e *localExporterInstance) Export(ctx context.Context, inp *exporter.Source
return nil, nil, err
}
report := progress.OneOff(ctx, "sending tarball")
if err := fsutil.WriteTar(ctx, fs, w); err != nil {
if err := writeTar(ctx, fs, w); err != nil {
w.Close()
return nil, nil, report(err)
}
Expand Down
15 changes: 15 additions & 0 deletions exporter/tar/export_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build !windows
// +build !windows

package local

import (
"context"
"io"

"github.com/tonistiigi/fsutil"
)

func writeTar(ctx context.Context, fs fsutil.FS, w io.WriteCloser) error {
return fsutil.WriteTar(ctx, fs, w)
}
18 changes: 18 additions & 0 deletions exporter/tar/export_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package local

import (
"context"
"io"

"github.com/Microsoft/go-winio"
"github.com/tonistiigi/fsutil"
)

func writeTar(ctx context.Context, fs fsutil.FS, w io.WriteCloser) error {
// Windows rootfs has a few special metadata files that
// require extra privileges to be accessed.
privileges := []string{winio.SeBackupPrivilege}
return winio.RunWithPrivileges(privileges, func() error {
return fsutil.WriteTar(ctx, fs, w)
})
}
4 changes: 0 additions & 4 deletions session/filesync/diffcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ type Stream interface {
RecvMsg(m interface{}) error
}

func sendDiffCopy(stream Stream, fs fsutil.FS, progress progressCb) error {
return errors.WithStack(fsutil.Send(stream.Context(), stream, fs, progress))
}

func newStreamWriter(stream grpc.ClientStream) io.WriteCloser {
wc := &streamWriterCloser{ClientStream: stream}
return &bufferedWriteCloser{Writer: bufio.NewWriter(wc), Closer: wc}
Expand Down
13 changes: 13 additions & 0 deletions session/filesync/diffcopy_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !windows
// +build !windows

package filesync

import (
"github.com/pkg/errors"
"github.com/tonistiigi/fsutil"
)

func sendDiffCopy(stream Stream, fs fsutil.FS, progress progressCb) error {
return errors.WithStack(fsutil.Send(stream.Context(), stream, fs, progress))
}
21 changes: 21 additions & 0 deletions session/filesync/diffcopy_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build windows
// +build windows

package filesync

import (
"github.com/Microsoft/go-winio"
"github.com/pkg/errors"
"github.com/tonistiigi/fsutil"
)

func sendDiffCopy(stream Stream, fs fsutil.FS, progress progressCb) error {
// adding one SeBackupPrivilege to the process so as to be able
// to run the subsequent goroutines in fsutil.Send that need
// to copy over special Windows metadata files.
// TODO(profnandaa): need to cross-check that this cannot be
// exploited in any way.
winio.EnableProcessPrivileges([]string{winio.SeBackupPrivilege})
defer winio.DisableProcessPrivileges([]string{winio.SeBackupPrivilege})
return errors.WithStack(fsutil.Send(stream.Context(), stream, fs, progress))
}
Loading