Skip to content

add e2e test for pkcs11 token signing #3495

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

Merged
merged 3 commits into from
Feb 5, 2024

Conversation

viveksahu26
Copy link
Contributor

Summary

closes #3343

Earlier e2e test doesn't have facility to test PKCS11, but this PR has the support for end-to-end pkcs11 token signing
Following commands being run to automate the e2e test for PKCS11:

sudo docker run -dit --name softhsm4 -p 2348:2345 vegardit/softhsm2-pkcs11-proxy

cd $HOME
apk update
# add git
apk add git
# clone cosign
git clone https://github.com/sigstore/cosign.git
# cd to cosign
cd cosign/
# add make pcsc-lite-libs go command
apk add make build-base go
# test
softhsm2-util --init-token --free --label "My Token" --pin 1234 --so-pin 1234
go test -v -cover -coverprofile=./cover.out -tags=softhsm,pkcs11key -coverpkg github.com/sigstore/cosign/v2/pkg/cosign/pkcs11key test/pkcs11_test.go

Release Note

Documentation

Copy link

codecov bot commented Jan 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (628df78) 40.10% compared to head (71eec70) 40.10%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3495   +/-   ##
=======================================
  Coverage   40.10%   40.10%           
=======================================
  Files         155      155           
  Lines       10044    10044           
=======================================
  Hits         4028     4028           
  Misses       5530     5530           
  Partials      486      486           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -0,0 +1,32 @@
#!/bin/bash

# Copyright 2021 The Sigstore Authors.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be 2024

Copy link
Member

Choose a reason for hiding this comment

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

also update the line 1 to #!/usr/bin/env bash

thanks

# add git
apk add git
# clone cosign
git clone https://github.com/sigstore/cosign.git
Copy link
Contributor

Choose a reason for hiding this comment

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

This would test Cosign at HEAD rather than on the PR.

test/e2e_test.sh Outdated
# Test pkcs11 token signing
echo "testing pkcs11 token signing"
CONTAINER_ID=$(sudo docker run -dit --name softhsm -p 2345:2345 vegardit/softhsm2-pkcs11-proxy)
sudo docker exec -i $CONTAINER_ID /bin/bash < ./test/e2e_test_pkcs11.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be run without sudo? I'd prefer that the tests could be run locally without needed 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.

Yeah, sure.

test/e2e_test.sh Outdated
@@ -79,6 +79,11 @@ docker run -d -p 5000:5000 --restart always -e REGISTRY_STORAGE_DELETE_ENABLED=t
export COSIGN_TEST_REPO=localhost:5000
go test -tags=e2e -v ./test/... -run TestSignVerifyClean

# Test pkcs11 token signing
echo "testing pkcs11 token signing"
CONTAINER_ID=$(sudo docker run -dit --name softhsm -p 2345:2345 vegardit/softhsm2-pkcs11-proxy)
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to cleanup container after the test completed

test/e2e_test.sh Outdated
@@ -79,6 +79,15 @@ docker run -d -p 5000:5000 --restart always -e REGISTRY_STORAGE_DELETE_ENABLED=t
export COSIGN_TEST_REPO=localhost:5000
go test -tags=e2e -v ./test/... -run TestSignVerifyClean

# Test pkcs11 token signing
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 put this in its own shell script and workflow, following the pattern of other e2e tests, so it runs in parallel?

test/e2e_test.sh Outdated
@@ -79,6 +79,15 @@ docker run -d -p 5000:5000 --restart always -e REGISTRY_STORAGE_DELETE_ENABLED=t
export COSIGN_TEST_REPO=localhost:5000
go test -tags=e2e -v ./test/... -run TestSignVerifyClean

# Test pkcs11 token signing
echo "testing pkcs11 token signing"
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove testing line

test/e2e_test.sh Outdated
@@ -79,6 +79,15 @@ docker run -d -p 5000:5000 --restart always -e REGISTRY_STORAGE_DELETE_ENABLED=t
export COSIGN_TEST_REPO=localhost:5000
go test -tags=e2e -v ./test/... -run TestSignVerifyClean

# Test pkcs11 token signing
echo "testing pkcs11 token signing"
CONTAINER_ID=$(docker run -dit --name softhsm -v $(pwd):/root/cosign -p 2345:2345 vegardit/softhsm2-pkcs11-proxy)
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 pin the docker container by hash?

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.

Just one small thing, moving the test to a different GHA. Thanks!

cc @cpanato if you any other comments

@@ -119,6 +119,9 @@ jobs:
- name: Run end-to-end tests
run: ./test/e2e_test.sh

- name: Run pkcs11 end-to-end tests
Copy link
Contributor

Choose a reason for hiding this comment

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

# Test pkcs11 token signing
CONTAINER_ID=$(docker run -dit --name softhsm -v $(pwd):/root/cosign -p 2345:2345 vegardit/softhsm2-pkcs11-proxy@sha256:557a65d2a14e3986f2389d36ddce75609cbd8fb7ee6cf08a78adcc8236c2a80e)

docker exec -i $CONTAINER_ID /bin/bash << 'EOF'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
docker exec -i $CONTAINER_ID /bin/bash << 'EOF'
docker exec -i $CONTAINER_ID /bin/bash << 'EOF'

haydentherapper
haydentherapper previously approved these changes Feb 1, 2024
Copy link
Member

@cpanato cpanato left a comment

Choose a reason for hiding this comment

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

thanks for this pr a few changes

# See the License for the specific language governing permissions and
# limitations under the License.

set -ex
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this explicit?

like

set -o errexit
set -o nounset
set -o pipefail

Copy link
Contributor

Choose a reason for hiding this comment

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

just need to update this

@@ -73,3 +76,17 @@ jobs:
- name: Run e2e_signblob_tsa_mtls.sh
shell: bash
run: make && PATH="$PWD:$PATH" ./test/e2e_signblob_tsa_mtls.sh

e2e-test-pkcs11:
name: Run pkcs11 e2e tests
Copy link
Member

Choose a reason for hiding this comment

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

you can drop this

go-version: ${{ env.GO_VERSION }}
check-latest: true

- name: Run pkcs11 end-to-end tests
Copy link
Member

Choose a reason for hiding this comment

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

set the shell to bash like the others

Signed-off-by: Vivek Kumar Sahu <[email protected]>

add license

Signed-off-by: Vivek Kumar Sahu <[email protected]>

small fix

Signed-off-by: Vivek Kumar Sahu <[email protected]>

update shebang portable with cross platform

Signed-off-by: Vivek Kumar Sahu <[email protected]>

enable exit on error and xtrace mode

Signed-off-by: Vivek Kumar Sahu <[email protected]>

cleanup container

Signed-off-by: Vivek Kumar Sahu <[email protected]>

pkcs11 test with upcoming changes

Signed-off-by: Vivek Kumar Sahu <[email protected]>

run pkcs11 e2e test in a separate workflow

Signed-off-by: Vivek Kumar Sahu <[email protected]>

add pkcs11 test in separate workflow

Signed-off-by: Vivek Kumar Sahu <[email protected]>
Signed-off-by: Vivek Kumar Sahu <[email protected]>
Signed-off-by: Vivek Kumar Sahu <[email protected]>
@haydentherapper
Copy link
Contributor

@cpanato PTAL

Copy link
Member

@cpanato cpanato left a comment

Choose a reason for hiding this comment

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

i will do any adjust in a followup

@cpanato
Copy link
Member

cpanato commented Feb 5, 2024

thanks for this pr!

@cpanato cpanato merged commit 7951940 into sigstore:main Feb 5, 2024
@github-actions github-actions bot added this to the v2.3.0 milestone Feb 5, 2024
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.

Add end-to-end testing for PKCS11 token signing
4 participants