Skip to content

Commit a411dc2

Browse files
committed
verif local training / signing / verify works
Signed-off-by: laurentsimon <laurentsimon@google.com>
1 parent fde0112 commit a411dc2

File tree

2 files changed

+61
-20
lines changed

2 files changed

+61
-20
lines changed

model_signing/readme.md

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,32 @@ All you needed to verify was an identity and its provider. No cryptographic keys
4646
### End-to-end model signing and verification
4747

4848
#### Mode training
49-
TODO: download ready-made or instruction to run it.
5049

51-
This will take 10mn or so. You can download a pre-trained model if you prefer.
50+
Training will take up to 15mn. You can use the pre-trained model from the previous section instead.
51+
52+
Ensure you are running in the [python virtal environment](https://github.com/slsa-framework/oss-na24-slsa-workshop/blob/main/INSTALLATION.md#sigstore-python) where you installed the tooling:
53+
54+
```shell
55+
$ cd sigstore-python
56+
$ source env/bin/activate
57+
$ cd ..
58+
```
59+
60+
Then follow the instuctions below:
61+
62+
```shell
63+
$ git clone git@github.com:slsa-framework/oss-na24-slsa-workshop-model-integrity.git && cd oss-na24-slsa-workshop-model-integrity
64+
# One of Linux, Windows or macOS
65+
$ OS=Linux
66+
$ python3 -m pip install --require-hashes -r "slsa_for_models/install/requirements_${OS}.txt"
67+
# Start the training
68+
# WARNING: This may take up to 15mn.
69+
$ python3 slsa_for_models/main.py tensorflow_saved_model
70+
$ model_path=$(pwd)/tensorflow_saved_model
71+
$ cd ..
72+
```
73+
74+
The mode is stored under directory `tensorflow_saved_model`.
5275

5376
#### Model signing
5477

@@ -62,16 +85,17 @@ $ cd ..
6285

6386
```shell
6487
$ cd model-transparency/model_signing
65-
$ model=path/to/model/
66-
$ python3 main.py sign --path "${model}"
88+
$ python3 main.py sign --path "${model_path}"
6789
Go to the following link in a browser:
6890

6991
https://oauth2.sigstore.dev/auth/auth?response_type=code....
7092

7193
Enter verification code:
7294
```
7395

74-
What just happened? What is this link? Sigstore is asking you to authenticate to you email provider via [OIDC Connect](https://openid.net/developers/how-connect-works/). At the time of writing, Sigstore supports [three identity providers](https://github.com/sigstore/model-transparency/blob/main/model_signing/README.md): Google, Microsoft and GitHub. Copy the weblink that is presented to you in your web browser and follow the steps. You'll get a token. Copy it in the terminal and press Enter.
96+
You shoud be prompted with a verification code. If you do not, re-run the same command but additionally pass the `--disable-ambient` flag.
97+
98+
WWHat is the verification code? Sigstore is asking you to authenticate to your email provider via [OIDC Connect](https://openid.net/developers/how-connect-works/). At the time of writing, Sigstore supports [three identity providers](https://github.com/sigstore/model-transparency/blob/main/model_signing/README.md): Google, Microsoft and GitHub. Copy the weblink that is presented to you in your web browser and follow the steps. You'll get a token. Copy it in the terminal and press Enter.
7599

76100
```shell
77101
Enter verification code: .....
@@ -92,8 +116,7 @@ To verify, you need to know both the identity of the signer and its identity pro
92116
```shell
93117
$ provider=_one_of_providers_above
94118
$ identity=email@provider.com
95-
$ model=path/to/model/
96-
$ python3 main.py verify --path "${model}" --identity "${identity}" --identity-provider "${provider}"
119+
$ python3 main.py verify --path "${model_path}" --identity "${identity}" --identity-provider "${provider}"
97120
```
98121

99122
Try editing, deleting or adding files to your model and re-run the verification.
@@ -105,10 +128,9 @@ The signature file is in a format called a [Sigstore bundle](https://github.com/
105128
Let's take a look at the signature file. Make sure [jq](https://github.com/slsa-framework/oss-na24-slsa-workshop/blob/main/INSTALLATION.md#jq) and [openssl](https://github.com/slsa-framework/oss-na24-slsa-workshop/blob/main/INSTALLATION.md#openssl) are installed on your machine.
106129

107130
```shell
108-
$ model=path/to/model/
109-
$ jq < "${model}model.sig"
131+
$ jq < "${model_path}/model.sig"
110132
# Visualize the certificate Sigstore created for your identity
111-
$ jq -r '.verificationMaterial.certificate.rawBytes'< "${model}"model.sig | base64 -d | openssl x509 -text -noout
133+
$ jq -r '.verificationMaterial.certificate.rawBytes'< "${model_path}/model.sig" | base64 -d | openssl x509 -text -noout
112134
[...]
113135
X509v3 Subject Alternative Name: critical
114136
email:laurentsimon@google.com
@@ -123,31 +145,46 @@ The identity and identity providers will look different for you.
123145
Now let's see the actual data that was signed:
124146

125147
```shell
126-
$ model=path/to/model/
127-
$ jq -r '.dsseEnvelope.payload' <"${model}"model.sig | base64 -d | jq
148+
$ jq -r '.dsseEnvelope.payload' <"${model_path}/model.sig" | base64 -d | jq
128149
[...]
129150
"files": [
130151
{
131-
"path": "file1",
152+
"path": "fingerprint.pb",
153+
"digest": {
154+
"sha256-p1": "6c6b3dab5e529ac434f5640dc0c2593eff1569a2b87238cd7fc35181f42b1cbf"
155+
}
156+
},
157+
{
158+
"path": "saved_model.pb",
159+
"digest": {
160+
"sha256-p1": "ea9e0870b9a6911a3e2066cd91b7ea467c2c26248ee171c2f6c7c32f7c13c7fd"
161+
}
162+
},
163+
{
164+
"path": "variables/variables.data-00000-of-00001",
132165
"digest": {
133-
"sha256-p1": "219f53a60f342f50dbe0d826c11daa01d55fded4b508c7559952fdae38c0e835"
166+
"sha256-p1": "f4058fefc1932d7e6480087fb357b38dc935084494d81afeb50b02a54a80938b"
134167
}
135168
},
136169
{
137-
"path": "file2",
170+
"path": "variables/variables.index",
138171
"digest": {
139-
"sha256-p1": "7c006a42fcd3bfff91e279da0f467ecc7ba07027a8f208e9f5671f5e844bfd2c"
172+
"sha256-p1": "35a26c0124980180d0bd40cb883bce58b06d421ec1ed49be634d9a37bafbab6e"
140173
}
141174
}
142-
[...]
143175
]
176+
144177
```
145178

146-
You see a list of files present in the model, each with their path and digest. Notice the digest is of type `sha256-p1`. Model files can be several hundreds of gigabytes in size. So to speed up hash computation, each file is split into multiple chunks that are hashes separately. `p` stands for parallel, because multiple hashing routine work in parallel to compute a file digest.
179+
You see a list of files present in the model, each with their corresponding path and digest. Notice the digest is of type `sha256-p1`. Model files can be several hundreds of gigabytes in size. So to speed up hash computation, each file is split into multiple chunks that are hashes separately. `p` stands for "parallel", because multiple hashing routines work in parallel to compute a file digest.
147180

148181
### Future work
149182

150-
#### Support other protection types
183+
#### Sign on publication
184+
185+
Try signinng your models before uploading them to your favorite hub, [Huggingface](https://huggingface.co/), [Tensorflow hub](https://www.tensorflow.org/hub), [PyTorch hub](https://pytorch.org/hub/), etc.
186+
187+
#### Support workoad identities
151188

152189
Signing with Sigstore not only supports human identity (email addresses), but also workflow identity. For automated signing using a workload identity, the following platforms are currently supported, shown with their expected identities:
153190

@@ -158,6 +195,10 @@ Buildkite CI (`https://buildkite.com/ORGANIZATION_SLUG/PIPELINE_SLUG`)
158195

159196
Try that out and let us know how it goes!
160197

198+
#### Sign other data
199+
200+
You can use the same CLI / API to sign datasets, checkpoints, etc.
201+
161202
## Take the quizz!
162203

163204
After completing this activity, you should be able to answer the following questions:

slsa_for_models/tensorflow_cifar10.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def supported_models():
129129
'tensorflow_model.keras': lambda m, p: m.save(p, save_format='keras'),
130130
# TF SavedModel formats, full model and weights only
131131
# TODO: Re-enable support for these when SLSA supports directories
132-
# 'tensorflow_saved_model': lambda m, p: m.save(p, save_format='tf'),
132+
'tensorflow_saved_model': lambda m, p: tf.saved_model.save(m, p),
133133
# 'tensorflow_exported_model': lambda m, p: m.export(p),
134134
# Legacy HDFS format, full model and weights only
135135
'tensorflow_hdf5_model.h5': lambda m, p: m.save(p, save_format='h5'),

0 commit comments

Comments
 (0)