Skip to content

Conversation

ostromart
Copy link
Contributor

Fixes #6069
Tell me if this looks reasonable and I will test it.

@ostromart ostromart requested a review from ayj June 20, 2018 18:13
@@ -210,7 +211,11 @@ func (wh *Webhook) Run(stop <-chan struct{}) {
log.Errorf("update error: %v", err)
break
}

caCertPEM, err := ioutil.ReadFile(wh.certFile)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the server's cert file (wh.certFile) include the CA bundle?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that was a mistake - fixed.

@@ -241,6 +247,13 @@ func (wh *Webhook) Run(stop <-chan struct{}) {
}
}

// GetCABundlePEM returns the CA bundle PEM, read from the cert file. Safe for concurrent use.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the intent here to support CA cert rotation? If not, the caCertPEM re-load code can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, might as well include this since it's a minor addition.

@@ -86,6 +86,9 @@ var (
return multierror.Prefix(err, "failed to patch webhook config")
}

if err := patchCertLoop(wh.GetCABundlePEM); 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.

patchCert() can be removed with this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently if we don't succeed within 1 min we get an error and exit. If this is removed, we would continue and just log the error. Is that acceptable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes

@@ -131,6 +134,24 @@ func patchCert() error {
return err
}

// patchCertLoop continually reapplies the caBundle PEM. This is required because it can be overwritten with empty
// values if the original yaml is reapplied (https://github.com/istio/istio/issues/6069).
func patchCertLoop(getCABundlePEM func() []byte) error {
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 an improvement over the existing (broken) behavior. It will lead to some noise in api-server logs. That could be mitigated by updating PatchMutatingWebhookConfig to skip invoking PATCH if the strategic merge patch is empty.

Ideally this would be driven by watching the webhook configuration (via watch or informer) and only PATCH'ing if change is observed. Is there a follow-up tracking issue for that work item?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is now: #6451

@codecov
Copy link

codecov bot commented Jun 20, 2018

Codecov Report

Merging #6435 into master will increase coverage by 1%.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #6435    +/-   ##
=======================================
+ Coverage      68%     68%    +1%     
=======================================
  Files         357     351     -6     
  Lines       31086   30833   -253     
=======================================
- Hits        21010   20847   -163     
+ Misses       9240    9144    -96     
- Partials      836     842     +6
Impacted Files Coverage Δ
pkg/util/webhookpatch.go 78% <100%> (+1%) ⬆️
galley/pkg/server/server.go 81% <0%> (-9%) ⬇️
pilot/pkg/config/memory/monitor.go 82% <0%> (-9%) ⬇️
mixer/adapter/circonus/circonus.go 68% <0%> (-7%) ⬇️
mixer/adapter/signalfx/registry.go 86% <0%> (-5%) ⬇️
pilot/pkg/serviceregistry/kube/controller.go 64% <0%> (-4%) ⬇️
galley/pkg/mcp/snapshot/snapshot.go 96% <0%> (-4%) ⬇️
pilot/pkg/serviceregistry/kube/queue.go 86% <0%> (-3%) ⬇️
pilot/pkg/proxy/envoy/v2/debug.go 30% <0%> (-2%) ⬇️
galley/pkg/mcp/server/server.go 85% <0%> (-2%) ⬇️
... and 74 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 ab75e24...24ca447. Read the comment docs.

@@ -86,6 +86,9 @@ var (
return multierror.Prefix(err, "failed to patch webhook config")
}

if err := patchCertLoop(wh.GetCABundlePEM); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently if we don't succeed within 1 min we get an error and exit. If this is removed, we would continue and just log the error. Is that acceptable?

@@ -131,6 +134,24 @@ func patchCert() error {
return err
}

// patchCertLoop continually reapplies the caBundle PEM. This is required because it can be overwritten with empty
// values if the original yaml is reapplied (https://github.com/istio/istio/issues/6069).
func patchCertLoop(getCABundlePEM func() []byte) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is now: #6451

@@ -210,7 +211,11 @@ func (wh *Webhook) Run(stop <-chan struct{}) {
log.Errorf("update error: %v", err)
break
}

caCertPEM, err := ioutil.ReadFile(wh.certFile)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that was a mistake - fixed.

@@ -241,6 +247,13 @@ func (wh *Webhook) Run(stop <-chan struct{}) {
}
}

// GetCABundlePEM returns the CA bundle PEM, read from the cert file. Safe for concurrent use.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, might as well include this since it's a minor addition.

defer wh.mu.Unlock()
return wh.caCertPEM
}

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 didn't like entangling the patch functionality into this type, so I moved it entirely into main.


if string(patch) != "{}" {
_, err = client.Patch(webhookConfigName, types.StrategicMergePatchType, patch)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Lines 103-105 are correct for validating webhook. You need to make the same change for the mutating webhook on line 61.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

const retryTimes = 6 // Try for one minute.
// patchCertLoop continually reapplies the caBundle PEM. This is required because it can be overwritten with empty
// values if the original yaml is reapplied (https://github.com/istio/istio/issues/6069).
func patchCertLoop() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also reference the tracking issue for watch triggered patch (#6451)? e.g.

// TODO(https://github.com/istio/istio/issues/6451) - only patch when caBundle changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

case <-watcher.Event:
caCertPem, err = ioutil.ReadFile(flags.caCertFile)
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't filter on file event type (e.g. delete). Any chance that this read will fail in such cases and overwrite caCertPem with nil? Maybe something like the following?

if b, err := ioutil.ReadFile(flags.caCertFile); err != nil { 
    /* error */ 
} else {
    caCertPem = b
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@ayj ayj changed the title Reapply CA bundle to prevent overwrite Reapply sidecar injector CA bundle to prevent overwrite Jun 22, 2018
Copy link
Contributor

@ayj ayj left a comment

Choose a reason for hiding this comment

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

/lgtm

Also, pausing auto-merge until fix is manually verified
/hold

@ostromart
Copy link
Contributor Author

Verified that reapplying istio.yaml blows away caBundle but it is immediately restored.

@ostromart
Copy link
Contributor Author

/hold cancel

@istio-testing istio-testing removed the do-not-merge/hold Block automatic merging of a PR. label Jun 22, 2018
@ostromart ostromart force-pushed the cabundle_fix branch 2 times, most recently from e7b8a0d to 6556a0a Compare June 22, 2018 22:51
@ayj
Copy link
Contributor

ayj commented Jun 22, 2018

/lgtm

@hklai
Copy link
Contributor

hklai commented Jun 23, 2018

/lgtm

@istio-testing
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ayj, hklai, ostromart

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

@hklai
Copy link
Contributor

hklai commented Jun 23, 2018

/test istio-unit-tests

@istio-testing
Copy link
Collaborator

istio-testing commented Jun 23, 2018

@ostromart: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
prow/e2e-dashboard.sh 24ca447 link /test e2e-dashboard
prow/istio-unit-tests.sh 24ca447 link /test istio-unit-tests

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@istio-testing istio-testing merged commit 67ac3e2 into istio:master Jun 23, 2018
ayj added a commit to ayj/istio that referenced this pull request Jun 25, 2018
@hklai hklai mentioned this pull request Jun 26, 2018
rshriram pushed a commit that referenced this pull request Jun 27, 2018
* Continuously reapply galley CA bundle to prevent overwrite

See related issue #6435.

* fix linter error

* refactor CreateClientset() into common pkg/kube

* linter fixes
quanjielin pushed a commit to quanjielin/istio that referenced this pull request Jul 2, 2018
* Reapply CA bundle to prevent overrwrite

* Add watcher, move cert reapply out of webhook

* Fix review comments

* Patch loop should be in goroutine

* Lint
quanjielin pushed a commit to quanjielin/istio that referenced this pull request Jul 2, 2018
* Continuously reapply galley CA bundle to prevent overwrite

See related issue istio#6435.

* fix linter error

* refactor CreateClientset() into common pkg/kube

* linter fixes
@ostromart ostromart deleted the cabundle_fix branch November 17, 2018 00:14
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.

5 participants