Skip to content

feat: add agent attestation#188

Merged
think-in-universe merged 7 commits intomainfrom
feat/agent-attestation
Feb 23, 2026
Merged

feat: add agent attestation#188
think-in-universe merged 7 commits intomainfrom
feat/agent-attestation

Conversation

@nickpismenkov
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @nickpismenkov, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request extends the attestation reporting capabilities by integrating agent instance attestations into the existing combined attestation report. This allows for a more comprehensive verification of the entire trust chain, including the integrity and authenticity of agent instances running on trusted hardware. The changes involve defining new data structures for agent attestations, updating the API endpoint to accept agent-specific queries, and implementing the necessary backend logic to retrieve and consolidate these attestations.

Highlights

  • New AgentAttestation Structure: Introduced a new AgentAttestation struct in crates/api/src/models.rs to represent attestation data for agent instances, including fields for image digest, event log, Intel TDX quote, TLS certificates, and request nonce.
  • CombinedAttestationReport Enhancement: The CombinedAttestationReport struct was updated to include an optional agent_attestations field, allowing the comprehensive report to now incorporate attestation details for agent instances.
  • Agent Attestation Query Parameter: Added an optional agent query parameter to the /v1/attestation/report endpoint in crates/api/src/routes/attestation.rs, enabling clients to request agent-specific attestations.
  • Agent Attestation Fetching Logic: Implemented new logic in crates/api/src/routes/attestation.rs to fetch agent attestations from the compose-api when the agent query parameter is provided. This involves querying agent instance details and combining attestation reports from different compose-api endpoints.
Changelog
  • crates/api/src/models.rs
    • Added AgentAttestation struct to define the structure for agent instance attestation data.
    • Updated CombinedAttestationReport to include an optional agent_attestations field, allowing it to hold a vector of AgentAttestation.
  • crates/api/src/routes/attestation.rs
    • Added Clone derive to AttestationQuery struct.
    • Introduced an optional agent field to AttestationQuery for specifying an agent instance ID.
    • Updated the utoipa::path macro for /v1/attestation/report to document the new agent query parameter.
    • Modified get_attestation_report to clone the AttestationQuery parameters and exclude the agent parameter when forwarding requests to the cloud-api.
    • Ensured request_nonce is cloned when used for chat_api_gateway_attestation and cloud_api_gateway_attestation.
    • Added conditional logic within get_attestation_report to call fetch_agent_attestations if an agent ID is provided in the query.
    • Integrated the fetched agent_attestations into the CombinedAttestationReport.
    • Implemented fetch_agent_attestations asynchronous function to retrieve agent attestation data from the compose-api by making multiple HTTP requests and combining the results.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@nickpismenkov nickpismenkov linked an issue Feb 23, 2026 that may be closed by this pull request
@nickpismenkov nickpismenkov changed the title add agent attestation feat: add agent attestation Feb 23, 2026
@claude
Copy link

claude bot commented Feb 23, 2026

PR Review: feat: add agent attestation

Critical Issues

1. Nonce not forwarded to compose-api (security flaw in attestation)

crates/api/src/routes/attestation.rsfetch_agent_attestations

The request_nonce is stored in the returned struct, but it is never sent to compose-api when fetching the attestation report. The whole point of the nonce is to be included in the attestation request so the remote service binds the quote to it (replay protection/freshness). Without it, the returned quote is not actually tied to the client's nonce.

Compare to the main attestation flow, where the nonce travels as a query param:

let path = format\!("attestation/report?{}", query);  // query includes nonce

But in fetch_agent_attestations:

let attestation_path = "attestation/report";  // no nonce\!

Fix — pass the nonce as a query parameter:

let attestation_path = format\!("attestation/report?nonce={}", request_nonce);

2. Path injection via instance_name

let instance_attestation_path = format\!("instances/{}/attestation", instance_name);

instance_name comes from the database but is used unencoded in URL construction. A name containing /, .., or URL-encoded separators could resolve to an unintended path on compose-api. URL-encode the segment:

use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
let encoded = utf8_percent_encode(instance_name, NON_ALPHANUMERIC);
let instance_attestation_path = format\!("instances/{}/attestation", encoded);

3. Sequential HTTP calls that can be parallelized

The two proxy_service.forward_request calls are independent and sequential. In a TEE context where attestation latency matters, these should run concurrently:

let (attestation_response, instance_response) = tokio::join\!(
    app_state.proxy_service.forward_request(Method::GET, attestation_path, http::HeaderMap::new(), None),
    app_state.proxy_service.forward_request(Method::GET, &instance_attestation_path, http::HeaderMap::new(), None),
);
let attestation_response = attestation_response.map_err(|e| { ... })?;
let instance_response = instance_response.map_err(|e| { ... })?;

Note: this requires instance_name lookup to happen before both calls (it does), but means the two HTTP requests overlap.


Minor

  • AgentAttestation.info is typed as Option<String> while ModelAttestation.info is Option<serde_json::Value>. If the field contains structured JSON from compose-api, parsing will silently stringify it instead of preserving structure — verify the actual response shape.

⚠️ Issues found — the nonce omission is the most important fix before merge given the TEE trust model.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces agent attestation, enhancing trust and security. However, several critical security issues were identified, including a potential panic leading to Denial of Service due to unvalidated nonce length, a missing access control check (IDOR) allowing unauthorized access to agent attestations, and a potential path traversal vulnerability when constructing proxy request paths using user-controlled agent names. Addressing these is crucial for the robustness and security of the attestation service. Additionally, consider refactoring duplicated logic in the new fetch_agent_attestations function to improve maintainability.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds agent attestation functionality to the attestation endpoint, allowing users to retrieve attestation information for their agent instances. The feature integrates agent attestations into the existing combined attestation report that already includes chat-api gateway, cloud-api gateway, and model attestations.

Changes:

  • Added new AgentAttestation model with fields for agent instance attestation data (name, image_digest, event_log, intel_quote, TLS certificates, etc.)
  • Extended CombinedAttestationReport to include optional agent attestations
  • Modified attestation endpoint to accept optional agent query parameter and fetch agent attestations from compose-api with proper authorization checks

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
crates/api/src/models.rs Added AgentAttestation struct and updated CombinedAttestationReport to include agent attestations field
crates/api/src/routes/attestation.rs Added agent query parameter, authentication requirement, validation functions (nonce, instance name), and fetch_agent_attestations function with IDOR protection
Comments suppressed due to low confidence (3)

crates/api/src/routes/attestation.rs:181

  • The code clones request_nonce twice (lines 149 and 181) to reuse it later. However, the original request_nonce is only used once at line 130, so you could move that usage to after the clones and avoid one of the clones. Consider whether this micro-optimization is worth the code clarity tradeoff, or if the original single clone approach was clearer.
            request_nonce: request_nonce.clone(),
            info: None,
            vpc: vpc_info,
        }
    } else {
        let client = dstack_sdk::dstack_client::DstackClient::new(None);

        let info = client.info().await.map_err(|e| {
            tracing::error!(
                "Failed to get chat API attestation info, are you running in a CVM?: {:?}",
                e
            );
            ApiError::internal_server_error("Failed to get chat API attestation info")
        })?;

        let cpu_quote = client.get_quote(report_data).await.map_err(|e| {
            tracing::error!(
                "Failed to get chat API attestation, are you running in a CVM?: {:?}",
                e
            );
            ApiError::internal_server_error("Failed to get chat API attestation")
        })?;

        ApiGatewayAttestation {
            signing_address: None,
            signing_algo: None,
            intel_quote: cpu_quote.quote,
            event_log: serde_json::from_str(&cpu_quote.event_log)
                .map_err(|_| ApiError::internal_server_error("Failed to deserialize event_log"))?,
            info: Some(serde_json::to_value(info).map_err(|_| {
                ApiError::internal_server_error("Failed to serialize attestation info")
            })?),
            request_nonce: request_nonce.clone(),

crates/api/src/routes/attestation.rs:257

  • The nonce validation logic has an inconsistency: it first checks if the nonce exceeds MAX_NONCE_LEN (256 chars), then checks if it's not exactly EXPECTED_NONCE_LEN (64 chars). This means nonces between 65-256 characters will trigger the "Nonce must be exactly 64 characters" error rather than the "Nonce is too long" error. Consider reordering the checks so the exact length check happens first, and the max length check is only needed as a safety fallback (or remove it entirely if you always require exactly 64 characters).
    if nonce.len() > MAX_NONCE_LEN {
        tracing::warn!("Nonce exceeds maximum length: {}", nonce.len());
        return Err(ApiError::bad_request("Nonce is too long"));
    }

    if !nonce.chars().all(|c| c.is_ascii_hexdigit()) {
        tracing::warn!("Nonce contains non-hex characters");
        return Err(ApiError::bad_request("Nonce must be a valid hex string"));
    }

    if nonce.len() != EXPECTED_NONCE_LEN {
        tracing::warn!(
            "Nonce has unexpected length: {} (expected {})",
            nonce.len(),
            EXPECTED_NONCE_LEN
        );
        return Err(ApiError::bad_request(format!(
            "Nonce must be exactly {} characters",
            EXPECTED_NONCE_LEN
        )));
    }

crates/api/src/routes/attestation.rs:270

  • The instance name validation rejects backslashes, which might be overly restrictive for Windows-style paths or legitimate instance names. However, given this is likely for Docker container names or similar identifiers that shouldn't contain backslashes anyway, this is probably fine. Consider documenting the allowed character set for instance names in the API documentation or error message to help users understand the constraints.
fn validate_instance_name(name: &str) -> Result<(), ApiError> {
    // Reject names containing path traversal sequences
    if name.contains("..") || name.contains("/") || name.contains("\\") {
        tracing::warn!("Instance name contains invalid characters: {}", name);
        return Err(ApiError::bad_request(
            "Instance name contains invalid characters",
        ));
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@think-in-universe think-in-universe merged commit a024a16 into main Feb 23, 2026
1 check passed
@think-in-universe think-in-universe deleted the feat/agent-attestation branch February 23, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: get attestation info of an agent

3 participants