Page MenuHomePhabricator

Shell accounts containing `-` not recognized when parsing "user@host" clause from a `!log` message
Closed, ResolvedPublic

Description

For example this does not get parsed correctly:

+logmsgbot_cloud> !log raymond-ndibe@cloudcumin1001 tools START - Cookbook wmcs.toolforge.k8s.worker.upgrade for node tools-k8s-worker-nfs-20 from 1.26.15 to 1.27.16 (T359641)
18:46:15
<+stashbot> https://stashbot.toolforge.org/ logmsgbot_cloud: Unknown project "raymond-ndibe@cloudcumin1001"
18:47:24

Happened when upgrading k8s

Event Timeline

Stashbot in the #wikimedia-cloud-feed channel expects !log messages to start with the project to assign the log event to. This is different than the assumption in most other channels that all the logging goes to the production SAL. Some info at https://wikitech.wikimedia.org/wiki/Tool:Stashbot#!log_processing

some pointers that might help to reproduce this:

log into cloud cumins:

ssh user@cloudcumin1001.eqiad.wmnet

run tmux

tmux

inside tmux, run sudo su:

sudo su

run cookbook with task-id specified

cookbook <cookbook.path> --task-id <task id>

The above is the way I'm currently running the cookbook. Hopefully it'll help in reproducing this

some pointers that might help to reproduce this:

log into cloud cumins:

ssh user@cloudcumin1001.eqiad.wmnet

run tmux

tmux

inside tmux, run sudo su:

sudo su

run cookbook with task-id specified

cookbook <cookbook.path> --task-id <task id>

The above is the way I'm currently running the cookbook. Hopefully it'll help in reproducing this

@bd808 am I doing anything wrong here?

some pointers that might help to reproduce this:
...
The above is the way I'm currently running the cookbook. Hopefully it'll help in reproducing this

@bd808 am I doing anything wrong here?

No, it's not you :), I think that the cookbook might not differenciate between -cloud-feed and -cloud

No, it's not you :), I think that the cookbook might not differenciate between -cloud-feed and -cloud

This looks to be a Stashbot parsing bug related to @Raymond_Ndibe's Developer account shell name.

Compare:

[14:26:39] <logmsgbot_cloud>	 !log raymond-ndibe@cloudcumin1001 tools START - Cookbook wmcs.toolforge.k8s.worker.upgrade for node tools-k8s-worker-102 from 1.26.15 to 1.27.16 (T359641)
[14:26:39] <stashbot>	 logmsgbot_cloud: Unknown project "raymond-ndibe@cloudcumin1001"

vs

[14:27:52] <logmsgbot_cloud>	 !log aborrero@cloudcumin1001 admin START - Cookbook wmcs.openstack.tofu running tofu plan for https://gitlab.wikimedia.org/repos/cloud/cloud-vps/tofu-infra/-/merge_requests/45

In the first Stashbot rejected the log line, but in the second it processed things as expected and wrote https://sal.toolforge.org/log/toc7-5EBFk7ipym_mRkO and https://wikitech.wikimedia.org/w/index.php?title=Nova_Resource:Admin/SAL&diff=prev&oldid=2227244.

The problem was introduced in rLTST7cd54b314241: Parse user@host in wm-bot2 messages:

# - Strip 'user@host' portion
parts = bang["message"].split(None, 1)
if len(parts) > 1 and re.match(r"\w+@\w+", parts[0]):
    if is_from_logmsgbot:
        # we trust messages coming from logmsgbot
        bang["nick"], bang["message"] = parts
    if is_from_wmbot:
        # wm-bot can be easily spoofed, so we add a "wmbot~" prefix
        bang["nick"] = "wmbot~%s" % parts[0]
        bang["message"] = parts[1]

re.match(r"\w+@\w+", parts[0]) is not matching "raymond-ndibe@cloudcumin1001". The user portion of this regex (\w+) is only matching Python's word characters; - is not a word character. The regex used in Striker to validate shell account names is r"^[a-z][a-z0-9_-]{0,31}$". The most important difference for this case is that this regex includes the - character. I think we can make things even simpler for Stashbot's message parser and use re.match(r"[^@]+@\w+", parts[0]) when sniffing for a "user@host" identifier to strip.

Change #1073296 had a related patch set uploaded (by BryanDavis; author: Bryan Davis):

[labs/tools/stashbot@master] sal: Expand regex used to check for "user@host" clause

https://gerrit.wikimedia.org/r/1073296

bd808 renamed this task from [cookbook,sal] it does not seem to parse correctly the user@host header anymore to Shell accounts containing `-` not recognized when parsing "user@host" clause from a `!log` message.Sep 16 2024, 11:10 PM

Change #1073296 merged by jenkins-bot:

[labs/tools/stashbot@master] sal: Expand regex used to check for "user@host" clause

https://gerrit.wikimedia.org/r/1073296

Mentioned in SAL (#wikimedia-cloud) [2024-09-17T00:03:28Z] <wmbot~bd808@tools-bastion-12> Updated to 25edc86 (T374875)

[00:04]  <logmsgbot_cloud> !log raymond-ndibe@cloudcumin1001 tools END (PASS) - Cookbook wmcs.toolforge.k8s.reboot (exit_code=0) for tools-k8s-worker-nfs-31, tools-k8s-worker-nfs-32, tools-k8s-worker-nfs-33, tools-k8s-worker-nfs-36 (T359641)

https://sal.toolforge.org/log/E31L_ZEBKFqumxvtyNSf