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
Keep but deprecate registry v2 schema1 logic and revert to libtrust-key-based engine ID #39365
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f23a51a
Revert "Remove Schema1 integration test suite"
0811297
use gotest.tools assertions in docker_cli_push_test.go
f695e98
Revert "Remove the rest of v1 manifest support"
53dad9f
Remove v1 manifest code
f923321
Add test for keeping same daemon ID on upgrade
d35f8f4
Add deprecation message for schema1
3f1cdd5
validate: temporarily disable deprecate-integration-cli as part of a …
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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
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,57 @@ | ||
package daemon // import "github.com/docker/docker/daemon" | ||
|
||
import ( | ||
"encoding/json" | ||
"encoding/pem" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/docker/docker/pkg/ioutils" | ||
"github.com/docker/docker/pkg/system" | ||
"github.com/docker/libtrust" | ||
) | ||
|
||
// LoadOrCreateTrustKey attempts to load the libtrust key at the given path, | ||
// otherwise generates a new one | ||
// TODO: this should use more of libtrust.LoadOrCreateTrustKey which may need | ||
// a refactor or this function to be moved into libtrust | ||
func loadOrCreateTrustKey(trustKeyPath string) (libtrust.PrivateKey, error) { | ||
err := system.MkdirAll(filepath.Dir(trustKeyPath), 0755, "") | ||
if err != nil { | ||
return nil, err | ||
} | ||
trustKey, err := libtrust.LoadKeyFile(trustKeyPath) | ||
if err == libtrust.ErrKeyFileDoesNotExist { | ||
trustKey, err = libtrust.GenerateECP256PrivateKey() | ||
if err != nil { | ||
return nil, fmt.Errorf("Error generating key: %s", err) | ||
} | ||
encodedKey, err := serializePrivateKey(trustKey, filepath.Ext(trustKeyPath)) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error serializing key: %s", err) | ||
} | ||
if err := ioutils.AtomicWriteFile(trustKeyPath, encodedKey, os.FileMode(0600)); err != nil { | ||
return nil, fmt.Errorf("Error saving key file: %s", err) | ||
} | ||
} else if err != nil { | ||
return nil, fmt.Errorf("Error loading key file %s: %s", trustKeyPath, err) | ||
} | ||
return trustKey, nil | ||
} | ||
|
||
func serializePrivateKey(key libtrust.PrivateKey, ext string) (encoded []byte, err error) { | ||
if ext == ".json" || ext == ".jwk" { | ||
encoded, err = json.Marshal(key) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to encode private key JWK: %s", err) | ||
} | ||
} else { | ||
pemBlock, err := key.PEMBlock() | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to encode private key PEM: %s", err) | ||
} | ||
encoded = pem.EncodeToMemory(pemBlock) | ||
} | ||
return | ||
} |
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 daemon // import "github.com/docker/docker/daemon" | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"gotest.tools/assert" | ||
is "gotest.tools/assert/cmp" | ||
"gotest.tools/fs" | ||
) | ||
|
||
// LoadOrCreateTrustKey | ||
func TestLoadOrCreateTrustKeyInvalidKeyFile(t *testing.T) { | ||
tmpKeyFolderPath, err := ioutil.TempDir("", "api-trustkey-test") | ||
assert.NilError(t, err) | ||
defer os.RemoveAll(tmpKeyFolderPath) | ||
|
||
tmpKeyFile, err := ioutil.TempFile(tmpKeyFolderPath, "keyfile") | ||
assert.NilError(t, err) | ||
|
||
_, err = loadOrCreateTrustKey(tmpKeyFile.Name()) | ||
assert.Check(t, is.ErrorContains(err, "Error loading key file")) | ||
} | ||
|
||
func TestLoadOrCreateTrustKeyCreateKeyWhenFileDoesNotExist(t *testing.T) { | ||
tmpKeyFolderPath := fs.NewDir(t, "api-trustkey-test") | ||
defer tmpKeyFolderPath.Remove() | ||
|
||
// Without the need to create the folder hierarchy | ||
tmpKeyFile := tmpKeyFolderPath.Join("keyfile") | ||
|
||
key, err := loadOrCreateTrustKey(tmpKeyFile) | ||
assert.NilError(t, err) | ||
assert.Check(t, key != nil) | ||
|
||
_, err = os.Stat(tmpKeyFile) | ||
assert.NilError(t, err, "key file doesn't exist") | ||
} | ||
|
||
func TestLoadOrCreateTrustKeyCreateKeyWhenDirectoryDoesNotExist(t *testing.T) { | ||
tmpKeyFolderPath := fs.NewDir(t, "api-trustkey-test") | ||
defer tmpKeyFolderPath.Remove() | ||
tmpKeyFile := tmpKeyFolderPath.Join("folder/hierarchy/keyfile") | ||
|
||
key, err := loadOrCreateTrustKey(tmpKeyFile) | ||
assert.NilError(t, err) | ||
assert.Check(t, key != nil) | ||
|
||
_, err = os.Stat(tmpKeyFile) | ||
assert.NilError(t, err, "key file doesn't exist") | ||
} | ||
|
||
func TestLoadOrCreateTrustKeyCreateKeyNoPath(t *testing.T) { | ||
defer os.Remove("keyfile") | ||
key, err := loadOrCreateTrustKey("keyfile") | ||
assert.NilError(t, err) | ||
assert.Check(t, key != nil) | ||
|
||
_, err = os.Stat("keyfile") | ||
assert.NilError(t, err, "key file doesn't exist") | ||
} | ||
|
||
func TestLoadOrCreateTrustKeyLoadValidKey(t *testing.T) { | ||
tmpKeyFile := filepath.Join("testdata", "keyfile") | ||
key, err := loadOrCreateTrustKey(tmpKeyFile) | ||
assert.NilError(t, err) | ||
expected := "AWX2:I27X:WQFX:IOMK:CNAK:O7PW:VYNB:ZLKC:CVAE:YJP2:SI4A:XXAY" | ||
assert.Check(t, is.Contains(key.String(), expected)) | ||
} |
This file was deleted.
Oops, something went wrong.
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
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.
FWIW; had a chat with @dmcgowan, and there's a desire to get rid of this dependency; not sure if it's worth doing so as part of this PR (if we plan to remove it in the next release); his suggestion was to copy the parts we use into this repository (somewhere in
pkg
orinternal
perhaps?), so that we can remove the dependencyThere 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.
@thaJeztah Sure I can do that in a followup, don't want to add more changes to this PR which is already big.