API JWT Secret Rotation
Overview
The V3 API is returning and expecting several JSON Web Tokens (JWT’s) when the provided endpoints of the API are used. To prevent attacks, the JWT’s are signed with a secret that belongs to the related APP. For security reasons SECURITY-4022 we got the task to implement a periodic rotation for all non archived applications (SUITEDEV-27129).
Details
The script itself is very simple and is triggered by CRON on a daily base:
-
CRON invokes the script
-
The script checks if the flipper
ROTATE_API_JWT_SECRET_ENABLEDis set totrue. If this is not the case, the script will log this and just exit. -
If the flipper
ROTATE_API_JWT_SECRET_ENABLEDis set the script-
queries a maximum of 10 applications where date in
api_jwt_secret_expires_atis less than the actual date and the fieldarchived_atisNULLAND -
does for each of the applications the following in the database
-
update the
api_jwt_secret_expires_attonowplus 6 months -
update the value of
api_jwt_secretto a new secret -
update the updated date
-
reports the update of the application via the
entity-eventsto the me-client-service so that this service can invalidate the respective cache entry. -
log the success/failure of the update
-
-
Environment
The script is using the following environment variables:
-
ROTATE_API_JWT_SECRET_ENABLED: If set to exactlytruethe rotation will be executed (is enabled) otherwise the script will do nothing.
Artefacts
-
The script is dependent on the
applicationstable DB entries in thepushdatabase -
The script updates matching entries contained in the
applicationstable DB entries in thepushdatabase -
The script produces log entries which contain information about the success/failure of the updates.
Monitoring & Alarming
No extensions on the existing monitoring were done as error logs automatically will trigger an alarm.
Error Handling
jwt-secret-rotation-failed
If the rotation of the key for one or more APP fails, there is no real "standard procedure" which can be followed as this normally cannot not happen. If it was just a DB issue (no connection, not reachable,…) you would not need to do anything, because the APP(s) will be picked up with the next run on the following day.
Remarks
|
Be careful if you think to modify the number of APPs which are taken into account for key rotation
during a single day as this can heavily impact the |
|
If you want to enforce the key rotation for a specific APP you either can use the UI or
you just set the date in the |