@@ -13,11 +13,11 @@ use cb_common::{
1313 commit:: {
1414 constants:: {
1515 GENERATE_PROXY_KEY_PATH , GET_PUBKEYS_PATH , RELOAD_PATH , REQUEST_SIGNATURE_PATH ,
16- STATUS_PATH ,
16+ REVOKE_JWT , STATUS_PATH ,
1717 } ,
1818 request:: {
19- EncryptionScheme , GenerateProxyRequest , GetPubkeysResponse , SignConsensusRequest ,
20- SignProxyRequest , SignRequest ,
19+ EncryptionScheme , GenerateProxyRequest , GetPubkeysResponse , RevokeJWTRequest ,
20+ SignConsensusRequest , SignProxyRequest , SignRequest ,
2121 } ,
2222 } ,
2323 config:: StartSignerConfig ,
@@ -47,7 +47,7 @@ struct SigningState {
4747 manager : Arc < RwLock < SigningManager > > ,
4848 /// Map of modules ids to JWT secrets. This also acts as registry of all
4949 /// modules running
50- jwts : Arc < HashMap < ModuleId , String > > ,
50+ jwts : Arc < RwLock < HashMap < ModuleId , String > > > ,
5151}
5252
5353impl SigningService {
@@ -61,7 +61,7 @@ impl SigningService {
6161
6262 let state = SigningState {
6363 manager : Arc :: new ( RwLock :: new ( start_manager ( config. clone ( ) ) . await ?) ) ,
64- jwts : config. jwts . into ( ) ,
64+ jwts : Arc :: new ( RwLock :: new ( config. jwts ) ) ,
6565 } ;
6666
6767 let loaded_consensus = state. manager . read ( ) . await . available_consensus_signers ( ) ;
@@ -77,6 +77,7 @@ impl SigningService {
7777 . route ( GENERATE_PROXY_KEY_PATH , post ( handle_generate_proxy) )
7878 . route_layer ( middleware:: from_fn_with_state ( state. clone ( ) , jwt_auth) )
7979 . route ( RELOAD_PATH , post ( handle_reload) )
80+ . route ( REVOKE_JWT , post ( handle_revoke_jwt) )
8081 . with_state ( state. clone ( ) )
8182 . route_layer ( middleware:: from_fn ( log_request) )
8283 . route ( STATUS_PATH , get ( handle_status) ) ;
@@ -108,7 +109,8 @@ async fn jwt_auth(
108109 SignerModuleError :: Unauthorized
109110 } ) ?;
110111
111- let jwt_secret = state. jwts . get ( & module_id) . ok_or_else ( || {
112+ let guard = state. jwts . read ( ) . await ;
113+ let jwt_secret = guard. get ( & module_id) . ok_or_else ( || {
112114 error ! ( "Unauthorized request. Was the module started correctly?" ) ;
113115 SignerModuleError :: Unauthorized
114116 } ) ?;
@@ -270,7 +272,7 @@ async fn handle_reload(
270272 }
271273 } ;
272274
273- state. jwts = config. jwts . clone ( ) . into ( ) ;
275+ state. jwts = Arc :: new ( RwLock :: new ( config. jwts . clone ( ) ) ) ;
274276
275277 let new_manager = match start_manager ( config) . await {
276278 Ok ( manager) => manager,
@@ -285,6 +287,17 @@ async fn handle_reload(
285287 Ok ( StatusCode :: OK )
286288}
287289
290+ async fn handle_revoke_jwt (
291+ State ( state) : State < SigningState > ,
292+ Json ( request) : Json < RevokeJWTRequest > ,
293+ ) -> Result < impl IntoResponse , SignerModuleError > {
294+ let mut guard = state. jwts . write ( ) . await ;
295+ guard
296+ . remove ( & request. module_id )
297+ . ok_or ( SignerModuleError :: ModuleIdNotFound )
298+ . map ( |_| StatusCode :: OK )
299+ }
300+
288301async fn start_manager ( config : StartSignerConfig ) -> eyre:: Result < SigningManager > {
289302 let proxy_store = if let Some ( store) = config. store . clone ( ) {
290303 Some ( store. init_from_env ( ) ?)
0 commit comments