Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add postgres db to store keys metadata #24

Merged
merged 8 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env-example → .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ CERBERUS_HOME=${HOME}/cerberus
CERBERUS_KEYSTORE_DIR=${CERBERUS_HOME}/data/keystore
CERBERUS_GRPC_PORT=50051
CERBERUS_METRICS_PORT=9081

DB_NAME=cerberus
DB_USER=postgres
DB_PASSWORD=postgres
DB_PORT=5432
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.env
**/.env
data/
bin/
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ tests: ## runs all tests
.PHONY: docker
docker: ## runs docker build
docker build -t $(APP_NAME):latest .

.PHONY: migrate
migrate: ## runs database migrations
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
migrate -path internal/database/migrations/ -database "postgres://user:password@localhost:5432/cerberus?sslmode=disable" --verbose up
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Remote Signer Implementation of cerberus-api
This is a remote signer which supports BLS signatures on the BN254 curve.

## Disclaimer
🚧 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. 🚧

<!-- TOC -->
* [Remote Signer Implementation of cerberus-api](#remote-signer-implementation-of-cerberus-api)
* [Installation](#installation)
Expand Down Expand Up @@ -62,19 +65,21 @@ GLOBAL OPTIONS:
--aws-profile value AWS profile (default: "default") [$AWS_PROFILE]
--aws-region value AWS region (default: "us-east-2") [$AWS_REGION]
--aws-secret-access-key value AWS secret access key [$AWS_SECRET_ACCESS_KEY]
--gcp-project-id value Project ID for Google Cloud Platform [$GCP_PROJECT_ID]
--grpc-port value Port for the gRPC server (default: "50051") [$GRPC_PORT]
--keystore-dir value Directory where the keystore files are stored (default: "./data/keystore") [$KEYSTORE_DIR]
--log-format value Log format - supported formats: text, json (default: "text") [$LOG_FORMAT]
--log-level value Log level - supported levels: debug, info, warn, error (default: "info") [$LOG_LEVEL]
--metrics-port value Port for the metrics server (default: "9091") [$METRICS_PORT]
--postgres-database-url value Postgres database URL (default: "postgres://user:password@localhost:5432/cerberus?sslmode=disable") [$POSTGRES_DATABASE_URL]
--storage-type value Storage type - supported types: filesystem, aws-secret-manager (default: "filesystem") [$STORAGE_TYPE]
--tls-ca-cert value TLS CA certificate [$TLS_CA_CERT]
--tls-server-key value TLS server key [$TLS_SERVER_KEY]
--help, -h show help
--version, -v print the version

COPYRIGHT:
(c) 2024 EigenLab
(c) 2025 EigenLabs
```

### Storage Backend
Expand Down
14 changes: 12 additions & 2 deletions cmd/cerberus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log/slog"
"os"
"sort"
"time"

"github.com/Layr-Labs/cerberus/internal/configuration"
"github.com/Layr-Labs/cerberus/internal/server"
Expand Down Expand Up @@ -108,6 +109,13 @@ var (
Usage: "Project ID for Google Cloud Platform",
EnvVars: []string{"GCP_PROJECT_ID"},
}

postgresDatabaseURLFlag = &cli.StringFlag{
Name: "postgres-database-url",
Usage: "Postgres database URL",
Value: "postgres://user:password@localhost:5432/cerberus?sslmode=disable",
EnvVars: []string{"POSTGRES_DATABASE_URL"},
}
)

func main() {
Expand All @@ -126,7 +134,7 @@ func main() {
app.Name = "cerberus"
app.Usage = "Remote BLS Signer"
app.Version = version
app.Copyright = "(c) 2024 EigenLabs"
app.Copyright = fmt.Sprintf("(c) %d Eigen Labs", time.Now().Year())
shrimalmadhur marked this conversation as resolved.
Show resolved Hide resolved

app.Flags = []cli.Flag{
keystoreDirFlag,
Expand All @@ -143,6 +151,7 @@ func main() {
awsAccessKeyIDFlag,
awsSecretAccessKeyFlag,
gcpProjectIDFlag,
postgresDatabaseURLFlag,
}
sort.Sort(cli.FlagsByName(app.Flags))

Expand Down Expand Up @@ -172,7 +181,7 @@ func start(c *cli.Context) error {
awsAccessKeyID := c.String(awsAccessKeyIDFlag.Name)
awsSecretAccessKey := c.String(awsSecretAccessKeyFlag.Name)
gcpProjectID := c.String(gcpProjectIDFlag.Name)

postgresDatabaseURL := c.String(postgresDatabaseURLFlag.Name)
cfg := &configuration.Configuration{
KeystoreDir: keystoreDir,
GrpcPort: grpcPort,
Expand All @@ -186,6 +195,7 @@ func start(c *cli.Context) error {
AWSAccessKeyID: awsAccessKeyID,
AWSSecretAccessKey: awsSecretAccessKey,
GCPProjectID: gcpProjectID,
PostgresDatabaseURL: postgresDatabaseURL,
}

if err := cfg.Validate(); err != nil {
Expand Down
22 changes: 21 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.8'
services:
cerberus:
image: ghcr.io/layr-labs/cerberus:latest
Expand All @@ -9,8 +8,29 @@ services:
environment:
- "KEYSTORE_DIR=/keystore"
- "METRICS_PORT=${CERBERUS_METRICS_PORT}"
- "POSTGRES_DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:5432/${DB_NAME}?sslmode=disable"
volumes:
- "${CERBERUS_KEYSTORE_DIR}:/keystore"
env_file:
- .env
restart: unless-stopped
depends_on:
- db

db:
image: postgres:15
container_name: db
ports:
- "${DB_PORT}:${DB_PORT}"
environment:
- "POSTGRES_PASSWORD=${DB_PASSWORD}"
- "POSTGRES_USER=${DB_USER}"
- "POSTGRES_DB=${DB_NAME}"
volumes:
- postgres_data:/var/lib/postgresql/data
env_file:
- .env
restart: unless-stopped

volumes:
postgres_data:
52 changes: 48 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,25 +1,68 @@
module github.com/Layr-Labs/cerberus

go 1.21
go 1.22.0

toolchain go1.21.11
toolchain go1.22.3

require (
cloud.google.com/go/secretmanager v1.14.2
github.com/Layr-Labs/bn254-keystore-go v0.0.0-20241118175331-3ceaf682f032
github.com/Layr-Labs/cerberus-api v0.0.1
github.com/Layr-Labs/bn254-keystore-go v0.0.0-20250107020618-26bd412fae87
github.com/Layr-Labs/cerberus-api v0.0.2-0.20250107174124-05df6050f723
github.com/aws/aws-sdk-go-v2 v1.32.5
github.com/aws/aws-sdk-go-v2/config v1.28.5
github.com/aws/aws-sdk-go-v2/credentials v1.17.46
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.34.6
github.com/consensys/gnark-crypto v0.12.1
github.com/golang-migrate/migrate/v4 v4.18.1
github.com/prometheus/client_golang v1.20.3
github.com/stretchr/testify v1.10.0
github.com/testcontainers/testcontainers-go v0.34.0
github.com/urfave/cli/v2 v2.27.5
google.golang.org/api v0.203.0
google.golang.org/grpc v1.67.1
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v27.2.0+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
)

require (
cloud.google.com/go/auth v0.9.9 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
Expand Down Expand Up @@ -50,6 +93,7 @@ require (
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/lib/pq v1.10.9
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
Loading
Loading