Rust SDK — Agent Configuration¶
The agent can be configured programmatically or from YAML.
Programmatic Configuration¶
use phytrace_sdk::{PhyTraceConfig, SourceType};
let config = PhyTraceConfig::new("robot-001")
.with_endpoint("https://api.phycloud.phyware.io/v1/events")
.with_api_key("your-api-key")
.with_source_type(SourceType::Amr)
.with_fleet_id("warehouse-fleet")
.with_site_id("site-nyc-01")
.with_buffer_path("/tmp/phytrace-buffer")
.with_buffer_max_size_mb(512)
.with_batch_size(100)
.with_retry_max(5);
YAML Configuration¶
See the Python SDK Agent docs for the full YAML schema — both SDKs use the same configuration format.
Merkle Batch Signing¶
With a TPM signer, sign events in Merkle batches: one TPM signature per batch, with each event carrying its inclusion proof (ProvenanceSigner::sign_batch, verify_value). The format and the trade-offs are described in the Python SDK provenance docs; both SDKs produce the same batches.
Heartbeats¶
The agent sends a signed system_heartbeat event every heartbeat.interval_secs (default 60), starting one interval after start(). PhyCloud uses them to report when a device was offline or missing (Heartbeats and Absence Detection):
TPM Signing and Attestation¶
On a PhyTAU, sign with the TPM (the phytrace-tpm crate) and turn on device attestation:
provenance:
sequence_path: /var/lib/phytrace/sequence.json
attestation:
enabled: true
interval_secs: 3600
pcrs: "sha256:0,1,2,3,4,5,6,7"
use std::sync::Arc;
use phytrace_tpm::{TpmConfig, TpmSigner};
let signer = Arc::new(TpmSigner::open(&TpmConfig::default())?);
let agent = PhyTraceAgent::from_config_with_signer(config, Some(signer)).await?;
agent.start().await?; // first TPM quote happens here
To make the signing key boot-bound (see Boot-bound signing keys), set TpmConfig::boot_policy with a new key_handle:
use phytrace_tpm::BootPolicy;
let policy = BootPolicy::load(
&std::fs::read_to_string("/etc/phytrace/release-key.pem")?,
&std::fs::read_to_string("/etc/phytrace/boot-approvals.json")?,
)?;
let signer = TpmSigner::open(&TpmConfig {
key_handle: 0x8100_0120,
boot_policy: Some(policy),
..TpmConfig::default()
})?;
Signing then fails with a boot state error unless the PCRs match an approval.
With attestation enabled, the agent quotes the TPM's PCRs over a PhyCloud nonce at start and then once per interval_secs. Every event's signed provenance carries device_attestation: {"mode": "tpm", "quote_id": "...", "quote_status": "verified"}. If a refresh fails, the previous quote_id is kept and the error is recorded. A signer without a TPM gets {"mode": "software", "warning": "no hardware root of trust"}.
Before the first run, register the device once with an operator key that has devices:write, using phytrace_sdk::core::enrollment:
use phytrace_sdk::core::enrollment::{bind_hardware, enroll_device, register_attestation_key};
let device = enroll_device(endpoint, operator_key, signer.as_ref(), "tb4-01", None).await?;
let device_id = device["device_id"].as_str().unwrap_or_default();
register_attestation_key(endpoint, operator_key, signer.as_ref(), device_id).await?;
// Prove the keys live in the TPM; returns the device with its certificate.
bind_hardware(endpoint, operator_key, signer.as_ref(), device_id, &[]).await?;
The blocks, keys and messages are the same as the Python SDK's, so either SDK can enroll a device the other runs.