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

Initial support for configuring policies #4015

Merged
merged 13 commits into from
Mar 8, 2020
Merged

Initial support for configuring policies #4015

merged 13 commits into from
Mar 8, 2020

Conversation

justinvp
Copy link
Member

@justinvp justinvp commented Mar 3, 2020

Apologies for the larger PR. It's broken up into more digestible commits.

This adds support for the --policy-pack-config flag and underlying implementation to apply configuration to policies. It also includes support for sending config schema to the service and using configuration from the service.

The pulumi/pulumi-policy side of the change is here: pulumi/pulumi-policy#207

Fixes pulumi/pulumi-policy#185
Fixes pulumi/pulumi-policy#186
Fixes pulumi/pulumi-policy#189
Fixes pulumi/pulumi-policy#190

Part of pulumi/pulumi-policy#187
Part of pulumi/pulumi-policy#188

@justinvp justinvp marked this pull request as ready for review March 4, 2020 16:15
@justinvp justinvp force-pushed the justin/pac_config branch from cbc4f70 to 7498136 Compare March 4, 2020 16:16
Comment on lines 260 to 267
analyzerInfo, err := analyzer.GetAnalyzerInfo()
if err != nil {
return err
}
config, err := plugin.ReconcilePolicyPackConfig(analyzerInfo.Policies, configFromAPI)
if err != nil {
return errors.Wrapf(err, "reconciling configuration for analyzer %q", analyzerInfo.Name)
}
Copy link
Member Author

@justinvp justinvp Mar 4, 2020

Choose a reason for hiding this comment

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

Note: An alternative to retrieving the metadata and reconciling the config here would be to just pass the config directly from the service (or from a --policy-pack-config specified file) to the Policy Pack. However, then each language SDK for policies would have to handle reconciling its default values with the specified config. Looking ahead to implementing the SDK for Python, .NET, and Go, it seemed "better" to have a single implementation here for doing this reconciliation, rather than writing it N times for each language.

Copy link
Contributor

@ekrengel ekrengel left a comment

Choose a reason for hiding this comment

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

Still parsing through, but thought I'd get this first batch out there!

pkg/backend/httpstate/client/client.go Show resolved Hide resolved
pkg/resource/plugin/analyzer_plugin.go Outdated Show resolved Hide resolved
pkg/backend/httpstate/client/client.go Outdated Show resolved Hide resolved
pkg/backend/httpstate/client/client.go Outdated Show resolved Hide resolved
pkg/resource/plugin/analyzer_plugin.go Outdated Show resolved Hide resolved
pkg/resource/plugin/analyzer_config.go Outdated Show resolved Hide resolved
Copy link
Contributor

@lukehoban lukehoban left a comment

Choose a reason for hiding this comment

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

Just a few notes - but overall looks good to me. Not an expert on the design of the policy config feature though - or the specific interactions with the service APIs - so will leave detailed feedback to @ekrengel.

pkg/resource/plugin/analyzer_config.go Outdated Show resolved Hide resolved
pkg/resource/plugin/analyzer_config.go Outdated Show resolved Hide resolved
pkg/resource/plugin/analyzer_plugin.go Outdated Show resolved Hide resolved
pkg/resource/plugin/analyzer_plugin.go Show resolved Hide resolved
justinvp added 5 commits March 6, 2020 07:42
Instead of returning these as a single combined error, emit these as individual diagnostic messages. This allows these errors to be seen in the Pulumi Console. Also, make it so that all validation errors for all policy packs are returned.

We should still consider adding a new diagnostic event for these, which would allow improved grouping and display, but that requires changes to both the CLI and service and can be done subsequently.

Also, cleaned up some things and added more tests.
The way we're calling it, it's always going to be set, since we fill in the default enforcement level value from the policy metadata.
Older policy packs do not support config, so avoid sending schema for such policy packs so that the service can distinguish whether a policy pack is configurable or not. Also, avoid configuring policy packs that don't support config.
Copy link
Contributor

@ekrengel ekrengel left a comment

Choose a reason for hiding this comment

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

👍

@justinvp justinvp merged commit 80f6c61 into master Mar 8, 2020
@pulumi-bot pulumi-bot deleted the justin/pac_config branch March 8, 2020 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants