Skip to content

Commit e7ceb63

Browse files
committed
wip: tar and local exporter running with privileges
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 <[email protected]>
1 parent 3d789eb commit e7ceb63

File tree

6 files changed

+68
-5
lines changed

6 files changed

+68
-5
lines changed

exporter/tar/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (e *localExporterInstance) Export(ctx context.Context, inp *exporter.Source
166166
return nil, nil, err
167167
}
168168
report := progress.OneOff(ctx, "sending tarball")
169-
if err := fsutil.WriteTar(ctx, fs, w); err != nil {
169+
if err := writeTar(ctx, fs, w); err != nil {
170170
w.Close()
171171
return nil, nil, report(err)
172172
}

exporter/tar/export_unix.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package local
5+
6+
import (
7+
"context"
8+
"io"
9+
10+
"github.com/tonistiigi/fsutil"
11+
)
12+
13+
func writeTar(ctx context.Context, fs fsutil.FS, w io.WriteCloser) error {
14+
return fsutil.WriteTar(ctx, fs, w)
15+
}

exporter/tar/export_windows.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package local
2+
3+
import (
4+
"context"
5+
"io"
6+
7+
"github.com/Microsoft/go-winio"
8+
"github.com/tonistiigi/fsutil"
9+
)
10+
11+
func writeTar(ctx context.Context, fs fsutil.FS, w io.WriteCloser) error {
12+
// Windows rootfs has a few special metadata files that
13+
// require extra privileges to be accessed.
14+
privileges := []string{winio.SeBackupPrivilege}
15+
return winio.RunWithPrivileges(privileges, func() error {
16+
return fsutil.WriteTar(ctx, fs, w)
17+
})
18+
}

session/filesync/diffcopy.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ type Stream interface {
2121
RecvMsg(m interface{}) error
2222
}
2323

24-
func sendDiffCopy(stream Stream, fs fsutil.FS, progress progressCb) error {
25-
return errors.WithStack(fsutil.Send(stream.Context(), stream, fs, progress))
26-
}
27-
2824
func newStreamWriter(stream grpc.ClientStream) io.WriteCloser {
2925
wc := &streamWriterCloser{ClientStream: stream}
3026
return &bufferedWriteCloser{Writer: bufio.NewWriter(wc), Closer: wc}

session/filesync/diffcopy_unix.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package filesync
5+
6+
import (
7+
"github.com/pkg/errors"
8+
"github.com/tonistiigi/fsutil"
9+
)
10+
11+
func sendDiffCopy(stream Stream, fs fsutil.FS, progress progressCb) error {
12+
return errors.WithStack(fsutil.Send(stream.Context(), stream, fs, progress))
13+
}

session/filesync/diffcopy_windows.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build windows
2+
// +build windows
3+
4+
package filesync
5+
6+
import (
7+
"github.com/Microsoft/go-winio"
8+
"github.com/pkg/errors"
9+
"github.com/tonistiigi/fsutil"
10+
)
11+
12+
func sendDiffCopy(stream Stream, fs fsutil.FS, progress progressCb) error {
13+
// adding one SeBackupPrivilege to the process so as to be able
14+
// to run the subsequent goroutines in fsutil.Send that need
15+
// to copy over special Windows metadata files.
16+
// TODO(profnandaa): need to cross-check that this cannot be
17+
// exploited in any way.
18+
winio.EnableProcessPrivileges([]string{winio.SeBackupPrivilege})
19+
defer winio.DisableProcessPrivileges([]string{winio.SeBackupPrivilege})
20+
return errors.WithStack(fsutil.Send(stream.Context(), stream, fs, progress))
21+
}

0 commit comments

Comments
 (0)