-
Notifications
You must be signed in to change notification settings - Fork 7k
feat: Allow multiple extenal URLs for SSO access #14208
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a490369
Allow multiple extenal URLs for SSO access
tjamet fc11e68
Add new field to the documentation
tjamet fa62e0f
Fix codeql issue
tjamet 6385144
Add a test to ensure validity of the documented cm
tjamet 7c87dbb
rename additionalURLs for URLs
tjamet b8f31d6
Allow responses redirected from SSO to alternate URLs
tjamet a2ee8bd
Consider dex enabled when there are additional URLs configured
tjamet a9fd852
Parse new URLs config from argocd-cm
tjamet 8cc2978
Detect additional SSO URLs from requests
tjamet 18b08d5
Handle logout properly
tjamet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,10 @@ import ( | |
| "crypto/tls" | ||
| "crypto/x509" | ||
| "encoding/base64" | ||
| "errors" | ||
| "fmt" | ||
| "math/big" | ||
| "net/http" | ||
| "net/url" | ||
| "path" | ||
| "reflect" | ||
|
|
@@ -47,6 +49,9 @@ type ArgoCDSettings struct { | |
| // URL is the externally facing URL users will visit to reach Argo CD. | ||
| // The value here is used when configuring SSO. Omitting this value will disable SSO. | ||
| URL string `json:"url,omitempty"` | ||
| // URLs is a list of externally facing URLs users will visit to reach Argo CD. | ||
| // The value here is used when configuring SSO reachable from multiple domains. | ||
| URLs []string `json:"urls,omitempty"` | ||
| // Indicates if status badge is enabled or not. | ||
| StatusBadgeEnabled bool `json:"statusBadgeEnable"` | ||
| // Indicates if status badge custom root URL should be used. | ||
|
|
@@ -392,6 +397,8 @@ const ( | |
| settingServerPrivateKey = "tls.key" | ||
| // settingURLKey designates the key where Argo CD's external URL is set | ||
| settingURLKey = "url" | ||
| // settingURLsKey designates the key where Argo CD's external URLs is set | ||
| settingURLsKey = "urls" | ||
| // repositoriesKey designates the key where ArgoCDs repositories list is set | ||
| repositoriesKey = "repositories" | ||
| // repositoryCredentialsKey designates the key where ArgoCDs repositories credentials list is set | ||
|
|
@@ -1422,6 +1429,16 @@ func updateSettingsFromConfigMap(settings *ArgoCDSettings, argoCDCM *apiv1.Confi | |
| if err := validateExternalURL(argoCDCM.Data[settingUiBannerURLKey]); err != nil { | ||
| log.Warnf("Failed to validate UI banner URL in configmap: %v", err) | ||
| } | ||
| if argoCDCM.Data[settingURLsKey] != "" { | ||
| if err := yaml.Unmarshal([]byte(argoCDCM.Data[settingURLsKey]), &settings.URLs); err != nil { | ||
| log.Warnf("Failed decode all UI banner URLs in configmap: %v", err) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message does not seem accurate |
||
| } | ||
| } | ||
| for _, url := range settings.URLs { | ||
| if err := validateExternalURL(url); err != nil { | ||
| log.Warnf("Failed to validate UI banner URL in configmap: %v", err) | ||
| } | ||
| } | ||
| settings.UiBannerURL = argoCDCM.Data[settingUiBannerURLKey] | ||
| settings.UserSessionDuration = time.Hour * 24 | ||
| if userSessionDurationStr, ok := argoCDCM.Data[userSessionDurationKey]; ok { | ||
|
|
@@ -1740,7 +1757,7 @@ func (a *ArgoCDSettings) IsSSOConfigured() bool { | |
| } | ||
|
|
||
| func (a *ArgoCDSettings) IsDexConfigured() bool { | ||
| if a.URL == "" { | ||
| if a.URL == "" && len(a.URLs) == 0 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is Dex using this new URLs setting? It seems unclear if Dex should be valid if there are only URLs configured. |
||
| return false | ||
| } | ||
| dexCfg, err := UnmarshalDexConfig(a.DexConfig) | ||
|
|
@@ -1925,6 +1942,31 @@ func (a *ArgoCDSettings) RedirectURL() (string, error) { | |
| return appendURLPath(a.URL, common.CallbackEndpoint) | ||
| } | ||
|
|
||
| func (a *ArgoCDSettings) ArgoURLForRequest(r *http.Request) (string, error) { | ||
| if a == nil { | ||
| return "", errors.New("nil argocd settings") | ||
| } | ||
|
|
||
| for _, candidateURL := range append([]string{a.URL}, a.URLs...) { | ||
| u, err := url.Parse(candidateURL) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| if u.Host == r.Host && strings.HasPrefix(r.URL.RequestURI(), u.RequestURI()) { | ||
| return candidateURL, nil | ||
| } | ||
| } | ||
| return a.URL, nil | ||
| } | ||
|
|
||
| func (a *ArgoCDSettings) RedirectURLForRequest(r *http.Request) (string, error) { | ||
| base, err := a.ArgoURLForRequest(r) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return appendURLPath(base, common.CallbackEndpoint) | ||
| } | ||
|
|
||
| func (a *ArgoCDSettings) DexRedirectURL() (string, error) { | ||
| return appendURLPath(a.URL, common.DexCallbackEndpoint) | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If only the url is necessary to find the config, pass only the URL instead of the whole request object.