Skip to content

Commit 1af3bf7

Browse files
committed
Read pccs_url from env var
1 parent 10ed752 commit 1af3bf7

File tree

12 files changed

+49
-29
lines changed

12 files changed

+49
-29
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ default-net = "0.22.0"
116116
# Cryptography/Security
117117
aes-gcm = "0.10.3"
118118
curve25519-dalek = "4.1.3"
119-
dcap-qvl = "0.2.2"
119+
dcap-qvl = "0.2.4"
120120
elliptic-curve = { version = "0.13.8", features = ["pkcs8"] }
121121
getrandom = "0.3.1"
122122
hkdf = "0.12.4"

basefiles/app-compose.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/bash
22

3+
HOST_SHARED_DIR="/dstack/.host-shared"
4+
SYS_CONFIG_FILE="$HOST_SHARED_DIR/.sys-config.json"
5+
CFG_PCCS_URL=$([ -f "$SYS_CONFIG_FILE" ] && jq -r '.pccs_url//""' "$SYS_CONFIG_FILE" || echo "")
6+
export PCCS_URL=${PCCS_URL:-$CFG_PCCS_URL}
7+
38
if [ $(jq 'has("pre_launch_script")' app-compose.json) == true ]; then
49
echo "Running pre-launch script"
510
tdxctl notify-host -e "boot.progress" -d "pre-launch" || true

gateway/src/main_service/sync_client.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct SyncClient {
2525
ca_cert_pem: String,
2626
app_id: Vec<u8>,
2727
timeout: Duration,
28+
pccs_url: Option<String>,
2829
}
2930

3031
impl SyncClient {
@@ -43,6 +44,7 @@ impl SyncClient {
4344
.tls_client_key(self.key_pem.clone())
4445
.tls_ca_cert(self.ca_cert_pem.clone())
4546
.tls_built_in_root_certs(false)
47+
.maybe_pccs_url(self.pccs_url.clone())
4648
.cert_validator(Box::new(move |cert| {
4749
let cert = cert.context("TLS cert not found")?;
4850
let remote_app_id = cert.app_id.context("App id not found")?;
@@ -112,6 +114,7 @@ pub(crate) async fn sync_task(
112114
ca_cert_pem: keys.certificate_chain.last().cloned().unwrap_or_default(),
113115
app_id: my_app_id,
114116
timeout: config.sync.timeout,
117+
pccs_url: config.pccs_url.clone(),
115118
}
116119
} else {
117120
SyncClient {
@@ -121,6 +124,7 @@ pub(crate) async fn sync_task(
121124
ca_cert_pem: "".into(),
122125
app_id: vec![],
123126
timeout: config.sync.timeout,
127+
pccs_url: config.pccs_url.clone(),
124128
}
125129
};
126130

gateway/tapp/docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ services:
3131
- ACME_STAGING=${ACME_STAGING}
3232
- SUBNET_INDEX=${SUBNET_INDEX}
3333
- RUST_LOG=info,certbot=debug
34+
- PCCS_URL=${PCCS_URL}
3435
restart: always
3536

3637
volumes:

kms/kms.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ mandatory = false
2121
[core]
2222
cert_dir = "/etc/kms/certs"
2323
subject_postfix = ".dstack"
24-
pccs_url = "https://api.trustedservices.intel.com/tdx/certification/v4"
2524

2625
[core.auth_api]
2726
type = "webhook"

kms/src/onboard_service.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ impl OnboardRpc for OnboardHandler {
8080
&request.source_url,
8181
&request.domain,
8282
self.state.config.onboard.quote_enabled,
83+
self.state.config.pccs_url.clone(),
8384
)
8485
.await
8586
.context("Failed to onboard")?;
@@ -171,14 +172,19 @@ impl Keys {
171172
})
172173
}
173174

174-
async fn onboard(other_kms_url: &str, domain: &str, quote_enabled: bool) -> Result<Self> {
175+
async fn onboard(
176+
other_kms_url: &str,
177+
domain: &str,
178+
quote_enabled: bool,
179+
pccs_url: Option<String>,
180+
) -> Result<Self> {
175181
let kms_client = RaClient::new(other_kms_url.into(), true)?;
176182
let mut kms_client = KmsClient::new(kms_client);
177183

178184
if quote_enabled {
179185
let tmp_ca = kms_client.get_temp_ca_cert().await?;
180186
let (ra_cert, ra_key) = gen_ra_cert(tmp_ca.temp_ca_cert, tmp_ca.temp_ca_key).await?;
181-
let ra_client = RaClient::new_mtls(other_kms_url.into(), ra_cert, ra_key)
187+
let ra_client = RaClient::new_mtls(other_kms_url.into(), ra_cert, ra_key, pccs_url)
182188
.context("Failed to create client")?;
183189
kms_client = KmsClient::new(ra_client);
184190
}

kms/tapp/compose-dev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ services:
1919
- PORT=8000
2020
- ETH_RPC_URL=${ETH_RPC_URL}
2121
- KMS_CONTRACT_ADDR=${KMS_CONTRACT_ADDR}
22+
- PCCS_URL=${PCCS_URL}
2223
restart: unless-stopped
2324

2425
kms:

ra-rpc/src/client.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,19 @@ impl RaClient {
9292
.context("failed to create client")
9393
}
9494

95-
pub fn new_mtls(remote_uri: String, cert_pem: String, key_pem: String) -> Result<Self> {
95+
pub fn new_mtls(
96+
remote_uri: String,
97+
cert_pem: String,
98+
key_pem: String,
99+
pccs_url: Option<String>,
100+
) -> Result<Self> {
96101
RaClientConfig::builder()
97102
.tls_no_check(true)
98103
.tls_built_in_root_certs(false)
99104
.remote_uri(remote_uri)
100105
.tls_client_cert(cert_pem)
101106
.tls_client_key(key_pem)
107+
.maybe_pccs_url(pccs_url)
102108
.build()
103109
.into_client()
104110
.context("failed to create client")

ra-tls/src/attestation.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Attestation functions
22
3+
use std::borrow::Cow;
4+
35
use anyhow::{anyhow, bail, Context, Result};
46
use dcap_qvl::quote::Quote;
57
use qvl::{
@@ -294,7 +296,15 @@ impl Attestation {
294296
if &self.decode_report_data()? != report_data {
295297
bail!("report data mismatch");
296298
}
297-
let report = qvl::collateral::get_collateral_and_verify(quote, pccs_url)
299+
let mut pccs_url = Cow::Borrowed(pccs_url.unwrap_or_default());
300+
if pccs_url.is_empty() {
301+
// try to read from PCCS_URL env var
302+
pccs_url = match std::env::var("PCCS_URL") {
303+
Ok(url) => Cow::Owned(url),
304+
Err(_) => Cow::Borrowed(""),
305+
};
306+
}
307+
let report = qvl::collateral::get_collateral_and_verify(quote, Some(pccs_url.as_ref()))
298308
.await
299309
.context("Failed to get collateral")?;
300310
if let Some(report) = report.report.as_td10() {

0 commit comments

Comments
 (0)