forked from secure-systems-lab/securesystemslib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Very bare bones Signer for Google Cloud KMS: Private keys live in KMS, signing happens in KMS (although payloading hash happens in Signer). This is not super usable without issue secure-systems-lab#447 but demonstrates the simplicity. Key creation is not supported at this point. A test is added with a few caveats: * dependencies are not added to requirements.txt: this would more than triple the size of requirements-pinnex.txt... Not sure what the best path her is * Test only works on GitHub (because of the authentication) * There's a separate tox env, meaning the test only runs once per test run: this allows testing separate requirements but also makes it easier to set very low usage quotas on GCP
- Loading branch information
Showing
6 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,9 +28,15 @@ jobs: | |
- python-version: 3.8 | ||
os: ubuntu-latest | ||
toxenv: lint | ||
- python-version: 3.x | ||
os: ubuntu-latest | ||
toxenv: kms | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
permissions: | ||
id-token: 'write' # for OIDC auth for GCP authentication | ||
|
||
steps: | ||
- name: Checkout securesystemslib | ||
uses: actions/checkout@v2 | ||
|
@@ -54,11 +60,19 @@ jobs: | |
# A match with 'restore-keys' is used as fallback | ||
restore-keys: ${{ runner.os }}-pip- | ||
|
||
- name: 'Authenticate to Google Cloud' | ||
# Authenticate to GCP KMS, but only if we're running KMS tests | ||
if: ${{ matrix.toxenv == 'kms' }} | ||
uses: 'google-github-actions/auth@c4799db9111fba4461e9f9da8732e5057b394f72' | ||
with: | ||
token_format: 'access_token' | ||
workload_identity_provider: 'projects/843741030650/locations/global/workloadIdentityPools/securesystemslib-tests/providers/securesystemslib-tests' | ||
service_account: '[email protected]' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install --upgrade tox | ||
- name: Run tox | ||
run: tox -e ${{ matrix.toxenv }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
google-cloud-kms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
This test confirms that signing using Google Cloud KMS works. | ||
Requirements to successfully run it: | ||
* Google Cloud authentication details have to be available in the | ||
environment (see https://github.com/googleapis/python-kms) | ||
* The key defined in the test has to be available to the authenticated | ||
user | ||
Likely the only place where both can be true is the Securesystemslib | ||
GitHub Action environment. | ||
NOTE: the filename is purposefully check_ rather than test_ so that test | ||
discovery doesn't find this unittest and the tests within are only run | ||
when explicitly invoked. | ||
""" | ||
|
||
import unittest | ||
|
||
from securesystemslib.signer import GCPSigner | ||
from securesystemslib import keys | ||
|
||
class TestKMSKeys(unittest.TestCase): | ||
"""Test that KMS keys can be used to sign.""" | ||
|
||
def test_gcp(self): | ||
"""Test that GCP KMS key works for signing | ||
In case of problems with KMS account, please file an issue and | ||
assign @jku | ||
""" | ||
|
||
data = "data".encode("utf-8") | ||
|
||
pubkey = { | ||
"keyid": "abcd", | ||
"keytype": "ecdsa", | ||
"scheme": "ecdsa-sha2-nistp256", | ||
"keyval": { | ||
"public": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/ptvrXYuUc2ZaKssHhtg/IKNbO1X\ncDWlbKqLNpaK62MKdOwDz1qlp5AGHZkTY9tO09iq1F16SvVot1BQ9FJ2dw==\n-----END PUBLIC KEY-----\n" | ||
}, | ||
} | ||
|
||
gcp_id = "projects/python-tuf-kms/locations/global/keyRings/securesystemslib-tests/cryptoKeys/ecdsa-sha2-nistp256/cryptoKeyVersions/1" | ||
hash_algo = "sha256" | ||
|
||
signer = GCPSigner(gcp_id, hash_algo, pubkey["keyid"]) | ||
sig = signer.sign(data) | ||
|
||
self.AssertTrue(keys.verify_signature(pubkey, sig.to_dict(), data)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main(verbosity=1, buffer=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters