Hi, I have an issue with scoped API keys and clea...
# community-help
i
Hi, I have an issue with scoped API keys and cleaning them up. I was not aware that these keys are not automatically cleaned up if it expires, and I have around 6M keys that need to be cleaned up. The issue is I cant list them via the API (timeout). How can I get all the ID's for expired keys for cleaning up if I cannot get it via the API?
👀 1
m
They are base64 encoded and and the expiration timestamp is saved in the key. If the underlying key that was used for creating scoped key expired or got deleted the scoped key also should not work anymore.
i
Sorry I have just had a look - these are not scoped keys. These were created using
keys.create
and not
keys.generate_scoped_search_key
(python API). I assume this is why there is ~6M keys, most of which are expired. I have found a workaround, I noticed the ID's are sequential so I have scripted a sequential delete of a range of keys to recover. But deleting 6M API keys is estimated to take ~24 hours - even with 16 workers. Is there any way of speeding this up?
I noticed v26.0 has the autodelete flag which will be useful to avoid this going forward.
k
There's no other way to do this. This is why we had to introduce the auto delete flag.
j
The keys should have an auto-generated ID. So instead of trying to do a
GET /keys
to fetch all keys, you could have a simple counter in a loop, that does
GET /keys/0
,
GET /keys/1
, etc check the expires_at and delete it if it is expired.
But yeah, starting from v26 you want to use the
autodelete
for that many number of keys
i
Thanks, I will just run it over a day and migrate to v26.