lnrpc+macaroon: skip subserver macaroons on stateless_init
This will prevent the subservers from writing macaroons to disk when the stateless_init flag is set to true. It accomplishes this by storing the StatelessInit value in the Macaroon Service.
This commit is contained in:
parent
0b9b7def15
commit
5aa0d26251
@ -72,16 +72,6 @@ var (
|
|||||||
"still in the process of starting")
|
"still in the process of starting")
|
||||||
)
|
)
|
||||||
|
|
||||||
// fileExists reports whether the named file or directory exists.
|
|
||||||
func fileExists(name string) bool {
|
|
||||||
if _, err := os.Stat(name); err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Server is a sub-server of the main RPC server: the chain notifier RPC. This
|
// Server is a sub-server of the main RPC server: the chain notifier RPC. This
|
||||||
// RPC sub-server allows external callers to access the full chain notifier
|
// RPC sub-server allows external callers to access the full chain notifier
|
||||||
// capabilities of lnd. This allows callers to create custom protocols, external
|
// capabilities of lnd. This allows callers to create custom protocols, external
|
||||||
@ -111,9 +101,12 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now that we know the full path of the chain notifier macaroon, we can
|
// Now that we know the full path of the chain notifier macaroon, we can
|
||||||
// check to see if we need to create it or not.
|
// check to see if we need to create it or not. If stateless_init is set
|
||||||
|
// then we don't write the macaroons.
|
||||||
macFilePath := cfg.ChainNotifierMacPath
|
macFilePath := cfg.ChainNotifierMacPath
|
||||||
if cfg.MacService != nil && !fileExists(macFilePath) {
|
if cfg.MacService != nil && !cfg.MacService.StatelessInit &&
|
||||||
|
!lnrpc.FileExists(macFilePath) {
|
||||||
|
|
||||||
log.Infof("Baking macaroons for ChainNotifier RPC Server at: %v",
|
log.Infof("Baking macaroons for ChainNotifier RPC Server at: %v",
|
||||||
macFilePath)
|
macFilePath)
|
||||||
|
|
||||||
@ -121,8 +114,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
|||||||
// doesn't yet, exist, so we need to create it with the help of
|
// doesn't yet, exist, so we need to create it with the help of
|
||||||
// the main macaroon service.
|
// the main macaroon service.
|
||||||
chainNotifierMac, err := cfg.MacService.NewMacaroon(
|
chainNotifierMac, err := cfg.MacService.NewMacaroon(
|
||||||
context.Background(),
|
context.Background(), macaroons.DefaultRootKeyID,
|
||||||
macaroons.DefaultRootKeyID,
|
|
||||||
macaroonOps...,
|
macaroonOps...,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -134,7 +126,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
|||||||
}
|
}
|
||||||
err = ioutil.WriteFile(macFilePath, chainNotifierMacBytes, 0644)
|
err = ioutil.WriteFile(macFilePath, chainNotifierMacBytes, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(macFilePath)
|
_ = os.Remove(macFilePath)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,8 +92,11 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Now that we know the full path of the invoices macaroon, we can
|
// Now that we know the full path of the invoices macaroon, we can
|
||||||
// check to see if we need to create it or not.
|
// check to see if we need to create it or not. If stateless_init is set
|
||||||
if !lnrpc.FileExists(macFilePath) && cfg.MacService != nil {
|
// then we don't write the macaroons.
|
||||||
|
if cfg.MacService != nil && !cfg.MacService.StatelessInit &&
|
||||||
|
!lnrpc.FileExists(macFilePath) {
|
||||||
|
|
||||||
log.Infof("Baking macaroons for invoices RPC Server at: %v",
|
log.Infof("Baking macaroons for invoices RPC Server at: %v",
|
||||||
macFilePath)
|
macFilePath)
|
||||||
|
|
||||||
@ -113,7 +116,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
|||||||
}
|
}
|
||||||
err = ioutil.WriteFile(macFilePath, invoicesMacBytes, 0644)
|
err = ioutil.WriteFile(macFilePath, invoicesMacBytes, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(macFilePath)
|
_ = os.Remove(macFilePath)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,16 +131,6 @@ type Server struct {
|
|||||||
// gRPC service.
|
// gRPC service.
|
||||||
var _ RouterServer = (*Server)(nil)
|
var _ RouterServer = (*Server)(nil)
|
||||||
|
|
||||||
// fileExists reports whether the named file or directory exists.
|
|
||||||
func fileExists(name string) bool {
|
|
||||||
if _, err := os.Stat(name); err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// New creates a new instance of the RouterServer given a configuration struct
|
// New creates a new instance of the RouterServer given a configuration struct
|
||||||
// that contains all external dependencies. If the target macaroon exists, and
|
// that contains all external dependencies. If the target macaroon exists, and
|
||||||
// we're unable to create it, then an error will be returned. We also return
|
// we're unable to create it, then an error will be returned. We also return
|
||||||
@ -156,9 +146,12 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now that we know the full path of the router macaroon, we can check
|
// Now that we know the full path of the router macaroon, we can check
|
||||||
// to see if we need to create it or not.
|
// to see if we need to create it or not. If stateless_init is set
|
||||||
|
// then we don't write the macaroons.
|
||||||
macFilePath := cfg.RouterMacPath
|
macFilePath := cfg.RouterMacPath
|
||||||
if !fileExists(macFilePath) && cfg.MacService != nil {
|
if cfg.MacService != nil && !cfg.MacService.StatelessInit &&
|
||||||
|
!lnrpc.FileExists(macFilePath) {
|
||||||
|
|
||||||
log.Infof("Making macaroons for Router RPC Server at: %v",
|
log.Infof("Making macaroons for Router RPC Server at: %v",
|
||||||
macFilePath)
|
macFilePath)
|
||||||
|
|
||||||
@ -178,7 +171,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
|||||||
}
|
}
|
||||||
err = ioutil.WriteFile(macFilePath, routerMacBytes, 0644)
|
err = ioutil.WriteFile(macFilePath, routerMacBytes, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(macFilePath)
|
_ = os.Remove(macFilePath)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,9 +103,12 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now that we know the full path of the signer macaroon, we can check
|
// Now that we know the full path of the signer macaroon, we can check
|
||||||
// to see if we need to create it or not.
|
// to see if we need to create it or not. If stateless_init is set
|
||||||
|
// then we don't write the macaroons.
|
||||||
macFilePath := cfg.SignerMacPath
|
macFilePath := cfg.SignerMacPath
|
||||||
if cfg.MacService != nil && !lnrpc.FileExists(macFilePath) {
|
if cfg.MacService != nil && !cfg.MacService.StatelessInit &&
|
||||||
|
!lnrpc.FileExists(macFilePath) {
|
||||||
|
|
||||||
log.Infof("Making macaroons for Signer RPC Server at: %v",
|
log.Infof("Making macaroons for Signer RPC Server at: %v",
|
||||||
macFilePath)
|
macFilePath)
|
||||||
|
|
||||||
@ -125,7 +128,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
|||||||
}
|
}
|
||||||
err = ioutil.WriteFile(macFilePath, signerMacBytes, 0644)
|
err = ioutil.WriteFile(macFilePath, signerMacBytes, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(macFilePath)
|
_ = os.Remove(macFilePath)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,9 +170,12 @@ func New(cfg *Config) (*WalletKit, lnrpc.MacaroonPerms, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now that we know the full path of the wallet kit macaroon, we can
|
// Now that we know the full path of the wallet kit macaroon, we can
|
||||||
// check to see if we need to create it or not.
|
// check to see if we need to create it or not. If stateless_init is set
|
||||||
|
// then we don't write the macaroons.
|
||||||
macFilePath := cfg.WalletKitMacPath
|
macFilePath := cfg.WalletKitMacPath
|
||||||
if !lnrpc.FileExists(macFilePath) && cfg.MacService != nil {
|
if cfg.MacService != nil && !cfg.MacService.StatelessInit &&
|
||||||
|
!lnrpc.FileExists(macFilePath) {
|
||||||
|
|
||||||
log.Infof("Baking macaroons for WalletKit RPC Server at: %v",
|
log.Infof("Baking macaroons for WalletKit RPC Server at: %v",
|
||||||
macFilePath)
|
macFilePath)
|
||||||
|
|
||||||
@ -180,8 +183,7 @@ func New(cfg *Config) (*WalletKit, lnrpc.MacaroonPerms, error) {
|
|||||||
// yet, exist, so we need to create it with the help of the
|
// yet, exist, so we need to create it with the help of the
|
||||||
// main macaroon service.
|
// main macaroon service.
|
||||||
walletKitMac, err := cfg.MacService.NewMacaroon(
|
walletKitMac, err := cfg.MacService.NewMacaroon(
|
||||||
context.Background(),
|
context.Background(), macaroons.DefaultRootKeyID,
|
||||||
macaroons.DefaultRootKeyID,
|
|
||||||
macaroonOps...,
|
macaroonOps...,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -193,7 +195,7 @@ func New(cfg *Config) (*WalletKit, lnrpc.MacaroonPerms, error) {
|
|||||||
}
|
}
|
||||||
err = ioutil.WriteFile(macFilePath, walletKitMacBytes, 0644)
|
err = ioutil.WriteFile(macFilePath, walletKitMacBytes, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(macFilePath)
|
_ = os.Remove(macFilePath)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user