Skip to content

Commit

Permalink
manifest: label /usr/bin/{,u}mount correct
Browse files Browse the repository at this point in the history
Similar as #287 we need to
label `/usr/bin/{mount,umount}` as `install_exec_t` to prevent
an selinux denial warning when osbuild runs mount/unmount.

See dea1af4 for more details.
  • Loading branch information
mvo5 committed Jan 25, 2024
1 parent a8de56f commit 1d0034d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/manifest/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ func (p *BuildrootFromContainer) serializeEnd() {
p.containerSpecs = nil
}

func (p *BuildrootFromContainer) getSELinuxLabels() map[string]string {
labels := map[string]string{
"/usr/bin/ostree": "system_u:object_r:install_exec_t:s0",
}
if p.containerBuildable {
labels["/usr/bin/mount"] = "system_u:object_r:install_exec_t:s0"
labels["/usr/bin/umount"] = "system_u:object_r:install_exec_t:s0"
}
return labels
}

func (p *BuildrootFromContainer) serialize() osbuild.Pipeline {
if len(p.containerSpecs) == 0 {
panic("serialization not started")
Expand All @@ -229,9 +240,7 @@ func (p *BuildrootFromContainer) serialize() osbuild.Pipeline {
pipeline.AddStage(osbuild.NewSELinuxStage(
&osbuild.SELinuxStageOptions{
FileContexts: "etc/selinux/targeted/contexts/files/file_contexts",
Labels: map[string]string{
"/usr/bin/ostree": "system_u:object_r:install_exec_t:s0",
},
Labels: p.getSELinuxLabels(),
},
))

Expand Down
20 changes: 20 additions & 0 deletions pkg/manifest/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,23 @@ func TestNewBuildFromContainerSpecs(t *testing.T) {
build.serializeEnd()
require.Nil(t, build.getContainerSpecs())
}

func TestBuildFromContainerSpecsGetSelinuxLabelsNotBuildable(t *testing.T) {
build := &BuildrootFromContainer{}

assert.Equal(t, build.getSELinuxLabels(), map[string]string{
"/usr/bin/ostree": "system_u:object_r:install_exec_t:s0",
})
}

func TestBuildFromContainerSpecsGetSelinuxLabelsWithContainerBuildable(t *testing.T) {
build := &BuildrootFromContainer{
containerBuildable: true,
}

assert.Equal(t, build.getSELinuxLabels(), map[string]string{
"/usr/bin/ostree": "system_u:object_r:install_exec_t:s0",
"/usr/bin/mount": "system_u:object_r:install_exec_t:s0",
"/usr/bin/umount": "system_u:object_r:install_exec_t:s0",
})
}

0 comments on commit 1d0034d

Please sign in to comment.