@@ -13,23 +13,29 @@ import { Logger } from '../../../logger';
1313
1414const logger = Logger ( 'sdx-p2p-provider-pattern' ) ;
1515
16+ // TODO: clean this up a bit!
17+ const SDX_KONG_URL =
18+ process . env . SDX_KONG_URL || 'http://sdx-konghc-kong-admin:8001' ;
19+
20+ interface ProviderUpgrades {
21+ sign : { } ;
22+ verify : { } ;
23+ token_exchange : {
24+ token_endpoint : string ;
25+ client_id : string ;
26+ scopes : string [ ] ;
27+ audience : string ;
28+ } ;
29+ }
30+
1631export interface SDXP2PProviderPatternConfig extends Record < string , any > {
1732 organization : string ;
1833 conn_id : string ;
1934 client_id : string ;
2035 service_id : string ;
2136 upstream_url : string ;
22- upgrades : string ;
37+ upgrades : ProviderUpgrades ;
2338 use_sni : string ;
24- kms_key_id ?: string ;
25- upgrade_config : {
26- token_exchange : {
27- token_endpoint : string ;
28- client_id : string ;
29- scopes : string [ ] ;
30- audience : string ;
31- } ;
32- } ;
3339}
3440
3541export interface SDXP2PProviderPatternData {
@@ -75,7 +81,7 @@ export const SDXP2PProviderPattern = {
7581
7682 let key : KongKey = undefined ;
7783 if ( upgrades . includes ( 'org-kms-sign' ) ) {
78- const keys = new KongKeys ( 'http://sdx-konghc-kong-admin:8001' ) ;
84+ const keys = new KongKeys ( SDX_KONG_URL ) ;
7985
8086 key = await keys . getKeyByName ( name ) ;
8187
@@ -90,7 +96,7 @@ export const SDXP2PProviderPattern = {
9096 } ;
9197 } ,
9298
93- eval : ( inputs : Record < string , string > , data : SDXP2PProviderPatternData ) => {
99+ eval : ( inputs : Record < string , any > , data : SDXP2PProviderPatternData ) => {
94100 const serviceLocator = data . service . name ;
95101 const serviceHost = data . service . subsystem . runtimeGroup . host ;
96102
@@ -103,7 +109,7 @@ export const SDXP2PProviderPattern = {
103109
104110 const upstreamUrl = inputs . upstream_url ;
105111
106- const upgrades = inputs . upgrades || '' ;
112+ const upgrades : ProviderUpgrades = inputs . upgrades || { } ;
107113
108114 return [
109115 {
@@ -153,20 +159,13 @@ export const SDXP2PProviderPattern = {
153159 tags : [ ...tags , `service:${ serviceLocator } ` , `client:${ clientLocator } ` ] ,
154160 url : upstreamUrl ,
155161 plugins : [
156- ...( upgrades . includes ( 'edge- sign')
162+ ...( upgrades . hasOwnProperty ( ' sign')
157163 ? [ upgradeToTrustSign ( tags , data ) ]
158164 : [ ] ) ,
159- ...( upgrades . includes ( 'edge- verify')
165+ ...( upgrades . hasOwnProperty ( ' verify')
160166 ? [ upgradeToTrustVerify ( tags , data ) ]
161167 : [ ] ) ,
162- ...( upgrades . includes ( 'org-kms-sign' )
163- ? [ upgradeToTrustKMSSign ( tags , data ) ]
164- : [ ] ) ,
165- ...( upgrades . includes ( 'timestamp' )
166- ? [ upgradeToTimestamp ( tags , data ) ]
167- : [ ] ) ,
168- ...( upgrades . includes ( 'ledger' ) ? [ upgradeToLedger ( tags , data ) ] : [ ] ) ,
169- ...( upgrades . includes ( 'token-exchange' )
168+ ...( upgrades . hasOwnProperty ( 'token_exchange' )
170169 ? [
171170 upgradeToTokenExchange (
172171 tags ,
@@ -213,65 +212,27 @@ function upgradeToTrustVerify(tags: string[], data: SDXP2PProviderPatternData) {
213212 } ;
214213}
215214
216- function upgradeToTrustKMSSign (
217- tags : string [ ] ,
218- data : SDXP2PProviderPatternData
219- ) {
220- if ( data . key == null ) {
221- logger . warn ( 'Unable to configure trust KMS - no key found' ) ;
222- }
223- return {
224- name : 'trust-kms' ,
225- tags : tags ,
226- config : {
227- direction : 'response' ,
228- operation : 'sign' ,
229- signature_header_key : 'X-Edge-Token' ,
230- key_id : data . key ?. kid ,
231- } ,
232- } ;
233- }
234-
235- function upgradeToTimestamp ( tags : string [ ] , data : SDXP2PProviderPatternData ) {
236- return {
237- name : 'trust-timestamp' ,
238- tags : tags ,
239- config : {
240- endpoint_url : 'https://freetsa.org/tsr' ,
241- policy_oid : '1.2.1.2.1' ,
242- } ,
243- } ;
244- }
245-
246- function upgradeToLedger ( tags : string [ ] , data : SDXP2PProviderPatternData ) {
247- return {
248- name : 'trust-ledger' ,
249- tags : tags ,
250- config : {
251- endpoint_url : 'https://rekor.sigstore.dev' ,
252- provider : 'rekor' ,
253- } ,
254- } ;
255- }
256-
257215function upgradeToTokenExchange (
258216 tags : string [ ] ,
259217 data : SDXP2PProviderPatternData ,
260218 inputs : SDXP2PProviderPatternConfig
261219) {
220+ const tokenExchangeConfig = inputs . upgrades . token_exchange ;
221+
262222 const kid = `urn:ca:bc:sdx:edge:${ data . service . subsystem . runtimeGroup . name } :edge` ;
223+
263224 return {
264225 name : 'token-exchange' ,
265226 tags : tags ,
266227 config : {
267- token_endpoint : inputs . upgrade_config ?. token_exchange ?. token_endpoint ,
268- client_id : inputs . upgrade_config ?. token_exchange ?. client_id ,
228+ client_id : tokenExchangeConfig ?. client_id ,
229+ token_endpoint : tokenExchangeConfig ?. token_endpoint ,
230+ scopes : tokenExchangeConfig ?. scopes ,
231+ audience : tokenExchangeConfig ?. audience ,
232+ key_id : kid ,
269233 private_key_location : '/etc/secrets/sdx-edge-signing-cert/tls.key' ,
270234 algorithm : 'ES256' ,
271235 expiration : 60 ,
272- key_id : kid ,
273- scopes : inputs . upgrade_config ?. token_exchange ?. scopes ,
274- audience : inputs . upgrade_config ?. token_exchange ?. audience ,
275236 } ,
276237 } ;
277238}
0 commit comments