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

[MM-61915] feat: support configurable scheme for serverURL #879

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion cmd/ltkeycloak/from_mattermost.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func RunSyncFromMattermostCommandF(cmd *cobra.Command, _ []string) error {
siteURL = mattermostHost
}

mmClient := model.NewAPIv4Client("http://" + siteURL)
mmClient := model.NewAPIv4Client(deploymentConfig.ServerScheme + "://" + siteURL)

_, _, err = mmClient.Login(cmd.Context(), deploymentConfig.AdminEmail, deploymentConfig.AdminPassword)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions config/deployer.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
"S3BucketDumpURI" : "",
"DBDumpURI": "",
"SiteURL": "",
"ServerURL": "",
"ServerScheme": "http",
"EnableNetPeekMetrics": false,
"TerraformDBSettings": {
"InstanceCount": 1,
Expand Down
6 changes: 5 additions & 1 deletion config/deployer.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ MattermostDownloadURL = 'https://latest.mattermost.com/mattermost-enterprise-lin
MattermostLicenseFile = ''
S3BucketDumpURI = ''
SiteURL = ''
EnableNetPeekMetrics = false
ServerURL = ''
ServerScheme = 'http'

# Agent configuration
AgentInstanceCount = 2
Expand Down Expand Up @@ -46,6 +47,9 @@ ProxyInstanceType = 'c5.xlarge'
ProxyInstanceCount = 1
ProxyAllocatePublicIPAddress = true

# Metrics
EnableNetPeekMetrics = false

[ClusterSubnetIDs]
App = []
Job = []
Expand Down
2 changes: 2 additions & 0 deletions deployment/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ type Config struct {
// Mattermost servers. This is used to override the server URL in the agent's config in case there's a
// proxy in front of the Mattermost server.
ServerURL string `default:""`
// ServerScheme is the scheme to use when connecting to the Mattermost server.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I the only one who thinks this is getting slightly confusing?

We already have two settings to override URLs in slightly different ways, and now we are adding a third to control the scheme portion. I think that eventually we'll need to take a step back and try to simplify some of it because we are starting to tweak things for any little new use case we find. @agarciamontoro Thoughts?

Also, what happens if either SiteURL or ServerURL already have a scheme set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I the only one who thinks this is getting slightly confusing?

No 😬 It already was, honestly, based on the logic around the code regarding the URLs, the proxy, etc.

We already have two settings to override URLs in slightly different ways, and now we are adding a third to control the scheme portion. I think that eventually we'll need to take a step back and try to simplify some of it because we are starting to tweak things for any little new use case we find. @agarciamontoro Thoughts?

The problem here is what to use in what places. Honestly I would just use a complete setting (a complete URL) as the URL the clients should connect to, that being a node, a proxy, a load balancer... and leaving it empty would try to guess what to use from the configuration.

Also, what happens if either SiteURL or ServerURL already have a scheme set?

it won't work since the code prepends the scheme (both before and after this change)

I will let you discuss this a bit internally before making more changes to the PR.

ServerScheme string `default:"http" validate:"oneof:{http,https}"`
// UsersFilePath specifies the path to an optional file containing a list of credentials for the controllers
// to use. If present, it is used to automatically upload it to the agents and override the agent's config's
// own UsersFilePath.
Expand Down
9 changes: 7 additions & 2 deletions deployment/terraform/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ func (t *Terraform) generateLoadtestAgentConfig() (*loadtest.Config, error) {

url := getServerURL(t.output, t.config)

cfg.ConnectionConfiguration.ServerURL = "http://" + url
cfg.ConnectionConfiguration.WebSocketURL = "ws://" + url
websocketScheme := "ws"
if t.config.ServerScheme == "https" {
websocketScheme = "wss"
}

cfg.ConnectionConfiguration.ServerURL = url
cfg.ConnectionConfiguration.WebSocketURL = strings.Replace(url, t.config.ServerScheme+"://", websocketScheme+"://", 1)
cfg.ConnectionConfiguration.AdminEmail = t.config.AdminEmail
cfg.ConnectionConfiguration.AdminPassword = t.config.AdminPassword

Expand Down
11 changes: 7 additions & 4 deletions deployment/terraform/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,21 @@ func (t *Terraform) Create(extAgent *ssh.ExtAgent, initData bool) error {
switch {
// SiteURL defined, multiple app nodes: we use SiteURL, since that points to the proxy itself
case t.config.SiteURL != "" && t.output.HasProxy():
siteURL = "http://" + t.config.SiteURL
siteURL = t.config.ServerScheme + "://" + t.config.SiteURL
// SiteURL defined, single app node: we use SiteURL plus the port, since SiteURL points to the app node (which is listening in 8065)
case t.config.SiteURL != "":
siteURL = "http://" + t.config.SiteURL + ":8065"
siteURL = t.config.ServerScheme + "://" + t.config.SiteURL + ":8065"
// SiteURL not defined, multiple app nodes: we use the proxy's public DNS
case t.output.HasProxy():
// This case will only succeed if siteURL is empty.
// And it's an error to have siteURL empty and set multiple proxies. (see (c *Config) validateProxyConfig)
// So we can safely take the DNS of the first entry.
siteURL = "http://" + t.output.Proxies[0].PublicDNS
siteURL = t.config.ServerScheme + "://" + t.output.Proxies[0].PublicDNS
// SiteURL not defined, single app node: we use the app node's public DNS plus port
case t.config.ServerURL != "":
siteURL = t.config.ServerScheme + "://" + t.config.ServerURL
default:
siteURL = "http://" + t.output.Instances[0].PublicDNS + ":8065"
siteURL = t.config.ServerScheme + "://" + t.output.Instances[0].PublicDNS + ":8065"
}

// Updating the config.json for each instance of app server
Expand All @@ -245,6 +247,7 @@ func (t *Terraform) Create(extAgent *ssh.ExtAgent, initData bool) error {
pingURL = t.output.Proxies[0].PublicDNS
}

// Non-ssl is used for pinging the server
if err := pingServer("http://" + pingURL); err != nil {
return fmt.Errorf("error whiling pinging server: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion deployment/terraform/keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (t *Terraform) setupKeycloakAppConfig(sshc *ssh.Client, cfg *model.Config)
cfg.SamlSettings.IdpDescriptorURL = model.NewPointer(keycloakUrl + "/realms/" + t.config.ExternalAuthProviderSettings.KeycloakRealmName)
cfg.SamlSettings.IdpMetadataURL = model.NewPointer(keycloakUrl + "/realms/" + t.config.ExternalAuthProviderSettings.KeycloakRealmName + "/protocol/saml/descriptor")
cfg.SamlSettings.ServiceProviderIdentifier = model.NewPointer(t.config.ExternalAuthProviderSettings.KeycloakSAMLClientID)
cfg.SamlSettings.AssertionConsumerServiceURL = model.NewPointer("http://" + getServerURL(t.output, t.config) + "/login/sso/saml")
cfg.SamlSettings.AssertionConsumerServiceURL = model.NewPointer(t.config.ServerScheme + "://" + getServerURL(t.output, t.config) + "/login/sso/saml")
cfg.SamlSettings.SignatureAlgorithm = model.NewPointer("RSAwithSHA1")
cfg.SamlSettings.CanonicalAlgorithm = model.NewPointer("Canonical1.0")
cfg.SamlSettings.ScopingIDPProviderId = model.NewPointer("")
Expand Down
4 changes: 2 additions & 2 deletions deployment/terraform/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (t *Terraform) getAsset(filename string) string {
// 4. First app server IP
func getServerURL(output *Output, deploymentConfig *deployment.Config) string {
if deploymentConfig.ServerURL != "" {
return deploymentConfig.ServerURL
return deploymentConfig.ServerScheme + "://" + deploymentConfig.ServerURL
}

url := output.Instances[0].PrivateIP
Expand All @@ -344,7 +344,7 @@ func getServerURL(output *Output, deploymentConfig *deployment.Config) string {
url = output.Proxies[0].PrivateIP
}

return url
return deploymentConfig.ServerScheme + "://" + url
}

// GetAWSConfig returns the AWS config, using the profile configured in the
Expand Down
41 changes: 30 additions & 11 deletions deployment/terraform/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ func TestGetServerURL(t *testing.T) {
PrivateIP: "localhost",
}},
},
config: &deployment.Config{},
expected: "localhost:8065",
config: &deployment.Config{
ServerScheme: "http",
},
expected: "http://localhost:8065",
}, {
name: "proxy, no siteurl",
output: &Output{
Expand All @@ -62,8 +64,10 @@ func TestGetServerURL(t *testing.T) {
PrivateIP: "proxy_ip",
}},
},
config: &deployment.Config{},
expected: "proxy_ip",
config: &deployment.Config{
ServerScheme: "http",
},
expected: "http://proxy_ip",
}, {
name: "no proxy, siteurl",
output: &Output{
Expand All @@ -72,9 +76,10 @@ func TestGetServerURL(t *testing.T) {
}},
},
config: &deployment.Config{
SiteURL: "ltserver",
SiteURL: "ltserver",
ServerScheme: "http",
},
expected: "ltserver:8065",
expected: "http://ltserver:8065",
}, {
name: "proxy, siteurl",
output: &Output{
Expand All @@ -86,9 +91,10 @@ func TestGetServerURL(t *testing.T) {
}},
},
config: &deployment.Config{
SiteURL: "ltserver",
SiteURL: "ltserver",
ServerScheme: "http",
},
expected: "ltserver",
expected: "http://ltserver",
}, {
name: "serverurl takes priority",
output: &Output{
Expand All @@ -100,10 +106,23 @@ func TestGetServerURL(t *testing.T) {
}},
},
config: &deployment.Config{
SiteURL: "siteurl",
ServerURL: "serverurl",
SiteURL: "siteurl",
ServerURL: "serverurl",
ServerScheme: "http",
},
expected: "http://serverurl",
}, {
name: "https is supported",
output: &Output{
Instances: []Instance{{
PrivateIP: "localhost",
}},
},
config: &deployment.Config{
SiteURL: "ltserver",
ServerScheme: "https",
},
expected: "serverurl",
expected: "https://ltserver:8065",
},
} {
t.Run(tc.name, func(t *testing.T) {
Expand Down
12 changes: 12 additions & 0 deletions docs/config/deployer.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,18 @@ The name of a host that will be used for two purposes:
- It will populate a new entry in the /etc/hosts file of the app nodes, so that it points to the proxy private IP or, if there's no proxy, to the current app node.
This config is used for tests that require an existing database dump that contains permalinks. These permalinks point to a specific hostname. Without this setting, that hostname is not known by the nodes of a new deployment and the permalinks cannot be resolved.

## ServerURL

*string*

The URL of the Mattermost server. This is used to override the server's `SiteURL` setting for specific scenarios where a different URL is needed on deployments without the proxy server.

## ServerScheme

*string*

The scheme of the Mattermost server. Defaults to `http`.

## UsersFilePath

*string*
Expand Down
Loading