Skip to content

Commit

Permalink
Merge pull request #3 from smallstep/jdoss/sigstore-python_2.0.1
Browse files Browse the repository at this point in the history
Update sigstore-python to 2.0.1
  • Loading branch information
jdoss authored Oct 19, 2023
2 parents 274d533 + 8f01e25 commit 46e86ca
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 39 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/black.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: pre-commit

on:
push:
tags-ignore:
- 'v*'
branches:
- "main"
pull_request:


jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.0
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.286
hooks:
- id: ruff

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: trailing-whitespace
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ verify_artifact_cert_identity: user@example.com # The identity to check for in t
verify_artifact_cert_oidc_issuer: https://oidc.example.com # The OIDC issuer URL to check for in the certificate's OIDC issuer extension (Required)
verify_artifact_fail_run: True # If set to False it will _not_ fail the playbook run if verification fails (Defaults to True)
verify_artifact_pip_sigstore_install: True # Ensure the pip sigstore package is installed (Defaults to True)
verify_artifact_pip_sigstore_version: 1.1.2 # Specific version to install. (Defaults to 1.1.2)
verify_artifact_pip_sigstore_version: 2.0.1 # Specific version to install. (Defaults to 2.0.1)
```

### Example Playbook
Expand All @@ -82,7 +82,7 @@ verify_artifact_pip_sigstore_version: 1.1.2 # Specific version to install. (Defa
verify_artifact_cert_oidc_issuer: https://oidc.example.com
verify_artifact_fail_run: True
verify_artifact_pip_sigstore_install: True
verify_artifact_pip_sigstore_version: 1.1.2
verify_artifact_pip_sigstore_version: 2.0.1
```

## Testing
Expand Down
31 changes: 18 additions & 13 deletions plugins/modules/sigstore_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,19 @@
sample: True
"""

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import missing_required_lib
from ansible.module_utils.common.text.converters import to_native
from ansible_collections.smallstep.sigstore.plugins.module_utils.sigstore import (
import base64 # noqa: E402
import binascii # noqa: E402
import traceback # noqa: E402
from pathlib import Path # noqa: E402

from ansible.module_utils.basic import AnsibleModule, missing_required_lib # noqa: E402
from ansible.module_utils.common.text.converters import to_native # noqa: E402
from ansible_collections.smallstep.sigstore.plugins.module_utils.sigstore import ( # noqa: E402
Sigstore,
)

import base64
import binascii
import traceback
from pathlib import Path

try:
from sigstore.verify import Verifier, VerificationMaterials
from sigstore.verify import VerificationMaterials, Verifier
from sigstore.verify.policy import Identity
except ImportError:
HAS_SIGSTORE = False
Expand Down Expand Up @@ -149,10 +148,14 @@ def verify_artifact(self) -> list:
# The signature to verify
signature = Path(params["signature"])

with artifact.open("rb") as a, cert.open("r") as c, signature.open("rb") as s:
with artifact.open("rb") as a, cert.open("r") as c, signature.open(
"rb"
) as s:
try:
cert_data = c.read()
cert_data_processed = base64.b64decode(cert_data, validate=True).decode("utf-8")
cert_data_processed = base64.b64decode(
cert_data, validate=True
).decode("utf-8")
except binascii.Error:
cert_data_processed = cert_data
materials = VerificationMaterials(
Expand Down Expand Up @@ -209,7 +212,9 @@ def define_module():
def main():
module = AnsibleSigstoreVerify.define_module()
if not HAS_SIGSTORE:
module.fail_json(msg=missing_required_lib("sigstore"), exception=SIGSTORE_IMPORT_ERROR)
module.fail_json(
msg=missing_required_lib("sigstore"), exception=SIGSTORE_IMPORT_ERROR
)

sigstore = AnsibleSigstoreVerify(module)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sigstore=1.1.2
sigstore=2.0.1
6 changes: 3 additions & 3 deletions roles/verify_artifact/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ verify_artifact_cert_identity: user@example.com # The identity to check for in t
verify_artifact_cert_oidc_issuer: https://oidc.example.com # The OIDC issuer URL to check for in the certificate's OIDC issuer extension (Required)
verify_artifact_fail_run: True # If set to False it will _not_ fail the playbook run if verification fails (Defaults to True)
verify_artifact_pip_sigstore_install: True # Ensure the pip sigstore package is installed (Defaults to True)
verify_artifact_pip_sigstore_version: 1.1.2 # Specific version to install. (Defaults to 1.1.2)
verify_artifact_pip_sigstore_version: 2.0.1 # Specific version to install. (Defaults to 2.0.1)
```
## Example Playbook
Expand All @@ -40,7 +40,7 @@ Here is how you can include this role in your playbook to verify an archive with
verify_artifact_cert_oidc_issuer: https://oidc.example.com
verify_artifact_fail_run: True
verify_artifact_pip_sigstore_install: True
verify_artifact_pip_sigstore_version: 1.1.2
verify_artifact_pip_sigstore_version: 2.0.1
```
## Author Information
Expand All @@ -50,6 +50,6 @@ Smallstep Engineering
## License
[Apache License Version 2.0](http://www.apache.org/licenses/LICENSE-2.0>)
[Apache License Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
Copyright 2023 Smallstep Labs Inc.
2 changes: 1 addition & 1 deletion roles/verify_artifact/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# defaults file for verify_artifact
verify_artifact_fail_run: True
verify_artifact_pip_sigstore_install: True
verify_artifact_pip_sigstore_version: 1.1.2
verify_artifact_pip_sigstore_version: 2.0.1
2 changes: 1 addition & 1 deletion roles/verify_artifact/tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
verify_artifact_cert_oidc_issuer: https://oidc.example.com
verify_artifact_fail_run: True
verify_artifact_pip_sigstore_install: True
verify_artifact_pip_sigstore_version: 1.1.2
verify_artifact_pip_sigstore_version: 2.0.1

0 comments on commit 46e86ca

Please sign in to comment.