@@ -27,6 +27,7 @@ use ra_tls::{
2727} ;
2828use safe_write:: safe_write;
2929use sha2:: Digest ;
30+ use tokio:: sync:: Mutex as AsyncMutex ;
3031use tracing:: info;
3132
3233use crate :: {
@@ -43,6 +44,7 @@ use crate::{
4344pub struct OnboardState {
4445 config : KmsConfig ,
4546 attestation_verifier : Arc < AttestationVerifier > ,
47+ bootstrap_lock : Arc < AsyncMutex < ( ) > > ,
4648}
4749
4850impl OnboardState {
@@ -54,6 +56,7 @@ impl OnboardState {
5456 Ok ( Self {
5557 config,
5658 attestation_verifier,
59+ bootstrap_lock : Arc :: new ( AsyncMutex :: new ( ( ) ) ) ,
5760 } )
5861 }
5962}
@@ -94,7 +97,12 @@ fn validate_onboarding_domain(domain: &str) -> Result<()> {
9497impl OnboardRpc for OnboardHandler {
9598 async fn bootstrap ( self , request : BootstrapRequest ) -> Result < BootstrapResponse > {
9699 validate_onboarding_domain ( & request. domain ) ?;
97- ensure_self_kms_allowed ( & self . state . config , & self . state . attestation_verifier )
100+ let _bootstrap_guard = self . state . bootstrap_lock . lock ( ) . await ;
101+ let cfg = & self . state . config ;
102+ if cfg. bootstrap_info ( ) . exists ( ) || cfg. root_ca_key ( ) . exists ( ) || cfg. k256_key ( ) . exists ( ) {
103+ bail ! ( "KMS has already been bootstrapped" ) ;
104+ }
105+ ensure_self_kms_allowed ( cfg, & self . state . attestation_verifier )
98106 . await
99107 . context ( "KMS is not allowed to bootstrap" ) ?;
100108 let keys = Keys :: generate ( & request. domain , self . state . config . attest_rpc_cert )
@@ -105,7 +113,6 @@ impl OnboardRpc for OnboardHandler {
105113 let ca_pubkey = keys. ca_key . public_key_der ( ) ;
106114 let attestation = attest_keys ( & ca_pubkey, & k256_pubkey) . await ?;
107115
108- let cfg = & self . state . config ;
109116 let response = BootstrapResponse {
110117 ca_pubkey,
111118 k256_pubkey,
0 commit comments