Skip to content

Commit 0277b9b

Browse files
Remove escalated privileges
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
1 parent d5c18df commit 0277b9b

6 files changed

Lines changed: 18 additions & 90 deletions

File tree

integration/client/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.19
44

55
require (
66
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 // replaced; see replace rules for actual version used.
7-
github.com/Microsoft/go-winio v0.6.1
7+
github.com/Microsoft/go-winio v0.6.1 // indirect
88
github.com/Microsoft/hcsshim v0.10.0-rc.8
99
github.com/Microsoft/hcsshim/test v0.0.0-20210408205431-da33ecd607e1
1010
github.com/containerd/cgroups/v3 v3.0.1

integration/client/snapshot_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
. "github.com/containerd/containerd"
2424
"github.com/containerd/containerd/snapshots"
25+
"github.com/containerd/containerd/snapshots/testsuite"
2526
)
2627

2728
func newSnapshotter(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) {
@@ -39,5 +40,9 @@ func newSnapshotter(ctx context.Context, root string) (snapshots.Snapshotter, fu
3940
}
4041

4142
func TestSnapshotterClient(t *testing.T) {
42-
runTestSnapshotterClient(t)
43+
if testing.Short() {
44+
t.Skip()
45+
}
46+
47+
testsuite.SnapshotterSuite(t, DefaultSnapshotter, newSnapshotter)
4348
}

integration/client/snapshot_unix_test.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

integration/client/snapshot_windows_test.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

mount/mount_windows.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var (
3939
)
4040

4141
// Mount to the provided target.
42-
func (m *Mount) mount(target string) error {
42+
func (m *Mount) mount(target string) (retErr error) {
4343
readOnly := false
4444
for _, option := range m.Options {
4545
if option == "ro" {
@@ -70,23 +70,23 @@ func (m *Mount) mount(target string) error {
7070
HomeDir: home,
7171
}
7272

73-
if err = hcsshim.ActivateLayer(di, layerID); err != nil {
73+
if err := hcsshim.ActivateLayer(di, layerID); err != nil {
7474
return fmt.Errorf("failed to activate layer %s: %w", m.Source, err)
7575
}
7676
defer func() {
77-
if err != nil {
77+
if retErr != nil {
7878
if layerErr := hcsshim.DeactivateLayer(di, layerID); layerErr != nil {
7979
log.G(context.TODO()).WithError(layerErr).Error("failed to deactivate layer during mount failure cleanup")
8080
}
8181
}
8282
}()
8383

84-
if err = hcsshim.PrepareLayer(di, layerID, parentLayerPaths); err != nil {
84+
if err := hcsshim.PrepareLayer(di, layerID, parentLayerPaths); err != nil {
8585
return fmt.Errorf("failed to prepare layer %s: %w", m.Source, err)
8686
}
8787

8888
defer func() {
89-
if err != nil {
89+
if retErr != nil {
9090
if layerErr := hcsshim.UnprepareLayer(di, layerID); layerErr != nil {
9191
log.G(context.TODO()).WithError(layerErr).Error("failed to unprepare layer during mount failure cleanup")
9292
}
@@ -98,11 +98,11 @@ func (m *Mount) mount(target string) error {
9898
return fmt.Errorf("failed to get volume path for layer %s: %w", m.Source, err)
9999
}
100100

101-
if err = bindfilter.ApplyFileBinding(target, volume, readOnly); err != nil {
101+
if err := bindfilter.ApplyFileBinding(target, volume, readOnly); err != nil {
102102
return fmt.Errorf("failed to set volume mount path for layer %s: %w", m.Source, err)
103103
}
104104
defer func() {
105-
if err != nil {
105+
if retErr != nil {
106106
if bindErr := bindfilter.RemoveFileBinding(target); bindErr != nil {
107107
log.G(context.TODO()).WithError(bindErr).Error("failed to remove binding during mount failure cleanup")
108108
}
@@ -112,7 +112,7 @@ func (m *Mount) mount(target string) error {
112112
// Add an Alternate Data Stream to record the layer source.
113113
// See https://docs.microsoft.com/en-au/archive/blogs/askcore/alternate-data-streams-in-ntfs
114114
// for details on Alternate Data Streams.
115-
if err = os.WriteFile(filepath.Clean(target)+":"+sourceStreamName, []byte(m.Source), 0666); err != nil {
115+
if err := os.WriteFile(filepath.Clean(target)+":"+sourceStreamName, []byte(m.Source), 0666); err != nil {
116116
return fmt.Errorf("failed to record source for layer %s: %w", m.Source, err)
117117
}
118118

snapshots/testsuite/testsuite.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,13 +820,13 @@ func checkSnapshotterViewReadonly(ctx context.Context, t *testing.T, snapshotter
820820
}
821821

822822
testfile := filepath.Join(viewMountPoint, "testfile")
823-
if err := os.WriteFile(testfile, []byte("testcontent"), 0777); err != nil {
823+
err = os.WriteFile(testfile, []byte("testcontent"), 0777)
824+
testutil.Unmount(t, viewMountPoint)
825+
if err != nil {
824826
t.Logf("write to %q failed with %v (EROFS is expected but can be other error code)", testfile, err)
825827
} else {
826-
testutil.Unmount(t, viewMountPoint)
827828
t.Fatalf("write to %q should fail (EROFS) but did not fail", testfile)
828829
}
829-
testutil.Unmount(t, viewMountPoint)
830830
assert.Nil(t, snapshotter.Remove(ctx, view))
831831
assert.Nil(t, snapshotter.Remove(ctx, committed))
832832
}

0 commit comments

Comments
 (0)