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

Warn about ambient plugins loaded from $PATH #13607

Merged
merged 1 commit into from Jul 27, 2023
Merged

Conversation

Frassle
Copy link
Member

@Frassle Frassle commented Jul 27, 2023

Description

By default Pulumi will load ambient plugins from $PATH before looking in the plugins directory or at bundled plugins.

While this is very useful for development it often causes confusion when people have forgotten that they have plugins left on $PATH.

This makes the use of these $PATH plugins a diagnostic warning to try and make that failure mode a little less silent.

Normal users shouldn't ever have plugins on $PATH and so won't see this new warning.

Checklist

  • I have run make tidy to update any new dependencies
  • I have run make lint to verify my code passes the lint check
    • I have formatted my code using gofumpt
  • I have added tests that prove my fix is effective or that my feature works
  • I have run make changelog and committed the changelog/pending/<file> documenting my change
  • Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version

@pulumi-bot
Copy link
Contributor

Changelog

[uncommitted] (2023-07-27)

Features

  • [cli/plugin] CLI will now warn when loading ambient plugins from $PATH.
    #13607

@Frassle Frassle requested a review from a team July 27, 2023 14:04
Copy link
Contributor

@thomas11 thomas11 left a comment

Choose a reason for hiding this comment

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

This is great, thank you!

// We prefer the ambient path, but we need to check if this is the same as the bundled
// path to decide if we're warning or not.
if ambientPath != "" {
if ambientPath != bundledPath {
Copy link
Contributor

Choose a reason for hiding this comment

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

don't you need to check for bundledPath != "" here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, if bundledPath is empty then this was a non-bundled plugin (like a provider) and we want to warn. "path" != "" is true and we log the warning.

Copy link
Contributor

@abhinav abhinav left a comment

Choose a reason for hiding this comment

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

No blockers. Suggested some improvements.

Comment on lines 1823 to 1833
return &PluginInfo{
Kind: kind,
Name: name,
Path: filepath.Dir(ambientPath),
}, ambientPath, nil
} else if bundledPath != "" {
return &PluginInfo{
Kind: kind,
Name: name,
Path: filepath.Dir(bundledPath),
}, bundledPath, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: I think this would be cleaner if we didn't have the two separate returns. We could have a block calculating a plugin path, and then just building PluginInfo from that.

pluginPath := bundledPath
if ambientPath != "" {
	if ambientPath != pluginPath {
		// warn
	}
	pluginPath = ambientPath
}
if pluginPath != "" {
	return &PluginInfo{..}, pluginPath, nil
}

@@ -1080,15 +1146,74 @@ func TestBundledPluginSearch(t *testing.T) {
err = os.WriteFile(ambientPath, []byte{}, 0o700) //nolint: gosec
require.NoError(t, err)

d := &mockSink{t: t}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think for the cases where you don't care about the output, diagtest.LogSink may be preferable since it'll log to the testing.T:

func LogSink(t testing.TB) diag.Sink {

Copy link
Member Author

Choose a reason for hiding this comment

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

! I was looking for something like this
I'll rework things to use that module.

t.Setenv("PATH", pathDir)
ambientPath := filepath.Join(pathDir, "pulumi-resource-mock")
err := os.WriteFile(ambientPath, []byte{}, 0o700) //nolint: gosec
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine as-is, but you may find it easier to not have a mock sink and instead use a diag.DefaultSink with a buffer for stderr.

var stderr bytes.Buffer
d := diag.DefaultSink(
	iotest.LogWriter(t), // stdout
	&stderr,
	diag.FormatOptions{Color: "never"},
)

// ...

assert.Regexp(t, `using \S+/pulumi-resource-mock from \$PATH` stderr.String())

This way you're also validating the final message and where it's printed instead of the printf string template.

(iotest.LogWriter comes from here.)

By default Pulumi will load ambient plugins from $PATH before looking in
the plugins directory or at bundled plugins.

While this is very useful for development it often causes confusion when
people have forgotten that they have plugins left on $PATH.

This makes the use of these $PATH plugins a diagnostic warning to try
and make that failure mode a little less silent.

Normal users shouldn't ever have plugins on $PATH and so won't see this
new warning.
@Frassle
Copy link
Member Author

Frassle commented Jul 27, 2023

bors merge

bors bot added a commit that referenced this pull request Jul 27, 2023
13607: Warn about ambient plugins loaded from $PATH r=Frassle a=Frassle



<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

By default Pulumi will load ambient plugins from $PATH before looking in the plugins directory or at bundled plugins.

While this is very useful for development it often causes confusion when people have forgotten that they have plugins left on $PATH.

This makes the use of these $PATH plugins a diagnostic warning to try and make that failure mode a little less silent.

Normal users shouldn't ever have plugins on $PATH and so won't see this new warning.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
@bors
Copy link
Contributor

bors bot commented Jul 27, 2023

Build failed:

@Frassle
Copy link
Member Author

Frassle commented Jul 27, 2023

Some automation api tests hit the race detector, looks the same as what Kyle opened an issue on the other day.

bors retry

@bors
Copy link
Contributor

bors bot commented Jul 27, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit 504abb2 into master Jul 27, 2023
52 checks passed
@bors bors bot deleted the fraser/warnAmbient branch July 27, 2023 20:08
bors bot added a commit that referenced this pull request Aug 4, 2023
13657: Revert "Warn about ambient plugins loaded from $PATH" r=dixler a=dixler

Reverts #13607

Fixes #13656 

Co-authored-by: Kyle Dixler <kdixle2@gmail.com>
bors bot added a commit that referenced this pull request Aug 5, 2023
13657: Revert "Warn about ambient plugins loaded from $PATH" r=dixler a=dixler

Reverts #13607

Fixes #13656 

Co-authored-by: Kyle Dixler <kdixle2@gmail.com>
bors bot added a commit that referenced this pull request Aug 5, 2023
13657: Revert "Warn about ambient plugins loaded from $PATH" r=dixler a=dixler

Reverts #13607

Fixes #13656 

Co-authored-by: Kyle Dixler <kdixle2@gmail.com>
Frassle added a commit that referenced this pull request Aug 8, 2023
By default Pulumi will load ambient plugins from $PATH before looking in
the plugins directory or at bundled plugins.

While this is very useful for development it often causes confusion when
people have forgotten that they have plugins left on $PATH.

This makes the use of these $PATH plugins a diagnostic warning to try
and make that failure mode a little less silent.

Normal users shouldn't ever have plugins on $PATH and so won't see this
new warning.

Re-instates #13607 with a fix for
symlinks included.
Frassle added a commit that referenced this pull request Aug 8, 2023
By default Pulumi will load ambient plugins from $PATH before looking in
the plugins directory or at bundled plugins.

While this is very useful for development it often causes confusion when
people have forgotten that they have plugins left on $PATH.

This makes the use of these $PATH plugins a diagnostic warning to try
and make that failure mode a little less silent.

Normal users shouldn't ever have plugins on $PATH and so won't see this
new warning.

Re-instates #13607 with a fix for
symlinks included.
Frassle added a commit that referenced this pull request Aug 8, 2023
By default Pulumi will load ambient plugins from $PATH before looking in
the plugins directory or at bundled plugins.

While this is very useful for development it often causes confusion when
people have forgotten that they have plugins left on $PATH.

This makes the use of these $PATH plugins a diagnostic warning to try
and make that failure mode a little less silent.

Normal users shouldn't ever have plugins on $PATH and so won't see this
new warning.

Re-instates #13607 with a fix for
symlinks included.
bors bot added a commit that referenced this pull request Aug 8, 2023
13670: Warn about ambient plugins loaded from $PATH r=Frassle a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

By default Pulumi will load ambient plugins from $PATH before looking in the plugins directory or at bundled plugins.

While this is very useful for development it often causes confusion when people have forgotten that they have plugins left on $PATH.

This makes the use of these $PATH plugins a diagnostic warning to try and make that failure mode a little less silent.

Normal users shouldn't ever have plugins on $PATH and so won't see this new warning.

Re-instates #13607 with a fix for symlinks included.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
bors bot added a commit that referenced this pull request Aug 8, 2023
13670: Warn about ambient plugins loaded from $PATH r=Frassle a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

By default Pulumi will load ambient plugins from $PATH before looking in the plugins directory or at bundled plugins.

While this is very useful for development it often causes confusion when people have forgotten that they have plugins left on $PATH.

This makes the use of these $PATH plugins a diagnostic warning to try and make that failure mode a little less silent.

Normal users shouldn't ever have plugins on $PATH and so won't see this new warning.

Re-instates #13607 with a fix for symlinks included.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
bors bot added a commit that referenced this pull request Aug 8, 2023
13670: Warn about ambient plugins loaded from $PATH r=Frassle a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

By default Pulumi will load ambient plugins from $PATH before looking in the plugins directory or at bundled plugins.

While this is very useful for development it often causes confusion when people have forgotten that they have plugins left on $PATH.

This makes the use of these $PATH plugins a diagnostic warning to try and make that failure mode a little less silent.

Normal users shouldn't ever have plugins on $PATH and so won't see this new warning.

Re-instates #13607 with a fix for symlinks included.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
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.

None yet

4 participants