Update Key Set Policy
This guide explains how to attach a policy template to specific keyset chains by deriving configurations from predefined templates. This process ensures that keyset policies are consistently applied across authentication keysets.
Prerequisites
Access to the
apishare_db_<tenantName>database with the appropriate permissions.Administrative privileges, specifically using a tenant Owner or serviceAccount ApiShare user.
Operational Steps
Initial Setup
Before executing SQL queries, connect to the database and set the correct schema context:
Once connected, execute:
This ensures that all subsequent queries are executed in the correct schema.
Step 1: Create Keyset Policy Templates
Generate the policy template with the required specifications (e.g., rotation after X months, expiration after Y months) using the Admin Functionality. For further details, follow the guide on this page: Keyset management | managing authentication keys policies
Step 2: Retrieve Keyset Policy Template IDs
Retrieve the list of available keyset policy templates IDs (authentication_keyset_policy_template_id ) by executing the following query:
Step 3: Retrieve Target Keyset Chain IDs
Identify the keyset chains (authentication_keyset_chain_id)to which the policy should be applied. Run the following query:
Step 4: Upsert Keyset Chain Policy
To apply or update the policy for a keyset chain, use the following SQL statement. This operation inserts a new policy if it does not exist or updates it if already present.
⚠ Warning: Certain scenarios may introduce unexpected behaviors. Carefully review the impact before executing the update.
Step 5: Enforce Schedulation to Keyset
This step must be executed only if you want to maintain the current credentials without impacting those consuming the APIs authenticated by these keys. Alternatively, it is still possible to manually regenerate the key (as long as the policy assigned in the previous steps allows it).
This step should only be executed under the following conditions:
The keyset marked as "latest" is NOT in a PENDING state.
The keyset marked as "latest" is NOT in a final state (e.g., REVOKED, EXPIRED).
If the above conditions are met, the automatic policy evaluation and scheduling assignment process has already occurred, and it is therefore necessary to override the scheduled dates.
⚠ Warning: Certain scenarios may lead to unexpected behaviors. Carefully assess the impact before proceeding with the update. For example, the scheduled expiration date must be later than the expected rotation date. Scheduled dates should not be set in the past.
Date Format:
Dy, DD Mon YYYY HH24:MI:SS +0000 (e.g. Thu, 20 Feb 2025 23:59:59 +0000)
Step 6: Refresh Keyset Elastic Index
Execute the elasticsearch-refresher
Verifications
Verify that the new policy has been successfully inserted or updated in the
as_authentication_keyset_policytable.Ensure that the policies have the expected expiration, rotation, and regeneration settings.
Login to ApiShare to confirm that the policies are enforced Keys Set Management | Viewing Key Set Details