Skip to content

Commit f22533e

Browse files
authored
fix!: URL encode secret names in InsecureProvider (#913)
BREAKING CHANGE: Secret names with special characters (such as `/`) will be URL encoded. Existing secrets containing special characters must be recreated. Signed-off-by: FelixTing <[email protected]>
1 parent e167086 commit f22533e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Jenkinsfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//
22
// Copyright (c) 2019 Intel Corporation
3+
// Copyright (c) 2025 IOTech Ltd
34
//
45
// Licensed under the Apache License, Version 2.0 (the "License");
56
// you may not use this file except in compliance with the License.
@@ -15,5 +16,6 @@
1516
//
1617

1718
edgeXBuildGoMod (
18-
project: 'go-mod-bootstrap'
19+
project: 'go-mod-bootstrap',
20+
goVersion: '1.23'
1921
)

bootstrap/secret/insecure.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*******************************************************************************
22
* Copyright 2020-2023 Intel Corporation
3+
* Copyright 2025 IOTech Ltd
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
56
* in compliance with the License. You may obtain a copy of the License at
@@ -22,6 +23,7 @@ import (
2223
"github.com/edgexfoundry/go-mod-core-contracts/v4/errors"
2324
"net"
2425
"net/http"
26+
"net/url"
2527
"strings"
2628
"time"
2729

@@ -72,8 +74,11 @@ func (p *InsecureProvider) GetSecret(secretName string, keys ...string) (map[str
7274
return nil, err
7375
}
7476

77+
// URL encode the secretName to handle special characters like '/' which is used as key delimiter by core-keeper
78+
encodedSecretName := url.QueryEscape(secretName)
79+
7580
for _, insecureSecret := range insecureSecrets {
76-
if insecureSecret.SecretName == secretName {
81+
if insecureSecret.SecretName == encodedSecretName {
7782
if len(keys) == 0 {
7883
// If no keys are provided then all the keys associated with the specified secretName will be returned
7984
for k, v := range insecureSecret.SecretData {
@@ -119,15 +124,18 @@ func (p *InsecureProvider) StoreSecret(secretName string, secrets map[string]str
119124
return errors.NewCommonEdgeX(errors.KindNotAllowed, "can't store secrets. ConfigurationProvider is not in use or has not been properly initialized", nil)
120125
}
121126

127+
// URL encode the secretName to handle special characters like '/' which is used as key delimiter by core-keeper
128+
encodedSecretName := url.QueryEscape(secretName)
129+
122130
// insert the top-level data about the secret name
123-
err := configClient.PutConfigurationValue(config.GetInsecureSecretNameFullPath(secretName), []byte(secretName))
131+
err := configClient.PutConfigurationValue(config.GetInsecureSecretNameFullPath(encodedSecretName), []byte(encodedSecretName))
124132
if err != nil {
125133
return errors.NewCommonEdgeX(errors.KindCommunicationError, "error setting secretName value in the config provider", err)
126134
}
127135

128136
// insert each secret key/value pair
129137
for key, value := range secrets {
130-
err = configClient.PutConfigurationValue(config.GetInsecureSecretDataFullPath(secretName, key), []byte(value))
138+
err = configClient.PutConfigurationValue(config.GetInsecureSecretDataFullPath(encodedSecretName, key), []byte(value))
131139
if err != nil {
132140
return errors.NewCommonEdgeX(errors.KindCommunicationError, "error setting secretData key/value pair in the config provider", err)
133141
}

0 commit comments

Comments
 (0)