Skip to content

Commit

Permalink
targets: Use online root meta if not found locally
Browse files Browse the repository at this point in the history
If a user has not taken neither root nor targets keys offline then there
are only two root versions in a given factory.
In such the case, the bundle will have no any root
metadata. Therefore, to make the `show` command work properly the
command needs to fetch the latest (i.e. version 2) root meta from the
backend.

Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
mike-sul committed Apr 16, 2024
1 parent 3ce1763 commit dde69aa
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion subcommands/targets/offline-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,10 @@ func getLatestRoot(bundleTufPath string) (*client.AtsTufRoot, error) {
if !errors.Is(readErr, os.ErrNotExist) {
return nil, readErr
}

if latestVersionBytes == nil {
// None of the N.root.json where N starts from 3 was found in the bundle
return nil, os.ErrNotExist
}
rootMeta := client.AtsTufRoot{}
if err := json.Unmarshal(latestVersionBytes, &rootMeta); err != nil {
return nil, err
Expand Down Expand Up @@ -562,6 +565,12 @@ func doShowBundle(cmd *cobra.Command, args []string) {
}

rootMeta, err := getLatestRoot(tufMetaPath)
if errors.Is(err, os.ErrNotExist) && bundleMeta.ouBundleMeta.Type == "ci" {
// If no any N.root.json is found in the bundle and this is the "ci" bundle,
// then this is the valid case - a user has not taken their TUF targets key offline.
// Therefore, instead of failing the command fetches the root meta from the backend.
rootMeta, err = api.TufRootGet(viper.GetString("factory"))
}
subcommands.DieNotNil(err)
fmt.Println("\tAllowed keys:")
for _, key := range rootMeta.Signed.Roles["targets"].KeyIDs {
Expand Down

0 comments on commit dde69aa

Please sign in to comment.