Commit graph

3736 commits

Author SHA1 Message Date
Matt Ellis 5be8b5da12 Fix lint issues
The linter had been warning me for a while that some comments we had
confused it.  I fixed this.  Then the linter found a place where we
were ignoring a return value.  Looking at it, it feels like we want to
continue in this case, so I just `contract.IgnoreError`'d it.
2019-05-15 00:02:35 -07:00
Matt Ellis e453c7db9e Eagerly validate secrets-provider option
Validate the value is well formed much earlier so you don't end up
seeing you've picked a bad value in the middle of trying to create
your new stack. Update the helptext to list currently supported
values.

Fixes #2727
2019-05-15 00:02:29 -07:00
Matt Ellis c91ddf996b Do not prompt for passphrase multiple times
The change does two things:

- Reorders some calls in the CLI to prevent trying to create a secrets
  manager twice (which would end up prompting twice).

- Adds a cache inside the passphrase secrets manager such that when
  decrypting a deployment, we can re-use the one created earlier in
  the update. This is sort of a hack, but is needed because otherwise
  we would fail to decrypt the deployment, meaning that if you had a
  secret value in your deployment *and* you were using local
  passphrase encryption *and* you had not set PULUMI_CONFIG_PASSPHRASE
  you would get an error asking you to do so.

Fixes #2729
2019-05-14 23:35:27 -07:00
Tomáš Hübelbauer 247edadd69 Make the timer demo more concise
Easier on the eyes this way IMO
2019-05-14 13:27:38 -07:00
Matt Ellis f6c25b7d2d Update Changelog for 0.17.11 2019-05-13 17:38:19 -07:00
Matt Ellis 825a461b2e Fix a SxS issue with isSecret
Because of our Proxy types, every output will return something when
you call `.isSecret` on it. However, if you call it on an output from
a version of `@pulumi/pulumi` which did not support secrets, the thing
you will get back is not undefined but rather an `Output` which wraps
undefined.

Because of this, care must be taken when reading this property and so
a small helper is introduced and used in places we care about.
2019-05-13 15:45:08 -07:00
Matt Ellis 1af821db9c Don't capture secret outputs in closures.
Until #2718 is addressed, we will just disallow capturing secret
outputs when we serialize closures.
2019-05-13 15:45:08 -07:00
Matt Ellis 5659875b18 Handel nulls/undefined correctly in marshalling
Undefined values can come as stack output during previewing, and nulls
may also be present.  Guard against both cases.
2019-05-13 10:53:35 -07:00
Matt Ellis 120bf897ed
Merge pull request #2678 from pulumi/ellismg/secrets-secretsmanager
Encrypt secrets in deployment and allow encryption scheme to vary
2019-05-10 19:35:58 -07:00
Matt Ellis 5a5d320b7d Wordsmith CHNAGELOG.md 2019-05-10 17:12:35 -07:00
Matt Ellis 8a865acf11 Don' fail early when loading passphrase secrets managers from state
This is helpful some round trip cases where we many not be able to
build the encrypter or decrypter but we will end up not needing
them. When we fail to load the manager, we return a manager that has
the correct state, but will error when it tries to preform any
operations.  However, if there are no secrets in the deployment, these
methods will never be called and we'll be able to correctly roundtrip
checkpoints even without having access to the password (since there
were no secret values to decrypt or encrypt).
2019-05-10 17:07:52 -07:00
Matt Ellis ffc6053c88 Fix --json output
We were dropping new and old states on the floor instead of including
them as part of the previewed operation due to a logic error (we want
to append them when there are no errors from serialization, vs when
there are errors).
2019-05-10 17:07:52 -07:00
Matt Ellis cad1949dba Fix an issue updating a newly created stack from the local backend
When creating a new stack using the local backend, the default
checkpoint has no deployment. That means there's a nil snapshot
created, which means our strategy of using the base snapshot's secrets
manager was not going to work. Trying to do so would result in a panic
because the baseSnapshot is nil in this case.

Using the secrets manager we are going to use to persist the snapshot
is a better idea anyhow, as that's what's actually going to be burned
into the deployment when we serialize the snapshot, so let's use that
instead.
2019-05-10 17:07:52 -07:00
Matt Ellis 25453d88bf Fix a bug in out logic for replacing secrets with [secret] 2019-05-10 17:07:52 -07:00
Matt Ellis 9926071e19 Set a passphrase in more tests 2019-05-10 17:07:52 -07:00
Matt Ellis 16932873a4 Update CHANGELOG.md 2019-05-10 17:07:52 -07:00
Matt Ellis fb1ebd0e06 Add an End to End test of secrets
This test ensures that our secrets support works by deploying
resources with a mix of secret and plantext inputs and then checks the
deployment file to ensure that everything is marked as a secret.
2019-05-10 17:07:52 -07:00
Matt Ellis 75744f1d6c Add some convience methods to pulumi.Config for getting secrets 2019-05-10 17:07:52 -07:00
Matt Ellis 7b4d6f9d5a Do not support secrets natively in the dynamic provider
All existing implementations would fail if secret values were passed
to the dyanmic provider. When the provider says it does not support
secrets, the engine will do basic secrets tracking (any outputs with
the same names as secret inputs become secrets themselves).
2019-05-10 17:07:52 -07:00
Matt Ellis a5ef966caf Update --json output for preview in light of secrets
Replace any secret properties with the string `[secret]` for now. We
can consider allowing something like allowing `--show-secrets` to show
them.
2019-05-10 17:07:52 -07:00
Matt Ellis 2ff54fa150 Push secretness "up" while deserializing objects.
Since we don't support nesting secrets (as they are modeled as
Outputs), as we deserialize, we push the secretness up to top level,
where we will correctly use it to mark the output as secret.

This fixes an issue where if you created a StackReference resource,
with a mix of secret and non secret properties, you would see the
"wire form" of the secrets as values on the `outputs` map of the
StackReference resource.
2019-05-10 17:07:52 -07:00
Matt Ellis ade9cd4588 Flush out comment on isSecret promise 2019-05-10 17:07:52 -07:00
Matt Ellis f705dde7fb Remove acceptsSecrets from InvokeRequest
In our system, we model secrets as outputs with an additional bit of
metadata that says they are secret. For Read and Register resource
calls, our RPC interface says if the client side of the interface can
handle secrets being returned (i.e. the language SDK knows how to
sniff for the special signiture and resolve the output with the
special bit set).

For Invoke, we have no such model. Instead, we return a `Promise<T>`
where T's shape has just regular property fields.  There's no place
for us to tack the secretness onto, since there are no Outputs.

So, for now, don't even return secret values back across the invoke
channel. We can still take them as arguments (which is good) but we
can't even return secrets as part of invoke calls. This is not ideal,
but given the way we model these sources, there's no way around
this.  Fortunately, the result of these invoke calls are not stored in
the checkpoint and since the type is not Output<T> it will be clear
that the underlying value is just present in plaintext. A user that
wants to pass the result of an invoke into a resource can turn an
existing property into a secret via `pulumi.secret`.
2019-05-10 17:07:52 -07:00
Matt Ellis cb59c21c01 Rename SecretOutputs to AdditionalSecretOutputs
This makes the intention of this field clearer.
2019-05-10 17:07:52 -07:00
Matt Ellis ae4d126d8c Support Secrets in Python SDK
A new static method, `secret` now exists on `pulumi.Output` which can
be used to create secrets.
2019-05-10 17:07:52 -07:00
Matt Ellis b7fbe74404 Remove errant import 2019-05-10 17:07:52 -07:00
Matt Ellis 70e16a2acd Allow using the passphrase secrets manager with the pulumi service
This change allows using the passphrase secrets manager when creating
a stack managed by the Pulumi service.  `pulumi stack init`, `pulumi
new` and `pulumi up` all learned a new optional argument
`--secrets-provider` which can be set to "passphrase" to force the
passphrase based secrets provider to be used.  When unset the default
secrets provider is used based on the backend (for local stacks this
is passphrase, for remote stacks, it is the key managed by the pulumi
service).

As part of this change, we also initialize the secrets manager when a
stack is created, instead of waiting for the first time a secret
config value is stored. We do this so that if an update is run using
`pulumi.secret` before any secret configuration values are used, we
already have the correct encryption method selected for a stack.
2019-05-10 17:07:52 -07:00
Matt Ellis ce4b585065 Don't show secret outputs by default on the CLI
When using `pulumi stack` or `pulumi stack output`, we were showing
secret values in the worst way possible. They were displayed in our
object structure with a signature key that denoted they were secrets
but they were not encrypted, so you still saw the underlying value.

To be able to continue to leverage the mechanisms we have for
serializing property maps, we add a rewriting step where we make a
pass over the property map before we serialize it. For any secret
values we find, if `--show-secrets` was passed, we simply replace the
secret value with the underlying element it wraps (this ensures that
we don't serialize it as a rich object with the signature key). If
`--show-secrets` was not passed, we simply replace it with a new
string property with the value `[secret]`.

This mimics the behavor we see from the stack outputs we see when you
complete a `pulumi update`
2019-05-10 17:07:52 -07:00
Matt Ellis 39894e4843 Stop using the Base64SecretsManager in cmd
We have now done all the work needed such that we can start passing
the passphrase and service secrets managers into the engine to be used
when storing values.

With this change `pulumi up` will now correctly encrypt secrets
instead of just base64 encoding them.
2019-05-10 17:07:52 -07:00
Matt Ellis e5d3a20399 Use "passphrase" and "service" instead of "local" and "cloud" 2019-05-10 17:07:52 -07:00
Matt Ellis 88012c4d96 Enable "cloud" and "local" secrets managers across the system
We move the implementations of our secrets managers in to
`pkg/secrets` (which is where the base64 one lives) and wire their use
up during deserialization.

It's a little unfortunate that for the passphrase based secrets
manager, we have to require `PULUMI_CONFIG_PASSPHRASE` when
constructing it from state, but we can make more progress with the
changes as they are now, and I think we can come up with some ways to
mitigate this problem a bit (at least make it only a problem for cases
where you are trying to take a stack reference to another stack that
is managed with local encryption).
2019-05-10 17:07:52 -07:00
Matt Ellis 207219dc9f Remove unused method
Logs are no longer provided by the service (this is a holdover from
the PPC days where service deployments where done in the cloud and it
handled collecting logs).

Removing this breaks another cycle that would be introduced with the
next change (in our test code)
2019-05-10 17:07:52 -07:00
Matt Ellis 6278c1c8d9 Do not depend on backend package from client package
The next change is going to do some code motion that would create some
circular imports if we did not do this. There was nothing that
required the members we were moving be in the backend package, so it
was easy enough to pull them out.
2019-05-10 17:07:52 -07:00
Matt Ellis a4dd8cba1f Add secrets managers for passphrase and service based encryption
After adding these, move all the code in the CLI over to use the
secrets managers. We'll start passing them to the engine next.
2019-05-10 17:07:52 -07:00
Matt Ellis e7e934a59a Push initialization of SecretsManager out of the backend
When preforming an update, require that a secrets manager is passed in
as part of the `backend.UpdateOperation` bag and use it.  The CLI now
passes this in (it still uses the default base64 secrets manager, so
this is just code motion into a high layer, since the CLI will be the
one to choose what secrets manager to use based on project settings).
2019-05-10 17:07:52 -07:00
Matt Ellis 307ee72b5f Use existing secrets manager when roundtripping
There are a few operations we do (stack rename, importing and edits)
where we will materialize a `deploy.Snapshot` from an existing
deployment, mutate it in somewhay, and then store it.

In these cases, we will just re-use the secrets manager that was used
to build the snapshot when we re-serialize it. This is less than ideal
in some cases, because many of these operations could run on an
"encrypted" copy of the Snapshot, where Inputs and Outputs have not
been decrypted.

Unfortunately, our system now is not set up in a great way to support
this and adding something like a `deploy.EncryptedSnapshot` would
require large scale code duplications.

So, for now, we'll take the hit of decrypting and re-encrypting, but
long term introducing a `deploy.EncryptedSnapshot` may be nice as it
would let us elide the encryption/decryption steps in some places and
would also make it clear what parts of our system have access to the
plaintext values of secrets.
2019-05-10 17:07:52 -07:00
Matt Ellis db18ee3905 Retain the SecretsManager that was used to deserialize a deployment
We have many cases where we want to do the following:

deployment -> snapshot -> process snapshot -> deployment

We now retain information in the snapshot about the secrets manager
that was used to construct it, so in these round trip cases, we can
re-use the existing manager.
2019-05-10 17:07:52 -07:00
Matt Ellis d758a2a6a0 Expose additionalSecretOutputs in the NodeJS SDK 2019-05-10 17:07:52 -07:00
Matt Ellis 480a2f6c9e Augment secret outputs based on per request options 2019-05-10 17:07:52 -07:00
Matt Ellis 8e84b3c4fd Regnerate generated code 2019-05-10 17:07:52 -07:00
Matt Ellis 3193d5d8a5 Provide a way to denote additional outputs to treat a secrets
For a given {Read,Register}Resource call, there may be a set of
outputs that should be treated as secrets, even if the provider itself
does not think they are always sensitive.  For example, when
constructing a `@pulumi/random::RandomString` it's possible that you
will be using the string as a shared secret between two
resources (e.g. the resigstration of a webhook and its handler) and so
you want the value stored in the checkpoint in a secure manner.

This change augments the RPCs such that we can communicate this from
the language host into the engine.
2019-05-10 17:07:52 -07:00
Matt Ellis b606b3091d Allow passing a nil SecretsManager to SerializeDeployment
When nil, it means no information is retained in the deployment about
the manager (as there is none) and any attempt to persist secret
values fails.

This should only be used in cases where the snapshot is known to not
contain secret values.
2019-05-10 17:07:52 -07:00
Matt Ellis 67bb134c28 Don't return serialized outputs from stack.GetRooStacktResource
Half of the call sites didn't care about these values and with the
secrets work the ergonmics of calling this method when it has to
return serialized ouputs isn't great. Move the serialization for this
into the CLI itself, as it was the only place that cared to do
this (so it could display things to end users).
2019-05-10 17:07:52 -07:00
Matt Ellis d341b4e000 Don't track a stack's configuration file in the backend
The previous changes to remove config loading out of the backend means
that the backends no longer need to track this information, as they
never use it.
2019-05-10 17:07:52 -07:00
Matt Ellis 10792c417f Remove backend.GetStackCrypter
As part of the pluggable secrets work, the crypter's used for secrets
are no longer tied to a backend. To enforce this, we remove the
`backend.GetStackCrypter` function and then have the relevent logic to
construct one live inside the CLI itself.

Right now the CLI still uses the backend type to decide what Crypter
to build, but we'll change that shortly.
2019-05-10 17:07:52 -07:00
Matt Ellis 5cde8e416a Rename base64sm to b64 2019-05-10 17:07:52 -07:00
Matt Ellis 97902ee50b Refactor config loading out of the backend
We require configuration to preform updates (as well as previews,
destroys and refreshes). Because of how everything evolved, loading
this configuration (and finding the coresponding decrypter) was
implemented in both the file and http backends, which wasn't great.

Refactor things such that the CLI itself builds out this information
and passes it along to the backend to preform operations. This means
less code duplicated between backends and less places the backend
assume things about the existence of `Pulumi.yaml` files and in
general makes the interface more plesent to use for others uses.
2019-05-10 17:07:52 -07:00
Matt Ellis d076bad1a5 Remove Config() from backend.Stack
For cloud backed stacks, this was already returning nil and due to the
fact that we no longer include config in the checkpoint for local
stacks, it was nil there as well.

Removing this helps clean stuff up and is should make some future
refactorings around custom secret managers easier to land.

We can always add it back later if we miss it (and make it actually do
the right thing!)
2019-05-10 17:07:52 -07:00
Matt Ellis cc74ef8471 Encrypt secret values in deployments
When constructing a Deployment (which is a plaintext representation of
a Snapshot), ensure that we encrypt secret values. To do so, we
introduce a new type `secrets.Manager` which is able to encrypt and
decrypt values. In addition, it is able to reflect information about
itself that can be stored in the deployment such that we can
deserialize the deployment into a snapshot (decrypting the values in
the process) without external knowledge about how it was encrypted.

The ability to do this is import for allowing stack references to
work, since two stacks may not use the same manager (or they will use
the same type of manager, but have different state).

The state value is stored in plaintext in the deployment, so it **must
not** contain sensitive data.

A sample manager, which just base64 encodes and decodes strings is
provided, as it useful for testing. We will allow it to be varried
soon.
2019-05-10 17:07:52 -07:00
Matt Ellis 294df77703 Retain secrets for unenlightented providers
When a provider does not natively understand secrets, we need to pass
inputs as raw values, as to not confuse it.

This leads to a not great experience by default, where we pass raw
values to `Check` and then use the results as the inputs to remaining
operations. This means that by default, we don't end up retaining
information about secrets in the checkpoint, since the call to `Check`
erases all of our information about secrets.

To provide a nicer experience we were don't lose information about
secrets even in cases where providers don't natively understand them,
we take property maps produced by the provider and mark any values in
them that are not listed as secret as secret if the coresponding input
was a secret.

This ensures that any secret property values in the inputs are
reflected back into the outputs, even for providers that don't
understand secrets natively.
2019-05-10 17:07:52 -07:00