-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathcreate_layout.py
95 lines (90 loc) · 3.25 KB
/
create_layout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from in_toto.util import import_rsa_key_from_file
from in_toto.models.layout import Layout
from in_toto.models.metadata import Metablock
def main():
# Load Alice's private key to later sign the layout
key_alice = import_rsa_key_from_file("alice")
# Fetch and load Bob's and Carl's public keys
# to specify that they are authorized to perform certain step in the layout
key_bob = import_rsa_key_from_file("../functionary_bob/bob.pub")
key_carl = import_rsa_key_from_file("../functionary_carl/carl.pub")
layout = Layout.read({
"_type": "layout",
"keys": {
key_bob["keyid"]: key_bob,
key_carl["keyid"]: key_carl,
},
"steps": [{
"name": "clone",
"expected_materials": [],
"expected_products": [["CREATE", "demo-project/foo.py"], ["DISALLOW", "*"]],
"pubkeys": [key_bob["keyid"]],
"expected_command": [
"git",
"clone",
"https://github.com/in-toto/demo-project.git"
],
"threshold": 1,
},{
"name": "update-version",
"expected_materials": [["MATCH", "demo-project/*", "WITH", "PRODUCTS",
"FROM", "clone"], ["DISALLOW", "*"]],
"expected_products": [["ALLOW", "demo-project/foo.py"], ["DISALLOW", "*"]],
"pubkeys": [key_bob["keyid"]],
"expected_command": [],
"threshold": 1,
},{
"name": "package",
"expected_materials": [
["MATCH", "demo-project/*", "WITH", "PRODUCTS", "FROM",
"update-version"], ["DISALLOW", "*"],
],
"expected_products": [
["CREATE", "demo-project.tar.gz"], ["DISALLOW", "*"],
],
"pubkeys": [key_carl["keyid"]],
"expected_command": [
"tar",
"--exclude",
".git",
"-zcvf",
"demo-project.tar.gz",
"demo-project",
],
"threshold": 1,
}],
"inspect": [{
"name": "untar",
"expected_materials": [
["MATCH", "demo-project.tar.gz", "WITH", "PRODUCTS", "FROM", "package"],
# FIXME: If the routine running inspections would gather the
# materials/products to record from the rules we wouldn't have to
# ALLOW other files that we aren't interested in.
["ALLOW", ".keep"],
["ALLOW", "alice.pub"],
["ALLOW", "root.layout"],
["DISALLOW", "*"]
],
"expected_products": [
["MATCH", "demo-project/foo.py", "WITH", "PRODUCTS", "FROM", "update-version"],
# FIXME: See expected_materials above
["ALLOW", "demo-project/.git/*"],
["ALLOW", "demo-project.tar.gz"],
["ALLOW", ".keep"],
["ALLOW", "alice.pub"],
["ALLOW", "root.layout"],
["DISALLOW", "*"]
],
"run": [
"tar",
"xzf",
"demo-project.tar.gz",
]
}],
})
metadata = Metablock(signed=layout)
# Sign and dump layout to "root.layout"
metadata.sign(key_alice)
metadata.dump("root.layout")
if __name__ == '__main__':
main()