Skip to content

Commit

Permalink
fix(CSI-213): fix selinux context based on protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyberezansky committed Aug 4, 2024
1 parent 0ce9f62 commit 954669b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pkg/wekafs/mountoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import (
)

const (
selinuxContext = "wekafs_csi_volume"
selinuxContextWekaFs = "wekafs_csi_volume_t"
selinuxContextNfs = "nfs_t"
MountOptionSyncOnClose = "sync_on_close"
MountOptionReadOnly = "ro"
MountOptionWriteCache = "writecache"
MountOptionCoherent = "coherent"
MountOptionReadCache = "readcache"
MountProtocolWekafs = "wekafs"
MountProtocolNfs = "nfs"
)

type mountOption struct {
Expand Down Expand Up @@ -145,12 +148,22 @@ func (opts MountOptions) Hash() uint32 {
return h.Sum32()
}

func (opts MountOptions) setSelinux(selinuxSupport bool) {
func (opts MountOptions) setSelinux(selinuxSupport bool, mountProtocol string) {
if selinuxSupport {
o := newMountOptionFromString(fmt.Sprintf("fscontext=\"system_u:object_r:%s_t:s0\"", selinuxContext))
var o mountOption
if mountProtocol == MountProtocolWekafs {
o = newMountOptionFromString(fmt.Sprintf("fscontext=\"system_u:object_r:%s:s0\"", selinuxContextWekaFs))
} else if mountProtocol == MountProtocolNfs {
o = newMountOptionFromString(fmt.Sprintf("context=\"system_u:object_r:%s:s0\"", selinuxContextNfs))
}
opts.customOptions[o.option] = o
} else {
delete(opts.customOptions, "fscontext")
if mountProtocol == MountProtocolWekafs {
delete(opts.customOptions, "fscontext")
}
if mountProtocol == MountProtocolNfs {
delete(opts.customOptions, "context")
}
}
}

Expand Down

0 comments on commit 954669b

Please sign in to comment.