Update script and config to start local dendrite with authorization checks (#934)

- Update the start-local-dendrite.sh to be able to start local dendrite
with / without authorization checks
- Update dendrite config to support command line arg
This commit is contained in:
Tak Wai Wong 2022-11-16 09:05:04 -08:00 committed by GitHub
parent b9e047dfac
commit 0f4febc65a
3 changed files with 12 additions and 5 deletions

View file

@ -589,9 +589,9 @@ func (config *Dendrite) replaceWithEnvVariables() {
// If env variable is set, get the value from the env
// variable and replace it in each supported field.
err := godotenv.Load(".env")
err := godotenv.Load()
if err != nil {
logrus.Errorln("error loading .env file", err)
logrus.Warningln(err)
}
config.Global.ServerName = gomatrixserverlib.ServerName(
@ -616,7 +616,7 @@ func (config *Dendrite) replaceWithEnvVariables() {
replaceWithEnvVariables(config.ClientAPI.PublicKeyAuthentication.Ethereum.ConfigEnableAuthz)
logrus.Infof(
"Supported Ethereum chain_id=%v, network_url=%v, enable_authz=%v",
"Loaded config for Ethereum chain_id=%v, network_url=%v, enable_authz=%v",
config.ClientAPI.PublicKeyAuthentication.Ethereum.ConfigChainID,
config.ClientAPI.PublicKeyAuthentication.Ethereum.NetworkUrl,
config.ClientAPI.PublicKeyAuthentication.Ethereum.ConfigEnableAuthz,

View file

@ -25,9 +25,9 @@ type EthereumAuthConfig struct {
Version uint `yaml:"version"`
NetworkUrl string `yaml:"network_url"` // Blockchain network provider URL
ConfigChainID string `yaml:"chain_id"` // Blockchain chain ID. Env variable can replace this property.
ConfigEnableAuthz string `yaml:"enable_authz"` // Enable / disable authorization during development. Will be removed when feature is done.
ConfigEnableAuthz string `yaml:"enable_authz"` // Enable / disable authorization during development. todo: remove this flag when feature is done.
chainID int
enableAuthz bool
enableAuthz bool // todo: remove this flag when feature is done.
}
func (c *EthereumAuthConfig) GetChainID() int {

View file

@ -18,6 +18,7 @@ import (
"flag"
"fmt"
"os"
"strconv"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/setup/config"
@ -28,6 +29,7 @@ var (
configPath = flag.String("config", "dendrite.yaml", "The path to the config file. For more information, see the config file in this repository.")
version = flag.Bool("version", false, "Shows the current version and exits immediately.")
enableRegistrationWithoutVerification = flag.Bool("really-enable-open-registration", false, "This allows open registration without secondary verification (reCAPTCHA). This is NOT RECOMMENDED and will SIGNIFICANTLY increase the risk that your server will be used to send spam or conduct attacks, which may result in your server being banned from rooms.")
enableAuthorizationChecks = flag.Bool("enable-authz", false, "Enables authorization checks (aka space/channel gating).")
)
// ParseFlags parses the commandline flags and uses them to create a config.
@ -53,5 +55,10 @@ func ParseFlags(monolith bool) *config.Dendrite {
cfg.ClientAPI.OpenRegistrationWithoutVerificationEnabled = true
}
// cmdline --enable-authz flag. env overrides it so that deployment scripts can set it.
// todo: remove this flag when feature is done.
cfg.ClientAPI.PublicKeyAuthentication.Ethereum.ConfigEnableAuthz = strconv.FormatBool(*enableAuthorizationChecks)
logrus.Info("enable-authz flag is set to ", *enableAuthorizationChecks)
return cfg
}