-
Notifications
You must be signed in to change notification settings - Fork 886
feat: implement bitbucket-server external auth defaults #10520
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
Conversation
Bitbucket cloud != Bitbucket server Add reasonable defaults for server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll let @spikecurtis review the go
code, but the Bitbucket configuration variables look good.
coderd/externalauth/externalauth.go
Outdated
@@ -493,8 +494,27 @@ func ConvertConfig(entries []codersdk.ExternalAuthConfig, accessURL *url.URL) ([ | |||
} | |||
|
|||
// applyDefaultsToConfig applies defaults to the config entry. | |||
func applyDefaultsToConfig(config *codersdk.ExternalAuthConfig) { | |||
defaults := defaults[codersdk.EnhancedExternalAuthProvider(config.Type)] | |||
func configDefaults(config *codersdk.ExternalAuthConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why shorten the name? configDefaults
seems like it could return defaults, whereas apply states that it'd apply to the arg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed. I just had to make another func that actually applies the defaults. See new names of applyDefaultsToConfig
and copyDefaultSettings(config *codersdk.ExternalAuthConfig, defaults codersdk.ExternalAuthConfig)
|
||
// Populate Regex, ValidateURL, and TokenURL. | ||
// Default regex should be anything using the same host as the auth url. | ||
defaults.Regex = fmt.Sprintf(`^(https?://)?%s(/.*)?$`, strings.ReplaceAll(auth.Host, ".", `\.`)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we be doing these for all of them? Seems like making it just for BitBucket server is weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps the self-hosted ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do.
Azure
coder/coderd/externalauth/externalauth.go
Line 607 in 84509a1
Regex: `^(https?://)?dev\.azure\.com(/.*)?$`, |
Bitbucket Cloud
coder/coderd/externalauth/externalauth.go
Line 616 in 84509a1
Regex: `^(https?://)?bitbucket\.org(/.*)?$`, |
Gitlab
coder/coderd/externalauth/externalauth.go
Line 625 in 84509a1
Regex: `^(https?://)?gitlab\.com(/.*)?$`, |
Github
coder/coderd/externalauth/externalauth.go
Line 634 in 84509a1
Regex: `^(https?://)?github\.com(/.*)?$`, |
Bitbucket Server is always hosted on a different domain for each customer. So it's a dynamic regex string based on the AUTH_URL
. The other providers are all cloud based with static urls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spikecurtis yes, the self hosted ones need this dynamic approach. We need to handle them case by case. Maybe there will be generalizations, but for now I only implemented self hosted bitbucket server.
Gitlab for example can definitely have some broken defaults right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Emyrk automatically doing the Regex should be a global change in my mind; it's weird to do it for a single provider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex is automatic for all providers. As in, the default values are correct for every type now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked to @kylecarbs offline a bit.
Yes this problem exists with Gitlab and Github Enterprise. We should probably have some solution for these.
I do not want to break backwards compatibility, and I do not have the test environments to confirm those (eg, are the urls consistent? bitbucket cloud and server are different).
So for this PR, I'd rather not try and solve github enterprise and gitlab self hosted.
defer func() { | ||
// The config type determines the config ID (if unset). So change the legacy | ||
// type to the correct new type after the defaults have been configured. | ||
config.Type = string(codersdk.EnhancedExternalAuthProviderBitBucketCloud) | ||
}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused why we need to do this when we set it above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because the actual string "bitbucket" is being used in the copyDefaultSettings
function, so for legacy reasons it has to be the legacy value. But at the end of the function, we need to set it to the new type. And I just did it in a defer to not put the if statement in 2 places.
What this does
Bitbucket cloud (SaaS cloud) != Bitbucket server (self hosted)
We need reasonable defaults for
bitbucket-server
. Usingbitbucket
cloud defaults is not only confusing, but incorrect.This sets the correct oauth urls based on the
AUTH_URL
. Sets:CODER_EXTERNAL_AUTH_1_TOKEN_URL=<url>/rest/oauth2/latest/token
CODER_EXTERNAL_AUTH_1_VALIDATE_URL=<url>/rest/api/latest/inbox/pull-requests/count
CODER_EXTERNAL_AUTH_1_SCOPES="PUBLIC_REPOS,REPO_READ,REPO_WRITE"
CODER_EXTERNAL_AUTH_1_REGEX=^(https?://)?<host>(/.*)?$
Minimum env vars
Before
TOKEN_URL
,VALIDATE_URL
,SCOPES
, andREGEX
were all required.