Skip to main content

Key Hygiene page

The Key Hygiene page lists the virtual keys worth a second look, meaning keys nobody uses, keys without a budget or an expiry date, and keys older than the rotation policy, and lets you block, expire or delete them in bulk. It lives at /ui/key-hygiene. It has no entry in the left nav. Open it from the Key hygiene link in the header of the Virtual Keys page, which is shown to proxy admins, admin viewers, organization admins and admins of at least one team. The page needs a Spanway Enterprise license that includes the key_hygiene feature, and the server enforces the same license on the report routes.

Who sees which keys is decided by the server. Proxy admins and admin viewers see every key. Organization admins see the keys of their organizations and of the teams in them, team admins see the keys of the teams they administer, and anyone else is refused. The report leaves out blocked keys, keys that have already expired, Admin UI session keys and keys of teams the policy exempts.

A real-world scenario​

A security review asks for every key nobody used in 90 days to be expired. The admin opens Key Hygiene, picks the unused finding, selects all rows, and sets them to expire in 7 days so owners who still need a key have time to speak up.

Steps​

  1. Open Virtual Keys and follow the link to Key hygiene, or go to /ui/key-hygiene.

  2. Read the summary and open the unused keys tab. The same data with the API:

    curl "http://localhost:4000/key/hygiene?finding=unused&page_size=50" -H "Authorization: Bearer $SPANWAY_MASTER_KEY"
  3. Tick the rows, click Set expiry, choose 7d under Expire in, and confirm.

Expected result​

The selected keys show an expiry date seven days out, and they stop working with expired_key after it.

Header and summary​

The page opens with the title Key hygiene and the description "Virtual keys nobody uses, keys without a budget or expiry date, and keys older than the rotation policy.".

Below it are four summary tiles, one per finding, each with the number of keys that have it. Click a tile to show that finding in the table. The selected tile has a highlighted border.

TileCounts keys that
UnusedHave not been used for more than the policy's unused period. A key that was never used is measured from its creation date.
No budgetHave no max budget and no budget attached. Team and organization budgets still apply to them.
No expiryHave no expiry date.
Rotation overdueAre not on auto-rotation and were last rotated, or created, longer ago than the rotation policy allows. Shows Off when the policy does not set a rotation age.

Under the tiles a note sums up the active policy, for example "Unused after 90 days, rotation age is not checked, auto-expiry is off, key lifetime is not capped, owners are emailed 30 and 1 days before a key expires.". When auto-expiry is on it says how many days out unused keys get an expiry and how many keys would get one on the next run. The note also gives the maximum key lifetime and the days before expiry when owners are emailed.

Policy card​

Under the summary, the Policy card edits general_settings.key_hygiene without a config file change. A proxy admin sees these fields and a Save policy button.

FieldTypeWhat it does
Unused after (days)Text boxA key with no request for this long counts as unused. 1 to 3650, 90 by default.
Rotation overdue after (days)Text boxFlags a key that does not rotate itself and was last rotated, or created, longer ago than this. Empty turns the check off. 1 to 3650.
Maximum key lifetime (days)Text boxEvery key gets an expiry no later than its creation date plus this many days, existing keys included. Empty means no cap. 1 to 3650.
Expiry emails (days before)Text boxComma separated days before expiry when the key owner is emailed, for example 30, 1. Each value is 1 to 365 and may appear once. Empty turns the emails off.
Give unused keys an expiry dateSwitchOff by default. On, the hourly job gives every unused key an expiry date the grace period away, so keys nobody uses any more stop working on their own and a leaked old key cannot be used for long. Off, unused keys are only reported. Using a key afterwards does not cancel its expiry, the owner has to extend it, so check the note under the tiles, which says how many keys the next run would touch, before you switch it on. Only proxy admins can change it. When on, Grace period (days) sets how far out the expiry is, 1 to 365, and its help line says how long an unused key keeps working.

A value the gateway would reject shows a message under the fields and keeps Save policy disabled. Saving writes the whole policy, keeps the exempt_team_ids list as it is, and refreshes the tiles and the note. The hourly job uses the new policy on its next run. When the config file sets key_hygiene, the fields are read only and the card says "Set in the gateway config file, so it cannot be changed here.". Other roles see the fields read only with "Only a proxy admin can change the key hygiene policy.".

Finding tabs​

A row of buttons, Unused, No budget, No expiry and Rotation overdue, picks the finding the table shows. It defaults to Unused. Switching finding goes back to the first page and clears your selection.

Bulk actions​

The action bar is shown to the session roles Admin, Internal User and proxy_admin. It shows how many keys are selected, and every action button stays disabled until at least one key is selected.

ControlTypeWhat it does
BlockButtonBlocks the selected keys. Requests with a blocked key are rejected until it is unblocked on the Virtual Keys page.
Expire inSelectThe expiry to set, 7d (default), 30d or 90d.
Set expiryButtonGives the selected keys an expiry that many days from now.
DeleteButtonDeletes the selected keys.

Each action opens a confirmation titled Block keys, Expire keys in followed by the chosen duration, or Delete keys, which says how many keys it applies to. The delete confirmation adds "Deleted keys stop working at once and cannot be restored.". Confirming runs the action, shows a "done" message and clears the selection, and Cancel closes the dialog without changes. The actions use the normal key block, update and delete routes, so each key still goes through its own permission check and audit record. Block and Set expiry try every selected key. If some fail, the error says how many keys were not changed and how many were, with the first reason, the changed keys stay changed, and the selection is kept. Delete sends one request for all selected keys, and for anyone but a proxy admin it is all or nothing: if one key is outside your scope, no key is deleted and the error names the problem.

Deleting is permanent. The keys move to the deleted keys archive, which you can still read under the Deleted status on the Virtual Keys page and on the Deleted Keys tab of the Logs page, but they cannot be brought back. Blocking and setting an expiry can be undone from the key's detail view on the Virtual Keys page.

Key table​

The table shows 50 keys per page for the selected finding. Previous and Next move between pages, and Previous is disabled on the first page and Next on the last.

ColumnMeaning
CheckboxSelects the key for a bulk action. The header checkbox selects or clears every key on this page.
KeyKey alias, or the key name, or the start of the hashed key ID.
TeamTeam ID, or "None".
CreatedCreation date in UTC.
Last usedLast use date in UTC, or "Never".
SpendSpend in dollars.
ExpiresExpiry date in UTC, or "Never".
FindingsA badge for every finding the key has, which can be more than the selected one. Unused keys read "Idle N days" or "Never used, created N days ago". Overdue keys read "Not rotated for N days, policy is M". The others read "No budget" or "No expiry".

Empty, error and disabled states​

A short loading state shows while the license is checked. Without a license that includes key hygiene it shows "Key hygiene needs a Spanway Enterprise license" and names Key hygiene as the missing feature, with a link to get a trial license. The same message appears if the license check could not be read but the server then refuses the report for lack of a license.

When no key has the selected finding the table shows "No keys have this finding.". If the server refuses you, the page shows "You cannot see key hygiene" and says only proxy admins, admin viewers, organization admins and team admins can see it. Any other failure shows "Key hygiene could not be loaded" with the error and a prompt to reload. If the summary request fails the tiles and policy note are not shown, while the finding buttons and table still work. A policy that does not validate makes the report fail with the reason from the server.

The bulk action buttons are disabled until you select a key, and the confirm button shows "Working..." while an action runs.

Differences by role and license​

WhoWhat changes
Admin and proxy_adminSee every key and the bulk action bar, and can edit the Policy card.
Admin ViewerSees every key. The bulk action bar is hidden for this session role, and the server rejects key writes from this role with 403.
Org AdminSees the keys of their organizations and their teams. The bulk action bar is hidden for this session role.
Team adminSees the keys of the teams they administer. The bulk action bar is shown when their session role is Internal User.
Other rolesThe Key hygiene link is hidden, and opening the URL shows "You cannot see key hygiene".
No key_hygiene licenseThe page shows the license message instead of the report.

Errors​

What you seeWhat it meansFix
A card that says the page needs a Spanway Enterprise licenseThe license lacks key_hygiene.Add the feature.
"N of M keys could not be changed and K were changed: ..."Your role may not block or change some of the selected keys. The others were changed.Use a proxy admin account for the rest.
Delete fails and nothing is deletedAt least one selected key is outside your team or organization.Clear that key from the selection, or ask a proxy admin.
A key you expired is still neededThe owner asked for it after the review.Extend it with /key/update or the key's Settings tab.

Logs​

The page writes no log lines of its own. The hourly job behind the Policy card logs what it did, described in key hygiene.