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

Allow disabling default providers #8829

Merged
merged 8 commits into from
Jan 26, 2022

Conversation

iwahbe
Copy link
Member

@iwahbe iwahbe commented Jan 25, 2022

This is done with an opt-in setting in pulumi config. For example, to
disable default providers for aws, use:

pulumi config set --path pulumi:disable-default-providers[0] aws

To add kubernetes to the disabled list, use

pulumi config set --path pulumi:disable-default-providers[1] kubernetes

To disable all default providers, * can be used.


Under the hood, whenever we handle a default provider request (with defaultProviders.handleRequest), we make sure it isn't on the deny list. If it is, we replace the requested reference with a special DenyDefaultProvider reference. We check for this reference whenever we are about to get a provider to do actual work. By intercepting denied providers when references are created, we ensure that we never use a denied provider by accident.

Description

Fixes #3383

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

This is done with an opt-in setting in `pulumi config`. For example, to
disable default providers for `aws`, use:

```sh
pulumi config set --path pulumi:disable-default-providers[0] aws
```

To add `kubernetes` to the disabled list, use
```sh
pulumi config set --path pulumi:disable-default-providers[1] kubernetes
```

To disable all default providers, `*` can be used.

---

Under the hood, whenever we handle a default provider request (with
`defaultProviders.handleRequest`), we make sure it isn't on the deny
list. If it is, we replace the requested reference with a special
`DenyDefaultProvider` reference. We check for this reference whenever we
are about to get a provider to do actual work. By intercepting denied
providers when references are created, we ensure that we never use a
denied provider.
@iwahbe iwahbe self-assigned this Jan 25, 2022
The lint errors appear to be unrelated to the original PR. Fixing them
unblocks the CI.
@codecov
Copy link

codecov bot commented Jan 25, 2022

Codecov Report

Merging #8829 (d51f499) into master (dbb807f) will increase coverage by 0.01%.
The diff coverage is 65.51%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8829      +/-   ##
==========================================
+ Coverage   59.37%   59.39%   +0.01%     
==========================================
  Files         639      639              
  Lines       98237    98289      +52     
  Branches     1389     1389              
==========================================
+ Hits        58328    58377      +49     
+ Misses      36614    36610       -4     
- Partials     3295     3302       +7     
Impacted Files Coverage Δ
pkg/resource/deploy/step.go 79.34% <0.00%> (-0.51%) ⬇️
pkg/resource/deploy/source_eval.go 72.10% <59.45%> (-0.72%) ⬇️
pkg/resource/deploy/providers/reference.go 85.93% <100.00%> (+2.30%) ⬆️
pkg/resource/deploy/step_generator.go 84.56% <100.00%> (+0.35%) ⬆️
sdk/go/common/diag/errors.go 70.58% <100.00%> (+1.83%) ⬆️
pkg/codegen/hcl2/model/type_eventuals.go 93.01% <0.00%> (+0.43%) ⬆️
sdk/go/common/util/ciutil/github_actions.go 73.52% <0.00%> (+38.23%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dbb807f...d51f499. Read the comment docs.

@iwahbe iwahbe requested review from Frassle and t0yv0 January 26, 2022 12:26
pkg/resource/deploy/source_eval.go Outdated Show resolved Hide resolved
pkg/resource/deploy/step.go Outdated Show resolved Hide resolved
// Retrieves the name of the denied provider.
//
// Panics if called on a provider that is not a DenyDefaultProvider.
func DeniedDefaultProvider(ref Reference) string {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func DeniedDefaultProvider(ref Reference) string {
func GetDeniedDefaultProviderName(ref Reference) string {

I wonder if this should just be GetProviderName and allow any provider ref? Or maybe just use ref.URN().Name() inline?

Copy link
Member Author

Choose a reason for hiding this comment

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

It really should be (and now is) called GetDeniedDefaultProviderPkg. I'm just storing the desired property in the ref.URN().Name() field. I clarified the intended behavior in comments.

if !value.IsString() {
return true, fmt.Errorf("Unexpected endecoding of pulumi:disable-default-providers")
}
if err := json.Unmarshal([]byte(value.StringValue()), &array); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Our config is YAML why don't we allow proper array options? String will be fine for now but it would be a nice improvement to config.

Copy link
Member Author

Choose a reason for hiding this comment

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

The config (Pulumi.*.yaml) actually has a proper array. We serialize it to json as some earlier step. I'm not sure why it isn't kept an array.

@iwahbe iwahbe merged commit 33f9c7a into master Jan 26, 2022
@pulumi-bot pulumi-bot deleted the iwahbe/3383/allow-disable-default-providers branch January 26, 2022 17:08
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.

Provide opt-in setting to disable default providers
2 participants