@@ -497,6 +497,8 @@ fn create_signer_service_dirk(
497497 let mut envs = IndexMap :: from ( [
498498 get_env_val ( CONFIG_ENV , CONFIG_DEFAULT ) ,
499499 get_env_same ( JWTS_ENV ) ,
500+ get_env_same ( ADMIN_JWT_ENV ) ,
501+ get_env_val ( SIGNER_TLS_CERTIFICATES_PATH_ENV , SIGNER_TLS_CERTIFICATES_PATH_DEFAULT ) ,
500502 get_env_val ( DIRK_CERT_ENV , DIRK_CERT_DEFAULT ) ,
501503 get_env_val ( DIRK_KEY_ENV , DIRK_KEY_DEFAULT ) ,
502504 get_env_val ( DIRK_DIR_SECRETS_ENV , DIRK_DIR_SECRETS_DEFAULT ) ,
@@ -548,6 +550,7 @@ fn create_signer_service_dirk(
548550
549551 // write jwts to env
550552 service_config. envs . insert ( JWTS_ENV . into ( ) , format_comma_separated ( & service_config. jwts ) ) ;
553+ service_config. envs . insert ( ADMIN_JWT_ENV . into ( ) , random_jwt_secret ( ) ) ;
551554
552555 // CA cert volume and env
553556 if let Some ( ca_cert_path) = ca_cert_path {
@@ -589,8 +592,8 @@ fn create_signer_service_dirk(
589592 environment : Environment :: KvPair ( envs) ,
590593 healthcheck : Some ( Healthcheck {
591594 test : Some ( HealthcheckTest :: Single ( format ! (
592- "curl -f http://localhost: {}/status" ,
593- signer_config . port ,
595+ "curl -k -f {}/status" ,
596+ cb_config . signer_server_url ( SIGNER_PORT_DEFAULT ) ,
594597 ) ) ) ,
595598 interval : Some ( "30s" . into ( ) ) ,
596599 timeout : Some ( "5s" . into ( ) ) ,
@@ -932,6 +935,13 @@ mod tests {
932935 service. volumes . iter ( ) . any ( |v| matches ! ( v, Volumes :: Simple ( s) if s. contains( substr) ) )
933936 }
934937
938+ fn get_healthcheck_cmd ( service : & Service ) -> Option < String > {
939+ service. healthcheck . as_ref ( ) . and_then ( |hc| match & hc. test {
940+ Some ( HealthcheckTest :: Single ( cmd) ) => Some ( cmd. clone ( ) ) ,
941+ _ => None ,
942+ } )
943+ }
944+
935945 fn has_port ( service : & Service , substr : & str ) -> bool {
936946 match & service. ports {
937947 Ports :: Short ( ports) => ports. iter ( ) . any ( |p| p. contains ( substr) ) ,
@@ -1309,12 +1319,33 @@ mod tests {
13091319 assert ! ( env_str( & service, DIRK_CERT_ENV ) . is_some( ) ) ;
13101320 assert ! ( env_str( & service, DIRK_KEY_ENV ) . is_some( ) ) ;
13111321 assert ! ( env_str( & service, DIRK_DIR_SECRETS_ENV ) . is_some( ) ) ;
1322+ assert ! ( has_env_key( & service, ADMIN_JWT_ENV ) ) ;
1323+ assert ! ( has_env_key( & service, SIGNER_TLS_CERTIFICATES_PATH_ENV ) ) ;
13121324 assert ! ( has_volume( & service, "client.crt" ) ) ;
13131325 assert ! ( has_volume( & service, "client.key" ) ) ;
13141326 assert ! ( has_volume( & service, "dirk_secrets" ) ) ;
13151327 Ok ( ( ) )
13161328 }
13171329
1330+ #[ test]
1331+ fn test_create_signer_service_dirk_generates_admin_jwt ( ) -> eyre:: Result < ( ) > {
1332+ let mut sc = minimal_service_config ( ) ;
1333+ let signer_config = dirk_signer_config ( ) ;
1334+ create_signer_service_dirk (
1335+ & mut sc,
1336+ & signer_config,
1337+ Path :: new ( "/certs/client.crt" ) ,
1338+ Path :: new ( "/certs/client.key" ) ,
1339+ Path :: new ( "/dirk_secrets" ) ,
1340+ & None ,
1341+ & None ,
1342+ ) ?;
1343+
1344+ let admin_jwt = sc. envs . get ( ADMIN_JWT_ENV ) . expect ( "ADMIN_JWT_ENV must be set" ) ;
1345+ assert ! ( !admin_jwt. is_empty( ) , "admin JWT secret must not be empty" ) ;
1346+ Ok ( ( ) )
1347+ }
1348+
13181349 #[ test]
13191350 fn test_create_signer_service_dirk_with_ca_cert ( ) -> eyre:: Result < ( ) > {
13201351 let mut sc = minimal_service_config ( ) ;
@@ -1690,6 +1721,50 @@ mod tests {
16901721 Ok ( ( ) )
16911722 }
16921723
1724+ #[ test]
1725+ fn test_create_signer_service_dirk_healthcheck_uses_https_with_tls ( ) -> eyre:: Result < ( ) > {
1726+ let dir = tempfile:: tempdir ( ) ?;
1727+ let certs_path = dir. path ( ) . to_path_buf ( ) ;
1728+ std:: fs:: write ( certs_path. join ( SIGNER_TLS_CERTIFICATE_NAME ) , b"cert" ) ?;
1729+ std:: fs:: write ( certs_path. join ( SIGNER_TLS_KEY_NAME ) , b"key" ) ?;
1730+
1731+ let mut sc = service_config_with_tls ( certs_path) ;
1732+ let signer_config = dirk_signer_config ( ) ;
1733+ let service = create_signer_service_dirk (
1734+ & mut sc,
1735+ & signer_config,
1736+ Path :: new ( "/certs/client.crt" ) ,
1737+ Path :: new ( "/certs/client.key" ) ,
1738+ Path :: new ( "/dirk_secrets" ) ,
1739+ & None ,
1740+ & None ,
1741+ ) ?;
1742+
1743+ let cmd = get_healthcheck_cmd ( & service) . expect ( "healthcheck must be set" ) ;
1744+ assert ! ( cmd. contains( "https://" ) , "healthcheck must use https with TLS: {cmd}" ) ;
1745+ assert ! ( cmd. contains( "-k" ) , "healthcheck must use -k flag for self-signed certs: {cmd}" ) ;
1746+ Ok ( ( ) )
1747+ }
1748+
1749+ #[ test]
1750+ fn test_create_signer_service_dirk_healthcheck_uses_http_without_tls ( ) -> eyre:: Result < ( ) > {
1751+ let mut sc = minimal_service_config ( ) ;
1752+ let signer_config = dirk_signer_config ( ) ;
1753+ let service = create_signer_service_dirk (
1754+ & mut sc,
1755+ & signer_config,
1756+ Path :: new ( "/certs/client.crt" ) ,
1757+ Path :: new ( "/certs/client.key" ) ,
1758+ Path :: new ( "/dirk_secrets" ) ,
1759+ & None ,
1760+ & None ,
1761+ ) ?;
1762+
1763+ let cmd = get_healthcheck_cmd ( & service) . expect ( "healthcheck must be set" ) ;
1764+ assert ! ( cmd. contains( "http://" ) , "healthcheck must use http without TLS: {cmd}" ) ;
1765+ Ok ( ( ) )
1766+ }
1767+
16931768 // -------------------------------------------------------------------------
16941769 // create_module_service – TLS cert env/volume
16951770 // -------------------------------------------------------------------------
0 commit comments