Skip to content

Commit 90976b9

Browse files
committed
feat(ra-tls): adjust certificate validity periods for security
- Change default certificate validity from 10 years to 1 hour - Add server_cert_not_after() helper for long-lived server certs (10 years) - Add client_cert_not_after() helper for short-lived client certs (10 minutes) - Update KMS CA, RPC and App CA certs to use 10-year validity - Update Gateway RPC cert to use 10-year validity - Update dstack-util generated certs to use 10-year validity - Update RA-TLS temp certs to use 10-minute validity
1 parent 029f167 commit 90976b9

5 files changed

Lines changed: 28 additions & 5 deletions

File tree

dstack-util/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use k256::schnorr::SigningKey;
1313
use ra_rpc::Attestation;
1414
use ra_tls::{
1515
attestation::QuoteContentType,
16-
cert::generate_ra_cert,
16+
cert::{generate_ra_cert, server_cert_not_after},
1717
kdf::{derive_ecdsa_key, derive_ecdsa_key_pair_from_bytes},
1818
rcgen::KeyPair,
1919
};
@@ -348,6 +348,7 @@ fn cmd_gen_ca_cert(args: GenCaCertArgs) -> Result<()> {
348348
.attestation(&attestation)
349349
.key(&key)
350350
.ca_level(args.ca_level)
351+
.not_after(server_cert_not_after())
351352
.build();
352353

353354
let cert = req
@@ -419,6 +420,7 @@ fn make_app_keys(
419420
.attestation(&attestation)
420421
.key(app_key)
421422
.ca_level(ca_level)
423+
.not_after(server_cert_not_after())
422424
.build();
423425
let cert = req
424426
.self_signed()

gateway/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ async fn maybe_gen_certs(config: &Config, tls_config: &TlsConfig) -> Result<()>
110110
.subject("dstack-gateway")
111111
.alt_names(std::slice::from_ref(&config.rpc_domain))
112112
.usage_server_auth(true)
113+
.not_after(ra_tls::cert::server_cert_not_after())
113114
.build()
114115
.self_signed()
115116
.context("Failed to self-sign rpc cert")?;

kms/src/main_service.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use k256::ecdsa::SigningKey;
1717
use ra_rpc::{CallContext, RpcCall};
1818
use ra_tls::{
1919
attestation::VerifiedAttestation,
20-
cert::{CaCert, CertRequest, CertSigningRequestV1, CertSigningRequestV2, Csr},
20+
cert::{
21+
server_cert_not_after, CaCert, CertRequest, CertSigningRequestV1, CertSigningRequestV2, Csr,
22+
},
2123
kdf,
2224
};
2325
use scale::Decode;
@@ -224,6 +226,7 @@ impl RpcHandler {
224226
.ca_level(0)
225227
.app_id(app_id)
226228
.special_usage("app:ca")
229+
.not_after(server_cert_not_after())
227230
.build();
228231
let app_ca = self
229232
.state

kms/src/onboard_service.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use k256::ecdsa::SigningKey;
1717
use ra_rpc::{client::RaClient, CallContext, RpcCall};
1818
use ra_tls::{
1919
attestation::{QuoteContentType, VersionedAttestation},
20-
cert::{CaCert, CertRequest},
20+
cert::{client_cert_not_after, server_cert_not_after, CaCert, CertRequest},
2121
rcgen::{Certificate, KeyPair, PKCS_ECDSA_P256_SHA256},
2222
};
2323
use safe_write::safe_write;
@@ -128,6 +128,7 @@ impl Keys {
128128
.subject("Dstack Client Temp CA")
129129
.ca_level(0)
130130
.key(&tmp_ca_key)
131+
.not_after(server_cert_not_after())
131132
.build()
132133
.self_signed()?;
133134

@@ -137,6 +138,7 @@ impl Keys {
137138
.subject("Dstack KMS CA")
138139
.ca_level(1)
139140
.key(&ca_key)
141+
.not_after(server_cert_not_after())
140142
.build()
141143
.self_signed()?;
142144
let attestation = if quote_enabled {
@@ -159,6 +161,7 @@ impl Keys {
159161
.special_usage("kms:rpc")
160162
.maybe_attestation(attestation.as_ref())
161163
.key(&rpc_key)
164+
.not_after(server_cert_not_after())
162165
.build()
163166
.signed_by(&ca_cert, &ca_key)?;
164167
Ok(Keys {
@@ -341,6 +344,7 @@ async fn gen_ra_cert(ca_cert_pem: String, ca_key_pem: String) -> Result<(String,
341344
.subject("RA-TLS TEMP Cert")
342345
.attestation(&attestation)
343346
.key(&key)
347+
.not_after(client_cert_not_after())
344348
.build();
345349
let cert = ca.sign(req).context("Failed to sign certificate")?;
346350
Ok((cert.pem(), key.serialize_pem()))

ra-tls/src/cert.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ use crate::traits::CertExt;
3232
use dstack_attest::attestation::QuoteContentType;
3333
use dstack_attest::attestation::{Attestation, AttestationQuote, VersionedAttestation};
3434

35+
/// Returns the expiration time for long-lived server certificates (10 years from now).
36+
pub fn server_cert_not_after() -> SystemTime {
37+
let day = Duration::from_secs(86400);
38+
SystemTime::now() + day * 365 * 10
39+
}
40+
41+
/// Returns the expiration time for short-lived client certificates (10 minutes from now).
42+
pub fn client_cert_not_after() -> SystemTime {
43+
let minute = Duration::from_secs(60);
44+
SystemTime::now() + minute * 10
45+
}
46+
3547
/// A CA certificate and private key.
3648
pub struct CaCert {
3749
/// The original PEM certificate.
@@ -402,8 +414,8 @@ impl<Key> CertRequest<'_, Key> {
402414
.not_after
403415
.unwrap_or_else(|| {
404416
let now = SystemTime::now();
405-
let day = Duration::from_secs(86400);
406-
now + day * 365 * 10
417+
let hour = Duration::from_secs(3600);
418+
now + hour
407419
})
408420
.into();
409421
Ok(params)
@@ -550,6 +562,7 @@ pub fn generate_ra_cert_with_app_id(
550562
.subject("RA-TLS TEMP Cert")
551563
.key(&key)
552564
.attestation(&attestation)
565+
.not_after(client_cert_not_after())
553566
.build();
554567
let cert = ca.sign(req).context("Failed to sign certificate")?;
555568
Ok(CertPair {

0 commit comments

Comments
 (0)