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

Tests for secret handling in provider configuration #2440

Closed
t0yv0 opened this issue Sep 24, 2024 · 7 comments · Fixed by #2716
Closed

Tests for secret handling in provider configuration #2440

t0yv0 opened this issue Sep 24, 2024 · 7 comments · Fixed by #2716
Assignees
Labels
area/testing The internal testing setup of the bridge kind/engineering Work that is not visible to an external user resolution/fixed This issue was fixed
Milestone

Comments

@t0yv0
Copy link
Member

t0yv0 commented Sep 24, 2024

For the following combinations:

  • provider-sdk: sdkv2, pf
  • property-type: string, number, bool, list
  • property-nesting: top-level vs nested
  • provider: default vs explicit

Check that first-class secrets work as expected:

  • When a program configures the provider with a secret input
  • Pulumi up succeeds and TF code receives the expected un-secreted value
  • Secret material does not leak to state

Check that schema-based secrets work as expected:

  • When a provider property is sensitive according to SchemaInfo or underlying TF schema
  • User configures the provider with a plain value
  • The plain value does not leak to state but is secreted instate

Some suggestions on "bulletproof" test suite at integration level to work around concerns of mixing things up around provider configuration due to Config Encoding.

CC @VenelinMartinov @iwahbe @guineveresaenger

One other thing to call out is checking upgrade scenarios where DiffConfig() might be in play and receive a previous version of the schema.

@pulumi-bot pulumi-bot added the needs-triage Needs attention from the triage team label Sep 24, 2024
@t0yv0
Copy link
Member Author

t0yv0 commented Sep 24, 2024

TBD move to the bridge

@t0yv0 t0yv0 transferred this issue from pulumi/pulumi-aws Sep 24, 2024
@t0yv0
Copy link
Member Author

t0yv0 commented Sep 24, 2024

Jotting this down as part of discussion re: #2439

@t0yv0
Copy link
Member Author

t0yv0 commented Sep 24, 2024

@iwahbe brought up a good point that due to pulumi/pulumi#15032 the language dimension is pertinent here. We do not know from a YAML-based test that C# or TypeScript are going to work because languages differ due to SDK handling in how they pass config information over the wire.

We discussed a reluctance to add language-specific testes to the bridge codebase as in an idealized world language variance would be guaranteed by pulumi/pulumi machinery and out of scope for the bridged codebase. In the immediate term Ian is to introduce replay tests that mimic TypeScript behavior.

It is however not entirely satisfactory as we will not be able to push #2439 forward without having tests that assure us that bridged providers behave correctly for configuration in each language after the change, and there is the Gordian knot that the bridge does not bottom out at a supported Go SDK. This could be done either by language-variant tests in the bridge or else by introducing tests in pulumi/pulumi that depend on bridged providers. Expecting some pushback both ways but we'll need to pick our poison to move the 2439 forward.

@iwahbe iwahbe added kind/engineering Work that is not visible to an external user and removed needs-triage Needs attention from the triage team labels Sep 25, 2024
@t0yv0
Copy link
Member Author

t0yv0 commented Sep 27, 2024

Put it on the list for M111 ( pulumi/pulumi#15032 ).. even if we don't put language tests in the bridge we should be able to solidly test 15032 through Tier1 providers, even if we need temporary tests to do this.

@mjeffryes mjeffryes added this to the 0.111 milestone Oct 2, 2024
iwahbe added a commit that referenced this issue Oct 9, 2024
This is a pre-requisite for #2440.
iwahbe added a commit that referenced this issue Oct 9, 2024
This is a pre-requisite for #2440.
iwahbe added a commit that referenced this issue Oct 9, 2024
This is a pre-requisite for #2440.
iwahbe added a commit that referenced this issue Oct 9, 2024
This is a pre-requisite for #2440.
iwahbe added a commit that referenced this issue Oct 9, 2024
This is a pre-requisite for #2440.
iwahbe added a commit that referenced this issue Oct 9, 2024
This is a pre-requisite for #2440.
iwahbe added a commit that referenced this issue Oct 9, 2024
This is a pre-requisite for #2440.
iwahbe added a commit that referenced this issue Oct 9, 2024
This is a pre-requisite for #2440.
iwahbe added a commit that referenced this issue Oct 9, 2024
This is a pre-requisite for #2440.
@t0yv0
Copy link
Member Author

t0yv0 commented Oct 9, 2024

Thanks for picking this up! I've been collecting some more feedback and developing the ideas in https://docs.google.com/document/d/1cnBJzAGWMnjjj2Q5fDdVcq0DcrWd-OqvPPlSxQV50R4/edit?usp=sharing TLDR trying to take care of the language dimension in pulumi/pulumi conformance tests. But this is very much needed too.

iwahbe added a commit that referenced this issue Oct 9, 2024
The interface for configure cross-tests is:
```go
func Configure(
    t *testing.T, 
    schema schema.Schema,          // The provider's schema
    tfConfig map[string]cty.Value, // Config values for HCL/TF
    puConfig resource.PropertyMap, // Config values for Pulumi YAML/Pulumi
)
```

Because the mapping between `tfConfig` and `puConfig` is non-trivial,
and to allow for secret injection, I have chosen to allow setting
`tfConfig` and `puConfig` separately.

This is a pre-requisite for #2440.

---

When the underlying provider configuration doesn't match between Pulumi
and TF, the error looks like this:

```go
func TestFailure(t *testing.T) {
	crosstests.Configure(t,
		schema.Schema{Attributes: map[string]schema.Attribute{
			"k": schema.StringAttribute{Optional: true},
		}},
		map[string]cty.Value{"k": cty.StringVal("foo")},
		resource.PropertyMap{"k": resource.NewProperty("oo")},
	)
}
```

```
go test -test.run \^TestFailure\$
warning: resource:test_res.Docs received a non-zero custom value &{ [32]     false false} that is being ignored. Plugin Framework based providers do not yet support this feature.
--- FAIL: TestFailure (2.25s)
    configure.go:129: Pulumi.yaml:
        backend:
            url: file://./data
        name: project
        resources:
            p:
                properties:
                    k: oo
                type: pulumi:providers:test
        runtime: yaml
    --- FAIL: TestFailure/compare (0.00s)
        configure.go:174: 
            	Error Trace:	/Users/ianwahbe/go/src/github.com/pulumi/pulumi-terraform-bridge/pf/tests/internal/cross-tests/configure.go:174
            	Error:      	Not equal: 
            	            	expected: tfsdk.Config{Raw:tftypes.Value{typ:tftypes.Object{AttributeTypes:map[string]tftypes.Type{"k":tftypes.primitive{name:"String", _:[]struct {}(nil)}}, OptionalAttributes:map[string]struct {}(nil), _:[]struct {}(nil)}, value:map[string]tftypes.Value{"k":tftypes.Value{typ:tftypes.primitive{name:"String", _:[]struct {}(nil)}, value:"foo"}}}, Schema:schema.Schema{Attributes:map[string]schema.Attribute{"k":schema.StringAttribute{CustomType:basetypes.StringTypable(nil), Required:false, Optional:true, Sensitive:false, Description:"", MarkdownDescription:"", DeprecationMessage:"", Validators:[]validator.String(nil)}}, Blocks:map[string]schema.Block(nil), Description:"", MarkdownDescription:"", DeprecationMessage:""}}
            	            	actual  : tfsdk.Config{Raw:tftypes.Value{typ:tftypes.Object{AttributeTypes:map[string]tftypes.Type{"k":tftypes.primitive{name:"String", _:[]struct {}(nil)}}, OptionalAttributes:map[string]struct {}(nil), _:[]struct {}(nil)}, value:map[string]tftypes.Value{"k":tftypes.Value{typ:tftypes.primitive{name:"String", _:[]struct {}(nil)}, value:"oo"}}}, Schema:schema.Schema{Attributes:map[string]schema.Attribute{"k":schema.StringAttribute{CustomType:basetypes.StringTypable(nil), Required:false, Optional:true, Sensitive:false, Description:"", MarkdownDescription:"", DeprecationMessage:"", Validators:[]validator.String(nil)}}, Blocks:map[string]schema.Block(nil), Description:"", MarkdownDescription:"", DeprecationMessage:""}}
            	            	
            	            	Diff:
            	            	--- Expected
            	            	+++ Actual
            	            	@@ -18,3 +18,3 @@
            	            	     },
            	            	-    value: (string) (len=3) "foo"
            	            	+    value: (string) (len=2) "oo"
            	            	    }
            	Test:       	TestFailure/compare
FAIL
exit status 1
FAIL	github.com/pulumi/pulumi-terraform-bridge/pf/tests	3.059s
```
@iwahbe iwahbe added the area/testing The internal testing setup of the bridge label Oct 15, 2024
iwahbe added a commit that referenced this issue Oct 23, 2024
As part of
#2440, I wanted
to be able to write cross-tests with that passed secrets to `Configure`.
This PR implements `crosstests.Configure`.

The PR stacks on top of
#2505.

Fixes #2274
@mjeffryes mjeffryes modified the milestones: 0.111, 0.112 Oct 30, 2024
@mjeffryes mjeffryes removed this from the 0.112 milestone Nov 13, 2024
@mjeffryes mjeffryes added this to the 0.114 milestone Nov 13, 2024
t0yv0 added a commit that referenced this issue Dec 9, 2024
Relates: #2440 

This adds the necessary tests to make sure Pulumi CLI plays well with
bridged providers in handling secrets in provider configuration. To
complete #2440 same assurances need to be built out for Plugin Framework
based providers.
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.97.0.

@pulumi-bot
Copy link
Contributor

This issue has been addressed in PR #2716 and shipped in release v3.98.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing The internal testing setup of the bridge kind/engineering Work that is not visible to an external user resolution/fixed This issue was fixed
Projects
None yet
4 participants