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

hardware key runners #1977

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

James-Pickett
Copy link
Contributor

@James-Pickett James-Pickett commented Dec 4, 2024

  • adds secure enclave create key command to desktop user server, client, and root desktop runner
  • adds a "runner" style struct to handle initializing keys for both tpm and secure enclave that is added to the rungroup in main launcher command, this allows for initializing (and retrying failures) of tpm and secure enclave keys
  • signing with secure enclave will come in a follow on PR

@James-Pickett James-Pickett changed the title rough draft hardware key runners Dec 4, 2024
"err", err,
)

if currentRetryInterval < maxRetryInterval {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lazy backoff ... is there a better way or is this good enough?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this and think it's good enough! Since you use it here and in the tpmrunner (and since I can imagine it being useful in other areas too) I wonder if we might want to extract it into pkg/backoff?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I just saw we do actually have a Backoff in that package -- I forgot we had anything in there besides WaitFor 😅 . Maybe an opportunity to use that/combine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't really like what was in there for this application, because there was no way to stop, so I created a custom ticker with "Multiplicative Backoff" (duration * ticks) ... maybe went a little overboard =)

@James-Pickett James-Pickett marked this pull request as ready for review December 5, 2024 23:32
Copy link
Contributor

@RebeccaMahany RebeccaMahany left a comment

Choose a reason for hiding this comment

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

I really like how all of this fits together with the runners!

ee/desktop/user/client/client.go Outdated Show resolved Hide resolved
ee/secureenclaverunner/secureenclaverunner.go Show resolved Hide resolved
ee/secureenclaverunner/secureenclaverunner.go Outdated Show resolved Hide resolved
ee/secureenclaverunner/secureenclaverunner.go Show resolved Hide resolved
defer ser.mux.Unlock()

cu, err := firstConsoleUser(ctx)
if err != nil {
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 a special error for no console users found (from line 265 below) so we can distinguish between that case and consoleuser.CurrentUsers(ctx) returning an error (257) here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I started to do this, but I don't see where we would need to switch on the error and behave differently. Do you have a specific case in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggested this while thinking about the other comment on handling the case where there's no console user -- #1977 (comment). I thought we might want special handling for the case where there's no console user (e.g. maybe back off to a longer interval faster? or something else?), so we'd need a specific error to be able to detect that state.

ee/tpmrunner/tpmrunner_test.go Show resolved Hide resolved
@@ -0,0 +1,241 @@
package tpmrunner
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you add a quick diagram/writeup in the docs/architecture folder for this? Since this work traverses both root and user launcher, and the implementation differs between darwin/other OSes (plus the keys are pretty important) I think it's worth documenting how the different pieces fit together. Doesn't have to be in this PR!

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little curious about this as well. I understand why we need to move the secure enclave signing. But I'm much less sure what's happening with the TPM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@RebeccaMahany , I will write up some docs for this PR

@directionless there are 2 reasons I went ahead and made the tpm a "runner" style like secure enclave.

  1. We do see errors pop up with TPM operations that I can't reproduce. I'm hoping that these have something to do with the TPM not being ready or unavailable for some reason, taking this route we'll keep trying in the background hoping it becomes available.

  2. It felt cleaner to have both hardware signature mechanisms operate in the same way. Understanding that no kind of hardware signing can be expected to be available immediately after start up.

ee/tpmrunner/tpmrunner.go Outdated Show resolved Hide resolved
ee/tpmrunner/tpmrunner.go Outdated Show resolved Hide resolved
"err", err,
)

if currentRetryInterval < maxRetryInterval {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this and think it's good enough! Since you use it here and in the tpmrunner (and since I can imagine it being useful in other areas too) I wonder if we might want to extract it into pkg/backoff?

"github.com/kolide/launcher/pkg/traces"
)

func setupHardwareKeys(ctx context.Context, slogger *slog.Logger, store types.GetterSetterDeleter) (keyInt, error) {
// SetHardwareKeysRunner creates a secure enclave runner and sets it as the agent hardware key as it also implements the keyInt/cyrpto.Signer interface.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// SetHardwareKeysRunner creates a secure enclave runner and sets it as the agent hardware key as it also implements the keyInt/cyrpto.Signer interface.
// SetHardwareKeysRunner creates a secure enclave runner and sets it as the agent hardware key as it also implements the keyInt/crypto.Signer interface.

}

k, err := tpm.New(priData, pubData)
// SetHardwareKeysRunner creates a tpm runner and sets it as the agent hardware key as it also implements the keyInt/cyrpto.Signer interface.
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming question... If this returns a runner, why is it called Set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The runner also implements keyInt & crypto.Signer and gets set as the hardware key, maybe CreateSetHardwareKeysRunner? Or possible different functions for create and set?

ee/secureenclaverunner/secureenclaverunner.go Show resolved Hide resolved
ee/secureenclaverunner/secureenclaverunner.go Show resolved Hide resolved
@@ -0,0 +1,241 @@
package tpmrunner
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little curious about this as well. I understand why we need to move the secure enclave signing. But I'm much less sure what's happening with the TPM

ee/tpmrunner/tpmrunner.go Outdated Show resolved Hide resolved
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.

3 participants