Hardening SSH targets
Werbot decides who may open a resource, which commands run and which folders they touch (policies.md). These rules read the command text, so they are the second line of defence and the audit trail. The first line is the permissions of the account Werbot logs in with on the host: whatever that account can do, a script or a program it runs can do too (honest limits).
One account per access level
Section titled “One account per access level”Do not let every resource log in as one shared account, and never as root.
- Create one Unix account per access level, for example
webro(reads the application and its logs) anddeploy(writes releases). - Add one resource per account on the same host:
web-rowith the loginwebro,web-deploywith the logindeploy, each with its own credential. - Bind people to the resource of the level they need. A JIT request for
web-deploythen means “write access”, and the audit log shows which level was used. - Set
PermitRootLogin noinsshd_config.
Folder permissions and ACLs
Section titled “Folder permissions and ACLs”Give each account only the folders it needs:
chown -R deploy:web /srv/appchmod -R u=rwX,g=rX,o= /srv/appsetfacl -R -m u:webro:rX /srv/app /var/log/appsetfacl -R -d -m u:webro:rX /srv/app /var/log/app # new files inherit the ACL- Keep secrets (
.env, keys) readable only by the service account, not bywebro. - An
onlyfolder rule in Werbot should match these permissions: the rule explains the intent and audits it, the permissions enforce it.
Accounts for files only
Section titled “Accounts for files only”An account that only transfers files needs no shell. In sshd_config:
Match User files ChrootDirectory /srv/files ForceCommand internal-sftp AllowTcpForwarding no X11Forwarding no PermitTTY noThe chroot folder and every folder above it must be owned by root and not writable by group or others; give the account a writable folder inside it.
Narrow sudo
Section titled “Narrow sudo”Prefer separate accounts to sudo. Where sudo is needed, allow exact commands with full paths and fixed arguments:
deploy ALL=(root) NOPASSWD: /usr/bin/systemctl restart web.service, /usr/bin/systemctl status web.service- No
ALL, no wildcards in commands or arguments. - No editors, pagers, shells, interpreters or file tools (
vi,less,bash,python,tee,cp) as allowed commands: they can run other programs or write any file. - Use
sudoeditfor editing a fixed file instead of an editor undersudo. - Keep
Defaults use_ptyand a log ofsudoon the host.
Login shell and startup files
Section titled “Login shell and startup files”The command console runs each line through the login shell of the target account, which reads its startup files (command console).
- Give the account a POSIX shell (
sh,bash,dash,zshorksh). - Make
~/.profile,~/.bashrc,~/.bash_profileand~/.zshrcowned byrootand not writable by the account, so functions and aliases there cannot change what a line runs.
Checklist
Section titled “Checklist”- One account per access level, no shared account, no
rootlogins. - Folder permissions and ACLs match the Werbot folder rules.
- File-only accounts use
ChrootDirectoryandForceCommand internal-sftp. -
sudoerslists exact commands only. - Startup files of the login shell are not writable by the account.
- Werbot rules on top: folder rules, the allowed-commands preset and a
consoleterminal rule where people work by hand.