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

validate backend #1908

Merged
merged 8 commits into from
Feb 22, 2023
Merged

validate backend #1908

merged 8 commits into from
Feb 22, 2023

Conversation

rawdaGastan
Copy link
Contributor

if err != nil {
return fmt.Errorf("failed to parse backend with error: %w", err)
}
if port == "" {
Copy link
Member

Choose a reason for hiding this comment

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

This is not necessary, if you check the code for the SplitHostPort function you see that it already return error if the format is wrong or if the port is empty.

But it does validate that the IP value or the Port value are valid. hence parsing of the splited ip, and port still need to be done of course

if u.Port() == "" {
return fmt.Errorf("missing port in backend address")

parsedPort, err := strconv.ParseInt(port, 10, 64)
Copy link
Member

Choose a reason for hiding this comment

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

use ParseUint instead, since a negative value is illegal.

pkg/gridtypes/zos/gw_fqdn.go Outdated Show resolved Hide resolved
xmonader
xmonader previously approved these changes Feb 21, 2023
Copy link
Member

@muhamadazmy muhamadazmy left a comment

Choose a reason for hiding this comment

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

Okay, this looks much better. Except this is only half the work. This only fix the validation issue. but in the code where the backend actually being used is still assuming it's always a URL.

Please check the code here
https://github.com/threefoldtech/zos/blob/main/pkg/gateway/gateway.go#L569

If you need to change few things so the validation and processing of the Backend value is not replicated everywhere.

I suggest replace the Valid function with instead some another function (say Parse(tls bool), or something else that return (string, error) where the error is return if it's not valid, but the string is the value that need to be used as backend in the configuration

return "", fmt.Errorf("port '%s' must be <= 65535", port)
}

hostName = host
Copy link
Member

Choose a reason for hiding this comment

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

this is wrong because you need to return ip:port in case of tls, or http://ip:port in case of no tls

}
u, err := url.Parse(backend)
log.Debug().Str("hostname", u.Host).Str("backend", backend).Msg("tls passthrough")
host, err := zos.Backend(backend).Parse(true)
Copy link
Member

Choose a reason for hiding this comment

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

this is still wrong because instead it can be like

for idx, backend := range backends {
   u, err := zos.Backend(backend).Parse(TLSPassthrout)
    // check error
   if TLSPassthrough {
   servers[ids] = Server{ Address: u} 
   } else {
   servers[idx] = Server{ Url: u} 
  } 
}

@muhamadazmy muhamadazmy merged commit 23cfd55 into main Feb 22, 2023
@muhamadazmy muhamadazmy deleted the development_backend_validate branch February 22, 2023 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants