Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: reject GitOps workflow config if —external-url is not set (#4885)
Tianzhou (天舟)6ba3a32ae62e
diff --git a/backend/bin/server/cmd/root.go b/backend/bin/server/cmd/root.goindex 4894115a05..3c60416f79 100644--- a/backend/bin/server/cmd/root.go+++ b/backend/bin/server/cmd/root.go@@ -118,7 +118,7 @@ func init() {// 1. Constructing the correct callback URL when configuring the VCS provider. The callback URL points to the frontend.// 2. Creating the correct webhook endpoint when configuring the project GitOps workflow. The webhook endpoint points to the backend.// Since frontend and backend are bundled and run on the same address in the release build, thus we just need to specify a single external URL.- rootCmd.PersistentFlags().StringVar(&flags.externalURL, "external-url", common.ExternalURLDocsLink, "the external URL where user visits Bytebase, must start with http:// or https://")+ rootCmd.PersistentFlags().StringVar(&flags.externalURL, "external-url", common.ExternalURLPlaceholder, "the external URL where user visits Bytebase, must start with http:// or https://")rootCmd.PersistentFlags().StringVar(&flags.dataDir, "data", ".", "directory where Bytebase stores data. If relative path is supplied, then the path is relative to the directory where Bytebase is under")rootCmd.PersistentFlags().BoolVar(&flags.readonly, "readonly", false, "whether to run in read-only mode")// Must be one of the subpath name in the ./store/demo/ directory@@ -284,8 +284,8 @@ func start() {}externalAddr := profile.ExternalURL- if profile.ExternalURL == common.ExternalURLDocsLink {- externalAddr = fmt.Sprintf("!!! You have not set --external-url. If you want to make Bytebase\n!!! externally accessible, follow:\n\n%s", common.ExternalURLDocsLink)+ if profile.ExternalURL == common.ExternalURLPlaceholder {+ externalAddr = fmt.Sprintf("!!! You have not set --external-url. If you want to make Bytebase\n!!! externally accessible, follow:\n\n%s", common.ExternalURLPlaceholder)}fmt.Printf(greetingBanner, fmt.Sprintf("Version %s (schema version %v) has started on port %d", profile.Version, s.SchemaVersion, flags.port), externalAddr)diff --git a/backend/common/config.go b/backend/common/config.goindex 099c7d78ad..b8bba60d0f 100644--- a/backend/common/config.go+++ b/backend/common/config.go@@ -1,3 +1,4 @@+// Package common provides common libraries for the service.package common// ReleaseMode is the mode for release, such as dev or release.diff --git a/backend/common/docs.go b/backend/common/docs.godeleted file mode 100644index 9a64faa2e0..0000000000--- a/backend/common/docs.go+++ /dev/null@@ -1,7 +0,0 @@-// Package common provides common libraries for the service.-package common--const (- // ExternalURLDocsLink is the docs link to configure --external-url.- ExternalURLDocsLink = "https://www.bytebase.com/docs/get-started/install/external-url"-)diff --git a/backend/common/util.go b/backend/common/util.goindex e6a66d8761..b62e74ba0a 100644--- a/backend/common/util.go+++ b/backend/common/util.go@@ -14,8 +14,12 @@ import ("time")-// MaxSheetSize is the maximum size of a sheet for displaying.-const MaxSheetSize = 10240+const (+ // MaxSheetSize is the maximum size of a sheet for displaying.+ MaxSheetSize = 10240+ // ExternalURLPlaceholder is the docs link to configure --external-url.+ ExternalURLPlaceholder = "https://www.bytebase.com/docs/get-started/install/external-url"+)// FindString returns the search index of sorted strings.func FindString(stringList []string, search string) int {diff --git a/backend/server/project.go b/backend/server/project.goindex 5257e01a93..e9255322eb 100644--- a/backend/server/project.go+++ b/backend/server/project.go@@ -308,6 +308,12 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {repositoryCreate.WebhookSecretToken = repo.WebhookSecretTokenrepositoryCreate.ExternalWebhookID = repo.ExternalWebhookID} else {+ // Bytebase needs to create a webbook in the connecting repository pointing back to the+ // Bytebase address exposed at --external-url.+ if s.profile.ExternalURL == common.ExternalURLPlaceholder {+ return echo.NewHTTPError(http.StatusBadRequest, "Bytebase must start with --external-url to configure GitOps workflow")+ }+repositoryCreate.WebhookEndpointID = fmt.Sprintf("%s-%d", s.workspaceID, time.Now().Unix())secretToken, err := common.RandomString(gitlab.SecretTokenLength)if err != nil {diff --git a/backend/server/server_frontend_embed.go b/backend/server/server_frontend_embed.goindex b065d26316..aabede4289 100644--- a/backend/server/server_frontend_embed.go+++ b/backend/server/server_frontend_embed.go@@ -56,8 +56,8 @@ func oauthRedirectURL(externalURL string) string {}func oauthErrorMessage(externalURL string) string {- if externalURL == common.ExternalURLDocsLink {- return fmt.Sprintf("Failed to exchange OAuth token. You have not configured --external-url, please follow %s", common.ExternalURLDocsLink)+ if externalURL == common.ExternalURLPlaceholder {+ return fmt.Sprintf("Failed to exchange OAuth token. You have not configured --external-url, please follow %s", common.ExternalURLPlaceholder)}return fmt.Sprintf("Failed to exchange OAuth token. Make sure --external-url %s matches your browser host. Note that if you are not using port 80 or 443, you should also specify the port such as --external-url=http://host:port", externalURL)}