Skip to content

Commit

Permalink
feat: report process MAC labels
Browse files Browse the repository at this point in the history
This will be useful for debugging process access rights once we start implementing SELinux

Signed-off-by: Dmitry Sharshakov <dmitry.sharshakov@siderolabs.com>
  • Loading branch information
dsseng committed Apr 22, 2024
1 parent d460328 commit 6fbd126
Show file tree
Hide file tree
Showing 6 changed files with 1,134 additions and 1,073 deletions.
1 change: 1 addition & 0 deletions api/machine/machine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ message ProcessInfo {
string command = 8;
string executable = 9;
string args = 10;
string label = 11;
}

// rpc restart
Expand Down
6 changes: 3 additions & 3 deletions cmd/talosctl/cmd/talos/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func processesOutput(ctx context.Context, c *client.Client) (output string, err

s := []string{}

s = append(s, "NODE | PID | STATE | THREADS | CPU-TIME | VIRTMEM | RESMEM | COMMAND")
s = append(s, "NODE | PID | STATE | THREADS | CPU-TIME | VIRTMEM | RESMEM | LABEL | COMMAND")

for _, msg := range resp.Messages {
procs := msg.Processes
Expand Down Expand Up @@ -221,8 +221,8 @@ func processesOutput(ctx context.Context, c *client.Client) (output string, err
}

s = append(s,
fmt.Sprintf("%12s | %6d | %1s | %4d | %8.2f | %7s | %7s | %s",
node, p.Pid, p.State, p.Threads, p.CpuTime, humanize.Bytes(p.VirtualMemory), humanize.Bytes(p.ResidentMemory), args))
fmt.Sprintf("%12s | %6d | %1s | %4d | %8.2f | %7s | %7s | %64s | %s",
node, p.Pid, p.State, p.Threads, p.CpuTime, humanize.Bytes(p.VirtualMemory), humanize.Bytes(p.ResidentMemory), p.Label, args))
}
}

Expand Down
7 changes: 7 additions & 0 deletions internal/pkg/miniprocfs/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ func (procs *Processes) readProc(pidString string) (*machine.ProcessInfo, error)
return nil, err
}

var label string

if err = procs.readFileIntoBuf(path + "attr/current"); err == nil {
label = string(bytes.TrimSpace(procs.buf))
}

return &machine.ProcessInfo{
Pid: int32(pid),
Ppid: int32(ppid),
Expand All @@ -172,6 +178,7 @@ func (procs *Processes) readProc(pidString string) (*machine.ProcessInfo, error)
Command: command,
Executable: executable,
Args: args,
Label: label,
}, nil
}

Expand Down
Loading

0 comments on commit 6fbd126

Please sign in to comment.