Skip to content

(PE-47146) Use TCP-only ss and inode matching for S0041/S0042 - #254

Merged
beechtom merged 2 commits into
mainfrom
PE-47146/main/ss-tcp-inode-match
Nov 10, 2026
Merged

beechtom merged 2 commits into
mainfrom
PE-47146/main/ss-tcp-inode-match

Conversation

@beechtom

Copy link
Copy Markdown
Contributor

Summary

S0041 and S0042 ran ss -onp state established '( dport = :PORT )'. Without -t, ss queries every socket family it knows, including DCCP, and -p makes it walk /proc/<pid>/fd for every process. On kernels whose SELinux netlink table no longer includes DCCPDIAG_GETSOCK (reproduced on AL2023 with kernel 6.18.56), every run logs:

SELinux: unrecognized netlink message: protocol=4 nlmsg_type=19 sclass=netlink_tcpdiag_socket ... comm=ss

This reuses the approach agent_status_check AS002 has used since v2.5.0, moved into PEStatusCheck so the checks can share it:

  • ss -tone state established '( dport = :PORT )' collects socket inodes (2 TCP netlink queries instead of 13; no DCCP, no -p)
  • the target process comes from the systemd unit's MainPID
  • the check passes if that process holds one of the socket inodes

S0042 checks pxp-agent. S0041 checks pe-puppetserver: on compilers the PCP broker runs inside puppetserver, and pe-orchestration-services does not run there. This also stops S0041 matching any unrelated java process (it used result.include?('java')).

Jira: PE-47146. Not changed: AS002 (it still globs /proc/*/cmdline; it could move to the shared helpers in a follow-up).

Testing

Unit: 13 examples pass (helpers, plus S0041/S0042 chunks with a stubbed PEStatusCheck). The chunk tests fail if S0041 looks at the wrong unit. The repo's normal spec_helper does not load in my environment (Puppet 8.19 on Ruby 3.3.7 raises a FrozenError, with or without this change), so I ran the new specs with a stubbed puppet. Please run them in CI.

Live PE 2025.12.3-rc0-7-gf7c6aae, RHEL 9 primary + compiler, SELinux enforcing:

  • S0041 and S0042 are true. S0042 goes false with pxp-agent stopped and S0041 goes false with pe-puppetserver stopped; both recover after restart.
  • Traced commands are ss -tone ... only, no -p.
  • 0 AVCs.

AL2023, kernel 6.18.56, enforcing, real PE agent with an established 8142 connection (S0042 chunk):

code, 3 runs each S0042 "unrecognized netlink" warnings
original true +6
this PR true +0
original again true +6

AL2023 kernels 6.1.49 and 6.12.114 and RHEL 9 (5.14) do not log the warning with either version, so the fix only changes the logged output on newer kernels.

Not covered

  • Only the S0042 chunk was run on AL2023: the whole fact cannot resolve on a non-infrastructure node. S0041 was run on the RHEL 9 compiler only.
  • No acceptance test change (the ticket suggests an ausearch/AVC check and a compiler in the matrix). I can follow up.
  • The 2023.8.x line pins v4.3.0, so it needs a bump or a patch release.
  • This repo's recent commits are syncing from "puppetlabs/support_workflows". If it is mirrored, this may need to land there first.

🤖 Generated with Claude Code

S0041 and S0042 ran `ss -onp state established ...`. Without `-t`, ss
queries every socket family it knows, including DCCP. On kernels where
SELinux's netlink table no longer has DCCPDIAG_GETSOCK (e.g. AL2023 with
kernel 6.18) each run logs:

  SELinux: unrecognized netlink message: protocol=4 nlmsg_type=19
  sclass=netlink_tcpdiag_socket ... comm=ss

`-p` also made ss walk /proc/<pid>/fd for every process.

Reuse the approach agent_status_check AS002 has used since v2.5.0, moved
into PEStatusCheck so the checks can share it:

* `ss -tone state established '( dport = :PORT )'` collects socket inodes
  (2 TCP netlink queries instead of 13, no DCCP, no -p)
* the target process is found from the systemd unit's MainPID
* the check passes if the process holds one of those socket inodes

S0042 uses pxp-agent. S0041 uses pe-puppetserver: on compilers the PCP
broker runs inside puppetserver, and pe-orchestration-services does not
run there. This also stops S0041 matching any unrelated java process.

Adds unit tests for the helpers and for the S0041/S0042 chunks.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@beechtom
beechtom requested review from a team as code owners November 10, 2026 20:06
@beechtom
beechtom requested a balanced review from Copilot November 10, 2026 20:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The use of systemctl show --value breaks compatibility with systemd 219 on supported Linux 7 hosts, causing S0041 and S0042 to falsely report unhealthy connections.

1 open issue
What changed in this PR

This PR changes S0041/S0042 connection checks to use TCP socket inodes and systemd service PIDs, avoiding unnecessary socket-family queries that trigger SELinux warnings.

Changes:

  • Add shared helpers for TCP socket discovery, process socket ownership, and service PID lookup.
  • Match S0041 against pe-puppetserver and S0042 against pxp-agent, replacing process-name matching.
  • Add unit coverage for the helpers and both fact chunks.
File Description
spec/​unit/​pe_status_check_sockets_spec.rb Tests socket helpers and PID lookup.
spec/​unit/​pe_status_check_fact_sockets_spec.rb Tests service selection, connection results, and failure handling.
lib/​shared/​pe_status_check.rb Adds TCP inode matching and systemd PID helpers.
lib/​facter/​pe_status_check.rb Switches S0041/S0042 to service-specific socket ownership checks.

Review effort: Balanced

Comment thread lib/shared/pe_status_check.rb Resolved
@beechtom beechtom added the bug Something isn't working label Nov 10, 2026
`systemctl show --value` needs systemd 230+. RHEL/CentOS/Oracle Linux 7
(still in metadata.json) ship systemd 219, where the command fails and
S0041/S0042 would report false on healthy hosts. Read the `MainPID=<n>`
line from plain `systemctl show --property=MainPID` instead.

Addresses review feedback on #254.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@beechtom

Copy link
Copy Markdown
Contributor Author

EL7 validation (follow-up to the systemd 219 review comment)

Tested on RHEL 7.2 (systemd 219) with a real PE agent (puppet-agent 8.22.2.8, installed from a PE 2025.12.3 primary), with pxp-agent holding an established connection to the broker on 8142. Each version of the S0042 chunk was loaded from git history and run with the agent's own Ruby:

code S0042
original (ss -onp) true
first commit 522ad59 (systemctl show --value) false, a false negative: the connection exists
fix fd7d523 (parse MainPID=) true
fix, pxp-agent stopped false
fix, pxp-agent restarted true

So the review comment was right: on systemd 219 the original change reported an unhealthy broker connection on a healthy host, and fd7d523 resolves it.

Not covered: S0041 on EL7 (compiler-only; this host is not a compiler), and CentOS/OracleLinux/Scientific 7, which share systemd 219 but were not tested. S0041 uses the same service_main_pid helper and was verified on a RHEL 9 compiler.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the service-specific TCP socket checks.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@beechtom
beechtom merged commit 58a405a into main Nov 10, 2026
17 of 21 checks passed
@beechtom
beechtom deleted the PE-47146/main/ss-tcp-inode-match branch November 10, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants