Automatically cleans up phones in the limbo state of "Generic Smartphone" in Duo Security.
Project description
duo_phone_cleanup
This script cleans up phones in the limbo state of "Generic Smartphone" in Duo Security.
The issue
If a user starts setting up a phone during the Duo registration, but then stops before they actually activate the phone successfully, they will be left in a state where they cannot log in. This can lead to help desk call and a bad user experience.
Instead, we want to remove any phone in this limbo state so that the user can try again later.
Usage
usage: duo_phone_cleanup [-h] [--skey SKEY] [--ikey IKEY] [--host HOST]
[--grace-period GRACE_PERIOD] [--force | --no-force | -f]
[--verbose]
[user ...]
Automatically cleans up phones in the limbo state of "Generic
Smartphone" in Duo Security.
The first time it sees a phone, it will tag it (on Duo) with a timestamp.
On the next run, if that timestamp is older than the specified grace
period, it will be removed.
All arguments except the positional `user` can also be environment
variables, e.g. `--skey` can also be provided as the environment
variable `DUO_SKEY`
positional arguments:
user A specific user to operate upon. Can be repeated. Not
required.
options:
-h, --help show this help message and exit
--skey SKEY, -s SKEY Duo Secret key. Remember that "The security of your
Duo application is tied to the security of your secret
key (skey). Secure it as you would any sensitive
credential. Don't share it with unauthorized
individuals or email it to anyone under any
circumstances!"
--ikey IKEY, -i IKEY Duo Integration key
--host HOST, -H HOST Address of the Duo SSO API application, e.g.
api-<yourid>.duosecurity.com
--grace-period GRACE_PERIOD, -g GRACE_PERIOD
The maximum duration (in minutes) that this tool will
allow a "Generic Smartphone" to remain registered once
it has been tagged by a prior run."
--force, --no-force, -f
If negated with `--no-force`, this tool will prompt
for confirmation before deleting each "Generic
Smartphone" device (default: True)
--verbose, -v Set output verbosity (-v=warning, -vv=debug)
examples:
duo_phone_cleanup <args>
How it works
This script is intended to be run on a regular interval (e.g. Cron)
- The first time it processed a device with the platform
Generic Smartphone
, it assigns a timestamp in the Duo API. - If the grace period (default 10 minutes) has passed when the phone is processed on subsequent runs, it will be removed.
The grace period is intended not to interrupt a user who may be actively setting up their smartphone (the timeout to setup a new phone on the Duo end seems to be about 17 minutes?)
The script starts by enumerating through the users in Duo. It checks each users phone to see if it is in the "Generic Smartphone" state. If so, it then determines if the phone has been in this state for longer than the grace period. Since Duo does not record when a phone was registered, we need to store the time when this script first sees the phone. We have to save this information somewhere. Rather than creating a local database to be maintained, we utilize the often ignored "Name" field that Duo uses to store the name of a phone. Since this field is blank by default, we store the seconds since the epoch when we first see the phone in this field. If a date is already in this field, we check if it is beyond the grace period. If it is, we remove the phone.
This should be safe, but YMMV, so please be careful!
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
To run the test suite:
# Dependent targets create venv and install dependencies
make
Please make sure to update tests along with any changes.
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file duo_phone_cleanup-0.0.3.tar.gz
.
File metadata
- Download URL: duo_phone_cleanup-0.0.3.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b659def0d71fa82e4d9119091b387d0670579c830b8ba8aa392360471847a0b |
|
MD5 | 966b098af3956a9d8581e7704b64f1c9 |
|
BLAKE2b-256 | 6d70d2a14255387725daa6fecc84065d13c04690f73533c85c8e1fe04df77999 |
File details
Details for the file duo_phone_cleanup-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: duo_phone_cleanup-0.0.3-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47ead7865b49b9f3278d1124906bac14b9fbb629f395a37049bbb425d3267309 |
|
MD5 | 766c7c616880f4825665042cb2238671 |
|
BLAKE2b-256 | 29ca34b06197a8cc1a30bafd490d90906a845f7f5e59fa1fd6167286694d7820 |