Skip to content

Commit aa23e9b

Browse files
authored
Merge pull request #651 from Dstack-TEE/feat/kms-optional-self-auth
feat(kms): make self-authorization enforcement configurable
2 parents a673ab7 + 39a3a31 commit aa23e9b

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

kms/kms.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ mandatory = false
2626
cert_dir = "/etc/kms/certs"
2727
subject_postfix = ".dstack"
2828
admin_token_hash = ""
29+
# Whether trusted RPCs require the KMS to first attest itself to its own
30+
# auth API. Defaults to true (strict). Set to false ONLY when running KMS
31+
# outside a TEE (e.g. local dev/testing) where the local guest agent socket
32+
# is unavailable.
33+
enforce_self_authorization = true
2934

3035
[core.image]
3136
verify = true

kms/src/config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ pub(crate) struct KmsConfig {
4040
pub image: ImageConfig,
4141
#[serde(with = "serde_human_bytes")]
4242
pub admin_token_hash: Vec<u8>,
43+
/// Whether trusted RPCs require the KMS to first attest itself to its
44+
/// own auth API. Defaults to `true` (strict). Set `false` only for local
45+
/// dev/testing where the KMS runs outside a TEE and cannot reach a guest
46+
/// agent socket.
47+
#[serde(default = "default_true")]
48+
pub enforce_self_authorization: bool,
49+
}
50+
51+
fn default_true() -> bool {
52+
true
4353
}
4454

4555
impl KmsConfig {

kms/src/main_service.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use ra_tls::{
2626
use scale::Decode;
2727
use sha2::Digest;
2828
use tokio::sync::OnceCell;
29-
use tracing::info;
29+
use tracing::{info, warn};
3030
use upgrade_authority::{build_boot_info, local_kms_boot_info, BootInfo};
3131

3232
use crate::{
@@ -76,6 +76,9 @@ impl KmsState {
7676
config.image.download_timeout,
7777
config.pccs_url.clone(),
7878
);
79+
if !config.enforce_self_authorization {
80+
warn!("self-authorization is disabled; trusted RPCs will not be gated by KMS self-attestation - do not use in production TEE deployments");
81+
}
7982
Ok(Self {
8083
inner: Arc::new(KmsStateInner {
8184
config,
@@ -102,6 +105,9 @@ struct BootConfig {
102105

103106
impl RpcHandler {
104107
async fn ensure_self_allowed(&self) -> Result<()> {
108+
if !self.state.config.enforce_self_authorization {
109+
return Ok(());
110+
}
105111
let boot_info = self
106112
.state
107113
.self_boot_info

kms/src/main_service/upgrade_authority.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ pub(crate) fn pad64(hash: [u8; 32]) -> Vec<u8> {
206206
}
207207

208208
pub(crate) async fn ensure_self_kms_allowed(cfg: &KmsConfig) -> Result<()> {
209+
if !cfg.enforce_self_authorization {
210+
return Ok(());
211+
}
209212
let boot_info = local_kms_boot_info(cfg.pccs_url.as_deref())
210213
.await
211214
.context("failed to build local KMS boot info")?;

0 commit comments

Comments
 (0)