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 cosign verify-manifest command #490

Merged
merged 4 commits into from
Jul 29, 2021

Conversation

joshes
Copy link
Contributor

@joshes joshes commented Jul 27, 2021

Adds support for verifying kubernetes resources (manifests) and addresses #437

It's a naive approach, but wanted to get feedback early on, especially around YAML parsing via regex and JSON support as discussed in the ticket.

Signed-off-by: Joshua Hansen <j4ah4n@gmail.com>
@cpanato cpanato added this to the v1.0.0 milestone Jul 27, 2021
Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>
LongHelp: `Verify all signature of images in a Kubernetes resource manifest by checking claims
against the transparency log.

Shell-like variables in the Dockerfile's FROM lines will be substituted with values from the OS ENV.
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is coming from the verify-dockerfile command description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the help docs to reflect.


func getImagesFromYamlManifest(manifest string) ([]string, error) {
var images []string
re := regexp.MustCompile(`image:\s?(?P<Image>.*)\s?`)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Perhaps it could be more robust to decode the manifest and validate that the extensions are among those identified in the issue (Pod, DaemonSet...), then use the decoded object to get the image value for all the containers (e.g. obj.Spec.Containers[*].Image).
Otherwise you could have a some resources that might not be among the identified list, e.g. CRs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let me know if you want me to help you with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hectorj2f yes, this was a consideration as mentioned in #437 (comment) - I think it would be better, but as different Kinds come out, it binds us more to the K8s API for parsing unless we still just walk down the tree looking for "image" keys (but guaranteed valid YAML) which would address your other comment.

This regex also doesn't account for quoted string variants, so either way this naive approach needs to change in some fashion.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. There's prior art for ducktyping PodSpec-like Objects, but I don't think it's worth blocking merge for a "perfect solution

Copy link
Contributor

Choose a reason for hiding this comment

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

There's prior art for ducktyping PodSpec-like Objects.

Yes, you could use runtime.Raw and decode the object to the list of supported types here.

Sure, the current implementation should not be blocked by this. Once this PR is merged, I could open a PR with my proposed changes, so you can have a look at them.


manifestPath := args[0]

err := isExtensionAllowed(manifestPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: try to decode the yaml file to verify it is a valid.

Copy link
Member

Choose a reason for hiding this comment

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

(YAML or JSON)

Eventually we should probably just use a canonical k8s parser

Copy link
Member

@dekkagaijin dekkagaijin 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 OK squeaking this in for 1.0.0, with the mentioned caveats...


func getImagesFromYamlManifest(manifest string) ([]string, error) {
var images []string
re := regexp.MustCompile(`image:\s?(?P<Image>.*)\s?`)
Copy link
Member

Choose a reason for hiding this comment

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

Agreed. There's prior art for ducktyping PodSpec-like Objects, but I don't think it's worth blocking merge for a "perfect solution


manifestPath := args[0]

err := isExtensionAllowed(manifestPath)
Copy link
Member

Choose a reason for hiding this comment

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

(YAML or JSON)

Eventually we should probably just use a canonical k8s parser

@cpanato cpanato modified the milestones: v1.0.0, v1.1.0 Jul 28, 2021
@hectorj2f
Copy link
Contributor

@joshes You need to sign off your commits.

Signed-off-by: Joshua Hansen <josh.hansen@handsome.is>
Signed-off-by: Joshua Hansen <josh.hansen@handsome.is>
@joshes
Copy link
Contributor Author

joshes commented Jul 29, 2021

@joshes You need to sign off your commits.

Signed and pushed, thanks.

@dlorenc
Copy link
Member

dlorenc commented Jul 29, 2021

Amazing work! Let's get this in and follow up :)

@dlorenc dlorenc merged commit 0fdfaa9 into sigstore:main Jul 29, 2021
@joshes joshes deleted the feature/verify-manifest branch July 29, 2021 15:43
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.

None yet

6 participants