You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python library which supports TPM embedded credentials for various cloud providers.
4
4
5
-
Ath the moment, only GCP but followup with AWS and Azure when i find time (they're all implemented in golang, its just tedious to map to python)
6
-
7
-
For GCP:
8
-
9
-
This is an extension of GCP [google-auth-python](https://github.com/googleapis/google-auth-library-python) specifically intended to use service account credentials which are embedded inside a `Trusted Platform Module (TPM)`.
10
-
11
5
on python pypi: [https://pypi.org/project/cloud-auth-tpm/](https://pypi.org/project/cloud-auth-tpm/)
12
6
13
-
14
7
> **>>WARNING<<**: This code is not affiliated with or supported by google
15
8
16
9
---
17
10
18
11
### Usage
19
12
20
-
-**GCPCredentials**
13
+
You need to first embed an RSA key into a TPM thats readable by [python-tss](https://github.com/tpm2-software/tpm2-pytss). See the [Setup](#setup)
14
+
15
+
##### **GCPCredentials**
21
16
22
17
```python
23
18
from google.cloud import storage
24
19
from cloud_auth_tpm.gcp.gcpcredentials import GCPCredentials
|**`client_id`**| Azure Application (client) ID (required; default: ``) |
122
+
|**`certificate_path`**| x509 certificate to authenticate with (required; default ``) |
86
123
87
124
---
88
125
89
126
### Setup
90
127
91
128
This library uses the [Feature API](https://tpm2-pytss.readthedocs.io/en/latest/fapi.html) provided through `tpm2_pytss`.
92
129
93
-
To install that:
130
+
You need to first install [tpm2-tss](https://github.com/tpm2-software/tpm2-tss)`version>=4.1.0` (see [issue#596](https://github.com/tpm2-software/tpm2-pytss/issues/596))
There are several ways you can have a TPM based service account key:
140
+
You can initialize a TPM based RSA key and optional certificate in several ways:
104
141
105
-
1. create a key on the tpm, use it to create an x509 and upload the certificate
142
+
1. create a key on the tpm
106
143
2. import an the raw private key into the TPM
107
144
3. securely transfer a key from on machine to the machine with the TPM and then import
108
145
109
-
This example will just cover (2) for simplicity. For more info, see [oauth2/tpm2tokensource](https://github.com/salrashid123/oauth2?tab=readme-ov-file#usage)
146
+
This example will just cover (2) for simplicity which for the FAPI, is done using the [example/load.py](example/load.py) utility.
147
+
148
+
For more info, see [oauth2/tpm2tokensource](https://github.com/salrashid123/oauth2?tab=readme-ov-file#usage)
110
149
111
150
For additional examples on using FAPI with python to perform operations, see [salrashid123/tpm2/pytss](https://github.com/salrashid123/tpm2/tree/master/pytss)
112
151
113
-
Once you install the FAPI, you will need to embed a service account key into the TPM.
152
+
153
+
#### Setup - GCP
154
+
155
+
This is an extension of GCP [google-auth-python](https://github.com/googleapis/google-auth-library-python) specifically intended to use service account credentials which are embedded inside a `Trusted Platform Module (TPM)`.
@@ -175,19 +217,106 @@ So since we have the RSA key on the TPM, we can use the FAPI to make it "sign" d
175
217
176
218
#### Setup - AWS
177
219
178
-
##### HMAC
220
+
[AWS Roles Anywhere](https://docs.aws.amazon.com/rolesanywhere/latest/userguide/introduction.html) allows for client authentication based on digital signature from trusted private keys.
179
221
180
-
TODO: once FAPI supports hmac
222
+
The trusted client RSA or EC key is embedded within a TPM and that is used to sign the RolesAnywhere header values.
181
223
182
-
ref: [AWS Credentials for Hardware Security Modules and TPM based AWS_SECRET_ACCESS_KEY](https://github.com/salrashid123/aws_hmac)
224
+
In the example in this repo, we will use a *EXAMPLE* CA and key. If you follow this setup, you are using a the rsa key and CA found in this repo....so *please* remember to use test resources and promptly delete/disable this.
183
225
184
-
##### Roles Anywhere
226
+
The specific certificate CA and private key is the same as described in the sample here:
185
227
186
-
TODO: support [AWA RolesAnywhere Signer](https://github.com/salrashid123/aws_rolesanywhere_signer)
When you setup RolesAnywhere, note down the ARN for the `TrustAnchorArn`, `ProfileArn` and `RoleArn` as well as the `region`. Ideally, the role has `AmazonS3ReadOnlyAccess` to list buckets.
231
+
232
+
We'll use `example/load.py` FAPI commands to embed the key into the TPM and save it at FAPI path of your choice, eg `/HS/SRK/awssign1`:
233
+
234
+
```bash
235
+
cd example/
236
+
# rm -rf ~/.local/share/tpm2-tss # warning, this will clear any FAPI objects
Currently ONLY RSASSA keys are supported (its easy enough to support others, TODO)
263
+
264
+
An alternative to using this library is invoking a process to acquire credentials from any SDK. See: [AWS Process Credentials for Trusted Platform Module (TPM)](https://github.com/salrashid123/aws-tpm-process-credential).
265
+
266
+
TODO: once FAPI supports hmac, i'll try to add on HMAC auth too ref: [AWS Credentials for Hardware Security Modules and TPM based AWS_SECRET_ACCESS_KEY](https://github.com/salrashid123/aws_hmac) and specifically [AWS v4 signed request using Trusted Platform Module](https://gist.github.com/salrashid123/bca7a24e1d59567adb89fef093d8564d)
187
267
188
268
#### Setup - Azure
189
269
190
-
TODO: [KMS, TPM and HSM based Azure Certificate Credentials](https://github.com/salrashid123/azsigner)
270
+
Azure authentication uses an the basic [Microsoft identity platform application authentication certificate credentials](https://learn.microsoft.com/en-us/entra/identity-platform/certificate-credentials) where the variation here is that the client rsa key is on the TPM
271
+
272
+
The following example assumes you have set this up. You can find an example/test setup here:
273
+
274
+
*[KMS, TPM and HSM based Azure Certificate Credentials](https://github.com/salrashid123/azsigner)
275
+
276
+
We'll use `example/load.py` FAPI commands to embed the key into the TPM and save it at FAPI path of your choice, eg `/HS/SRK/azuresign1`:
277
+
278
+
```bash
279
+
cd example/
280
+
# rm -rf ~/.local/share/tpm2-tss # warning, this will clear any FAPI objects
0 commit comments