-
Notifications
You must be signed in to change notification settings - Fork 16
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
using tpm to store node identity seed #1790
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1b194f9
vm.sh update to use tpm
muhamadazmy 6b18e70
fix path
muhamadazmy 09a9614
Abstract access to node idenity key
muhamadazmy 78e0546
tpm utils
muhamadazmy 1af3fd6
wip: policy create
muhamadazmy 32a72bc
Build all utils for tpm mgmt
muhamadazmy 7f09b4f
Build tpm store
muhamadazmy 6114d64
migrate from file to tpm store if available
muhamadazmy a2539c8
fix typo
muhamadazmy 8f967fe
add missing file
muhamadazmy d1b088c
fix ci
muhamadazmy 0defcf2
Make sure identityd resstart when bins are updated
muhamadazmy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,71 @@ | ||
package identity | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/rs/zerolog/log" | ||
"github.com/threefoldtech/zos/pkg/identity/store" | ||
) | ||
|
||
const ( | ||
seedName = "seed.txt" | ||
) | ||
|
||
// NewStore tries to build the best key store available | ||
// for this ndoe. | ||
// On a machine with no tpm support, that would be a file | ||
// store. | ||
// If TPM is supported, TPM will be used. | ||
// There is a special case if tpm is supported, but a file seed | ||
// exits, this file key will be migrated to the TPM store then | ||
// deleted (only if delete is set to true) | ||
func NewStore(root string, delete bool) (store.Store, error) { | ||
file := store.NewFileStore(filepath.Join(root, seedName)) | ||
if !store.IsTPMEnabled() { | ||
return file, nil | ||
} | ||
|
||
// tpm is supported, but do we have a key | ||
tpm := store.NewTPM() | ||
exists, err := file.Exists() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to check for seed file: %s", err) | ||
} | ||
|
||
if !exists { | ||
return tpm, nil | ||
} | ||
|
||
if ok, err := tpm.Exists(); err == nil && ok { | ||
// so there is a key on disk, but tpm already has a stored key | ||
// then we still just return no need for migration to avoid | ||
// overriding the key in tpm | ||
return tpm, nil | ||
} | ||
|
||
// if we failed to get the key from store | ||
// may be better generate a new one? | ||
// todo: need discussion | ||
|
||
key, err := file.Get() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to load key from file: %w", err) | ||
} | ||
|
||
// migration of key | ||
if err := tpm.Set(key); err != nil { | ||
// we failed to do migration but we have a valid key. | ||
// we shouldn't then fail instead use the file store | ||
log.Error().Err(err).Msg("failed to migrate key to tpm store") | ||
return file, nil | ||
} | ||
|
||
if delete { | ||
if err := file.Annihilate(); err != nil { | ||
log.Error().Err(err).Msg("failed to clear up key file") | ||
} | ||
} | ||
|
||
return tpm, nil | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about old data/signatures in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually to avoid overriding the key inside tpm if someone decided to put another key on disk. The idea is that key migration will happen one time (and one time only) and then delete the key file. If suddenly a key appeared then it means something is fishy and the new key file is just ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, got it. I think we also assume there's no other key at our chosen address, right? (not managed by us).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's actually hard to grantee. Maybe we should add a validation (and clearing step) if the key is invalid.