Update query for users listing (#3324)

- Filter undesired entries.
- LEFT JOIN to include users missing groups.

#2488
This commit is contained in:
Zach Wasserman 2021-12-11 16:25:08 -08:00 committed by GitHub
parent 8ec3986263
commit 3a5037f798
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

1
changes/update-users Normal file
View file

@ -0,0 +1 @@
* Remove host users without login shells, and include host users missing groups.

View file

@ -517,7 +517,7 @@ FROM python_packages;
}
var usersQuery = DetailQuery{
Query: `SELECT uid, username, type, groupname, shell FROM users u JOIN groups g ON g.gid=u.gid;`,
Query: `SELECT uid, username, type, groupname, shell FROM users u LEFT JOIN groups g ON g.gid=u.gid WHERE type <> 'special' AND shell NOT LIKE '%/false' AND shell NOT LIKE '%/nologin' AND shell NOT LIKE '%/shutdown' AND shell NOT LIKE '%/halt' AND username NOT LIKE '%$' AND username NOT LIKE '\_%' ESCAPE '\' AND NOT (username = 'sync' AND shell ='/bin/sync')`,
IngestFunc: func(logger log.Logger, host *fleet.Host, rows []map[string]string) error {
var users []fleet.HostUser
for _, row := range rows {