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

Fix HSTS Missing From HTTPS Server(Nessus Scanner) #96502

Merged
merged 1 commit into from Jan 13, 2021

Conversation

249043822
Copy link
Member

@249043822 249043822 commented Nov 12, 2020

What type of PR is this?

/kind feature

What this PR does / why we need it:

Nessus scanner treats this as a Medium Risk

Which issue(s) this PR fixes:

Fixes #96040

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Adds the ability to pass --strict-transport-security-directives to the kube-apiserver to set the HSTS header appropriately.  Be sure you understand the consequences to browsers before setting this field.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Nov 12, 2020
@k8s-ci-robot
Copy link
Contributor

@249043822: This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Nov 12, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @249043822. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Nov 12, 2020
@fedebongio
Copy link
Contributor

/remove-sig api-machinery
/sig auth

@k8s-ci-robot k8s-ci-robot added sig/auth Categorizes an issue or PR as relevant to SIG Auth. and removed sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Nov 12, 2020
@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Nov 13, 2020
@leilajal
Copy link
Contributor

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Nov 17, 2020
@249043822
Copy link
Member Author

/assign @mikedanese @deads2k

@249043822
Copy link
Member Author

/assign @mikedanese @deads2k

@249043822
Copy link
Member Author

/assgin @liggitt @caesarxuchao

@liggitt
Copy link
Member

liggitt commented Nov 27, 2020

/hold

Thanks for the PR, but we cannot unilaterally indicate all ports on the host the API server was accessed by must be serving https (other processes can be serving http on different ports). This would affect things like development servers on localhost and servers which surface other services via other ports. The same applies to including subdomains… the kube-apiserver cannot make decisions for all subdomains of its host

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 27, 2020
if len(hstsHeaders) != 0 {
for _, hstsHeader := range hstsHeaders {
if len(strings.TrimSpace(hstsHeader)) == 0 {
return fmt.Errorf("empty value in strict-transport-security-headers")
Copy link
Contributor

Choose a reason for hiding this comment

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

build a full slice of errors []error and then use pkg/util/errors.NewAggregate at the end. If memory serves, it correctly results nil on an empty slice, so you get the "easy" behavior that works and all the errors at the same time.

if hstsHeader != "includeSubDomains" && hstsHeader != "preload" {
maxAgeValue := strings.Split(hstsHeader, "=")
if len(maxAgeValue) != 2 || maxAgeValue[0] != "max-age" {
return fmt.Errorf("--strict-transport-security-headers invalid, must be of format: max-age=expireTime,includeSubDomains,preload")
Copy link
Contributor

Choose a reason for hiding this comment

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

please link to the spec saying these are the only valid values. The format appears more flexible to me https://tools.ietf.org/html/rfc6797#section-6.1 with some kind of a registry somewhere for extension.

@@ -161,6 +185,9 @@ func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) {
"List of allowed origins for CORS, comma separated. An allowed origin can be a regular "+
"expression to support subdomain matching. If this list is empty CORS will not be enabled.")

fs.StringSliceVar(&s.HSTSHeaders, "strict-transport-security-headers", s.HSTSHeaders, ""+
Copy link
Contributor

Choose a reason for hiding this comment

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

please provide an example in the usage. I may have misunderstood the code. Are these the hsts directives that go into a single header? The code suggests the header cannot be repeated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, all hsts directives go into a single header

@@ -18,7 +18,9 @@ package options

import (
"fmt"
"k8s.io/apimachinery/pkg/util/errors"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit order. this belongs in the next block of imports.

@deads2k
Copy link
Contributor

deads2k commented Jan 11, 2021

Yea, all hsts directives go into a single header

Sorry about this, I hadn't read in detail before. Can you replace all the headers with directives to match the RFC. The variables and the flags.

/approve

After we get the names fixed, I think this is ready to go.

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 11, 2021
@dims
Copy link
Member

dims commented Jan 11, 2021

what does Nessus scanner treats this as a Medium Risk in kubernetes 1.18.10. mean? @249043822

@dims
Copy link
Member

dims commented Jan 11, 2021

@deads2k looks like we are just trying to make a specific scanner happy. are we going to get a deluge of more such PRs?

@brandond
Copy link

brandond commented Jan 11, 2021

@dims It means someone pointed at security scanning tool at a host running the apiserver and it came back complaining about a HTTPS 'website' not returning HSTS headers. To me these really only make sense to send for a site serving browser traffic, but it doesn't seem like it hurts anything to let someone configure them if it gets their infosec team off their back.

@249043822
Copy link
Member Author

what does Nessus scanner treats this as a Medium Risk in kubernetes 1.18.10. mean? @249043822

@dims The Nessus Scanner report as followers:

MEDIUM HSTS Missing From HTTPS Server
Description
The remote HTTPS server is not enforcing HTTP Strict Transport Security (HSTS). HSTS is an optional response header that can be configured on the server to instruct the browser to only communicate via HTTPS. The lack of HSTS allows downgrade attacks, SSL-stripping man-in-the-middle attacks, and weakens cookie-hijacking protections.

Solution
Configure the remote web server to use HSTS.

See Also
https://tools.ietf.org/html/rfc6797

Output
The remote HTTPS server does not send the HTTP
"Strict-Transport-Security" header.

Port Hosts
6443 / tcp / www

@249043822
Copy link
Member Author

Yea, all hsts directives go into a single header

Sorry about this, I hadn't read in detail before. Can you replace all the headers with directives to match the RFC. The variables and the flags.

/approve

After we get the names fixed, I think this is ready to go.

@deads2k I have fixed these.

@249043822
Copy link
Member Author

/retest

@caesarxuchao
Copy link
Member

/sig-remove api-machinery

@caesarxuchao
Copy link
Member

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jan 12, 2021
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Jan 13, 2021
@deads2k
Copy link
Contributor

deads2k commented Jan 13, 2021

The feedback from the website PR is that the doc is updated automatically.

Please don't do this.
This file is autogenerated, not for direct editing.
The related flag will show up when the feature is in the next release.

The release-note has been specified.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 13, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 249043822, deads2k

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

@k8s-ci-robot k8s-ci-robot merged commit 3351827 into kubernetes:master Jan 13, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.21 milestone Jan 13, 2021
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. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/auth Categorizes an issue or PR as relevant to SIG Auth. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HSTS Header Missing From HTTPS apiserver