Merge pull request #2485 from AkihiroSuda/fix-native-root-permission

native: set '/' permission to 0755
This commit is contained in:
Phil Estes 2018-07-23 09:52:53 -04:00 committed by GitHub
commit 92d147ebde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -251,6 +251,9 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to create temp dir") return nil, errors.Wrap(err, "failed to create temp dir")
} }
if err := os.Chmod(td, 0755); err != nil {
return nil, errors.Wrapf(err, "failed to chmod %s to 0755", td)
}
defer func() { defer func() {
if err != nil { if err != nil {
if td != "" { if td != "" {

View File

@ -62,6 +62,7 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context.
t.Run("StatInWalk", makeTest(name, snapshotterFn, checkStatInWalk)) t.Run("StatInWalk", makeTest(name, snapshotterFn, checkStatInWalk))
t.Run("CloseTwice", makeTest(name, snapshotterFn, closeTwice)) t.Run("CloseTwice", makeTest(name, snapshotterFn, closeTwice))
t.Run("RootPermission", makeTest(name, snapshotterFn, checkRootPermission))
} }
func makeTest(name string, snapshotterFn func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error), fn func(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string)) func(t *testing.T) { func makeTest(name string, snapshotterFn func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error), fn func(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string)) func(t *testing.T) {
@ -844,3 +845,18 @@ func closeTwice(ctx context.Context, t *testing.T, snapshotter snapshots.Snapsho
t.Fatalf("The second close failed: %+v", err) t.Fatalf("The second close failed: %+v", err)
} }
} }
func checkRootPermission(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
preparing, err := snapshotterPrepareMount(ctx, snapshotter, "preparing", "", work)
if err != nil {
t.Fatal(err)
}
defer testutil.Unmount(t, preparing)
st, err := os.Stat(preparing)
if err != nil {
t.Fatal(err)
}
if mode := st.Mode() & 0777; mode != 0755 {
t.Fatalf("expected 0755, got 0%o", mode)
}
}