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

Sanitize exported stack state by scrubbing secrets #107

Merged
merged 8 commits into from
Sep 9, 2024

Conversation

thomas11
Copy link
Contributor

@thomas11 thomas11 commented Sep 6, 2024

When upgrade tests persist stack.json, it contains secrets, making it unsuitable for committing. This PR adds a sanitization step that scrubs secrets, as identified by the p/p signature, from the state.

Fixes #106

upgrade.go Outdated Show resolved Hide resolved
Copy link
Contributor

@VenelinMartinov VenelinMartinov left a comment

Choose a reason for hiding this comment

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

Great! Thanks for fixing!

"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
)

const plaintextSub = "REDACTED BY PROVIDERTEST"
Copy link
Member

Choose a reason for hiding this comment

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

Won't this break the tests upon reading the state back?

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps some tests are sensitive to the secret values and some aren't. Make it optional so we can opt in or out on a per-test basis. I'd prefer eventually pulumi/pulumi#17158 as I have a hunch that "official" encrypting should also be able to decrypt upon reading, given a fixed secrets provider.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pulumi/pulumi#17158 would be great, but we should never persist and commit secrets. GH will reject them on push anyway. Not sure how a test could be not sensitive to them?

Copy link
Member

Choose a reason for hiding this comment

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

With 17158 they're persisted in encrypted form, but you're right that it might be that the passphrase or encrypting key is plaintexted somewhere in our libs, we'd need to sanity check them. To elaborate the test being sensitive, I mean that you might get a test failing if you replace a value with "REDACTED BY PROVIDERTEST" sometimes, it would seem? If the test actually cares about the value? Maybe it's rare in practice.

Copy link
Member

Choose a reason for hiding this comment

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

The passphrase is definitely hard coded. I think, for the time being a simple hard-coded value is fine for most situations. If this causes an issue in the future then we could try do do something smarter where we mirror the shape of the secret data while entirely replacing it. E.g. if it's not a string but instead an object, then sanitise all the values within the object. In practice, in tests I think 99% of secrets will be individual strings, and might not even be used.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure, IMO the cleanest is pulumi/pulumi#17158 + keeping your passphrase in GH secrets instead of sources gets you there as Pulumi already has the sanitization machinery for stack state. As to storing gRPC logs, encrypt-at-rest could do the job.

Copy link
Member

Choose a reason for hiding this comment

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

But thanks for getting something working quickly!

Sanitize by default when previewing provider upgrades.
@danielrbradley danielrbradley merged commit c0ea332 into main Sep 9, 2024
2 checks passed
@danielrbradley danielrbradley deleted the tkappler/scrub-secrets branch September 9, 2024 10:08
@pulumi-bot
Copy link

This PR has been shipped in release v0.1.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Secrets plaintexted in captured state
5 participants