Skip to content

Conversation

ayj
Copy link
Contributor

@ayj ayj commented Apr 7, 2018

Create a common webhook service for server-side configuration validation. This uses the existing pilot and mixer validation code for now. The k8s webhook specific code, cert provisioning, and registration has been copied from the sidecar-injector.

This service is optional (requires >= k8s 1.9) so I created a new component. Instead of creating a throwaway service (i.e. config-validator), and since Galley will be responsible for config validation anyway, I went ahead and created the galley component, charts, etc. The validation service is run from the validator subcommand.

fixes #1894

TODO in follow-up PRs

@ayj ayj requested review from ozevren and xiaolanz April 7, 2018 00:43
@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label Apr 7, 2018
Copy link
Contributor

@xiaolanz xiaolanz left a comment

Choose a reason for hiding this comment

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

/lgtm

- kind: ServiceAccount
name: istio-galley-service-account
namespace: {{ .Release.Namespace }}
{{- end }}
Copy link
Contributor

Choose a reason for hiding this comment

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

add last blank line

- enduserauthenticationpolicyspecs
- enduserauthenticationpolicyspecbindings
- serviceroles
- servicerolebindings
Copy link
Contributor

Choose a reason for hiding this comment

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

missing policy.authentication.istio.io

validation. This uses the existing pilot and mixer validation code for
now. The k8s webhook specific code, cert provisioning, and
registration has been copied from the sidecar-injector.

This service is optional (requires >= k8s 1.9) so I created a new
component. Instead of creating a throwaway service
(i.e. config-validator), and since Galley will be responsible for
config validation anyway, I went ahead and created the galley
component, charts, etc. The validation service is run from the
`validator` subcommand.

fixes istio#1894

TODO
- [ ] add integration test
- [ ] update e2e test(s) to use server-side validation
- [ ] update istio.io documentation
@ayj ayj force-pushed the enable-config-validation branch from dcec14d to 08afacb Compare April 10, 2018 18:18
@codecov
Copy link

codecov bot commented Apr 10, 2018

Codecov Report

Merging #4811 into master will increase coverage by 1%.
The diff coverage is 82%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #4811    +/-   ##
=======================================
+ Coverage      72%     73%    +1%     
=======================================
  Files         302     300     -2     
  Lines       25376   25035   -341     
=======================================
- Hits        18189   18076   -113     
+ Misses       6446    6227   -219     
+ Partials      741     732     -9
Impacted Files Coverage Δ
mixer/cmd/mixs/cmd/root.go 0% <ø> (ø) ⬆️
pilot/cmd/pilot-agent/main.go 35% <ø> (ø) ⬆️
mixer/pkg/config/crd/store.go 99% <100%> (ø) ⬆️
pkg/util/webhookpatch.go 77% <79%> (+2%) ⬆️
galley/pkg/crd/validation/webhook.go 82% <82%> (ø)
mixer/adapter/solarwinds/metrics_handler.go 75% <0%> (-8%) ⬇️
mixer/adapter/stackdriver/log/log.go 87% <0%> (-5%) ⬇️
mixer/adapter/servicecontrol/reportprocessor.go 79% <0%> (-1%) ⬇️
mixer/adapter/statsd/statsd.go 96% <0%> (-1%) ⬇️
mixer/adapter/rbac/rbacStore.go 84% <0%> (ø) ⬇️
... and 14 more

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 95ffd4a...c44b0aa. Read the comment docs.

@istio-testing istio-testing removed the needs-rebase Indicates a PR needs to be rebased before being merged label Apr 10, 2018
@ayj ayj changed the title WIP: add common config validation service Add common config validation service Apr 10, 2018
@@ -144,13 +144,11 @@ var (
// TODO: move it to a configmap later when we have more services to support.
webhookServiceAccounts = []string{
"istio-sidecar-injector-service-account",
"istio-mixer-validator-service-account",
"istio-pilot-service-account",
"istio-galley-service-account",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fyi @yusuoh

@ayj
Copy link
Contributor Author

ayj commented Apr 10, 2018

cc @mandarjog for helm/install review and top-level OWNERS approval

)

// resolveConfig checks whether to use the in-cluster or out-of-cluster config
func resolveConfig(kubeconfig string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need all of this? (It looks like this is from Pilot?).
In the code I have, I just ask for config and use BuildConfigFromFlags (I'd prefer to be very explicit with the user, but that's just me.)

If we do indeed keep this, can we move this to to a common package in istio/pkg/? It looks like this should be standardized among all command-line tools expecting a config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simple is good. I removed resolvedConfig in favor of calling BuildConfigFromFlags directly with kubeconfig.

}
if kubeconfig == "" {
defaultCfg := path.Join(homedir.HomeDir(), ".kube/config")
fmt.Printf("(3) %v\n", defaultCfg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Runaway Printf?

)

// waitSignal awaits for SIGINT or SIGTERM and closes the channel
func waitSignal(stop chan struct{}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we can use this for other commands as well. Hoist to a different file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created isto.io/istio/pkt/cmd/ for common command functions.

webhookConfigName, err)
select {
case <-stop:
// canceled by caller
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit : cancelled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://www.grammarly.com/blog/canceled-vs-cancelled. Given my emacs dictionary is american I chose "cancel". :)

Copy link
Contributor

Choose a reason for hiding this comment

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

crikey. :)

},
}

validatorCmd.PersistentFlags().StringVar(&webhookConfigName,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need the webhook-name flags? Seems like these should be constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For testing purposes in a shared cluster we might need to scope Istio to a single namespace. Multiple validation webhooks would exist and their names ought to be unique.

stop := make(chan struct{})

go func() {
if err := patchCert(stop); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens when patchCert fails? It looks like the webhook will still try to serve?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Validation will be broken. The webhook will continue to serve but api-server won't call it. The sidecar injector has a similar problem. I'm hoping the environments WG can address this problem as part of k8s install/upgrade process. cc @yusuoh

Copy link

@yusuoh yusuoh Apr 11, 2018

Choose a reason for hiding this comment

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

sidecar injector service will fail if it cannot patch the cert after several retries.

https://github.com/istio/istio/blob/master/pilot/cmd/sidecar-injector/main.go#L86

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a tracking bug for this? It would be nice to tag this with a TODO with reference to the bug (otherwise it will most likely get lost and lurk as an issue).


// CreateMixerValidator creates a mixer backend validator.
func CreateMixerValidator(kubeconfig string) (store.BackendValidator, error) {
info := generatedTmplRepo.SupportedTmplInfo
Copy link
Contributor

Choose a reason for hiding this comment

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

These seem problematic. Specifically, this depends on Mixer's own built-in templates, which effectively exposes Mixer internals to Galley. (which is also apparent from the imports in this file).

I wasn't expecting to pull this much Mixer code into Galley. Would it be better if we split this CR and do some refactoring before implementing the webhook in Galley?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per our offline discussion I'd prefer to reverse the order since config validation is P0 for Istio 1.0. I created #4887 to track the follow-up refactoring.

Copy link
Contributor

@ozevren ozevren Apr 13, 2018

Choose a reason for hiding this comment

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

@geeknoid
FYI. Hopefully, after Mandar lands CRD normalization, we can start utilizing a declarative config check for adapter configs and reduce the scope of dependencies to Mixer to the pkg/ level.

}
case err := <-wh.watcher.Error:
log.Errorf("Watcher error: %v", err)
case <-healthC:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need the health check file here? Is this needed for web hooks in general?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All Istio components should have health checks. https://goo.gl/QRRdwm recommends that components use file based health checking.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but can we move this to use the standard health-check library?

Copy link
Contributor

@costinm costinm left a comment

Choose a reason for hiding this comment

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

A bit too large to understand, but it's good to move it out of pilot.

I don't think this was enabled in pilot - so would feel more comfortable with keeping it off by default in 0.8.

@@ -8,6 +8,9 @@ global:
sidecar-injector:
enabled: true

galley:
enabled: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be enabled by default in 0.8 ? What are the dependencies / setup / etc ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k8s >= 1.9

Config validation is targeted BETA for 1.0. I could disable for 0.8 but would like to (re)enable for 0.9 for additional testing prior to 1.0.

@istio-merge-robot istio-merge-robot added the needs-rebase Indicates a PR needs to be rebased before being merged label Apr 11, 2018
@istio-merge-robot
Copy link

@ayj PR needs rebase

@istio-testing istio-testing removed the needs-rebase Indicates a PR needs to be rebased before being merged label Apr 12, 2018
Copy link
Contributor

@costinm costinm left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@istio-testing
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: costinm, xiaolanz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@istio-merge-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@istio-merge-robot
Copy link

Automatic merge from submit-queue.

@istio-merge-robot istio-merge-robot merged commit 8d8a990 into istio:master Apr 13, 2018
@ayj ayj deleted the enable-config-validation branch April 30, 2018 19:19
@ayj ayj unassigned xiaolanz Sep 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable server-side config validation with webhooks
8 participants