scheduled-job: keep the Slack channel token out of state via ephemeral + write-only - #37
Merged
Merged
Conversation
…otification channels Reading Slack__API_token_for_alertlib with a data source persists the token value into Terraform state (state stores the full data-source response) and from there into every saved plan file; this is how the token was exposed by the committed-tfplan incident. New notification_channel_ids input: pass full resource names of pre-created Cloud Monitoring channels and the alert policies use them directly; the data source and module-managed channel are skipped entirely, so Terraform never touches the token. The token-based path remains as a deprecated default for backward compatibility and should be removed in the next major version. Suggest releasing as scheduled-job-v0.4.0.
…raform-managed via ephemeral + write-only Reworks the previous commit per review: instead of offloading channel creation to pre-created channels, keep the Slack notification channel fully module-managed and fix the leak with the mechanism built for it. The token is read with an ephemeral resource and written via the write-only sensitive_labels.auth_token_wo argument (google provider 7.19.0+), so the value never touches Terraform state or plan files. Rotation is an explicit slack_token_rotation counter bump. Requires Terraform >= 1.11 and hashicorp/google >= 7.19.0; consumers currently pin 7.8.0 and bump the provider when they adopt v0.4.0.
Member
This seems like useless information. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The scheduled-job module reads
Slack__API_token_for_alertlibwith adata "google_secret_manager_secret_version"to build each job's Slack notification channel. Terraform state stores the full data-source response, includingsecret_data, so the token value sits in every consumer's state and every saved plan file; this is how the token was exposed by the committed-tfplan incident (see Khan/actions#274 and the consumer migrations).Change
The channel stays fully Terraform-managed; the leak is fixed with the ephemeral/write-only mechanism (https://developer.hashicorp.com/terraform/language/manage-sensitive-data/ephemeral):
ephemeral "google_secret_manager_secret_version"(never persisted to state or plans), andsensitive_labels.auth_token_wo+auth_token_wo_versionarguments, added togoogle_monitoring_notification_channelin provider 7.19.0.Rotation becomes explicit: after adding a new secret version, bump the new
slack_token_rotationvariable; the next apply re-reads the latest version and rewrites the channel token. (The old data-source design also only picked up new versions on the next plan, so nothing is lost; the bump makes the cutover reviewable.)An earlier revision of this PR added a
notification_channel_idsinput for pre-created channels; that is dropped in favor of keeping channel management in Terraform.Requirements and rollout
required_providersnow enforces both.scheduled-job-v0.4.0.7.8.0to>= 7.19.0in the two stacks that pin exactly (no committed lock files, so that is the whole change). The adoption plan should show the channel's sensitive labels updating in place; after apply plus a state refresh, the token value is gone from live state.