-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Data aws_kms_secrets always changing on plan and exposing plaintext secrets #14564
Comments
Similar (data source |
While the changing |
@jbardin Indeed, and I think running acceptance tests with TF 0.13 will flush out many more such cases. |
I'm also hitting this issue - we have a CI run that validates no drift in configuration. This currently runs: terraform plan -input=false -detailed-exitcode We now see output:
Terraform then returns exit code 2 indicating there is a diff even though there is nothing to apply. This completely breaks our validation pipeline. |
Also curious why the |
My temporary hack is to filter the output with terraform ..... | perl -p0e 's/plaintext(.*?)=.*?}\n/\n ---removed-secret----\n/s' so a plaintext secret from |
@pwilczynskiclearcode I took a similar approach but built a wrapper with support to filter out other secrets from non-conforming providers. For example, we get leaks from AWS CF objects with DB connection strings. When you find other patterns to filter, just drop them in the the Just call [terraform.sh] #!/usr/bin/env bash
set -euo pipefail
BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Wrapper around terraform which filters the output from terraform apply / plan to redact secrets and sensitive tokens.
# Primarily called from CI validation runs to ensure secrets are not logged in job output.
if [[ $@ != *'plan'* ]] && [[ $@ != *'apply'* ]]; then
terraform $@ || exit $?
return
fi
# Fall through to execute filtered "apply" or "plan" action.
TEMP_LOG=$(mktemp)
cleanup_on_exit() {
EXIT_CODE=$?
rm -f ${TEMP_LOG}
exit ${EXIT_CODE}
}
trap cleanup_on_exit EXIT SIGHUP SIGINT SIGTERM
# Ensure -no-color flag is present so we can filter pure text content with grep and sed
if [[ $@ != *'-no-color'* ]]; then
echo "Error: required \"-no-color\" flag is missing in args: $@"
exit 1
fi
# Apply verb (plan or apply) and filter output to redact sensitive data
terraform $@ 2>&1 | \
sed -f "${BASEDIR}/terraform.sed" | \
tee "${TEMP_LOG}"
# Validate output has zero diffs. Note that we cannot currently make use of -detailed-exitcode due to the
# https://github.com/terraform-providers/terraform-provider-aws/issues/14564 which shows perpetual data diffs
# on aws_kms_secrets.
grep -qE '^Plan: 0 to add, 0 to change, 0 to destroy\.$|^No changes. Infrastructure is up-to-date.$' ${TEMP_LOG} || exit 2 [terraform.sed] # post-process the output of `terraform plan` in order to redact sensitive secrets and tokens.
# Remove data-diff output for "aws_kms_secret"
# <= data "aws_kms_secrets" ... {
# ...
# }
#
/ <= data "aws_kms_secrets" .*{/,/^ }/d
# Redact Datapipeline password
# Key: '*password'
# StringValue: <password>
#
/Key: '\*password'$/{
N
s/StringValue: .*$/StringValue: ***REDACTED***/
} |
This has been partially addressed with the merge of #15169 (to release with |
Upgrading to AWS Provider 3.12.0 from 2.x fixed the secrets leak. Now I see:
But the ID still changes every apply. I've seen other providers pushing fixes for that part of the problem, but it doesn't look fixed on the AWS provider. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Community Note
Terraform CLI and Terraform AWS Provider Version
terraform v0.13.0
aws provider v3.1.0
Affected Resource(s)
data aws_kms_secrets
Terraform Configuration Files
This is just one example, where we use several kms encrypted secrets to fill our kubernetes secrets
Expected Behavior
when nothing changed it will not appear in the terraform plan
I expect the plaintext secrets to be an output and not printed in the plan phase
Actual Behavior
the data output is printed every time there is a plan, because the ID is a date time
("2020-08-11 15:34:53.668567 +0000 UTC")
the data aws_kms_secrets is also printing in the output the plaintext map with keys and values
fake plan example:
Steps to Reproduce
create a resource aws_kms_secrets and use the data aws_kms_secrets after to test.
The text was updated successfully, but these errors were encountered: