marble

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 18 Imported by: 0

README

Marble SDK Wrapper

This package is a thin SDK that wraps MarbleRun primitives for services:

  • Loads Coordinator-injected TLS certs/CA and builds an mTLS HTTP client for cross-marble traffic.
  • Exposes injected secrets via Marble.Secret/UseSecret.
  • Surfaces TEE identity (report, UUID, marble type) to services.

We keep this layer even though MarbleRun is used because it provides:

  1. A stable Go API inside services (tests and simulation can mock it).
  2. A single place to translate environment injection (MARBLE_CERT, MARBLE_KEY, MARBLE_ROOT_CA, MARBLE_SECRETS, MARBLE_UUID) into usable clients/configs.
  3. Enforcement of the official cross-marble communication path (mTLS via Marble.HTTPClient), rather than ad-hoc HTTP clients.

Components

Marble (marble.go)

Core Marble type for TEE service configuration.

m, err := marble.New(marble.Config{
    MarbleType: "neocompute",
})
Service (service.go)

Low-level service base (identity + router + dependency holders).

Most services should embed infrastructure/service.BaseService, which wraps *marble.Service and adds:

  • Lifecycle hooks (Start/Stop) with safe shutdown handling
  • Background worker registration helpers
  • Standard endpoints (/health, /ready, /info)
base := commonservice.NewBase(&commonservice.BaseConfig{
    ID:      "myservice",
    Name:    "My Service",
    Version: "1.0.0",
    Marble:  cfg.Marble,
    DB:      cfg.DB,
})

base.RegisterStandardRoutes()

Secret Management

Secrets are injected by MarbleRun Coordinator and accessed via the Marble instance:

// Get secret (returns false if not found)
secret, ok := m.Secret("COMPUTE_MASTER_KEY")
if !ok {
    return errors.New("COMPUTE_MASTER_KEY not configured")
}
defer crypto.ZeroBytes(secret) // Always zero secrets after use
Available Secrets
Secret Service Description
NEOFEEDS_SIGNING_KEY Datafeed ECDSA private key for signing prices
NEOVRF_SIGNING_KEY NeoVRF Master key for VRF signing (>= 32 bytes)
COMPUTE_MASTER_KEY Confidential Compute Master key for encryption/signing (>= 32 bytes)
POOL_MASTER_KEY AccountPool HD derivation master key (>= 32 bytes)
POOL_MASTER_KEY_HASH AccountPool SHA-256 hash of derived master pubkey (32 bytes; required in enclave mode)
POOL_MASTER_ATTESTATION_HASH AccountPool Optional attestation/bundle hash (for on-chain anchoring)
GLOBALSIGNER_MASTER_SEED GlobalSigner 32-byte master seed for deterministic key derivation
SECRETS_MASTER_KEY Edge + Services AES-256 master key for user secrets (32 bytes; same envelope across Edge + TEE)

mTLS Communication

For secure inter-service communication within the MarbleRun mesh:

// Get mTLS HTTP client
httpClient := m.HTTPClient()

// Make request to another marble
resp, err := httpClient.Get("https://neoaccounts:8085/info")
External Gateways (Supabase Edge)

By default, enclave services only accept client certificates signed by the MarbleRun root CA (MARBLE_ROOT_CA). To support external gateways that must connect via mTLS (e.g. Supabase Edge Functions), you can append additional PEM roots to the server-side client CA pool by setting:

  • MARBLE_EXTRA_CLIENT_CA (PEM)

This affects inbound mTLS verification (tls.Config.ClientCAs) and does not change the trust roots used for outbound mesh calls.

External HTTP Calls

For outbound calls to non-mesh endpoints (Supabase, Neo RPC, third-party APIs), use:

httpClient := m.ExternalHTTPClient()
resp, err := httpClient.Get("https://api.coingecko.com/api/v3/ping")

Service Lifecycle

// Service lifecycle and workers are provided by `infrastructure/service.BaseService`.

// Get service info
id := svc.ID()
name := svc.Name()
version := svc.Version()

// Get HTTP router
router := svc.Router()

// Get database repository
db := svc.DB()

Testing

For testing without actual MarbleRun:

m, _ := marble.New(marble.Config{MarbleType: "test"})

// Set test secrets
m.SetTestSecret("MY_SECRET", []byte("test-value"))
go test ./infrastructure/marble/... -v

Current test coverage: 43.8%

Environment Variables

Variable Description
MARBLE_TYPE Service type identifier
MARBLE_CERT TLS certificate (injected)
MARBLE_KEY TLS private key (injected)
MARBLE_ROOT_CA Root CA certificate (injected)
MARBLE_EXTRA_CLIENT_CA Optional extra client CA PEMs (inbound mTLS)
MARBLE_SECRETS JSON-encoded secrets (injected)
MARBLE_UUID Unique marble instance ID

Documentation

Overview

Package marble provides attestation utilities for TEE services.

Package marble provides the core Marble SDK for MarbleRun integration. Each service runs as a Marble inside an EGo SGX enclave.

Package marble provides the service framework for MarbleRun Marbles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeAttestationHash

func ComputeAttestationHash(m *Marble, serviceID string) []byte

ComputeAttestationHash computes a SHA-256 hash for attestation purposes. It tries multiple sources in order: report, MARBLE_CERT, marble type/UUID. The serviceID is used as a fallback identifier when no other source is available.

Types

type Config

type Config struct {
	MarbleType string
	DNSNames   []string
}

Config holds Marble configuration.

type Marble

type Marble struct {
	// contains filtered or unexported fields
}

Marble represents a MarbleRun Marble instance. It handles attestation, secrets injection, and secure communication.

func New

func New(cfg Config) (*Marble, error)

New creates a new Marble instance.

func (*Marble) ExternalHTTPClient

func (m *Marble) ExternalHTTPClient() *http.Client

ExternalHTTPClient returns an HTTP client suitable for outbound calls to non-Marblerun endpoints (Supabase, Neo RPC, third-party APIs).

It never installs the MarbleRun root CA or client certificate, ensuring the connection uses the system trust store and does not attempt mTLS.

func (*Marble) HTTPClient

func (m *Marble) HTTPClient() *http.Client

HTTPClient returns an HTTP client configured for mTLS.

func (*Marble) Initialize

func (m *Marble) Initialize(ctx context.Context) error

Initialize performs Marble initialization with the Coordinator. This is called automatically by MarbleRun before the application starts.

func (*Marble) IsEnclave

func (m *Marble) IsEnclave() bool

IsEnclave returns true if running inside an SGX enclave.

func (*Marble) MarbleType

func (m *Marble) MarbleType() string

MarbleType returns the Marble type.

func (*Marble) Report

func (m *Marble) Report() *attestation.Report

Report returns the enclave self-report.

func (*Marble) Secret

func (m *Marble) Secret(name string) ([]byte, bool)

Secret returns a secret by name.

func (*Marble) SetTestReport

func (m *Marble) SetTestReport(report *attestation.Report)

SetTestReport sets an enclave report for testing purposes only. This method should only be used in tests.

func (*Marble) SetTestSecret

func (m *Marble) SetTestSecret(name string, value []byte)

SetTestSecret sets a secret for testing purposes only. This method should only be used in tests.

func (*Marble) TLSConfig

func (m *Marble) TLSConfig() *tls.Config

TLSConfig returns the TLS configuration for secure communication.

func (*Marble) UUID

func (m *Marble) UUID() string

UUID returns the Marble's unique identifier.

func (*Marble) UseSecret

func (m *Marble) UseSecret(name string, fn func([]byte) error) error

UseSecret provides secure access to a secret via callback. The secret is zeroed after the callback returns.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is a minimal base for Marble-hosted services.

Prefer embedding `infrastructure/service.BaseService` in actual services; it wraps this type and provides lifecycle hooks, workers, and standard routes.

func NewService

func NewService(cfg ServiceConfig) *Service

NewService creates a new base service.

func (*Service) DB

DB returns the database repository.

func (*Service) ID

func (s *Service) ID() string

ID returns the service ID.

func (*Service) IsRunning

func (s *Service) IsRunning() bool

IsRunning returns true if the service is running.

func (*Service) Marble

func (s *Service) Marble() *Marble

Marble returns the Marble instance.

func (*Service) Name

func (s *Service) Name() string

Name returns the service name.

func (*Service) Router

func (s *Service) Router() *mux.Router

Router returns the HTTP router.

func (*Service) Start

func (s *Service) Start(ctx context.Context) error

Start starts the service.

func (*Service) Stop

func (s *Service) Stop() error

Stop stops the service.

func (*Service) Version

func (s *Service) Version() string

Version returns the service version.

type ServiceConfig

type ServiceConfig struct {
	ID      string
	Name    string
	Version string
	Marble  *Marble
	DB      database.RepositoryInterface
}

ServiceConfig holds service configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL