Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(rexctl): match the edge itself when DNS points to a proxy (#3591)

Hampusec05bc2a5adc
diff --git a/deploy/helm/fluxer/files/Caddyfile b/deploy/helm/fluxer/files/Caddyfile
index f64a3fa4a..ea06f1326 100644
--- a/deploy/helm/fluxer/files/Caddyfile
+++ b/deploy/helm/fluxer/files/Caddyfile
@@ -24,6 +24,11 @@
respond "OK" 200
}
+ handle /_edge {
+ header Cache-Control no-store
+ respond "{system.hostname}" 200
+ }
+
handle_path /api/* {
import upstream api:8080
}
@@ -72,4 +77,8 @@
handle /.well-known/fluxer {
import upstream api:8080
}
+
+ handle /_edge {
+ respond "{system.hostname}" 200
+ }
}
diff --git a/fluxer_rexctl/internal/checks/dns.go b/fluxer_rexctl/internal/checks/dns.go
index 41ba9dfaa..d6d18e168 100644
--- a/fluxer_rexctl/internal/checks/dns.go
+++ b/fluxer_rexctl/internal/checks/dns.go
@@ -4,7 +4,6 @@ package checks
import (
"context"
- "encoding/json"
"errors"
"fmt"
"io"
@@ -87,17 +86,17 @@ func (e *Env) forwardsHere(ctx context.Context) bool {
if e.Instance == nil || !e.running(ctx, "edge") {
return false
}
- local, err := e.discoveryDoc(ctx)
- if err != nil {
+ local, err := e.exec(ctx, "edge", "", "wget", "-q", "-O", "-", "http://127.0.0.1:8088/_edge")
+ if err != nil || local == "" {
return false
}
- return servesInstance(ctx, e.Domain, local)
+ return servesEdge(ctx, e.Domain, local)
}
-func servesInstance(ctx context.Context, domain, local string) bool {
+func servesEdge(ctx context.Context, domain, local string) bool {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
- req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://"+domain+"/.well-known/fluxer", nil)
+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://"+domain+"/_edge", nil)
if err != nil {
return false
}
@@ -106,23 +105,6 @@ func servesInstance(ctx context.Context, domain, local string) bool {
return false
}
defer resp.Body.Close()
- remote, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
- if err != nil || resp.StatusCode != http.StatusOK {
- return false
- }
- key := instanceKey(local)
- return key != "" && key == instanceKey(string(remote))
-}
-
-func instanceKey(doc string) string {
- var d struct {
- Push struct {
- Key string `json:"public_vapid_key"`
- } `json:"push"`
- }
- start := strings.Index(doc, "{")
- if start < 0 || json.Unmarshal([]byte(doc[start:]), &d) != nil {
- return ""
- }
- return d.Push.Key
+ remote, err := io.ReadAll(io.LimitReader(resp.Body, 1<<10))
+ return err == nil && resp.StatusCode == http.StatusOK && strings.TrimSpace(string(remote)) == local
}
diff --git a/fluxer_rexctl/internal/instance/adopt_known.go b/fluxer_rexctl/internal/instance/adopt_known.go
index 528041e8d..c27fd4ad8 100644
--- a/fluxer_rexctl/internal/instance/adopt_known.go
+++ b/fluxer_rexctl/internal/instance/adopt_known.go
@@ -131,6 +131,7 @@ var shippedHashes = map[string][]string{
"7fd66a72a740258ed71fcaebce927bdc9b2528177cfeb5ca9e0c0ee778dd8769",
"cb68f62d48bc54bc908840c6dce85843ac5580e6196e5a9b978dd14ffb3d5280",
"e9ab1a7ad99211172f68cfa2728beeb86dd4ed220635cab5f8461bb2b49cb023",
+ "6f88e16d9fa2d2c57431304bcdb1384236ad0f82f3e205692e10050c57381352",
"f02d23b1c650c157ab53ee7cc2057c0d6dec7b93f5dbd99982c594cdd6c766d1",
},
".env.example": {
diff --git a/fluxer_rexctl/internal/stack/files/Caddyfile b/fluxer_rexctl/internal/stack/files/Caddyfile
index f64a3fa4a..ea06f1326 100644
--- a/fluxer_rexctl/internal/stack/files/Caddyfile
+++ b/fluxer_rexctl/internal/stack/files/Caddyfile
@@ -24,6 +24,11 @@
respond "OK" 200
}
+ handle /_edge {
+ header Cache-Control no-store
+ respond "{system.hostname}" 200
+ }
+
handle_path /api/* {
import upstream api:8080
}
@@ -72,4 +77,8 @@
handle /.well-known/fluxer {
import upstream api:8080
}
+
+ handle /_edge {
+ respond "{system.hostname}" 200
+ }
}