| 1 | # Go implementation of in-toto |
| 2 | [](https://github.com/in-toto/in-toto-golang/actions?query=workflow%3Abuild) [](https://coveralls.io/github/in-toto/in-toto-golang) [](https://pkg.go.dev/github.com/in-toto/in-toto-golang) [](https://goreportcard.com/report/github.com/in-toto/in-toto-golang) |
| 3 | [](https://api.securityscorecards.dev/projects/github.com/in-toto/in-toto-golang) |
| 4 | |
| 5 | Go implementation of the |
| 6 | [in-toto specification](https://github.com/in-toto/docs/blob/master/in-toto-spec.md). |
| 7 | |
| 8 | ## Docs |
| 9 | |
| 10 | To read the documentation along with some examples, run: |
| 11 | |
| 12 | ```bash |
| 13 | godoc -http :8080 |
| 14 | ``` |
| 15 | |
| 16 | and navigate to `localhost:8080/pkg/github.com/in-toto/in-toto-golang/` |
| 17 | |
| 18 | Alternatively, you can use [pkg.go.dev](https://pkg.go.dev/github.com/in-toto/in-toto-golang). |
| 19 | |
| 20 | ## Example |
| 21 | |
| 22 | A very simple example, just to help you starting: |
| 23 | |
| 24 | ```go |
| 25 | package main |
| 26 | |
| 27 | import ( |
| 28 | "time" |
| 29 | toto "github.com/in-toto/in-toto-golang/in_toto" |
| 30 | ) |
| 31 | |
| 32 | func main() { |
| 33 | t := time.Now() |
| 34 | t = t.Add(30 * 24 * time.Hour) |
| 35 | |
| 36 | var keys = make(map[string]toto.Key) |
| 37 | |
| 38 | var metablock = toto.Metablock{ |
| 39 | Signed: toto.Layout{ |
| 40 | Type: "layout", |
| 41 | Expires: t.Format("2006-01-02T15:04:05Z"), |
| 42 | Steps: []toto.Step{}, |
| 43 | Inspect: []toto.Inspection{}, |
| 44 | Keys: keys, |
| 45 | }, |
| 46 | } |
| 47 | |
| 48 | var key toto.Key |
| 49 | |
| 50 | key.LoadKey("keys/alice", "rsassa-pss-sha256", []string{"sha256", "sha512"}) |
| 51 | |
| 52 | metablock.Sign(key) |
| 53 | |
| 54 | metablock.Dump("root.layout") |
| 55 | } |
| 56 | ``` |
| 57 | |
| 58 | ## Building |
| 59 | |
| 60 | Download the source, run `make build`. |
| 61 | |
| 62 | ## CLI |
| 63 | |
| 64 | The CLI reference can be found in the autogenerated [docs](doc/in-toto.md). |
| 65 | |
| 66 | ## Integration with SPIFFE/SPIRE |
| 67 | |
| 68 | This implementation of in-toto has been integrated with SPIFFE/SPIRE. The |
| 69 | integration is made possible by |
| 70 | [ITE-7](https://github.com/in-toto/ITE/blob/master/ITE/7/README.adoc), an |
| 71 | enhancement that adds support for X.509 signing to in-toto. |
| 72 | |
| 73 | ### Running the Demo |
| 74 | |
| 75 | To run the demo, pull down the source code, install Go, and run |
| 76 | `make test-verify`. This will use openssl to generate a certificate chain. |
| 77 | |
| 78 | To run the demo using SPIRE, pull down the source code, install Go and Docker, |
| 79 | and run `make test-spiffe-verify`. |
| 80 | |
| 81 | SPIFFE compliant Leaf certificates are generated with SVIDs corresponding to |
| 82 | functionaries. These certificates are consumed by in-toto to sign link metadata |
| 83 | and the layout policy. |
| 84 | |
| 85 | During the in-toto verification process, certificate constraints are checked to |
| 86 | ensure the build step link meta-data was signed with the correct SVID. |
| 87 | |
| 88 | ### Layout Certificate Constraints |
| 89 | |
| 90 | Currently the following constraints supported: |
| 91 | |
| 92 | ```json |
| 93 | { |
| 94 | "cert_constraints": [{ |
| 95 | "common_name": "write-code.example.com", |
| 96 | "dns_names": [ |
| 97 | "" |
| 98 | ], |
| 99 | "emails": [ |
| 100 | "" |
| 101 | ], |
| 102 | "organizations": [ |
| 103 | "*" |
| 104 | ], |
| 105 | "roots": [ |
| 106 | "*" |
| 107 | ], |
| 108 | "uris": [ |
| 109 | "spiffe://example.com/write-code" |
| 110 | ] |
| 111 | }, { |
| 112 | "uris": [], |
| 113 | "common_names": ["Some User"] |
| 114 | }] |
| 115 | } |
| 116 | ``` |
| 117 | |
| 118 | ## Not (yet) supported |
| 119 | |
| 120 | This golang implementation was focused on verification on admission controllers |
| 121 | and kubectl plugins. As such, it focused on providing a strong, auditable set |
| 122 | of core functions rather than a broad and (possibly) unstable feature set. In |
| 123 | other words, we believe that the current feature set is stable enough for |
| 124 | production use. |
| 125 | |
| 126 | If any of these features are necessary for your use case please let us know and |
| 127 | we will try to provide them as soon as possible. Alternatively we welcome pull |
| 128 | requests with feature additions! |
| 129 | |
| 130 | * [GPG keys](https://github.com/in-toto/in-toto-golang/issues/26) |