14.5.1. Server Tools¶
privacyidea-expired-users, privacyidea-usercache-cleanup and
privacyidea-get-serial work directly on the database of a privacyIDEA
server, the web server does not need to run. They read the configuration file
/etc/privacyidea/pi.cfg, or the file given in the environment variable
PRIVACYIDEA_CONFIGFILE (see The Config File). Run them as the user
privacyIDEA runs as, so that they can read the configuration and the
encryption key.
14.5.1.1. privacyidea-expired-users¶
privacyidea-expired-users looks for users whose account has expired and
unassigns or deletes their tokens. It needs an LDAP resolver with
"accountExpires": "accountExpires" in its attribute mapping, see
Expired Users. Accounts that never expire are skipped:
privacyidea-expired-users [-r REALM] [-u REGEX] [-d REGEX] [-a KEY] [-n]
-r REALM,--realm REALMOnly check the users of this realm. Without it, the users of all realms are checked.
-u REGEX,--unassign_serial REGEXUnassign the tokens of an expired user whose serial matches the regular expression. The default
.*matches every token.-d REGEX,--delete_serial REGEXDelete the tokens of an expired user whose serial matches the regular expression. By default no token is deleted.
-a KEY,--attribute_name KEYThe key of the attribute mapping that holds the expiration date. The default is
accountExpires. The LDAP resolver only compares this key as a date, so keep the default.-n,--noactionOnly show which accounts have expired and what would be done with their tokens.
A regular expression matches if it is found anywhere in the serial, use ^
to match the beginning. If a resolver cannot be queried, the tool skips it and
prints a warning, as the result is then incomplete.
Warning
The tool unassigns and deletes tokens without asking. As -u
defaults to .*, a run without options unassigns all tokens of every
expired user. Run it with -n first and check the output.
List the expired users of the realm ad and their tokens, then unassign all
their tokens and delete those whose serial starts with TOTP:
privacyidea-expired-users -r ad -n
privacyidea-expired-users -r ad -d '^TOTP'
14.5.1.2. privacyidea-usercache-cleanup¶
privacyidea-usercache-cleanup deletes the entries of the User Cache
that are older than the expiration timeout (see User Cache expiration in seconds).
While the user cache is disabled, it does nothing. Run it regularly, e.g.
daily, see Cleanup Jobs.
-n,--noactionOnly list the expired entries, do not delete them.
The tool lists every entry it deletes on stdout. In a crontab, discard the
output with > /dev/null, errors are still written to stderr.
14.5.1.3. privacyidea-get-serial¶
privacyidea-get-serial finds the token that generated a given OTP value,
like Find Token Serial Number in the WebUI:
privacyidea-get-serial [-t TYPE] [-s SERIAL] [-a | -u] [-w WINDOW] OTP
-t TYPE,--type TYPEOnly search tokens of this type, e.g.
hotportotp.-s SERIAL,--serial SERIALOnly search tokens whose serial contains this string.
-a,--assignedOnly search tokens that are assigned to a user.
-u,--unassignedOnly search tokens that are not assigned to a user.
-w WINDOW,--window WINDOWThe number of OTP values to check per token, default
10: the next counter values of HOTP tokens, the time steps around the current time for TOTP tokens.
The tool calculates OTP values for every token in the search, which takes a
while with many tokens, so narrow the search down with -t and -s. If
more than one token matches, it stops with an error. When a token is found,
its counter is moved past the OTP value, so this OTP value can no longer be
used to authenticate.
Search the HOTP tokens whose serial contains OATH:
privacyidea-get-serial -t hotp -s OATH 123456
14.5.1.4. privacyidea-standalone¶
privacyidea-standalone creates a local privacyIDEA instance that needs no
web server, and checks user names and passwords against it on the command
line, e.g. from a script on a single machine. An instance is a directory,
by default ~/.privacyidea, that holds the configuration file pi.cfg,
an SQLite database, the encryption key, the audit keys and the log file. All
commands take the directory with -i DIR (--instance DIR).
privacyidea-standalone create [-i DIR]Creates a new instance. The directory must not exist yet. The command asks for the password of the administrator
super. It then offers to create the resolverdefresolverin the realmdefrealm, either as a user table in the database of the instance (you manage the users in the WebUI) or with the users from/etc/passwd. The command callspi-manage, so run it with the virtual environment activated. If a step fails, the directory is removed again.privacyidea-standalone configure [-i DIR]Starts a local web server at
http://127.0.0.1:5000, where you configure the instance in the WebUI, e.g. enroll tokens. Stop it with Ctrl-C when you are done. Do not make this server reachable from the network.privacyidea-standalone check [-i DIR] [-u USER] [-p PASSWORD] [-r]Checks a user name and password against the instance, like an authentication request to
/validate/check. The password is the static part, e.g. the OTP PIN, followed by the OTP value. The command exits with0if the user authenticated successfully, with1if the authentication failed, and with another non-zero status on errors, e.g. if the instance does not exist.-r(--response) prints the HTTP status and the JSON response. The output is not pure JSON: it starts with the banner of the tool, followed byStatus: ...andData:, so a script that parses the response has to skip these lines. Use the exit status to decide whether the authentication succeeded.If
-uor-pis missing, the command asks for it. Without a terminal, e.g. when called from a script, it reads the missing values from standard input, one per line: first the user name, then the password. Prefer this over-p, because command line arguments are visible to other users in the process list.
14.5.1.5. privacyidea-diag¶
privacyidea-diag collects information about the system and the privacyIDEA
installation into one file for your support team. Run it as root, optionally
with the path of the configuration file (default /etc/privacyidea/pi.cfg):
privacyidea-diag /etc/privacyidea/pi.cfg
pi-manage has to be in the PATH. The script is written for Debian,
Ubuntu and RHEL (also CentOS Stream, Rocky Linux and AlmaLinux); on other
distributions it collects less. It writes the
file /tmp/<yy-mm-dd>_pi_diag_<random>.tar.gz, which only root can read,
and prints its name. The file contains:
the distribution, the installed system packages, the Python packages in
/opt/privacyidea, the processes and the disk usage,pi.cfg, the revision of the database schema, the resolvers, realms, event handlers and policies, and the SMTP, RADIUS and privacyIDEA server definitions,the file list of the FreeRADIUS configuration, the Apache configuration, the last 100 lines of the Apache or nginx logs and, on RHEL, the SELinux denials,
the privacyIDEA log file and the audit log of the last two days.
privacyidea-diag censors secrets before it writes them into the file:
pi.cfgis included without comments. The values of the settings whose name containsSECRET,PASSWORD,PASSWD,PEPPERorCREDENTIAL, or ends with_KEY,_OPTIONSorEXTRA_PARAMS, are censored. Of the settings whose name ends with_URIor_URL, e.g.SQLALCHEMY_DATABASE_URI, only the scheme is kept, which shows the database driver.PI_BASE_URLis kept as it is.In the exported resolvers, event handlers, policies and server definitions, the passwords and secrets that the export itself censors are censored, and so are all text values of keys that contain
secret,passw,bindpw,authorization,credential,api_key,private_keyoraccess_code(the last three also with-or without a separator) ormotppin, or that end withtoken(likeaccess_tokenorauthtoken), regardless of case. This covers e.g. the mOTP PIN of the token event handler and the access code of the Yubikey enrollment policy. This also applies to JSON objects inside values, e.g. HTTP headers.
Secrets in free text are not recognized, e.g. in the data of a webhook event handler, and the privacyIDEA log file and the audit log are included as they are. So the file still contains your configuration, and user names and IP addresses from the logs: only give it to recipients you trust.