Skip to content

Commit af5d6b8

Browse files
committed
fix: show SELinux labels on pseudo-fs
On devtmpfs or sysfs SELinux attribute is not listed unless it has been set, yet it is available and represents the SELinux label of file. Signed-off-by: Dmitry Sharshakov <dmitry.sharshakov@siderolabs.com>
1 parent f46922f commit af5d6b8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

internal/app/machined/internal/server/v1alpha1/v1alpha1_server.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ func (s *Server) Copy(req *machine.CopyRequest, obj machine.MachineService_CopyS
791791

792792
// List implements the machine.MachineServer interface.
793793
//
794-
//nolint:gocyclo
794+
//nolint:gocyclo,cyclop
795795
func (s *Server) List(req *machine.ListRequest, obj machine.MachineService_ListServer) error {
796796
if req == nil {
797797
req = new(machine.ListRequest)
@@ -847,13 +847,27 @@ func (s *Server) List(req *machine.ListRequest, obj machine.MachineService_ListS
847847
xattrs := []*machine.Xattr{}
848848

849849
if req.ReportXattrs {
850+
// On filesystems such as devtmpfs and sysfs, xattrs are not supported.
851+
// However, we can still get the label from the security.selinux xattr for automatic labels.
852+
foundSelinux := false
853+
850854
if list, err := xattr.List(fi.FullPath); err == nil {
851855
for _, attr := range list {
852856
if data, err := xattr.Get(fi.FullPath, attr); err == nil {
857+
if attr == "security.selinux" {
858+
foundSelinux = true
859+
}
860+
853861
xattrs = append(xattrs, &machine.Xattr{Name: attr, Data: data})
854862
}
855863
}
856864
}
865+
866+
if !foundSelinux {
867+
if data, err := xattr.Get(fi.FullPath, "security.selinux"); err == nil {
868+
xattrs = append(xattrs, &machine.Xattr{Name: "security.selinux", Data: data})
869+
}
870+
}
857871
}
858872

859873
if fi.Error != nil {

0 commit comments

Comments
 (0)