mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
Verify eval plugin archives with scoped signing keys (#63528)
## Why The archive verifier counted keys returned in `eval_keys` but ignored them during key lookup, so it could not verify archives signed with those keys. ## What changed Accept eval signing keys from `eval_keys` and release signing keys from `keys`. Enforce each list's signing purpose and reject duplicate key IDs across both lists. Reuse the existing cache scoped by endpoint and authentication headers. ## Testing Cover rejection of legacy eval keys in `keys`, successful verification with a scoped eval key, and cache isolation across endpoints, accounts, and tokens. Add an app-server test that checks local installation precedes the remote install request for a valid eval archive and that tampering prevents both operations. GitOrigin-RevId: e8b6132f204c7e4e5f30d1dcb30357bac4c136ab
This commit is contained in:
@@ -20,6 +20,7 @@ use std::time::Instant;
|
||||
use tokio::sync::Semaphore;
|
||||
|
||||
const MARKETPLACE_ARCHIVE_PURPOSE: &str = "PLUGIN_RELEASE_ARCHIVE_SIGNING";
|
||||
const EVAL_ARCHIVE_PURPOSE: &str = "EVAL_PLUGIN_RELEASE_ARCHIVE_SIGNING";
|
||||
const MAX_CACHED_SCOPES: usize = 8;
|
||||
const MAX_SIGNING_KEYS: usize = 64;
|
||||
const MAX_SIGNING_KEYS_RESPONSE_BYTES: usize = 128 * 1024;
|
||||
@@ -108,6 +109,7 @@ impl SigningKey {
|
||||
pub(crate) fn archive_kind(&self) -> &'static str {
|
||||
match self.purpose.as_str() {
|
||||
MARKETPLACE_ARCHIVE_PURPOSE => "release",
|
||||
EVAL_ARCHIVE_PURPOSE => "eval",
|
||||
_ => "unknown",
|
||||
}
|
||||
}
|
||||
@@ -263,20 +265,25 @@ async fn fetch_signing_keys(
|
||||
return Err(ArchiveVerificationFailure::InvalidSigningKeysResponse);
|
||||
}
|
||||
let mut keys = HashMap::with_capacity(key_count);
|
||||
// Older servers published eval keys to all callers in `keys`.
|
||||
for key in response.keys {
|
||||
if key.key_id.is_empty()
|
||||
|| key.public_key_spki_der_base64.len() > MAX_PUBLIC_KEY_BASE64_BYTES
|
||||
|| keys.contains_key(&key.key_id)
|
||||
{
|
||||
return Err(ArchiveVerificationFailure::InvalidSigningKeysResponse);
|
||||
for (list, expected_purpose) in [
|
||||
// Older servers published eval keys to all callers in `keys`. Only `eval_keys` is scoped.
|
||||
(response.keys, MARKETPLACE_ARCHIVE_PURPOSE),
|
||||
(response.eval_keys, EVAL_ARCHIVE_PURPOSE),
|
||||
] {
|
||||
for key in list {
|
||||
if key.key_id.is_empty()
|
||||
|| key.public_key_spki_der_base64.len() > MAX_PUBLIC_KEY_BASE64_BYTES
|
||||
|| keys.contains_key(&key.key_id)
|
||||
{
|
||||
return Err(ArchiveVerificationFailure::InvalidSigningKeysResponse);
|
||||
}
|
||||
keys.insert(
|
||||
key.key_id.clone(),
|
||||
(key.purpose == expected_purpose)
|
||||
.then_some(key)
|
||||
.ok_or(ArchiveVerificationFailure::UnsupportedKeyPurpose),
|
||||
);
|
||||
}
|
||||
keys.insert(
|
||||
key.key_id.clone(),
|
||||
(key.purpose == MARKETPLACE_ARCHIVE_PURPOSE)
|
||||
.then_some(key)
|
||||
.ok_or(ArchiveVerificationFailure::UnsupportedKeyPurpose),
|
||||
);
|
||||
}
|
||||
let now = Instant::now();
|
||||
let expires_at = now
|
||||
|
||||
@@ -375,8 +375,11 @@ async fn canceled_refresh_leaves_waiter_free_to_fetch_new_keys() {
|
||||
#[tokio::test]
|
||||
async fn rejects_invalid_key_responses() {
|
||||
let valid = key_response();
|
||||
let mut eval_key = valid["keys"][0].clone();
|
||||
eval_key["purpose"] = json!(EVAL_ARCHIVE_PURPOSE);
|
||||
for response in [
|
||||
json!({"keys": [], "cache_ttl_seconds": 600}),
|
||||
json!({"keys": valid["keys"], "eval_keys": [eval_key], "cache_ttl_seconds": 600}),
|
||||
json!({"keys": valid["keys"], "cache_ttl_seconds": -1}),
|
||||
] {
|
||||
let server = MockServer::start().await;
|
||||
@@ -400,3 +403,56 @@ async fn rejects_invalid_key_responses() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn eval_key_cache_requires_the_same_endpoint_account_and_token() {
|
||||
let server = MockServer::start().await;
|
||||
let cache = SigningKeyCache::default();
|
||||
let mut keys = key_response();
|
||||
let mut eval_key = keys["keys"][0].clone();
|
||||
eval_key["key_id"] = json!("eval-key");
|
||||
eval_key["purpose"] = json!(EVAL_ARCHIVE_PURPOSE);
|
||||
keys["eval_keys"] = json!([eval_key]);
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/first/ps/plugins/signing-keys"))
|
||||
.and(header("authorization", "Bearer e30.e30.b2xk"))
|
||||
.and(header("chatgpt-account-id", "employee"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(keys))
|
||||
.with_priority(/*p*/ 1)
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
// Other callers and endpoints publish only the marketplace key.
|
||||
Mock::given(method("GET"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(key_response()))
|
||||
.expect(3)
|
||||
.mount(&server)
|
||||
.await;
|
||||
let eval_key: SigningKey = serde_json::from_value(eval_key).unwrap();
|
||||
let unknown = ArchiveVerificationFailure::UnknownSigningKey;
|
||||
for (endpoint, account, token, expected) in [
|
||||
("first", "employee", "e30.e30.b2xk", Ok(eval_key)),
|
||||
("second", "employee", "e30.e30.b2xk", Err(unknown)),
|
||||
("first", "other", "e30.e30.b2xk", Err(unknown)),
|
||||
("first", "employee", "e30.e30.bmV3", Err(unknown)),
|
||||
] {
|
||||
let base_url = format!("{}/{endpoint}", server.uri());
|
||||
let auth = auth_headers(token, account);
|
||||
assert_eq!(
|
||||
cache
|
||||
.key(&base_url, "eval-key", key_request(auth.clone()))
|
||||
.await,
|
||||
expected
|
||||
);
|
||||
if expected.is_ok() {
|
||||
assert_eq!(
|
||||
cache
|
||||
.key(&base_url, "eval-key", |_| async {
|
||||
Err(ArchiveVerificationFailure::AuthenticationRequired)
|
||||
})
|
||||
.await,
|
||||
Err(ArchiveVerificationFailure::AuthenticationRequired)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,15 @@ async fn server_with_keys(keys: Value) -> (MockServer, String) {
|
||||
async fn verifies_production_compatible_archive_and_rejects_tampering() {
|
||||
let cache = SigningKeyCache::default();
|
||||
let (archive, fixture) = signed_fixture();
|
||||
let (_server, base_url) = server_with_keys(fixture["signing_keys_response"].clone()).await;
|
||||
// Legacy servers included eval keys in the same list as marketplace keys for all callers.
|
||||
let mut keys = fixture["signing_keys_response"].clone();
|
||||
let mut eval_key = keys["keys"][0].clone();
|
||||
eval_key["key_id"] = json!("old-eval-key");
|
||||
eval_key["purpose"] = json!("EVAL_PLUGIN_RELEASE_ARCHIVE_SIGNING");
|
||||
keys["keys"].as_array_mut().unwrap().push(eval_key.clone());
|
||||
eval_key["key_id"] = json!("scoped-eval-key");
|
||||
keys["eval_keys"] = json!([eval_key]);
|
||||
let (_server, base_url) = server_with_keys(keys).await;
|
||||
let auth = auth_headers("user-token", "account");
|
||||
let metadata = download(&fixture["signing"]);
|
||||
|
||||
@@ -86,6 +94,31 @@ async fn verifies_production_compatible_archive_and_rejects_tampering() {
|
||||
Err(ArchiveVerificationFailure::SigningKeysUnavailable)
|
||||
);
|
||||
|
||||
let mut eval_signing = fixture["signing"].clone();
|
||||
eval_signing["key_id"] = json!("old-eval-key");
|
||||
assert_eq!(
|
||||
download(&eval_signing)
|
||||
.verify(
|
||||
archive.clone(),
|
||||
&base_url,
|
||||
&cache,
|
||||
key_request(auth.clone())
|
||||
)
|
||||
.await,
|
||||
Err(ArchiveVerificationFailure::UnsupportedKeyPurpose)
|
||||
);
|
||||
eval_signing["key_id"] = json!("scoped-eval-key");
|
||||
assert_eq!(
|
||||
download(&eval_signing)
|
||||
.verify(
|
||||
archive.clone(),
|
||||
&base_url,
|
||||
&cache,
|
||||
key_request(auth.clone())
|
||||
)
|
||||
.await,
|
||||
Ok((archive.clone(), PluginArchiveVerification::Verified))
|
||||
);
|
||||
let mut altered_archive = archive.clone();
|
||||
altered_archive[0] ^= 1;
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user