Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

tests: fix when $HOME is only accessible by current user #3559

Merged
merged 1 commit into from Jan 30, 2017

Conversation

mxinden
Copy link
Collaborator

@mxinden mxinden commented Jan 25, 2017

Previously CommandsNeedRoot tested by executing rkt binary with user
"nobody". This fails when the ~/ folder of the user is only accessible
by the user itself. Now the test first chooses the owner of the rkt
binary file and if that is root it uses the "nobody" user as a fallback.

Fixes #1737

@lucab lucab changed the title Test/CommandsNeedRoot: Fix when ~/ is only accesible by current user tests: fix when ~/ is only accesible by current user Jan 25, 2017
@lucab lucab changed the title tests: fix when ~/ is only accesible by current user tests: fix when $HOME is only accesible by current user Jan 25, 2017
@jonboulle jonboulle changed the title tests: fix when $HOME is only accesible by current user tests: fix when $HOME is only accessible by current user Jan 25, 2017
@lucab lucab added this to the v1.24.0 milestone Jan 25, 2017
@lucab
Copy link
Member

lucab commented Jan 25, 2017

It looks like the flakes are related to #3477.

@lucab
Copy link
Member

lucab commented Jan 25, 2017

It looks like there are some more cases not covered here, so deferring review to next iteration.

@mxinden
Copy link
Collaborator Author

mxinden commented Jan 26, 2017

Fixes #1737

Copy link
Contributor

@s-urbaniak s-urbaniak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fedora24 failure is a known flake, this LGTM, thanks 🎉!

Leaving the last word to @lucab

@@ -220,6 +221,19 @@ func (ctx *RktRunCtx) rktBin() string {
return abs
}

func (ctx *RktRunCtx) GetUidGidRktBinOwnerNotRoot() (int, int) {
s, _ := os.Stat(ctx.rktBin())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may error out for some reason, in which case we implicitly panic here below. Better to check for error and fallback to GetUnprivilegedUidGid() in that case.

Previously tested by executing rkt binary with user "nobody". This fails
when the $HOME folder of the user is only accessible by the user itself.
Now the tests first choose the owner of the rkt binary file and if that
is root they use the "nobody" user as a fallback.
@lucab lucab merged commit 6418f5e into rkt:master Jan 30, 2017
@evverx
Copy link
Contributor

evverx commented Feb 9, 2017

=== RUN   TestNonRootReadInfo
--- FAIL: TestNonRootReadInfo (14.82s)
	rkt_non_root_test.go:79: #0: Running /home/vagrant/go/gopath/src/github.com/coreos/rkt/build-rkt-1.24.0+git/tmp/functional/rkt --dir=/tmp/datadir-661380370 --local-config=/tmp/localdir-451935049 --system-config=/tmp/systemdir-182948372 --user-config=/tmp/userdir-381586531 --insecure-options=image run --mds-register=false /home/vagrant/go/gopath/src/github.com/coreos/rkt/build-rkt-1.24.0+git/tmp/functional/test-tmp/rkt-inspect-1.aci
	rkt_non_root_test.go:79: #1: Running /home/vagrant/go/gopath/src/github.com/coreos/rkt/build-rkt-1.24.0+git/tmp/functional/rkt --dir=/tmp/datadir-661380370 --local-config=/tmp/localdir-451935049 --system-config=/tmp/systemdir-182948372 --user-config=/tmp/userdir-381586531 --insecure-options=image run --no-overlay --mds-register=false /home/vagrant/go/gopath/src/github.com/coreos/rkt/build-rkt-1.24.0+git/tmp/functional/test-tmp/rkt-inspect-2.aci
	rkt_non_root_test.go:79: #2: Running /home/vagrant/go/gopath/src/github.com/coreos/rkt/build-rkt-1.24.0+git/tmp/functional/rkt --dir=/tmp/datadir-661380370 --local-config=/tmp/localdir-451935049 --system-config=/tmp/systemdir-182948372 --user-config=/tmp/userdir-381586531 --insecure-options=image run --no-overlay --private-users --mds-register=false /home/vagrant/go/gopath/src/github.com/coreos/rkt/build-rkt-1.24.0+git/tmp/functional/test-tmp/rkt-inspect-3.aci
	rkt_non_root_test.go:84: Running /home/vagrant/go/gopath/src/github.com/coreos/rkt/build-rkt-1.24.0+git/tmp/functional/rkt --dir=/tmp/datadir-661380370 --local-config=/tmp/localdir-451935049 --system-config=/tmp/systemdir-182948372 --user-config=/tmp/userdir-381586531 image list
	rkt_tests.go:388: cannot start rkt: fork/exec /home/vagrant/go/gopath/src/github.com/coreos/rkt/build-rkt-1.24.0+git/tmp/functional/rkt: permission denied

This fixes that test for me:

diff --git a/tests/rkt_non_root_test.go b/tests/rkt_non_root_test.go
index 5794424..98546f9 100644
--- a/tests/rkt_non_root_test.go
+++ b/tests/rkt_non_root_test.go
@@ -38,7 +38,9 @@ func TestNonRootReadInfo(t *testing.T) {
        ctx := testutils.NewRktRunCtx()
        defer ctx.Cleanup()

-       gid, err := common.LookupGid(common.RktGroup)
+       uid, _ := ctx.GetUidGidRktBinOwnerNotRoot()
+
+       rktGid, err := common.LookupGid(common.RktGroup)
        if err != nil {
                t.Skipf("Skipping the test because there's no %q group", common.RktGroup)
        }
@@ -82,7 +84,7 @@ func TestNonRootReadInfo(t *testing.T) {

        imgListCmd := fmt.Sprintf("%s image list", ctx.Cmd())
        t.Logf("Running %s", imgListCmd)
-       runRktAsGidAndCheckOutput(t, imgListCmd, "inspect-", false, gid)
+       runRktAsUidGidAndCheckOutput(t, imgListCmd, "inspect-", false, uid, rktGid)
 }

@evverx
Copy link
Contributor

evverx commented Feb 9, 2017

Fix is waiting in #3580
Please take a look

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants