server_keys_json which stores the raw JSON that we got, and is unique on (server_name, key_json, from_server).
server_signature_keys which stores the JSON fields as columns, and is unique on (server_name, key_json)
When fetching keys from the store in Keyring, we used the first table. However, the fetch function didn't correctly account for multiple rows per server / key ID, and so would return whichever row happened to be returned last by Postgres. (This is often the most recent row, but also often not).
The fix here is: a) fix the read path to return the most recently added key JSON, and b) use the server_signature_keys instead for Keyring as we don't need the full JSON anyway.
We have two tables:
server_keys_json
which stores the raw JSON that we got, and is unique on(server_name, key_json, from_server)
.server_signature_keys
which stores the JSON fields as columns, and is unique on(server_name, key_json)
When fetching keys from the store in
Keyring
, we used the first table. However, the fetch function didn't correctly account for multiple rows per server / key ID, and so would return whichever row happened to be returned last by Postgres. (This is often the most recent row, but also often not).The fix here is: a) fix the read path to return the most recently added key JSON, and b) use the
server_signature_keys
instead forKeyring
as we don't need the full JSON anyway.