User API Keys¶
Each NetBox user attaches their own RIR credential to one or more RIRConfig rows. Keys are encrypted at rest and never returned by the REST API after creation.
Why per-user keys¶
The plugin assumes a multi-tenant operations model. RIR audit trails attribute every change to the credential that submitted it, so the plugin records, on every synced or written object:
synced_by-- theRIRUserKeywhose call produced the row (onRIROrganization,RIRContact,RIRNetwork).submitted_by-- theRIRUserKeythat submitted a write (onRIRTicket).
Per-user keys also avoid the operational hazard of a shared secret, and make rotation a per-user concern.
Which key an operation uses¶
- Anything a user initiates runs only with that user's own key -- the Sync, Reassign, Reallocate, Remove, and Delete actions, and the background work an edit sets off (automatic reassignment when a prefix gets a site and tenant, automatic removal when a prefix is deleted or deactivated). If that user has no key for the config, nothing is sent to the RIR; the UI reports an error, or, for edit-driven work, a
skippedsync log row names the user and the config. - Work no user initiates -- the scheduled sync, or automation running outside any request -- uses the config's default key (
RIRConfig.default_key). If none is set, it is skipped. Its changes are attributed in NetBox's change log to the default key's owner. - A deactivated user's keys are never used, whether as their own key or as a config's default key. Deactivating a user stops their keys the same way deleting the user does: work that would need one is skipped and the log names the deactivated user. This includes jobs queued before the deactivation: a prefix sync, reassign or remove job whose key's owner is deactivated by the time it runs makes no RIR call and writes a
skippedsync log row instead, and a queued manual RIR Sync fails with a job message naming the deactivated user. A deactivated user's key cannot be chosen as a config's default key.
A user's edit never falls back to the default key, so every write at the RIR is attributable to the person who made it. Background jobs run as the acting user, so NetBox's job list and changelog record who triggered them.
Adding a key¶
- Go to RIR Manager > User Keys and click Add.
- Pick a NetBox user (admins can create keys for other users).
- Pick the RIR Config. The pair (user, config) must be unique.
- Paste the API key into the password input.
- Save.
The form widget uses forms.PasswordInput, so the value is masked while typing. The serializer marks api_key as write_only, so it is never echoed back over the REST API.
Encryption at rest¶
The RIRUserKey.api_key column is an EncryptedCharField. Saving it transparently runs the value through Fernet encryption with a key derived from the plugin's encryption_key setting (or NetBox's SECRET_KEY when the setting is empty). Reading it (via the ORM) transparently decrypts.
Implementation details:
- KDF: HKDF-SHA256, salt
netbox-rir-manager, infoapi-key-encryption, output 32 bytes. - Cipher: Fernet (AES-128-CBC + HMAC-SHA256 + IV).
- Storage prefix:
$FERNET$<token>. Values without the prefix are returned as-is, which preserves backward compatibility with rows written before the field was added. - Decryption failure mode:
InvalidTokenreturns the stored value verbatim instead of raising. This means a misconfiguredencryption_keywill not crash the application, but write operations will fail at the RIR with confusing errors. See the warning below.
The implementation is netbox_rir_manager.fields.EncryptedCharField.
Rotation¶
Rotating a single user's RIR API key:
- Update the key with the RIR.
- Edit the
RIRUserKeyrow in NetBox and paste the new value. - Save. The new ciphertext replaces the old.
Rotating the encryption_key setting:
- Pre-flight: write a one-shot Django shell snippet that loops over every
RIRUserKey, readsapi_key(which decrypts under the old key), andsave()s it back (which re-encrypts under the same old key). This guarantees no plaintext rows remain. - Update
encryption_keyinconfiguration.py. - Restart NetBox and the RQ worker.
- Have each user re-enter their key. There is no way to recover the old ciphertext under the new key.
Lost keys are unrecoverable
Changing or losing encryption_key (or SECRET_KEY when the plugin's setting is empty) makes every previously encrypted API key unrecoverable. Treat the encryption key like a database password: store it in your secrets manager and back it up alongside the database.
REST API¶
GET /api/plugins/rir-manager/user-keys/
POST /api/plugins/rir-manager/user-keys/
GET /api/plugins/rir-manager/user-keys/{id}/
PATCH /api/plugins/rir-manager/user-keys/{id}/
DELETE /api/plugins/rir-manager/user-keys/{id}/
api_key is write_only. List and retrieve responses omit it entirely.
Example create:
curl -X POST https://netbox.example.com/api/plugins/rir-manager/user-keys/ \
-H "Authorization: Token <netbox-token>" \
-H "Content-Type: application/json" \
-d '{
"user": 1,
"rir_config": 1,
"api_key": "API-XXXX-XXXX-XXXX-XXXX"
}'
Filtering¶
The list view filters by user and rir_config_id. Search matches user.username.
Permissions¶
- Managing keys uses the standard
RIRUserKeypermissions:view_riruserkeyto list and view keys,add_riruserkey,change_riruserkeyanddelete_riruserkeyto manage them. The key form lets the editor pick any user; see User keys to limit users to their own keys. - Sync and write actions, in the web UI and the REST API, require the
addpermission on the model they act on (for exampleadd_rirnetworkfor Reassign,add_rirconfigfor Sync), within that permission's constraints, as well as the user's own key on the config. A key alone is not enough, and a permission without a key sends nothing to the RIR. Through the REST API, the token must also have write access.
See Reference: Permissions for the full list.