RFC cifs.upcall helper script enabling complex key description matching
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest12 patches 0 repliesNew
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/12 | contrib: add directory and documentation for cifs-upcall-helpercontrib/ | +138 | 0 replies | |
| 2/12 | upcall-helper: add a sample config filecontrib/ | +66 | 0 replies | |
| 3/12 | contrib: add cifs-upcall-helper scriptcontrib/ | +74 | 0 replies | |
| 4/12 | upcall-helper: obtain and parse key description, assigning fields to key_varscontrib/ | +49 | 0 replies | |
| 5/12 | upcall-helper: open and read each line of the helper's config filecontrib/ | +56 | 0 replies | |
| 6/12 | upcall-helper: set upcall_opts on a match, or if 'default' is givencontrib/ | +34 | 0 replies | |
| 7/12 | upcall-helper: set log level from config filecontrib/ | +18 | 0 replies | |
| 8/12 | upcall-helper: build command-line and set environment variables for cifs.upcallcontrib/ | +17 | 0 replies | |
| 9/12 | upcall-helper: replace macros in upcall argument stringscontrib/ | +30 | 0 replies | |
| 10/12 | upcall-helper: add string comparisoncontrib/ | +28 | 0 replies | |
| 11/12 | upcall-helper: add uid comparisoncontrib/ | +14 | 0 replies | |
| 12/12 | upcall-helper: add IP address comparisonscontrib/ | +84 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [cifs-utils RFC PATCH 00/12] cifs.upcall helper script enabling complex key description matching
Background:
The request-key mechanism, used to execute upcalls, uses string matching of lines in the conf file to determine which program it should run to instantiate a key. This can usually be done based solely on the requested key type.
It also allows further selection of the executable and/or program arguments, based on string matches of the description and callout information fields of the upcall with lines of the request-key conf files. Each field (key type, key description, callout information) can also contain a single '*' wildcard to be used when doing the string matches, and the string must fully match in order to be selected.
When the kernel performs the upcall during a cifs mount in which kerberos is involved, the 'cifs.spnego' key type is requested. The key's description contains a number of key=value pairs, providing information such as the server's name and IP address, the username of the mount, and uid under which to search for the kerberos credentials.
An example key description:
ver=0x2;host=smbserver;ip4=192.168.122.11;sec=krb5;uid=0x0;creduid=0x0;user=user1;pid=0xbaf7d
request-key will attempt to match the key's description with the string in the description field of the config file, and executes cifs.upcall with the given arguments. However, the default configuration simply calls cifs.upcall for all 'cifs.spnego' key types, regardless of the key's description, and no additional arguments (other than the key id) are given to the upcall:
create cifs.spnego * * /usr/sbin/cifs.upcall %k
Specifying the string more explicitly to match the key's description more fully allows differentiation between servers, username, etc., and cifs.upcall will then execute with arguments specific to that server or user, such as (with catch-all for fallback to the default cifs.upcall execution):
create cifs.spnego ver=0x2;host=smbserver;ip4=192.168.122.11;sec=krb5;uid=0x0;creduid=0x501;user=user1;* * /usr/sbin/cifs.upcall -K /etc/smbserver_user1.keytab %k
create cifs.spnego * * /usr/sbin/cifs.upcall %k
Unfortunately, the key's description includes the pid of the requesting process, so in order to match the description string in the config file with the key's description, the '*' wildcard must be used to cover that portion of the description string. As a result, each description string in the config file must fully specify all of the other fields. This includes cases where a server name may resolve to multiple IP addresses; each combination must be individually specified. For example:
create cifs.spnego ver=0x2;host=smbserver;ip4=192.168.122.11;sec=krb5;uid=0x0;creduid=0x501;user=user1;* * /usr/sbin/cifs.upcall -K /etc/smbserver_user1.keytab %k
create cifs.spnego ver=0x2;host=smbserver;ip4=192.168.122.12;sec=krb5;uid=0x0;creduid=0x501;user=user1;* * /usr/sbin/cifs.upcall -K /etc/smbserver_user1.keytab %k
create cifs.spnego ver=0x2;host=smbserver;ip4=192.168.122.13;sec=krb5;uid=0x0;creduid=0x501;user=user1;* * /usr/sbin/cifs.upcall -K /etc/smbserver_user1.keytab %kThis is inflexible, and can quickly become unmanageable; the addition or change of an IP address to a server hostname would require updating the /etc/request-key.d/cifs.spnego.conf file on all clients, and adding a second user & keytab would require replicating the lines, with just minor variations:
create cifs.spnego ver=0x2;host=smbserver;ip4=192.168.122.11;sec=krb5;uid=0x0;creduid=0x502;user=user2* * /usr/sbin/cifs.upcall -K /etc/smbserver_user2.keytab %k
create cifs.spnego ver=0x2;host=smbserver;ip4=192.168.122.12;sec=krb5;uid=0x0;creduid=0x502;user=user2* * /usr/sbin/cifs.upcall -K /etc/smbserver_user2.keytab %k
create cifs.spnego ver=0x2;host=smbserver;ip4=192.168.122.13;sec=krb5;uid=0x0;creduid=0x502;user=user2* * /usr/sbin/cifs.upcall -K /etc/smbserver_user2.keytab %kIn addition, enabling use of gssproxy for credential retrieval is done by setting an environment variable, rather than an argument to cifs.upcall, changing the execution of cifs.upcall:
create cifs.spnego * * /usr/bin/env GSS_USE_PROXY=yes /usr/sbin/cifs.upcall %k
This script:
This helper script takes the place of cifs.upcall in the request-key.conf file, and is called directly for all 'cifs.spnego' types. It allows the use of more complex matching criteria of the fields of the key description, then executes the actual cifs.upcall with the appropriate arguments.
The matching is done by reading from the helper's config file (/etc/cifs-upcall-helper.conf), where each line consists of a set of match criteria and options to pass to cifs.upcall in the event of a match.
Each of the match criteria consists of a field name (parsed from the fields of the key's description - 'host', 'user', 'creduid', etc.), a comparison operator, and the value to compare, and multiple match criteria may be specified (all of which must pass in order to be selected).
Comparison operators include string matching and regexes for string fields (host and user), numeric comparisons (<, >, =, !=, etc.) for uid and creduid, and various IPv4 comparisons (ip ranges, network/netmask, network/prefix, etc.) (IPv6 still to be implemented).
When a match is made, the options list can specify flags to cifs.upcall; a keytab or krb5.conf file to use, a keyword to set the GSS_USE_PROXY environment variable, etc. Several % macros are also available, expanding to the values of the fields in the key's description.
For example, the following line can replace the 3 lines above which specify the hostname 'smbserver' and 'user1' username, and give a keytab to use:
host=smbserver,user=user1 keytab=/etc/smbserver_user1.keytab
or to cover multiple users, use %u macro for username:
host=smbserver keytab=/etc/smbserver_%u.keytab
The helper script then sets the appropriate arguments (and/or environment variables), and execs cifs.upcall.
In addition to matching, key descriptions, the config file is also used to increase debugging (to syslog) and to set the default arguments for future matches in the file:
# set the default arguments to cifs.upcall for subsequent matches
default use_proxy # increase helper's syslog verbosity to 'info' level or 'debug'
# level (from errors-only):
verbosity info
verbosity debugDetails of the implemented matching rules can be found in the README file, and additional example config file lines are in cifs-upcall-helper.conf.examples.
I welcome feedback on the helper script, as well as thoughts on its inclusion in cifs-utils.
Frank Sorenson (12):
contrib: add directory and documentation for cifs-upcall-helper
upcall-helper: add a sample config file
contrib: add cifs-upcall-helper script
upcall-helper: obtain and parse key description, assigning fields to
key_vars
upcall-helper: open and read each line of the helper's config file
upcall-helper: set upcall_opts on a match, or if 'default' is given
upcall-helper: set log level from config file
upcall-helper: build command-line and set environment variables for
cifs.upcall
upcall-helper: replace macros in upcall argument strings
upcall-helper: add string comparison
upcall-helper: add uid comparison
upcall-helper: add IP address comparisons
contrib/upcall-helper/README | 138 ++++++ contrib/upcall-helper/cifs-upcall-helper | 400 ++++++++++++++++++ .../cifs-upcall-helper.conf.examples | 66 +++ 3 files changed, 604 insertions(+) create mode 100644 contrib/upcall-helper/README create mode 100755 contrib/upcall-helper/cifs-upcall-helper create mode 100644 contrib/upcall-helper/cifs-upcall-helper.conf.examples
Signature · 1 line
2.49.0