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

Cosign Signing Integration #817

Merged
merged 2 commits into from Sep 27, 2021
Merged

Cosign Signing Integration #817

merged 2 commits into from Sep 27, 2021

Conversation

DennyHoang
Copy link
Contributor

@DennyHoang DennyHoang commented Aug 31, 2021

This PR integrates cosign for image signing as specified in RFC #694

When an operator attaches a cosign formatted secret (contains at least cosign.key data key) to the service account used for building the image, the image will then attempt to be signed after it has been built and pushed to a repository.

Status: Ready for Review

Currently, we are opening this draft PR to get an early review of our current implementation. There are still features that have not been implemented as listed in the Features checklist below. Also, open for discussion, would it be alright to have Signing/Verifying builder/clusterBuilder images as a separate PR such that the next version of kpack could have the initial image signing first? Then, we will work on implementing the Signing/Verifying builder/clusterBuilder images portion afterwards as the upcoming feature cutoff is nearing for the next release candidate for kpack.

Features:

  • Signing when keys are mounted for buildPod scenario
  • Signing when keys are mounted for rebasePod scenario
  • Add static annotations to signature for build number and build timestamp
  • Support custom annotations to be added to signature
  • Support for alternative registry for built image vs cosign signature
  • Support for legacy docker media type
  • Signing/Verifying builder/clusterBuilder images This will be addressed in a separate PR. Currently requires ability to provide a different keychain. Issue raised to cosign here and here for signing builder images as mentioned here

We had some questions which are added as "Review" items to help organize discussion into threads.

go.mod Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Aug 31, 2021

Codecov Report

Merging #817 (d1b125d) into main (3768e62) will increase coverage by 0.26%.
The diff coverage is 93.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #817      +/-   ##
==========================================
+ Coverage   68.20%   68.46%   +0.26%     
==========================================
  Files         112      114       +2     
  Lines        4878     4938      +60     
==========================================
+ Hits         3327     3381      +54     
- Misses       1186     1189       +3     
- Partials      365      368       +3     
Impacted Files Coverage Δ
pkg/apis/build/v1alpha2/build_types.go 100.00% <ø> (ø)
pkg/apis/build/v1alpha2/image_types.go 50.00% <ø> (ø)
pkg/apis/build/v1alpha2/cosign_validation.go 83.33% <83.33%> (ø)
pkg/cosign/image_signer.go 87.50% <87.50%> (ø)
pkg/apis/build/v1alpha2/build_pod.go 97.17% <100.00%> (+0.01%) ⬆️
pkg/apis/build/v1alpha2/image_builds.go 68.15% <100.00%> (+0.20%) ⬆️
pkg/apis/build/v1alpha2/image_validation.go 97.87% <100.00%> (+0.02%) ⬆️
pkg/notary/image_signer.go 71.60% <100.00%> (+1.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3768e62...d1b125d. Read the comment docs.

@@ -141,6 +142,56 @@ To create the notary secret used by kpack for image signing, run the following c
- `<password>`: The password provided to encrypt the private key.
- `<hash>.key`: The private key file.

### <a id='cosign-config'></a>Cosign Configuration
Copy link
Contributor Author

@DennyHoang DennyHoang Aug 31, 2021

Choose a reason for hiding this comment

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

Would it be alright to have Signing/Verifying builder/clusterBuilder images as a separate PR such that the next version of kpack could have the initial image signing first? Then, we will work on implementing the Signing/Verifying builder/clusterBuilder images portion of the RFC as the following kpack version since upcoming feature cutoff is near for the next release candidate for kpack.

logger.Fatal(err)
}

for _, c := range append(dockerCfgCredentials, dockerConfigCredentials...) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I realize this was the existing behavior in completion but, it seems unnecessary to rebuild the keychain to just write to docker/config.json again. Can we just mount the same credentials from export into completion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you mean that I remount the homeVolume and set the Env HOME to /builder/home?

I noticed that build-init would save the config to /builder/home/docker/config.json and could therefore be reused by completion during the regular buildPod flow. However, during the rebasePod flow, as the only initContainer is the "rebase" container. It does load some docker credentials but it does not save it. I could introduce the "Save" portion to the rebase image and therefore the completion container could leverage a shared volume for both buildPod and rebasePod scenarios. Is it ideal to introduce this logic into "rebase" when it itself doesn't need the file to be saved just so we can leverage the byproduct of that outside of that container in completion?

The keychain still needed to be built or loaded into a variable to be passed into Notary while cosign only requires the config to be writing to a file named config.json. The keychain could be built from the config.json though instead of from each secret individually if mounting a shared volume is the way to go

Copy link
Contributor Author

@DennyHoang DennyHoang Sep 8, 2021

Choose a reason for hiding this comment

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

@matthewmcnew If I'm understanding this wrong, please lemme know what the best approach is :D

Copy link
Collaborator

Choose a reason for hiding this comment

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

I forgot about the complexities introduced by the rebase container. I think it would eventually be a good idea for the rebase container to "save" the credentials to a volume that can be loaded in completion. I don't think you need to introduce this in your PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since that is the case, I will leave the current credential generation and saving inside the completion image. When we introduce and find a more uniform way of saving credentials, we can adjust the completion container then. For cosign portion in the completion container, with the shared volume during non rebase case, it seemed to work from my quick testing when mounting the shared home volume. For the notary portion, it is still likely that the keychain would need to be loaded to be passed into the notary sign function. Is there a place I can put stories or track this concern? Do I just make a Github issue saying to standardize docker credential saving using shared volumes to be more consistent between rebasePod/buildPod/initContainers/containers?

@DennyHoang DennyHoang changed the title [Draft] Cosign Signing Integration Cosign Signing Integration Sep 13, 2021
@DennyHoang DennyHoang marked this pull request as ready for review September 13, 2021 17:44
cmd/completion/main.go Outdated Show resolved Hide resolved
cmd/completion/main.go Outdated Show resolved Hide resolved
@DennyHoang
Copy link
Contributor Author

@tomkennedy513 @tylerphelan @matthewmcnew I believe I have currently addressed all the outstanding review comments :) Please take a look when you have time, thanks.

Copy link
Collaborator

@tomkennedy513 tomkennedy513 left a comment

Choose a reason for hiding this comment

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

Looks great! Would you mind squashing these commits and rebasing when everything is approved?

@dumez-k dumez-k self-requested a review September 22, 2021 19:10
go.mod Outdated Show resolved Hide resolved

cliSignCmd := func(ctx context.Context, ko cli.KeyOpts, annotations map[string]interface{}, imageRef, certPath string, upload bool, payloadPath string, force, recursive bool) error {
t.Helper()
assert.Equal(t, testCtx, ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I really like that these tests actually validate the signature. I think the additional validation of the values passed to the cliSignCmd here might be unnecessary (and may make it hard to use new api versions).

I think it is fine for now but, perhaps something to think about in the future.

@DennyHoang
Copy link
Contributor Author

DennyHoang commented Sep 23, 2021

Please dont merge yet
I am getting an error for nodeSelector:

Edit: Going to figure out the squashing tomorrow because of my interweaved merge commits.

Figured out thanks to Tom!

@DennyHoang
Copy link
Contributor Author

DennyHoang commented Sep 23, 2021

Hmm, small change is required.
If I build an image without cosign, it is trying to look into the cosign secret folder but it doesnt exist because no secrets were mounted there.

Going to make a small adjustment to log there instead of returning an error as it should continue if there are no secrets found.

@DennyHoang
Copy link
Contributor Author

DennyHoang commented Sep 23, 2021

Thanks @tomkennedy513 for your help with the squash!

If people are okay with that adjustment I made in the above comment/commit, then this PR is good to go!

Co-authored-by: Mauren Berti <mribeirobert@vmware.com>
Co-authored-by: Denny Hoang <dhoang@vmware.com>
Co-authored-by: Andrés Torres <andrest@vmware.com>
Co-authored-by: Kavitha Krishnan <krishnanka@vmware.com>
@dumez-k dumez-k self-requested a review September 27, 2021 16:20
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.

Tracking Issue - Cosign signing via secrets configured on service account
9 participants