Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Add strict transport security and secure cookie options#741

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
f0ssel merged 6 commits intomainfromf0ssel/security
Mar 31, 2022

Conversation

f0ssel
Copy link
Contributor

No description provided.

@codecov
Copy link

codecovbot commentedMar 30, 2022
edited
Loading

Codecov Report

Merging#741 (49f2e75) intomain (6ab1a68) willdecrease coverage by0.37%.
The diff coverage is100.00%.

@@            Coverage Diff             @@##             main     #741      +/-   ##==========================================- Coverage   64.31%   63.93%   -0.38%==========================================  Files         198      199       +1       Lines       11635    11830     +195       Branches       87       87              ==========================================+ Hits         7483     7564      +81- Misses       3351     3441      +90- Partials      801      825      +24
FlagCoverage Δ
unittest-go-63.03% <100.00%> (-0.61%)⬇️
unittest-go-macos-latest58.98% <100.00%> (-0.05%)⬇️
unittest-go-ubuntu-latest61.79% <100.00%> (-0.21%)⬇️
unittest-go-windows-202258.07% <100.00%> (-0.23%)⬇️
unittest-js62.63% <ø> (ø)
Impacted FilesCoverage Δ
coderd/coderd.go96.47% <ø> (ø)
cli/start.go66.00% <100.00%> (-0.16%)⬇️
coderd/users.go57.41% <100.00%> (+0.05%)⬆️
coderd/database/db.go55.17% <0.00%> (-13.80%)⬇️
coderd/provisionerdaemons.go59.52% <0.00%> (-4.56%)⬇️
coderd/parameter/compute.go74.07% <0.00%> (-4.45%)⬇️
cli/ssh.go38.88% <0.00%> (-4.45%)⬇️
agent/conn.go65.38% <0.00%> (-3.59%)⬇️
agent/agent.go67.30% <0.00%> (-1.09%)⬇️
peer/conn.go75.38% <0.00%> (-1.02%)⬇️
... and15 more

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update6ab1a68...49f2e75. Read thecomment docs.

Emyrk
Emyrk previously requested changesMar 30, 2022
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if hsts {
w.Header().Set(HSTSHeader, fmt.Sprintf("max-age=%d", int64(HSTSMaxAge)))
Copy link
Member

Choose a reason for hiding this comment

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

The time should be in seconds. Golang times are int64 innanoseconds

f0ssel reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Should we make the value of this header configurable by the flag? With "true" defaulting to ourmax-age? Seems like there's a swath of options that wecould set, but might not have the best idea when it's appropriate.

Copy link
Member

Choose a reason for hiding this comment

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

Idk, HSTSshould be applied to a long time. Like 1-2 years. Anything shorter is strange. Idk why you'd set it short.

Copy link
Member

Choose a reason for hiding this comment

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

I'd just stick withon/off

Copy link
Member

Choose a reason for hiding this comment

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

There's an optionincludeSubdomains you can add too. What happens when a customer asks for it? Unless we're confident they won't, it's really simple for us to add now.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I think adding things that aren't required is a big part of what helped get v1 where it is today. No one asking for this is a bet I would take 10/10 times right now.

I could see an argument for changing this toCODER_STRICT_SECURITY_HEADER with the default value"" in which we don't set it, and otherwise they provide the value for the header - like"max-age=63072000;"

kylecarbs reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

I think your argument is fair. It's weird to offer something nobody is asking for, and this is easy to change later too!

t.Parallel()

res := setup(true)
require.Contains(t, res.Header.Get(httpmw.HSTSHeader), fmt.Sprintf("max-age=%d", int64(httpmw.HSTSMaxAge)))
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather us hard code the seconds integer, given that this value is likely massively too high atm.

f0ssel and kylecarbs reacted with thumbs up emoji
t.Parallel()

res := setup(false)
require.NotContains(t, res.Header.Get(httpmw.HSTSHeader), fmt.Sprintf("max-age=%d", int64(httpmw.HSTSMaxAge)))
Copy link
Member

Choose a reason for hiding this comment

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

The false case should probably check it contains the empty string ""

f0ssel reacted with thumbs up emoji
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if hsts {
w.Header().Set(HSTSHeader, fmt.Sprintf("max-age=%d", int64(HSTSMaxAge)))
Copy link
Member

Choose a reason for hiding this comment

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

Should we make the value of this header configurable by the flag? With "true" defaulting to ourmax-age? Seems like there's a swath of options that wecould set, but might not have the best idea when it's appropriate.

cli/start.go Outdated
@@ -334,6 +338,8 @@ func start() *cobra.Command {
cliflag.BoolVarP(root.Flags(), &useTunnel, "tunnel", "", "CODER_DEV_TUNNEL", true, "Serve dev mode through a Cloudflare Tunnel for easy setup")
_ = root.Flags().MarkHidden("tunnel")
cliflag.BoolVarP(root.Flags(), &traceDatadog, "trace-datadog", "", "CODER_TRACE_DATADOG", false, "Send tracing data to a datadog agent")
cliflag.BoolVarP(root.Flags(), &hsts, "hsts", "", "CODER_HSTS", false, "Set the 'strict-transport-security' header on http responses")
Copy link
Member

Choose a reason for hiding this comment

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

HSTS andstruct-transport-security confuse me a bit. With my other comment, could we call this:

CODER_STRICT_TRANSPORT_SECURITY

f0ssel reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I had this originally and thought it may be too long and changed it lol.

kylecarbs reacted with thumbs up emoji
cli/start.go Outdated
@@ -334,6 +338,8 @@ func start() *cobra.Command {
cliflag.BoolVarP(root.Flags(), &useTunnel, "tunnel", "", "CODER_DEV_TUNNEL", true, "Serve dev mode through a Cloudflare Tunnel for easy setup")
_ = root.Flags().MarkHidden("tunnel")
cliflag.BoolVarP(root.Flags(), &traceDatadog, "trace-datadog", "", "CODER_TRACE_DATADOG", false, "Send tracing data to a datadog agent")
cliflag.BoolVarP(root.Flags(), &hsts, "hsts", "", "CODER_HSTS", false, "Set the 'strict-transport-security' header on http responses")
cliflag.BoolVarP(root.Flags(), &secureCookie, "secure-cookie", "", "CODER_SECURE_COOKIE", false, "Set the 'Secure' property on browser session cookies")
Copy link
Member

Choose a reason for hiding this comment

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

Our description would be more helpful if it linked to MDN or something. As a user, I'd just Google that right away!

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

We do in the dash but I wanted to keep these help docs slim. But I'm down to add it if we don't mind the verbosity.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I personally kind of like just letting people google the header? It's super easy to grok

Copy link
Member

Choose a reason for hiding this comment

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

In that case, I'd adjust these to use" like other parameter help sections do for consistency. I wouldn't call thisSet either. In other commands we useSpecifies, which I think more accurately describes it (because it's a bool).

f0ssel reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

SecureCookie might be worth explicitly statingSecureAuthCookie instead. That way there's no ambiguity.

f0ssel reacted with thumbs up emoji
Comment on lines 11 to 12

"github.com/coder/coder/coderd/httpmw"
Copy link
Member

Choose a reason for hiding this comment

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

close this import gap

@f0ssel
Copy link
ContributorAuthor

Updated with the feedback. I think we should keep max-age unconfigurable for now, it's really easy to add it later as a envflag and I'm not convinced anyone will ever ask for it.

@f0sself0sselforce-pushed thef0ssel/security branch 3 times, most recently fromb7eda3e to803313dCompareMarch 30, 2022 22:31
Comment on lines 10 to 12
"github.com/stretchr/testify/require"

"github.com/coder/coder/coderd/httpmw"
Copy link
Member

Choose a reason for hiding this comment

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

Wait still need to close this gap right? Github imports have no newline gaps?

Copy link
Member

Choose a reason for hiding this comment

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

Nah, they do forinternal imports.

Copy link
Member

@kylecarbskylecarbs left a comment

Choose a reason for hiding this comment

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

Make sure to rename thehsts*.go files before merge. I added another comment about renamingsecureCookie tosecureAuthCookie instead, which I think makes it a bit more explicit.

I don't think we should export objectsjust for testing. Apart from that, looks good to me!


const (
StrictTransportSecurityHeader = "Strict-Transport-Security"
StrictTransportSecurityMaxAge = time.Hour * 24 * 365 // 1 year
Copy link
Member

Choose a reason for hiding this comment

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

If we just check for the existence of the header, we can remove these as exports.

Exporting just for tests is bad practice from my perspective. If a customer were to depend on these constant values and they changed randomly, it would break their stuff. Tests should run against the API just like a customer would.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

We have a lint rule that requires that tests usehttmw_test package which then forces you to export. I'll figure out how to disable that linter?

Copy link
Member

Choose a reason for hiding this comment

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

We should disable that lint rule, as it prevents us from creating good package scopes.

I think it's totally reasonable to test unexported vars/consts.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should disable that linter, I think we should duplicate the values!

Customers testing against our APIs likely won't use our constants, they'll probably use the values.

I intentionally enabled that linter to avoid package bloat and poor decomposition.

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/maratori/testpackage

I recommend you read the attached posts (there are like four of them) describing its intention. If you still disagree, I'm happy to reconsider.

Copy link
ContributorAuthor

@f0sself0sselMar 31, 2022
edited
Loading

Choose a reason for hiding this comment

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

I personally see the value, and get the philosophy forcing tests to use the public api. Also I'm behind the duplicate values thing too, I considered that solution as well.

I do however think when it comes to testing I'd rather have both public and private functional testing as anoption if we want it. I see value in the forcing function but think it may be too heavy handed to say "no private function testing".

I'll dupe the values for this PR and keep the lint rule for now.

Copy link
ContributorAuthor

@f0sself0sselMar 31, 2022
edited
Loading

Choose a reason for hiding this comment

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

I think the "export_test" example (the 4th link) is a pretty bad pattern. I wouldn't want to have a test file dedicated to bridging the gap and avoid the linter, seems super confusing and fighting the toolchain.

Emyrk reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Ah we can doXXX_internal_test.go. So I'm good with the linter if we have the option to go around it 👍.

Copy link
Member

Choose a reason for hiding this comment

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

I think the "export_test" example (the 4th link) is a pretty bad pattern. I wouldn't want to have a test file dedicated to bridging the gap and avoid the linter, seems super confusing and fighting the toolchain.

Yea, I was not a fan of that either. I think with the_internal_ option for naming though, we can still write internal tests. I am fine with that.

Copy link
Member

@kylecarbskylecarbsMar 31, 2022
edited
Loading

Choose a reason for hiding this comment

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

Exactly! There are of course edge-cases, but the linting rule optimizes for 95% of cases. In the 5% where it doesn't fit, the_internal_ pattern provides well.

f0ssel reacted with thumbs up emoji
@f0sself0sselforce-pushed thef0ssel/security branch 2 times, most recently from96bcf77 to368ead5CompareMarch 31, 2022 02:13
Comment on lines 9 to 13
const (
strictTransportSecurityHeader = "Strict-Transport-Security"
strictTransportSecurityMaxAge = time.Hour * 24 * 365 // 1 year
)

Copy link
Member

Choose a reason for hiding this comment

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

Since these are just used in the one place, I don't think they should be constants.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

consts are more self documenting (variable name) and cleaner code to read imo. I feel like I was told never to use magic numbers like day 1 of programming and have never looked back.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I did it anyways to get this pr merged....

Copy link
Member

Choose a reason for hiding this comment

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

We can leave em' as consts that's just a minor nit.

Comment on lines 16 to 19
const (
strictTransportSecurityHeader = "Strict-Transport-Security"
strictTransportSecurityMaxAge = time.Hour * 24 * 365
)
Copy link
Member

Choose a reason for hiding this comment

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

These should probably be in the test function scope. If they aren't used globally between tests, it could be confusing.

f0ssel reacted with thumbs up emoji
Copy link
Member

@kylecarbskylecarbs left a comment

Choose a reason for hiding this comment

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

LGTM! One comment is just a question, not a change.

r.Use(chitrace.Middleware())
r.Use(
chitrace.Middleware(),
httpmw.StrictTransportSecurity(api.StrictTransportSecurity),
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed for static assets as well?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@Emyrk ? I don't know but my guess is "no" because it will already be set on the browser after the first api call and also static assets would never have sensitive data.

Copy link
Member

Choose a reason for hiding this comment

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

HSTSshould be on static, but I think it might not really matter as you only need to hit 1 HSTS header for it "take effect". Every HSTS header after is redundant

Copy link
Member

Choose a reason for hiding this comment

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

We should probably move it outside of there then, just to confirm properly.

@kylecarbs
Copy link
Member

We should update the title too- since we renamedHSTS toStrictTransportSecurity.

@f0sself0ssel changed the titlefeat: Add HSTS and secure cookie optionsfeat: Add strict transport security and secure cookie optionsMar 31, 2022
kylecarbs added a commit that referenced this pull requestMar 31, 2022
A discussion (linked below) was had that touched on why this linteris enabled. To avoid losing that history, adding the comment inline withour linting rules can avoid duplicating this discussion!#741 (comment)
@ammario
Copy link
Member

HSTS should be configured by a load balancer or proxy, not the end application. It's a niche requirement and readily configurable by almost every reverse proxy.

Not even GitLab has built in HSTS. Instead, they suggest users configure nginx.

ammario
ammario previously requested changesMar 31, 2022
Copy link
Member

@ammarioammario left a comment

Choose a reason for hiding this comment

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

(See my comment)

@f0ssel
Copy link
ContributorAuthor

@ammario can I link this comment in 6 months when an enterprise customer / our PM asks for this again like they did in v1?

@ammario
Copy link
Member

@f0ssel of course :)

@f0sself0ssel dismissed stale reviews fromammario andEmyrkMarch 31, 2022 17:30

deleted the code

@f0sself0ssel merged commit0d53795 intomainMar 31, 2022
@f0sself0ssel deleted the f0ssel/security branchMarch 31, 2022 17:31
kylecarbs added a commit that referenced this pull requestMar 31, 2022
A discussion (linked below) was had that touched on why this linteris enabled. To avoid losing that history, adding the comment inline withour linting rules can avoid duplicating this discussion!#741 (comment)
@missknissmisskniss added this to theV2 Beta milestoneMay 15, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@EmyrkEmyrkAwaiting requested review from Emyrk

@kylecarbskylecarbsAwaiting requested review from kylecarbs

@ammarioammarioAwaiting requested review from ammario

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
V2 Beta
Development

Successfully merging this pull request may close these issues.

5 participants
@f0ssel@kylecarbs@ammario@Emyrk@misskniss

[8]ページ先頭

©2009-2025 Movatter.jp