-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
james/tpm runner handle no tpm (#2066)
- Loading branch information
1 parent
1d64d1c
commit 77daf4c
Showing
5 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
package tpmrunner | ||
|
||
// isTPMNotFoundErr always return false on linux because we don't yet how to | ||
// detect if a TPM is not found on linux. | ||
func isTPMNotFoundErr(err error) bool { | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//go:build !darwin | ||
// +build !darwin | ||
|
||
package tpmrunner | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package tpmrunner | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/google/go-tpm/tpmutil/tbs" | ||
) | ||
|
||
func isTPMNotFoundErr(err error) bool { | ||
return errors.Is(err, tbs.ErrTPMNotFound) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package tpmrunner | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/go-tpm/tpmutil/tbs" | ||
"github.com/kolide/launcher/ee/agent/storage/inmemory" | ||
"github.com/kolide/launcher/ee/tpmrunner/mocks" | ||
"github.com/kolide/launcher/pkg/log/multislogger" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_tpmRunner_windows(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("handles no tpm in exectue", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
tpmSignerCreatorMock := mocks.NewTpmSignerCreator(t) | ||
tpmRunner, err := New(context.TODO(), multislogger.NewNopLogger(), inmemory.NewStore(), withTpmSignerCreator(tpmSignerCreatorMock)) | ||
require.NoError(t, err) | ||
|
||
// we should never try again after getting TPMNotFound err | ||
tpmSignerCreatorMock.On("CreateKey").Return(nil, nil, tbs.ErrTPMNotFound).Once() | ||
|
||
go func() { | ||
// sleep long enough to get through 2 cycles of execute | ||
|
||
// "CreateKey" should only be called once | ||
time.Sleep(3 * time.Second) | ||
tpmRunner.Interrupt(errors.New("test")) | ||
}() | ||
|
||
require.NoError(t, tpmRunner.Execute()) | ||
require.Nil(t, tpmRunner.Public()) | ||
}) | ||
|
||
t.Run("handles no tpm in Public() call", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
tpmSignerCreatorMock := mocks.NewTpmSignerCreator(t) | ||
tpmRunner, err := New(context.TODO(), multislogger.NewNopLogger(), inmemory.NewStore(), withTpmSignerCreator(tpmSignerCreatorMock)) | ||
require.NoError(t, err) | ||
|
||
// we should never try again after getting TPMNotFound err | ||
tpmSignerCreatorMock.On("CreateKey").Return(nil, nil, tbs.ErrTPMNotFound).Once() | ||
|
||
// this is the only time "CreateKey" should be called | ||
require.Nil(t, tpmRunner.Public()) | ||
|
||
go func() { | ||
// sleep long enough to get through 2 cycles of execute | ||
time.Sleep(3 * time.Second) | ||
tpmRunner.Interrupt(errors.New("test")) | ||
}() | ||
|
||
require.NoError(t, tpmRunner.Execute()) | ||
require.Nil(t, tpmRunner.Public()) | ||
}) | ||
|
||
} |