Skip to content

Commit

Permalink
filesystem/policy:added ostree specific mountpoints
Browse files Browse the repository at this point in the history
Ostree specific filesystem policy to prevent users form
accidentally  creating custom filesystems that can ovewrite the
systems filesystem.

Signed-off-by: Sayan Paul <[email protected]>
  • Loading branch information
say-paul committed Dec 5, 2023
1 parent f18b991 commit 32d6b1a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/pathpolicy/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ var CustomFilesPolicies = NewPathPolicies(map[string]PathPolicy{
"/etc/passwd": {Deny: true},
"/etc/group": {Deny: true},
})

// MountpointPolicies for ostree
var OstreeMountpointPolicies = NewPathPolicies(map[string]PathPolicy{
"/": {},
"/ostree": {Deny: true},
})
32 changes: 32 additions & 0 deletions internal/pathpolicy/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,35 @@ func TestMountpointPolicies(t *testing.T) {
})
}
}

func TestOstreeMountpointPolicies(t *testing.T) {
type testCase struct {
path string
allowed bool
}

testCases := []testCase{
{"/ostree", false},
{"/ostree/foo", false},

{"/foo", true},
{"/foo/bar", true},

{"/var", true},
{"/var/roothome", true},

{"/home", true},
{"/home/shadowman", true},
}

for _, tc := range testCases {
t.Run(tc.path, func(t *testing.T) {
err := OstreeMountpointPolicies.Check(tc.path)
if err != nil && tc.allowed {
t.Errorf("expected %s to be allowed, but got error: %v", tc.path, err)
} else if err == nil && !tc.allowed {
t.Errorf("expected %s to be denied, but got no error", tc.path)
}
})
}
}

0 comments on commit 32d6b1a

Please sign in to comment.