|
| 1 | +# Artifact Content Addressable Storage (CAS) Proxy |
| 2 | + |
| 3 | +The artifact proxy is a **Content Addressable Storage (CAS) Proxy** that sits in front of different storage backends. |
| 4 | + |
| 5 | +Clients such as the Chainloop Control Plane or the CLI can use this proxy to make sure that **immutable uploads are performed**. Files that later, on **can only be referenced by their content digest (sha256)**. |
| 6 | + |
| 7 | +NOTE: At the moment of this writing, only an [OCI](https://opencontainers.org/) storage backend is supported. In the future you should potentially expect Object Storage Support (i.e AWS s3) as well. |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +The project is a [Go](https://go.dev/) service that leverages [protocol buffers](https://github.com/protocolbuffers/protobuf) and [gRPC](https://grpc.io/) for its streaming API, [wire](https://github.com/google/wire/) for dependency injection and the [Kratos framework](https://github.com/go-kratos/kratos) for additional utilities such middlewares, configuration management or error handling. |
| 12 | + |
| 13 | +The proxy API implements [a bytestream](https://pkg.go.dev/google.golang.org/api/transport/bytestream) gRPC service. This enables an efficient, and modern, streaming API for chunk based operations on top of HTTP/2. |
| 14 | + |
| 15 | +Its structure contains the following top to down layers. |
| 16 | + |
| 17 | +- API definition layer `./api/`. proto definitions and generated code for the external gRPC API |
| 18 | +- Server layer `./internal/server`. Definition and registration of the HTTP and gRPC servers and middlewares. |
| 19 | +- Service layer `./internal/service`. Implementation of the protocol buffer services. |
| 20 | + |
| 21 | +## System Dependencies |
| 22 | + |
| 23 | +The CAS proxy **has only one running dependency**. A secret storage backend to retrieve the OCI repository credentials. Currently we support both [Hashicorp Vault](https://www.vaultproject.io/) and [AWS Secret Manager](https://aws.amazon.com/secrets-manager/). |
| 24 | + |
| 25 | +This secret backend is used to download OCI repository credentials (repository path + key pair) during upload/downloads. This makes the Artifact CAS multi-tenant by default since the destination OCI backend gets selected at runtime. |
| 26 | + |
| 27 | +## AuthN/AuthZ |
| 28 | + |
| 29 | +The Artifact CAS API expects each request to contain a [JSON Web Token](https://auth0.com/docs/secure/tokens/json-web-tokens) with references to a) what operation is this token allowed to do (Download, Upload) and b) a reference to where the CAS can find the OCI credentials. |
| 30 | + |
| 31 | +Currently, this token is generated by the Control Plane and used on demand. You can find the generator we use to craft those tokens [here](../../internal/robotaccount/cas/robotaccount.go). |
| 32 | + |
| 33 | +The token gets signed by the control plane with a private key and verified by the CAS with the previously configured public key. |
| 34 | + |
| 35 | +Note: there are plans to support [JWKS endpoints](https://auth0.com/docs/secure/tokens/json-web-tokens/json-web-key-sets) to enable easy rotation of credentials. |
| 36 | + |
| 37 | +## Runbook |
| 38 | + |
| 39 | +We leverage `make` for most development tasks. Run `make -C app/artifact-cas` to see a list of the available tasks. |
| 40 | + |
| 41 | +### Run the project in development |
| 42 | + |
| 43 | +Refer to [development guide](../../devel/README.md) for more information but in a nutshell. |
| 44 | + |
| 45 | +``` |
| 46 | +# Run external dependency (Vault for secret management) |
| 47 | +
|
| 48 | +docker compose -f devel/docker-compose.yml up |
| 49 | +
|
| 50 | +# Run the service |
| 51 | +make -C app/artifact-cas run |
| 52 | +``` |
| 53 | + |
| 54 | +Next, follow the steps that can be found [here](../../devel/README.md#4---using-the-cli-pointing-to-the-local-environment) to configure the CLI |
| 55 | + |
| 56 | +Once configured you can try to perform a file upload and download. |
| 57 | + |
| 58 | +```sh |
| 59 | +cd app/cli |
| 60 | +go run main.go --insecure artifact upload -f [FILE] # will return a sha256 digest |
| 61 | + |
| 62 | +# download |
| 63 | +go run main.go --insecure artifact download -d [sha256:...] |
| 64 | +``` |
| 65 | + |
| 66 | +### Run tests |
| 67 | + |
| 68 | +``` |
| 69 | +make test |
| 70 | +``` |
| 71 | + |
| 72 | +### Build binary |
| 73 | + |
| 74 | +``` |
| 75 | +make build |
| 76 | +``` |
| 77 | + |
| 78 | +### Generate API code from protocol buffer defintions (\*.proto) |
| 79 | + |
| 80 | +We leverage buf.io to lint and generate proto files. Make sure you [install buf](https://docs.buf.build/installation) first. Once done, generating the API code is as easy as executing |
| 81 | + |
| 82 | +``` |
| 83 | +make api |
| 84 | +``` |
| 85 | + |
| 86 | +### Update configuration schema |
| 87 | + |
| 88 | +The service runtime configuration is implemented by using [kratos built-in config module](https://go-kratos.dev/en/docs/component/config/). |
| 89 | + |
| 90 | +Meaning that the configuration schema is defined at `internal/conf/conf.proto`. |
| 91 | + |
| 92 | +To regenerate it run: |
| 93 | + |
| 94 | +``` |
| 95 | +make config |
| 96 | +``` |
| 97 | + |
| 98 | +### Update dependency injection |
| 99 | + |
| 100 | +In order to enforce inversion of control and prevent import cycles we use [wire](https://github.com/google/wire/) for dependency injection. |
| 101 | + |
| 102 | +Wire has a fairly steep learning curve, so we recommend taking a look [at their tutorial](https://github.com/google/wire/blob/main/_tutorial/README.md). In practice, in this project you will find a couple of wire_gen.go files (i.e `cmd/wire_gen.go`) and different provider defined. |
| 103 | + |
| 104 | +If you need to re-generate the injection code after a change just run `make generate` |
| 105 | + |
| 106 | +## Contribution guidelines |
| 107 | + |
| 108 | +Please make sure to review the [Contribution guidelines](../../CONTRIBUTING.md) and feel free to reach out if you have any questions! |
| 109 | + |
| 110 | +Welcome! |
0 commit comments