Skip to content

Commit bd104ca

Browse files
feat: add postgres db to store keys metadata (#24)
1 parent d5b380b commit bd104ca

26 files changed

+1027
-51
lines changed

.env-example renamed to .env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ CERBERUS_HOME=${HOME}/cerberus
22
CERBERUS_KEYSTORE_DIR=${CERBERUS_HOME}/data/keystore
33
CERBERUS_GRPC_PORT=50051
44
CERBERUS_METRICS_PORT=9081
5+
6+
DB_NAME=cerberus
7+
DB_USER=postgres
8+
DB_PASSWORD=postgres
9+
DB_PORT=5432

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
.env
1+
**/.env
22
data/
33
bin/

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ tests: ## runs all tests
3636
.PHONY: docker
3737
docker: ## runs docker build
3838
docker build -t $(APP_NAME):latest .
39+
40+
.PHONY: migrate
41+
migrate: ## runs database migrations
42+
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
43+
migrate -path internal/database/migrations/ -database "postgres://user:password@localhost:5432/cerberus?sslmode=disable" --verbose up

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Remote Signer Implementation of cerberus-api
22
This is a remote signer which supports BLS signatures on the BN254 curve.
33

4+
## Disclaimer
5+
🚧 Cerberus is under active development and has not been audited. Cerberus is rapidly being upgraded, features may be added, removed or otherwise improved or modified and interfaces will have breaking changes. Cerberus should be used only for testing purposes and not in production. Cerberus is provided "as is" and Eigen Labs, Inc. does not guarantee its functionality or provide support for its use in production. 🚧
6+
47
<!-- TOC -->
58
* [Remote Signer Implementation of cerberus-api](#remote-signer-implementation-of-cerberus-api)
69
* [Installation](#installation)
@@ -62,19 +65,21 @@ GLOBAL OPTIONS:
6265
--aws-profile value AWS profile (default: "default") [$AWS_PROFILE]
6366
--aws-region value AWS region (default: "us-east-2") [$AWS_REGION]
6467
--aws-secret-access-key value AWS secret access key [$AWS_SECRET_ACCESS_KEY]
68+
--gcp-project-id value Project ID for Google Cloud Platform [$GCP_PROJECT_ID]
6569
--grpc-port value Port for the gRPC server (default: "50051") [$GRPC_PORT]
6670
--keystore-dir value Directory where the keystore files are stored (default: "./data/keystore") [$KEYSTORE_DIR]
6771
--log-format value Log format - supported formats: text, json (default: "text") [$LOG_FORMAT]
6872
--log-level value Log level - supported levels: debug, info, warn, error (default: "info") [$LOG_LEVEL]
6973
--metrics-port value Port for the metrics server (default: "9091") [$METRICS_PORT]
74+
--postgres-database-url value Postgres database URL (default: "postgres://user:password@localhost:5432/cerberus?sslmode=disable") [$POSTGRES_DATABASE_URL]
7075
--storage-type value Storage type - supported types: filesystem, aws-secret-manager (default: "filesystem") [$STORAGE_TYPE]
7176
--tls-ca-cert value TLS CA certificate [$TLS_CA_CERT]
7277
--tls-server-key value TLS server key [$TLS_SERVER_KEY]
7378
--help, -h show help
7479
--version, -v print the version
7580
7681
COPYRIGHT:
77-
(c) 2024 EigenLab
82+
(c) 2025 EigenLabs
7883
```
7984
8085
### Storage Backend

cmd/cerberus/main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log/slog"
66
"os"
77
"sort"
8+
"time"
89

910
"github.com/Layr-Labs/cerberus/internal/configuration"
1011
"github.com/Layr-Labs/cerberus/internal/server"
@@ -108,6 +109,13 @@ var (
108109
Usage: "Project ID for Google Cloud Platform",
109110
EnvVars: []string{"GCP_PROJECT_ID"},
110111
}
112+
113+
postgresDatabaseURLFlag = &cli.StringFlag{
114+
Name: "postgres-database-url",
115+
Usage: "Postgres database URL",
116+
Value: "postgres://user:password@localhost:5432/cerberus?sslmode=disable",
117+
EnvVars: []string{"POSTGRES_DATABASE_URL"},
118+
}
111119
)
112120

113121
func main() {
@@ -126,7 +134,7 @@ func main() {
126134
app.Name = "cerberus"
127135
app.Usage = "Remote BLS Signer"
128136
app.Version = version
129-
app.Copyright = "(c) 2024 EigenLabs"
137+
app.Copyright = fmt.Sprintf("(c) %d Eigen Labs", time.Now().Year())
130138

131139
app.Flags = []cli.Flag{
132140
keystoreDirFlag,
@@ -143,6 +151,7 @@ func main() {
143151
awsAccessKeyIDFlag,
144152
awsSecretAccessKeyFlag,
145153
gcpProjectIDFlag,
154+
postgresDatabaseURLFlag,
146155
}
147156
sort.Sort(cli.FlagsByName(app.Flags))
148157

@@ -172,7 +181,7 @@ func start(c *cli.Context) error {
172181
awsAccessKeyID := c.String(awsAccessKeyIDFlag.Name)
173182
awsSecretAccessKey := c.String(awsSecretAccessKeyFlag.Name)
174183
gcpProjectID := c.String(gcpProjectIDFlag.Name)
175-
184+
postgresDatabaseURL := c.String(postgresDatabaseURLFlag.Name)
176185
cfg := &configuration.Configuration{
177186
KeystoreDir: keystoreDir,
178187
GrpcPort: grpcPort,
@@ -186,6 +195,7 @@ func start(c *cli.Context) error {
186195
AWSAccessKeyID: awsAccessKeyID,
187196
AWSSecretAccessKey: awsSecretAccessKey,
188197
GCPProjectID: gcpProjectID,
198+
PostgresDatabaseURL: postgresDatabaseURL,
189199
}
190200

191201
if err := cfg.Validate(); err != nil {

docker-compose.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '3.8'
21
services:
32
cerberus:
43
image: ghcr.io/layr-labs/cerberus:latest
@@ -9,8 +8,29 @@ services:
98
environment:
109
- "KEYSTORE_DIR=/keystore"
1110
- "METRICS_PORT=${CERBERUS_METRICS_PORT}"
11+
- "POSTGRES_DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:5432/${DB_NAME}?sslmode=disable"
1212
volumes:
1313
- "${CERBERUS_KEYSTORE_DIR}:/keystore"
1414
env_file:
1515
- .env
1616
restart: unless-stopped
17+
depends_on:
18+
- db
19+
20+
db:
21+
image: postgres:15
22+
container_name: db
23+
ports:
24+
- "${DB_PORT}:${DB_PORT}"
25+
environment:
26+
- "POSTGRES_PASSWORD=${DB_PASSWORD}"
27+
- "POSTGRES_USER=${DB_USER}"
28+
- "POSTGRES_DB=${DB_NAME}"
29+
volumes:
30+
- postgres_data:/var/lib/postgresql/data
31+
env_file:
32+
- .env
33+
restart: unless-stopped
34+
35+
volumes:
36+
postgres_data:

go.mod

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,68 @@
11
module github.com/Layr-Labs/cerberus
22

3-
go 1.21
3+
go 1.22.0
44

5-
toolchain go1.21.11
5+
toolchain go1.22.3
66

77
require (
88
cloud.google.com/go/secretmanager v1.14.2
9-
github.com/Layr-Labs/bn254-keystore-go v0.0.0-20241118175331-3ceaf682f032
10-
github.com/Layr-Labs/cerberus-api v0.0.1
9+
github.com/Layr-Labs/bn254-keystore-go v0.0.0-20250107020618-26bd412fae87
10+
github.com/Layr-Labs/cerberus-api v0.0.2-0.20250107174124-05df6050f723
1111
github.com/aws/aws-sdk-go-v2 v1.32.5
1212
github.com/aws/aws-sdk-go-v2/config v1.28.5
1313
github.com/aws/aws-sdk-go-v2/credentials v1.17.46
1414
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.34.6
1515
github.com/consensys/gnark-crypto v0.12.1
16+
github.com/golang-migrate/migrate/v4 v4.18.1
1617
github.com/prometheus/client_golang v1.20.3
1718
github.com/stretchr/testify v1.10.0
19+
github.com/testcontainers/testcontainers-go v0.34.0
1820
github.com/urfave/cli/v2 v2.27.5
1921
google.golang.org/api v0.203.0
2022
google.golang.org/grpc v1.67.1
2123
)
2224

25+
require (
26+
dario.cat/mergo v1.0.0 // indirect
27+
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
28+
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
29+
github.com/Microsoft/go-winio v0.6.2 // indirect
30+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
31+
github.com/containerd/log v0.1.0 // indirect
32+
github.com/containerd/platforms v0.2.1 // indirect
33+
github.com/cpuguy83/dockercfg v0.3.2 // indirect
34+
github.com/distribution/reference v0.6.0 // indirect
35+
github.com/docker/docker v27.2.0+incompatible // indirect
36+
github.com/docker/go-connections v0.5.0 // indirect
37+
github.com/docker/go-units v0.5.0 // indirect
38+
github.com/go-ole/go-ole v1.2.6 // indirect
39+
github.com/gogo/protobuf v1.3.2 // indirect
40+
github.com/google/uuid v1.6.0 // indirect
41+
github.com/hashicorp/errwrap v1.1.0 // indirect
42+
github.com/hashicorp/go-multierror v1.1.1 // indirect
43+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
44+
github.com/magiconair/properties v1.8.7 // indirect
45+
github.com/moby/docker-image-spec v1.3.1 // indirect
46+
github.com/moby/patternmatcher v0.6.0 // indirect
47+
github.com/moby/sys/sequential v0.5.0 // indirect
48+
github.com/moby/sys/user v0.1.0 // indirect
49+
github.com/moby/sys/userns v0.1.0 // indirect
50+
github.com/moby/term v0.5.0 // indirect
51+
github.com/morikuni/aec v1.0.0 // indirect
52+
github.com/opencontainers/go-digest v1.0.0 // indirect
53+
github.com/opencontainers/image-spec v1.1.0 // indirect
54+
github.com/pkg/errors v0.9.1 // indirect
55+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
56+
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
57+
github.com/shoenig/go-m1cpu v0.1.6 // indirect
58+
github.com/sirupsen/logrus v1.9.3 // indirect
59+
github.com/tklauser/go-sysconf v0.3.12 // indirect
60+
github.com/tklauser/numcpus v0.6.1 // indirect
61+
github.com/yusufpapurcu/wmi v1.2.3 // indirect
62+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect
63+
go.uber.org/atomic v1.7.0 // indirect
64+
)
65+
2366
require (
2467
cloud.google.com/go/auth v0.9.9 // indirect
2568
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
@@ -50,6 +93,7 @@ require (
5093
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
5194
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
5295
github.com/klauspost/compress v1.17.9 // indirect
96+
github.com/lib/pq v1.10.9
5397
github.com/mmcloughlin/addchain v0.4.0 // indirect
5498
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
5599
github.com/pmezard/go-difflib v1.0.0 // indirect

0 commit comments

Comments
 (0)