Skip to main content

a2a_protocol_server/
profile_report.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Tom F. <[email protected]> (https://github.com/tomtom215)
3
4//! What a handler's profiles guarantee, what an escape hatch gave up, and what
5//! no process can check about itself (adversarial review of 2026-11-13: "keep
6//! explicit escape hatches but report which guarantees they disable").
7
8/// The guarantees of the profiles a handler was built with, as `build()`
9/// left them: [`RequestHandler::profile_report`](crate::RequestHandler::profile_report).
10///
11/// `build()` refuses a profile whose requirements are not met, so every entry
12/// of [`checked`](Self::checked) held when the handler was built. An entry of
13/// [`disabled`](Self::disabled) is a guarantee one of the profiles would
14/// otherwise give, turned off by a call the builder was given. An entry of
15/// [`not_verifiable`](Self::not_verifiable) is something the profile depends
16/// on that the deployment has to show by other means: a running process
17/// cannot see its own backups, the network in front of it, or where its keys
18/// are kept.
19///
20/// A handler built with no profile has an empty report: nothing was checked.
21#[derive(Debug, Clone, Default, PartialEq, Eq)]
22#[non_exhaustive]
23pub struct ProfileReport {
24    /// The profiles applied, in the order they were applied.
25    pub profiles: Vec<&'static str>,
26    /// What `build()` verified.
27    pub checked: Vec<&'static str>,
28    /// Each escape hatch the builder was given, and what it gives up.
29    pub disabled: Vec<(&'static str, &'static str)>,
30    /// What the profiles rely on that no check at startup can establish.
31    pub not_verifiable: Vec<&'static str>,
32    /// What the deployment declared about the controls outside this process
33    /// ([`declare_external_control`](crate::RequestHandlerBuilder::declare_external_control)),
34    /// as declared: nothing here was verified.
35    pub declared: Vec<(ExternalControl, String)>,
36}
37
38/// A control outside this process that a profile relies on and cannot see,
39/// declared with
40/// [`RequestHandlerBuilder::declare_external_control`](crate::RequestHandlerBuilder::declare_external_control).
41///
42/// A declaration is a statement for the record, not a check: it is carried
43/// into [`ProfileReport::declared`] so that what the deployment said it does
44/// is logged beside what the handler checked, and can be compared with the
45/// deployment's evidence. [`Profile::RegulatedData`](crate::profile::Profile::RegulatedData)
46/// refuses to build until each control it relies on has been declared.
47#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
48#[non_exhaustive]
49pub enum ExternalControl {
50    /// Which proxies may set forwarded headers (`Forwarded`, `X-Forwarded-For`)
51    /// that a rate limiter or credential throttle reads, or that none do.
52    TrustedProxies,
53    /// Where the key-encryption keys of sealed stores and audit privacy are
54    /// held, who can use them, and how they are rotated.
55    KeyCustody,
56    /// That the databases are backed up, and a restore has been rehearsed.
57    Backups,
58    /// The retention schedule, and the jobs that apply it (`purge_expired`,
59    /// `AuditLog::purge`, `StepJournal::sweep`).
60    Retention,
61    /// That task content is encrypted at rest by the storage itself (the
62    /// database or the disk), in place of `EncryptedTaskStore` (feature
63    /// `encryption`).
64    EncryptionAtRest,
65}
66
67impl ExternalControl {
68    /// A short name for the control, as reports print it.
69    #[must_use]
70    pub const fn name(self) -> &'static str {
71        match self {
72            Self::TrustedProxies => "trusted proxies",
73            Self::KeyCustody => "key custody",
74            Self::Backups => "backups and restore",
75            Self::Retention => "retention",
76            Self::EncryptionAtRest => "encryption at rest",
77        }
78    }
79}
80
81impl ProfileReport {
82    /// Adds `items` to `list`, each once.
83    pub(crate) fn add(list: &mut Vec<&'static str>, items: &[&'static str]) {
84        for item in items {
85            if !list.contains(item) {
86                list.push(item);
87            }
88        }
89    }
90}
91
92impl std::fmt::Display for ProfileReport {
93    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
94        if self.profiles.is_empty() {
95            return f.write_str("no deployment profile: nothing was checked");
96        }
97        writeln!(f, "profiles: {}", self.profiles.join(", "))?;
98        for item in &self.checked {
99            writeln!(f, "  checked: {item}")?;
100        }
101        for (hatch, lost) in &self.disabled {
102            writeln!(f, "  disabled by {hatch}: {lost}")?;
103        }
104        for item in &self.not_verifiable {
105            writeln!(f, "  not verifiable here: {item}")?;
106        }
107        for (control, how) in &self.declared {
108            writeln!(f, "  declared, not verified: {}: {how}", control.name())?;
109        }
110        Ok(())
111    }
112}