pulumi/pkg/backend/display
Daniel Bradley 275ab73ba7
Simplify deployment deserialization encyption (#18603)
1. Remove unused error returns when constructing an `Encrypter` or
`Decrypter` from a `SecretManager`.
2. Remove passing an `Encrypter` into the deserialization methods.

## Design rational

1. We were calling encrypt within deserialize whenever the source was
plaintext, but would just discard the result if the decrypter wasn't an
instance of `cachingCrypter`. Therefore the first optimisation we can
make is to only encrypt after we've established that we've got a
`cachingCrypter` to write to.
3. When the decrypter is a `cachingCrypter`, it must have been created
by the `cachingManager` and so we know that the encrypter also came from
the `cachingManager`. However, the `cachingCrypter` was instantiated
twice - once with only an encrypter and once with only a decrypter. If
we make the encrypter available within the same instance of the
`cachingCrypter`, then we can use the encrypter from the instance
instead of requiring the encrypter to be passed in as a separate
argument.
4. If the `cachingCrypter` class is just implementing the Encrypter and
Decrypter interfaces with the values from the `cachingSecretsManager`,
we could just implement these interfaces directly on the
`cachingSecretsManager` instead to avoid copying references to the cache
into the `cachingCrypter`. This makes it much easier to follow how the
cache gets reused between the decrypter and encrypter instances as
they're now the same object.

Adding the crypter interface onto the `cachingSecretsManager` makes it
easiest to fetch the underlying encrypter and decrypter instances within
the constructor which opens a couple of questions:

### Is both Encrypter and Decrypter always available?

- Passphrase, service, cloud and base64 secret managers only have a
single crypter object returned from both Encrypter and Decrypter
methods.
- The cachingSecretsManager just calls through to the provided Encrypter
or Decrypter.
- Only the MockSecretsManager could have only one of the encrypter or
decrypter set up. However, this panics rather than returns an error.

### In what situations are we returned an error when asking the
SecretManager for an Encrypter or Decrypter?
- Never.

Therefore, we can just delete the error returns from all `SecretManager`
`Encrypter()` and `Decrypter()` methods.

Finally, having moved the `EncryptValue` call to the
`cachingSecretsManager`, we no longer use the encrypter on any code
paths for Snapshot deserialization and can remove all unused instances
of this argument.

Commits are factored to separate out these logical steps for review.

## Pending questions

> Why do we call encrypt at all during deserialization?

It appears the purpose it to prime the cache so that all existing
secrets are contained in the cache after deserialization so we're able
to re-serialize it very quickly, if unchanged.

> Do we always need these cached values?

Not always. The cache is only _required_ when round-tripping a
deployment, which could in theory be done using a NoopCrypter which
never really deserializes the secrets but just sets the plaintexts to
the ciphertext then reverses the process during serialization.

Therefore we can't entirely remove the process of injecting the secret
values into the cache, but this should allow us to simplify further with
the new abstractions being built for bulk serialization in
https://github.com/pulumi/pulumi/pull/18576
2025-02-17 10:15:45 +00:00
..
internal/terminal Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
testdata Show the count of unchanged resources (#17257) 2024-09-17 08:41:53 +00:00
wasm [display] Enable WASM compilation (#16246) 2024-05-24 20:27:56 +00:00
diff.go Add --show-secrets flag for up command (#18503) 2025-02-14 20:33:29 +00:00
diff_test.go Fix rendering of output events in rendering update diffs (#17029) 2024-08-27 18:37:03 +00:00
display.go Move `sdk/go/common/channel` to `pkg` (#17895) 2024-12-02 16:25:50 +00:00
display_test.go Include all engine events in the event log (#17101) 2024-08-30 10:31:19 +00:00
doc.go
events.go Simplify deployment deserialization encyption (#18603) 2025-02-17 10:15:45 +00:00
events_test.go Don't omit an empty detailedDiff (#15213) 2024-01-23 00:00:14 +00:00
json.go Fix deletes not being show in `refresh` when using json output (#16851) 2024-09-09 10:16:10 +00:00
jsonmessage.go Hide unnecessary rows in non-interactive mode (#17188) 2024-09-09 07:44:27 +00:00
object_diff.go Add --show-secrets flag for up command (#18503) 2025-02-14 20:33:29 +00:00
object_diff_test.go Add --show-secrets flag for up command (#18503) 2025-02-14 20:33:29 +00:00
options.go Add --show-secrets flag for up command (#18503) 2025-02-14 20:33:29 +00:00
progress.go Add --show-secrets flag for up command (#18503) 2025-02-14 20:33:29 +00:00
progress_bar.go Use events to report downloads as system messages (#17019) 2024-09-03 12:12:04 +00:00
progress_bar_test.go Use events to report downloads as system messages (#17019) 2024-09-03 12:12:04 +00:00
progress_test.go Always print summaries in preview (#18465) 2025-02-06 14:20:10 +00:00
query.go Use events to report downloads as system messages (#17019) 2024-09-03 12:12:04 +00:00
rows.go Display `[retain]` in all cases of delete retention (#16506) 2024-06-28 23:19:26 +00:00
sigint_unix.go
sigint_windows.go
tableutil.go
tree.go Show the count of unchanged resources (#17257) 2024-09-17 08:41:53 +00:00
tree_test.go Clean up display rewinding and wrapping (#17007) 2024-08-19 15:30:48 +00:00
watch.go Enable some more linting rules (#17456) 2024-10-03 17:37:13 +00:00