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

Added support for attaching Time stamp authority Response in attach command #3001

Merged
merged 9 commits into from
Jun 6, 2023
Merged

Added support for attaching Time stamp authority Response in attach command #3001

merged 9 commits into from
Jun 6, 2023

Conversation

Mukuls77
Copy link
Contributor

Summary

The PR provide the support to attach Timestamp authority response for signed signature time stamp in attach command.
using this functionality now we can attach a TSR response for the generated signature and attach that along with the associated certificates and certificate chain. This PR will help specifically in private CA cases where now Private CA can issue short lived certificates and attach the Time stamp of the signature. This will help in checking the validity of the associated certificates using the signature time stamp

Release Note

Following files have been modified for the PR.
cmd/cosign/cli/attach.go
cmd/cosign/cli/attach/sig.go
cmd/cosign/cli/options/attach.go
doc/cosign_attach_signature.md
test/e2e_test.go
test/e2e_test_attach.sh
test/testdata/test_attach_freetsacacert.pem
Add a release note for each of the following conditions:

Documentation

This PR introduce a new parameter that can be used in the Attach command to pass the path of the Time stamp Authority response.
The updated command help is as below

$ ./cosign attach signature --help
Attach signatures to the supplied container image

Usage:
cosign attach signature [flags]

Examples:
cosign attach signature

Flags:
--allow-http-registry whether to allow using HTTP protocol while connecting to registries. Don't use this for anything but testing
--allow-insecure-registry whether to allow insecure connections to registries (e.g., with expired or self-signed TLS certificates). Don't use this for anything but testing
--attachment-tag-prefix [AttachmentTagPrefix]sha256-[TargetImageDigest].[AttachmentName] optional custom prefix to use for attached image tags. Attachment images are tagged as: [AttachmentTagPrefix]sha256-[TargetImageDigest].[AttachmentName]
--certificate string path to the X.509 certificate in PEM format to include in the OCI Signature
--certificate-chain string path to a list of CA X.509 certificates in PEM format which will be needed when building the certificate chain for the signing certificate. Must start with the parent intermediate CA certificate of the signing certificate and end with the root certificate. Included in the OCI Signature
-h, --help help for signature
--k8s-keychain whether to use the kubernetes keychain instead of the default keychain (supports workload identity).
--payload string path to the payload covered by the signature
--signature string path to the signature, or {-} for stdin
--timeStampedSignatureResponse string path to the Time Stamped Signature Response from RFC3161 compliant TSA

Global Flags:
--output-file string log output to a file
-t, --timeout duration timeout for commands (default 3m0s)
-d, --verbose log debug output

Testing

Make , lint , Docgen test were done. also e2e test related to attach command were done. attached are the logs
Build_Lint_Docgen_test_logs.txt

e2e_attach_test_logs.txt

…ommand

Signed-off-by: Mukuls77 <mukul.sharma@nokia.com>
@codecov
Copy link

codecov bot commented May 23, 2023

Codecov Report

Merging #3001 (2b4c9b3) into main (f21081a) will increase coverage by 0.70%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main    #3001      +/-   ##
==========================================
+ Coverage   30.25%   30.95%   +0.70%     
==========================================
  Files         151      153       +2     
  Lines        9473     9678     +205     
==========================================
+ Hits         2866     2996     +130     
- Misses       6162     6224      +62     
- Partials      445      458      +13     
Impacted Files Coverage Δ
cmd/cosign/cli/attach.go 0.00% <0.00%> (ø)
cmd/cosign/cli/options/attach.go 0.00% <0.00%> (ø)

... and 11 files with indirect coverage changes

Signed-off-by: Mukuls77 <mukul.sharma@nokia.com>
Signed-off-by: Mukuls77 <mukul.sharma@nokia.com>
Copy link
Contributor

@haydentherapper haydentherapper left a comment

Choose a reason for hiding this comment

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

LGTM on the feature, just a comment on flag name and testing.

@@ -46,6 +47,10 @@ IMAGE_URI_DIGEST=$IMAGE_URI@$SRC_DIGEST

## Sign with Leafcert Private Key
openssl dgst -sha256 -sign ./private_key -out payload.sig payload.json
## Generate TSR for the signature
openssl ts -query -data payload.sig -sha256 -cert -out payload.tsq
curl -H "Content-Type: application/timestamp-query" --data-binary '@payload.tsq' https://freetsa.org/tsr > payload.tsr
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 the libraries in the sigstore/timestamp-authority repo to generate a timestamp (see unit tests, there should be some examples), or stand up an instance of the tsa for an e2e test (also there should be examples of such). We shouldn’t call out to a third party service as part of our tests.

Copy link
Contributor Author

@Mukuls77 Mukuls77 May 30, 2023

Choose a reason for hiding this comment

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

I tried to check the instance in the existing e2e test cases where we have used a separate instance of the tsa, but was not able to find any example. In the unit test i could see there are many instance of test cases covering the TSA testing and verification. so i think adding a new unit test case for attach case will not add up much functionality as in unit test case we directly modify the signature structure to include cert, cert-chain and tsa.
If it is ok with you i can remove the changes i did to introduce TSA functionality in attach test case, as it is already covered in unit test of sign and verify.

Copy link
Contributor

Choose a reason for hiding this comment

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

This test has an example of spinning up a local server - https://github.com/sigstore/cosign/blob/main/test/e2e_test.go#L724

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Hayden i have created a new test cases for using TSR in attach command in e2e_test.go file also i have reverted the changes in e2e_test_attach.sh file which were using freetsa for getting TSR. kindly review the changes,

@@ -54,6 +55,8 @@ func (o *AttachSignatureOptions) AddFlags(cmd *cobra.Command) {
"when building the certificate chain for the signing certificate. "+
"Must start with the parent intermediate CA certificate of the "+
"signing certificate and end with the root certificate. Included in the OCI Signature")
cmd.Flags().StringVar(&o.TimeStampedSig, "timeStampedSignatureResponse", "",
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 an acronym “—tsr” for the flag name instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree i will change the flag name from --timeStampedSignatureResponse to --tsr

Signed-off-by: Mukuls77 <mukul.sharma@nokia.com>
Signed-off-by: Mukuls77 <mukul.sharma@nokia.com>
Signed-off-by: Mukuls77 <mukul.sharma@nokia.com>
Signed-off-by: Mukuls77 <mukul.sharma@nokia.com>
Copy link

@malancas malancas left a comment

Choose a reason for hiding this comment

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

This LGTM now that the test uses sigstore/timestamp-authority libraries but I'll wait for @haydentherapper to give this another look as well.

@Mukuls77
Copy link
Contributor Author

Mukuls77 commented Jun 3, 2023

Thanks @malancas for the review @haydentherapper can you pls also review the PR changes

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you delete this cert?

test/e2e_test.go Outdated
pemleafRef := mkfile(string(pemLeaf), td, t)
pemrootRef := mkfile(string(pemRoot), td, t)

certchainRef := mkfile(string(appendSlices([][]byte{pemSub, pemRoot})), td, t)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can you just inline the concatenation of these two, string(append(pemSub, pemRoot...)) and remove appendSlices given it's not used elsewhere?

Copy link
Contributor

@haydentherapper haydentherapper 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! Just two small comments, thanks for updating the tests.

Signed-off-by: Mukuls77 <mukul.sharma@nokia.com>
@Mukuls77
Copy link
Contributor Author

Mukuls77 commented Jun 6, 2023

Thanks @haydentherapper for the review i have done the required changes pls check

@haydentherapper haydentherapper merged commit 1894263 into sigstore:main Jun 6, 2023
@github-actions github-actions bot added this to the v1.14.0 milestone Jun 6, 2023
@Mukuls77 Mukuls77 deleted the Mukuls77-AddCmd-Branch branch June 6, 2023 08: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.

4 participants