What happened?
filterSensitiveInformation fails to redact multiline string values (PEM private keys, passwords, certificates) from Terraform diagnostic output.
|
func (ts Setup) filterSensitiveInformation(s string) string { |
|
for _, v := range ts.Configuration { |
|
if str, ok := v.(string); ok && str != "" { |
|
s = strings.ReplaceAll(s, str, "REDACTED") |
|
} |
|
} |
|
return s |
|
} |
The filter value is the raw Go string however, Terraform's diagnostic output is JSON. The sensitive value goes through two levels of JSON encoding before reaching the filter:
- upjet writes
ps.Configuration to main.tf.json (1st encoding: real \n -> \\n in JSON source)
- Terraform outputs diagnostics with
main.tf.json content embedded in a snippet.code field (2nd encoding: \\n -> \\\\n)
The raw subprocess output therefore contains \\n where the filter value has \n. strings.ReplaceAll finds no match and the sensitive value is logged in plaintext.
How can we reproduce it?
Using any upjet-based provider that puts a PEM private key in ps.Configuration e.g. provider-okta
Expected: all values in ps.Configuration appear as REDACTED in Terraform diagnostic log output.
Actual: base_url, client_id, org_name are redacted; private_key appears in plaintext in the snippet.code field of diagnostic output:
\\\"client_id\\\":\\\"REDACTED\\\",\\\"org_name\\\":\\\"REDACTED\\\",\\\"private_key\\\":\\\"-----BEGIN PRIVATE KEY-----\\\\n...
References
What happened?
filterSensitiveInformationfails to redact multiline string values (PEM private keys, passwords, certificates) from Terraform diagnostic output.upjet/pkg/terraform/store.go
Lines 327 to 334 in a4d9eb9
The filter value is the raw Go string however, Terraform's diagnostic output is JSON. The sensitive value goes through two levels of JSON encoding before reaching the filter:
ps.Configurationtomain.tf.json(1st encoding: real\n->\\nin JSON source)main.tf.jsoncontent embedded in asnippet.codefield (2nd encoding:\\n->\\\\n)The raw subprocess output therefore contains
\\nwhere the filter value has\n.strings.ReplaceAllfinds no match and the sensitive value is logged in plaintext.How can we reproduce it?
Using any upjet-based provider that puts a PEM private key in
ps.Configuratione.g. provider-oktaExpected: all values in
ps.Configurationappear asREDACTEDin Terraform diagnostic log output.Actual:
base_url,client_id,org_nameare redacted;private_keyappears in plaintext in thesnippet.codefield of diagnostic output:References