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

feat: add implementation for notation inspect #528

Merged
merged 1 commit into from
Feb 16, 2023

Conversation

byronchien
Copy link
Contributor

@byronchien byronchien commented Feb 2, 2023

Adds support for notation inspect (spec here)

Example output:

chienb@a07817b52895 notation % ./bin/notation inspect $IMAGE
Resolved artifact tag `v1` to digest `sha256:5a07385af4e6b6af81b0ebfd435aedccdfa3507f0609c658209e1aba57159b2b` before inspect.
Warning: The resolved digest may not point to the same signed artifact, since tags are mutable.
Inspecting all signatures for signed artifact
localhost:5000/net-monitor@sha256:5a07385af4e6b6af81b0ebfd435aedccdfa3507f0609c658209e1aba57159b2b
└── application/vnd.cncf.notary.signature
    └── sha256:34e5843a1a8b1607d2ba7da9b61c6a5b3953f5680751c160fb944df87b01b2b2
        ├── signature algorithm : RSASSA-PSS-SHA-256
        ├── signed attributes
        │   ├── expiry : 0001-01-01 00:00:00 +0000 UTC
        │   ├── signingScheme : notary.x509
        │   └── signingTime : 2023-01-27 17:02:22 -0800 PST
        ├── user defined attributes
        │   └── io.wabbit-networks.buildId : 123
        ├── unsigned attributes
        │   └── signingAgent : Notation/1.0.0
        ├── certificates
        │   └── SHA1 fingerprint e1ef7b0f984d1f8222d6bf297e1ad10047997b54
        │       ├── issued to : CN=byron.test,O=Notary,L=Seattle,ST=WA,C=US
        │       ├── issued by : CN=byron.test,O=Notary,L=Seattle,ST=WA,C=US
        │       └── expiry : 2023-01-29 01:02:13 +0000 UTC
        └── signed artifact
            ├── media type : application/vnd.docker.distribution.manifest.v2+json
            ├── digest : sha256:5a07385af4e6b6af81b0ebfd435aedccdfa3507f0609c658209e1aba57159b2b
            └── size : 942
chienb@a07817b52895 notation % ./bin/notation inspect $IMAGE --output json
{
    "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
    "Signatures": [
        {
            "digest": "sha256:34e5843a1a8b1607d2ba7da9b61c6a5b3953f5680751c160fb944df87b01b2b2",
            "signatureAlgorithm": "RSASSA-PSS-SHA-256",
            "signedAttributes": {
                "expiry": "0001-01-01 00:00:00 +0000 UTC",
                "signingScheme": "notary.x509",
                "signingTime": "2023-01-27 17:02:22 -0800 PST"
            },
            "userDefinedAttributes": {
                "io.wabbit-networks.buildId": "123"
            },
            "unsignedAttributes": {
                "signingAgent": "Notation/1.0.0"
            },
            "certificates": [
                {
                    "SHA1Fingerprint": "e1ef7b0f984d1f8222d6bf297e1ad10047997b54",
                    "issuedTo": "CN=byron.test,O=Notary,L=Seattle,ST=WA,C=US",
                    "issuedBy": "CN=byron.test,O=Notary,L=Seattle,ST=WA,C=US",
                    "expiry": "2023-01-29 01:02:13 +0000 UTC"
                }
            ],
            "signedArtifact": {
                "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
                "digest": "sha256:5a07385af4e6b6af81b0ebfd435aedccdfa3507f0609c658209e1aba57159b2b",
                "size": 942
            }
        }
    ]
}

NOTE: this PR is on top of the changes for user-metadata verifictation and json output from there PRs:

suggested order for review: notation-go #261 => notation-core-go #111 => notation #527 =>notation #528 (this one)

Signed-off-by: Byron Chien chienb@amazon.com

@byronchien
Copy link
Contributor Author

order to review:
#507
#527
#528

@byronchien
Copy link
Contributor Author

@shizhMSFT shizhMSFT changed the title Adds implementation for notation inspect feat: add implementation for notation inspect Feb 8, 2023
@byronchien byronchien force-pushed the inspect-impl branch 3 times, most recently from 555dc3f to 5f4afdf Compare February 8, 2023 19:13
@codecov-commenter
Copy link

codecov-commenter commented Feb 9, 2023

Codecov Report

Merging #528 (00896e4) into main (54b42cb) will decrease coverage by 1.98%.
The diff coverage is 21.16%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main     #528      +/-   ##
==========================================
- Coverage   36.34%   34.36%   -1.98%     
==========================================
  Files          30       32       +2     
  Lines        1607     1848     +241     
==========================================
+ Hits          584      635      +51     
- Misses       1002     1192     +190     
  Partials       21       21              
Impacted Files Coverage Δ
cmd/notation/main.go 0.00% <0.00%> (ø)
internal/envelope/envelope.go 25.92% <0.00%> (-74.08%) ⬇️
cmd/notation/inspect.go 14.21% <14.21%> (ø)
internal/tree/tree.go 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@byronchien byronchien force-pushed the inspect-impl branch 3 times, most recently from 15bb78b to e675c75 Compare February 10, 2023 01:09
Comment on lines 20 to 25
const (
treeItemPrefix = "├──"
treeItemPrefixLast = "└──"
subTreePrefix = "│ "
subTreePrefixLast = " "
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use some external library to create this tree structure? If not, can we create one?

Copy link
Contributor

Choose a reason for hiding this comment

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

opened issue to track this #545

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on having a new package for tree printing.

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be done in this PR instead of refactoring in a later PR for code quality considerations.

Otherwise, the notation inspect code is not maintainable, especially for new contributors.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't consider printing tree while loading signatures pages, you may consider https://github.com/need-being/go-tree as it is MIT.

Copy link
Contributor

@priteshbandi priteshbandi Feb 10, 2023

Choose a reason for hiding this comment

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

IMO adding not a well known library such as need-being/go-tree is risky and since the amount of code we are taking about is less than 100 lines I would prefer that we we write our own.

@@ -74,7 +74,7 @@ var _ = Describe("notation quickstart E2E test", Ordered, func() {

It("Verify the container image with jws format", func() {
notation.Exec("verify", artifact.ReferenceWithDigest()).
MatchContent(fmt.Sprintf("Successfully verified signature for %s\n", artifact.ReferenceWithDigest()))
MatchKeyWords(fmt.Sprintf("Successfully verified signature for %s\n", artifact.ReferenceWithDigest()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we changing this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Same question here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when running the E2E tests, sometimes the tests with user-metadata would run before this one, causing the output to mismatch since the signature with user-metadata would be verified first and cause the output to not match exactly. Changing it so that the test just checks that the verification passes successfully regardless of whether tags are present or not.

priteshbandi
priteshbandi previously approved these changes Feb 10, 2023
Copy link
Contributor

@priteshbandi priteshbandi left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -74,7 +74,7 @@ var _ = Describe("notation quickstart E2E test", Ordered, func() {

It("Verify the container image with jws format", func() {
notation.Exec("verify", artifact.ReferenceWithDigest()).
MatchContent(fmt.Sprintf("Successfully verified signature for %s\n", artifact.ReferenceWithDigest()))
MatchKeyWords(fmt.Sprintf("Successfully verified signature for %s\n", artifact.ReferenceWithDigest()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question here.

Comment on lines 20 to 25
const (
treeItemPrefix = "├──"
treeItemPrefixLast = "└──"
subTreePrefix = "│ "
subTreePrefixLast = " "
)
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on having a new package for tree printing.

Comment on lines 20 to 25
const (
treeItemPrefix = "├──"
treeItemPrefixLast = "└──"
subTreePrefix = "│ "
subTreePrefixLast = " "
)
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be done in this PR instead of refactoring in a later PR for code quality considerations.

Otherwise, the notation inspect code is not maintainable, especially for new contributors.

Comment on lines 20 to 25
const (
treeItemPrefix = "├──"
treeItemPrefixLast = "└──"
subTreePrefix = "│ "
subTreePrefixLast = " "
)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't consider printing tree while loading signatures pages, you may consider https://github.com/need-being/go-tree as it is MIT.

Comment on lines 23 to 25
const (
NotarySignatureMediaType = "application/vnd.cncf.notary.signature"
)
Copy link
Contributor

@shizhMSFT shizhMSFT Feb 10, 2023

Choose a reason for hiding this comment

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

You can directly reference registry.ArtifactTypeNotation from notation-go.

@priteshbandi priteshbandi dismissed their stale review February 10, 2023 18:08

Needs re-review

go.mod Outdated
@@ -4,6 +4,7 @@ go 1.20

require (
github.com/docker/docker-credential-helpers v0.7.0
github.com/need-being/go-tree v0.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.

Adding not a well known library such as need-being/go-tree is risky and since the amount of code we are taking about is less than 100 lines I would prefer that we we write our own.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since it is MIT, we can borrow their code.

go.mod Outdated
@@ -4,6 +4,7 @@ go 1.20

require (
github.com/docker/docker-credential-helpers v0.7.0
github.com/need-being/go-tree v0.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.

Since it is MIT, we can borrow their code.

shizhMSFT
shizhMSFT previously approved these changes Feb 15, 2023
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM with suggestions

priteshbandi
priteshbandi previously approved these changes Feb 15, 2023
Copy link
Contributor

@priteshbandi priteshbandi left a comment

Choose a reason for hiding this comment

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

LGTM

@byronchien byronchien dismissed stale reviews from priteshbandi and shizhMSFT via 5025773 February 15, 2023 00:57
priteshbandi
priteshbandi previously approved these changes Feb 15, 2023
Copy link
Contributor

@patrickzheng200 patrickzheng200 left a comment

Choose a reason for hiding this comment

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

LGTM with all comments addressed.

shizhMSFT
shizhMSFT previously approved these changes Feb 15, 2023
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM

priteshbandi
priteshbandi previously approved these changes Feb 15, 2023
Copy link
Contributor

@priteshbandi priteshbandi left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Byron Chien <byronc@ucla.edu>
shizhMSFT
shizhMSFT previously approved these changes Feb 16, 2023
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@patrickzheng200 patrickzheng200 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@patrickzheng200 patrickzheng200 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@priteshbandi priteshbandi left a comment

Choose a reason for hiding this comment

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

LGTM

@priteshbandi priteshbandi merged commit d62fd58 into notaryproject:main Feb 16, 2023
@yizha1 yizha1 linked an issue Feb 17, 2023 that may be closed by this pull request
duffney pushed a commit to duffney/notation that referenced this pull request Mar 30, 2023
Adds support for `notation inspect` ([spechere](https://github.com/notaryproject/notation/blob/main/specs/commandline/inspect.md))

Example output:
```
chienb@a07817b52895 notation % ./bin/notation inspect $IMAGE
localhost:5000/net-monitor@sha256:5a07385af4e6b6af81b0ebfd435aedccdfa3507f0609c658209e1aba57159b2b
└── application/vnd.cncf.notary.signature
    └── sha256:34e5843a1a8b1607d2ba7da9b61c6a5b3953f5680751c160fb944df87b01b2b2
        ├── signature algorithm : RSASSA-PSS-SHA-256
        ├── signed attributes
        │   ├── expiry : 0001-01-01 00:00:00 +0000 UTC
        │   ├── signingScheme : notary.x509
        │   └── signingTime : 2023-01-27 17:02:22 -0800 PST
        ├── user defined attributes
        │   └── io.wabbit-networks.buildId : 123
        ├── unsigned attributes
        │   └── signingAgent : Notation/1.0.0
        ├── certificates
        │   └── SHA1 fingerprint e1ef7b0f984d1f8222d6bf297e1ad10047997b54
        │       ├── issued to : CN=byron.test,O=Notary,L=Seattle,ST=WA,C=US
        │       ├── issued by : CN=byron.test,O=Notary,L=Seattle,ST=WA,C=US
        │       └── expiry : 2023-01-29 01:02:13 +0000 UTC
        └── signed artifact
            ├── media type : application/vnd.docker.distribution.manifest.v2+json
            ├── digest : sha256:5a07385af4e6b6af81b0ebfd435aedccdfa3507f0609c658209e1aba57159b2b
            └── size : 942
```

Signed-off-by: Byron Chien <chienb@amazon.com>
Signed-off-by: Josh Duffney <jduffney@microsoft.com>
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.

Implementing inspect command
6 participants