Rotate Pritunl token and secret directly in mongodb…

Pritunl API token autnetication checkbox and the token and secret are visible after installing the Enterprise key for Pritunl and restarting the service. But it looks like the underlying auth IS present, att least when I queried the administrators collection, I found the fields auth_api, token and secret present. I did not test full functionality before installing the Enterprise key, but I have a note to do that before installing the Enterprise key on the next iteration of testing.
Here’s how to access and manipulate these keys directly in the mongodb
Install mongosh
To install mongosh (the MongoDB Shell) on Ubuntu 22.04 (Jammy)
1. Import MongoDB’s public GPG key
| |
This is MongoDB’s GPG key used for verifying packages.
2. Add the MongoDB repo to APT sources
| |
3. Update package lists
| |
4. Install mongosh
| |
5. ✅ Test it
| |
Login to Mongodb
| |
Enable API Auth
To enable API authentication for a Pritunl administrator in mongosh, you need to set the auth_api field to true in the administrators collection.
1. Connect to your Pritunl database:
| |
Or locally:
| |
Then:
| |
2. Find the admin users:
| |
This shows you all usernames and whether auth_api is enabled.
3. Enable auth_api for a specific user:
Replace "user_name" with your actual username:
| |
4. Confirm the change:
| |
You should see:
| |
Rotate Token and Secret
To rotate the token and secret for an administrator in Pritunl via mongosh, you’ll directly update the fields in the administrators collection.
Generate new token and secret values
Use your terminal to generate secure values:
32-character:
| |
64-character:
| |
Update the admin in MongoDB
Substitute the values into the command below:
| |
Confirm the update
| |
⚠️ Notes
- The new
tokenandsecretare effective immediately — update Terraform or any automation that uses them. - Be sure to keep the
auth_apifield astrue:
—doug



