Skip to content

Commit

Permalink
wip: tar and local exporter running with privileges
Browse files Browse the repository at this point in the history
TODO: need to cross-check that there is no way the
SeBackupPrivilege can be abused/exploited.

WIP: how best to handle the files to be exclused
without touching `fsutil`.

Signed-off-by: Anthony Nandaa <profnandaa@gmail.com>
  • Loading branch information
profnandaa committed Jun 10, 2024
1 parent 3d789eb commit 2a25c5b
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 5 deletions.
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))
}
9 changes: 9 additions & 0 deletions vendor/github.com/tonistiigi/fsutil/metadata_unix.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions vendor/github.com/tonistiigi/fsutil/metadata_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions vendor/github.com/tonistiigi/fsutil/send.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vendor/github.com/tonistiigi/fsutil/tarwriter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2a25c5b

Please sign in to comment.