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

R4R: Implement HTTPS for the LCD REST server #2364

Merged
merged 5 commits into from
Sep 21, 2018

Conversation

alessio
Copy link
Contributor

@alessio alessio commented Sep 20, 2018

In order to guarantee a secure connection between apps and the LCD the communication must be encrypted - even if clients and server run on the same local machine, credentials must never be transmitted in clear text.

Upon start up, if no certificate/key file pair is supplied by the user, the server generates a self-signed certificate and a key; both are stored as temporary files and removal is guaranteed on exit.

This new behaviour is now enabled by default, though users are provided
with a --insecure flag to switch it off.

See #595

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote tests
  • Updated relevant documentation (docs/)
  • Added entries in PENDING.md with issue #
  • rereviewed Files changed in the github PR explorer

For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@codecov
Copy link

codecov bot commented Sep 20, 2018

Codecov Report

Merging #2364 into develop will decrease coverage by 0.38%.
The diff coverage is 39.87%.

@@             Coverage Diff             @@
##           develop    #2364      +/-   ##
===========================================
- Coverage    64.77%   64.39%   -0.39%     
===========================================
  Files          137      138       +1     
  Lines         8469     8617     +148     
===========================================
+ Hits          5486     5549      +63     
- Misses        2620     2693      +73     
- Partials       363      375      +12

@alessio alessio force-pushed the alessio/595-lcd-over-https branch 2 times, most recently from e474e98 to 44b929a Compare September 20, 2018 13:47
@alessio alessio changed the title WIP: Implement HTTPS for the LCD REST server R4R: Implement HTTPS for the LCD REST server Sep 20, 2018
@zmanian
Copy link
Member

zmanian commented Sep 20, 2018

One of the very important attacks that this change should mitigate is the ability to a website to use javascript to search for an instance of LCD and interact with it b/c the browser will not trust this certificate and javascript can't override this.

)

// default: 10 years
const defaultValidFor = 365 * 24 * time.Hour
Copy link
Member

Choose a reason for hiding this comment

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

Can anyone think a reason why 10 year validity is dangerous for a ephemeral cert?

In most cases where you would have a unusually long lived instance of the LCD best practice would be to supply your own Cert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zmanian I've set it to 1 year already. Do you reckon that is reasonable?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe 30 days? @jessysaurusrex What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Certainly not a year either I think. 30 days sounds reasonable. Some other system event might even kill the LCD before that anyway.

client/lcd/certificates.go Outdated Show resolved Hide resolved
// default: 10 years
const defaultValidFor = 365 * 24 * time.Hour

func generateSelfSignedCert(host, ecdsaCurve string, rsaBits int) (certBytes []byte, priv interface{}, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it should only be localhost?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dropped a test case for IPv6 addresses too. IMvHO that should be user's call, though "localhost" sounds like a sane default to me.

client/lcd/root.go Outdated Show resolved Hide resolved
Copy link
Member

@zmanian zmanian left a comment

Choose a reason for hiding this comment

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

Remove the configurability of the self signed cert option and create an option to pass in an externally generated cert.

Copy link
Member

@zmanian zmanian left a comment

Choose a reason for hiding this comment

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

utACK

In order to guarantee a secure connection between apps and the LCD the
communication must be encrypted - even if clients and server run on the
same local machine, credentials must never be transmitted in clear text.

Upon start up, the server generates a self-signed certificate and a key.
Both are stored as temporary files; removal is guaranteed on exit.

This new behaviour is now enabled by default, though users are provided
with a --insecure flag to switch it off.

See #595
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Few minor comments, otherwise great work @alessio 👍

)

// default: 10 years
const defaultValidFor = 365 * 24 * time.Hour
Copy link
Contributor

Choose a reason for hiding this comment

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

Certainly not a year either I think. 30 days sounds reasonable. Some other system event might even kill the LCD before that anyway.


func generateSelfSignedCert(host string) (certBytes []byte, priv *ecdsa.PrivateKey, err error) {
priv, err = ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
notBefore := time.Now()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be using UTC for consistency?

template := x509.Certificate{
SerialNumber: serialNumber,
Subject: pkix.Name{
Organization: []string{"Acme Co"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want some other org here? I guess it doesn't really matter for self-signed certs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Naah, it does not really matter. I could let the user customise it though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do users see this (maybe if they inspect the certificate) - what about "Gaia Lite" as the organization?

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

Thanks - mostly looks good, a few minor comments.

client/lcd/certificates.go Outdated Show resolved Hide resolved
template := x509.Certificate{
SerialNumber: serialNumber,
Subject: pkix.Name{
Organization: []string{"Acme Co"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Do users see this (maybe if they inspect the certificate) - what about "Gaia Lite" as the organization?

client/lcd/certificates.go Show resolved Hide resolved
client/lcd/root.go Outdated Show resolved Hide resolved
client/lcd/root.go Show resolved Hide resolved
@cwgoes
Copy link
Contributor

cwgoes commented Sep 21, 2018

Ah @alessio looks like this breaks the integration tests, can we change those to test the HTTPS server?

Never mind, just an intermittent failure.

@cwgoes cwgoes merged commit e2da4ca into develop Sep 21, 2018
@cwgoes cwgoes deleted the alessio/595-lcd-over-https branch September 21, 2018 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants