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.4.tar.gz
.
File metadata
- Download URL: duo_phone_cleanup-0.0.4.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44f46310ced24ad32843a1558506b8d0cf71b3ddd3d56e94a733916c0445fed2 |
|
MD5 | 53a2f8cadf4782b1f4cab4ec12af54e0 |
|
BLAKE2b-256 | 722882256ad991af75a04713744a2c0caed6a1c5250ebb5987030b4b99b92de8 |
File details
Details for the file duo_phone_cleanup-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: duo_phone_cleanup-0.0.4-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 | 20ef566f6ad631344cc159f6a96ea93c8d48caa33b0d21e9447f0b588f7965cf |
|
MD5 | 8875760eab6123e25ae643378ddb9cc5 |
|
BLAKE2b-256 | d78e53c393c82c5de7c59769ceb93c6880487ea8d1a5c387ded84cc80020959f |