AUTHPROGS(1)
β¨ AUTHPROGS(1) β¨ β the authprogs manual, but make it cute
okay bestie, buckle up, because authprogs is literally the bouncer for your SSH commands and she is NOT letting just anyone walk in π
πΈ NAME πΈ
authprogs β SSH command authenticator
π SYNOPSIS π
authprogs --run [options]
authprogs --install_key [options]
authprogs --dump_config [options]
authprogs --help
π¦ DESCRIPTION π¦
So. authprogs is an SSH command authenticator. It gets invoked over on an ssh server, and it decides whether the command the ssh client asked for should actually run or get rejected, based on the logic living inside the authprogs configuration file. No cap.
Passwordless SSH with ssh identities or pubkeys unlocks sooo much wonderful automation β think unattended batch jobs, slurping down backups, pushing out code. Iconic, honestly. But here's the thing, and it's giving red flag: a key, once it's trusted, is allowed by default to run anything on that system. Not just the small set of commands you actually need. So if that key gets compromised? You're at risk of a security breach π and it could be catastrophic β like, say, if the access is to the root account. Yikes.
Authprogs runs on the SSH server and compares the requested command against the authprogs configuration file/files. That's what lets it make intelligent decisions based on stuff like the command itself, the SSH key that was used, the client IP, and such. Main character energy fr fr.
And how do you turn it on? With the command= option in the authorized_keys file. Periodt.
π KEY INSTALLATION π
You can install your ssh identities/pubkeys manually, or you can let authprogs do the work for you. Dealer's choice, bestie.
π MANUAL KEY INSTALLATION π
You need to set up your ~/.ssh/authorized_keys file to force invocation of authprogs for the key or keys you wish to protect.
A line of an unrestricted authorized_key entry might look like this:
ssh-rsa AAAAxxxxx...xxxxx user@example.com
When you set up this key to use authprogs, you add a command= option to the very beginning of that line, pointing to the location where authprogs lives. So, for example, if authprogs is in /usr/bin/authprogs, you'd use this:
command="/usr/bin/authprogs --run" ssh-rsa AAAAxxxxx...xxxxx user@example.com
You must include --run to let authprogs know it's running in SSH command mode. Don't skip it, I'm begging π
Authprogs has other command line options you may wish to include as well, for example:
command="/usr/bin/authprogs --keyname=backups --run" ssh-rsa AAAA...xxxxx user@example.com
Lastly, if you wish, ssh offers a number of other helpful restrictions you may wish to include that are separate from authprogs. These can be appended right after (or before) the command="" section if you wish.
command="/usr/bin/authprogs --run",no-port-forwarding,no-pty ssh-rsa AAAA...xxxxx user@example.com
See the sshd(8) man page for more information about allowed authorized_keys configuration options. iykyk π
π AUTOMATED KEY INSTALLATION π
Authprogs is capable of adding your key to your authorized_keys file (~/.ssh/authorized_keys by default) programmatically. It also disables ssh port forwarding by default for this key β which is a sensible default for most batch jobs, ngl.
β οΈ authprogs will refuse to install a key that is already present in the authorized_keys file.
For example, the following:
authprogs --install_key /path/to/backups_key.pub --keyname=backups
would cause the following line to be added to your ~/.ssh/authorized_keys file:
command="/usr/bin/authprogs --keyname backups --run",no-port-forwarding ssh-rsa AAAA...xxxxx user@example.com
π RUN MODE OPTIONS π
Authprogs can run in several modes, depending on which of these command line switches you provide.
--runβ Act in run mode, as from anauthorized_keysfile.--install_keyfilename β Install the key contained in the named file into yourauthorized_keysfile.--dump_configβ Dump the configuration in a python-style view. Helpful only for debugging. (lowkey just a peek behind the curtain π)--silentβ Do not inform the user if their command has been rejected. Default is to let them know it was rejected to prevent confusion.--helpβ Show help information
π OTHER OPTIONS π
The following options may apply to multiple run modes, as appropriate.
--keynamekey_name β This option Β΄namesΒ΄ the key, for help in crafting your rules. Since an account may have multiple keys allowed, this helps us differentiate which one was used so we can make sensible choices.
In run mode, this specifies which name is used when matching in the configuration, e.g.
command="/usr/bin/authprogs --keyname backups --run" ...
In key installation mode, this adds the --keyname option to the authorized_keys entry.
π¨ key_name may contain no whitespace.
--configfileβ Specifies the authprogs configuration file to read. Defaults to~/.ssh/authprogs.yaml.
In key installation mode, this adds the --configfile option to the authorized_keys entry.
--configdirβ Specifies the authprogs configuration, in which multiple configuration files can be found. Defaults to~/.ssh/authprogs.dif present.
Files in the configuration directory are read as rules in filename order. See CONFIGURATION for more info.
π LIMITATIONS π
Commands are executed via fork/exec, and are not processed through the shell. Which means... no. You cannot have multiple commands separated by semicolons, pipelines, redirections, backticks, shell builtins, wildcards, variables, etc. She said what she said π
Also β and this one's a little heartbreaking β you cannot have spaces in any arguments your command runs. Why? Because the SSH server takes the command that was specified by the client and squashes it into the SSH_ORIGINAL_COMMAND variable. By doing this it makes it impossible for us to know what spaces in SSH_ORIGINAL_COMMAND were between arguments and which were part of arguments. The audacity, honestly π
Here are some commands that would not work through authprogs:
ssh host "rm /tmp/foo; touch /tmp/success"ssh host "rm /tmp/*.html"ssh host "cut -d: -f 1 /etc/passwd > /tmp/users"ssh host "touch Β΄/tmp/file with spacesΒ΄"ssh host "for file in /tmp/*.html; do w3m -dump $file > $file.txt; done"
You can work around these limitations by writing a shell script that does what you need and calling that from authprogs, rather than attempting to run complicated command lines via ssh directly. Slay, problem solved π«Ά
π§ CONFIGURATION FILES π§
authprogs rules are maintained in one or more configuration files in YAML format.
The rules allow you to decide whether the clientΒ΄s command should be run based on criteria such as the command itself, the client IP address, and ssh key in use.
Rules can be read from a single file (~/.ssh/authprogs.yaml by default) or by putting files in a configuration directory (~/.ssh/authprogs.d). The configuration directory method is most useful when you want to be able to easily add or remove rules without manually editing a single configuration file β such as when installing rules via your configuration tool of choice. Chef's kiss π
All the authprogs configuration files are concatenated together into one large yaml document which is then processed. The files are concatenated in the following order:
~/.ssh/authprogs.yaml, if present- files in
~/.ssh/authprogs.d/directory, in asciibetical order
Dotfiles contained in a configuration directory are ignored. The configuration directory is not recursed; only those files directly contained are processed.
Each rule in the configuration file/files is tested in order and once a match is found, processing stops and the command is run.
Rules are made of rule selection options (e.g. client IP address) and subrules (e.g. a list of allowed commands). All pieces must match for the command to be run.
The general format of a rule is as follows:
# First rule
-
# Selection options
#
# All must match or we stop processing this rule.
selection_option_1: value
selection_option_2: value
# The allow block, aka subrules
#
# This lets us group a bunch of possible commands
# into one rule. Otherwise weΒ΄d need a bunch of
# rules where you repeat selection options.
allow:
-
rule_type: value
rule_param_1: value
rule_param_2: value
-
rule_type: value2
rule_param_1: value
rule_param_2: value
# Next rule
-
selection_option_3: value
...
Some of the keys take single arguments, while others may take lists. See the definition of each to understand the values it accepts.
π RULE SELECTION OPTIONS π
These configuration options apply to the entire rule, and help you limit under what conditions the rule matches.
from: This is a single value or list of values that define what SSH client IP addresses are allowed to match this rule. The client IP address is gleaned by environment variables set by the SSH server. Anyfromvalue may be an IP address or a CIDR network.
Examples:
-
from: 192.168.1.5
...
-
from: [192.168.0.1, 10.0.0.3]
...
-
from:
- 192.168.0.0/24
- 10.10.0.3
...
keynames: This is a single value or list of values that define which SSH pubkeys are allowed to match this rule. The keyname is specified by the--keyname fooparameter in the authprogs command line in the entry inauthorized_keys.
Examples:
-
keynames: backups
...
-
keynames: [repo_push, repo_pull]
...
-
keynames:
- repo_push
- repo_pull
...
π ALLOW SUBRULE SECTION π
The allow section of a rule is a single subrule or list of subrules.
Subrules can be simple β for example the explicit command match β or be more program-aware, such as scp support. You specify which kind of subrule you want with the rule_type option:
-
allow:
-
rule_type: command
command: /bin/touch /tmp/timestamp
-
command: /bin/rm /tmp/bar
-
rule_type: scp
allow_upload: true
...
See the separate subrules sections below for how to craft each type. π
π COMMAND SUBRULES π
okay so this whole section is your bestie if rule_type is set to command β or if you didn't set rule_type at all, in which case this is just the default vibe. no notes. π
here's the tea: whatever command the client asks for gets compared against the command sitting in the rule. spaces get squashed together (yes, squashed, like a lil bug π). if they match? the command runs. slay.
but listen β and this is the part that lowkey ruins people β the command has to be exactly the same. authprogs has zero clue which arguments a command supports, so it genuinely cannot tell that ls -la and ls -a -l and ls -al and ls -l -a are all, like, the same thing. it's giving literal. so if you need to accept variants, you just list multiple commands. no cap.
simplest config ever, look at her:
-
allow:
command: /bin/true
or you can hand it a whole list of commands, main character energy:
-
allow:
- command: /bin/true
- command: /bin/false
and then there's a lil pile of optional settings that tweak how the matching goes down. obsessed. π
allow_trailing_args: trueβ this lets you write a partial command and have it match as long as what the client asked for is the same or longer. perfect for when you cannot be bothered listing every single variant of a command a client might wanna run. β¨
examples:
-
allow:
-
command: /bin/echo
allow_trailing_args: true
-
command: /bin/ls
allow_trailing_args: true
-
command: /bin/rm -i
allow_trailing_args: true
pcre_match: trueβ compares the command using pcre regular expressions instead of doing an explicit match character by character. and heads up: the regex is not anchored at the beginning or the end of the string, so if you want it anchored, that is 100% on you to do. π
β οΈ caution: never underestimate the sneakiness of an adversary who may find a way to match your regex and still do something nasty. they will. they always do. π
examples:
-
allow:
-
# Touch the foo file, allowing any
# optional command line params
# before the filename
command: ^touch\\s+(-\\S+\\s+)*foo$
pcre_match: true
-
# attempt to allow rm of files in /var/tmp
# but actually would fail to catch malicious
# commands e.g. /var/tmp/../../etc/passwd
#
# As I said, be careful with pcre matching!!!
command: ^/bin/rm\\s+(-\\S+\\s+)*/var/tmp/\\S*$
pcre_match: true
π RSYNC SUBRULES π
authprogs has special support for rsync file transfer, and it's genuinely so cute of her. you do not have to use it β you could totally just use a simple command subrule and match explicit rsync commands β but an rsync-specific subrule gives you way more flexibility. π
rsync support is in beta, so please raise any bugs found. supporting the full set of rsync command line options is a moving target. she's trying her best, okay?? π
to get into rsync mode, use rule_type: rsync. periodt.
the rsync options are, in order, as follows. buckle up bestie, there's a lot: π«Ά
rule_type: rsyncβ this is the lil flag that says "yes this is an rsync subrule".allow_upload: false|trueβ allow files to be uploaded to the ssh server. defaults tofalse.allow_download: false|trueβ allow files to be downloaded from the ssh server. defaults tofalse.allow_archive: false|trueβ allow file archive, i.e. the options that get set when you use-aor--archive. this exists to simplify authprogs config files. specifying this and negating one of the associated options (likeallow_recursive: false) is considered an error. defaults tofalse.pathsβ a list of explicit files/directories that are allowed to match. files specified by the client get resolved viarealpathto avoid any symlink trickery, so the members ofpathshave to be the real paths.
β οΈ WARNING: specifying a directory inpathswould allow rsync to act on any files therein at potentially infinite depth, e.g. whenallow_recursiveis set, or when the client uses--files-from. if you want to restrict to specific files, you must name them explicitly. no shortcuts, babe. π
see RSYNC SYMLINK SUPPORT for potential limitations to paths.
path_startswithβ a list of pathname prefixes that are allowed to match. files specified by the client get resolved viarealpath, and if they start with the name you provided, they're allowed. β¨
this is a simple prefix match. so like, if you had
path_startswith: [ /tmp ]
then it would match all of the following
/tmp
/tmp/
/tmpfiles # may not be what you meant!
/tmp/foo.txt
/tmp/dir1/dir2/bar.txt
if you want it to match only a directory (and any infinite subdirectories), be sure to include a trailing slash, e.g. /tmp/
see RSYNC SYMLINK SUPPORT for potential limitations to paths.
allow_acls: false|trueβ allow syncing of file ACLs. (--acls). defaults tofalse.allow_checksum: true|falseβ allow checksum method for identifying files that need syncing. (-c/--checksum) defaults totrue.allow_debug: true|falseβ allow fine-grained debug verbosity. (--debug FLAGS). no support for sanity checking the debug flags that are specified. defaults totrue.allow_delete: false|trueβ allow any of the delete options. (--del--delete--delete-after--delete-before--delete-delay--delete-during--delete-excluded--delete-missing-args). defaults tofalse.allow_devices: false|trueβ allow syncing of device files. (--devices). defaults tofalse.allow_group: false|trueβ allow group change. (-g--group). defaults tofalse.allow_info: true|falseβ allow fine-grained info verbosity. (-info FLAGS). no support for sanity checking the info flags that are specified. defaults totrue.allow_links: false|trueβ allow copying symlinks as symlinks. (-l--links). defaults tofalse.allow_group: false|trueβ allow ownership change. (-o--owner). defaults tofalse.allow_perms: false|trueβ allow perms change. (-p--perms). defaults tofalse.allow_recursive: false|trueβ allow recursive sync. (-r--recursive). defaults tofalse.allow_specials: false|trueβ allow syncing of special files, e.g. fifos. (--specials). defaults tofalse.allow_times: true|falseβ allow setting synced file times. (-t--times). defaults totrue.allow_verbose: true|false|#β allow verbose output. (-v--verbose). rsync allows multiple-voptions, so this one acceptstrue(allow any verbosity),false(deny any verbosity), or a number which is the maximum number of-voptions that are allowed β e.g.2would allow-vor-vvbut not-vvv. defaults totrue.
π RSYNC COMMAND LINE OPTIONS π
not all rsync options are currently implemented in authprogs. she's working on it. π§
if an option is listed as "not implemented", then there are two possibilities for how authprogs will behave:
- if the option is not actually sent on the remote command line, then
authprogsis blissfully unaware and the command will succeed. many options are actually client-side only. we have not thoroughly investigated every single option yet. π - if the option is sent on the remote command line, then
authprogswill fail.
here's the list of rsync options and their current authprogs support status:
rsync client arg authprogs support
---------------- -----------------
...and we're BACK in the option list bestie, no skipping, no summarising, every single one of these is getting its moment π
--appendβ<not implemented>π--append-verifyβ<not implemented>π--backup-dirβ<not implemented>π--bwlimitβ<not implemented>π--checksum-seedβ<not implemented>π--chownβ converted to--usermapand--groupmapβ¨--compare-destβ<not implemented>π--compress-levelβ<not implemented>π--contimeoutβ<not implemented>π--copy-destβ<not implemented>π--copy-unsafe-linksβ<not implemented>π--debugβ maps toallow_debugβ--delβ maps toallow_deleteβ--delay-updatesβ<not implemented>π--deleteβ maps toallow_deleteβ--delete-afterβ maps toallow_deleteβ--delete-beforeβ maps toallow_deleteβ--delete-delayβ maps toallow_deleteβ--delete-duringβ maps toallow_deleteβ--delete-excludedβ maps toallow_deleteβ--delete-missing-argsβ maps toallow_deleteβ--devicesβ maps toallow_devicesβ--existingβ<not implemented>π--fake-superβ<not implemented>π--files-fromβ<not implemented>π--forceβ<not implemented>π--groupmapβ<not implemented>π--iconvβ<not implemented>π--ignore-errorsβ<not implemented>π--ignore-existingβ<not implemented>π--ignore-missing-argsβ<not implemented>π--infoβ maps toallow_infoβ--inplaceβ<not implemented>π--link-destβ<not implemented>π--list-onlyβ<not implemented>π--log-fileβ<not implemented>π--log-file-formatβ<not implemented>π--max-deleteβ<not implemented>π--max-sizeβ<not implemented>π--min-sizeβ<not implemented>π--new-compressβ<not implemented>π--no-XXXXXβ<not implemented>(that's negating options, like--no-r) π--numeric-idsβ<not implemented>π--only-write-batchβ<not implemented>π--outbufβ<not implemented>π--partialβ<not implemented>π--partial-dirβ<not implemented>π--preallocateβ<not implemented>π--protocolβ<not implemented>π--read-batchβ<not implemented>π--remove-sent-filesβ<not implemented># deprecated version ofremove-source-filesπ--remove-source-filesβ<not implemented>π--safe-linksβ<not implemented>π--size-onlyβ<not implemented>π--skip-compressβ<not implemented>π--specialsβ maps toallow_specialsβ--statsβ<not implemented>π--stop-atβ<not implemented>π--suffixβ<not implemented>π--superβ<not implemented>π--time-limitβ<not implemented>π--timeoutβ<not implemented>π--usermapβ<not implemented>π--write-batchβ<not implemented>π-0,--from0β<not implemented>π-@,--modify-windowβ<not implemented>π-A,--aclsβ maps toallow_aclsβ-B,--block-sizeβ<not implemented>π-C,--cvs-excludeβ<not implemented>π-Dβ maps toallow_devicesandallow_specialsβ β-E,--executabilityβ<not implemented>π-H,--hard-linksβ<not implemented>π-I,--ignore-timesβ<not implemented>π-J,--omit-link-timesβ<not implemented>π-K,--keep-dirlinksβ<not implemented>π-L,--copy-linksβ<not implemented>π-O,--omit-dir-timesβ<not implemented>π-Pβ Same as--partial --progressβ¨-R,--relativeβ<not implemented>π-S,--sparseβ<not implemented>π-T,--temp-dirβ<not implemented>π-W,--whole-fileβ<not implemented>π-X,--xattrsβ<not implemented>π-a,--archiveβ Same as-rlptgoD; go see those options π--progressβ<not implemented>π-b,--backupβ<not implemented>π-c,--checksumβ maps toallow_checksumβ-d,--dirsβ<not implemented>π-f,--filterβ<not implemented>π-g,--groupβ maps toallow_groupβ-i,--itemize-changesβ<not implemented>π-k,--copy-dirlinksβ<not implemented>π-l,--linksβ maps toallow_linksβ-m,--prune-empty-dirsβ<not implemented>π-n,--dry-runβ<not implemented>π-o,--ownerβ maps toallow_ownerβ-p,--permsβ maps toallow_permsβ-r,--recursiveβ maps toallow_recursiveβ-s,--protect-argsβ<not implemented>π-t,--timesβ maps toallow_timesβ-u,--updateβ<not implemented>π-v,--verboseβ maps toallow_verboseβ-x,--one-file-systemβ<not implemented>π-y,--fuzzyβ<not implemented>π-z,--compressβ<not implemented>π--checksum-choice=STRβ<not implemented>π--exclude-fromβ<not implemented>π--excludeβ<not implemented>π--include-fromβ<not implemented>π--includeβ<not implemented>π--rsync-pathβ<not implemented>π--out-formatβ<not implemented>π
<h2>β¨ server-side only options that ARE supported β¨</h2>
These ones only ever show up on the server, and they're supported, so:
-e,--rsh=COMMANDβ the value is ignored (it's just there to indicate protocol feature support) π«Ά--senderβ when it's present, that means download from server; when it's absent, that means upload to server π--serverβ always present on server π
<h2>π client options that don't count π</h2>
Okay so these rsync client options only matter for daemon mode (aka an rsync daemon listening on TCP directly, no SSH involved), or they just never end up on the server command line at all. Which means they're not taken into consideration when we're figuring out if a command is allowed or not. So don't stress about them π
--addressβ client-only option--chmodβ client-only option (permissions get indicated via the rsync protocol, not via command line flags π« )--blocking-ioβ client-only option--daemonβ daemon-only option--msgs2stderrβ client-only option--munge-linksβ client-only option--no-motdβ client-only option--noatimeβ client-only option--password-fileβ daemon-only option--portβ client-only option--sockoptsβ daemon-only option--versionβ client-only option-4,--ipv4β client-only option-6,--ipv6β client-only option-8,--8-bit-outputβ client-only option-Fβ client-only option (peep--filter)-M,--remote-option=OPTIONβ client-only option-h,--human-readableβ client-only option-q,--quietβ client-only option
π RSYNC BINARY PATH π
So like, rsync has to live at an official path, because otherwise a user's environment could just... pick one of their own little programs instead of the real one. Not on our watch bestie π The official paths are:
/usr/bin/rsync/usr/local/bin/rsync
If a user hits us with --rsync-path pointing somewhere else, or they've got an rsync sitting earlier in their $PATH? Denied. Periodt. π«
π¦ RSYNC SYMLINK SUPPORT π¦
rsync has multiple ways of handling symlinks, and which one you get depends on the command line parameters and on which component(s) of a path happen to be symlinks. It's giving choose-your-own-adventure π
If you're usingpathsorpaths_startswithto limit what files may be uploaded/downloaded, then it is your responsibility to make sure symlink games aren't being used to exceed the restrictions you wanted. no cap.
Example time, bestie. Say the file /tmp/me.txt is a symlink to /home/wbagg/me.txt, and you had:
- rule_type: rsync
allow_upload: true
paths:
- /tmp/me.txt
then if the user ran
rsync /some/local/file remote:/tmp/me.txt
then instead of updating the file at /home/wbagg.me.txt, the symlink at /tmp/me.txt would be replaced with a normal file. Yeah. π
A future update to authprogs may attempt to handle symlinks by calling os.path.realpath prior to doing comparisons. π
π¨ RSYNC PATHNAME GOTCHA π¨
Okay so picture this: you wanna restrict uploads to just the file /tmp/foo.txt, so you write yourself this rsync subrule:
- rule_type: rsync
allow_upload: true
paths:
- /tmp/foo.txt
From an end-user's perspective, both of these commands would seem allowed from the client machine, because both would create a file on the remote named /tmp/foo.txt:
$ rsync foo.txt remote:/tmp/foo.txt # provide full target filename
$ rsync foo.txt remote:/tmp # imply source name for target
But plot twist π only the first one actually works! Why? Because authprogs on the server side sees literally just /tmp in the second case. That's it. That's the whole gotcha.
So if you wanted to restrict uploads to just the file /tmp/foo.txt, then on the client side you must run that first (explicit filename) rsync command. No shortcuts, bestie π
π RSYNC SUBRULE KNOWN AND POSSIBLE BUGS π
- If uploading to a file that does not yet exist when you've set
paths, this will fail. Adding a newallow_createoption is the most likely solution here, but it's not yet implemented. π - No investigation of the rsync options
--include/--exclude/--files-fromhas yet been performed β this may affect path matching security. π«£ - Though we do expand file globs and check each individual path that is returned, we do not explicitly use these resolved files when calling rsync. (Reason: it's possible we exceed the allowed size of a command line with globs that return many files.) As such, if rsync's glob and
shutils.globhave different behaviour, we may get false positives or negatives. π - when
allow_downloadis off, the client should NOT be able to grab file contents. but bestie, plot twist: rsync ships checksums as part of its protocol, so it's possible that info about server file contents could be gleaned by comparing those checksums to possible content checksums when doing uploads. π so like, it's not a full leak of the file, but it's not nothing either. noted, on the record, moving on.
πΈ SCP SUBRULES πΈ
authprogs has special support for scp file transfer, and it's genuinely so nice of it. you are not required to use this β you could just use a plain command subrule to match explicit scp commands β but an scp-specific subrule gives you so much more flexibility. β¨
to flip on scp mode, use rule_type: scp.
the scp options are, in order, no skipping: π
rule_type: scpβ says hey, this one is an scp subrule. that's it. that's the vibe. πallow_upload: false|trueβ let files be uploaded to the ssh server. defaults tofalse.allow_download: false|trueβ let files be downloaded from the ssh server. defaults tofalse.allow_recursive: false|trueβ allow recursive (-r) file up/download. defaults tofalse.allow_recursion: false|trueβ deprecated version ofallow_recursive. will be removed in 1.0 release. ngl, retire her. πallow_permissions: true|falseβ let scp get/set the permissions of the file/files being transferred. defaults tofalse.pathsβ lets you say exactly which file or files are allowed to be transferred. if you don't specify this, then transfers are not restricted based on filename. (iykyk β that's a big deal.) π
examples, because seeing it is believing:
-
allow:
- rule_type: scp
allow_download: true
paths:
- /etc/group
- /etc/passwd
- rule_type: scp
allow_upload: true
paths: [/tmp/file1, /tmp/file2]
π₯ EXAMPLES π₯
here's a sample configuration file with multiple rules, going from simple to more complex. she ate, fr fr.
note that this config can be spread around between the ~/.ssh/authprogs.yaml and ~/.ssh/authprogs.d directory. so like, organize her however you want. π§
# All files should start with an initial solo dash -
# remember, weΒ΄re being concatenated with all other
# files!
# Simple commands, no IP restrictions.
-
allow:
- command: /bin/tar czvf /backups/www.tgz /var/www/
- command: /usr/bin/touch /var/www/.backups.complete
# Similar, but with IP restrictions
-
from: [192.168.0.10, 192.168.0.15, 172.16.3.3]
allow:
- command: git --git-dir=/var/repos/foo/.git pull
- command: sudo /etc/init.d/apache2 restart
# Some more complicated subrules
-
# All of these Β΄allowsΒ΄ have the same Β΄fromΒ΄ restrictions
from:
- 10.1.1.20
- 10.1.1.21
- 10.1.1.22
- 10.1.1.23
allow:
# Allow unrestricted ls
- command: /bin/ls
allow_trailing_args: true
# Allow any Β΄service apache2 (start|stop)Β΄ commands via sudo
- command: sudo service apache2
allow_trailing_args:true
# How about a regex? Allow wget of any https url, outputting
# to /tmp/latest
- command: ^/usr/bin/wget\\s+https://\\S+\\s+-O\\s+/tmp/latest$
pcre_match: true
# Allow some specific file uploads
- rule_type: scp
allow_upload: true
paths:
- /srv/backups/host1.tgz
- /srv/backups/host2.tgz
- /srv/backups/host3.tgz
# Allow rsync to upload everything, deny any download
- rule_type: rsync
allow_upload: true
# Allow rsync to recursively sync /tmp/foo/ to the server
# in archive mode (-a, or any subset of -logptrD)
# but do not allow download
- rule_type: rsync
allow_upload: true
allow_recursive: true
allow_archive: true
paths:
- /tmp/foo
# Allow rsync to write some specific files and any individual
# files under /data/lhc/ directory, such as /data/lhc/foo
# or /data/lhc/subdir/foo.
#
# Disallow download (explicitly listed) or recursive
# upload (default false).
- rule_type: rsync
allow_upload: true
allow_download: false
paths:
- /srv/htdocs/index.html
- /srv/htdocs/status.html
path_startswith:
- /data/lhc/
π«Ά TROUBLESHOOTING π«Ά
--dump_config is your friend. your actual bestie. β¨ if your yaml config isn't parsing, consider --dump_config --logfile=/dev/tty for more debug output to find the error. do it, thank me later. π
π FILES π
~/.ssh/authorized_keysβ the default place your key should be installed and configured to call authprogs. the actual location can differ if your administrator has changed it. (ask your admin bestie.)~/.ssh/authprogs.yamlβ default authprogs configuration file. override with--configfile.~/.ssh/authprogs.dβ default authprogs configuration directory. override with--configdir.
π ENVIRONMENT π
authprogs uses the following environment variables that are set by the sshd(8) binary:
SSH_CONNECTIONβ used to determine the client IP address.SSH_CLIENTβ used to determine the client IP address ifSSH_CONNECTIONwas not present.SSH_ORIGINAL_COMMANDβ the (squashed) original SSH command that was issued by the client.
authprogs sets the following environment variables for use by the authenticated process:
AUTHPROGS_KEYNAMEβ the value of the--keynamecommand line. will be set to an empty string if no--keynamewas set.
β EXIT STATUS β
on unexpected error, or when rejecting the command, authprogs will exit 126. periodt.
if the command was accepted, then it returns the exit code of the command that was run. cute, right?
heads up bestie: if you're invoking ssh via another tool, that program may provide a different exit status and give you a misleading error message when authprogs returns a failure. for example, rsync will exit 12 and assume a "protocol problem" rather than a rejection on the server side. π so don't let the wrong tool gaslight you about what happened.
π LOGGING AND DEBUGGING π
if a --logfile is specified, then it will be opened in append mode, and a line about each command that is attempted to be run will be written to it. the line itself is in the form of a python dictionary. so readable, so structured, we love her. π
if authprogs is run with --debug, then this logfile will get increased debugging information, including the configuration, rule matching status as they are checked, etc. everything. the whole tea. β
π¦ HISTORY π¦
a perl version of authprogs was originally published at https://www.hackinglinuxexposed.com/articles/20030115.html in 2003. this is a complete rewrite in python, with a more extensible configuration, and avoiding some of the limitations of the former. glow-up of the century, no cap. π
π SEE ALSO π
πΈ AUTHOR πΈ
Bri Hatch mailto:bri@ifokr.org
okay that's the whole page bestie, you made it to the end!! π this was AUTHPROGS(1), dated March 2021 β go forth and lock down your ssh, you're the main character now. mwah. πβ¨π
π¦ where this page comes from
- debian bookworm: authprogs 0.7.5-1 Β· GPL-2.0-only
- debian trixie: authprogs 0.7.5-2 Β· GPL-2.0-only
- ubuntu jammy: authprogs 0.7.5-1 Β· GPL-2.0-only
- ubuntu noble: authprogs 0.7.5-2 Β· GPL-2.0-only
- ubuntu resolute: authprogs 0.7.5-2build1 Β· GPL-2.0-only
- ubuntu stonking: authprogs 0.7.5-2build1 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms