-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from cloudscale-ch/denis/lb-status-hostname
Add option to prevent cluster-traffic from bypassing loadbalancers
- Loading branch information
Showing
8 changed files
with
432 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/cloudscale-ch/cloudscale-cloud-controller-manager/cmd/http-echo | ||
|
||
go 1.23.0 | ||
|
||
require github.com/pires/go-proxyproto v0.7.0 |
This file contains 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/pires/go-proxyproto v0.7.0 h1:IukmRewDQFWC7kfnb66CSomk2q/seBuilHBYFwyq0Hs= | ||
github.com/pires/go-proxyproto v0.7.0/go.mod h1:Vz/1JPY/OACxWGQNIRY2BeyDmpoaWmEP40O9LbuiFR4= |
This file contains 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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// A http echo server to get information about connections made to it. | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"net" | ||
"net/http" | ||
"time" | ||
|
||
proxyproto "github.com/pires/go-proxyproto" | ||
) | ||
|
||
func main() { | ||
host := flag.String("host", "127.0.0.1", "Host to connect to") | ||
port := flag.Int("port", 8080, "Port to connect to") | ||
|
||
flag.Parse() | ||
|
||
serve(*host, *port) | ||
} | ||
|
||
// log http requests in basic fashion | ||
func log(h http.Handler) http.Handler { | ||
return http.HandlerFunc( | ||
func(w http.ResponseWriter, r *http.Request) { | ||
h.ServeHTTP(w, r) | ||
fmt.Printf("%s %s (%s)\n", r.Method, r.RequestURI, r.RemoteAddr) | ||
}) | ||
} | ||
|
||
// serve HTTP API on the given host and port | ||
func serve(host string, port int) { | ||
router := http.NewServeMux() | ||
|
||
// Returns 'true' if the PROXY protocol was used for the given connection | ||
router.HandleFunc("GET /proxy-protocol/used", | ||
func(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintln(w, r.Context().Value("HasProxyHeader")) | ||
}) | ||
|
||
addr := fmt.Sprintf("%s:%d", host, port) | ||
|
||
server := http.Server{ | ||
Addr: addr, | ||
Handler: log(router), | ||
ConnContext: func(ctx context.Context, c net.Conn) context.Context { | ||
hasProxyHeader := false | ||
|
||
if c, ok := c.(*proxyproto.Conn); ok { | ||
hasProxyHeader = c.ProxyHeader() != nil | ||
} | ||
|
||
return context.WithValue(ctx, "HasProxyHeader", hasProxyHeader) | ||
}, | ||
} | ||
|
||
listener, err := net.Listen("tcp", server.Addr) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Printf("Listening on %s\n", addr) | ||
|
||
proxyListener := &proxyproto.Listener{ | ||
Listener: listener, | ||
ReadHeaderTimeout: 10 * time.Second, | ||
} | ||
defer proxyListener.Close() | ||
|
||
server.Serve(proxyListener) | ||
} |
This file contains 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 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
Oops, something went wrong.