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

Rebuild app fqdn based on inferred proxy public addr #52718

Open
wants to merge 3 commits into
base: avatus/use_proxy_addr
Choose a base branch
from

Conversation

avatus
Copy link
Contributor

@avatus avatus commented Mar 3, 2025

This allows web apps to be launched and authenticated from any registered proxy public addr. The web launcher will use the fqdn-only launch path for apps with this flag (AlwaysUseProxyPublicAddr).

Requires #52693

to test:
in your proxy config, add a couple different public_addr. make sure your certs are valid for these domains

you can add always_use_proxy_public_addr in your app spec. in the web UI, you should now see something like "appName.proxyPublicAddrYouAreOn" in the webUI on the app's card. this value should change depending on what proxy public addr you are on. also, when you authenticate the app, the destination should match that public addr. apps without these field set should work as expected (show the first public addr regardless of what proxy public addr youre on)

@avatus avatus added the no-changelog Indicates that a PR does not require a changelog entry label Mar 3, 2025
@avatus avatus requested review from flyinghermit and kimlisa March 3, 2025 18:31
@avatus avatus marked this pull request as ready for review March 3, 2025 18:48
@avatus avatus marked this pull request as draft March 3, 2025 18:59
@avatus avatus force-pushed the avatus/web_proxy_addr branch from 62b3472 to 2d56b07 Compare March 3, 2025 19:28
@avatus avatus marked this pull request as ready for review March 4, 2025 00:18
@github-actions github-actions bot requested review from gzdunek and ravicious March 4, 2025 00:18
Comment on lines +41 to +46
// InferProxyPublicAddr tries to extract a proxyDNSName from a given fqdn and the list of proxy public addrs.
// If a proxyDNS name is not found, the default param will be returned.
func InferProxyPublicAddr(fqdn string, proxyDNSNames []string, defaultPublicAddr string) string {
if fqdn == "" || defaultPublicAddr == "" {
return defaultPublicAddr
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Two questions:

  1. What is the source of defaultPublicAddr? Does it come from app config spec or is calculated from some other values?
  2. What are the implication of returning an empty string? Should we return an error here if the value is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the source is at the callsite. its up to the caller to pass in a default value, and if they pass in an empty string, it would be because they want to default to empty if the proxyDNSName cannot be inferred (i dont have a use case for it, but i dont think an error should be called here)

however, i wont die on this hill. tbh, the signature without any error is easier to deal with where this is called but, thats my only excuse

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. From the name of the function, it seems like caller depends on the correct address to be inferred. As such, I would expect it to be explicitly return an inferred value or an error if it cant.

Alternatively, if we are sure that the empty return value is handeld at every call site, then maybe just explaining that in the comment would be ok too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also please double check that if the we expect public_addr field from app spec to be not empty. I did a quick look and only found the value is checked to be a valid fqdn. I think whatever value this function returns, we should ensure the value is verified exactly as we do for the public_addr field.

RequiresRequest: c.RequiresRequest,
Integration: app.GetIntegration(),
PermissionSets: permissionSets,
AlwaysUseProxyPublicAddr: app.GetAlwaysUseProxyPublicAddr(),
Copy link
Contributor

@flyinghermit flyinghermit Mar 4, 2025

Choose a reason for hiding this comment

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

suggestion for the field name: useProxyPublicAddrAsFQDN so it conveys what the proxy public addr will be used for. Also a Godoc to explain that please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its not quite as simple as that name suggests, but i do agree my name isnt the best either.
whats actually happening is
"UseProxyPublicAddrFromThisRequestPrefixedWithAppNameAsFQDN" lol but that doesnt flow off the tongue

right now, our proxy allows multiple configured publicAddr, but for apps, unless they have a publicaddr specified explicitly, the apps public addr is just "appName.proxyPublicAddrs[0]".

however, this means if someone wants to access the app from some other proxyPublicAddr, they would have to then get redirected and authenticated with that publicaddr and all that yada yada yada.

I think I'll keep this field name but i will definitely expand upon the godoc for sure, also see here #52693 for more convo. maybe the field name will change there as well

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is "always" that makes the name a bit controversial lol. Still think useProxyPublicAddrAsFQDN better suits here but I will let you decide on that. We add app name as prefix to that is an implementation detailed explained in a comment should suffice.

@avatus avatus removed request for ravicious and gzdunek March 5, 2025 18:04
@avatus avatus force-pushed the avatus/use_proxy_addr branch from ab39323 to 6e528e2 Compare March 5, 2025 18:51
@avatus avatus force-pushed the avatus/web_proxy_addr branch from 2d56b07 to 34acece Compare March 5, 2025 18:54
@avatus avatus force-pushed the avatus/use_proxy_addr branch from 6e528e2 to 2715530 Compare March 5, 2025 19:00
@avatus avatus force-pushed the avatus/web_proxy_addr branch from 34acece to abcfcd8 Compare March 5, 2025 19:01
@avatus avatus force-pushed the avatus/use_proxy_addr branch from 2715530 to 2fa7b9d Compare March 5, 2025 19:07
@avatus avatus force-pushed the avatus/web_proxy_addr branch from abcfcd8 to 8660d82 Compare March 5, 2025 19:08
@avatus avatus force-pushed the avatus/use_proxy_addr branch from 2fa7b9d to d317cc6 Compare March 5, 2025 19:17
This allows web apps to be launched and authenticated from any
registered proxy public addr. The web launcher will use the fqdn-only
launch path for apps with this flag (AlwaysUseProxyPublicAddr).
@avatus avatus force-pushed the avatus/web_proxy_addr branch from 8660d82 to 7cfc788 Compare March 5, 2025 19:19
@avatus avatus requested a review from flyinghermit March 5, 2025 19:27
@avatus
Copy link
Contributor Author

avatus commented Mar 5, 2025

added steps to test in the description

Copy link
Contributor

@flyinghermit flyinghermit left a comment

Choose a reason for hiding this comment

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

Looks good overall

@@ -35,3 +37,23 @@ func ClientIPFromConn(conn net.Conn) (string, error) {

return clientIP, nil
}

// InferProxyPublicAddr tries to extract a proxyDNSName from a given fqdn and the list of proxy public addrs.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// InferProxyPublicAddr tries to extract a proxyDNSName from a given fqdn and the list of proxy public addrs.
// InferProxyPublicAddr tries to extract a proxyDNSName from a given app FQDN and the list of proxy public addrs.

I think this comment also warrant some more explanation on what each params field expects and how should the caller treat empty string return value.

Comment on lines +41 to +46
// InferProxyPublicAddr tries to extract a proxyDNSName from a given fqdn and the list of proxy public addrs.
// If a proxyDNS name is not found, the default param will be returned.
func InferProxyPublicAddr(fqdn string, proxyDNSNames []string, defaultPublicAddr string) string {
if fqdn == "" || defaultPublicAddr == "" {
return defaultPublicAddr
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. From the name of the function, it seems like caller depends on the correct address to be inferred. As such, I would expect it to be explicitly return an inferred value or an error if it cant.

Alternatively, if we are sure that the empty return value is handeld at every call site, then maybe just explaining that in the comment would be ok too.

name: "Exact match",
fqdn: "proxy.example.com",
proxyDNSNames: []string{"proxy.example.com"},
defaultPublicAddr: "default",
Copy link
Contributor

Choose a reason for hiding this comment

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

what is defaultPublicAddr. Is it the public_addr value from app spec?

Also can we use fqdn value instead of "default" string.

RequiresRequest: c.RequiresRequest,
Integration: app.GetIntegration(),
PermissionSets: permissionSets,
AlwaysUseProxyPublicAddr: app.GetAlwaysUseProxyPublicAddr(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is "always" that makes the name a bit controversial lol. Still think useProxyPublicAddrAsFQDN better suits here but I will let you decide on that. We add app name as prefix to that is an implementation detailed explained in a comment should suffice.

Comment on lines +41 to +46
// InferProxyPublicAddr tries to extract a proxyDNSName from a given fqdn and the list of proxy public addrs.
// If a proxyDNS name is not found, the default param will be returned.
func InferProxyPublicAddr(fqdn string, proxyDNSNames []string, defaultPublicAddr string) string {
if fqdn == "" || defaultPublicAddr == "" {
return defaultPublicAddr
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Also please double check that if the we expect public_addr field from app spec to be not empty. I did a quick look and only found the value is checked to be a valid fqdn. I think whatever value this function returns, we should ensure the value is verified exactly as we do for the public_addr field.

@@ -121,7 +128,9 @@ type MakeAppsConfig struct {
// MakeApp creates an application object for the WebUI.
func MakeApp(app types.Application, c MakeAppsConfig) App {
labels := ui.MakeLabelsWithoutInternalPrefixes(app.GetAllLabels())
fqdn := utils.AssembleAppFQDN(c.LocalClusterName, c.LocalProxyDNSName, c.AppClusterName, app)
proxyPublicAddr := utils.InferProxyPublicAddr(c.RequestHost, c.ProxyPublicAddrs, c.LocalProxyDNSName)
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, the value of c.RequestHost should always match one of the value in the ProxyPublicAddrs right? cause this request handled in the proxy itself.

Is it that if AlwaysUseProxyPublicAddr is true, can we directly use proxyPublicAddr = c.RequestHost ?

fqdn := utils.AssembleAppFQDN(c.LocalClusterName, c.LocalProxyDNSName, c.AppClusterName, app)
proxyPublicAddr := utils.InferProxyPublicAddr(c.RequestHost, c.ProxyPublicAddrs, c.LocalProxyDNSName)

fqdn := utils.AssembleAppFQDN(c.LocalClusterName, proxyPublicAddr, c.AppClusterName, app)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we update TestMakeApps to cover that fqdn is derived as expected when AlwaysUseProxyPublicAddr is true/false?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Indicates that a PR does not require a changelog entry size/md ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants