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 an authorized_keys file.
  • --install_key filename β€” Install the key contained in the named file into your authorized_keys file.
  • --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.

  • --keyname key_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.d if 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:

  1. ~/.ssh/authprogs.yaml, if present
  2. 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. Any from value 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 foo parameter in the authprogs command line in the entry in authorized_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 to false.
  • allow_download: false|true β€” allow files to be downloaded from the ssh server. defaults to false.
  • allow_archive: false|true β€” allow file archive, i.e. the options that get set when you use -a or --archive. this exists to simplify authprogs config files. specifying this and negating one of the associated options (like allow_recursive: false) is considered an error. defaults to false.
  • paths β€” a list of explicit files/directories that are allowed to match. files specified by the client get resolved via realpath to avoid any symlink trickery, so the members of paths have to be the real paths.
⚠️ WARNING: specifying a directory in paths would allow rsync to act on any files therein at potentially infinite depth, e.g. when allow_recursive is 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 via realpath, 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 to false.
  • allow_checksum: true|false β€” allow checksum method for identifying files that need syncing. (-c / --checksum) defaults to true.
  • allow_debug: true|false β€” allow fine-grained debug verbosity. (--debug FLAGS). no support for sanity checking the debug flags that are specified. defaults to true.
  • 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 to false.
  • allow_devices: false|true β€” allow syncing of device files. (--devices). defaults to false.
  • allow_group: false|true β€” allow group change. (-g --group). defaults to false.
  • allow_info: true|false β€” allow fine-grained info verbosity. (-info FLAGS). no support for sanity checking the info flags that are specified. defaults to true.
  • allow_links: false|true β€” allow copying symlinks as symlinks. (-l --links). defaults to false.
  • allow_group: false|true β€” allow ownership change. (-o --owner). defaults to false.
  • allow_perms: false|true β€” allow perms change. (-p --perms). defaults to false.
  • allow_recursive: false|true β€” allow recursive sync. (-r --recursive). defaults to false.
  • allow_specials: false|true β€” allow syncing of special files, e.g. fifos. (--specials). defaults to false.
  • allow_times: true|false β€” allow setting synced file times. (-t --times). defaults to true.
  • allow_verbose: true|false|# β€” allow verbose output. (-v --verbose). rsync allows multiple -v options, so this one accepts true (allow any verbosity), false (deny any verbosity), or a number which is the maximum number of -v options that are allowed β€” e.g. 2 would allow -v or -vv but not -vvv. defaults to true.

πŸ“‹ 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 authprogs is 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 authprogs will 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 --usermap and --groupmap ✨
  • --compare-dest β€” <not implemented> πŸ™ˆ
  • --compress-level β€” <not implemented> πŸ™ˆ
  • --contimeout β€” <not implemented> πŸ™ˆ
  • --copy-dest β€” <not implemented> πŸ™ˆ
  • --copy-unsafe-links β€” <not implemented> πŸ™ˆ
  • --debug β€” maps to allow_debug βœ…
  • --del β€” maps to allow_delete βœ…
  • --delay-updates β€” <not implemented> πŸ™ˆ
  • --delete β€” maps to allow_delete βœ…
  • --delete-after β€” maps to allow_delete βœ…
  • --delete-before β€” maps to allow_delete βœ…
  • --delete-delay β€” maps to allow_delete βœ…
  • --delete-during β€” maps to allow_delete βœ…
  • --delete-excluded β€” maps to allow_delete βœ…
  • --delete-missing-args β€” maps to allow_delete βœ…
  • --devices β€” maps to allow_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 to allow_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 of remove-source-files πŸ’€
  • --remove-source-files β€” <not implemented> πŸ™ˆ
  • --safe-links β€” <not implemented> πŸ™ˆ
  • --size-only β€” <not implemented> πŸ™ˆ
  • --skip-compress β€” <not implemented> πŸ™ˆ
  • --specials β€” maps to allow_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 to allow_acls βœ…
  • -B, --block-size β€” <not implemented> πŸ™ˆ
  • -C, --cvs-exclude β€” <not implemented> πŸ™ˆ
  • -D β€” maps to allow_devices and allow_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 to allow_checksum βœ…
  • -d, --dirs β€” <not implemented> πŸ™ˆ
  • -f, --filter β€” <not implemented> πŸ™ˆ
  • -g, --group β€” maps to allow_group βœ…
  • -i, --itemize-changes β€” <not implemented> πŸ™ˆ
  • -k, --copy-dirlinks β€” <not implemented> πŸ™ˆ
  • -l, --links β€” maps to allow_links βœ…
  • -m, --prune-empty-dirs β€” <not implemented> πŸ™ˆ
  • -n, --dry-run β€” <not implemented> πŸ™ˆ
  • -o, --owner β€” maps to allow_owner βœ…
  • -p, --perms β€” maps to allow_perms βœ…
  • -r, --recursive β€” maps to allow_recursive βœ…
  • -s, --protect-args β€” <not implemented> πŸ™ˆ
  • -t, --times β€” maps to allow_times βœ…
  • -u, --update β€” <not implemented> πŸ™ˆ
  • -v, --verbose β€” maps to allow_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 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 using paths or paths_startswith to 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 new allow_create option is the most likely solution here, but it's not yet implemented. 😭
  • No investigation of the rsync options --include / --exclude / --files-from has 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.glob have different behaviour, we may get false positives or negatives. πŸ™ƒ
  • when allow_download is 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 to false.
  • allow_download: false|true β€” let files be downloaded from the ssh server. defaults to false.
  • allow_recursive: false|true β€” allow recursive (-r) file up/download. defaults to false.
  • allow_recursion: false|true β€” deprecated version of allow_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 to false.
  • 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 if SSH_CONNECTION was 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 --keyname command line. will be set to an empty string if no --keyname was 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 πŸ‘‘

ssh(1), sshd(8), scp(1).


🌸 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. πŸ’–βœ¨πŸŽ€