@@ -36,7 +36,6 @@ import {
3636 RELAY_MANAGED_TUNNEL_RECOVERY_TYP ,
3737 RELAY_MINT_REQUEST_TYP ,
3838 RELAY_MINT_RESPONSE_TYP ,
39- signRelayJwt ,
4039 verifyRelayJwt ,
4140} from "@t3tools/shared/relayJwt" ;
4241import { isSecureRelayUrl } from "@t3tools/shared/relayUrl" ;
@@ -95,7 +94,7 @@ import {
9594 RELAY_ISSUER_SECRET ,
9695 RELAY_URL_SECRET ,
9796} from "./config.ts" ;
98- import { getOrCreateEnvironmentKeyPairFromSecretStore } from "./environmentKeys.ts" ;
97+ import { EnvironmentSigningKey } from "./environmentKeys.ts" ;
9998import * as ConnectReachability from "./ConnectReachability.ts" ;
10099import * as ManagedEndpointRuntime from "./ManagedEndpointRuntime.ts" ;
101100import * as ManagedLimits from "../policy/managedLimits.ts" ;
@@ -525,6 +524,7 @@ const make = Effect.gen(function* () {
525524 const awarenessRelay = yield * AgentAwarenessRelay . AgentAwarenessRelay ;
526525 const random = yield * SecureRandom . SecureRandom ;
527526 const signature = yield * Signature . Signature ;
527+ const signingKey = yield * EnvironmentSigningKey ;
528528 const config = yield * ServerConfig . ServerConfig ;
529529 const fileSystem = yield * FileSystem . FileSystem ;
530530 const path = yield * Path . Path ;
@@ -581,9 +581,6 @@ const make = Effect.gen(function* () {
581581 requestUrl : string ,
582582 allowNonLoopbackRequestHost = false ,
583583 ) {
584- const keyPair = yield * getOrCreateEnvironmentKeyPairFromSecretStore ( secrets ) . pipe (
585- Effect . provideService ( Signature . Signature , signature ) ,
586- ) ;
587584 if (
588585 ! isSupportedLinkProviderKind ( request ) ||
589586 ! isAllowedEndpointOrigin ( {
@@ -608,24 +605,24 @@ const make = Effect.gen(function* () {
608605 challenge : request . challenge ,
609606 descriptor,
610607 environmentId : descriptor . environmentId ,
611- environmentPublicKey : normalizePemForSignedPayload ( keyPair . publicKey ) ,
608+ environmentPublicKey : normalizePemForSignedPayload ( signingKey . publicKey ) ,
612609 endpoint : request . endpoint ,
613610 origin : request . origin ,
614611 scopes : linkProofScopes ( request ) ,
615612 } satisfies RelayEnvironmentLinkProofPayload ;
616- return yield * signRelayJwt ( {
617- privateKey : keyPair . privateKey ,
618- typ : RELAY_LINK_PROOF_TYP ,
619- payload,
620- } ) . pipe (
621- Effect . provideService ( Signature . Signature , signature ) ,
622- Effect . mapError (
623- ( cause ) =>
624- new EnvironmentAuth . ServerAuthCloudLinkJwtSigningError ( {
625- cause,
626- } ) ,
627- ) ,
628- ) ;
613+ return yield * signingKey
614+ . sign ( {
615+ typ : RELAY_LINK_PROOF_TYP ,
616+ payload,
617+ } )
618+ . pipe (
619+ Effect . mapError (
620+ ( cause ) =>
621+ new EnvironmentAuth . ServerAuthCloudLinkJwtSigningError ( {
622+ cause,
623+ } ) ,
624+ ) ,
625+ ) ;
629626 } ) ;
630627
631628 const linkProof = Effect . fn ( "environment.cloud.linkProof" ) (
@@ -925,9 +922,6 @@ const make = Effect.gen(function* () {
925922 const makeManagedTunnelRecoveryProof = Effect . fn (
926923 "environment.cloud.makeManagedTunnelRecoveryProof" ,
927924 ) ( function * ( input : ManagedTunnelRecoveryProofInput ) {
928- const keyPair = yield * getOrCreateEnvironmentKeyPairFromSecretStore ( secrets ) . pipe (
929- Effect . provideService ( Signature . Signature , signature ) ,
930- ) ;
931925 const configuredIssuer = yield * secrets . get ( RELAY_ISSUER_SECRET ) ;
932926 const now = yield * DateTime . now ;
933927 const issuedAt = Math . floor ( now . epochMilliseconds / 1_000 ) ;
@@ -953,16 +947,16 @@ const make = Effect.gen(function* () {
953947 }
954948 : { ...claims , action : "recover" as const , origin : input . origin } ;
955949
956- return yield * signRelayJwt ( {
957- privateKey : keyPair . privateKey ,
958- typ : RELAY_MANAGED_TUNNEL_RECOVERY_TYP ,
959- payload,
960- } ) . pipe (
961- Effect . provideService ( Signature . Signature , signature ) ,
962- Effect . mapError (
963- ( cause ) => new CloudLinkInternalError ( { operation : "sign-recovery-proof" , cause } ) ,
964- ) ,
965- ) ;
950+ return yield * signingKey
951+ . sign ( {
952+ typ : RELAY_MANAGED_TUNNEL_RECOVERY_TYP ,
953+ payload,
954+ } )
955+ . pipe (
956+ Effect . mapError (
957+ ( cause ) => new CloudLinkInternalError ( { operation : "sign-recovery-proof" , cause } ) ,
958+ ) ,
959+ ) ;
966960 } ) ;
967961
968962 /** Keep credentials: clock skew can cause 401s. A relink during the request returns false without marking; accepted registration clears the mark. */
@@ -1481,9 +1475,6 @@ const make = Effect.gen(function* () {
14811475 return yield * new CloudLinkProofReplayedError ( { request : "health" } ) ;
14821476 }
14831477
1484- const keyPair = yield * getOrCreateEnvironmentKeyPairFromSecretStore ( secrets ) . pipe (
1485- Effect . provideService ( Signature . Signature , signature ) ,
1486- ) ;
14871478 const descriptor = yield * environment . getDescriptor ;
14881479 const responseExpiresAt = DateTime . add ( now , { minutes : 5 } ) ;
14891480 const responsePayload = {
@@ -1499,19 +1490,19 @@ const make = Effect.gen(function* () {
14991490 descriptor,
15001491 checkedAt : DateTime . formatIso ( now ) ,
15011492 } satisfies RelayEnvironmentHealthResponseProofPayload ;
1502- const responseProof = yield * signRelayJwt ( {
1503- privateKey : keyPair . privateKey ,
1504- typ : RELAY_HEALTH_RESPONSE_TYP ,
1505- payload : responsePayload ,
1506- } ) . pipe (
1507- Effect . provideService ( Signature . Signature , signature ) ,
1508- Effect . mapError (
1509- ( cause ) =>
1510- new EnvironmentAuth . ServerAuthCloudHealthJwtSigningError ( {
1511- cause,
1512- } ) ,
1513- ) ,
1514- ) ;
1493+ const responseProof = yield * signingKey
1494+ . sign ( {
1495+ typ : RELAY_HEALTH_RESPONSE_TYP ,
1496+ payload : responsePayload ,
1497+ } )
1498+ . pipe (
1499+ Effect . mapError (
1500+ ( cause ) =>
1501+ new EnvironmentAuth . ServerAuthCloudHealthJwtSigningError ( {
1502+ cause,
1503+ } ) ,
1504+ ) ,
1505+ ) ;
15151506 return {
15161507 environmentId,
15171508 status : "online" ,
@@ -1587,9 +1578,6 @@ const make = Effect.gen(function* () {
15871578 return yield * new CloudLinkProofReplayedError ( { request : "mint" } ) ;
15881579 }
15891580
1590- const keyPair = yield * getOrCreateEnvironmentKeyPairFromSecretStore ( secrets ) . pipe (
1591- Effect . provideService ( Signature . Signature , signature ) ,
1592- ) ;
15931581 const issued = yield * environmentAuth . createPairingLink ( {
15941582 scopes : AuthStandardClientScopes ,
15951583 subject : "cloud-connect" ,
@@ -1609,19 +1597,19 @@ const make = Effect.gen(function* () {
16091597 requestNonce : proof . nonce ,
16101598 credential : issued . credential ,
16111599 } satisfies RelayEnvironmentMintResponseProofPayload ;
1612- const responseProof = yield * signRelayJwt ( {
1613- privateKey : keyPair . privateKey ,
1614- typ : RELAY_MINT_RESPONSE_TYP ,
1615- payload : responsePayload ,
1616- } ) . pipe (
1617- Effect . provideService ( Signature . Signature , signature ) ,
1618- Effect . mapError (
1619- ( cause ) =>
1620- new EnvironmentAuth . ServerAuthCloudMintJwtSigningError ( {
1621- cause,
1622- } ) ,
1623- ) ,
1624- ) ;
1600+ const responseProof = yield * signingKey
1601+ . sign ( {
1602+ typ : RELAY_MINT_RESPONSE_TYP ,
1603+ payload : responsePayload ,
1604+ } )
1605+ . pipe (
1606+ Effect . mapError (
1607+ ( cause ) =>
1608+ new EnvironmentAuth . ServerAuthCloudMintJwtSigningError ( {
1609+ cause,
1610+ } ) ,
1611+ ) ,
1612+ ) ;
16251613 return {
16261614 credential : issued . credential ,
16271615 expiresAt : DateTime . formatIso ( issued . expiresAt ) ,
0 commit comments