Skip to content

Input stringData gets stripped completely #302

Closed
@danopia

Description

@danopia

It appears as though the redactSecrets method is using stringData as a behind-the-scenes crutch to print a redacted data diff:

helm-diff/diff/diff.go

Lines 94 to 129 in 818e596

if old != nil {
oldSecret.StringData = make(map[string]string, len(oldSecret.Data))
for k, v := range oldSecret.Data {
if new != nil && bytes.Equal(v, newSecret.Data[k]) {
oldSecret.StringData[k] = fmt.Sprintf("REDACTED # (%d bytes)", len(v))
} else {
oldSecret.StringData[k] = fmt.Sprintf("-------- # (%d bytes)", len(v))
}
}
}
if new != nil {
newSecret.StringData = make(map[string]string, len(newSecret.Data))
for k, v := range newSecret.Data {
if old != nil && bytes.Equal(v, oldSecret.Data[k]) {
newSecret.StringData[k] = fmt.Sprintf("REDACTED # (%d bytes)", len(v))
} else {
newSecret.StringData[k] = fmt.Sprintf("++++++++ # (%d bytes)", len(v))
}
}
}
// remove Data field now that we are using StringData for serialization
var buf bytes.Buffer
if old != nil {
oldSecret.Data = nil
if err := serializer.Encode(&oldSecret, &buf); err != nil {
}
old.Content = getComment(old.Content) + strings.Replace(strings.Replace(buf.String(), "stringData", "data", 1), " creationTimestamp: null\n", "", 1)
buf.Reset() //reuse buffer for new secret
}
if new != nil {
newSecret.Data = nil
if err := serializer.Encode(&newSecret, &buf); err != nil {
}
new.Content = getComment(new.Content) + strings.Replace(strings.Replace(buf.String(), "stringData", "data", 1), " creationTimestamp: null\n", "", 1)

The issue is that if the chart being diffed uses stringData then all those fields are completely hidden from the diff output. For example, this template:

---
apiVersion: v1
kind: Secret
metadata:
  name: {{ $config.name }}
type: Opaque
stringData:
  kongCredType: acl
  group: inbound-traffic
  otherField: |
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    Sed sed felis id ex ultricies tempor.

shows as this in helm-diff:

my-namespace, my-name, Secret (v1) has been added:
+ # Source: secret.yaml
+ apiVersion: v1
+ kind: Secret
+ metadata:
+   name: my-name
+ type: Opaque

This effectively defeats the diffing for any secret values that do not need to be redacted.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions