@@ -24,14 +24,10 @@ import {
2424} from 'cli-testing' ;
2525
2626import { extractPropertyFromResults } from '../common/utils' ;
27+ import { getSecretByLabel , getSecretField } from 'steps/utils/kubernetes' ;
2728import ZenkoDrctl from 'steps/dr/drctl' ;
2829import assert from 'assert' ;
2930
30- interface ServiceUsersCredentials {
31- accessKey : string ;
32- secretKey : string ;
33- }
34-
3531// Zenko entities
3632export interface SavedIdentity {
3733 identityName : string ;
@@ -54,8 +50,8 @@ export interface ZenkoWorldParameters extends ClientOptions {
5450 AccountName : string ;
5551 AccountAccessKey : string ;
5652 AccountSecretKey : string ;
57- DRAdminAccessKey ? : string ;
58- DRAdminSecretKey ? : string ;
53+ AdminAccessKey : string ;
54+ AdminSecretKey : string ;
5955 DRSubdomain ?: string ;
6056 VaultAuthHost : string ;
6157 NotificationDestination : string ;
@@ -83,7 +79,6 @@ export interface ZenkoWorldParameters extends ClientOptions {
8379 StorageAccountOwnerUsername : string ;
8480 DataConsumerUsername : string ;
8581 DataAccessorUsername : string ;
86- ServiceUsersCredentials : string ;
8782 KeycloakTestPassword : string ;
8883 AzureAccountName : string ;
8984 AzureAccountKey : string ;
@@ -93,17 +88,14 @@ export interface ZenkoWorldParameters extends ClientOptions {
9388 AzureArchiveManifestTier : string ;
9489 AzureArchiveQueue : string ;
9590 TimeProgressionFactor : number ;
96- KafkaDeadLetterQueueTopic : string ;
97- KafkaObjectTaskTopic : string ;
98- KafkaGCRequestTopic : string ;
9991 InstanceID : string ;
10092 BackbeatApiHost : string ;
10193 BackbeatApiPort : string ;
10294 KafkaCleanerInterval : string ;
10395 SorbetdRestoreTimeout : string ;
10496 UtilizationServiceHost : string ;
10597 UtilizationServicePort : string ;
106- [ key : string ] : unknown ;
98+ KubeconfigPath ? : string ;
10799}
108100
109101/**
@@ -137,26 +129,19 @@ export default class Zenko extends World<ZenkoWorldParameters> {
137129 static readonly SECONDARY_SITE_NAME = 'dradmin' ;
138130 static readonly PRA_INSTALL_COUNT_KEY = 'praInstallCount' ;
139131
132+ static kafkaTopics : {
133+ deadLetterQueue : string ;
134+ objectTask : string ;
135+ gcRequest : string ;
136+ } ;
137+
140138 /**
141139 * @constructor
142140 * @param {Object } options - parameters provided as a CLI parameter when running the tests
143141 */
144142 constructor ( options : IWorldOptions < ZenkoWorldParameters > ) {
145143 super ( options ) ;
146144 Logger . createLogger ( this ) ;
147- // store service users credentials from world parameters
148- if ( this . parameters . ServiceUsersCredentials ) {
149- const serviceUserCredentials =
150- JSON . parse ( this . parameters . ServiceUsersCredentials ) as Record < string , ServiceUsersCredentials > ;
151- for ( const serviceUserName in serviceUserCredentials ) {
152- if ( ! Identity . hasIdentity ( IdentityEnum . SERVICE_USER , serviceUserName , this . parameters . AccountName ) ) {
153- Identity . addIdentity ( IdentityEnum . SERVICE_USER , serviceUserName , {
154- accessKeyId : serviceUserCredentials [ serviceUserName ] . accessKey ,
155- secretAccessKey : serviceUserCredentials [ serviceUserName ] . secretKey ,
156- } , this . parameters . AccountName ) ;
157- }
158- }
159- }
160145
161146 // Workaround to be able to access global parameters in BeforeAll/AfterAll hooks
162147 CacheHelper . cacheParameters ( {
@@ -191,29 +176,11 @@ export default class Zenko extends World<ZenkoWorldParameters> {
191176 } ;
192177 }
193178
194- if ( this . needsSecondarySite ( ) ) {
195- if ( ! Identity . hasIdentity ( IdentityEnum . ADMIN , Zenko . SECONDARY_SITE_NAME ) ) {
196- Identity . addIdentity ( IdentityEnum . ADMIN , Zenko . SECONDARY_SITE_NAME , {
197- accessKeyId : this . parameters . DRAdminAccessKey ! ,
198- secretAccessKey : this . parameters . DRAdminSecretKey ! ,
199- } , undefined , undefined , undefined , this . parameters . DRSubdomain ) ;
200- }
201-
202- Zenko . sites [ 'sink' ] = {
203- accountName : `dr${ this . parameters . AccountName } ` ,
204- adminIdentityName : Zenko . SECONDARY_SITE_NAME ,
205- } ;
206- }
207-
208179 this . logger . debug ( 'Zenko sites' , {
209180 sites : Zenko . sites ,
210181 } ) ;
211182 }
212183
213- private needsSecondarySite ( ) {
214- return this . parameters . DRAdminAccessKey && this . parameters . DRAdminSecretKey && this . parameters . DRSubdomain ;
215- }
216-
217184 /**
218185 * This function will dynamically determine if the result from the AWS command
219186 * is a success or a failure. Based on the fact that AWS either return an empty string
@@ -630,6 +597,74 @@ export default class Zenko extends World<ZenkoWorldParameters> {
630597 this . saveIdentityInformation ( roleName , IdentityEnum . ASSUMED_ROLE , Identity . getCurrentAccountName ( ) ) ;
631598 }
632599
600+ private static async loadServiceUsers ( accountName : string ) {
601+ const instanceSelector = 'app.kubernetes.io/instance=end2end' ;
602+ const serviceUsers : Record < string , string > = {
603+ 'backbeat-lcbp-user-creds' : 'backbeat-lifecycle-bp-1' ,
604+ 'backbeat-lcc-user-creds' : 'backbeat-lifecycle-conductor-1' ,
605+ 'backbeat-lcop-user-creds' : 'backbeat-lifecycle-op-1' ,
606+ 'backbeat-qp-user-creds' : 'backbeat-qp-1' ,
607+ } ;
608+
609+ for ( const [ secretName , userName ] of Object . entries ( serviceUsers ) ) {
610+ const labelSelector = `app.kubernetes.io/name=${ secretName } ,${ instanceSelector } ` ;
611+ const raw = await getSecretByLabel ( labelSelector , `${ userName } .json` ) ;
612+ const parsed = JSON . parse ( raw ) as { accessKey : string ; secretKey : string } ;
613+ Identity . addIdentity ( IdentityEnum . SERVICE_USER , userName , {
614+ accessKeyId : parsed . accessKey ,
615+ secretAccessKey : parsed . secretKey ,
616+ } , accountName ) ;
617+ }
618+
619+ const sorbetSelector =
620+ `app.kubernetes.io/name=sorbet-fwd-creds,${ instanceSelector } ` ;
621+ const accessKey = await getSecretByLabel ( sorbetSelector , 'accessKey' ) ;
622+ const secretKey = await getSecretByLabel ( sorbetSelector , 'secretKey' ) ;
623+ Identity . addIdentity ( IdentityEnum . SERVICE_USER , 'sorbet-fwd-2' , {
624+ accessKeyId : accessKey ,
625+ secretAccessKey : secretKey ,
626+ } , accountName ) ;
627+ }
628+
629+ private static async loadSorbetConfig ( ) {
630+ const labelSelector =
631+ 'app.kubernetes.io/name=cold-sorbet-config-e2e-azure-archive' +
632+ ',app.kubernetes.io/instance=end2end' ;
633+ const raw = await getSecretByLabel ( labelSelector , 'config.json' ) ;
634+ const config = JSON . parse ( raw ) as Record < string , string > ;
635+ Zenko . kafkaTopics = {
636+ deadLetterQueue : config [ 'kafka-dead-letter-topic' ] ,
637+ objectTask : config [ 'kafka-object-task-topic' ] ,
638+ gcRequest : config [ 'kafka-gc-request-topic' ] ,
639+ } ;
640+ }
641+
642+ private static async loadPRACredentials ( parameters : ZenkoWorldParameters ) {
643+ if ( ! parameters . DRSubdomain ) {
644+ return ;
645+ }
646+ const secretName = 'end2end-pra-management-vault-admin-creds.v1' ;
647+ let accessKey : string ;
648+ let secretKey : string ;
649+ try {
650+ accessKey = await getSecretField ( secretName , 'accessKey' ) ;
651+ secretKey = await getSecretField ( secretName , 'secretKey' ) ;
652+ } catch {
653+ // PRA secret does not exist — fine for non-PRA tests
654+ return ;
655+ }
656+ if ( ! Identity . hasIdentity ( IdentityEnum . ADMIN , Zenko . SECONDARY_SITE_NAME ) ) {
657+ Identity . addIdentity ( IdentityEnum . ADMIN , Zenko . SECONDARY_SITE_NAME , {
658+ accessKeyId : accessKey ,
659+ secretAccessKey : secretKey ,
660+ } , undefined , undefined , undefined , parameters . DRSubdomain ) ;
661+ }
662+ Zenko . sites [ 'sink' ] = {
663+ accountName : `dr${ parameters . AccountName } ` ,
664+ adminIdentityName : Zenko . SECONDARY_SITE_NAME ,
665+ } ;
666+ }
667+
633668 /**
634669 * Hook Zenko is a utility function to prepare a Zenko
635670 * @param {Object.<string,*> } parameters - the client-provided parameters
@@ -639,6 +674,11 @@ export default class Zenko extends World<ZenkoWorldParameters> {
639674 CacheHelper . logger . debug ( 'Initializing Zenko' , {
640675 parameters,
641676 } ) ;
677+
678+ await Zenko . loadServiceUsers ( parameters . AccountName ) ;
679+ await Zenko . loadSorbetConfig ( ) ;
680+ await Zenko . loadPRACredentials ( parameters ) ;
681+
642682 // Create the default account for each site configured
643683 // and generate access keys for it
644684 for ( const siteKey in Zenko . sites ) {
0 commit comments