Repository navigation
fix(gateway): serve only web endpoint addresses on their domain #7451
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
40bacdb
fix(server): leave the web endpoint proxy out of OpenAPI validation
otavio 6d53b5c
fix(gateway): serve only web endpoint addresses on their domain
otavio 7fa0fa3
test: serve a test stack's gateway over HTTPS
otavio 4c77012
test: cover web endpoints end to end
otavio c6d7477
test: refuse deleting another namespace's web endpoint
otavio e36d3f5
test(ui): wait for the namespace deletion before reading what is left
otavio c766b40
fix(openapi): document the 402 a namespace delete answers while billi…
otavio 3a49eea
test(ui): pin the statuses of the namespace deletions
otavio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,13 @@ | ||
| ARG GOLANG_VERSION | ||
|
|
||
| FROM golang:${GOLANG_VERSION} | ||
|
|
||
| WORKDIR /src | ||
|
|
||
| COPY main.go . | ||
|
|
||
| RUN CGO_ENABLED=0 go build -o /usr/local/bin/device-http main.go | ||
|
|
||
| USER nobody | ||
|
|
||
| ENTRYPOINT ["device-http"] |
This file contains hidden or 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,90 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "crypto/ecdsa" | ||
| "crypto/elliptic" | ||
| "crypto/rand" | ||
| "crypto/tls" | ||
| "crypto/x509" | ||
| "crypto/x509/pkix" | ||
| "encoding/json" | ||
| "log" | ||
| "math/big" | ||
| "net" | ||
| "net/http" | ||
| "os" | ||
| "time" | ||
| ) | ||
|
|
||
| type seen struct { | ||
| Name string `json:"name"` | ||
| Host string `json:"host"` | ||
| URI string `json:"uri"` | ||
| TLS bool `json:"tls"` | ||
| } | ||
|
|
||
| func selfSigned(domain string) (tls.Certificate, error) { | ||
| key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | ||
| if err != nil { | ||
| return tls.Certificate{}, err | ||
| } | ||
|
|
||
| template := &x509.Certificate{ | ||
| SerialNumber: big.NewInt(1), | ||
| Subject: pkix.Name{CommonName: domain}, | ||
| DNSNames: []string{domain}, | ||
| NotBefore: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC), | ||
| NotAfter: time.Date(2100, time.January, 1, 0, 0, 0, 0, time.UTC), | ||
| KeyUsage: x509.KeyUsageDigitalSignature, | ||
| ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, | ||
| } | ||
|
|
||
| der, err := x509.CreateCertificate(rand.Reader, template, template, &key.PublicKey, key) | ||
| if err != nil { | ||
| return tls.Certificate{}, err | ||
| } | ||
|
|
||
| return tls.Certificate{Certificate: [][]byte{der}, PrivateKey: key}, nil | ||
| } | ||
|
|
||
| func main() { | ||
| name := os.Getenv("NAME") | ||
|
|
||
| handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| w.Header().Set("Content-Type", "application/json") | ||
| if err := json.NewEncoder(w).Encode(seen{Name: name, Host: r.Host, URI: r.RequestURI, TLS: r.TLS != nil}); err != nil { | ||
| log.Printf("answering a request: %v", err) | ||
| } | ||
| }) | ||
|
|
||
| certificate, err := selfSigned(os.Getenv("TLS_DOMAIN")) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
|
|
||
| var listen net.ListenConfig | ||
|
|
||
| plainListener, err := listen.Listen(context.Background(), "tcp", os.Getenv("HTTP_ADDRESS")) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
|
|
||
| tcpListener, err := listen.Listen(context.Background(), "tcp", os.Getenv("TLS_ADDRESS")) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
|
|
||
| secureListener := tls.NewListener(tcpListener, &tls.Config{ | ||
| Certificates: []tls.Certificate{certificate}, | ||
| MinVersion: tls.VersionTLS13, | ||
| }) | ||
|
|
||
| plain := &http.Server{Handler: handler, ReadHeaderTimeout: 5 * time.Second} | ||
| secure := &http.Server{Handler: handler, ReadHeaderTimeout: 5 * time.Second} | ||
|
|
||
| go func() { log.Fatal(secure.Serve(secureListener)) }() | ||
|
|
||
| log.Print("listening") | ||
| log.Fatal(plain.Serve(plainListener)) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.