Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

[18.06 backport] pkg/archive: fix TestTarUntarWithXattr failure on recent kernel #152

Closed
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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ RUN apt-get update && apt-get install -y \
btrfs-tools \
iptables \
jq \
libcap2-bin \
libdevmapper-dev \
libudev-dev \
libsystemd-dev \
Expand Down
20 changes: 14 additions & 6 deletions pkg/archive/archive_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"
Expand Down Expand Up @@ -226,6 +227,13 @@ func TestTarWithBlockCharFifo(t *testing.T) {
// TestTarUntarWithXattr is Unix as Lsetxattr is not supported on Windows
func TestTarUntarWithXattr(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
if _, err := exec.LookPath("setcap"); err != nil {
t.Skip("setcap not installed")
}
if _, err := exec.LookPath("getcap"); err != nil {
t.Skip("getcap not installed")
}

origin, err := ioutil.TempDir("", "docker-test-untar-origin")
assert.NilError(t, err)
defer os.RemoveAll(origin)
Expand All @@ -236,8 +244,9 @@ func TestTarUntarWithXattr(t *testing.T) {
assert.NilError(t, err)
err = ioutil.WriteFile(filepath.Join(origin, "3"), []byte("will be ignored"), 0700)
assert.NilError(t, err)
err = system.Lsetxattr(filepath.Join(origin, "2"), "security.capability", []byte{0x00}, 0)
assert.NilError(t, err)
// there is no known Go implementation of setcap/getcap with support for v3 file capability
out, err := exec.Command("setcap", "cap_block_suspend+ep", filepath.Join(origin, "2")).CombinedOutput()
assert.NilError(t, err, string(out))

for _, c := range []Compression{
Uncompressed,
Expand All @@ -255,10 +264,9 @@ func TestTarUntarWithXattr(t *testing.T) {
if len(changes) != 1 || changes[0].Path != "/3" {
t.Fatalf("Unexpected differences after tarUntar: %v", changes)
}
capability, _ := system.Lgetxattr(filepath.Join(origin, "2"), "security.capability")
if capability == nil && capability[0] != 0x00 {
t.Fatalf("Untar should have kept the 'security.capability' xattr.")
}
out, err := exec.Command("getcap", filepath.Join(origin, "2")).CombinedOutput()
assert.NilError(t, err, string(out))
assert.Check(t, is.Contains(string(out), "= cap_block_suspend+ep"), "untar should have kept the 'security.capability' xattr")
}
}

Expand Down