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

Print security notice when index is added #616

Merged
merged 5 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/krew/cmd/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ var indexAddCmd = &cobra.Command{
if !indexoperations.IsValidIndexName(name) {
return errInvalidIndexName
}
return indexoperations.AddIndex(paths, name, args[1])
err := indexoperations.AddIndex(paths, name, args[1])
if 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.

I think if err != nil { return err} then printing this outside the if-block would be better.

also worth adding tests for (just to check WARNING: exists)

internal.PrintWarning(os.Stderr, `You have added a new index from %q
The plugins in this index are not audited for security by the Krew maintainers.
Run them at your own risk.`+"\n", args[1])
Copy link
Member

Choose a reason for hiding this comment

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

It might be better to say Install them at your own risk. for this particular msg.

}
return err
},
}

Expand All @@ -86,7 +92,7 @@ var indexDeleteCmd = &cobra.Command{

It is only safe to remove indexes without installed plugins. Removing an index
while there are plugins installed will result in an error, unless the --force
option is used ( not recommended).`,
option is used (not recommended).`,

Args: cobra.ExactArgs(1),
RunE: indexDelete,
Expand Down
5 changes: 4 additions & 1 deletion cmd/krew/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sigs.k8s.io/krew/internal/index/validation"
"sigs.k8s.io/krew/internal/installation"
"sigs.k8s.io/krew/internal/pathutil"
"sigs.k8s.io/krew/pkg/constants"
"sigs.k8s.io/krew/pkg/index"
)

Expand Down Expand Up @@ -173,7 +174,9 @@ Remarks:
output += fmt.Sprintf("Caveats:\n%s\n", indent(plugin.Spec.Caveats))
}
fmt.Fprintln(os.Stderr, indent(output))
internal.PrintSecurityNotice(plugin.Name)
if entry.indexName == constants.DefaultIndexName {
internal.PrintSecurityNotice(plugin.Name)
}
}
if len(failed) > 0 {
return errors.Wrapf(returnErr, "failed to install some plugins: %+v", failed)
Expand Down
5 changes: 4 additions & 1 deletion cmd/krew/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/krew/internal/installation"
"sigs.k8s.io/krew/internal/installation/receipt"
"sigs.k8s.io/krew/internal/pathutil"
"sigs.k8s.io/krew/pkg/constants"
)

func init() {
Expand Down Expand Up @@ -104,7 +105,9 @@ kubectl krew upgrade foo bar"`,
return errors.Wrapf(err, "failed to upgrade plugin %q", pluginDisplayName)
}
fmt.Fprintf(os.Stderr, "Upgraded plugin: %s\n", pluginDisplayName)
internal.PrintSecurityNotice(plugin.Name)
if indexName == constants.DefaultIndexName {
Copy link
Member

Choose a reason for hiding this comment

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

TestKrewInstallDoesntShowSecurityWarningForCustomIndex

Copy link
Contributor

Choose a reason for hiding this comment

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

+1
Even if it looks redundant, it is an important documentation of our intended logic.

internal.PrintSecurityNotice(plugin.Name)
}
}
if nErrors > 0 {
fmt.Fprintf(os.Stderr, "WARNING: Some plugins failed to upgrade, check logs above.\n")
Expand Down