Conversation
There was a problem hiding this comment.
LGTM
1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile
|
Eco-CI Output:
🌳 CO2 Data: Total cost of whole PR so far: |
| return len(energy_machine_providers) <= 1 | ||
|
|
||
| def check_ssh_connections(): | ||
| ps = subprocess.run(['pgrep', 'sshd'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False) |
There was a problem hiding this comment.
But this checks if the demon is running not if someone is connected. Even if no one is connected there will still be a sshd demon running so people can connect.
who should expose users that are connected via sshd or ss -tnp | grep :22 will show open ssh connections
There was a problem hiding this comment.
I did look into that when creating the PR and apparently my testing was not sufficient.
On my test system the ssh port listening was done by systemd. Looked like this:
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:2798 0.0.0.0:* users:(("sshd",pid=597,fd=3))
LISTEN 0 128 [::]:2798 [::]:* users:(("sshd",pid=597,fd=4))But now after your commented I probed more systems, where the sshd process directly sets the listener:
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 *:22 *:* users:(("sshd",pid=5830,fd=3),("systemd",pid=1,fd=309))The reason for not going for port 22 is that I also want to support ssh watching on non standard ports.
However given that I cannot identify the process I currently have no idea how to do it. Since the sshd is not readable the best shot would be to parse ss and check for port 22 or for sshd as process user ...
Or, maybe even better, to not allow any listening connections at all in the ss list ... (apart from DNS and our DB connection)?
You got a more sleek idea? Or any remarks?
There was a problem hiding this comment.
Couldn't you use who | grep pts?
There was a problem hiding this comment.
I will look into this, but I have a feeling that forced commands via SSH are not captured through that mechanism ...
There was a problem hiding this comment.
No, but isn’t that a server configuration? I would say that we add something into the documentation that this will then not work. My assumption is that 99+% will have a shell open.
Greptile Summary
Added system checks to warn users about active SSH connections and logged-in users that could affect measurement accuracy in the Green Metrics Tool.
lib/system_checks.pyto detect active SSH connections using pgrep sshdlib/system_checks.pyto identify active users via the who command