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

Ability to disable Envoy adding server headers to responses #4906

Merged
merged 17 commits into from
Jan 23, 2023

Conversation

vishal-chdhry
Copy link
Member

Signed-off-by: Vishal Choudhary contactvishaltech@gmail.com

adds server_header_transformation on HTTPConnectionManager
Fixes: #4359

Signed-off-by: Vishal Choudhary <contactvishaltech@gmail.com>
@vishal-chdhry vishal-chdhry requested a review from a team as a code owner December 7, 2022 18:27
@vishal-chdhry vishal-chdhry requested review from stevesloka and sunjayBhatia and removed request for a team December 7, 2022 18:27
Signed-off-by: Vishal Choudhary <contactvishaltech@gmail.com>
Signed-off-by: Vishal Choudhary <contactvishaltech@gmail.com>
@github-actions
Copy link

github-actions bot commented Jan 7, 2023

The Contour project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 14d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, the PR is closed

You can:

  • Mark this PR as fresh by commenting or pushing a commit
  • Close this PR
  • Offer to help out with triage

Please send feedback to the #contour channel in the Kubernetes Slack

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 7, 2023
@skriss skriss removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 11, 2023
@skriss skriss self-requested a review January 11, 2023 16:30
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
@vishal-chdhry vishal-chdhry changed the title WIP: Ability to disable Envoy adding server headers to responses Ability to disable Envoy adding server headers to responses Jan 14, 2023
Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

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

internal/contourconfig/contourconfiguration.go Outdated Show resolved Hide resolved
@@ -125,6 +125,9 @@ type ListenerConfig struct {
// MergeSlashes toggles Envoy's non-standard merge_slashes path transformation option for all listeners.
MergeSlashes bool

// ServerHeaderTransformation signifies we will not modify the Server header.
Copy link
Member

Choose a reason for hiding this comment

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

Update godoc to reflect enum nature

Copy link
Member

@skriss skriss Jan 20, 2023

Choose a reason for hiding this comment

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

Suggested change
// ServerHeaderTransformation signifies we will not modify the Server header.
// ServerHeaderTransformation defines the action to be applied to the Server header on the response path.

apis/projectcontour/v1alpha1/contourconfig.go Outdated Show resolved Hide resolved
apis/projectcontour/v1alpha1/contourconfig.go Outdated Show resolved Hide resolved
pkg/config/parameters.go Outdated Show resolved Hide resolved
pkg/config/parameters.go Outdated Show resolved Hide resolved
@skriss
Copy link
Member

skriss commented Jan 18, 2023

@vishal-chdhry just wanted to let you know that we are planning to cut a release candidate for 1.24 ~next Monday, so if possible it'd be great to get this updated by then.

@vishal-chdhry
Copy link
Member Author

@vishal-chdhry just wanted to let you know that we are planning to cut a release candidate for 1.24 ~next Monday, so if possible it'd be great to get this updated by then.

sure, i will be on it right away

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
@vishal-chdhry
Copy link
Member Author

@skriss how should I add the unit tests?

@vishal-chdhry vishal-chdhry requested a review from skriss January 19, 2023 05:21
apis/projectcontour/v1alpha1/contourconfig.go Outdated Show resolved Hide resolved
apis/projectcontour/v1alpha1/contourconfig.go Outdated Show resolved Hide resolved
apis/projectcontour/v1alpha1/contourconfig.go Outdated Show resolved Hide resolved
pkg/config/parameters.go Outdated Show resolved Hide resolved
pkg/config/parameters.go Outdated Show resolved Hide resolved
pkg/config/parameters.go Outdated Show resolved Hide resolved
site/content/docs/main/configuration.md Outdated Show resolved Hide resolved
@skriss
Copy link
Member

skriss commented Jan 19, 2023

Unit tests to add:

@skriss skriss added the release-note/small A small change that needs one line of explanation in the release notes. label Jan 19, 2023
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
@vishal-chdhry vishal-chdhry requested a review from skriss January 20, 2023 05:23
@vishal-chdhry
Copy link
Member Author

Unit tests to add:

@skriss done

Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

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

@vishal-chdhry one more round of minor feedback and then I think this is about ready to merge.

cmd/contour/servecontext_test.go Outdated Show resolved Hide resolved
@@ -125,6 +125,9 @@ type ListenerConfig struct {
// MergeSlashes toggles Envoy's non-standard merge_slashes path transformation option for all listeners.
MergeSlashes bool

// ServerHeaderTransformation signifies we will not modify the Server header.
Copy link
Member

@skriss skriss Jan 20, 2023

Choose a reason for hiding this comment

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

Suggested change
// ServerHeaderTransformation signifies we will not modify the Server header.
// ServerHeaderTransformation defines the action to be applied to the Server header on the response path.

internal/envoy/v3/listener.go Outdated Show resolved Hide resolved
internal/xdscache/v3/listener_test.go Outdated Show resolved Hide resolved
internal/envoy/v3/listener_test.go Outdated Show resolved Hide resolved
internal/featuretests/v3/listeners_test.go Outdated Show resolved Hide resolved
// When configured as APPEND_IF_ABSENT, ⁣If no Server header is present, append Server server_name If a Server header is present, pass it through.
// When configured as PASS_THROUGH, ⁣Pass through the value of the server header, and do not append a header if none is present.
//
// Values: `OVERWRITE` (default), `APPEND_IF_ABSENT`, `PASS_THROUGH`
Copy link
Member

Choose a reason for hiding this comment

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

@sunjayBhatia WDYT about casing here of the values here? For DNS lookup family we lowercased, but I don't see existing multi-word options. I guess we could switch these to lowercase, but honestly not sure if there's any point in doing so.

Copy link
Member Author

Choose a reason for hiding this comment

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

actually it's an integer in envoy

Copy link
Member

Choose a reason for hiding this comment

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

hm yeah as you say many if not all the other relevant consts in this package and pkg/config we define are lowercase, so for consistency we could switch to that, since we're not really going to pass the value straight through to Envoy it doesn't really matter

changelogs/unreleased/4906-Vishal-Chdhry-small.md Outdated Show resolved Hide resolved
@skriss skriss added release-note/minor A minor change that needs about a paragraph of explanation in the release notes. and removed release-note/small A small change that needs one line of explanation in the release notes. labels Jan 20, 2023
@skriss
Copy link
Member

skriss commented Jan 20, 2023

Looks like you need to re-run make generate and commit the results as well.

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
@vishal-chdhry vishal-chdhry requested a review from skriss January 21, 2023 16:03
skriss
skriss previously approved these changes Jan 23, 2023
Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

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

LGTM other than the enum value casing change, which we can change in a follow-up PR so we can get this in. Thanks for the work on this @vishal-chdhry!

@skriss skriss dismissed their stale review January 23, 2023 16:16

unit tests failing

@skriss
Copy link
Member

skriss commented Jan 23, 2023

Just noticed that there are some unit test failures that need to be addressed.

Signed-off-by: Steve Kriss <krisss@vmware.com>
@skriss
Copy link
Member

skriss commented Jan 23, 2023

I pushed fixes so we can get this in for the RC.

Signed-off-by: Steve Kriss <krisss@vmware.com>
@codecov
Copy link

codecov bot commented Jan 23, 2023

Codecov Report

Merging #4906 (b7cf999) into main (33964d6) will increase coverage by 0.05%.
The diff coverage is 89.79%.

❗ Current head b7cf999 differs from pull request most recent head 147e890. Consider uploading reports for the commit 147e890 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4906      +/-   ##
==========================================
+ Coverage   77.55%   77.60%   +0.05%     
==========================================
  Files         138      138              
  Lines       16789    16837      +48     
==========================================
+ Hits        13021    13067      +46     
- Misses       3513     3516       +3     
+ Partials      255      254       -1     
Impacted Files Coverage Δ
cmd/contour/serve.go 22.28% <0.00%> (-0.04%) ⬇️
internal/envoy/v3/listener.go 98.40% <83.33%> (-0.30%) ⬇️
cmd/contour/servecontext.go 80.83% <84.61%> (-0.08%) ⬇️
internal/contourconfig/contourconfiguration.go 96.93% <100.00%> (+0.01%) ⬆️
internal/xdscache/v3/listener.go 91.41% <100.00%> (+0.07%) ⬆️
pkg/config/parameters.go 86.97% <100.00%> (+0.35%) ⬆️
internal/xds/v3/callbacks.go 100.00% <0.00%> (ø)
internal/xds/v3/contour.go 100.00% <0.00%> (+3.22%) ⬆️

@skriss
Copy link
Member

skriss commented Jan 23, 2023

Pushed the lowercasing changes here too.

Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

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

LGTM, will wait for @sunjayBhatia to take one more look

@@ -336,6 +336,18 @@ type EnvoyListenerConfig struct {
// +optional
DisableMergeSlashes *bool `json:"disableMergeSlashes,omitempty"`

// Defines the action to be applied to the Server header on the response path
// When configured as overwrite, overwrites any Server header with the contents of server_name.
Copy link
Member

Choose a reason for hiding this comment

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

in this section probably replace server_name with envoy? since we don't make it configurable (i think this was copied from the envoy docs)

// Defines the action to be applied to the Server header on the response path
// When configured as overwrite, overwrites any Server header with the contents of server_name.
// When configured as append_if_absent, ⁣If no Server header is present, append Server server_name If a Server header is present, pass it through.
// When configured as pass_through, pPass through the value of the server header, and do not append a header if none is present.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// When configured as pass_through, pPass through the value of the server header, and do not append a header if none is present.
// When configured as pass_through, pass through the value of the server header, and do not append a header if none is present.

type ServerHeaderTransformationType string

const (
// Overwrite any Server header with the contents of server_name.
Copy link
Member

Choose a reason for hiding this comment

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

maybe similar here with server_name

@@ -489,6 +505,14 @@ type Parameters struct {
// which strips duplicate slashes from request URL paths.
DisableMergeSlashes bool `yaml:"disableMergeSlashes,omitempty"`

// Defines the action to be applied to the Server header on the response path
// When configured as overwrite, overwrites any Server header with the contents of server_name.
Copy link
Member

Choose a reason for hiding this comment

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

similar comment about server_name

Signed-off-by: Steve Kriss <krisss@vmware.com>
@skriss skriss merged commit cf769c1 into projectcontour:main Jan 23, 2023
vmw-yingy pushed a commit to vmw-yingy/contour that referenced this pull request Feb 28, 2023
…rojectcontour#4906)

Adds support for configuring Envoy's server
header transformation, which customizes how
Envoy treats the Server header on responses.
The Server header can now be passed through
as-is or only set to "envoy" if no other value
is present, in addition to the default behavior
of always setting the Server header to "envoy".

Closes projectcontour#4359.

Signed-off-by: Vishal Choudhary <contactvishaltech@gmail.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: Steve Kriss <krisss@vmware.com>
Co-authored-by: Steve Kriss <krisss@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/minor A minor change that needs about a paragraph of explanation in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to disable Envoy adding server headers to responses
3 participants