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

Add docker security headers via labels #2334

Merged
merged 1 commit into from
Nov 22, 2017

Conversation

dtomcej
Copy link
Contributor

@dtomcej dtomcej commented Oct 26, 2017

This PR creates the ability to configure the security headers for frontends via docker labels.
This should provide comprehensive functionality such as per-frontend SSL redirection.

Based on some of the work done in #2146

Fixes #1903

@dtomcej dtomcej requested a review from a team as a code owner October 26, 2017 19:35
@ldez ldez added this to the 1.5 milestone Oct 26, 2017
@ldez ldez added the kind/enhancement a new or improved feature. label Oct 26, 2017
"getRequestHeaders": p.getRequestHeaders,
"hasResponseHeaders": p.hasResponseHeaders,
"getResponseHeaders": p.getResponseHeaders,
"hasAllowedHostsHeaders": p.hasAllowedHostsHeaders,
Copy link
Contributor

Choose a reason for hiding this comment

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

You can simplify your code like that:

"hasAllowedHostsHeaders":            p.hasLabel(types.LabelFrontendAllowedHosts),
func (p Provider) hasLabel(label string) func(container dockerData) bool {
	return func(container dockerData) bool {
		label, err := getLabel(container, label)
		return err == nil && len(label) > 0
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good Call!

Was just getting code roughed in. I knew that there is a lot of duplication, but I wanted to see it as a whole first, before condensing :)

@dtomcej
Copy link
Contributor Author

dtomcej commented Nov 7, 2017

In case it wasn't clear, I will be integrating k8s annotations in this PR as well, since the functions will be the same.

@ldez
Copy link
Contributor

ldez commented Nov 16, 2017

@dtomcej So that your PR is integrated in the 1.5, it is imperative that it is ready by Tuesday 21 November at the latest. 🚀

@dtomcej
Copy link
Contributor Author

dtomcej commented Nov 16, 2017

Thank you for the reminder! Will have it ready!

@@ -16,6 +16,24 @@ const (
LabelFrontendEntryPoints = LabelPrefix + "frontend.entryPoints"
LabelFrontendRequestHeader = LabelPrefix + "frontend.headers.customrequestheaders"
LabelFrontendResponseHeader = LabelPrefix + "frontend.headers.customresoponseheaders"
Copy link
Contributor

Choose a reason for hiding this comment

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

I just noticed this typo: customresoponseheaders

Copy link
Contributor

Choose a reason for hiding this comment

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

It's already fixed in master

"getServicePassHostHeader": p.getServicePassHostHeader,
"getServicePriority": p.getServicePriority,
"getServiceBackend": p.getServiceBackend,
"getServiceRedirect": p.getServiceRedirect,
Copy link
Contributor

Choose a reason for hiding this comment

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

This entry is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added!

Copy link
Contributor

@nmengin nmengin left a comment

Choose a reason for hiding this comment

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

@dtomcej Many thanks for this PR! 👏

Just few suggestions about the documentation.


| Label | Description |
|-----------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `traefik.frontend.headers.allowedHosts=EXPR` | Provide a list of allowed hosts that requests will be processed. Format: `Host1,Host2` |
Copy link
Contributor

Choose a reason for hiding this comment

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

Provides to be homogeneous with the others lines

|`traefik.frontend.headers.customrequestheaders=EXPR ` | Provides the container with custom request headers that will be appended to each request forwarded to the container. Format: `HEADER:value,HEADER2:value2` |
| `traefik.frontend.headers.customresponseheaders=EXPR` | Appends the headers to each response returned by the container, before forwarding the response to the client. Format: `HEADER:value,HEADER2:value2` |
|`traefik.frontend.headers.hostsProxyHeaders=EXPR ` | Provides a list of headers that the proxied hostname may be stored. Format: `HEADER1,HEADER2` |
| `traefik.frontend.headers.SSLRedirect=true` | Force the frontend to redirect to SSL if a non-SSL request is sent. |
Copy link
Contributor

Choose a reason for hiding this comment

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

Forces to be homogeneous with the others lines

| `traefik.frontend.headers.customresponseheaders=EXPR` | Appends the headers to each response returned by the container, before forwarding the response to the client. Format: `HEADER:value,HEADER2:value2` |
|`traefik.frontend.headers.hostsProxyHeaders=EXPR ` | Provides a list of headers that the proxied hostname may be stored. Format: `HEADER1,HEADER2` |
| `traefik.frontend.headers.SSLRedirect=true` | Force the frontend to redirect to SSL if a non-SSL request is sent. |
| `traefik.frontend.headers.SSLTemporaryRedirect=true` | Force the frontend to redirect to SSL if a non-SSL request is sent, but by sending a 302 instead of a 301. |
Copy link
Contributor

Choose a reason for hiding this comment

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

Forces to be homogeneous with the others lines

func getBoolHeader(container dockerData, containerType string) bool {
label, err := getLabel(container, containerType)
return err == nil && len(label) > 0 && strings.EqualFold(strings.TrimSpace(label), "true")

Copy link
Contributor

Choose a reason for hiding this comment

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

Could your remove this empty line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup!

Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Copy link
Contributor

@nmengin nmengin left a comment

Choose a reason for hiding this comment

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

LGTM 👏 👏

Copy link
Member

@juliens juliens left a comment

Choose a reason for hiding this comment

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

LGTM

add template function list

function frameworks

add prelim function

added template functions

add functions to template

fix case on template vars

fix typo

re-add redirect

update templates

delete autogen

add security headers documentation

fix missing line

chore: add autogen.

chore: remove old generated file.

fix spelling :)

remove missing line
@robholland
Copy link

It doesn't look like this adds support for kubernetes?

@ldez
Copy link
Contributor

ldez commented Nov 23, 2017

@robholland this PR only concern Docker.

@robholland
Copy link

#2334 (comment) says kubernetes would be included and #2146 was closed in favour of this :(

@dtomcej
Copy link
Contributor Author

dtomcej commented Nov 23, 2017

@robholland You are correct. My intention was to have both in this PR, but it was decided to keep the two separate due to testing. Will have a new PR for k8s today. Again, apologies for the delay.

@dtomcej
Copy link
Contributor Author

dtomcej commented Nov 23, 2017

@robholland Discussed with the team, and the new PR will make it into 1.5, so will make the next release, so this delay will not affect the mainline release :)

@robholland
Copy link

Great, thanks! :)

| Label | Description |
|-----------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `traefik.frontend.headers.allowedHosts=EXPR` | Provides a list of allowed hosts that requests will be processed. Format: `Host1,Host2` |
|`traefik.frontend.headers.customrequestheaders=EXPR ` | Provides the container with custom request headers that will be appended to each request forwarded to the container. Format: `HEADER:value,HEADER2:value2` |
Copy link

Choose a reason for hiding this comment

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

are these meant to be lowercase or camel case?

traefik.frontend.headers.customrequestheaders should be traefik.frontend.headers.customRequestHeaders

Copy link
Contributor

@ldez ldez Nov 30, 2017

Choose a reason for hiding this comment

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

@vito-c Please open an issue instead of commented an already merged PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@vito-c or open a PR. thanks

@@ -16,6 +16,24 @@ const (
LabelFrontendEntryPoints = LabelPrefix + "frontend.entryPoints"
LabelFrontendRequestHeader = LabelPrefix + "frontend.headers.customrequestheaders"
Copy link

Choose a reason for hiding this comment

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

if camelcase then these should be updated as well

Copy link
Contributor

@ldez ldez Nov 30, 2017

Choose a reason for hiding this comment

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

@vito-c Please open an issue instead of commented an already merged PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@vito-c or open a PR. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants