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
Add cosign init
to initialize the SigStore root metadata
#520
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eca4164
verify TUF root
asraa b77f44b
Merge remote-tracking branch 'upstream/main' into verify-tuf-root-once
asraa ce73105
use tuf root for rekor and fulcio data
asraa c3caa52
add local tests and configs
asraa bae2314
Merge remote-tracking branch 'upstream/main' into verify-tuf-root-once
asraa 1787c29
update
asraa 4b3ec76
update gcs bucket to prod
asraa 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,8 @@ | |
*.libfuzzer | ||
*fuzz.a | ||
|
||
# Root metadata | ||
*.sigstore/root/ | ||
|
||
bin* | ||
dist/ |
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 @@ | ||
[ | ||
{ | ||
"keytype": "ecdsa-sha2-nistp256", | ||
"scheme": "ecdsa-sha2-nistp256", | ||
"keyid_hash_algorithms": [ | ||
"sha256", | ||
"sha512" | ||
], | ||
"keyval": { | ||
"public": "04cbc5cab2684160323c25cd06c3307178a6b1d1c9b949328453ae473c5ba7527e35b13f298b41633382241f3fd8526c262d43b45adee5c618fa0642c82b8a9803" | ||
} | ||
}, | ||
{ | ||
"keytype": "ecdsa-sha2-nistp256", | ||
"scheme": "ecdsa-sha2-nistp256", | ||
"keyid_hash_algorithms": [ | ||
"sha256", | ||
"sha512" | ||
], | ||
"keyval": { | ||
"public": "04a71aacd835dc170ba6db3fa33a1a33dee751d4f8b0217b805b9bd3242921ee93672fdcfd840576c5bb0dc0ed815edf394c1ee48c2b5e02485e59bfc512f3adc7" | ||
} | ||
}, | ||
{ | ||
"keytype": "ecdsa-sha2-nistp256", | ||
"scheme": "ecdsa-sha2-nistp256", | ||
"keyid_hash_algorithms": [ | ||
"sha256", | ||
"sha512" | ||
], | ||
"keyval": { | ||
"public": "04117b33dd265715bf23315e368faa499728db8d1f0a377070a1c7b1aba2cc21be6ab1628e42f2cdd7a35479f2dce07b303a8ba646c55569a8d2a504ba7e86e447" | ||
} | ||
}, | ||
{ | ||
"keytype": "ecdsa-sha2-nistp256", | ||
"scheme": "ecdsa-sha2-nistp256", | ||
"keyid_hash_algorithms": [ | ||
"sha256", | ||
"sha512" | ||
], | ||
"keyval": { | ||
"public": "04cc1cd53a61c23e88cc54b488dfae168a257c34fac3e88811c55962b24cffbfecb724447999c54670e365883716302e49da57c79a33cd3e16f81fbc66f0bcdf48" | ||
} | ||
}, | ||
{ | ||
"keytype": "ecdsa-sha2-nistp256", | ||
"scheme": "ecdsa-sha2-nistp256", | ||
"keyid_hash_algorithms": [ | ||
"sha256", | ||
"sha512" | ||
], | ||
"keyval": { | ||
"public": "048a78a44ac01099890d787e5e62afc29c8ccb69a70ec6549a6b04033b0a8acbfb42ab1ab9c713d225cdb52b858886cf46c8e90a7f3b9e6371882f370c259e1c5b" | ||
} | ||
} | ||
] |
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,72 @@ | ||
// | ||
// Copyright 2021 The Sigstore Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cli | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
|
||
"github.com/peterbourgon/ff/v3/ffcli" | ||
ctuf "github.com/sigstore/cosign/pkg/cosign/tuf" | ||
) | ||
|
||
func Init() *ffcli.Command { | ||
var ( | ||
flagset = flag.NewFlagSet("cosign init", flag.ExitOnError) | ||
// mirrorURL = flagset.String("mirror", tuf.TufRemoteStore, "GCS bucket to a SigStore TUF repository.") | ||
// outPath = flagset.String("out", "", "path to write the resulting trusted SigStore TUF repository.") | ||
) | ||
return &ffcli.Command{ | ||
Name: "init", | ||
ShortUsage: "cosign init -mirror <url> -out <file>", | ||
ShortHelp: `Initializes SigStore root to retrieve trusted certificate and key targets for verification.`, | ||
LongHelp: `Initializes SigStore root to retrieve trusted certificate and key targets for verification. | ||
|
||
The following options are used by default: | ||
- Initial root keys are pulled from .sigstore/keys. If it does not exist, uses root keys provided in the release. | ||
- SigStore current TUF repository is pulled from the GCS mirror at . | ||
- Resulting trusted metadata is written to .sigstore/root. | ||
|
||
To provide an out-of-band trusted root.json, copy the file into a directory named .sigstore/root/. | ||
|
||
The resulting updated TUF repository will be written to .sigstore/root/. | ||
|
||
Trusted keys and certificate used in cosign verification (e.g. verifying Fulcio issued certificates | ||
with Fulcio root CA) are pulled form the trusted metadata. | ||
|
||
EXAMPLES | ||
# initialize root with distributed root keys, default mirror, and default out path. | ||
cosign init | ||
|
||
# initialize with an out-of-band root key file. | ||
cosign init | ||
|
||
# initialize with an out-of-band root key file and custom repository mirror. | ||
cosign init-mirror <> | ||
`, | ||
FlagSet: flagset, | ||
Exec: func(ctx context.Context, args []string) error { | ||
// Update the rootKey file if provided. | ||
|
||
// Update the default local store. | ||
|
||
// Update the mirror for remote store. | ||
|
||
// Initialize or update the SigStore TUF repository in .sigstore/root. | ||
return ctuf.Init(context.Background()) | ||
}, | ||
} | ||
} |
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 | ||||
---|---|---|---|---|---|---|
|
@@ -15,6 +15,8 @@ | |||||
package cosign | ||||||
|
||||||
import ( | ||||||
"bytes" | ||||||
"context" | ||||||
"encoding/base64" | ||||||
"encoding/hex" | ||||||
"fmt" | ||||||
|
@@ -29,6 +31,7 @@ import ( | |||||
"github.com/pkg/errors" | ||||||
|
||||||
cremote "github.com/sigstore/cosign/pkg/cosign/remote" | ||||||
"github.com/sigstore/cosign/pkg/cosign/tuf" | ||||||
"github.com/sigstore/rekor/pkg/generated/client" | ||||||
"github.com/sigstore/rekor/pkg/generated/client/entries" | ||||||
"github.com/sigstore/rekor/pkg/generated/client/pubkey" | ||||||
|
@@ -41,6 +44,19 @@ import ( | |||||
// rekor.pub should be updated whenever the Rekor public key is rotated & the bundle annotation should be up-versioned | ||||||
//go:embed rekor.pub | ||||||
var rekorPub string | ||||||
var rekorTargetStr = `rekor.pub` | ||||||
|
||||||
func GetRekorPub() string { | ||||||
ctx := context.Background() // TODO: pass in context? | ||||||
buf := tuf.ByteDestination{Buffer: &bytes.Buffer{}} | ||||||
err := tuf.GetTarget(ctx, rekorTargetStr, &buf) | ||||||
if err != nil { | ||||||
// The user may not have initialized the local root metadata. Log the error and use the embedded root. | ||||||
fmt.Println("using embedded rekor public key. did you run `cosign init`? error retrieving target: ", err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return rekorPub | ||||||
} | ||||||
return buf.String() | ||||||
} | ||||||
|
||||||
// TLogUpload will upload the signature, public key and payload to the transparency log. | ||||||
func TLogUpload(rekorClient *client.Rekor, signature, payload []byte, pemBytes []byte) (*models.LogEntryAnon, error) { | ||||||
|
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.
IMHO we should put this somewhere under
cli/
in order to keep logging andcosign
binary-specific out of packageThere 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.
Ohhh hmmmm you mean keeping
fmt.Println
out? It's used elsewhere in this file as wellThere 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.
hrm yeah