Skip to content
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 TUF type #383

Merged
merged 6 commits into from
Aug 18, 2021
Merged

Add TUF type #383

merged 6 commits into from
Aug 18, 2021

Conversation

asraa
Copy link
Contributor

@asraa asraa commented Jul 26, 2021

Makes #265 up to date. It is functional and tested now!

Some notes:

  • Root is passed in as the public-key. It is verified when a new public key is created (trusted the keys).
  • An artifact is a TUF manifest of any type. Since it includes signatures, you don't need to provide those out of band.
  • You can search by the root.json file, or the manifest hash, or the type/version.
asraa@asraa-glaptop:~/git/rekor$ ./rekor upload --artifact snapshot.json --public-key 1.root.json --type tuf --rekor_server http://localhost:3000
Created entry at index 0, available at: http://localhost:3000/api/v1/log/entries/6ed8fa5e9f0aa31b6cdfd2cc6877692f5afba52edd7ff5774eebfb22228e8847
asraa@asraa-glaptop:~/git/rekor$ ./rekor search --public-key 1.root.json --pki-format tuf --rekor_server http://localhost:3000
Found matching entries (listed by UUID):
6ed8fa5e9f0aa31b6cdfd2cc6877692f5afba52edd7ff5774eebfb22228e8847

@SantiagoTorres @trishankatdatadog @mnm678

pkg/types/tuf/tuf.go Outdated Show resolved Hide resolved
@trishankatdatadog
Copy link
Contributor

Looking forward to hacking on this this week!

@cpanato cpanato modified the milestones: 0.3.0, v0.3.0, v0.4.0 Jul 27, 2021
@asraa asraa changed the title WIP Add TUF Add TUF type Aug 13, 2021
Co-authored-by: Santiago Torres <santiagotorres@purdue.edu>
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Marina Moore <mnm678@gmail.com>
Signed-off-by: Asra Ali <asraa@google.com>
Copy link
Member

@dlorenc dlorenc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code LGTM, but I'll let it stick around for @bobcallaway to have a look.

One nit: could you add some docs here: https://github.com/sigstore/rekor/blob/main/types.md

Signed-off-by: Asra Ali <asraa@google.com>
@asraa
Copy link
Contributor Author

asraa commented Aug 13, 2021

One nit: could you add some docs here: https://github.com/sigstore/rekor/blob/main/types.md

Done!

Copy link
Contributor

@mnm678 mnm678 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @asraa! Sometime in the future it'd be great if we could generate the test data so that it doesn't clog up the repo, but otherwise LGTM

Copy link
Member

@bobcallaway bobcallaway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looking good, a few questions and nits

pkg/types/tuf/v0.0.1/entry.go Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/entry.go Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/entry.go Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/tuf_v0_0_1_schema.json Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/tuf_manifest_v0_0_1_schema.json Outdated Show resolved Hide resolved
pkg/types/tuf/tuf_schema.json Outdated Show resolved Hide resolved
pkg/types/tuf/tuf_test.go Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/tuf_key_v0_0_1_schema.json Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/tuf_key_v0_0_1_schema.json Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/tuf_manifest_v0_0_1_schema.json Outdated Show resolved Hide resolved
asraa added 2 commits August 16, 2021 10:29
Signed-off-by: Asra Ali <asraa@google.com>
Signed-off-by: Asra Ali <asraa@google.com>
@asraa
Copy link
Contributor Author

asraa commented Aug 16, 2021

Comments addressed! had a minor snafu around decoding strfmt.DateTime -- all good now

@dlorenc
Copy link
Member

dlorenc commented Aug 16, 2021

Nice! I'll let @bobcallaway take another pass.

Copy link
Contributor

@trishankatdatadog trishankatdatadog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial comments. Great job, Asra!

pkg/generated/models/tuf_root_v001_schema.go Outdated Show resolved Hide resolved
pkg/generated/models/tuf_snapshot_v001_schema.go Outdated Show resolved Hide resolved
"threshold": 3
}
},
"spec_version": "1.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this should fail, no? Don't we expect the spec version to be 1.0.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things: just fixed the TODO that actually grabs the spec version.
Second: go-tuf doesn't actually do major.minor.patch.... https://github.com/theupdateframework/go-tuf/blob/aee6270feb5596036edde4b6d7564fa17db811cb/client/testdata/go-tuf/consistent-snapshot-true/0/repository/root.json#L84

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To close this out I made this a general string since go-tuf doesn't write in that format anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To close this out I made this a general string since go-tuf doesn't write in that format anyway.

"version": 1
}
},
"spec_version": "1.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same: should not work bcos should be 1.0.0, no?

pkg/types/tuf/tuf_schema.json Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/tuf_v0_0_1_schema.json Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/tuf_v0_0_1_schema.json Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/tuf_v0_0_1_schema.json Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/tuf_v0_0_1_schema.json Outdated Show resolved Hide resolved
IntegratedTime: 2021-08-13T19:17:33Z
UUID: 6ed8fa5e9f0aa31b6cdfd2cc6877692f5afba52edd7ff5774eebfb22228e8847
Body: {
"TufObj": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, no version property here, is that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure why this is, I think on get it doesn't write the version, but when I unmarshal the actual content of the stored entry I can view it.

asraa@asraa-glaptop:~/git/rekor$ curl -fs0  http://localhost:3000/api/v1/log/entries/68163ebd7d7ba41ece736e2910915944a85985c61892f947841729476f81b951 > logEntry.json
asraa@asraa-glaptop:~/git/rekor$ jq '."68163ebd7d7ba41ece736e2910915944a85985c61892f947841729476f81b951".body' logEntry.json | tr -d \" | base64 -d > body.json
asraa@asraa-glaptop:~/git/rekor$ cat body.json | jq
{
  "apiVersion": "0.0.1",
  "spec": {
    "metadata": {
      "content": "..."
    },
    "root": {
      "content": "..."
    },
    "spec_version": "1.0"
  },
  "kind": "tuf"
}

result = append(result, strings.ToLower(hex.EncodeToString(rootHash[:])))
}

// TODO: Index individual key IDs?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, I was looking for this :)

Yes, I think it would be super useful to be able to query Rekor for TUF metadata based on keyids. Could we pretty please add this? Happy to help with this effort also.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!! Let's do this in a follow up. Should be pretty easy to do by adding a method for KeyIDs in the PublicKey type for TUF

pkg/types/tuf/v0.0.1/entry.go Show resolved Hide resolved
pkg/types/tuf/v0.0.1/entry.go Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/entry.go Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/tuf_v0_0_1_schema.json Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/tuf_manifest_v0_0_1_schema.json Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/tuf_manifest_v0_0_1_schema.json Outdated Show resolved Hide resolved
pkg/types/tuf/v0.0.1/tuf_manifest_v0_0_1_schema.json Outdated Show resolved Hide resolved
asraa added 2 commits August 17, 2021 13:52
Signed-off-by: Asra Ali <asraa@google.com>
Signed-off-by: Asra Ali <asraa@google.com>
@asraa
Copy link
Contributor Author

asraa commented Aug 18, 2021

OK TUF metadata files are now stored as JSON. Unmarshalling the content is just the whole JSON of the metadata file rather than the inline content + the fields we cared about (type, expires, etc)

asraa@asraa-glaptop:~/git/rekor$ curl -fs0  http://localhost:3000/api/v1/log/entries/68163ebd7d7ba41ece736e2910915944a85985c61892f947841729476f81b951 > logEntry.json
asraa@asraa-glaptop:~/git/rekor$ jq '."68163ebd7d7ba41ece736e2910915944a85985c61892f947841729476f81b951".body' logEntry.json | tr -d \" | base64 -d > body.json
asraa@asraa-glaptop:~/git/rekor$ cat body.json | jq
{
  "apiVersion": "0.0.1",
  "spec": {
    "metadata": {
      "content": "..."
    },
    "root": {
      "content": "..."
    },
    "spec_version": "1.0"
  },
  "kind": "tuf"
}
asraa@asraa-glaptop:~/git/rekor$ 
asraa@asraa-glaptop:~/git/rekor$ jq '."68163ebd7d7ba41ece736e2910915944a85985c61892f947841729476f81b951".body' logEntry.json | tr -d \" | base64 -d | jq '.spec.metadata.content' | tr -d \" | base64 -d  | jq
{
  "signatures": [
    {
      "keyid": "2f64fb5eac0cf94dd39bb45308b98920055e9a0d8e012a7220787834c60aef97",
      "sig": "3045022100a7aa1299c325e9d42442ab3d2d25332692d598d5128bc44849fe7108738104ba02201fd3551848bbe94d5c74b9c305920c2d885746134241f54af705380ca4326789"
    },
    {
      "keyid": "bdde902f5ec668179ff5ca0dabf7657109287d690bf97e230c21d65f99155c62",
      "sig": "304502202d3eff55465a12fb9f35ce189872f1d5487428e2b3dab32a57cdc02bf652ebc5022100a735d4399ccd6f78dfa3b708b9fd4ce8148d3e9cb9e6bdb3b4a9f997d3e6f88b"
    },
    {
      "keyid": "eaf22372f417dd618a46f6c627dbc276e9fd30a004fc94f9be946e73f8bd090b",
      "sig": "3046022100a0eefb45472bef9803dfdd16e657603cf2c96561c587057f7ad92dc7851dcfcc02210095a78985adb2a5a1c239ea43019eaed8e4cffe58a224a32f31ffb9c45bd45928"
    },
    {
      "keyid": "f40f32044071a9365505da3d1e3be6561f6f22d0e60cf51df783999f6c3429cb",
      "sig": "304502201cb475203a2726ba21db3cceeff39739f4e1c4b05a8af5e4d1155b60b88a107702210085d841e5420cf403ef65cd94ca92cb75c90b558ebf82de9b93370d7ea0612b56"
    },
    {
      "keyid": "f505595165a177a41750a8e864ed1719b1edfccd5a426fd2c0ffda33ce7ff209",
      "sig": "3044022044b6fa3e918110508c21999974f0a7716a9dd4a0a68234e7330c889e2e336cab0220271a14fa0ea822ed539746f13546139414ae2e8a961db6732f18c3aba08da892"
    }
  ],
  "signed": {
    "_type": "snapshot",
    "expires": "2021-12-18T13:28:12.99008-06:00",
    "meta": {
      "root.json": {
        "hashes": {
          "sha512": "87d41965ac08a2e03a33aa2db1dbbf5a7d6616e49f0ca3b20afe1c46ae78e52e841e21cca347f7b77ec929b6a3687d86d320ee04ba5f75a1880974310958b9c2"
        },
        "length": 5096,
        "version": 1
      },
      "targets.json": {
        "hashes": {
          "sha512": "14018a7442402d31ea7090cf9d7f1e0f56b1811884d843f33e1754b4d50521a83cf3425b93b49ad8a7eaedf5c993cec053e558888d1a97ec94d539abd97022a3"
        },
        "length": 2235,
        "version": 1
      }
    },
    "spec_version": "1.0",
    "version": 1
  }
}

If it's okay I'd like to address the size limits #414 in a separate PR. It's a little complicated and I want to make it general to each type (so that there are configurable limits on the bytes per type if you send content with a file or URL)

@dlorenc
Copy link
Member

dlorenc commented Aug 18, 2021

If it's okay I'd like to address the size limits #414 in a separate PR. It's a little complicated and I want to make it general to each type (so that there are configurable limits on the bytes per type if you send content with a file or URL)

SGTM

Copy link
Contributor

@trishankatdatadog trishankatdatadog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy merging this PR now, and think we can address any improvements/changes in future PRs. Great work, Asra! 💯 💯

@dlorenc
Copy link
Member

dlorenc commented Aug 18, 2021

Here we go!

@dlorenc dlorenc merged commit 4fcdcaa into sigstore:main Aug 18, 2021
@cpanato cpanato modified the milestones: v0.4.0, v1.0.0 Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants