@@ -7,6 +7,7 @@ package secret
77import (
88 "context"
99 "encoding/json"
10+ "fmt"
1011 "regexp"
1112 "strconv"
1213 "strings"
@@ -323,17 +324,20 @@ func setSecretPath(section smap.Map, secretValue string, secretPaths []string) {
323324}
324325
325326// Read secret from output and mutate output with secret value
326- func ProcessOutputSecret (output smap.Map , secretValues map [string ]string ) []string {
327+ func ProcessOutputSecret (output smap.Map , secretValues map [string ]string ) ( []string , error ) {
327328
328329 // Unfortunately, there are two ways (formats) of specifying secret references in
329330 // policies: inline and path (see https://github.com/elastic/fleet-server/pull/5852).
330331 // So we try replacing secret references in both formats.
331332
332- keys := processMapWithInlineSecrets (output , secretValues )
333+ keys , err := processMapWithInlineSecrets (output , secretValues )
334+ if err != nil {
335+ return nil , fmt .Errorf ("failed processing output secret with inline secrets: %w" , err )
336+ }
333337 k := processMapWithPathSecrets (output , secretValues )
334338
335339 keys = append (keys , k ... )
336- return keys
340+ return keys , nil
337341}
338342
339343// processMapWithPathSecrets reads secrets from the output and mutates the output with the secret values using
@@ -370,26 +374,31 @@ func processMapWithPathSecrets(m smap.Map, secretValues map[string]string) []str
370374 return keys
371375}
372376
373- func processMapWithInlineSecrets (m smap.Map , secretValues map [string ]string ) []string {
377+ func processMapWithInlineSecrets (m smap.Map , secretValues map [string ]string ) ( []string , error ) {
374378 replacedM , keys := replaceInlineSecretRefsInMap (m , secretValues )
375379 for _ , key := range keys {
376380 rm := smap .Map (replacedM )
377- m .Set (key , rm .Get (key ))
381+ if err := m .Set (key , rm .Get (key )); err != nil {
382+ return nil , fmt .Errorf ("failed processing map with inline secrets: failed to set secret value for key %s: %w" , key , err )
383+ }
378384 }
379- return keys
385+ return keys , nil
380386}
381387
382388// ProcessMapSecrets reads and replaces secrets in the agent.download section of the policy
383- func ProcessMapSecrets (m smap.Map , secretValues map [string ]string ) []string {
389+ func ProcessMapSecrets (m smap.Map , secretValues map [string ]string ) ( []string , error ) {
384390 // Unfortunately, there are two ways (formats) of specifying secret references in
385391 // policies: inline and path (see https://github.com/elastic/fleet-server/pull/5852).
386392 // So we try replacing secret references in both formats.
387393
388- keys := processMapWithInlineSecrets (m , secretValues )
394+ keys , err := processMapWithInlineSecrets (m , secretValues )
395+ if err != nil {
396+ return nil , fmt .Errorf ("failed processing map secrets with inline secrets: %w" , err )
397+ }
389398 k := processMapWithPathSecrets (m , secretValues )
390399
391400 keys = append (keys , k ... )
392- return keys
401+ return keys , nil
393402}
394403
395404// replaceStringRef replaces values matching a secret ref regex, e.g. $co.elastic.secret{<secret ref>} -> <secret value>
0 commit comments