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

cli: prompt to accept the server TLS certificate for manual verification #2177

Merged
merged 11 commits into from
Jun 20, 2022

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Jun 2, 2022

Summary

This PR adds a new prompt to infra login when the servers TLS certificate is not already trusted. The prompt gives the user information about the server certificate and allows them to manually trust it.

Once trusted, the user will be able to login again to the same server without being prompted again.

This is a significant enhancement over --skip-tls-verify because even if the user doesn't properly inspect the fingerprint, the only opportunity for a man-in-the-middle attack is on that first request. Every subsequent request is secure.

In a follow up PR I will:

  • add a command line flag to specify a trusted certificate
  • add the same flag to the connector
  • update the quickstart to remove --skip-tls-verify

Related Issues

Resolves #1541

@dnephin dnephin force-pushed the dnephin/cli-accept-cert branch from 8726982 to 446f6aa Compare June 2, 2022 20:50
@infrahq infrahq deleted a comment from CLAassistant Jun 3, 2022
@CLAassistant
Copy link

CLAassistant commented Jun 3, 2022

CLA assistant check
All committers have signed the CLA.

internal/cmd/login.go Show resolved Hide resolved
internal/cmd/login.go Outdated Show resolved Hide resolved
@dnephin dnephin force-pushed the dnephin/cli-accept-cert branch from 446f6aa to f0abc35 Compare June 3, 2022 21:43
@dnephin dnephin force-pushed the dnephin/cli-accept-cert branch 6 times, most recently from 553d73f to 08a6424 Compare June 13, 2022 20:12
@dnephin dnephin marked this pull request as ready for review June 13, 2022 20:12
Copy link
Collaborator

@BruceMacD BruceMacD left a comment

Choose a reason for hiding this comment

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

I'm getting an error while attempting to test this on localhost any ideas?

$ infra login localhost
Error: Get "https://localhost": x509: “Infra” certificate is not trusted

This shouldn't block login like this completely I imagine.

internal/cmd/cmd.go Show resolved Hide resolved
internal/cmd/login.go Show resolved Hide resolved
internal/cmd/login.go Show resolved Hide resolved
@dnephin dnephin force-pushed the dnephin/cli-accept-cert branch 2 times, most recently from 35a0bf3 to bde40b7 Compare June 14, 2022 20:13
@dnephin
Copy link
Contributor Author

dnephin commented Jun 14, 2022

@BruceMacD this should be working on MacOS now. We have to repeat the request without the system cert pool to get the right error type.

destinations, err := client.ListDestinations(api.ListDestinationsRequest{})
if err != nil {
return nil
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching this


Certificate

Subject: %[1]s
Copy link
Contributor

@jmorganca jmorganca Jun 15, 2022

Choose a reason for hiding this comment

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

This is awesome. I wonder if we can trim this down a bit – e.g. do we need validity period, SANs, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I removed the SAN fields. We definitely don't need those since they will be verified automatically by the client.

I left the validity times, but I added a human readable version first which hopefully makes it read better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice work!

internal/cmd/login.go Show resolved Hide resolved
Copy link
Collaborator

@BruceMacD BruceMacD left a comment

Choose a reason for hiding this comment

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

This works great for me now, I agree with Jeff's comment about cutting down on the size of the output for trusting the cert, but I think we should leave the expiry in the output.

internal/cmd/login.go Show resolved Hide resolved
internal/cmd/login.go Show resolved Hide resolved
@dnephin dnephin force-pushed the dnephin/cli-accept-cert branch from bde40b7 to 84c21c1 Compare June 15, 2022 21:01
DNS Names: %[5]s
IP Addresses: %[6]v

SHA-256 Fingerprint
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this get printed in the server logs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does, but unfortunately only when the cert is first created.

As part of #2176 I'd like to change cert generation to happen at startup, instead of on first request. If we make that change we can have the fingerprint printed on every startup, instead of only when it is first created. That will ensure that the value is always in the logs for the pod. I believe right now it'll be hard to find if the server pod was recreated after the cert is generated.

The admin can also generate the the value using:

openssl x509 -noout -fingerprint -sha256 -inform pem -in

As long as they know where to find the certificate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, we can address that in a follow up change that moves cert generation to server start

dnephin added 7 commits June 16, 2022 13:43
And resolve a few TODOs around errors
So that as we upgrade the version of this config, tests should continue to use the latest version

Also fixes a TODO about a failing test. The config migration was doing something surprising when the
config had no version.
By using the new Description field.

Also fix a bug, previously the cerificate was not being saved as PEM
encoded on the second save.
previously our tests were not catching this problem because of the return nil.

With that fixed, the tests fail properly.
On darwin the error was of the wrong type when using the system cert pool
@dnephin dnephin force-pushed the dnephin/cli-accept-cert branch from ab498d9 to 6071725 Compare June 16, 2022 17:45
@dnephin dnephin merged commit 2d4e4b1 into main Jun 20, 2022
@dnephin dnephin deleted the dnephin/cli-accept-cert branch June 20, 2022 16:49
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.

Allow users to manually trust the server certificate on infra login
4 participants