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: cosign verifier #10

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft

Conversation

junczhu
Copy link

@junczhu junczhu commented Feb 13, 2025

What this PR does / why we need it:

Added design document

Implement cosign verifier

  • verify cosign signature including both with key and keyless verification
  • truststore mapping, including keys, certificates, and certchains for verification
  • using VerfierOptions, is for verifier creatation and VerifyOption and VerifyContext for verification

Which issue(s) this PR resolves

Resolves #39

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test?
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

Signed-off-by: Juncheng Zhu <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Feb 13, 2025

Codecov Report

Attention: Patch coverage is 38.24701% with 155 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cosign/verifier.go 29.03% 145 Missing and 9 partials ⚠️
...osign/verifycontextoptions/verifycontextoptions.go 90.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (38.24%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project status has failed because the head coverage (48.53%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Files with missing lines Coverage Δ
cosign/truststore/truststore.go 100.00% <100.00%> (ø)
...osign/verifycontextoptions/verifycontextoptions.go 90.00% <90.00%> (ø)
cosign/verifier.go 29.03% <29.03%> (ø)

@junczhu junczhu force-pushed the cosign-verifier branch 5 times, most recently from 05d3557 to 59240a2 Compare February 14, 2025 07:18
Signed-off-by: Juncheng Zhu <[email protected]>
Signed-off-by: Juncheng Zhu <[email protected]>
Signed-off-by: Juncheng Zhu <[email protected]>
@junczhu junczhu force-pushed the cosign-verifier branch 2 times, most recently from 513e55b to db55766 Compare February 17, 2025 04:35
Signed-off-by: Juncheng Zhu <[email protected]>
certChains map[string][]*x509.Certificate
}

func NewWithOpts(opts *VerifierOptions) TrustStore {
Copy link
Contributor

Choose a reason for hiding this comment

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

NewTrustStore?

Copy link
Contributor

Choose a reason for hiding this comment

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

does opts get used?

Copy link
Author

Choose a reason for hiding this comment

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

A1: Shall we rename or create a new package for this structure?
A2: I would read input from opts

Copy link
Author

Choose a reason for hiding this comment

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

use NewTrustStore

Copy link
Author

Choose a reason for hiding this comment

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

Updated

}

func (t *TrustStoreImp) GetVerifyOpts(subjectRef string) (*VOptions, error) {
return t.optsMap[subjectRef], nil
Copy link
Contributor

Choose a reason for hiding this comment

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

should we return err if it's not existing.

Copy link
Author

Choose a reason for hiding this comment

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

skip

@junczhu junczhu force-pushed the cosign-verifier branch 2 times, most recently from 49149f1 to 9c25283 Compare February 18, 2025 06:34
@junczhu
Copy link
Author

junczhu commented Feb 18, 2025

Gonna update the remote branch to apply those newly merged changes.

@junczhu junczhu marked this pull request as ready for review February 18, 2025 07:29
Copy link
Contributor

@binbin-li binbin-li left a comment

Choose a reason for hiding this comment

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

could you briefly explain how to support distinguish cert/keys for different repos/registries.

}

type verifyContextOptions struct {
optsMap map[string]*VerifyContext
Copy link
Contributor

Choose a reason for hiding this comment

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

the map seems mapping a digested reference to a context, which means users need to configure the context for each artifact that will be validated. It would be a huge work for users. Does all options in this VerifyContext vary for each artifact?

Copy link
Author

Choose a reason for hiding this comment

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

Would it be better to have a mapping function

return nil, v1.Hash{}, fmt.Errorf("unable to locate reference with artifactType %s", artifactTypeCosign)
}

signatureDesc := signatureDescriptors[numResults-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

seems it's an experimental feature for cosign, probably we still need to support the main user scenario. cc: @shizhMSFT

GetVerifyOpts(subjectRef string) (*VerifyContext, error)
}

type verifyContextOptions struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should either expose it or have a constructor to create it with values.

)

// VerifyContext holds the options for verifying a context.
type VerifyContext struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

we could remove some options if they are not required in this PR

Copy link
Author

Choose a reason for hiding this comment

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

Those ones are filtered and indeed used in this PR.
I would keep an eye on the changes based on the change of PR

Copy link

@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.

I would request a markdown of the design. Otherwise, it is too difficult to understand. Please provide an outline first, and then fill in the details.

cosign/go.mod Outdated

go 1.23.4

toolchain go1.23.6
Copy link
Author

Choose a reason for hiding this comment

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

need to remove

Copy link
Author

Choose a reason for hiding this comment

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

resolved

IgnoreSCT bool
}

type TrustStoreImp struct {
Copy link
Author

Choose a reason for hiding this comment

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

rename Imp

Copy link
Author

Choose a reason for hiding this comment

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

resolved

certChains map[string][]*x509.Certificate
}

func NewWithOpts(opts *VerifierOptions) TrustStore {
Copy link
Author

Choose a reason for hiding this comment

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

use NewTrustStore

}

func (t *TrustStoreImp) GetVerifyOpts(subjectRef string) (*VOptions, error) {
return t.optsMap[subjectRef], nil
Copy link
Author

Choose a reason for hiding this comment

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

skip

}

type verifyContextOptions struct {
optsMap map[string]*VerifyContext
Copy link
Author

Choose a reason for hiding this comment

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

Would it be better to have a mapping function

Verifier: v,
}
// TODO: update verify result
_, err = cosign.VerifyImageSignature(ctx, sig, signatureDescHash, checkOpts)
Copy link
Author

Choose a reason for hiding this comment

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

You are right, We should also consider cases that fail to verify but no error.

Signed-off-by: Juncheng Zhu <[email protected]>
Signed-off-by: Juncheng Zhu <[email protected]>
@junczhu junczhu marked this pull request as draft February 21, 2025 06:02
Signed-off-by: Juncheng Zhu <[email protected]>
Signed-off-by: Juncheng Zhu <[email protected]>
Signed-off-by: Juncheng Zhu <[email protected]>
Signed-off-by: Juncheng Zhu <[email protected]>
Signed-off-by: Juncheng Zhu <[email protected]>
@junczhu junczhu marked this pull request as ready for review February 24, 2025 00:59
@junczhu junczhu marked this pull request as draft February 26, 2025 06:45
@junczhu
Copy link
Author

junczhu commented Feb 26, 2025

Convert to draft as a PoC

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.

Implement cosign verifier
4 participants