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

multi: add CLI flag to enable public access to uni proof courier RPCs #499

Merged
merged 2 commits into from
Sep 20, 2023
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
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type RPCConfig struct {

MacaroonPath string

AllowPublicUniProofCourier bool

AllowPublicStats bool

LetsEncryptDir string
Expand Down Expand Up @@ -81,8 +83,6 @@ type Config struct {
// connecting to itself as a federation member.
RuntimeID int64

AcceptRemoteUniverseProofs bool

// TODO(roasbeef): use the Taproot Asset chain param wrapper here?
ChainParams chaincfg.Params

Expand Down
4 changes: 3 additions & 1 deletion itest/tapd_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
tapCfg.TapdDir = cfg.BaseDir
tapCfg.DebugLevel = *logLevel

tapCfg.Universe.AcceptRemoteProofs = true
// Enable universe proof courier RPC endpoints. These endpoints are
// also used within some tests for transferring proofs.
tapCfg.RpcConf.AllowPublicUniProofCourier = true

// Decide which DB backend to use.
switch *dbbackend {
Expand Down
13 changes: 10 additions & 3 deletions perms/perms.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,28 @@ var (
"/universerpc.Universe/QueryAssetRoots": {},
"/universerpc.Universe/AssetLeafKeys": {},
"/universerpc.Universe/AssetLeaves": {},
"/universerpc.Universe/QueryProof": {},
"/universerpc.Universe/InsertProof": {},
"/universerpc.Universe/Info": {},
}
)

// MacaroonWhitelist returns the set of RPC endpoints that don't require
// macaroon authentication.
func MacaroonWhitelist(allowPublicStats bool) map[string]struct{} {
func MacaroonWhitelist(allowPublicUniProofCourier bool,
allowPublicStats bool) map[string]struct{} {

// Make a copy of the default whitelist.
whitelist := make(map[string]struct{})
for k, v := range defaultMacaroonWhitelist {
whitelist[k] = v
}

// Conditionally add public multiverse proof courier RPC endpoints to
// the whitelist.
if allowPublicUniProofCourier {
whitelist["/universerpc.Universe/QueryProof"] = struct{}{}
whitelist["/universerpc.Universe/InsertProof"] = struct{}{}
}

// Conditionally add public stats RPC endpoints to the whitelist.
if allowPublicStats {
whitelist["/universerpc.Universe/QueryAssetStats"] = struct{}{}
Expand Down
4 changes: 0 additions & 4 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2921,10 +2921,6 @@ func (r *rpcServer) InsertProof(ctx context.Context,
return nil, fmt.Errorf("key cannot be nil")
}

if !r.cfg.AcceptRemoteUniverseProofs {
return nil, fmt.Errorf("remote proofs not accepted")
}

universeID, err := unmarshalUniID(req.Key.Id)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ func (s *Server) RunUntilShutdown(mainErrChan <-chan error) error {

// Get RPC endpoints which don't require macaroons.
macaroonWhitelist := perms.MacaroonWhitelist(
s.cfg.RPCConfig.AllowPublicUniProofCourier,
s.cfg.RPCConfig.AllowPublicStats,
)

Expand Down
8 changes: 3 additions & 5 deletions tapcfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ const (
defaultMaxLogFiles = 3
defaultMaxLogFileSize = 10

defaultAcceptRemoteProofs = false

defaultTestnetFederationServer = "testnet.universe.lightning.finance:10029"

// DefaultAutogenValidity is the default validity of a self-signed
Expand Down Expand Up @@ -204,7 +202,8 @@ type RpcConfig struct {
MacaroonPath string `long:"macaroonpath" description:"Path to write the admin macaroon for tapd's RPC and REST services if it doesn't exist"`
NoMacaroons bool `long:"no-macaroons" description:"Disable macaroon authentication, can only be used if server is not listening on a public interface."`

AllowPublicStats bool `long:"allow-public-stats" description:"Disable macaroon authentication for stats RPC endpoints."`
AllowPublicUniProofCourier bool `long:"allow-public-uni-proof-courier" description:"Disable macaroon authentication for universe proof courier RPC endpoints."`
AllowPublicStats bool `long:"allow-public-stats" description:"Disable macaroon authentication for stats RPC endpoints."`

RestCORS []string `long:"restcors" description:"Add an ip:port/hostname to allow cross origin access from. To allow all origins, set as \"*\"."`

Expand Down Expand Up @@ -352,8 +351,7 @@ func DefaultConfig() Config {
},
},
Universe: &UniverseConfig{
SyncInterval: defaultUniverseSyncInterval,
AcceptRemoteProofs: defaultAcceptRemoteProofs,
SyncInterval: defaultUniverseSyncInterval,
},
}
}
Expand Down
44 changes: 22 additions & 22 deletions tapcfg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,11 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
})

return &tap.Config{
DebugLevel: cfg.DebugLevel,
RuntimeID: runtimeID,
AcceptRemoteUniverseProofs: cfg.Universe.AcceptRemoteProofs,
Lnd: lndServices,
ChainParams: cfg.ActiveNetParams,
ReOrgWatcher: reOrgWatcher,
DebugLevel: cfg.DebugLevel,
RuntimeID: runtimeID,
Lnd: lndServices,
ChainParams: cfg.ActiveNetParams,
ReOrgWatcher: reOrgWatcher,
AssetMinter: tapgarden.NewChainPlanter(tapgarden.PlanterConfig{
GardenKit: tapgarden.GardenKit{
Wallet: walletAnchor,
Expand Down Expand Up @@ -384,22 +383,23 @@ func CreateServerFromConfig(cfg *Config, cfgLogger btclog.Logger,
serverCfg.SignalInterceptor = shutdownInterceptor

serverCfg.RPCConfig = &tap.RPCConfig{
LisCfg: &lnd.ListenerCfg{},
RPCListeners: cfg.rpcListeners,
RESTListeners: cfg.restListeners,
GrpcServerOpts: serverOpts,
RestDialOpts: restDialOpts,
RestListenFunc: restListen,
WSPingInterval: cfg.RpcConf.WSPingInterval,
WSPongWait: cfg.RpcConf.WSPongWait,
RestCORS: cfg.RpcConf.RestCORS,
NoMacaroons: cfg.RpcConf.NoMacaroons,
MacaroonPath: cfg.RpcConf.MacaroonPath,
AllowPublicStats: cfg.RpcConf.AllowPublicStats,
LetsEncryptDir: cfg.RpcConf.LetsEncryptDir,
LetsEncryptListen: cfg.RpcConf.LetsEncryptListen,
LetsEncryptEmail: cfg.RpcConf.LetsEncryptEmail,
LetsEncryptDomain: cfg.RpcConf.LetsEncryptDomain,
LisCfg: &lnd.ListenerCfg{},
RPCListeners: cfg.rpcListeners,
RESTListeners: cfg.restListeners,
GrpcServerOpts: serverOpts,
RestDialOpts: restDialOpts,
RestListenFunc: restListen,
WSPingInterval: cfg.RpcConf.WSPingInterval,
WSPongWait: cfg.RpcConf.WSPongWait,
RestCORS: cfg.RpcConf.RestCORS,
NoMacaroons: cfg.RpcConf.NoMacaroons,
MacaroonPath: cfg.RpcConf.MacaroonPath,
AllowPublicUniProofCourier: cfg.RpcConf.AllowPublicUniProofCourier,
AllowPublicStats: cfg.RpcConf.AllowPublicStats,
LetsEncryptDir: cfg.RpcConf.LetsEncryptDir,
LetsEncryptListen: cfg.RpcConf.LetsEncryptListen,
LetsEncryptEmail: cfg.RpcConf.LetsEncryptEmail,
LetsEncryptDomain: cfg.RpcConf.LetsEncryptDomain,
}

return tap.NewServer(serverCfg), nil
Expand Down