@@ -355,40 +355,28 @@ func GetSplunkReadableNamespaceScopedSecretData(ctx context.Context, c splcommon
355355
356356 // Create individual token type data
357357 for _ , tokenType := range splcommon .GetSplunkSecretTokenTypes () {
358- if _ , exists := namespaceScopedSecret .Data [tokenType ]; exists {
359- splunkReadableData [tokenType ] = namespaceScopedSecret .Data [tokenType ]
360- }
358+ splunkReadableData [tokenType ] = namespaceScopedSecret .Data [tokenType ]
361359 }
362360
363- // Create default.yml with optional splunk_secret
364- defaultYmlBuilder := fmt .Sprintf (`
361+ // Create default.yml
362+ splunkReadableData [ "default.yml" ] = [] byte ( fmt .Sprintf (`
365363splunk:
366364 hec_disabled: 0
367365 hec_enableSSL: 0
368366 hec_token: "%s"
369367 password: "%s"
370- pass4SymmKey: "%s"` ,
371- namespaceScopedSecret .Data ["hec_token" ],
372- namespaceScopedSecret .Data ["password" ],
373- namespaceScopedSecret .Data ["pass4SymmKey" ])
374-
375- // Add splunk_secret only if it exists
376- if splunkSecret , exists := namespaceScopedSecret .Data ["splunk_secret" ]; exists {
377- defaultYmlBuilder += fmt .Sprintf (`
378- splunk_secret: "%s"` , splunkSecret )
379- }
380-
381- // Add idxc and shc sections
382- defaultYmlBuilder += fmt .Sprintf (`
368+ pass4SymmKey: "%s"
383369 idxc:
384370 secret: "%s"
385371 shc:
386372 secret: "%s"
387373` ,
374+ namespaceScopedSecret .Data ["hec_token" ],
375+ namespaceScopedSecret .Data ["password" ],
376+ namespaceScopedSecret .Data ["pass4SymmKey" ],
388377 namespaceScopedSecret .Data ["idxc_secret" ],
389- namespaceScopedSecret .Data ["shc_secret" ])
378+ namespaceScopedSecret .Data ["shc_secret" ]))
390379
391- splunkReadableData ["default.yml" ] = []byte (strings .TrimSpace (defaultYmlBuilder ))
392380 return splunkReadableData , nil
393381}
394382
@@ -463,19 +451,9 @@ func ApplyNamespaceScopedSecretObject(ctx context.Context, client splcommon.Cont
463451 namespacedName := types.NamespacedName {Namespace : namespace , Name : splcommon .GetNamespaceScopedSecretName (namespace )}
464452 err := client .Get (ctx , namespacedName , & current )
465453 if err == nil {
466- // Validate existing secrets according to PasswordManagement documentation
467- err = validateNamespaceScopedSecrets (scopedLog , & current )
468- if err != nil {
469- return nil , err
470- }
471-
472454 // Generate values for only missing types of tokens them
473455 var updateNeeded bool = false
474456 for _ , tokenType := range splcommon .GetSplunkSecretTokenTypes () {
475- if tokenType == "splunk_secret" {
476- // splunk_secret is optional, skip if not found
477- continue
478- }
479457 if _ , ok := current .Data [tokenType ]; ! ok {
480458 scopedLog .Info ("Namespace scoped secret exists, missing value for token" , "missingTokenType" , tokenType )
481459 if current .Data == nil || reflect .ValueOf (current .Data ).Kind () != reflect .Map {
@@ -513,7 +491,7 @@ func ApplyNamespaceScopedSecretObject(ctx context.Context, client splcommon.Cont
513491 for _ , tokenType := range splcommon .GetSplunkSecretTokenTypes () {
514492 if tokenType == "hec_token" {
515493 current .Data [tokenType ] = generateHECToken ()
516- } else if tokenType != "splunk_secret" {
494+ } else {
517495 current .Data [tokenType ] = splcommon .GenerateSecret (splcommon .SecretBytes , 24 )
518496 }
519497 }
@@ -545,40 +523,6 @@ func ApplyNamespaceScopedSecretObject(ctx context.Context, client splcommon.Cont
545523 return & current , nil
546524}
547525
548- // validateNamespaceScopedSecrets validates that all Splunk secret tokens that exist are not empty
549- // and meet their specific requirements
550- // Validates secrets documented in PasswordManagement: hec_token, password, pass4SymmKey, idxc_secret, shc_secret
551- func validateNamespaceScopedSecrets (scopedLog interface {
552- Info (msg string , keysAndValues ... interface {})
553- Error (err error , msg string , keysAndValues ... interface {})
554- }, secret * corev1.Secret ) error {
555- if secret .Data == nil {
556- scopedLog .Info ("Secret data is nil for namespace scoped secret" )
557- return nil
558- }
559-
560- // Validate each documented secret token type
561- for _ , tokenType := range splcommon .GetSplunkSecretTokenTypes () {
562- if secretValue , exists := secret .Data [tokenType ]; exists {
563- var err error
564- if tokenType == "hec_token" {
565- err = ValidateHECToken (secretValue )
566- } else {
567- err = ValidateSecret (secretValue )
568- }
569-
570- if err != nil {
571- scopedLog .Error (err , "Validation failed for secret" , "secret" , tokenType )
572- return fmt .Errorf ("validation failed for secret %s: %w" , tokenType , err )
573- }
574-
575- scopedLog .Info ("Namespace scoped secret validation passed" , "secret" , tokenType )
576- }
577- }
578-
579- return nil
580- }
581-
582526// GetSecretByName retrieves namespace scoped secret object for a given name
583527func GetSecretByName (ctx context.Context , c splcommon.ControllerClient , namespace string , logHandle string , name string ) (* corev1.Secret , error ) {
584528 var namespaceScopedSecret corev1.Secret
0 commit comments