Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csi: Fix parsing of '=' in secrets at command line and HTTP #15670

Merged
merged 2 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/15670.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
csi: Fixed a bug where secrets that include '=' were incorrectly rejected
```
2 changes: 1 addition & 1 deletion command/agent/csi_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func parseCSISecrets(req *http.Request) structs.CSISecrets {
secrets := map[string]string{}
secretkvs := strings.Split(secretsHeader, ",")
for _, secretkv := range secretkvs {
kv := strings.Split(secretkv, "=")
kv := strings.SplitN(secretkv, "=", 2)
if len(kv) == 2 {
secrets[kv[0]] = kv[1]
}
tgross marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 2 additions & 0 deletions command/agent/csi_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func TestHTTP_CSIParseSecrets(t *testing.T) {
structs.CSISecrets(map[string]string{"one": "overwrite"})},
{"one=value_one,two=value_two",
structs.CSISecrets(map[string]string{"one": "value_one", "two": "value_two"})},
{"one=value_one=two,two=value_two",
structs.CSISecrets(map[string]string{"one": "value_one=two", "two": "value_two"})},
}
for _, tc := range testCases {
req, _ := http.NewRequest("GET", "/v1/plugin/csi/foo", nil)
Expand Down
2 changes: 1 addition & 1 deletion command/volume_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (c *VolumeDeleteCommand) Run(args []string) int {

secrets := api.CSISecrets{}
for _, kv := range secretsArgs {
s := strings.Split(kv, "=")
s := strings.SplitN(kv, "=", 2)
if len(s) == 2 {
secrets[s[0]] = s[1]
} else {
Expand Down
4 changes: 2 additions & 2 deletions command/volume_snapshot_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (c *VolumeSnapshotCreateCommand) Run(args []string) int {

secrets := api.CSISecrets{}
for _, kv := range secretsArgs {
s := strings.Split(kv, "=")
s := strings.SplitN(kv, "=", 2)
if len(s) == 2 {
secrets[s[0]] = s[1]
} else {
Expand All @@ -128,7 +128,7 @@ func (c *VolumeSnapshotCreateCommand) Run(args []string) int {

params := map[string]string{}
for _, kv := range parametersArgs {
p := strings.Split(kv, "=")
p := strings.SplitN(kv, "=", 2)
if len(p) == 2 {
params[p[0]] = p[1]
}
Expand Down
2 changes: 1 addition & 1 deletion command/volume_snapshot_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (c *VolumeSnapshotDeleteCommand) Run(args []string) int {

secrets := api.CSISecrets{}
for _, kv := range secretsArgs {
s := strings.Split(kv, "=")
s := strings.SplitN(kv, "=", 2)
if len(s) == 2 {
secrets[s[0]] = s[1]
} else {
Expand Down
2 changes: 1 addition & 1 deletion command/volume_snapshot_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (c *VolumeSnapshotListCommand) Run(args []string) int {

secrets := api.CSISecrets{}
for _, kv := range secretsArgs {
s := strings.Split(kv, "=")
s := strings.SplitN(kv, "=", 2)
if len(s) == 2 {
secrets[s[0]] = s[1]
} else {
Expand Down