Skip to content

Fix Complement not using HSPortBindingIP (127.0.0.1) for the homeserver BaseURL #781

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

Merged
merged 15 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/docker/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ func printPortBindingsOfAllComplementContainers(docker *client.Client, contextSt
log.Printf("=============== %s : END ALL COMPLEMENT DOCKER PORT BINDINGS ===============\n\n\n", contextStr)
}

// Transform the homeserver ports into the base URL and federation base URL.
func endpoints(p nat.PortMap, hsPortBindingIP string, csPort, ssPort int) (baseURL, fedBaseURL string, err error) {
csapiPortBinding, err := findPortBinding(p, hsPortBindingIP, csPort)
if err != nil {
Expand All @@ -554,7 +555,12 @@ func endpoints(p nat.PortMap, hsPortBindingIP string, csPort, ssPort int) (baseU
return
}

// Find a matching port binding for the given host/port in the nat.PortMap.
// Find a matching port binding for the given host/port in the `nat.PortMap`.
//
// This function will return the first port binding that matches the given host IP. If a
// `0.0.0.0` binding is found, we will assume that it is listening on all interfaces,
// including the `hsPortBindingIP`, and return a binding with the `hsPortBindingIP` as
// the host IP.
func findPortBinding(p nat.PortMap, hsPortBindingIP string, port int) (portBinding nat.PortBinding, err error) {
portString := fmt.Sprintf("%d/tcp", port)
portBindings, ok := p[nat.Port(portString)]
Expand Down
13 changes: 8 additions & 5 deletions internal/docker/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ func assertHostnameEqual(inputUrl string, expectedHostname string) error {
return nil
}

// Returns URL's that are accessible from the host machine (outside the container) for
// the homeserver's client API and federation API.
func getHostAccessibleHomeserverUrls(ctx context.Context, docker *client.Client, containerID string, hsPortBindingIP string) (baseURL string, fedBaseURL string, err error) {
inspectResponse, err := inspectPortsOnContainer(ctx, docker, containerID)
if err != nil {
Expand All @@ -537,10 +539,10 @@ func getHostAccessibleHomeserverUrls(ctx context.Context, docker *client.Client,

baseURL, fedBaseURL, err = endpoints(inspectResponse.NetworkSettings.Ports, hsPortBindingIP, 8008, 8448)

// Sanity check that the URL's match the expected binding hostname. It's important
// that we use the canonical publically accessible hostname for the homeserver as ...
// such as important cookies that are set during a SSO/OIDC login process (cookies are
// scoped to the domain).
// Sanity check that the URL's match the expected configured binding hostname. It's
// also important that we use the canonical publicly accessible hostname for the
// homeserver for some situations like SSO/OIDC login where important cookies are set
// for the domain.
err = assertHostnameEqual(baseURL, hsPortBindingIP)
if err != nil {
return "", "", fmt.Errorf("failed to assert baseURL has the correct hostname: %w", err)
Expand Down Expand Up @@ -574,7 +576,8 @@ func waitForPorts(ctx context.Context, docker *client.Client, containerID string
type ContainerInspectionError struct {
// Error message
msg string
// Whether this error should stop retrying to inspect the container.
// Indicates whether the caller should stop retrying to inspect the container because
// it has already exited.
Fatal bool
}

Expand Down
Loading