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

ACM-8739: ACM Policy that applies stringdata in a secret regression with templates #179

Merged
Merged
Changes from all commits
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
14 changes: 8 additions & 6 deletions controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2410,27 +2410,29 @@ func handleSingleKey(
}

if key == "stringData" && existingObj.GetKind() == "Secret" {
// override automatic conversion from stringData to data prior to evaluation
existingValue = existingObj.UnstructuredContent()["data"]

// override automatic conversion from stringData to data before evaluation
encodedValue, _, err := unstructured.NestedStringMap(existingObj.Object, "data")
if err != nil {
message := "Error accessing encoded data"

return message, false, mergedValue, false
}

for k, value := range encodedValue {
decodedVal, err := base64.StdEncoding.DecodeString(value)
decodedValue := make(map[string]interface{}, len(encodedValue))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this

existingValue.(map[string]interface{})[k] = string(decodedVal)
? because of this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for k, encoded := range encodedValue {
decoded, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
secretName := existingObj.GetName()
message := fmt.Sprintf("Error decoding secret: %s", secretName)

return message, false, mergedValue, false
}

existingValue.(map[string]interface{})[k] = string(decodedVal)
decodedValue[k] = string(decoded)
}

existingValue = decodedValue
}

// sort objects before checking equality to ensure they're in the same order
Expand Down