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

Activator Header Fixes #2047

Merged
merged 3 commits into from
Sep 18, 2018

Conversation

dprotaso
Copy link
Member

@dprotaso dprotaso commented Sep 18, 2018

Fixes #2046

  • Activator now reads the last header value for Revision Name, Revision Namespace and Configuration Name. This prevents external clients (outside the mesh) from activating the wrong revision
  • Activator and Queue Proxy now remove the activator headers when making requests. This prevents inadvertent Knative apps & functions from forwarding these headers

@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 18, 2018
@dprotaso
Copy link
Member Author

Holding for verification

/hold

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 18, 2018
@dprotaso
Copy link
Member Author

dprotaso commented Sep 18, 2018 via email

Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

I'm not sure this actually fixes #2046 since that issue is about confusion inside of the activator if an external entity sets these headers. This fixes the case where a service would forward the request as-is (and thus act as an external entity setting these headers), correct?


for _, h := range headersToRemove {
if r.Header.Get(h) != "" {
r.Header.Del(h)
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 you can omit the surrounding if since Del will delegate to delete which is a noop if nothing is there to delete.

}

orig := p.Director
p.Director = func(r *http.Request) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For my own understanding: Is it not possible to just drop the headers from the incoming request? Is it done this way to keep the incoming request object intact so other methods can happily use the headers just like today?

activator.ConfigurationHeader,
activator.RevisionHeaderName,
activator.RevisionHeaderNamespace,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a global constant/variable to avoid reallocations?

@dprotaso
Copy link
Member Author

I'm not sure this actually fixes #2046 since that issue is about confusion inside of the activator if an external entity sets these headers.

It's not the external entity (ie. outside the service mesh) setting the header - it's the virtual service.

I would say that's another related issue. Ideally we need the ingress to prune these header when they come from outside the mesh.

This fixes the case where a service would forward the request as-is (and thus act as an external entity setting these headers), correct?

Actually - this requires changes to the queue proxy. I'll update the PR to include that

@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 18, 2018
@dprotaso dprotaso changed the title Remove Istio headers in outbound activator requests Activator Header Fixes Sep 18, 2018
@dprotaso
Copy link
Member Author

/assign @markusthoemmes
/assign @josephburnett

Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

Implementation is LGTM, got some nits in the comments.

activator.RevisionHeaderNamespace,
}

func SetupHeaderPruning(p *httputil.ReverseProxy) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment.

}
}

func GetLastHeaderValue(r *http.Request, key string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment.

Should we narrow the interface to pass in r.Headers vs. passing in the whole request?

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 debating about that - it's obvious from the test that it should receive http.Header - i just chose to ignore it.

I'll make the change

pkg/activator/util/header.go Show resolved Hide resolved
@scothis
Copy link
Contributor

scothis commented Sep 18, 2018

Testing with this PR, the chain of functions that failed previously will now scale from zero as expected.

Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

/lgtm

Nice one, great tests! 🎉

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 18, 2018
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 18, 2018
@dprotaso
Copy link
Member Author

@markusthoemmes sorry made a minor style change

http.Header{
	headerKey: []string{"first", "second"},
},

to

http.Header{
	headerKey: {"first", "second"},
},

@dprotaso
Copy link
Member Author

/hold cancel

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 18, 2018
@markusthoemmes
Copy link
Contributor

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 18, 2018
@dprotaso
Copy link
Member Author

/test pull-knative-serving-integration-tests

2 similar comments
@dprotaso
Copy link
Member Author

/test pull-knative-serving-integration-tests

@dprotaso
Copy link
Member Author

/test pull-knative-serving-integration-tests

Copy link
Contributor

@josephburnett josephburnett 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

}

// SetupHeaderPruning will cause the http.ReverseProxy
// to no forward activator headers
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: ... to no[t] forward ...

@josephburnett
Copy link
Contributor

/assign @mattmoor

@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 18, 2018
@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@dprotaso
Copy link
Member Author

dprotaso commented Sep 18, 2018 via email

@josephburnett
Copy link
Contributor

/consent
/please?

@mattmoor
Copy link
Member

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state.

We need an admin to merge this. I will talk to @isdal

@googlebot
Copy link

CLAs look good, thanks!

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-serving-go-coverage to run the coverage report again

File Old Coverage New Coverage Delta
pkg/activator/util/header.go Do not exist 100.0%
pkg/http/header.go Do not exist 100.0%

@mattmoor
Copy link
Member

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 18, 2018
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, josephburnett, mattmoor

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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 18, 2018
@knative-prow-robot knative-prow-robot merged commit 4155662 into knative:master Sep 18, 2018
@dprotaso dprotaso deleted the activator-header-fix branch September 19, 2018 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants