Skip to content

PIV login enforcement#15874

Merged
Joerger merged 23 commits into
masterfrom
joerger/piv-login-enforcement
Sep 30, 2022
Merged

PIV login enforcement#15874
Joerger merged 23 commits into
masterfrom
joerger/piv-login-enforcement

Conversation

@Joerger
Copy link
Copy Markdown
Contributor

@Joerger Joerger commented Aug 26, 2022

Part 3 for implementing #14774

Changes:

  • Add PrivateKeyPolicy extension for TLS and SSH certificates, and enforce them for every API request.
  • Add hardware_key/hardware_key_touch enforcement during certificate signing operations.
    • Login endpoints have additional AttestationRequest field. When provided, the auth server will verify the attestation data, sign the certificates with the proper key policy extension, and store the attestation for future checks
      • Certificates generated outside the normal login flow, such as reissued certificates for database sessions or per-Session MFA certificates, get the attestation data from the backend.
      • If the attestation is rejected or not provided when a private key policy is required, Teleport Clients will receive an error containing the missing key policy and must re-login.
    • Before signing certificates, Auth server will check the user's require_session_mfa settings to see if attestation is required. If so, it will try to get a valid attestation from the signing request, or from a previously stored attestation in `/key_attestations/
  • Add private key policy guessing and error logic to tsh and Teleport Connect to automatically enable hardware key login when needed.
    • Add private_key_policy field to Ping response so that a cluster's default private key policy can be discovered.
  • Refactor/Generalize login logic to be reused by tsh and Teleport Connect. Specifically:
    • Abstract ssh login logic to be an sshLoginFunc function of type func(context.Context, *keys.PrivateKey) (*auth.SSHLoginResponse, error)
    • Create new generalized SSHLogin function, which takes an sshLoginFunc, prepares a private key for login, sends it through the login func, parses the response and returns a new client key.
    • Retry login if initial login fails due to a private key policy error.

e PR - https://github.com/gravitational/teleport.e/pull/528

Fixes #10489

@Joerger
Copy link
Copy Markdown
Contributor Author

Joerger commented Aug 26, 2022

@codingllama Could you give the current re-login flow a quick look? This is probably more in line with what you originally had in mind too.

During implementation I realized it would be much easier and simpler to wire attestation logic directly into login (rather than #14774 (comment)). This way, we don't need to add any new endpoints, or worry about handling certificates with reduced privileges.

Right now, the flow is simply:

login (with nil attestation field) -> 
  auth returns attestation error -> 
  get private key policy from error -> 
  bootstrap PIV private key -> 
  login (with valid attestation field) ->
  auth returns certs with proper extensions

Another benefit of this approach is that we have a clear lifetime for attestations stored in the backend - the login certificate TTL.

Once we agree on a solution in this PR, I'll update the RFD to reflect it.

Comment thread api/types/role.go Outdated
@Joerger Joerger force-pushed the joerger/piv-login-enforcement branch from aaf6f73 to 8dfa264 Compare August 26, 2022 20:19
Comment thread api/proto/buf.yaml Outdated
@codingllama
Copy link
Copy Markdown
Contributor

@codingllama Could you give the current re-login flow a quick look? This is probably more in line with what you originally had in mind too.

During implementation I realized it would be much easier and simpler to wire attestation logic directly into login (rather than #14774 (comment)). This way, we don't need to add any new endpoints, or worry about handling certificates with reduced privileges.

Right now, the flow is simply:

login (with nil attestation field) -> 
  auth returns attestation error -> 
  get private key policy from error -> 
  bootstrap PIV private key -> 
  login (with valid attestation field) ->
  auth returns certs with proper extensions

Another benefit of this approach is that we have a clear lifetime for attestations stored in the backend - the login certificate TTL.

Once we agree on a solution in this PR, I'll update the RFD to reflect it.

Yep, that sounds even better to me.

Is there anything in particular in the PR you'd like me to look at?

@Joerger Joerger force-pushed the joerger/piv-login branch 2 times, most recently from 568c473 to c566eec Compare August 30, 2022 19:52
@Joerger Joerger force-pushed the joerger/piv-login-enforcement branch 2 times, most recently from e55f6d7 to 1ccd9f7 Compare August 31, 2022 00:33
This was referenced Aug 31, 2022
@Joerger Joerger force-pushed the joerger/piv-login-enforcement branch from 872bc4b to 91649a4 Compare September 2, 2022 22:09
@Joerger Joerger changed the base branch from joerger/piv-login to joerger/piv-login-enforcement-temporary-base September 2, 2022 22:09
@Joerger Joerger force-pushed the joerger/piv-login-enforcement-temporary-base branch from f3f5d56 to ff839ed Compare September 6, 2022 17:36
@Joerger Joerger force-pushed the joerger/piv-login-enforcement branch from 91649a4 to 06b0e9a Compare September 6, 2022 18:11
@Joerger Joerger force-pushed the joerger/piv-login-enforcement-temporary-base branch from 5936f73 to 8501c7b Compare September 7, 2022 16:22
@Joerger Joerger force-pushed the joerger/piv-login-enforcement branch 2 times, most recently from 52c0fa0 to 659dcdc Compare September 7, 2022 18:49
@Joerger Joerger force-pushed the joerger/piv-login-enforcement-temporary-base branch from 8501c7b to d4f4638 Compare September 12, 2022 23:39
@Joerger Joerger force-pushed the joerger/piv-login-enforcement branch 2 times, most recently from 3cf42de to f2676af Compare September 12, 2022 23:53
@Joerger Joerger force-pushed the joerger/piv-login-enforcement-temporary-base branch 3 times, most recently from 1351549 to 950a80e Compare September 13, 2022 16:49
@Joerger Joerger force-pushed the joerger/piv-login-enforcement branch from f2676af to fe700d0 Compare September 13, 2022 16:54
@Joerger Joerger force-pushed the joerger/piv-login-enforcement-temporary-base branch from 950a80e to 5e83f77 Compare September 14, 2022 01:42
@Joerger Joerger force-pushed the joerger/piv-login-enforcement branch from fe700d0 to bc70db2 Compare September 14, 2022 01:43
Copy link
Copy Markdown
Contributor

@jakule jakule 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 minor comment.

Comment thread api/utils/keys/hardwaresigner_test.go Outdated
@github-actions github-actions Bot removed the request for review from LKozlowski September 29, 2022 01:46
Copy link
Copy Markdown
Contributor

@codingllama codingllama left a comment

Choose a reason for hiding this comment

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

Drive-by review, looking at a couple of changes that caught my eye.

Comment thread api/proto/buf.lock Outdated
Comment thread lib/utils/jsontools.go Outdated
Comment thread lib/utils/jsontools.go Outdated
@Joerger Joerger force-pushed the joerger/piv-login-enforcement branch from 90c0df2 to 2eed478 Compare September 30, 2022 20:36
@Joerger Joerger enabled auto-merge (squash) September 30, 2022 21:13
@Joerger Joerger merged commit ce20b20 into master Sep 30, 2022
wadells added a commit that referenced this pull request Oct 4, 2022
@Joerger missed running it before
#15874 merged.
@Joerger Joerger deleted the joerger/piv-login-enforcement branch October 4, 2022 16:32
wadells added a commit that referenced this pull request Oct 4, 2022
@Joerger missed running it before
#15874 merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kubernetes-access tsh tsh - Teleport's command line tool for logging into nodes running Teleport.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update tsh to use certificates in SSH agent when connecting to a host

6 participants