Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not inherit HOME and USER env vars from pebble daemon environment #262

Merged
merged 5 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ jobs:
- name: Test
run: |
go test -c ./internals/daemon
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E ./daemon.test -check.v -check.f ^execSuite\.TestUserGroup$
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E ./daemon.test -check.v -check.f ^execSuite\.TestUserIDGroupID$
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E ./daemon.test -check.v -check.f ^filesSuite\.TestWriteUserGroupReal$
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E ./daemon.test -check.v -check.f ^filesSuite\.TestMakeDirsUserGroupReal$
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E -H ./daemon.test -check.v -check.f ^execSuite\.TestUserGroup$
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E -H ./daemon.test -check.v -check.f ^execSuite\.TestUserIDGroupID$
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E -H ./daemon.test -check.v -check.f ^filesSuite\.TestWriteUserGroupReal$
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E -H ./daemon.test -check.v -check.f ^filesSuite\.TestMakeDirsUserGroupReal$
go test -c ./internals/overlord/servstate/
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E ./servstate.test -check.v -check.f ^S.TestUserGroup$
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E -H ./servstate.test -check.v -check.f ^S.TestUserGroup$

format:
runs-on: ubuntu-latest
Expand Down
11 changes: 11 additions & 0 deletions internals/daemon/api_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func (s *filesSuite) TestListFilesNonAbsPath(c *C) {
}

func (s *filesSuite) TestListFilesPermissionDenied(c *C) {
if os.Getuid() == 0 {
c.Skip("cannot run test as root")
}
tmpDir := c.MkDir()
noAccessDir := filepath.Join(tmpDir, "noaccess")
c.Assert(os.Mkdir(noAccessDir, 0o775), IsNil)
Expand Down Expand Up @@ -301,6 +304,10 @@ func (s *filesSuite) TestReadMultiple(c *C) {
}

func (s *filesSuite) TestReadErrors(c *C) {
if os.Getuid() == 0 {
c.Skip("cannot run test as root")
}

tmpDir := createTestFiles(c)
writeTempFile(c, tmpDir, "no-access", "x", 0)

Expand Down Expand Up @@ -1121,6 +1128,10 @@ nested user group
}

func (s *filesSuite) TestWriteErrors(c *C) {
if os.Getuid() == 0 {
c.Skip("cannot run test as root")
}

tmpDir := c.MkDir()
c.Assert(os.Mkdir(tmpDir+"/permission-denied", 0), IsNil)
pathNoContent := tmpDir + "/no-content"
Expand Down
10 changes: 9 additions & 1 deletion internals/overlord/cmdstate/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,16 @@ func Exec(st *state.State, args *ExecArgs) (*state.Task, ExecMetadata, error) {
return nil, ExecMetadata{}, errors.New("cannot use interactive mode without a terminal")
}

// Inherit the pebble daemon environment.
// Inherit the pebble daemon environment
// If the user is being changed, reset the HOME and USER env vars so that they
// can be set correctly later on in this method
benhoyt marked this conversation as resolved.
Show resolved Hide resolved
environment := osutil.Environ()
if args.UserID != nil && *args.UserID != os.Getuid() {
for _, k := range []string{"HOME", "USER"} {
delete(environment, k)
benhoyt marked this conversation as resolved.
Show resolved Hide resolved
}
benhoyt marked this conversation as resolved.
Show resolved Hide resolved
}

for k, v := range args.Environment {
// Requested environment takes precedence.
environment[k] = v
Expand Down
Loading