Skip to content

Commit

Permalink
Feature: track TUF key ownership
Browse files Browse the repository at this point in the history
Signed-off-by: Volodymyr Khoroz <[email protected]>
  • Loading branch information
vkhoroz committed Aug 11, 2023
1 parent bd229f1 commit d0e3d2a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions client/foundries_tuf_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ type RootChangeReason struct {
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
}

type RootKeyOwner struct {
PolisId string `json:"polis-id"`
CreatedAt time.Time `json:"created-at"`
}

type AtsRootMeta struct {
tuf.SignedCommon
Consistent bool `json:"consistent_snapshot"`
Keys map[string]AtsKey `json:"keys"`
Roles map[tuf.RoleName]*tuf.RootRole `json:"roles"`
Reason *RootChangeReason `json:"x-changelog,omitempty"`
KeyOwners map[string]RootKeyOwner `json:"x-key-owners,omitempty"`
}

type AtsTufRoot struct {
Expand Down
13 changes: 13 additions & 0 deletions subcommands/keys/tuf_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"io"
"os"
"strings"
"time"

canonical "github.com/docker/go/canonical/json"
"github.com/spf13/viper"
tuf "github.com/theupdateframework/notary/tuf/data"

"github.com/foundriesio/fioctl/client"
Expand Down Expand Up @@ -321,6 +323,17 @@ func addOfflineTufKey(
creds[base+".sec"] = key.atsPrivBytes
root.Signed.Keys[key.signer.Id] = key.atsPub
root.Signed.Roles[role].KeyIDs = append(oldKids, key.signer.Id)

factory := viper.GetString("factory")
user, err := api.UserAccessDetails(factory, "self")
subcommands.DieNotNil(err)
if root.Signed.KeyOwners == nil {
root.Signed.KeyOwners = make(map[string]client.RootKeyOwner)
}
root.Signed.KeyOwners[key.signer.Id] = client.RootKeyOwner{
PolisId: user.PolisId,
CreatedAt: time.Unix(time.Now().Unix(), 0).UTC(), // Strip millis
}
}

func removeUnusedTufKeys(root *client.AtsTufRoot) {
Expand Down

0 comments on commit d0e3d2a

Please sign in to comment.