Skip to content

Commit c58bebe

Browse files
goffrieConvex, Inc.
authored andcommitted
Stop accepting LegacyEncryptor-issued tokens, except admin keys (#41761)
These have not been issued in a long time. Keep accepting old admin keys, because those are long-lived, but log when we encounter them. GitOrigin-RevId: d5ea33f36b5bab715839a8e66f07b719119cbb84
1 parent f27864c commit c58bebe

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

crates/keybroker/src/broker.rs

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ use crate::{
105105
legacy_encryptor::LegacyEncryptor,
106106
metrics::{
107107
log_actions_token_expired,
108+
log_legacy_admin_key,
108109
log_store_file_auth_expired,
109110
},
110111
secret::InstanceSecret,
@@ -886,11 +887,12 @@ impl KeyBroker {
886887
pub fn is_encrypted_admin_key(&self, key: &str) -> bool {
887888
let encrypted_part = split_admin_key(key).map(|(_, key)| key).unwrap_or(key);
888889
let admin_key: Result<AdminKeyProto, _> = self
889-
.encryptor
890-
.decode_proto(ADMIN_KEY_VERSION, encrypted_part)
890+
.admin_key_encryptor
891+
.decrypt_proto(ADMIN_KEY_VERSION, encrypted_part)
891892
.or_else(|_| {
892-
self.admin_key_encryptor
893-
.decrypt_proto(ADMIN_KEY_VERSION, encrypted_part)
893+
self.encryptor
894+
.decode_proto(ADMIN_KEY_VERSION, encrypted_part)
895+
.inspect(|_| log_legacy_admin_key())
894896
});
895897
admin_key.is_ok()
896898
}
@@ -905,11 +907,12 @@ impl KeyBroker {
905907
identity,
906908
is_read_only,
907909
} = self
908-
.encryptor
909-
.decode_proto(ADMIN_KEY_VERSION, encrypted_part)
910+
.admin_key_encryptor
911+
.decrypt_proto(ADMIN_KEY_VERSION, encrypted_part)
910912
.or_else(|_| {
911-
self.admin_key_encryptor
912-
.decrypt_proto(ADMIN_KEY_VERSION, encrypted_part)
913+
self.encryptor
914+
.decode_proto(ADMIN_KEY_VERSION, encrypted_part)
915+
.inspect(|_| log_legacy_admin_key())
913916
})
914917
.with_context(|| format!("Couldn't decode the AdminKeyProto {key}"))?;
915918
let instance_name = instance_name
@@ -947,12 +950,8 @@ impl KeyBroker {
947950
authorization_type,
948951
component_id,
949952
} = self
950-
.encryptor
951-
.decode_proto(STORE_FILE_AUTHZ_VERSION, store_file_authorization)
952-
.or_else(|_| {
953-
self.store_file_encryptor
954-
.decrypt_proto(STORE_FILE_AUTHZ_VERSION, store_file_authorization)
955-
})
953+
.store_file_encryptor
954+
.decrypt_proto(STORE_FILE_AUTHZ_VERSION, store_file_authorization)
956955
.context(ErrorMetadata::unauthenticated(
957956
"StorageTokenInvalid",
958957
"Couldn't decode the StoreFileAuthorization token",
@@ -1047,9 +1046,8 @@ impl KeyBroker {
10471046
) -> anyhow::Result<Cursor> {
10481047
let cursor_version = persistence_version.index_key_version(CURSOR_VERSION);
10491048
let proto: InstanceCursorProto = self
1050-
.encryptor
1051-
.decode_proto(cursor_version, &cursor)
1052-
.or_else(|_| self.cursor_encryptor.decrypt_proto(cursor_version, &cursor))
1049+
.cursor_encryptor
1050+
.decrypt_proto(cursor_version, &cursor)
10531051
.with_context(cursor_parse_error)?;
10541052
self.proto_to_cursor(proto)
10551053
}
@@ -1081,12 +1079,8 @@ impl KeyBroker {
10811079
None => Ok(QueryJournal::new()),
10821080
Some(journal) => {
10831081
let proto: InstanceQueryJournalProto = self
1084-
.encryptor
1085-
.decode_proto(query_journal_version, &journal)
1086-
.or_else(|_| {
1087-
self.journal_encryptor
1088-
.decrypt_proto(query_journal_version, &journal)
1089-
})
1082+
.journal_encryptor
1083+
.decrypt_proto(query_journal_version, &journal)
10901084
.with_context(cursor_parse_error)?;
10911085
let end_cursor = match proto.end_cursor {
10921086
Some(cursor) => Some(self.proto_to_cursor(cursor)?),
@@ -1122,12 +1116,8 @@ impl KeyBroker {
11221116
issued_s,
11231117
component_id,
11241118
} = self
1125-
.encryptor
1126-
.decode_proto(ACTION_KEY_VERSION, token)
1127-
.or_else(|_| {
1128-
self.action_callback_encryptor
1129-
.decrypt_proto(ACTION_KEY_VERSION, token)
1130-
})
1119+
.action_callback_encryptor
1120+
.decrypt_proto(ACTION_KEY_VERSION, token)
11311121
.with_context(|| format!("Couldn't decode ActionCallbackTokenProto {token}"))?;
11321122

11331123
anyhow::ensure!(issued_s != 0, "ActionCallbackTokenProto missing issued_s");
@@ -1395,5 +1385,6 @@ mod tests {
13951385
let roundtripped = AdminIdentity::from_proto_unchecked(proto).unwrap();
13961386
assert_eq!(admin_identity, roundtripped);
13971387
}
1388+
13981389
}
13991390
}

crates/keybroker/src/metrics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ register_convex_counter!(
1818
pub fn log_actions_token_expired() {
1919
log_counter(&KEYBROKER_ACTIONS_TOKEN_EXPIRED_TOTAL, 1);
2020
}
21+
22+
register_convex_counter!(
23+
KEYBROKER_LEGACY_ADMIN_KEY_TOTAL,
24+
"Number of times that a LegacyEncryptor-issued admin key is encountered"
25+
);
26+
pub fn log_legacy_admin_key() {
27+
log_counter(&KEYBROKER_LEGACY_ADMIN_KEY_TOTAL, 1);
28+
}

npm-packages/js-integration-tests/fileStorage.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ describe("File storage with HTTPClient", () => {
345345
test("expired upload url", async () => {
346346
// This test uses a token that was created with the dev secret. The target will fail to decode the token if the secret is different.
347347
if (!process.env.SKIP_INSTANCE_SECRET_TESTS) {
348-
const expiredPostUrl = `${deploymentUrl}/api/storage/upload?token=012df53dad7f240d44729afc7d018378f47916060026f5870066118050545b6f45f52467338e8bd2826bf358c80b7d7846a080719fa0fc0a2d69e7`;
348+
const expiredPostUrl = `${deploymentUrl}/api/storage/upload?token=01fadba622425353075d310561a03992352aa952b2f0113f3cd713b6bfa023c765be18fb122abb7ffd5505b81e8362`;
349349
const postResult = await fetch(expiredPostUrl, {
350350
method: "POST",
351351
body: "helloworld",

0 commit comments

Comments
 (0)