Add ephemeral runtime registration and signed assertions (#55402)

## What changed

Extend `codex-runtime-agent-instance` with a registration client and an in-memory assertion signer. Pending registrations retain their signing key and idempotency key across caller-driven retries; registered runtimes generate fresh versioned assertions with a timestamp and unique ID.

Bound registration requests and responses, reject unsafe endpoints, disable redirects and request logging, and preserve network policy errors. Report server rejections using only the status and recognized error codes.

## Testing

Add HTTP-backed tests for retry stability, assertion signatures and freshness, policy revocation, endpoint and response validation, redirect refusal, and error redaction.

GitOrigin-RevId: a6dab0900459dfb75f72652a0a2ee1e4b65ca322
This commit is contained in:
cooper-oai
2026-10-19 23:01:54 +00:00
committed by copyberry
parent 431185b78b
commit 79a19cbb30
6 changed files with 564 additions and 3 deletions
@@ -0,0 +1,102 @@
//! A pending registration keeps its key and retry ID; a registered runtime signs v1 assertions.
use crate::RuntimeRegistrationRequest;
use crate::RuntimeRegistrationResponse;
use base64::Engine;
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
use codex_agent_identity::encode_ssh_ed25519_public_key;
use codex_utils_redacted_string::RedactedString;
use ed25519_dalek::Signer;
use ed25519_dalek::SigningKey;
use rand::TryRngCore;
use rand::rngs::OsRng;
use serde_json::json;
use std::fmt;
use std::io;
use std::sync::Arc;
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
use uuid::Uuid;
use zeroize::Zeroizing;
/// One initialization, including retries. Neither this key nor the resulting runtime is persisted.
pub struct RuntimeRegistration {
pub(crate) initialization_id: Uuid,
pub(crate) request: RuntimeRegistrationRequest,
pub(crate) signing_key: Arc<SigningKey>,
}
impl RuntimeRegistration {
pub fn new(
actor: crate::AuthenticatedActorAuthorization,
host: crate::AgentHostAuthorization,
metadata: crate::RuntimeRegistrationMetadata,
) -> io::Result<Self> {
let mut seed = Zeroizing::new([0u8; 32]);
OsRng
.try_fill_bytes(seed.as_mut())
.map_err(|_| io::Error::other("failed to generate runtime signing key"))?;
let signing_key = SigningKey::from_bytes(&seed);
Ok(Self {
initialization_id: Uuid::new_v4(),
request: RuntimeRegistrationRequest {
actor_auth: actor,
agent_host_auth: host,
public_key: encode_ssh_ed25519_public_key(&signing_key.verifying_key()),
metadata,
},
signing_key: Arc::new(signing_key),
})
}
}
/// A server-registered identity and its memory-only signer, shared for this runtime's lifetime.
pub struct RuntimeAgentInstance {
pub(crate) info: RuntimeRegistrationResponse,
pub(crate) signing_key: Arc<SigningKey>,
}
impl RuntimeAgentInstance {
pub fn info(&self) -> &RuntimeRegistrationResponse {
&self.info
}
/// Make a fresh assertion for each request attempt or connection handshake.
pub fn assertion(&self) -> io::Result<RedactedString> {
let issued_at = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map_err(|_| io::Error::other("system clock is before the Unix epoch"))?
.as_secs();
let protected =
URL_SAFE_NO_PAD.encode(br#"{"alg":"EdDSA","typ":"openai-agent-assertion+jws"}"#);
let payload = URL_SAFE_NO_PAD.encode(
json!({
"version": 1,
"runtime_agent_instance": self.info.runtime_agent_instance_id,
"iat": issued_at,
"id": Uuid::new_v4(),
})
.to_string(),
);
let signing_input = format!("{protected}.{payload}");
let signature =
URL_SAFE_NO_PAD.encode(self.signing_key.sign(signing_input.as_bytes()).to_bytes());
// The outer version routes the assertion; it is not part of the JWS signing input.
let assertion = format!("1.{signing_input}.{signature}");
if assertion.len() > 8192 {
return Err(io::Error::other("runtime assertion exceeds the size limit"));
}
Ok(assertion.into())
}
}
impl fmt::Debug for RuntimeAgentInstance {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RuntimeAgentInstance")
.field(
"runtime_agent_instance_id",
&self.info.runtime_agent_instance_id,
)
.finish_non_exhaustive()
}
}