Page MenuHomePhabricator

Standardize the stats system user uid
Closed, ResolvedPublic

Description

In T285355, we just added a new host that has the stats system user. This user now has 4 different uids across the fleet. Now that everything is Buster, we should ensure that the stats user has the same uid everywhere.

We did this for other analytics system users in T287063: Refactor profile::analytics::cluster::users. We should be able to follow the same procedure from there.

Event Timeline

The stats user is declared in statistics::user.

odimitrijevic triaged this task as High priority.
odimitrijevic moved this task from Incoming to Operational Excellence on the Analytics board.

stats has uid 499 on 5 hosts, and 495 and 498 on two others. Let's use 499.

19:30:04 [@cumin1001:/home/otto] $ sudo cumin 'R:Class = statistics::user' 'getent passwd stats'
7 hosts will be targeted:
an-launcher1002.eqiad.wmnet,an-web1001.eqiad.wmnet,stat[1004-1008].eqiad.wmnet
Ok to proceed on 7 hosts? Enter the number of affected hosts to confirm or "q" to quit 7
===== NODE GROUP =====
(1) an-launcher1002.eqiad.wmnet
----- OUTPUT of 'getent passwd stats' -----
stats:x:495:496::/var/lib/stats:/bin/bash
===== NODE GROUP =====
(5) an-web1001.eqiad.wmnet,stat[1004,1006-1008].eqiad.wmnet
----- OUTPUT of 'getent passwd stats' -----
stats:x:499:499::/var/lib/stats:/bin/bash
===== NODE GROUP =====
(1) stat1005.eqiad.wmnet
----- OUTPUT of 'getent passwd stats' -----
stats:x:498:498::/var/lib/stats:/bin/bash

Change 725098 had a related patch set uploaded (by Ottomata; author: Ottomata):

[operations/puppet@production] Standardize the stats system user uid

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

Ok, holding on this for now, its late Thursday and I'm not working tomorrow; don't want to break anything.

BTW, we are using uid 918, not 499 based on comment in patch.

Change 725098 merged by Ottomata:

[operations/puppet@production] Standardize the stats system user uid

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

Mentioned in SAL (#wikimedia-analytics) [2022-03-15T14:35:00Z] <ottomata> change stats uid and gid on all stat boxes to 918 - T291384

Done. Changed stats uid and gid on stat boxes using the following scripts:

#!/bin/bash

set -x

change_uid() {
    # $1 new uid
    # $2 username
    if id "$2" &>/dev/null
    then
        OLD_UID=$(id -u $2)
        usermod -u $1 $2
        find / \( -path /proc -o -path /mnt -o -path /sys -o -path /dev -o -path /media \) -prune -false -o -user $OLD_UID -print0 | xargs -0 chown -h $1
    fi
}

change_gid() {
    # $1 new gid
    # $2 username
    if getent group $2 &>/dev/null
    then
        OLD_GID=$(getent group $2 | cut -d ":" -f 3)
        groupmod -g $1 $2
        find / \( -path /proc -o -path /mnt -o -path /sys -o -path /dev -o -path /media \) -prune -false -o -group $OLD_GID -print0  | xargs -0 chgrp -h $1
    fi
}


change_uid 918 stats
change_gid 918 stats

Mentioned in SAL (#wikimedia-analytics) [2022-03-15T17:24:35Z] <ottomata> also change stats uid and gid to 918 on an-web1001 - T291384

I did not realize the stats user was also on an-web1001. Since puppet already changed the uid,gid there, I had to manually run the following to change the 499 uid and gid owned files to stats.

OLD_UID=499
find / \( -path /proc -o -path /mnt -o -path /sys -o -path /dev -o -path /media \) -prune -false -o -user $OLD_UID -print0 | xargs -0 chown -h stats

OLD_GID=499
find / \( -path /proc -o -path /mnt -o -path /sys -o -path /dev -o -path /media \) -prune -false -o -group $OLD_GID -print0  | xargs -0 chgrp -h stats