From e1407149b97970a3cfc9ee4600dc8a9f2e6787f0 Mon Sep 17 00:00:00 2001 From: Gustavo Trott Date: Thu, 29 Aug 2024 18:40:52 -0300 Subject: [PATCH] refactor (build/gql-middleware): Introduce config as a yml file (#20992) * Introduce Gql-Middleware config as a yml file * use path /usr/share/bbb-graphql-middleware/ instead of /usr/local/bigbluebutton/bbb-graphql-middleware * remove /etc/default/bbb-graphql-middleware file --- .../cmd/bbb-graphql-middleware/main.go | 39 ++----- bbb-graphql-middleware/config/Config.go | 102 ++++++++++++++++++ bbb-graphql-middleware/config/config.yml | 28 +++++ bbb-graphql-middleware/go.mod | 7 +- bbb-graphql-middleware/go.sum | 22 +++- .../internal/akka_apps/client.go | 4 +- .../internal/bbb_web/client.go | 4 +- .../internal/common/GlobalState.go | 21 +--- .../internal/common/PrometheusMetrics.go | 10 +- .../internal/gql_actions/client.go | 4 +- .../internal/hasura/client.go | 4 +- .../internal/hasura/conn/writer/writer.go | 16 ++- .../internal/websrv/connhandler.go | 9 +- .../internal/websrv/rediscli.go | 7 +- .../bbb-graphql-middleware-config.env | 19 ---- .../bbb-graphql-middleware.service | 1 - .../bbb-graphql-middleware/before-install.sh | 12 +++ .../bbb-graphql-middleware/build.sh | 8 +- docs/docs/administration/cluster-proxy.md | 11 +- 19 files changed, 211 insertions(+), 117 deletions(-) create mode 100644 bbb-graphql-middleware/config/Config.go create mode 100644 bbb-graphql-middleware/config/config.yml delete mode 100644 build/packages-template/bbb-graphql-middleware/bbb-graphql-middleware-config.env create mode 100644 build/packages-template/bbb-graphql-middleware/before-install.sh diff --git a/bbb-graphql-middleware/cmd/bbb-graphql-middleware/main.go b/bbb-graphql-middleware/cmd/bbb-graphql-middleware/main.go index 305ad68b166a..4fc4ed27efe2 100644 --- a/bbb-graphql-middleware/cmd/bbb-graphql-middleware/main.go +++ b/bbb-graphql-middleware/cmd/bbb-graphql-middleware/main.go @@ -1,6 +1,7 @@ package main import ( + "bbb-graphql-middleware/config" "bbb-graphql-middleware/internal/common" "bbb-graphql-middleware/internal/websrv" "context" @@ -9,15 +10,15 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" log "github.com/sirupsen/logrus" "net/http" - "os" - "strconv" "time" ) func main() { + cfg := config.GetConfig() + // Configure logger - if logLevelFromEnvVar, err := log.ParseLevel(os.Getenv("BBB_GRAPHQL_MIDDLEWARE_LOG_LEVEL")); err == nil { - log.SetLevel(logLevelFromEnvVar) + if logLevelFromConfig, err := log.ParseLevel(cfg.LogLevel); err == nil { + log.SetLevel(logLevelFromConfig) } else { log.SetLevel(log.InfoLevel) } @@ -33,35 +34,13 @@ func main() { // Listen msgs from akka (for example to invalidate connection) go websrv.StartRedisListener() - if jsonPatchDisabled := os.Getenv("BBB_GRAPHQL_MIDDLEWARE_JSON_PATCH_DISABLED"); jsonPatchDisabled != "" { + if cfg.Server.JsonPatchDisabled { log.Infof("Json Patch Disabled!") } // Websocket listener - //Define IP to listen - listenIp := "127.0.0.1" - if envListenIp := os.Getenv("BBB_GRAPHQL_MIDDLEWARE_LISTEN_IP"); envListenIp != "" { - listenIp = envListenIp - } - - // Define port to listen on - listenPort := 8378 - if envListenPort := os.Getenv("BBB_GRAPHQL_MIDDLEWARE_LISTEN_PORT"); envListenPort != "" { - if envListenPortAsInt, err := strconv.Atoi(envListenPort); err == nil { - listenPort = envListenPortAsInt - } - } - - //Define new Connections Rate Limit - maxConnPerSecond := 10 - if envMaxConnPerSecond := os.Getenv("BBB_GRAPHQL_MIDDLEWARE_MAX_CONN_PER_SECOND"); envMaxConnPerSecond != "" { - if envMaxConnPerSecondAsInt, err := strconv.Atoi(envMaxConnPerSecond); err == nil { - maxConnPerSecond = envMaxConnPerSecondAsInt - } - } - rateLimiter := common.NewCustomRateLimiter(maxConnPerSecond) - + rateLimiter := common.NewCustomRateLimiter(cfg.Server.MaxConnectionsPerSecond) http.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) { ctx, cancel := context.WithTimeout(r.Context(), 120*time.Second) defer cancel() @@ -84,6 +63,6 @@ func main() { // Add Prometheus metrics endpoint http.Handle("/metrics", promhttp.Handler()) - log.Infof("listening on %v:%v", listenIp, listenPort) - log.Fatal(http.ListenAndServe(fmt.Sprintf("%v:%v", listenIp, listenPort), nil)) + log.Infof("listening on %v:%v", cfg.Server.Host, cfg.Server.Port) + log.Fatal(http.ListenAndServe(fmt.Sprintf("%v:%v", cfg.Server.Host, cfg.Server.Port), nil)) } diff --git a/bbb-graphql-middleware/config/Config.go b/bbb-graphql-middleware/config/Config.go new file mode 100644 index 000000000000..8b4e8ac1c9bf --- /dev/null +++ b/bbb-graphql-middleware/config/Config.go @@ -0,0 +1,102 @@ +package config + +import ( + "dario.cat/mergo" + log "github.com/sirupsen/logrus" + "gopkg.in/yaml.v3" + "io/ioutil" + "os" + "path/filepath" + "sync" +) + +var ( + instance *Config + once sync.Once +) + +var DefaultConfigPath = "/usr/share/bbb-graphql-middleware/config.yml" +var OverrideConfigPath = "/etc/bigbluebutton/bbb-graphql-middleware.yml" + +type Config struct { + Server struct { + Host string `yaml:"listen_host"` + Port int `yaml:"listen_port"` + MaxConnections int `yaml:"max_connections"` + MaxConnectionsPerSecond int `yaml:"max_connections_per_session_token"` + MaxConnectionsPerSessionToken int `yaml:"max_connections_per_second"` + AuthorizedCrossOrigin string `yaml:"authorized_cross_origin"` + JsonPatchDisabled bool `yaml:"json_patch_disabled"` + SubscriptionAllowedList string `yaml:"subscriptions_allowed_list"` + SubscriptionsDeniedList string `yaml:"subscriptions_denied_list"` + } `yaml:"server"` + Redis struct { + Host string `yaml:"host"` + Port int32 `yaml:"port"` + Password string `yaml:"password"` + } `yaml:"redis"` + Hasura struct { + Url string `yaml:"url"` + } `yaml:"hasura"` + GraphqlActions struct { + Url string `yaml:"url"` + } `yaml:"graphql-actions"` + AuthHook struct { + Url string `yaml:"url"` + } `yaml:"auth_hook"` + SessionVarsHook struct { + Url string `yaml:"url"` + } `yaml:"session_vars_hook"` + LogLevel string `yaml:"log_level"` + PrometheusAdvancedMetricsEnabled bool `yaml:"prometheus_advanced_metrics_enabled"` +} + +func GetConfig() *Config { + once.Do(func() { + instance = &Config{} + instance.loadConfigs() + }) + return instance +} + +func (c *Config) loadConfigs() { + // Load default config file + configDefault, err := loadConfigFile(DefaultConfigPath) + if err != nil { + log.Fatalf("Error while loading config file (%s): %v", DefaultConfigPath, err) + } + + // Load override config file if exists + if _, err := os.Stat(OverrideConfigPath); err == nil { + configOverride, err := loadConfigFile(OverrideConfigPath) + if err != nil { + log.Fatalf("Error while loading override config file (%s): %v", OverrideConfigPath, err) + } + + log.Info("Override config found at " + OverrideConfigPath) + + // Use mergo to merge configs + err = mergo.Merge(&configDefault, configOverride, mergo.WithOverride) + if err != nil { + log.Fatalf("Erro ao mesclar as configurações: %v", err) + } + } + + // Update the singleton instance with the merged config + *instance = configDefault +} + +func loadConfigFile(path string) (Config, error) { + var config Config + data, err := ioutil.ReadFile(filepath.Clean(path)) + if err != nil { + return config, err + } + + err = yaml.Unmarshal(data, &config) + if err != nil { + return config, err + } + + return config, nil +} diff --git a/bbb-graphql-middleware/config/config.yml b/bbb-graphql-middleware/config/config.yml new file mode 100644 index 000000000000..0cda076e7c06 --- /dev/null +++ b/bbb-graphql-middleware/config/config.yml @@ -0,0 +1,28 @@ +server: + listen_host: 127.0.0.1 + listen_port: 8378 + #max of concurrent connections + max_connections: 500 + max_connections_per_session_token: 3 + #rate limit + max_connections_per_second: 100 + # If you are running a cluster proxy setup, you need to allow the url of the Frontend + # Add an Authorized Cross Origin. See https://docs.bigbluebutton.org/administration/cluster-proxy + #authorized_cross_origin: 'bbb-proxy.example.com' + json_patch_disabled: false + subscriptions_allowed_list: + subscriptions_denied_list: +redis: + host: 127.0.0.1 + port: 6379 + password: "" +hasura: + url: ws://127.0.0.1:8085/v1/graphql +graphql-actions: + url: http://127.0.0.1:8093 +auth_hook: + url: http://127.0.0.1:8090/bigbluebutton/connection/checkGraphqlAuthorization +session_vars_hook: + url: http://127.0.0.1:8901/userInfo +prometheus_advanced_metrics_enabled: false +log_level: INFO diff --git a/bbb-graphql-middleware/go.mod b/bbb-graphql-middleware/go.mod index 59539be02013..176e7380f472 100644 --- a/bbb-graphql-middleware/go.mod +++ b/bbb-graphql-middleware/go.mod @@ -3,12 +3,15 @@ module bbb-graphql-middleware go 1.22.5 require ( + dario.cat/mergo v1.0.1 github.com/evanphx/json-patch v0.5.2 github.com/google/uuid v1.6.0 github.com/mattbaird/jsonpatch v0.0.0-20240118010651-0ba75a80ca38 github.com/prometheus/client_golang v1.19.1 + github.com/redis/go-redis/v9 v9.6.1 github.com/sirupsen/logrus v1.9.3 golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 + gopkg.in/yaml.v3 v3.0.1 nhooyr.io/websocket v1.8.11 ) @@ -16,13 +19,11 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect - github.com/go-redis/redis v6.15.9+incompatible // indirect + github.com/kr/text v0.2.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.48.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect - github.com/redis/go-redis v6.15.9+incompatible // indirect - github.com/redis/go-redis/v9 v9.6.1 // indirect golang.org/x/sys v0.17.0 // indirect google.golang.org/protobuf v1.33.0 // indirect ) diff --git a/bbb-graphql-middleware/go.sum b/bbb-graphql-middleware/go.sum index 52d8b72bd1ca..c1a055921195 100644 --- a/bbb-graphql-middleware/go.sum +++ b/bbb-graphql-middleware/go.sum @@ -1,7 +1,14 @@ +dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s= +dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -9,13 +16,15 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8P3k= github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= -github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= -github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattbaird/jsonpatch v0.0.0-20240118010651-0ba75a80ca38 h1:hQWBtNqRYrI7CWIaUSXXtNKR90KzcUA5uiuxFVWw7sU= github.com/mattbaird/jsonpatch v0.0.0-20240118010651-0ba75a80ca38/go.mod h1:M1qoD/MqPgTZIk0EWKB38wE28ACRfVcn+cU08jyArI0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -30,10 +39,10 @@ github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSz github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= -github.com/redis/go-redis v6.15.9+incompatible h1:F+tnlesQSl3h9V8DdmtcYFdvkHLhbb7AgcLW6UJxnC4= -github.com/redis/go-redis v6.15.9+incompatible/go.mod h1:ic6dLmR0d9rkHSzaa0Ab3QVRZcjopJ9hSSPCrecj/+s= github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4= github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -47,7 +56,10 @@ golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9/go.mod h1:NDW/Ps6MPRej6f google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= nhooyr.io/websocket v1.8.11 h1:f/qXNc2/3DpoSZkHt1DQu6rj4zGC8JmkkLkWss0MgN0= nhooyr.io/websocket v1.8.11/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c= diff --git a/bbb-graphql-middleware/internal/akka_apps/client.go b/bbb-graphql-middleware/internal/akka_apps/client.go index f5cd3a4aa5f5..16bb65ff85d3 100644 --- a/bbb-graphql-middleware/internal/akka_apps/client.go +++ b/bbb-graphql-middleware/internal/akka_apps/client.go @@ -1,17 +1,17 @@ package akka_apps import ( + "bbb-graphql-middleware/config" "encoding/json" "fmt" log "github.com/sirupsen/logrus" "io/ioutil" "net/http" - "os" "strings" ) // sessionVarsHookUrl is the authentication hook URL obtained from an environment variable. -var sessionVarsHookUrl = os.Getenv("BBB_GRAPHQL_MIDDLEWARE_SESSION_VARS_HOOK_URL") +var sessionVarsHookUrl = config.GetConfig().SessionVarsHook.Url func AkkaAppsGetSessionVariablesFrom(browserConnectionId string, sessionToken string) (map[string]string, error) { logger := log.WithField("_routine", "AkkaAppsClient").WithField("browserConnectionId", browserConnectionId) diff --git a/bbb-graphql-middleware/internal/bbb_web/client.go b/bbb-graphql-middleware/internal/bbb_web/client.go index fbececf2ad73..7e45dcdd622d 100644 --- a/bbb-graphql-middleware/internal/bbb_web/client.go +++ b/bbb-graphql-middleware/internal/bbb_web/client.go @@ -1,18 +1,18 @@ package bbb_web import ( + "bbb-graphql-middleware/config" "encoding/json" "fmt" log "github.com/sirupsen/logrus" "io/ioutil" "net/http" "net/http/cookiejar" - "os" "strings" ) // authHookUrl is the authentication hook URL obtained from an environment variable. -var authHookUrl = os.Getenv("BBB_GRAPHQL_MIDDLEWARE_AUTH_HOOK_URL") +var authHookUrl = config.GetConfig().AuthHook.Url func BBBWebCheckAuthorization(browserConnectionId string, sessionToken string, cookies []*http.Cookie) (string, string, error) { logger := log.WithField("_routine", "BBBWebClient").WithField("browserConnectionId", browserConnectionId) diff --git a/bbb-graphql-middleware/internal/common/GlobalState.go b/bbb-graphql-middleware/internal/common/GlobalState.go index e504de870ed1..b04a657b36fa 100644 --- a/bbb-graphql-middleware/internal/common/GlobalState.go +++ b/bbb-graphql-middleware/internal/common/GlobalState.go @@ -1,9 +1,8 @@ package common import ( + "bbb-graphql-middleware/config" "github.com/google/uuid" - "os" - "strconv" "sync" "time" ) @@ -109,22 +108,8 @@ func RemoveStreamCursorValueCache(cacheKey uint32, delayInSecs time.Duration) { delete(StreamCursorValueCache, cacheKey) } -var MaxConnPerSessionToken = 3 -var MaxConnGlobal = 500 - -func init() { - if envMaxConnPerSessionToken := os.Getenv("BBB_GRAPHQL_MIDDLEWARE_MAX_CONN_PER_SESSION_TOKEN"); envMaxConnPerSessionToken != "" { - if envMaxConnPerSessionTokenAsInt, err := strconv.Atoi(envMaxConnPerSessionToken); err == nil { - MaxConnPerSessionToken = envMaxConnPerSessionTokenAsInt - } - } - - if envMaxConnGlobal := os.Getenv("BBB_GRAPHQL_MIDDLEWARE_MAX_CONN"); envMaxConnGlobal != "" { - if envMaxConnGlobalAsInt, err := strconv.Atoi(envMaxConnGlobal); err == nil { - MaxConnGlobal = envMaxConnGlobalAsInt - } - } -} +var MaxConnPerSessionToken = config.GetConfig().Server.MaxConnectionsPerSessionToken +var MaxConnGlobal = config.GetConfig().Server.MaxConnections func GetMaxConnectionsPerSessionToken() int { return MaxConnPerSessionToken diff --git a/bbb-graphql-middleware/internal/common/PrometheusMetrics.go b/bbb-graphql-middleware/internal/common/PrometheusMetrics.go index 32cfa84243ae..a5b2e1601243 100644 --- a/bbb-graphql-middleware/internal/common/PrometheusMetrics.go +++ b/bbb-graphql-middleware/internal/common/PrometheusMetrics.go @@ -1,17 +1,11 @@ package common import ( + "bbb-graphql-middleware/config" "github.com/prometheus/client_golang/prometheus" - "os" ) -var PrometheusAdvancedMetricsEnabled = false - -func init() { - if prometheusAdvancedMetricsEnabled := os.Getenv("BBB_GRAPHQL_MIDDLEWARE_PROMETHEUS_ADVANCED_METRICS_ENABLED"); prometheusAdvancedMetricsEnabled == "true" { - PrometheusAdvancedMetricsEnabled = true - } -} +var PrometheusAdvancedMetricsEnabled = config.GetConfig().PrometheusAdvancedMetricsEnabled var ( HttpConnectionGauge = prometheus.NewGauge(prometheus.GaugeOpts{ diff --git a/bbb-graphql-middleware/internal/gql_actions/client.go b/bbb-graphql-middleware/internal/gql_actions/client.go index cf950d697880..b666d8a441c5 100644 --- a/bbb-graphql-middleware/internal/gql_actions/client.go +++ b/bbb-graphql-middleware/internal/gql_actions/client.go @@ -1,6 +1,7 @@ package gql_actions import ( + "bbb-graphql-middleware/config" "bbb-graphql-middleware/internal/common" "bytes" "encoding/json" @@ -9,13 +10,12 @@ import ( log "github.com/sirupsen/logrus" "io/ioutil" "net/http" - "os" "regexp" "strings" "time" ) -var graphqlActionsUrl = os.Getenv("BBB_GRAPHQL_MIDDLEWARE_GRAPHQL_ACTIONS_URL") +var graphqlActionsUrl = config.GetConfig().GraphqlActions.Url func GraphqlActionsClient( browserConnection *common.BrowserConnection) error { diff --git a/bbb-graphql-middleware/internal/hasura/client.go b/bbb-graphql-middleware/internal/hasura/client.go index 0025a2ee5b98..fe5236a19d5a 100644 --- a/bbb-graphql-middleware/internal/hasura/client.go +++ b/bbb-graphql-middleware/internal/hasura/client.go @@ -1,6 +1,7 @@ package hasura import ( + "bbb-graphql-middleware/config" "bbb-graphql-middleware/internal/hasura/conn/reader" "bbb-graphql-middleware/internal/hasura/conn/writer" "context" @@ -10,7 +11,6 @@ import ( "net/http" "net/http/cookiejar" "net/url" - "os" "sync" "bbb-graphql-middleware/internal/common" @@ -19,7 +19,7 @@ import ( ) var lastHasuraConnectionId int -var hasuraEndpoint = os.Getenv("BBB_GRAPHQL_MIDDLEWARE_HASURA_WS") +var hasuraEndpoint = config.GetConfig().Hasura.Url // Hasura client connection func HasuraClient( diff --git a/bbb-graphql-middleware/internal/hasura/conn/writer/writer.go b/bbb-graphql-middleware/internal/hasura/conn/writer/writer.go index a66b6823d6ea..98dcf885da37 100644 --- a/bbb-graphql-middleware/internal/hasura/conn/writer/writer.go +++ b/bbb-graphql-middleware/internal/hasura/conn/writer/writer.go @@ -1,6 +1,7 @@ package writer import ( + "bbb-graphql-middleware/config" "bbb-graphql-middleware/internal/common" "context" "encoding/json" @@ -8,26 +9,21 @@ import ( "github.com/prometheus/client_golang/prometheus" log "github.com/sirupsen/logrus" "nhooyr.io/websocket" - "os" "strings" "sync" ) var allowedSubscriptions []string var deniedSubscriptions []string -var jsonPatchDisabled = false +var jsonPatchDisabled = config.GetConfig().Server.JsonPatchDisabled func init() { - if allowedSubscriptionsEnvVar := os.Getenv("BBB_GRAPHQL_MIDDLEWARE_ALLOWED_SUBSCRIPTIONS"); allowedSubscriptionsEnvVar != "" { - allowedSubscriptions = strings.Split(allowedSubscriptionsEnvVar, ",") + if config.GetConfig().Server.SubscriptionAllowedList != "" { + allowedSubscriptions = strings.Split(config.GetConfig().Server.SubscriptionAllowedList, ",") } - if deniedSubscriptionsEnvVar := os.Getenv("BBB_GRAPHQL_MIDDLEWARE_DENIED_SUBSCRIPTIONS"); deniedSubscriptionsEnvVar != "" { - deniedSubscriptions = strings.Split(deniedSubscriptionsEnvVar, ",") - } - - if jsonPatchDisabledEnvVar := os.Getenv("BBB_GRAPHQL_MIDDLEWARE_JSON_PATCH_DISABLED"); jsonPatchDisabledEnvVar != "" { - jsonPatchDisabled = true + if config.GetConfig().Server.SubscriptionsDeniedList != "" { + deniedSubscriptions = strings.Split(config.GetConfig().Server.SubscriptionsDeniedList, ",") } } diff --git a/bbb-graphql-middleware/internal/websrv/connhandler.go b/bbb-graphql-middleware/internal/websrv/connhandler.go index e980665a24de..7cb81fef1f2f 100644 --- a/bbb-graphql-middleware/internal/websrv/connhandler.go +++ b/bbb-graphql-middleware/internal/websrv/connhandler.go @@ -1,6 +1,7 @@ package websrv import ( + "bbb-graphql-middleware/config" "bbb-graphql-middleware/internal/akka_apps" "bbb-graphql-middleware/internal/bbb_web" "bbb-graphql-middleware/internal/common" @@ -16,7 +17,6 @@ import ( log "github.com/sirupsen/logrus" "net/http" "nhooyr.io/websocket" - "os" "strings" "sync" "time" @@ -48,9 +48,10 @@ func ConnectionHandler(w http.ResponseWriter, r *http.Request) { // Add sub-protocol var acceptOptions websocket.AcceptOptions acceptOptions.Subprotocols = append(acceptOptions.Subprotocols, "graphql-transport-ws") - bbbOrigin := os.Getenv("BBB_GRAPHQL_MIDDLEWARE_ORIGIN") - if bbbOrigin != "" { - acceptOptions.OriginPatterns = append(acceptOptions.OriginPatterns, bbbOrigin) + + //Add Authorized Cross Origin Url + if config.GetConfig().Server.AuthorizedCrossOrigin != "" { + acceptOptions.OriginPatterns = append(acceptOptions.OriginPatterns, config.GetConfig().Server.AuthorizedCrossOrigin) } browserWsConn, err := websocket.Accept(w, r, &acceptOptions) diff --git a/bbb-graphql-middleware/internal/websrv/rediscli.go b/bbb-graphql-middleware/internal/websrv/rediscli.go index 5d3ddd008250..6441f7d4df20 100644 --- a/bbb-graphql-middleware/internal/websrv/rediscli.go +++ b/bbb-graphql-middleware/internal/websrv/rediscli.go @@ -1,19 +1,20 @@ package websrv import ( + "bbb-graphql-middleware/config" "bbb-graphql-middleware/internal/common" "context" "encoding/json" + "fmt" "github.com/redis/go-redis/v9" log "github.com/sirupsen/logrus" - "os" "strings" "time" ) var redisClient = redis.NewClient(&redis.Options{ - Addr: os.Getenv("BBB_GRAPHQL_MIDDLEWARE_REDIS_ADDRESS"), - Password: os.Getenv("BBB_GRAPHQL_MIDDLEWARE_REDIS_PASSWORD"), + Addr: fmt.Sprintf("%s:%d", config.GetConfig().Redis.Host, config.GetConfig().Redis.Port), + Password: config.GetConfig().Redis.Password, DB: 0, }) diff --git a/build/packages-template/bbb-graphql-middleware/bbb-graphql-middleware-config.env b/build/packages-template/bbb-graphql-middleware/bbb-graphql-middleware-config.env deleted file mode 100644 index 2e9daaf951b3..000000000000 --- a/build/packages-template/bbb-graphql-middleware/bbb-graphql-middleware-config.env +++ /dev/null @@ -1,19 +0,0 @@ -BBB_GRAPHQL_MIDDLEWARE_LISTEN_IP=127.0.0.1 -BBB_GRAPHQL_MIDDLEWARE_LISTEN_PORT=8378 -BBB_GRAPHQL_MIDDLEWARE_REDIS_ADDRESS=127.0.0.1:6379 -BBB_GRAPHQL_MIDDLEWARE_REDIS_PASSWORD= -BBB_GRAPHQL_MIDDLEWARE_HASURA_WS=ws://127.0.0.1:8085/v1/graphql -BBB_GRAPHQL_MIDDLEWARE_MAX_CONN_PER_SECOND=100 -BBB_GRAPHQL_MIDDLEWARE_MAX_CONN=500 -BBB_GRAPHQL_MIDDLEWARE_MAX_CONN_PER_SESSION_TOKEN=3 -BBB_GRAPHQL_MIDDLEWARE_AUTH_HOOK_URL=http://127.0.0.1:8090/bigbluebutton/connection/checkGraphqlAuthorization -BBB_GRAPHQL_MIDDLEWARE_SESSION_VARS_HOOK_URL=http://127.0.0.1:8901/userInfo -BBB_GRAPHQL_MIDDLEWARE_GRAPHQL_ACTIONS_URL=http://127.0.0.1:8093 - -# If you are running a cluster proxy setup, you need to configure the Origin of -# the frontend. See https://docs.bigbluebutton.org/administration/cluster-proxy -# BBB_GRAPHQL_MIDDLEWARE_ORIGIN=bbb-proxy.example.com - -# LOG_LEVEL options: PANIC, FATAL, ERROR, WARN, INFO, DEBUG, TRACE -BBB_GRAPHQL_MIDDLEWARE_LOG_LEVEL=INFO -BBB_GRAPHQL_MIDDLEWARE_PROMETHEUS_ADVANCED_METRICS_ENABLED=false diff --git a/build/packages-template/bbb-graphql-middleware/bbb-graphql-middleware.service b/build/packages-template/bbb-graphql-middleware/bbb-graphql-middleware.service index 67fa7866ff16..9cd07880162c 100644 --- a/build/packages-template/bbb-graphql-middleware/bbb-graphql-middleware.service +++ b/build/packages-template/bbb-graphql-middleware/bbb-graphql-middleware.service @@ -10,7 +10,6 @@ Type=simple User=bigbluebutton Group=bigbluebutton WorkingDirectory=/usr/local/bin -EnvironmentFile=/etc/default/bbb-graphql-middleware ExecStart=/usr/local/bin/bbb-graphql-middleware ExecReload=/bin/kill -HUP $MAINPID Restart=always diff --git a/build/packages-template/bbb-graphql-middleware/before-install.sh b/build/packages-template/bbb-graphql-middleware/before-install.sh new file mode 100644 index 000000000000..e6060c2ba7b1 --- /dev/null +++ b/build/packages-template/bbb-graphql-middleware/before-install.sh @@ -0,0 +1,12 @@ +#!/bin/bash -e + +case "$1" in + install|upgrade|1|2) + + # the config is not longer env vars at /etc/default/bbb-graphql-middleware + if [ -f /etc/default/bbb-graphql-middleware ]; then + rm /etc/default/bbb-graphql-middleware + fi + + ;; +esac diff --git a/build/packages-template/bbb-graphql-middleware/build.sh b/build/packages-template/bbb-graphql-middleware/build.sh index 0dcadc6f8c0b..130a2e2ff40a 100755 --- a/build/packages-template/bbb-graphql-middleware/build.sh +++ b/build/packages-template/bbb-graphql-middleware/build.sh @@ -14,7 +14,7 @@ rm -rf staging rm -rf ./build # Create directories for fpm to process -DIRS="/usr/local/bin /lib/systemd/system /etc/default /usr/share/bigbluebutton/nginx" +DIRS="/usr/local/bin /lib/systemd/system /usr/share/bigbluebutton/nginx /usr/share/bbb-graphql-middleware/" for dir in $DIRS; do mkdir -p staging$dir done @@ -31,8 +31,9 @@ cp bbb-graphql-middleware staging/usr/local/bin/bbb-graphql-middleware mkdir -p staging/etc/nginx/conf.d cp bbb-graphql-client-settings-cache.conf staging/etc/nginx/conf.d -# Create service bbb-graphql-middleware -cp bbb-graphql-middleware-config.env staging/etc/default/bbb-graphql-middleware +# Create config file +cp config/config.yml staging/usr/share/bbb-graphql-middleware/config.yml + cp bbb-graphql-middleware.service staging/lib/systemd/system/bbb-graphql-middleware.service # Set nginx location @@ -46,6 +47,7 @@ fpm -s dir -C ./staging -n $PACKAGE \ --version $VERSION --epoch $EPOCH \ --after-install after-install.sh \ --after-remove after-remove.sh \ + --before-install before-install.sh \ --before-remove before-remove.sh \ --description "GraphQL middleware component for BigBlueButton" \ $DIRECTORIES \ diff --git a/docs/docs/administration/cluster-proxy.md b/docs/docs/administration/cluster-proxy.md index e8e6353741db..f2d8bb303660 100644 --- a/docs/docs/administration/cluster-proxy.md +++ b/docs/docs/administration/cluster-proxy.md @@ -183,13 +183,14 @@ Adjust the CORS settings in `/etc/default/bbb-web`: JDK_JAVA_OPTIONS="-Dgrails.cors.enabled=true -Dgrails.cors.allowCredentials=true -Dgrails.cors.allowedOrigins=https://bbb-proxy.example.com,https://https://bbb-01.example.com" ``` -Adjust the CORS setting in `/etc/default/bbb-graphql-middleware`: +Create the file `/etc/bigbluebutton/bbb-graphql-middleware.yml` with the following content: ```shell -BBB_GRAPHQL_MIDDLEWARE_LISTEN_PORT=8378 -# If you are running a cluster proxy setup, you need to configure the Origin of -# the frontend. See https://docs.bigbluebutton.org/administration/cluster-proxy -BBB_GRAPHQL_MIDDLEWARE_ORIGIN=bbb-proxy.example.com +# If you are running a cluster proxy setup, you need to allow the url of the Frontend +# Add an Authorized Cross Origin. See https://docs.bigbluebutton.org/administration/cluster-proxy +```yaml +server: + authorized_cross_origin: bbb-proxy.example.com ``` Pay attention that this one is without protocol, just the hostname.