A user_management role: create the operator account, its SSH keys and sudo, and optionally remove accounts that should not exist. Proposal first, for the same reason as the sshd role: the README lists user management as in scope and I do not know whether you already have it queued.
Why
A fresh host needs a non-root operator account before anything else can be hardened, and sshd hardening that turns off password login is unsafe without one. Doing it by hand, per host, is how you end up with different users and stale keys on every machine.
The role I use does this:
Ensures sudo is installed and creates the primary operator user, with a password hash, groups and a shell, from variables.
Manages additional users and their authorized_keys.
Optionally bootstraps: if the configured user cannot connect yet, it falls back to root to create it.
Optionally disables cloud-init's user management, so it does not rewrite the accounts.
Optionally removes users that are not in the managed list (authoritative mode).
Scope of what I would send
About 6 files, roughly 165 lines, with no_log on every task that handles a password hash or key. What I would change before sending: the mandatory vault-style ansible_become_password_hashed variable becomes a user_management_-prefixed input, the bootstrap-to-root assumption becomes an explicit opt-in, and my issue references go. A user_management_-prefixed variable set typed in argument_specs.yml, and a molecule scenario.
Risk, stated up front
The authoritative removal mode deletes users and, optionally, their home directories. I would ship it off by default and require an explicit allow-list before it removes anything, with molecule cases for the dangerous paths (removing the connecting user must be refused).
Questions for the maintainer
Is this role already queued from your environment repository? If so I would rather review it than duplicate it.
Is an authoritative removal mode wanted at all?
## What
A `user_management` role: create the operator account, its SSH keys and sudo, and optionally remove accounts that should not exist. Proposal first, for the same reason as the `sshd` role: the README lists user management as in scope and I do not know whether you already have it queued.
## Why
A fresh host needs a non-root operator account before anything else can be hardened, and `sshd` hardening that turns off password login is unsafe without one. Doing it by hand, per host, is how you end up with different users and stale keys on every machine.
The role I use does this:
- Ensures `sudo` is installed and creates the primary operator user, with a password hash, groups and a shell, from variables.
- Manages additional users and their `authorized_keys`.
- Optionally bootstraps: if the configured user cannot connect yet, it falls back to root to create it.
- Optionally disables cloud-init's user management, so it does not rewrite the accounts.
- Optionally removes users that are not in the managed list (authoritative mode).
## Scope of what I would send
About 6 files, roughly 165 lines, with `no_log` on every task that handles a password hash or key. What I would change before sending: the mandatory vault-style `ansible_become_password_hashed` variable becomes a `user_management_`-prefixed input, the bootstrap-to-root assumption becomes an explicit opt-in, and my issue references go. A `user_management_`-prefixed variable set typed in `argument_specs.yml`, and a molecule scenario.
## Risk, stated up front
The authoritative removal mode deletes users and, optionally, their home directories. I would ship it **off by default** and require an explicit allow-list before it removes anything, with molecule cases for the dangerous paths (removing the connecting user must be refused).
## Questions for the maintainer
- Is this role already queued from your environment repository? If so I would rather review it than duplicate it.
- Is an authoritative removal mode wanted at all?
Understood, and thanks for saying so before any code landed. I will not open a PR for this.
For reference only: I had already prepared a local, unpushed user_management role branch. The points I thought were worth deciding deliberately, in case they help your migration: a single user_management_users list instead of a separate primary-user variable; removal only through an explicit allow-list (never "everything not listed"), refusing root, the connecting user and anyone listed as present, with home removal a separate default-off switch; no_log on everything that touches a hash or key; and no "fall back to root" bootstrap. The Molecule scenario has not run. If it helps, say so and I will share it; otherwise it stays local and I will delete it once your role lands. I would be glad to review your version instead.
Assisted-by: Claude Code
Understood, and thanks for saying so before any code landed. I will not open a PR for this.
For reference only: I had already prepared a local, unpushed `user_management` role branch. The points I thought were worth deciding deliberately, in case they help your migration: a single `user_management_users` list instead of a separate primary-user variable; removal only through an explicit allow-list (never "everything not listed"), refusing root, the connecting user and anyone listed as present, with home removal a separate default-off switch; `no_log` on everything that touches a hash or key; and no "fall back to root" bootstrap. The Molecule scenario has not run. If it helps, say so and I will share it; otherwise it stays local and I will delete it once your role lands. I would be glad to review your version instead.
Assisted-by: Claude Code
Labelled Reviewed/Duplicate and withdrawn by the proposer, but still Status/Ready for Human. Recommend the maintainer closes it. (From Order of the implementation backlog, #198.)
Labelled Reviewed/Duplicate and withdrawn by the proposer, but still Status/Ready for Human. Recommend the maintainer closes it. (From Order of the implementation backlog, #198.)
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What
A
user_managementrole: create the operator account, its SSH keys and sudo, and optionally remove accounts that should not exist. Proposal first, for the same reason as thesshdrole: the README lists user management as in scope and I do not know whether you already have it queued.Why
A fresh host needs a non-root operator account before anything else can be hardened, and
sshdhardening that turns off password login is unsafe without one. Doing it by hand, per host, is how you end up with different users and stale keys on every machine.The role I use does this:
sudois installed and creates the primary operator user, with a password hash, groups and a shell, from variables.authorized_keys.Scope of what I would send
About 6 files, roughly 165 lines, with
no_logon every task that handles a password hash or key. What I would change before sending: the mandatory vault-styleansible_become_password_hashedvariable becomes auser_management_-prefixed input, the bootstrap-to-root assumption becomes an explicit opt-in, and my issue references go. Auser_management_-prefixed variable set typed inargument_specs.yml, and a molecule scenario.Risk, stated up front
The authoritative removal mode deletes users and, optionally, their home directories. I would ship it off by default and require an explicit allow-list before it removes anything, with molecule cases for the dangerous paths (removing the connecting user must be refused).
Questions for the maintainer
User management will first be migrated from my repo in wave one, see README.md
Understood, and thanks for saying so before any code landed. I will not open a PR for this.
For reference only: I had already prepared a local, unpushed
user_managementrole branch. The points I thought were worth deciding deliberately, in case they help your migration: a singleuser_management_userslist instead of a separate primary-user variable; removal only through an explicit allow-list (never "everything not listed"), refusing root, the connecting user and anyone listed as present, with home removal a separate default-off switch;no_logon everything that touches a hash or key; and no "fall back to root" bootstrap. The Molecule scenario has not run. If it helps, say so and I will share it; otherwise it stays local and I will delete it once your role lands. I would be glad to review your version instead.Assisted-by: Claude Code
Labelled Reviewed/Duplicate and withdrawn by the proposer, but still Status/Ready for Human. Recommend the maintainer closes it. (From Order of the implementation backlog, #198.)
@Dragonish pls check whether there sre things you added in your repo that we should migrate here.