diff --git a/conformance/battery_test.go b/conformance/battery_test.go index e53837f..6ad2b96 100644 --- a/conformance/battery_test.go +++ b/conformance/battery_test.go @@ -44,7 +44,8 @@ func TestBattery(t *testing.T) { // literals were measured (rowProblems); every key Envoy's rows exercise is exercised on the files of each version's // entries or refused by its target (coverage); every row that runs on an Envoy entry's file runs on one of the files // of each version's entries or names a key its target refuses (rowCoverage), the entries of one target and version - // judged together (versions); and each entry's target has a declaration and a generator (in its subtest). + // judged together (versions); each count of rows docs/conformance.md gives is the rows the entries run + // (pageCountProblems); and each entry's target has a declaration and a generator (in its subtest). keys := format.CoreKeys(format.Proxyfile) for _, s := range scenarios { for _, e := range s.exchanges { @@ -60,7 +61,8 @@ func TestBattery(t *testing.T) { if err != nil { t.Fatal(err) } - for _, problem := range slices.Concat(rowProblems(entries, byEntry), coverage(entries, byEntry), rowCoverage(entries, byEntry)) { + for _, problem := range slices.Concat(rowProblems(entries, byEntry), coverage(entries, byEntry), rowCoverage(entries, byEntry), + pageCountProblems(entries, byEntry)) { t.Error(problem) } // The run takes the conformance lock once, when its first file needs Docker, and gives it back when TestBattery diff --git a/conformance/counts_test.go b/conformance/counts_test.go new file mode 100644 index 0000000..5a0e346 --- /dev/null +++ b/conformance/counts_test.go @@ -0,0 +1,169 @@ +package conformance + +import ( + "fmt" + "maps" + "os" + "regexp" + "slices" + "strconv" + "strings" +) + +// countsPage is the page that says how many rows each entry runs, from this package's folder, and pageName its name +// from the repository's root, which a failure names. +const ( + countsPage = "../docs/conformance.md" + pageName = "docs/conformance.md" +) + +// countedGroup is entries the page gives one count of rows for, named there by words such as "each HAProxy entry", so +// every entry of a group must run the same rows on the same files. +type countedGroup struct { + words string + holds func(target) bool +} + +// otelImage reports whether tg runs one of nginx's images tagged -otel, the images pinnedImages reads from +// scripts/nginx-otel-images. +func otelImage(tg target) bool { return strings.Contains(tg.image, "-otel@") } + +// countedGroups are the groups the page counts rows for, in its order; each entry belongs to one. +var countedGroups = []countedGroup{ + {words: "Envoy's entry", holds: func(tg target) bool { return tg.name == "envoy" }}, + {words: "each nginx entry on the plain image", holds: func(tg target) bool { return tg.name == "nginx" && !otelImage(tg) }}, + {words: "each nginx entry on the image tagged `-otel`", holds: func(tg target) bool { return tg.name == "nginx" && otelImage(tg) }}, + {words: "each HAProxy entry", holds: func(tg target) bool { return tg.name == "haproxy" }}, +} + +// The passage that gives the counts, read with its white space made single spaces: the rows of each group on each +// file, a clause for each group in "; ", then "That is" each group's rows and the rows in all. A count is a number of +// one or more digits, written with commas, and the passage holds no other number, so one the battery cannot read in +// these forms fails the run rather than go unchecked. +var ( + countsPassage = regexp.MustCompile("The scenarios run in this order: (.*?)\\. That is (.*?), ([0-9][0-9,]*) in all\\b") + countOnFile = regexp.MustCompile("([0-9][0-9,]*) (?:rows )?on `([^`]+)`") + countNumber = regexp.MustCompile("[0-9][0-9,]*") + backquoted = regexp.MustCompile("`[^`]*`") +) + +// rowsOnFiles returns, by file label, how many rows run on each of files that runs one (fileKeys.runs). +func rowsOnFiles(files []fileKeys) map[string]int { + counts := map[string]int{} + for _, f := range files { + for _, s := range scenarios { + for _, e := range s.exchanges { + if f.runs(s, e) { + counts[f.label]++ + } + } + } + } + return counts +} + +// pageCountProblems returns a line for each count of rows docs/conformance.md gives that differs from what the +// entries run, with the page's number and the counted one: the rows of each group of entries on each of its files, +// those of each group, and those in all. The counts used to be kept by hand, and went stale each time a row was added. +// It also returns a line when the page names a file a group runs no row on, when two entries of one group run +// different rows, and when an entry belongs to no group or to two, as the page gives one count for each group. +func pageCountProblems(ts []target, byEntry map[string][]fileKeys) []string { + text, err := os.ReadFile(countsPage) + if err != nil { + return []string{fmt.Sprintf("reading the counts of rows: %v", err)} + } + passage := countsPassage.FindStringSubmatch(strings.Join(strings.Fields(string(text)), " ")) + if passage == nil { + return []string{fmt.Sprintf("%s holds no passage from %q to %q, which gives the rows each entry runs", pageName, + "The scenarios run in this order: ", "in all")} + } + breakdown, totals := passage[1], passage[2] + var lines []string + for _, part := range []struct { + text string + read int + }{{breakdown, len(countOnFile.FindAllString(breakdown, -1))}, {totals, len(countedGroups)}} { + if found := len(countNumber.FindAllString(backquoted.ReplaceAllString(part.text, ""), -1)); found != part.read { + lines = append(lines, fmt.Sprintf("%s holds %d numbers in %q, and the battery reads %d of them as counts", pageName, found, part.text, part.read)) + } + } + for _, tg := range ts { + groups := 0 + for _, g := range countedGroups { + if g.holds(tg) { + groups++ + } + } + if groups != 1 { + lines = append(lines, fmt.Sprintf("entry %s belongs to %d of the groups %s counts rows for, where it must belong to one", tg.label, groups, pageName)) + } + } + clauses := strings.Split(breakdown, "; ") + all := 0 + for _, g := range countedGroups { + var first string + var counted map[string]int + for _, tg := range ts { + if !g.holds(tg) { + continue + } + runs := rowsOnFiles(byEntry[tg.label]) + for _, n := range runs { + all += n + } + switch { + case counted == nil: + first, counted = tg.label, runs + case !maps.Equal(counted, runs): + lines = append(lines, fmt.Sprintf("%s and %s run different rows on their files, %v and %v, where %s gives one count for %s", + first, tg.label, counted, runs, pageName, g.words)) + } + } + i := slices.IndexFunc(clauses, func(c string) bool { return strings.HasPrefix(strings.TrimPrefix(c, "and "), "in "+g.words+" ") }) + var clause string + if i < 0 { + lines = append(lines, fmt.Sprintf("%s gives no count of the rows on each file in %s", pageName, g.words)) + } else { + clause = clauses[i] + } + given := map[string]bool{} + for _, m := range countOnFile.FindAllStringSubmatch(clause, -1) { + given[m[2]] = true + lines = appendDiffering(lines, m[1], counted[m[2]], fmt.Sprintf("the rows on `%s` in %s", m[2], g.words)) + } + for _, label := range slices.Sorted(maps.Keys(counted)) { + if !given[label] { + lines = append(lines, fmt.Sprintf("%s gives no count of the rows on `%s` in %s, and the battery counts %s", pageName, label, g.words, commas(counted[label]))) + } + } + total := 0 + for _, n := range counted { + total += n + } + m := regexp.MustCompile("([0-9][0-9,]*) (?:rows )?in " + regexp.QuoteMeta(g.words) + "(?:,| and |$)").FindStringSubmatch(totals) + if m == nil { + lines = append(lines, fmt.Sprintf("%s gives no count of the rows in %s after \"That is\", and the battery counts %s", pageName, g.words, commas(total))) + continue + } + lines = appendDiffering(lines, m[1], total, "the rows in "+g.words) + } + return appendDiffering(lines, passage[3], all, "the rows in all") +} + +// appendDiffering appends a line to lines when page, a count as the page writes it, is not counted, the count of what, +// and returns lines. +func appendDiffering(lines []string, page string, counted int, what string) []string { + if n, err := strconv.Atoi(strings.ReplaceAll(page, ",", "")); err != nil || n != counted { + return append(lines, fmt.Sprintf("%s gives %s as %s, and the battery counts %s", pageName, page, what, commas(counted))) + } + return lines +} + +// commas writes n as the page writes a count, with a comma between each group of three digits: 11,073. +func commas(n int) string { + digits := strconv.Itoa(n) + for i := len(digits) - 3; i > 0; i -= 3 { + digits = digits[:i] + "," + digits[i:] + } + return digits +} diff --git a/conformance/scenarios_test.go b/conformance/scenarios_test.go index f1ab8b4..416ef89 100644 --- a/conformance/scenarios_test.go +++ b/conformance/scenarios_test.go @@ -16,7 +16,7 @@ import ( // wait beside the rest of their own scenario alone: a later scenario's quiet and burst count on nothing else reaching // the proxy meanwhile. The rate limit runs last, so the requests the scenarios before it send to its route come first, // and its quiet lets that route's bucket fill again before its burst. -var scenarios = []scenario{routing, mutualTLS, cors, auth, timeout, retry, gRPC, paths, asWritten, offRoute, clientKeys, hash, tracing, tracingRetried, rateLimit, cost, backendLimits, traffic} +var scenarios = []scenario{routing, mutualTLS, cors, auth, toldScheme, timeout, retry, gRPC, paths, asWritten, offRoute, clientKeys, hash, tracing, tracingRetried, rateLimit, cost, backendLimits, traffic} // get is a GET over HTTP/1.1 to localhost, a host of the example's local environment. func get(path string) request { @@ -1499,11 +1499,15 @@ var auth = scenario{name: "auth", headers: map[string]string{"authorization": "Bearer allow", "x-api-key": "key"}}, want: answer{status: 200, service: "shop", received: map[string]string{"x-user-check": "GET /products/1?i={i} action= reports= country="}}}, // What a client could send past the check. + // Under client_address connection nginx tells the check the connection's scheme, whatever scheme the target + // names, so https over TLS on nginx-auth and portable, where the Envoy output tells the target's. {name: "an absolute target's host is the host the check is told, whatever the Host header", keys: []string{"auth.ask", "auth.accept"}, send: request{proto: "http/1.1", host: "127.0.0.1", line: "GET http://localhost/products/1 HTTP/1.1", raw: true, headers: map[string]string{"authorization": "Bearer report-forwarded", "x-api-key": "key"}}, want: answer{status: 200, service: "shop", host: "localhost", received: map[string]string{"x-user-check": "proto=http host=localhost"}}, - by: map[string]own{"haproxy": {difference: lineRow, literal: literal{want: answer{status: 400}}}}}, + by: map[string]own{"haproxy": {difference: lineRow, literal: literal{want: answer{status: 400}}}, + "nginx": {difference: "auth.send_request", files: []string{"nginx-auth", "portable"}, literal: literal{want: answer{status: 200, + service: "shop", host: "localhost", received: map[string]string{"x-user-check": "proto=https host=localhost"}}}}}}, {name: "a client's own user, question and unchecked mark do not reach the service when the check allows with none of them", keys: []string{"auth.ask", "auth.accept"}, send: request{proto: "http/1.1", method: "GET", host: "localhost", path: "/products/1", forgedMark: true, @@ -1793,6 +1797,95 @@ var refusedUnderAllow = map[string]own{ "nginx": {difference: "auth.when_unavailable", files: allowFiles, literal: literal{want: answer{status: 403}}}, } +// toldScheme: measured on Envoy 1.40.2 beside nginx 1.30.6 and 1.31.8 and HAProxy 3.2.26 and 3.4.7. Each row asks the +// check, which reports the scheme it was told, and the service reports the x-forwarded-proto it received. The rows +// whose keys hold client_address run on the files with client_address connection and send_request; the others on every +// file with send_request too, two-checks, nginx-checks and nginx-tracing among them, which write no tls and take +// forwarded. nginx-connection writes connection and no tls, so it is sent over plain HTTP. +// +// Under connection a client's own x-forwarded-proto, https or ftp, is replaced by the connection's scheme for the +// check and the service, by every proxy. An absolute https target over TLS is served and told https, but by HAProxy, +// which answers every absolute target 400 over HTTP/1.1; over plain HTTP, on nginx-connection, the Envoy output answers +// it 403 and asks no check, and nginx serves it, a way nginx is less strict that its list names, and tells the check +// http, the scheme the service is sent. An HTTP/2 request with :scheme https sent over plain HTTP on nginx-connection +// is told https by the Envoy output, while the service is sent http: it tells the check the :scheme, whatever the +// connection, where nginx, whose variables hold no :scheme, tells the connection's (auth.send_request). +// +// Under forwarded an absolute https target sent with x-forwarded-proto http is told https by the Envoy output and nginx, +// the target's scheme before the header, while the service is sent the header's http, and an HTTP/2 :scheme https +// sent with it is told https by the Envoy output and http, the header's, by nginx and HAProxy (auth.send_request). An +// x-forwarded-proto of ftp reaches the service through every proxy, and the Envoy output tells the check the +// connection's scheme, http, where nginx and HAProxy tell it ftp as written (auth.send_request). +var toldScheme = scenario{name: "the scheme the check is told", + exchanges: []exchange{ + {name: "an absolute https target", keys: []string{"client_address", "auth.ask", "auth.accept", "auth.send_request"}, + send: request{proto: "http/1.1", host: "localhost", line: "GET https://localhost/products/1 HTTP/1.1", raw: true, + headers: map[string]string{"authorization": "Bearer report-forwarded", "x-api-key": "key"}}, + want: answer{status: 200, service: "shop", host: "localhost", received: map[string]string{"x-user-check": "proto=https host=localhost"}}, + on: map[string]literal{"nginx-connection": {want: answer{status: 403}}}, + by: map[string]own{"haproxy": {difference: lineRow, literal: literal{want: answer{status: 400}}}, + "nginx": {difference: "client_address", files: []string{"nginx-connection"}, literal: literal{want: answer{status: 200, + service: "shop", host: "localhost", received: map[string]string{"x-user-check": "proto=http host=localhost"}}}}}}, + {name: "an HTTP/2 request with :scheme https under connection", keys: []string{"client_address", "auth.ask", "auth.accept", "auth.send_request"}, + send: request{proto: "h2", method: "GET", host: "localhost", path: "/products/1", raw: true, scheme: "https", + headers: schemeReport("")}, + want: toldTo("https", "https"), + on: map[string]literal{"nginx-connection": {want: toldTo("https", "http")}}, + by: map[string]own{"nginx": {difference: "auth.send_request", files: []string{"nginx-connection"}, + literal: literal{want: toldTo("http", "http")}}}}, + {name: "a client's own x-forwarded-proto https under connection", keys: []string{"client_address", "auth.ask", "auth.accept", "auth.send_request"}, + send: request{proto: "http/1.1", method: "GET", host: "localhost", path: "/products/1", headers: schemeReport("https")}, + want: toldTo("https", "https"), + on: map[string]literal{"nginx-connection": {want: toldTo("http", "http")}}}, + {name: "an absolute https target sent with x-forwarded-proto http", keys: []string{"auth.ask", "auth.accept", "auth.send_request"}, + send: request{proto: "http/1.1", host: "localhost", line: "GET https://localhost/products/1 HTTP/1.1", raw: true, + headers: schemeReport("http")}, + want: withHost(toldTo("https", "https")), + on: map[string]literal{"two-checks": {want: withHost(toldTo("https", "http"))}, "nginx-checks": {want: withHost(toldTo("https", "http"))}, + "nginx-tracing": {want: withHost(toldTo("https", "http"))}, "nginx-connection": {want: answer{status: 403}}}, + by: map[string]own{"haproxy": {difference: lineRow, literal: literal{want: answer{status: 400}}}, + "nginx": {difference: "client_address", files: []string{"nginx-connection"}, literal: literal{want: withHost(toldTo("http", "http"))}}}}, + {name: "an HTTP/2 request with :scheme https sent with x-forwarded-proto http", keys: []string{"auth.ask", "auth.accept", "auth.send_request"}, + send: request{proto: "h2", method: "GET", host: "localhost", path: "/products/1", raw: true, scheme: "https", + headers: schemeReport("http")}, + want: toldTo("https", "https"), + on: onEach([]string{"two-checks", "nginx-checks", "nginx-tracing", "nginx-connection"}, literal{want: toldTo("https", "http")}), + by: map[string]own{"nginx": {difference: "auth.send_request", files: []string{"nginx-checks", "nginx-tracing", "nginx-connection"}, + literal: literal{want: toldTo("http", "http")}}, + "haproxy": {difference: "auth.send_request", files: []string{"two-checks"}, literal: literal{want: toldTo("http", "http")}}}}, + {name: "an x-forwarded-proto that is neither http nor https", keys: []string{"auth.ask", "auth.accept", "auth.send_request"}, + send: request{proto: "http/1.1", method: "GET", host: "localhost", path: "/products/1", headers: schemeReport("ftp")}, + want: toldTo("https", "https"), + on: map[string]literal{"two-checks": {want: toldTo("http", "ftp")}, "nginx-checks": {want: toldTo("http", "ftp")}, + "nginx-tracing": {want: toldTo("http", "ftp")}, "nginx-connection": {want: toldTo("http", "http")}}, + by: map[string]own{"nginx": {difference: "auth.send_request", files: []string{"nginx-checks", "nginx-tracing"}, + literal: literal{want: toldTo("ftp", "ftp")}}, + "haproxy": {difference: "auth.send_request", files: []string{"two-checks"}, literal: literal{want: toldTo("ftp", "ftp")}}}}, + }} + +// schemeReport is the headers of a request the check answers with the scheme it was told (report-forwarded), with the +// client's own x-forwarded-proto when forwardedProto is not empty. +func schemeReport(forwardedProto string) map[string]string { + headers := map[string]string{"authorization": "Bearer report-forwarded", "x-api-key": "key"} + if forwardedProto != "" { + headers["x-forwarded-proto"] = forwardedProto + } + return headers +} + +// toldTo is a request of toldScheme served by shop, whose check was told the scheme check and whose service received +// the x-forwarded-proto service. +func toldTo(check, service string) answer { + return answer{status: 200, service: "shop", received: map[string]string{"x-user-check": "proto=" + check + " host=localhost", + "x-forwarded-proto": service}} +} + +// withHost is a, which also wants the service to receive the host localhost, the one an absolute target names. +func withHost(a answer) answer { + a.host = "localhost" + return a +} + // timeout: measured on Envoy 1.40.2. The check holds the request for 3 s, past auth.timeout's 1500 ms, and // when_unavailable is allow, so the request goes on to the service when the timeout ends, with the unchecked mark, as a // request the check could not answer must carry (the auth scenario names it). The row times the request on the client's @@ -2795,7 +2888,8 @@ func servedOnFull(forms map[string]*regexp.Regexp, received map[string]string) m const otelRow = "tracing.provider.otel" // tracing: every want measured on Envoy 1.40.2 beside nginx 1.30.6 and 1.31.8 on their images tagged -otel, and each of -// nginx's own literals (by) is a difference its support table declares. nginx-tracing.yaml traces 5% of the requests, +// nginx's own literals (by) is a difference its support table declares. The proxy runs with the two variables +// nginx-tracing.yaml's set env tags read (proxyEnvironment). nginx-tracing.yaml traces 5% of the requests, // drawn by the id, and sends its spans to the battery's collector (file.collector), so each row sends an id whose draw // is known (drawnID, undrawnID) and reads the span that carries it, or wants none; examples/full traces 10% to a // collector the world leaves unreachable, with client_address = connection, so on it a row reads what the service @@ -3076,6 +3170,19 @@ var tracing = scenario{name: "tracing", want: answer{status: 200, service: "shop", spanned: map[string]*regexp.Regexp{"inherited": regexp.MustCompile(`^own$`), "tenant": regexp.MustCompile(`^acme$`)}}, on: map[string]literal{"full": {want: answer{status: 200, service: "shop"}}}}, + {name: "an env tag whose variable is set reads it", keys: []string{"tracing", "tracing.tags..env"}, overlap: true, + send: tracedTo("/products/b7", drawnID("0000000000b7"), nil), + want: answer{status: 200, service: "shop", spanned: map[string]*regexp.Regexp{"region": regexp.MustCompile(`^eu-1$`)}}, + on: map[string]literal{"full": {want: answer{status: 200, service: "shop"}}}}, + // njs leaves a variable named like a property every object has out of process.env, so nginx reads toString as + // unset, where Envoy reads it. + {name: "an env tag on a set variable named like a property every object has", keys: []string{"tracing", + "tracing.tags..env", "tracing.tags..default"}, overlap: true, + send: tracedTo("/products/b8", drawnID("0000000000b8"), nil), + want: answer{status: 200, service: "shop", spanned: map[string]*regexp.Regexp{"inherited_set": regexp.MustCompile(`^ts1$`)}}, + on: map[string]literal{"full": {want: answer{status: 200, service: "shop"}}}, + by: map[string]own{"nginx": {difference: "tracing.tags..env", literal: literal{want: answer{status: 200, service: "shop", + spanned: map[string]*regexp.Regexp{"inherited_set": regexp.MustCompile(`^own$`)}}}}}}, {name: "a tag value keeps a quote, a backslash and bytes above 0x7F as sent", keys: []string{"tracing", "tracing.tags..header"}, overlap: true, send: request{proto: "http/1.1", method: "GET", host: "localhost", path: "/products/t22", raw: true, headers: map[string]string{"x-request-id": drawnID("000000000022"), "x-tenant": `a"b\cé`}}, diff --git a/conformance/targets_nginx_test.go b/conformance/targets_nginx_test.go index 935e8a7..224fcb0 100644 --- a/conformance/targets_nginx_test.go +++ b/conformance/targets_nginx_test.go @@ -15,8 +15,8 @@ import ( // a route limited by client; then its two files with the auth check, one asked under deny at two check addresses and // one under allow beside the other keys the generator writes and a limited route; then examples/full, whose committed // nginx.refused is checked by its render alone, and examples/portable, the full example's world with only the keys -// every generator is to render alike, which Envoy's entry runs too; and last the file of the connection limit -// (limitsFile). +// every generator is to render alike, which Envoy's entry runs too; then the file of the connection limit +// (limitsFile); and last the file with client_address connection and no tls (connectionFile). // After them comes an entry for each image scripts/nginx-otel-images pins, the same versions tagged -otel, which carry // ngx_otel_module. Each runs the battery's two files with tracing alone, the collector by address and by name: nginx -t // on a plain image stops at the files' load_module line for that module, and the plain entries run every other file. @@ -54,6 +54,7 @@ func nginxEntries(t testing.TB) []target { {label: "full", proxyfile: "../examples/full/hocon/Proxyfile"}, {label: "portable", proxyfile: "../examples/portable/hocon/Proxyfile"}, limitsFile, + connectionFile, })) } for _, p := range pinnedImages(t, "nginx-otel") { diff --git a/conformance/targets_test.go b/conformance/targets_test.go index 34e8d23..480a49b 100644 --- a/conformance/targets_test.go +++ b/conformance/targets_test.go @@ -58,6 +58,10 @@ var ( // limitsFile is the battery's file for the connection limit, which Envoy's entry and each plain nginx entry run; it // runs the rows of that scenario alone, as no other row is there for its limit of two. limitsFile = file{label: "nginx-limits", proxyfile: "testdata/nginx-limits.yaml", scenarios: []string{backendLimits.name}} + // connectionFile is the battery's file with client_address connection and no tls, which Envoy's entry and each plain + // nginx entry run; it runs the rows of the scheme the check is told alone, as no other row is there for plain HTTP + // under connection. + connectionFile = file{label: "nginx-connection", proxyfile: "testdata/nginx-connection.yaml", scenarios: []string{toldScheme.name}} ) // haproxyLimitsFile is the battery's file for HAProxy's connection limit, which Envoy's entry and each HAProxy entry @@ -105,6 +109,7 @@ func targets(t testing.TB) []target { tracingFile, tracingByNameFile, limitsFile, + connectionFile, }, image: image, // Envoy writes its log lines to stdout every 10 s by default; every 100 ms, a row that reads them (answer.logged) diff --git a/conformance/testdata/nginx-connection.yaml b/conformance/testdata/nginx-connection.yaml new file mode 100644 index 0000000..0a0b3f2 --- /dev/null +++ b/conformance/testdata/nginx-connection.yaml @@ -0,0 +1,26 @@ +# The conformance battery's file for nginx with client_address: connection and no tls, so the clients speak plain +# HTTP: the auth check under deny at one check address, asked of a request with an x-api-key header, accepting +# x-user-check, with send_request: true, and one route to shop. It runs the scenario of the scheme the check is told +# alone, so its rows show what each proxy tells the check over plain HTTP: an absolute https target, which the Envoy +# output answers 403 and nginx serves, an HTTP/2 request with :scheme https and a client's own x-forwarded-proto. +# Envoy's entry runs it too, so each literal on it is Envoy's measured answer. +listen: 10000 +admin: 9901 +client_address: connection +services: + shop: + http: 8080 + addresses: ["10.0.1.11", "10.0.1.12"] + checks: {http: 7070, address: "10.0.3.31"} +auth: + ask: checks /auth/check + timeout: 1500ms + enabled: true + when_unavailable: deny + only_with_header: x-api-key + accept: [x-user-check] + send_request: true +origins: + local: {hosts: [127.0.0.1, localhost]} +routes: + - {name: shop, prefix: /, to: shop} diff --git a/conformance/testdata/nginx-tracing.yaml b/conformance/testdata/nginx-tracing.yaml index 47de044..a76aef2 100644 --- a/conformance/testdata/nginx-tracing.yaml +++ b/conformance/testdata/nginx-tracing.yaml @@ -2,8 +2,10 @@ # route's limit, with no tls and no client_address key, so the clients speak plain HTTP, forwarded applies as the # default and a row's own x-request-id reaches the draw that picks the requests traced, and with tracing to the # collector at 10.0.3.40 at a rate of 5%, with a tag of each source the generator writes: an environment variable with -# a default, the request id, a header with a default and one without, a header whose lines Envoy joins, the check's -# first accept name, a default holding $, " and \, and a tag named like a field of the Envoy output's span. Only the nginx images tagged -otel load the +# a default, unset, and one set, the request id, a header with a default and one without, a header whose lines Envoy +# joins, the check's first accept name, a default holding $, " and \, and a tag named like a field of the Envoy output's +# span; and two tags of variables named like a property every object has, one unset and one set (the battery sets +# APP_REGION and toString, proxyEnvironment in world_test.go). Only the nginx images tagged -otel load the # tracing module, so only their entries run it, beside Envoy's, which measures its literals. A tracing row sends none # of its requests to the catalog route, whose bucket the rate limit rows count on. listen: 10000 @@ -217,4 +219,6 @@ tracing: component: {header: x-component} accepts: {header: accept} inherited: {env: constructor, default: own} + region: {env: APP_REGION, default: nowhere} + inherited_set: {env: toString, default: own} path_in_url: true diff --git a/conformance/world_test.go b/conformance/world_test.go index 7e4a5b5..7dd8e1f 100644 --- a/conformance/world_test.go +++ b/conformance/world_test.go @@ -51,6 +51,11 @@ const ( // battery reads the spans it kept on port 8080 inside its container (world.spans). const collector, collectorAddress, collectorName = "proxyfile-conformance-collector", "10.0.3.40", "collector.internal.example" +// proxyEnvironment is the environment every proxy runs with, which the env tags of nginx-tracing.yaml read: a variable +// set to a value, and one set under a name every object has as a property, which njs leaves out of process.env. Each is +// a name no other file reads, so only the rows of those tags see it. +var proxyEnvironment = []string{"APP_REGION=eu-1", "toString=ts1"} + // runFolder holds all a run writes to disk: the rendered file in config, the stub's build in stub, and the TLS files // with the server's key in tls and jwt. The battery names it as it names its Docker objects, so a run killed before // its cleanup leaves it where the next run's start removes it. @@ -128,8 +133,8 @@ func claimWorld(t *testing.T) { // the proxy so its first spans have somewhere to go; for every other file that address is left unreachable, and no // request waits for it. 10.0.0.0/22 is the smallest block holding every one of them. The ports 10000 and 9901 and the // folders /config, /etc/gateway/tls and /etc/gateway/jwt are the examples' listen, admin and tls keys and -// examples/full's auth.jwt.ca, the same for every target. plain says the rendered file's listener speaks plain HTTP, so -// the clients do too. +// examples/full's auth.jwt.ca, the same for every target, and the proxy runs with proxyEnvironment. plain says the +// rendered file's listener speaks plain HTTP, so the clients do too. func startWorld(t *testing.T, tg target, config string, plain, held, collects bool) *world { buildStub(t, filepath.Join(runFolder, "stub")) files := certificates(t, runFolder) @@ -172,9 +177,13 @@ func startWorld(t *testing.T, tg target, config string, plain, held, collects bo waitSpans(t) } // The listener is published on a port Docker picks, so a run never meets a port another program holds. - mustDocker(t, append([]string{"run", "-d", "--name", proxy, "--network", network, "--ip", "10.0.0.10", + run := []string{"run", "-d", "--name", proxy, "--network", network, "--ip", "10.0.0.10", "-p", "127.0.0.1::10000", "-v", config + ":/config:ro", "-v", files.tls + ":/etc/gateway/tls:ro", - "-v", files.jwt + ":/etc/gateway/jwt:ro", tg.image}, tg.args...)...) + "-v", files.jwt + ":/etc/gateway/jwt:ro"} + for _, variable := range proxyEnvironment { + run = append(run, "-e", variable) + } + mustDocker(t, append(append(run, tg.image), tg.args...)...) mustDocker(t, "run", "-d", "--name", accounts, "--network", "container:"+proxy, "-v", state, image, "serve", "-service", "accounts", "-instance", "accounts", "-ports", "7070") waitReady(t, tg.ready) diff --git a/docs/auth.md b/docs/auth.md index e5ce09a..d41ddc8 100644 --- a/docs/auth.md +++ b/docs/auth.md @@ -77,10 +77,19 @@ read: The request the check receives still goes to the path of `ask`. The proxy sets each of the four headers itself, so a client's own `x-forwarded-uri`, `x-forwarded-method` and `x-forwarded-host` never reach the check, also when `send` names them. Whose word the scheme is depends on [`client_address`](listener.md#the-clients-address). With -`connection` it is the connection's own. With `forwarded`, the default in a file without `tls`, it is the -`X-Forwarded-Proto` the request arrived with: a proxy in front sets it, and a client that reaches the gateway -directly writes it itself, so the check then reads `https` for a request sent over plain HTTP. A gateway that faces -its clients writes `client_address: connection`. The proxy sets `x-forwarded-uri`, `x-forwarded-method` and +`connection` it is the connection's own, the scheme the service is sent, but the Envoy output tells the check an HTTP/2 +request's `:scheme`: `https` for a request sent over plain HTTP with `:scheme https`, though the service is sent +`http`, and `http` for one sent over TLS with `:scheme http`. It also tells `http` for a request sent over TLS whose +absolute target says `http`, and answers `403` to an absolute `https` target sent over plain HTTP, which the nginx file +serves and tells the check `http`. With `forwarded`, the default in a file without `tls`, it is the scheme of an +absolute target when the request line holds one, and through the Envoy output an HTTP/2 request's `:scheme`, then the +`X-Forwarded-Proto` the request arrived with, and the connection's scheme when it arrived with none; the service is +sent that header, or the connection's scheme. A proxy in front sets the header, but the client writes the request +line, and a client that reaches the gateway directly writes the header too, so the check then reads `https` for a +request sent over plain HTTP. For an `X-Forwarded-Proto` of `ftp` the Envoy output tells the check the connection's +scheme, where the nginx and HAProxy files tell it `ftp`, as it arrived. A gateway that faces its clients writes +`client_address: connection`, and a check behind the Envoy output can trust an `https` it is told only with `tls`, as a +client can send `:scheme https` over plain HTTP. The proxy sets `x-forwarded-uri`, `x-forwarded-method` and `x-forwarded-host` on the check's request alone: a client's own copies reach the service as sent, unless `remove_from_clients` names them. diff --git a/docs/commands.md b/docs/commands.md index ce6c697..dff4907 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -29,7 +29,7 @@ or sending a service what the Envoy output would not, and names the page that li unchanged: ``` -proxyfile render: this HAProxy configuration is less strict than the Envoy output in 10 ways; docs/haproxy.md lists them under "Where HAProxy is less strict than the Envoy output" +proxyfile render: this HAProxy configuration is less strict than the Envoy output in 11 ways; docs/haproxy.md lists them under "Where HAProxy is less strict than the Envoy output" ``` nginx's line names [`docs/nginx.md`](nginx.md#where-nginx-is-less-strict-than-the-envoy-output), HAProxy's diff --git a/docs/conformance.md b/docs/conformance.md index 3cfce9b..d3f2b5d 100644 --- a/docs/conformance.md +++ b/docs/conformance.md @@ -7,10 +7,10 @@ so the released program never carries them. It runs each target of this version: ## What the battery proves -Each entry of the battery is a proxy image and the proxyfiles it runs. Envoy's entry, `envoy-1.40`, runs thirteen: +Each entry of the battery is a proxy image and the proxyfiles it runs. Envoy's entry, `envoy-1.40`, runs fourteen: [`examples/full/hocon/Proxyfile`](../examples/full/hocon/Proxyfile), which writes every key but the few its opening comment names, [`examples/portable/hocon/Proxyfile`](../examples/portable/hocon/Proxyfile), which writes in the same -world only the keys every generator is to render alike, nginx's own seven files, +world only the keys every generator is to render alike, nginx's own eight files, [`conformance/testdata/nginx.yaml`](../conformance/testdata/nginx.yaml) and [`conformance/testdata/nginx-plain.yaml`](../conformance/testdata/nginx-plain.yaml), the same with no pattern route, and, with an auth check, [`conformance/testdata/nginx-checks.yaml`](../conformance/testdata/nginx-checks.yaml) and @@ -18,7 +18,8 @@ with an auth check, [`conformance/testdata/nginx-checks.yaml`](../conformance/te [`conformance/testdata/nginx-tracing.yaml`](../conformance/testdata/nginx-tracing.yaml) and [`conformance/testdata/nginx-tracing-by-name.yaml`](../conformance/testdata/nginx-tracing-by-name.yaml), its collector found by name, and, with a connection limit, -[`conformance/testdata/nginx-limits.yaml`](../conformance/testdata/nginx-limits.yaml), +[`conformance/testdata/nginx-limits.yaml`](../conformance/testdata/nginx-limits.yaml), and, with `client_address: +connection` and no `tls`, [`conformance/testdata/nginx-connection.yaml`](../conformance/testdata/nginx-connection.yaml), and HAProxy's own four, [`conformance/testdata/haproxy.yaml`](../conformance/testdata/haproxy.yaml), [`conformance/testdata/two-checks.yaml`](../conformance/testdata/two-checks.yaml), [`conformance/testdata/haproxy-traffic.yaml`](../conformance/testdata/haproxy-traffic.yaml) and @@ -91,6 +92,13 @@ nginx entry on the plain image run it. HAProxy's `haproxy-limits.yaml` writes th one address, so HAProxy's own `maxconn` on that server binds, and runs the row of the connection limit alone; Envoy's entry and each HAProxy entry run it. +nginx's `nginx-connection.yaml` writes `client_address: connection` with no `tls`, so its clients speak plain HTTP, the +auth check with `send_request: true` and one route to shop, and runs the rows of the scenario the scheme the check is +told alone, so they show what each proxy tells the check over plain HTTP under `connection`: an absolute `https` target, +which the Envoy output answers `403` and nginx serves, telling the check the connection's scheme, an HTTP/2 request +with `:scheme https`, which the Envoy output tells the check as `https`, and a client's own `x-forwarded-proto`. Envoy's +entry and each nginx entry on the plain image run it. + nginx's `nginx-checks.yaml` is `two-checks.yaml` for nginx: the same check service with two addresses, `when_unavailable: deny`, the `x-api-key` condition and `send_request: true`, with `remove_from_clients` naming `x-request-id` alone, because the nginx generator refuses a name with a `*` prefix there, so each answer the check cannot give runs on nginx under @@ -105,10 +113,11 @@ route is, so the rows of a retried request that the check allows, denies or cann measured on Envoy. `nginx-tracing.yaml` is `nginx-auth.yaml` with no `tls` and no `client_address`, so its clients speak plain HTTP and `forwarded` applies, and a row's own `x-request-id` reaches the draw that picks the requests traced, and with `tracing`: the `otel` provider sending its spans to the battery's collector at `10.0.3.40:4317` ([The -world](#the-world)), `sample: {rate: 5%}`, `path_in_url: true` and seven tags, one of each source the nginx generator -reads a tag from: an environment variable with a default, `x-request-id`, a header with a default and one without, -the check's first `accept` name, a default holding `$`, `"` and `\`, and a tag named like a field of the Envoy output's -span, `component`. Envoy's entry runs it too, so each literal of its rows is measured on Envoy. +world](#the-world)), `sample: {rate: 5%}`, `path_in_url: true` and eleven tags, of each source the nginx generator +reads a tag from: an environment variable with a default, unset, and one set, `x-request-id`, a header with a default +and one without, a header whose lines Envoy joins, the check's first `accept` name, a default holding `$`, `"` and `\`, +a tag named like a field of the Envoy output's span, `component`, and two of variables named like a property every +object has, `constructor`, unset, and `toString`, set. Envoy's entry runs it too, so each literal of its rows is measured on Envoy. `nginx-tracing-by-name.yaml` is the same tracing with the collector named `collector.internal.example:4317` and `dns.resolver` naming the battery's resolver, which gives that name the collector's address, so nginx sends its spans through the relay it writes for a name ([nginx](nginx.md#what-the-file-writes)), and with only the shop service and @@ -129,8 +138,9 @@ origins file a proxyfile names and of the methods its `rpc.proto` reads; a row t Before any container starts, the battery fails when a row names a key that is not a core key of the format, when a row runs on no file of Envoy's entry, where its answers were measured, when a row holds an answer for a file label no entry carries or for a file the row does not run on, when a row that runs on a file of Envoy's runs on none of the files of a -proxy version's entries while that target refuses none of the row's keys, and when a key Envoy's rows exercise is -exercised on none of the files of a version's entries while that target does not refuse it. The entries of one version +proxy version's entries while that target refuses none of the row's keys, when a key Envoy's rows exercise is +exercised on none of the files of a version's entries while that target does not refuse it, and when a count of rows +this page gives below is not the number of rows the entries run. The entries of one version are judged together, nginx 1.31's on the plain image and on the image tagged `-otel` among them, and the entries of two versions never are. A row checks only what every proxy must answer: the status, which service and which of its backends answered and what it received (port, protocol, method, path, host and headers), the response headers that matter, @@ -151,16 +161,16 @@ nginx's exporter and the Envoy output's tracer each send the spans they hold eve scenario waits one second before it is sent, so the route's bucket fills again between the 10 of the scenario's rows that route serves before it and the 11 from it on, however fast a runner sends them; routing's and CORS's rows send it 9 more before them, so 19 reach the route before that wait on `portable`, whose bucket holds 20. The scenarios run in this -order: in Envoy's entry 602 rows on `full`, 512 on `portable`, 349 on `nginx-file`, 259 on `nginx-plain`, 378 on -`nginx-checks`, 525 on `nginx-auth`, 571 on `nginx-tracing`, 39 on `nginx-tracing-by-name` and 3 on `nginx-limits`, -nginx's own files, and 465 on `haproxy-file`, 361 on `two-checks`, 37 on `haproxy-traffic` and 1 on `haproxy-limits`, -HAProxy's own; in each -nginx entry on the plain image the same 349, 259, 378, 525 and 3 on `nginx-file`, `nginx-plain`, `nginx-checks`, -`nginx-auth` and `nginx-limits`, and the same 512 on `portable`; in each nginx entry on the image tagged `-otel` the -same 571 on `nginx-tracing` and 39 on `nginx-tracing-by-name`; and in each HAProxy entry the same 465 on `haproxy-file` -and 361 on `two-checks`, 12 on `haproxy-traffic` and 1 on `haproxy-limits`. That is 4,102 rows in Envoy's entry, -2,026 in each nginx entry on the plain image, 610 in each on the image tagged `-otel` and 839 in each HAProxy entry, -11,052 in all, and each passes. Before nginx wrote rate limits, RPC +order: in Envoy's entry 610 rows on `full`, 518 on `portable`, 349 on `nginx-file`, 259 on `nginx-plain`, 381 on +`nginx-checks`, 531 on `nginx-auth`, 576 on `nginx-tracing`, 39 on `nginx-tracing-by-name`, 3 on `nginx-limits` and 6 +on `nginx-connection`, nginx's own files, and 471 on `haproxy-file`, 364 on `two-checks`, 37 on `haproxy-traffic` and 1 +on `haproxy-limits`, HAProxy's own; in each nginx entry on the plain image 349 on `nginx-file`, 259 on `nginx-plain`, +381 on `nginx-checks`, 531 on `nginx-auth`, 518 on `portable`, 3 on `nginx-limits` and 6 on `nginx-connection`; in +each nginx entry on the image tagged `-otel` 576 on `nginx-tracing` and 39 on `nginx-tracing-by-name`; and in each +HAProxy entry 471 on `haproxy-file`, 364 on `two-checks`, 12 on `haproxy-traffic` and 1 on `haproxy-limits`. That is +4,145 rows in Envoy's entry, 2,047 in each nginx entry on the plain image, 615 in each nginx entry on the image tagged +`-otel` and 848 in each HAProxy entry, 11,165 in all, and each passes. The battery counts these rows before any +container starts and fails when one of these numbers is not what it counts. Before nginx wrote rate limits, RPC retries, balance, hash and DNS names the same entries ran 3,041, 1,310 and 791 rows: 40 rows were added, among them the scenarios client keys and hash, nginx's files gained the traffic keys those rows need, and each nginx entry runs `examples/portable`, where it ran no file of that world. Before nginx @@ -185,7 +195,12 @@ they ran 3,965, 2,001, 570 and 823: one row was added in the scenario routing, a with its own directives they ran 4,034, 2,009, 605 and 825: `haproxy-traffic.yaml` was added, seven rows were added, six in the scenario traffic keys and one in the scenario hash, `haproxy-limits.yaml` was added for the row of the connection limit, and `haproxy.yaml` gained a service found by DNS, so the row of `dns.resolver` runs on -`haproxy-file`. In order: +`haproxy-file`. Before nginx told the auth check the connection's scheme under `client_address: connection` and the +battery ran each proxy with two variables set they ran 4,102, 2,026, 610 and 839: `nginx-connection.yaml` was added +with the scenario the scheme the check is told, whose rows run on `full`, `portable`, `nginx-auth`, `haproxy-file` and +`nginx-connection`, and those whose keys hold no `client_address` on `two-checks`, `nginx-checks` and `nginx-tracing` +too, and two rows were added in the scenario tracing, each of an `env` tag whose variable is set, one +of them named like a property every object has, which run on `full` and `nginx-tracing`. In order: | Scenario | Keys | What its rows check | |---|---|---| @@ -193,6 +208,7 @@ connection limit, and `haproxy.yaml` gained a service found by DNS, so the row o | mutual TLS | `tls.certificate`, `tls.key`, `tls.clients.ca`, `origins..hosts` | A client with no certificate, one whose certificate another CA signed, and one whose certificate the clients CA signed and whose validity ended reach no service: the handshake fails, or the proxy refuses it, where nginx completes the handshake and answers an empty `400`, the difference nginx's row of `tls.clients.ca` names. A request whose TLS server name is one host of an environment and whose `Host` is another host of the same environment is served by Envoy and answered with an empty `421` by nginx, which asks for client certificates, a declared difference. The other CA carries the clients CA's name, so a proxy that matched the issuer by name would let it through. Every other row sends a client certificate the clients CA signed. A client that offers only TLS 1.1, a TLS 1.2 client that offers only a CBC suite, and one that offers only the group P-384 are refused in the handshake, and one that offers only the group X25519MLKEM768 is served. Eight rows, on every file but `nginx-plain`, `two-checks` and `nginx-checks`, which write no `tls`. | | CORS | `cors.allow_methods`, `cors.allow_headers`, `cors.expose_headers`, `cors.max_age`, `origins..hosts`, `origins..origins`, `origins..patterns` | A preflight from a listed origin and one from an origin a pattern covers answer `200` with `access-control-allow-origin` and `access-control-max-age`; a preflight and a request from another origin answer `403`, and so does a request from another origin to a path ending `.html`, as `text/plain` on every proxy, whose own answers take no type from the path's ending; a request from a listed origin reaches the service with its `origin` and is answered with `access-control-allow-origin` and `access-control-expose-headers`. The preflight from a listed origin and the request from another origin carry a token the check denies and one the token filter refuses, each answered `401` alone, so on a file that writes the check their `200` and `403` show that the origin is decided before the token and the check. An origin on the environment's own host that neither list holds, `https://api.example.org` to `api.example.org`, is admitted without `access-control-allow-origin`: its request reaches the service and its preflight answers `200`. With no list, an origin on one of the environment's hosts is admitted and every other refused: a request with no `Origin`, and one from `http://localhost` over `http` or `https`, with a port, or from the environment's other host `http://127.0.0.1` reaches the service, and a preflight from `http://localhost` is answered `200` by the proxy; an origin on another environment's host, the host in capitals, with a trailing dot or with other characters for its dots, `null`, a present but empty `Origin`, a preflight from another origin and a WebSocket upgrade from one answer `403`, where HAProxy's parser answers that upgrade, which carries no `Sec-WebSocket-Key`, `400`, a declared difference. An empty `Origin` over HTTP/2 is answered `403` too, and an empty `Origin` line before or after the origin of the host, or a tab before that origin, changes nothing: the service receives the origin as one line. A preflight from a listed origin with no token is answered with the method and the headers it asks for; one from a listed origin in capitals is admitted with the origin as sent, and one from a pattern's origin in capitals is refused. The `Origin` header is read as one line: two `Origin` lines a pattern covers when joined are admitted with the joined line in `access-control-allow-origin`, where nginx answers `403`, a declared difference, two whose first is listed, two of the request's own origin, and one line holding a listed origin after a comma are refused, and an empty `Origin` line after a listed one is left out; a preflight that asks on two lines for two methods or for headers is answered with both, joined with a comma, and by nginx with a comma and a space, a declared difference. A listed origin with a trailing space is admitted, and the service receives it without the space. A service that is down, asked from a listed origin, is answered `502` with `access-control-allow-origin` and `access-control-expose-headers`, and a request from a listed origin to a host no environment names is answered `404` with no `access-control-allow-origin`. A refused path, a preflight to it, an upgrade other than WebSocket, a request with a NUL byte in a header from a listed origin and one with `Content-Length` beside `Transfer-Encoding: chunked` from it are answered with no `access-control-allow-origin`, where HAProxy serves the last with it, a declared difference, and a header line of 9,000 bytes from one is served with it by every proxy, nginx's header buffers reading a line as long as the header limit ([nginx](nginx.md#the-header-limits)). An admitted `Origin` of 600 bytes is echoed beside a service's answer of 100 KB, and so is one of 1,100 bytes, where HAProxy answers `403` before the service, a declared difference. A preflight from a listed origin to `/..;x/products/1`, with no token and with a token the check allows, is answered `200` by Envoy, which resolves the path and asks no check, and `400` by nginx and HAProxy, which with the token ask the check first, each a declared difference, and a denial of the check from a listed origin carries `access-control-allow-origin` and `access-control-expose-headers`. Fifty-two rows, all on `full`, `portable`, `haproxy-file` and `nginx-auth`, fifty on `nginx-file`, which writes no check, and nineteen on `nginx-plain`, `two-checks` and `nginx-checks`, which write no list of origins and no `cors`. | | auth | `auth.ask`, `auth.only_with_header`, `auth.send`, `auth.accept`, `auth.send_request`, `auth.timeout`, `auth.when_unavailable`, `routes[].auth`, `remove_from_clients`, `auth.jwt.claims`, `services..host_header`, `cors.expose_headers`, `origins..origins`, `log` | A request with no `authorization` header reaches the service, which it could not if the check were asked; when the check allows, the service receives the check's headers `auth.accept` admits and not another, and what the check was told (the method, the path with its query, `x-country`), never the `x-forwarded-uri` and `x-forwarded-method` the client sent; the check's `401` and `403` reach the client, without the `x-envoy-upstream-service-time` Envoy's client for the check adds; a check that answers `503` lets the request through, as `when_unavailable = allow` says, and on `two-checks` and `nginx-checks`, whose `when_unavailable` is `deny`, gets `403`; the mark of a request the check could not answer reaches the service, and a client's own copy never does, whether the check allows or is not asked; a route with `auth = off` is not checked; a client's own copies of the headers `remove_from_clients` names, of the check's headers and question, and of the headers `auth.jwt.claims` sets never reach the service. A header `remove_from_clients` names does not reach the service when a client sends it on two lines, one with its name in capitals; a client's own `x-request-id` is replaced by another when `remove_from_clients` names it; and on `two-checks`, whose `remove_from_clients` names the prefix `ho*`, a client's `ho-x` does not reach the service and its `Host` does. The check is told it is internal and its deadline, `x-envoy-internal: true` and `x-envoy-expected-rq-timeout-ms: 1500`; a header sent on two lines reaches it as one line, joined with a comma; a client's own `x-forwarded-proto` reaches it under `forwarded`, and the connection's scheme under `connection`; it receives the `Host` the client sent whatever the check service's `host_header`; and the `only_with_header` header sent twice, an empty line before or after the token, asks it. A check's `201` is answered `403`, and a status of `600` is passed on as the check's own, where HAProxy and nginx answer `403`. A denial of 20,000 bytes, and one with a header of 50,000, reach the client, and an allowing answer whose `x-user-id` holds 20,000 bytes sets it on the request where `auth.accept` admits it, where HAProxy answers each `403`, a declared difference. An answer whose body breaks off, and one of 101 header lines, are a check that could not answer: the request is served with the mark under `allow` and answered `403` under `deny`. A `200` that RFC 9112 does not read whole is such a check for Envoy too, in nine forms: a `Content-Length` that is not a number, two `Content-Length` lines, a control byte in a header value, a status that is not three digits, a header name outside the token characters, `Content-Length` beside `Transfer-Encoding`, a chunk size that is not hexadecimal, a malformed header line in a `1xx` before it, and a malformed trailer line; HAProxy answers each `403` under `allow` too, a declared difference. Of 24 requests while `check-2`, one of the two check backends of `two-checks` and `nginx-checks`, refuses connections, at least one is answered `403` on those files: no other backend answers a check it refused. Rows for each form of an answer a check can write that RFC 9112 reads in a way of its own hold Envoy's reading, measured on Envoy 1.40.2: a status line of `2 0 0`, `20` or `000`, of `304` or of `101` is passed on as the check's own, and so is a denial with a folded header line; a status of `200.1`, `500`, `599`, or `503` with a body, a `200` with a header line with no colon, a header value with a vertical tab, `Transfer-Encoding: gzip, chunked`, or `identity` beside a `Content-Length`, a chunk that does not end its line, a space before a header's colon, a header name that holds a NUL or the byte `0xE9`, and a `Content-Length` past what any reader holds, are each a check that could not answer, and so is a denial with a header line with no colon; a `200` of `HTTP/2.0`, with two spaces after its version, with a space after a chunk's size, with spaces around its `Content-Length`, with a lone CR before a CRLF, with `_` in a header name, with bytes after its body, with a body of 1 MiB, or holding the relay's own header name `x-proxyfile-check`, is read as allowed. A denial with a body of 1 MiB, of 1 MiB and a byte and of 1,100,000 bytes reaches the client whole, and a denial's header that holds the byte `0xE9` reaches it as the check wrote it, and a denial with no body reaches it with no `content-type`. A `200` whose chunk-size line ends in a bare LF, or whose last chunk's line does, is a check that could not answer on Envoy, and a `200` whose chunk data, trailer line and final line end in a bare LF is read as allowed; nginx's relay and HAProxy's script refuse the first two under `allow` too, a declared difference. A `200` whose accepted header is folded reaches the service with the spaces and tabs of the fold, a tab, spaces on both lines or two folds, where HAProxy joins them by one space, a declared difference, and one whose accepted header is empty reaches the service empty. A `200` whose accepted header takes the request past the header size is answered `500`, where HAProxy answers `431`, a declared difference, and one whose accepted headers take it past the header count, 100 fields as Envoy counts them, is answered `500` by Envoy on every file but `full` and `portable`, which serve it, by nginx and by HAProxy, with an admitted origin's CORS answer, where one they take to the count is served: with `client_address: connection` the `x-forwarded-for` and `x-envoy-external-address` the proxy sets count too, so 87 lines from the client reach the count there and 91 elsewhere. A `200` that sets no accepted header is not counted, so with 96 numbered lines beside it the request is served by every proxy. With the accepted header and 91 numbered lines, a request with a chunked body is served, its `Transfer-Encoding` line not counted, and one with a body framed by its length is answered `500`, its `Content-Length` line counted, on `two-checks` and `nginx-checks`, where `haproxy-file` and `nginx-auth`, with three accepted headers and the two the proxy sets under `client_address: connection`, answer both `500` and `full` and `portable`, whose count is 150, serve both; and a gRPC call over HTTP/2 whose accepted header and 87 numbered fields take it past the count is answered `200` with `grpc-status` `2` and reaches no service, and one with 86 is served, where `haproxy-file` and `nginx-auth` answer 86 with `grpc-status` `2` too and `full` and `portable` serve both. nginx's relay reads some of these forms otherwise, and each such row holds nginx's own answer under `by`, named by the row of `auth.ask` or of `auth.when_unavailable` that declares it. Rows for how nginx asks the check hold Envoy's answer, and nginx's own where it declares a difference: the check location's own path asks the check as any other path does; an upload sent with `Expect: 100-continue` that the check refuses gets `100 Continue` first; a request with a body the check allows reaches the service with its body; a sent header that holds the byte `0xE9` reaches the check with a `!` for it, one that holds well-formed UTF-8 reaches it as sent, one that holds well-formed UTF-8 and then a byte that is not reaches it with a `!` for that byte, a header on two lines of characters outside ASCII reaches it as sent, joined by a comma, and a path of well-formed UTF-8 and then a byte that is not, over HTTP/2, is told to it escaped, as the service receives it; an `only_with_header` header sent as a lone tab is not asked; 100 checked streams at once on one HTTP/2 connection are each answered by their own check; an absolute target's host is the host the check is told, whatever the `Host` header; a client's own user, question and unchecked mark do not reach the service when the check allows with none of them, and the check receives none of a client's own removed header, user and mark; a dot segment with a `;` parameter asks the check first, and is answered `400` when the check allows; a denial of a request from a listed origin carries the CORS answer; a WebSocket upgrade the check allows reaches the service, and one it denies is answered with the denial; a header the check's answer sets on one request is not on the next request of the same connection, and a check's `2xx` other than `200` is answered at once on a kept-alive connection; a request the check denies, one whose check is unanswered and one whose check's status is passed on each have a body that holds a request read as a body, and the next request on the connection is answered, where nginx and HAProxy answer a status of `600` `403` and the unanswered one is `403` first on `two-checks` and `nginx-checks`; a client's own `x-proxyfile-method` and `x-proxyfile-path` change nothing the check is told; the check is told the path with an escaped letter, with a dot-dot segment and a query, with a query's escapes of unreserved and of reserved characters, and with a quote; an HTTP/2 request is told its `:scheme`; a client's `HTTP2-Settings` of an h2c upgrade does not reach the check, and with no upgrade it reaches it when `send` covers it; a check's redirect whose `Location` is a path reaches the client as the check sent it; and the request log holds how long a denied request's check took, no check time for a request with no `only_with_header` header, and an unanswered check for a request the check cannot answer under `allow`. A request to a retried route is checked once, before its first try: with one shop backend refusing connections, each of 20 requests the check allows reaches the other backend with the header the check accepted, each of 6 it denies is answered `403` with no service, and each of 10 whose check answers `503` reaches the other backend with the unchecked mark under `allow` and is answered `403` under `deny`. One hundred and fifty-two rows: all on `full`, one hundred and fifty-one on `nginx-auth`, which writes no `auth.jwt.claims`, one hundred and forty-eight on `portable`, which writes neither that nor `routes[].retries`, one hundred and forty-four on `haproxy-file`, which writes none of those and no `log`, one hundred and thirty-two on `nginx-checks`, which writes none of `auth.jwt.claims`, `auth.send` and `log`, no route with `auth = off` and no list of origins, one hundred and twenty-nine on `two-checks`, which writes no `routes[].retries` either, and the three rows of `remove_from_clients` also on `nginx-file` and `nginx-plain`, which write it and no check. | +| the scheme the check is told | `client_address`, `auth.ask`, `auth.accept`, `auth.send_request` | Each row asks the check, which reports the scheme it was told, and the service reports the `x-forwarded-proto` it received. Under `client_address: connection`: an absolute `https` target is served over TLS and told `https`, but by HAProxy, which answers an absolute target `400`, and on `nginx-connection`, over plain HTTP, the Envoy output answers it `403` and asks no check, and nginx serves it and tells the check and the service `http`, the connection's scheme; an HTTP/2 request with `:scheme https` is told `https` over TLS, and on `nginx-connection` the Envoy output tells the check `https` and sends the service `http`, where nginx tells both `http`, a declared difference; and a client's own `x-forwarded-proto` of `https` or `ftp` is replaced by the connection's scheme for the check and the service, by every proxy. Under `forwarded`, on `two-checks`, `nginx-checks` and `nginx-tracing`: an absolute `https` target sent with `x-forwarded-proto: http` is told `https`, the target's scheme, and the service is sent `http`, where HAProxy answers `400`; an HTTP/2 request with `:scheme https` sent with `x-forwarded-proto: http` is told `https` by the Envoy output and `http` by nginx and HAProxy, a declared difference, and the service is sent `http`; and an `x-forwarded-proto` of `ftp` reaches the service as sent, while the Envoy output tells the check `http`, the connection's scheme, and nginx and HAProxy tell it `ftp`, a declared difference, which nginx's list of ways it is less strict names. Each row runs on `full`, `portable`, `nginx-auth`, `haproxy-file` and `nginx-connection`, and the rows whose keys hold no `client_address` on `two-checks`, `nginx-checks` and `nginx-tracing` too. | | timeout | `auth.timeout`, `auth.when_unavailable`, `timeouts.idle` | The check holds the request for 3 s, past `auth.timeout`'s 1500 ms, and its `401`, and its `200`, send their body of 100 bytes a byte every 100 ms, so it ends after 10 s. The request reaches the service with the mark of a request the check could not answer under `allow`, and is answered `403` under `deny`, on `two-checks` and `nginx-checks`, after at least 1.45 s and in under 2.95 s, 50 ms inside the two times because the row reads a different clock from the proxy's and the check's (below). Three rows, on `full`, `portable`, `haproxy-file`, `two-checks`, `nginx-checks` and `nginx-auth`. With `timeouts.idle`, 2 s on `nginx-file`, `nginx-auth` and `haproxy-traffic` and 90 s on `full` and `portable`, three rows more. In "a service silent past the idle time" the stub holds its answer for 3 s (`x-stub-delay: 3s`), and Envoy and nginx answer `504` as `text/plain`, Envoy's own text where nginx's own page would be `text/html`, after at least 1.95 s and under 2.95 s (measured at 2.002 to 2.005 s on Envoy 1.40.2 and on nginx), where `full` and `portable` serve it with `200` after 2.95 s or more. In "an answer that pauses less than the idle time" the stub sends the status and headers, then a space after each of two pauses of 1.25 s (`x-stub-trickle: 2x1250ms`), then its echo: each pause is 0.75 s under the idle time and the answer ends 0.5 s past it, so a limit on the whole answer would end it, and every proxy serves it with `200` after at least 2.45 s. In "a request body that pauses past the idle time" a `POST` with `Content-Length: 4` is sent by hand, `ab`, then `cd` after 3 s: Envoy answers `408` after at least 1.95 s, so the row shows the idle time ended it, where nginx closes the connection with no answer, a declared difference on `timeouts.idle`, and `full` and `portable` serve it with `200` and the body `abcd`. Each bound keeps 50 ms from the time it tests, for the two clocks, and the `504` comes within 1 s past the idle time, for a loaded runner. | | retry | `routes[].retries`, `routes[].rpc.retries` | A request that reached the service is never tried again: a first try the service closes before any answer gives `502`, a gRPC call whose first try is reset gives `grpc-status` `14`, and a `503` from the service is passed on from its first try. A request whose connection a backend refused is tried again on the other: with one of the two shop backends refusing connections, 40 requests to the shop route and 40 gRPC calls to shop are each answered by the other backend; on `nginx-file`, whose shop route writes `retries: 0`, each of the 40 requests to the shop route is answered `502` with no service, as no other backend is tried, or by the backend that is up, and at least one of each, so a proxy that answered every request `502` would fail the row. On `nginx-plain`, whose rpc entry retries once and sends `example.hold.*` to the two backends that take no connection, a call is answered `200` with `grpc-status` `14` after at least 9.95 s and under 10.95 s, the two tries' connect time of 5 s each, and a request to its route `/held/`, which retries once to the same backends, `502` in the same bounds, which a script that found the route's time spent after the first try (`504` at 5 s) or a missing copy for the second try (`500`) fails; on the other files, which list no such method and no such route, both reach the shop route's service. A gRPC call that is not `POST`, a `GET` with gRPC's content type over HTTP/1.1 whose first try the service closes, is answered `200` with `grpc-status` `14` and not tried again. `nginx-auth`, `nginx-checks` and `nginx-plain`, whose shop routes write no retries, get `nginx-file`'s answers there. The rows of a retried route send to `/retried/products/1`, the route `/retried/` of `nginx-file`, `nginx-auth` and `nginx-checks` and the shop route of `full`, which retries; `nginx-plain` serves it by its shop route, which tries each request once, so there each answer is `502` or the other backend's, and at least one of each. nginx reads whole before the first try of a retried route a body with a length of at most 1 MiB and a request with no body, and sends any other, one in chunks among them, as it arrives and tries it once ([nginx](nginx.md#retries)). With one shop backend refusing connections, 40 requests are each answered by the other, and 40 `POST`s with neither `Content-Length` nor `Transfer-Encoding`; of 40 `GET`s whose 180,000 bytes come in one-byte chunks, each reaches the other backend whole through Envoy, which tries it again, and nginx answers `502` each one the refusing backend drew and serves the others, a declared difference; 40 `PUT`s of 1 MiB each reach it whole; of 40 `PUT`s of 1,048,577 bytes, one more than Envoy's buffer for a retry, at least one is answered `507` by Envoy and `502` by nginx, which tries it once, a declared difference; of 40 chunked `PUT`s, and of 40 over HTTP/2 with no content-length, at least one reaches the other backend with its body through Envoy, which tries again a body under its bound, and at least one is answered `502` by nginx, a declared difference. A row that needs the refusing backend drawn, or each backend, sends 40 requests, so a backend drawn at random is missed with a chance of 2^-40. A `PUT` whose first try the service closed once it arrived is answered `502` and not tried again, over HTTP/1.1 and over HTTP/2. A request whose every backend refuses is answered `502` and writes one upstream-failure line, with the flags `URX,UF`, its route and the status `502`, on Envoy and on both nginx versions; the line carries no request id, so the row finds it by route and status among the lines the proxy wrote after the row began. A `PUT` of 1,048,577 bytes with no backend refusing is served once, whole. Nineteen rows on `full` and `nginx-file`, fifteen on `nginx-auth`, which writes no rpc retries, fourteen on `nginx-checks`, which writes no `log` either, and eighteen on `nginx-plain`, which writes no `log`, and fifteen on `haproxy-traffic`, whose rpc entry writes no retries: `portable` writes no retries. | | gRPC | `routes[].rpc`, `routes[].rpc.to`, `routes[].rpc.to.`, `routes[].rpc.to..service`, `rpc.methods`, `rpc.methods[].service`, `rpc.methods[].method`, `rpc.methods[].action`, `rpc.methods[].reports`, `services..grpc`, `auth.ask`, `auth.when_unavailable`, `log` | A method of a package mapped to `shop` reaches shop's gRPC port over HTTP/2 and answers `grpc-status` `0`; a method of any other package reaches `accounts`; the check is told a method's action and reports, and not an action the client sent, and the service receives neither; a gRPC service's `X-Accel-Redirect` is passed on, not followed; a call through a `..` segment reaches the method's path; a call whose service refuses the connection on every backend is answered `200` with `grpc-status` `14`, `content-type` `application/grpc` and no `grpc-message`; a call whose service resets its stream is answered the same, with Envoy's and HAProxy's `grpc-message` naming the reset, where nginx sends none, a declared difference, and a request that is not a gRPC call, sent to that route, `503` with Envoy's text, where nginx and HAProxy answer `502` with no body, a declared difference; a call the check denies is answered in gRPC's form, `200` with `grpc-status` `16` and the denial's body in `grpc-message`, percent-encoded where it holds a `%`, a letter outside ASCII or a line feed. A call the check denies with `403` is answered `200` with `grpc-status` `7`; a call the check cannot answer goes on with the unchecked mark under `allow`, and is answered `200` with `grpc-status` `7` under `deny`; a call whose check's answer cannot be read is a check that could not answer; and a call the check cannot answer logs an unanswered check with the method's action. A call whose accepted header the check sends empty reaches the service with that header empty, where nginx sends a gRPC service none, a declared difference. Sixteen rows: all on `full`, `portable` and `nginx-auth`, fifteen on `haproxy-file`, which writes no `log`, eleven on `two-checks` and `nginx-checks`, which write no `rpc.methods[].action`, and seven on `nginx-file` and `nginx-plain`, which write neither that nor `auth.ask`. | @@ -201,7 +217,7 @@ connection limit, and `haproxy.yaml` gained a service found by DNS, so the row o | an auth-off prefix route | `routes[].prefix`, `routes[].auth`, `auth.ask`, `auth.only_with_header`, `auth.accept`, `auth.send_request` | On `portable`, which sends `/public/` to `shop` with `auth = off` before its other prefix routes: a path under it reaches the service unchecked with a token the check denies, and so does one with a repeated slash, which the service hears merged; a client's own copy of the mark of a request the check could not answer does not reach the service there either. A path that `..`, `%2e%2e`, `..%2f`, `..%5C` or `..\` takes out of `/public/` leaves the route: with a token the check denies it gets the check's `401`, and with a token the check allows it reaches the service, and the check is told the path the service hears, the normalised one; without the normalisation each would stay on the route and reach the service unchecked. `..;` with a token the check denies leaves the route too and gets the check's `401`, and so does an empty segment before a `..`, `/products//../public/readme`, written or, over HTTP/2, escaped, which the `..` removes, where nginx answers `400`, a declared difference. A dot segment with a `;` parameter is answered `400` and reaches no service with no token and with a token the check allows, the `;` written after `%2e%2e` or escaped as `%3B` after `..`. On `full`, which has no such route, the first and the third are answered `401` by the check its shop route asks. A client's own user, question and unchecked mark do not reach the service on that route either, and a request to it logs no check time. Twenty-two rows, on `full`, `portable` and `nginx-auth`, and twenty-one on `haproxy-file`, which writes no `log`. | | client keys | `routes[].rate_limit.by` | On `nginx-plain`, whose route `/limited/` admits one request a minute for each client under `client_address: forwarded`, eleven requests to that route, each after the rows before it, so a `200` is a client's first request and a `429` one whose bucket a row before spent: an `X-Forwarded-For` entry with a port, `10.80.0.1:80`, is the peer, so the next request with no entry is answered `429`; an address, `10.80.0.2`, is a client of its own, and the same address with spaces around it is the same client; an IPv6 address in capitals, `FD02::7`, is a client of its own, and `fd02:0::7`, the same address written another way, is the same client; the last entry of a list, `10.99.0.1, 10.80.0.3`, is the client, and that entry alone is the same client; an address in brackets, one with a leading zero and an IPv6 address with a zone are the peer, whose bucket is spent. On every other file that writes a limit's `by`, no route takes `/limited/`, so each request reaches `shop`. Eleven rows, on `full`, `portable`, `nginx-file`, `nginx-auth` and `nginx-plain`. | | hash | `services..hash.header` | On `nginx-file`, whose service `sessions`, at shop's two addresses, picks a backend by the hash of `x-session-id` on the route `/sessions/`, which no rate limit holds: 20 requests with an empty `x-session-id` all reach one backend, an empty header being a value, and so do 20 whose header comes on two lines, `a` and `b`, and 20 whose two lines come as `c` then `d` and as `d` then `c` in turn, which reach different backends when the lines are hashed in the order they came. A value of `x`, 60,000 spaces and `y` is answered within 2 s, where nginx took about 14 s while its script trimmed the value with a regular expression; on `portable`, whose header size nginx reads in buffers of 49,120 bytes, nginx answers that line `400` itself, a declared difference. `full` and `portable` have no such route and send the path to `shop`, either backend. One value of the header sent 20 times reaches one backend every time on `nginx-file` and on `haproxy-traffic`, whose route `/sessions/` hashes it too. Five rows, on `full`, `portable`, `nginx-file` and `haproxy-traffic`. | -| tracing | `tracing`, `tracing.provider.otel`, `tracing.provider.otel.sample.rate`, `tracing.tags..header`, `tracing.tags..env`, `tracing.tags..default`, `tracing.path_in_url`, `auth.ask`, `auth.accept`, `routes[].rpc`, `origins..hosts` | On `nginx-tracing`, which traces 5% of the requests by their `x-request-id` and sends its spans to the battery's collector, each row sends an id the draw picks, `000001f3-...`, or one it does not pick, `000001f4-...`, and reads from the collector the span that carries its id, or finds none, beside what the service received: a request whose id the draw picks is traced, with a `traceparent` marked sampled, and one whose id it does not pick is not; an id that is not a UUID is drawn by its first eight characters, and one shorter than eight is never traced; a client's sampled `traceparent` continues the client's trace, its span the client's span's child, over HTTP/1.1 and HTTP/2, when the draw picks the id, and is sent on not sampled when it does not; one marked not sampled is never traced, and a malformed one reaches the service as sent, a byte 0xFF and each of two lines with its `tracestate` lines included, with no span, over HTTP/1.1 and to a gRPC service; a `traceparent` and a `tracestate` line after a tab are read as Envoy reads them; one of another version than 00 continues the client's trace and keeps the client's `tracestate`, and is sent on not sampled when the draw does not pick the id; two `tracestate` lines reach the service as one, a `tracestate` holding the byte 0xFF reaches the service and the check as sent, Envoy adds an empty `tracestate` when the client sends no `traceparent`, and a client's `tracestate` reaches the span; the check receives the trace, a parent of another version than 00 and one marked not sampled continued, and no trace beside a malformed `traceparent`; a span carries the Envoy output's fields, its `peer.address` is the connection's whatever `X-Forwarded-For` says, and over HTTP/2 its `http.protocol` says so; its `http.url` holds `http` or `https` alone from `X-Forwarded-Proto`, in any letter case, and the host_header of the route's service; a request no route takes and a path both proxies refuse are named `ingress`, and `%00` in the path, a fragment in the target, a refused upgrade and a request line of another scheme than http and https, which is answered `400`, are not traced; a target of 256 bytes is whole in the span, and a query after characters Envoy escapes, a dot-dot segment, a client's `x-envoy-original-path` and a route with a rewrite each give the span the Envoy output's URL; a header tag reads the first of two lines, and every line joined on a header Envoy joins, one sent empty is not set, one absent takes its default, a tag on a header the check accepts reads the value the check accepted, and its default on a route the check is off for, an environment tag whose variable is unset takes its default, and so does one on a variable named like a property every object has, a value keeps a quote, a backslash and bytes above 0x7F, and a default keeps a dollar, a quote and a backslash; a tag named like a span field replaces it, and keeps the field's value when its header is absent; the tracing headers a client sends do not reach the service; a gRPC call's service receives the span's `traceparent`; a User-Agent after a tab is held by the span without it; a request from a refused origin is traced under its route. nginx's own literals are the differences its rows of `tracing.provider.otel`, `tracing.path_in_url` and `tracing.tags..header` declare: a `traceparent` of another version than 00, or after a tab, is sent on to the service and the check with the client's version and ids and no span, and a `tracestate` after a tab beside a parent gives no span, a User-Agent after a tab gives no span and is sent on not sampled, a gRPC call's malformed `traceparent` on two lines is answered `400`, a target the Envoy output normalises or rewrites, or beside a client's `x-envoy-original-path`, gets no span and is sent on not sampled, and the query after characters Envoy escapes is answered `400` on `nginx-tracing`, whose path nginx refuses, no empty `tracestate` goes with a `traceparent` of nginx's own, the status in a span is a number, a request no route takes has an empty `upstream_cluster`, a refused origin's span is named `ingress`, a target over 256 bytes gets no span, and an empty or absent header tag is set empty. On `full`, which traces 10% with `client_address: connection` to a collector its world leaves unreachable, a row reads what the service received, and nothing the draw decides. | +| tracing | `tracing`, `tracing.provider.otel`, `tracing.provider.otel.sample.rate`, `tracing.tags..header`, `tracing.tags..env`, `tracing.tags..default`, `tracing.path_in_url`, `auth.ask`, `auth.accept`, `routes[].rpc`, `origins..hosts` | On `nginx-tracing`, which traces 5% of the requests by their `x-request-id` and sends its spans to the battery's collector, each row sends an id the draw picks, `000001f3-...`, or one it does not pick, `000001f4-...`, and reads from the collector the span that carries its id, or finds none, beside what the service received: a request whose id the draw picks is traced, with a `traceparent` marked sampled, and one whose id it does not pick is not; an id that is not a UUID is drawn by its first eight characters, and one shorter than eight is never traced; a client's sampled `traceparent` continues the client's trace, its span the client's span's child, over HTTP/1.1 and HTTP/2, when the draw picks the id, and is sent on not sampled when it does not; one marked not sampled is never traced, and a malformed one reaches the service as sent, a byte 0xFF and each of two lines with its `tracestate` lines included, with no span, over HTTP/1.1 and to a gRPC service; a `traceparent` and a `tracestate` line after a tab are read as Envoy reads them; one of another version than 00 continues the client's trace and keeps the client's `tracestate`, and is sent on not sampled when the draw does not pick the id; two `tracestate` lines reach the service as one, a `tracestate` holding the byte 0xFF reaches the service and the check as sent, Envoy adds an empty `tracestate` when the client sends no `traceparent`, and a client's `tracestate` reaches the span; the check receives the trace, a parent of another version than 00 and one marked not sampled continued, and no trace beside a malformed `traceparent`; a span carries the Envoy output's fields, its `peer.address` is the connection's whatever `X-Forwarded-For` says, and over HTTP/2 its `http.protocol` says so; its `http.url` holds `http` or `https` alone from `X-Forwarded-Proto`, in any letter case, and the host_header of the route's service; a request no route takes and a path both proxies refuse are named `ingress`, and `%00` in the path, a fragment in the target, a refused upgrade and a request line of another scheme than http and https, which is answered `400`, are not traced; a target of 256 bytes is whole in the span, and a query after characters Envoy escapes, a dot-dot segment, a client's `x-envoy-original-path` and a route with a rewrite each give the span the Envoy output's URL; a header tag reads the first of two lines, and every line joined on a header Envoy joins, one sent empty is not set, one absent takes its default, a tag on a header the check accepts reads the value the check accepted, and its default on a route the check is off for, an environment tag whose variable is unset takes its default, and so does one on a variable named like a property every object has, one whose variable is set reads it, and one on a set variable named like such a property reads it through the Envoy output and takes its default through nginx, a value keeps a quote, a backslash and bytes above 0x7F, and a default keeps a dollar, a quote and a backslash; a tag named like a span field replaces it, and keeps the field's value when its header is absent; the tracing headers a client sends do not reach the service; a gRPC call's service receives the span's `traceparent`; a User-Agent after a tab is held by the span without it; a request from a refused origin is traced under its route. nginx's own literals are the differences its rows of `tracing.provider.otel`, `tracing.path_in_url` and `tracing.tags..header` declare: a `traceparent` of another version than 00, or after a tab, is sent on to the service and the check with the client's version and ids and no span, and a `tracestate` after a tab beside a parent gives no span, a User-Agent after a tab gives no span and is sent on not sampled, a gRPC call's malformed `traceparent` on two lines is answered `400`, a target the Envoy output normalises or rewrites, or beside a client's `x-envoy-original-path`, gets no span and is sent on not sampled, and the query after characters Envoy escapes is answered `400` on `nginx-tracing`, whose path nginx refuses, no empty `tracestate` goes with a `traceparent` of nginx's own, the status in a span is a number, a request no route takes has an empty `upstream_cluster`, a refused origin's span is named `ingress`, a target over 256 bytes gets no span, and an empty or absent header tag is set empty. On `full`, which traces 10% with `client_address: connection` to a collector its world leaves unreachable, a row reads what the service received, and nothing the draw decides. | | tracing a retried request | `tracing`, `routes[].retries` | With `shop-2` refusing connections, 40 traced requests to the retried route `/retried/` are each answered by `shop-1` and have one span, named `retried`, with `upstream_cluster` `shop_http` and the status `200`, whose trace and span ids are those of the `traceparent` the service read on the try that served it. | | rate limit | `routes[].rate_limit`, `routes[].rate_limit.requests`, `routes[].rate_limit.per`, `routes[].rate_limit.burst`, `routes[].rate_limit.by`, `auth.ask` | After 2.5 s with no request to the route, 60 requests to `/catalog/items` back to back: the first 30 on `full`, `nginx-file` and `nginx-auth` (20 a second and a burst of 10) and the first 20 on `portable` (20 a second and no burst) answer `200`, and at least one of the rest `429`; then, of 60 requests over the limit that carry a token the check denies and one the token filter refuses, at least one is answered `429`, not `401`, so the limit is applied before the token and the check; of 60 `POST`s over the limit with a body of 5 bytes, at least one is answered `429`, and of 60 more with the next request written after the body, at least one ends its connection, so that next request gets no answer (each row after the first sends 60, as a row of 10 that finds the bucket full, which the row before may leave it, gets no `429`); of 60 gRPC calls over HTTP/1.1, told by their content type, with a body and the next request written after it, at least one ends its connection too; of 60 gRPC calls over HTTP/2, at least one is answered `200` with `grpc-status` `8` and `content-type: application/grpc`, and of 60 Connect calls, `POST`s that carry `connect-protocol-version`, at least one `429` with `content-type: application/json`; another route is not limited; and after 2 s with no request to the route, of 40 requests the check denies, the first 30, or 20 on `portable`, are answered `401` and at least one of the rest `429`, so a request the check denies spends a token. On `nginx-file`'s route `/retried-limited/`, which admits 10 requests a minute for all and retries once, with one shop backend refusing connections, the first 10 of 40 requests are answered `200` and at least one of the rest `429`, so a request whose first try was refused spends one token, not two and not none; `full`, `nginx-auth` and `nginx-plain` serve the path by their shop routes, so there at least one answer comes from the backend that is up. Ten rows: all on `full` and `nginx-auth`, nine on `portable`, which writes no retries, eight on `nginx-file` and `haproxy-traffic`, which write no check, and two on `nginx-plain`, whose route `/limited/` has no burst: another route is not limited, and the row of a limited route whose first connections were refused, which its shop route serves. | | cost | `routes[].pattern`, `routes[].prefix`, `origins..patterns`, `limits.request_headers.size` | A path of 14,000 bytes that 24 pattern routes read, sent with an origin a pattern covers, reaches the prefix route's service with `access-control-allow-origin` within 500 ms, and an `Origin` of 8,000 bytes that 64 patterns of two `*` read is answered `403` within 500 ms; the request after each is served, which only a proxy still running answers. Each stopped HAProxy before its patterns ran in steps and its origin patterns were written so they cannot backtrack ([HAProxy](haproxy.md#what-a-pattern-route-costs)). On `nginx-file` the long path is served as on the other files, nginx's header buffers reading a request line as long as the header limit ([nginx](nginx.md#the-header-limits)), and so is a path of 61,000 bytes, about the longest nginx reads at the file's 60 KiB, a head of 61,133 bytes under the 61,376 it reads ("a path of 61,000 bytes, about the longest nginx reads at 60 KiB, that 24 pattern routes read"): every file but `haproxy-file` serves it with `access-control-allow-origin` within 500 ms, and HAProxy answers `414`, a declared difference; an `Origin` of 6,420 bytes that the last of the 64 patterns takes reaches the service with `access-control-allow-origin`, where HAProxy answers `403` before the service, as it answers any admitted `Origin` longer than it echoes, a declared difference, and one of 6,321 bytes that the 64 read is answered `403`, each within 500 ms on `haproxy-file` and `nginx-file`, the files that name an environment with its host, rows of their own because nginx's first form of the patterns refused the first and held a worker past the bound with the second ([nginx](nginx.md#what-a-pattern-route-and-an-origin-pattern-cost)). Two more `Origin`s sit past the bound nginx sets on the origin patterns. One of 16,384 bytes that the last of the 64 patterns takes ("an Origin of 16,384 bytes that the last of 64 patterns of two * takes") and one of 16,385 bytes ("an Origin of 16,385 bytes that the last of 64 patterns of two * takes") are served and echoed within 500 ms by Envoy and answered `403` within 500 ms by nginx, which matches no `Origin` longer than 8,192 bytes against the patterns, a declared difference on `origins..patterns`; HAProxy answers both `431`, as it answers any head that outgrows its buffer, a declared difference. A path of 53,005 bytes that the 24 pattern routes read, with an `Origin` of 8,192 bytes that the last pattern takes, the longest nginx matches, in a head of 61,326 bytes ("a path of 53,005 bytes and an Origin of 8,192 bytes that the last of 64 patterns of two * takes, about the longest head nginx reads at 60 KiB"), is served with the `Origin` echoed within 500 ms on `nginx-file` and `nginx-auth`, the files that write `limits.request_headers.size` and name the `Origin`'s host, and answered `404` on `full` and `portable`. On `full` and `portable`, which name no environment with the long `Origin`'s host, each long `Origin` is answered `404`. Then 3,000 requests over 24 connections at once, each to a path of `/k01/` to `/k40/` and 1,000 random `a` and `b`, which 40 pattern routes of `haproxy-file` read, are each served by the prefix route's service, and the proxy's memory, read through Docker's API, grows by less than 96 MiB and 4 MiB for each CPU Docker gives a container, 144 MiB with 12: HAProxy runs a thread for each CPU, and each keeps the states of its own patterns, where Envoy's RE2 keeps a cache for each pattern. On `haproxy-file` with 12 CPUs, HAProxy grew past the bound on the code before the states of a thread shared one budget and with a budget of about 8 MB a thread, and stays under it with the script's, of about 1 MB. It runs on every file that writes pattern and prefix routes, which `haproxy-file`, `nginx-file` and `nginx-auth`, the files with the 40 routes, share with `full` and `portable`. The row logs the memory it read on every run. Last, 2,000 connections are opened as a raw request's would be, over TLS with the client certificate on the files that write `tls`, and each sends the 65 bytes `GET /products/1 HTTP/1.1`, a line break, `Host: localhost`, a line break, `x-pad: ` and 15 `a`, one more than nginx's first header buffer of 64 bytes, and then nothing ("connections each holding a head just over 64 bytes keep the proxy's memory bounded", on `full`, `portable`, `nginx-file` and `nginx-auth`, the files that write `limits.request_headers.size`). The proxy's memory, read through Docker's API before the first connection opens and 3 s after the last, must grow by less than 64 KiB for each connection, 125 MiB for the 2,000, and every connection must still be open with no answer right after. In the eighteen runs whose times are given below, Envoy grew by 27.4 to 33.5 KiB a connection, median 30.6 KiB, and nginx 1.30.6 and 1.31.8 by 23.3 to 26.5 KiB, median 24.7 KiB, on `nginx-auth`, 27.1 to 30.7 KiB, median 28.8 KiB, on `nginx-file` and 48.5 to 52.1 KiB, median 51.2 KiB, on `portable`. One header buffer of 8 MiB in place of nginx's buffers fails the row with 2,000 connections and passes it with 500, so the row keeps 2,000. The row catches that one large buffer only where the kernel's transparent huge pages are `always`, as Docker Desktop's are, because the buffer then takes a whole huge page of 2 MiB; with `madvise` or `never` such a buffer costs the pages a head touches and can pass the row. On every kernel the row bounds the memory a connection holds, and the generator's own test holds the buffers' form. The row logs the memory it read. Every one runs on `nginx-file` and `nginx-auth`. | @@ -239,14 +255,14 @@ The battery starts every address the files name on one Docker network, so each r | Container | Address | What it is | |---|---|---| -| `proxyfile-conformance-proxy` | `10.0.0.10` | The proxy, with the rendered files read-only at `/config`, the TLS files at `/etc/gateway/tls` and the token CA at `/etc/gateway/jwt`. Its listener, port 10000, is published on `127.0.0.1` at a port Docker picks, so a run never meets a port another program holds. | +| `proxyfile-conformance-proxy` | `10.0.0.10` | The proxy, with the rendered files read-only at `/config`, the TLS files at `/etc/gateway/tls` and the token CA at `/etc/gateway/jwt`, and the environment variables `APP_REGION=eu-1` and `toString=ts1`, which only `nginx-tracing.yaml`'s tags read. Its listener, port 10000, is published on `127.0.0.1` at a port Docker picks, so a run never meets a port another program holds. | | `proxyfile-conformance-shop-1`, `proxyfile-conformance-shop-2` | `10.0.1.11`, `10.0.1.12` | `shop`: HTTP on 8080 and gRPC on 8081. | | `proxyfile-conformance-catalog` | `10.0.2.21` | `catalog` on 8090, an address `examples/full`, `examples/portable` and `conformance/testdata/nginx.yaml` leave to the resolver and the other files write themselves. | | `proxyfile-conformance-hold` | `10.0.2.30` | `hold` on 8095, which only `conformance/testdata/nginx-plain.yaml` names, so it starts only in a world on a file that names its address: a listener that never accepts a connection. It runs with `net.core.somaxconn` at 1, and fills its queue with two connections of its own at start, so the kernel drops the opening packet of every later connection and a client's connect waits until its own time runs out. | | `proxyfile-conformance-hold-2` | `10.0.2.31` | A second listener that never accepts a connection, on 8095, started with the first and as it is: `conformance/testdata/nginx-plain.yaml`'s `held` service has both addresses, so a call its rpc entry retries meets one that takes no connection on each try. | | `proxyfile-conformance-resolver` | `10.0.0.2`, port 53 | The resolver: `catalog.internal.example` is `10.0.2.21`, `collector.internal.example` is `10.0.3.40`, and any other name is NXDOMAIN. | | `proxyfile-conformance-accounts` | `127.0.0.1:7070` in the proxy's own network namespace | `accounts`, HTTP/1.1 and gRPC on one port, and the auth check `auth.ask` names. | -| `proxyfile-conformance-check-1`, `proxyfile-conformance-check-2` | `10.0.3.31`, `10.0.3.32` | `checks`, the check service of `conformance/testdata/two-checks.yaml` and `conformance/testdata/nginx-checks.yaml`: the stub's `accounts` on 7070 at each address, so a row can make one of the two refuse connections. | +| `proxyfile-conformance-check-1`, `proxyfile-conformance-check-2` | `10.0.3.31`, `10.0.3.32` | `checks`, the check service of `conformance/testdata/two-checks.yaml` and `conformance/testdata/nginx-checks.yaml`, and the first of `conformance/testdata/nginx-connection.yaml`: the stub's `accounts` on 7070 at each address, so a row can make one of the two refuse connections. | | `proxyfile-conformance-collector` | `10.0.3.40`, port 4317 | The tracing collector `nginx-tracing.yaml` sends its spans to, and `nginx-tracing-by-name.yaml` by the name `collector.internal.example`, as OTLP over gRPC, started only in those files' worlds, before the proxy. `examples/full` names the same address, which its world leaves unreachable: no request waits for it. | The network is `proxyfile-conformance` on `10.0.0.0/22`, the smallest block that holds every one of these addresses. diff --git a/docs/haproxy.md b/docs/haproxy.md index 68b06d9..d57b783 100644 --- a/docs/haproxy.md +++ b/docs/haproxy.md @@ -369,8 +369,11 @@ worker's exit line). ### Where HAProxy answers the check otherwise than the Envoy output Each difference below is declared on HAProxy's row of its key in -[Portability](portability.md#support-by-proxy-from-the-generators), and none is on -[the list of ways HAProxy is less strict](#where-haproxy-is-less-strict-than-the-envoy-output). In every case measured +[Portability](portability.md#support-by-proxy-from-the-generators), and one alone is on +[the list of ways HAProxy is less strict](#where-haproxy-is-less-strict-than-the-envoy-output): under `forwarded` the +check is told an `x-forwarded-proto` that is neither `http` nor `https` as it arrived, where the Envoy output tells it +the connection's scheme, so a check that decides by the scheme it is told reads the word of the client or of the proxy +in front. In every case measured on HAProxy 3.2.26 and 3.4.7 beside Envoy 1.40.2, the service received a request the check was asked about only after the check let it through; each case counted the requests the service and the check received. @@ -378,7 +381,7 @@ check let it through; each case counted the requests the service and the check r - **`auth.only_with_header`**: over HTTP/2 a request that carries the header with every value empty is asked, where Envoy does not ask it: HAProxy reads an HTTP/2 value of spaces alone as empty, and Envoy asks one, so HAProxy asks both. - **`auth.send`**: the check receives each byte of 0x80 or more that is not part of well-formed UTF-8 in a header it is sent as the client sent it, where Envoy writes a ! for each such byte. - **`auth.when_unavailable`**: with allow, an answer that breaks off inside its header lines, a chunk-size line or a trailer line, by a close or by passing auth.timeout, a 200 or a denial whose body never ends, an answer whose head or trailer section passes 81,920 bytes, a head of more than 100 header lines with a name on two of them, such as set-cookie, and an answer HAProxy cannot read as RFC 9112 writes one (a Content-Length that is not one line of digits, a control byte in a header value, a status line that does not end, a chunk-size line that ends in a bare LF) are answered 403, where Envoy serves the request with the unchecked mark, x-envoy-auth-failure-mode-allowed: true. -- **`auth.send_request`**: over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's, where Envoy tells it the :scheme. +- **`auth.send_request`**: over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's under client_address connection, and under forwarded the x-forwarded-proto it arrived with, or the connection's when it arrived with none, where Envoy tells it the :scheme; under client_address forwarded, an x-forwarded-proto that is neither http nor https, such as ftp, is told as it arrived, where Envoy tells the connection's scheme. - **`auth.accept`**: an accepted header too large for HAProxy's request buffer is answered 403, where Envoy sets it on the request (the sizes are in HAProxy's row of `auth.accept` in [Portability](portability.md#support-by-proxy-from-the-generators)); a * prefix never sets transfer-encoding, host or te from the check's answer, where Envoy sets each; a folded header line of the check's answer reaches the service joined to the value before it by one space, where Envoy keeps the spaces and tabs of both lines and drops the line end. Two forms are refused at render, naming the key: `auth.accept` naming content-length, transfer-encoding, host, te, connection or upgrade in full is refused by `--target haproxy`: HAProxy frames or routes a request by these headers, so the check's answer never sets them; remove the name from auth.accept. And `auth.accept` holding a * prefix that covers content-length, connection or upgrade is refused by `--target haproxy`: the Envoy output sends the body chunked once Content-Length is removed, and leaves a WebSocket upgrade unanswered once Connection or Upgrade is removed, which HAProxy cannot write; write the other names in full, or a longer prefix, or render it for envoy. - **`remove_from_clients`**: names and * prefixes that cover none of content-length, connection and upgrade. A value holding content-length, connection or upgrade, in full or under a * prefix, is refused by `--target haproxy`: the Envoy output sends the body chunked once Content-Length is removed, and leaves a WebSocket upgrade unanswered once Connection or Upgrade is removed, which HAProxy cannot write; write the other names in full, or a longer prefix, or render it for envoy. - **`origins..origins` and `origins..patterns`**: an admitted Origin longer than 872 bytes less the length of cors.expose_headers is answered 403 with the body Invalid CORS request before the check and the service, where the Envoy output echoes it: HAProxy has 1,024 bytes for the lines it adds to an answer. @@ -567,11 +570,12 @@ service what Envoy would not, are in [the next section](#where-haproxy-is-less-s ## Where HAProxy is less strict than the Envoy output These differences are not stricter than the Envoy output: in each, HAProxy serves a request the Envoy output refuses or -ends, or sends a service what the Envoy output would not. HAProxy's parsers decide each before any rule of the file -reads the request, its timeout counts the time without data, and no fetch reads a request trailer, which +ends, or sends a service what the Envoy output would not. HAProxy's parsers decide each but the last before any rule of +the file reads the request, its timeout counts the time without data, and no fetch reads a request trailer, which `option http-drop-request-trailers` removes before the service, so the file cannot close them. A header value that holds a control byte is not among them: the file refuses it with a rule, as Envoy does, and the entry on a trailer's value is -the one that stays. +the one that stays. The last is the file's own: under `client_address: forwarded` it keeps the `X-Forwarded-Proto` a +request arrived with, as the Envoy output keeps it for the service, and tells the check that header. `proxyfile render --target haproxy` counts them on standard error after it writes the files, and HAProxy's column in [Portability](portability.md#support-by-proxy-from-the-generators) names each on its row. Measured on HAProxy 3.2.26 and 3.4.7 beside Envoy 1.40.2: @@ -587,6 +591,7 @@ the one that stays. - **a WebSocket upgrade a service answers without switching passes the service's body**: A WebSocket upgrade a service answers `200` without switching reaches the client with the service's body, where Envoy passes the status and headers with no body. - **a trailer value holding a control byte is served**: A request trailer value holding one of the bytes 0x01 to 0x08, 0x0B, 0x0C, 0x0E to 0x1F or 0x7F is served, the service receiving the body and no trailer, where Envoy answers `400` over HTTP/1.1 and closes the connection over HTTP/2. A header value holding one is answered `400` over HTTP/1.1, as by Envoy, and its stream is reset over HTTP/2, where Envoy closes the connection; HAProxy refuses 0x00, a line feed and a carriage return in either value, with `400` over HTTP/1.1 and a reset stream over HTTP/2. - **without timeouts.request, an answer that keeps arriving runs past 15 s**: Without `timeouts.request`, a service that keeps sending runs past 15 s, where the Envoy output ends a request 15 s after it starts: HAProxy's `timeout server` counts the time without data (on HAProxy 3.4.7, a service that sent one byte a second for 10 s under a 2 s `timeout server` was served). +- **under forwarded, an x-forwarded-proto that is neither http nor https is told to the check as it arrived**: With `client_address: forwarded` and `auth.send_request: true`, a request sent over plain HTTP with `X-Forwarded-Proto: ftp`, such as `GET /products/1 HTTP/1.1`, is told `x-forwarded-proto: ftp` in the request to the check, where the Envoy output tells the check `http`, the connection's scheme. Both send the service `X-Forwarded-Proto: ftp`. Under `connection`, over TLS, both tell the check and the service `https`, the connection's scheme. ## What a file holds to load diff --git a/docs/nginx.md b/docs/nginx.md index 58b02e3..5a555a0 100644 --- a/docs/nginx.md +++ b/docs/nginx.md @@ -199,10 +199,12 @@ It also empties `x-envoy-decorator-operation`, `x-envoy-downstream-service-clust `x-envoy-original-host` and `x-envoy-original-path`, which only a proxy in front may send, besides the `x-envoy-` headers every file empties. A client's own `X-Real-IP` and `Forwarded` pass, as through the Envoy output. With `forwarded` the file writes none of these: the client's `X-Forwarded-For` passes as received, and the client's -`X-Forwarded-Proto` and `x-request-id` are kept when it sends them. These answers are equal to the Envoy output's but -for three refusals, measured on nginx 1.30.6 and 1.31.8 beside Envoy 1.40.2 and named on nginx's request-line row of -[Portability](portability.md#support-by-proxy-from-the-generators), which `proxyfile.js` makes before a route is -picked: +`X-Forwarded-Proto` and `x-request-id` are kept when it sends them. These answers are equal to the Envoy output's, +measured on nginx 1.30.6 and 1.31.8 beside Envoy 1.40.2, but for an absolute `https` target sent over plain HTTP under +`connection`, which nginx serves (below), a tab before or after a value, which reaches the service where Envoy removes +it ([the list](#where-nginx-is-less-strict-than-the-envoy-output)), and three refusals, named on nginx's request-line +row of [Portability](portability.md#support-by-proxy-from-the-generators), which `proxyfile.js` makes before a route +is picked: - **A header name that holds `_` and that nginx reads as one of its own is answered `400`**: `access-control-request-method`, `access-control-request-headers`, `x-request-id`, `x-forwarded-proto`, @@ -230,6 +232,14 @@ empty or, over HTTP/1.1, holds only spaces and tabs; the configuration alone can With `connection` the line is not read and the request is served. Measured on nginx 1.30.6 and 1.31.8 beside Envoy 1.40.2. +With `connection` and no `tls`, an absolute `https` target sent over plain HTTP, such as +`GET https://localhost/products/1 HTTP/1.1`, is served: the service receives `X-Forwarded-Proto: http`, and with +`auth.send_request: true` the check is told `x-forwarded-proto: http`, the connection's scheme, where the Envoy output +answers `403` with the body `Forbidden`, closes the connection and asks no check; with `forwarded` both serve it. It is +a way nginx is less strict than the Envoy output, named in [the list](#where-nginx-is-less-strict-than-the-envoy-output) +and on the `client_address` row of [Portability](portability.md#support-by-proxy-from-the-generators) (measured on nginx +1.30.6 and 1.31.8 beside Envoy 1.40.2). proxyfile 2.2.0 told the check `https` for it, the scheme the target names. + `remove_from_clients` names headers a client may not send. For each name, every route's location sets the header empty (`proxy_set_header ""`, and `grpc_set_header` where the location sends to a gRPC service), and every place `nginx.conf` itself reads a removed name reads it empty, so the request is answered as if the client had not sent it: @@ -806,14 +816,17 @@ With `admin`, nginx listens on `127.0.0.1` at that port and answers three paths `text/plain`, a `QUERY` sent with no `Content-Type` or with an empty one, which over HTTP/1.1 is also one of spaces and tabs alone, and a `#` in the target, `400` with no body and no `content-type`, and HTTP/1.0 `426` with `Upgrade Required` as `text/plain`, the connection closed after each. -- An absolute target is answered as the path it names, or `400` when nginx or the public listener's checks refuse it, as - one with an empty port, user information, a query right after its host or a scheme other than `http` and `https`, - where the Envoy output answers every absolute target `404`. +- An absolute target of `http` or `https` is answered as the path it names, `GET http://localhost/ready` with `200` and + `LIVE`, where the Envoy output answers every absolute target `404`, a way nginx is less strict than the Envoy output + ([the list](#where-nginx-is-less-strict-than-the-envoy-output)). One that nginx or the public listener's checks + refuse, as one with an empty port, user information, a query right after its host or a scheme other than `http` and + `https`, is answered `400`, where the Envoy output answers `404`. - The admin port writes no log line for a request, as the Envoy output writes none. None of the three paths is answered on the public listener: a route takes them as it takes any other path, on both -proxies. The contents of `/stats` and `/server_info`, the status of a refused path, the answer to `TRACE` and to an -absolute target are declared on nginx's `admin` row. +proxies. The contents of `/stats` and `/server_info`, the status of a refused path, the answer to `TRACE` and the `400` +to a refused absolute target are declared on nginx's `admin` row, and the absolute target served as a path is named +there as a way nginx is less strict. ## The auth check @@ -1007,8 +1020,11 @@ nginx versions sent the check `GET /auth/é/ü?x=ß`. The request holds: - with `tracing`, `traceparent` and `tracestate`, as [Tracing](#tracing) says; - with `send_request: true`, `x-forwarded-uri`, the path the route matched, normalised, with each byte of 0x80 or more escaped as the service receives it, and the query as the client wrote it, before a rewrite; `x-forwarded-method`; - `x-forwarded-proto`, the scheme of an absolute target in the letter case it was written in, and otherwise the - connection's scheme, or the client's own `x-forwarded-proto` under `client_address: forwarded`; and + `x-forwarded-proto`, under `client_address: connection` the connection's scheme, the one the service is sent, + whatever scheme an absolute target names, and under `forwarded` the scheme of an absolute target, written in any + letter case, and otherwise the client's own `x-forwarded-proto` as it arrived, whatever word it holds, or the + connection's scheme: the Envoy output tells the check the connection's scheme for an `x-forwarded-proto` of `ftp`, + which nginx tells as `ftp` ([the list](#where-nginx-is-less-strict-than-the-envoy-output)); and `x-forwarded-host`, the host nginx routes by. A client's own copies of those four are replaced, and a client's own `x-gateway-timeout-ms` is never sent. @@ -1308,22 +1324,24 @@ lets the request through, closing the connection after it, as the Envoy output d ### Where nginx answers the check otherwise than the Envoy output Each difference below is declared on nginx's row of its key in -[Portability](portability.md#support-by-proxy-from-the-generators). Three entries of [the list of ways nginx is less +[Portability](portability.md#support-by-proxy-from-the-generators). Four entries of [the list of ways nginx is less strict](#where-nginx-is-less-strict-than-the-envoy-output) concern the check: past the bound of local ports the `auth.ask` note gives, a check fails for want of a port, and with `allow` its request is served with the unchecked mark, so a request the check would refuse can be served; a worker with none of its 8192 connections left cannot ask the check either, with the same result under `allow`, as [Checks in flight on few workers](#checks-in-flight-on-few-workers) says; -and the request of a client that closes its connection while its check is asked can still reach the service once the -check allows it, as the last sentence on the request line says. In each of the others, a request the check refuses stays -refused, and nginx either refuses or holds a request the Envoy output serves, or answers or writes a line otherwise. The -words are the words of the declaration. +the request of a client that closes its connection while its check is asked can still reach the service once the +check allows it, as the last sentence on the request line says; and under `client_address: forwarded` the check is told +an `x-forwarded-proto` that is neither `http` nor `https` as it arrived, where the Envoy output tells it the +connection's scheme, so a check that decides by the scheme it is told reads the word of the client or of the proxy in +front. In each of the others, a request the check refuses stays refused, and nginx either refuses or holds a request +the Envoy output serves, or answers or writes a line otherwise. The words are the words of the declaration. - **`auth.ask`**: a request whose check answers in one of these forms is answered 403: a status outside 100 to 599, such as 2, 99, 600 or 2000, or 101, where Envoy passes the status on to the client; HTTP/2.0 or HTTP/1.2, two spaces or a tab after the version, a + before the status, a tab between the status and the reason, a lone CR, a space or a tab after a chunk size, a chunk size of nine hex digits, a chunk extension holding a control byte or a quoted CR LF, a chunk-size line past 1,024 bytes, bytes between a chunk's data and its line end, a folded trailer line, or a head of exactly 81,920 bytes with a line in a bare LF, which nginx counts a byte longer, where Envoy reads the answer; a 200 whose body passes 1 MiB, where Envoy serves the request; a denial whose body passes 1 MiB, where Envoy passes the denial on; a denial whose head has more than 100 header lines, folded lines not counted, with a name on two of them, where Envoy counts a name it keeps inline, such as date, once and passes the denial on; over HTTP/2, a gRPC call refused for the check's denial, or with deny for want of a readable answer, is answered as Envoy answers it, with one more header, content-length: 0; a check's 301, 302, 303, 307 or 308 to an HTTP/1.1 request that carries a body reaches the client with nginx's own page in place of the check's body, and a check's 304 to such a request with content-length: 0, as nginx discards the request's body, so that no byte of it is read as the next request; a denial reaches the client with Server: nginx where the check sent no Server header, with nginx's own reason phrase (302 Moved Temporarily, where Envoy writes Found), without a header line the check sent with an empty value, with the check's Access-Control-Allow-Origin beside the listed origin's own, where Envoy sends the origin's alone, and, to a HEAD request, with Content-Length: 0, where Envoy sends transfer-encoding: chunked; an error in proxyfile.js itself as it asks the check or reads its answer is answered 403, with allow too, and writes no log line; the check is sent connection: close on a new connection for each check, where Envoy sends no Connection header and keeps its connections to the check open, so nginx's local ports bound how many checks a second it can send to one check address: near 340,000 a second when the check closes its connection first after it answers, derived from the 0.13% of connections nginx's side then kept in TIME_WAIT and not reached, and about 470 a second when it does not, at most 28,231 checks to one address in any 60 s from the 28,232 ports of 32768 to 60999 (measured on nginx 1.30.6 and 1.31.8 beside Envoy 1.40.2); past that bound a check fails for want of a port, and its request is answered 403 with deny and served with the unchecked mark with allow; the relay listens on a socket file, /run/proxyfile-/check.sock, which nginx removes when it stops and a kill leaves, and nginx then does not start, its bind() to the file failing (98: Address already in use), until the file is removed or /run is a tmpfs. - **`auth.timeout`**: with allow, the request goes on with the unchecked mark at the first byte the check sends after auth.timeout, or after one auth.timeout with no byte from it, so a check that sends a byte just before each auth.timeout of silence holds the request up to twice auth.timeout, where Envoy goes on at auth.timeout. - **`auth.when_unavailable`**: with allow, a request whose check answers in a form Envoy reads as no answer (a malformed header line, framing or status line, a head or a trailer section past the 81,920 bytes Envoy reads, a head of more than 100 header lines with a name on two of them, such as set-cookie, or a body that never ends) is answered 403, where Envoy serves it with the unchecked mark, x-envoy-auth-failure-mode-allowed: true. - **`auth.only_with_header`**: over HTTP/1.1 a request whose header is a lone tab is asked, where Envoy does not ask it: nginx keeps the tab, which Envoy removes; over HTTP/2 a cookie sent as two or three empty cookie fields is asked, where Envoy does not ask it. One form is refused at render, naming the key: `auth.only_with_header` naming a header that remove_from_clients, auth.accept or the proxy itself removes from clients is refused by `--target nginx`: the Envoy output removes that header before it reads it and never asks the check, where nginx asks it; name a header the proxy passes on. - **`auth.send`**: a client's own x-proxyfile-method and x-proxyfile-path are not sent to the check when send covers them, where Envoy sends them; what the check is asked does not change. -- **`auth.send_request`**: in a file with no pattern route, a path holding a character Envoy escapes before it picks a route (" < > ^ ` { | }) is told in x-forwarded-uri as the client wrote that character, where Envoy tells it escaped; the service receives it escaped from both; over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's, where Envoy tells it the :scheme. +- **`auth.send_request`**: in a file with no pattern route, a path holding a character Envoy escapes before it picks a route (" < > ^ ` { | }) is told in x-forwarded-uri as the client wrote that character, where Envoy tells it escaped; the service receives it escaped from both; over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's under client_address connection, and under forwarded the x-forwarded-proto it arrived with, or the connection's when it arrived with none, where Envoy tells it the :scheme; under client_address connection, so is an absolute target over HTTP/1.1 whose scheme differs from its connection's: an http target sent over TLS is told https, where Envoy tells it http; under client_address forwarded, an x-forwarded-proto that is neither http nor https, such as ftp, is told as it arrived, where Envoy tells the connection's scheme. - **`auth.accept`**: names written in full, none of them a header nginx writes itself on the request it passes on; a request the accepted headers take past limits.request_headers is answered 500 as by Envoy, counted with the client's own Connection line, its own copies of the headers the proxy sets, each line of a name sent on several lines and each cookie field over HTTP/2, which Envoy drops, replaces or joins into one before it counts, so such a request can be answered 500 by those lines sooner; an accepted header the check sends empty reaches a gRPC service as no header, where Envoy sends it empty. Two forms are refused at render, naming the key: `auth.accept` holding a name with a `*` prefix is refused by `--target nginx`: nginx sets a request header only by a name its configuration writes; write each name in full. And `auth.accept` naming a header nginx frames or routes a request by is refused by `--target nginx`: nginx writes this header itself on the request it passes on, to frame or route it or to keep a client's copy from the service, x-forwarded-for, x-envoy-external-address and the five x-envoy- names Envoy removes from clients only with client_address: connection, and a check service must never change how nginx frames or routes that request; each is refused with either client_address, so a list stays valid when it changes; remove the name from `auth.accept`. - **`log`**: the request line holds `authz_us` in whole milliseconds, and a request refused for a dot segment with a `;` parameter logs `route` empty on each of its lines, where the Envoy output names the route that refuses it, `refused:dot-segment-with-parameter` ([The request log with the check](#the-request-log-with-the-check)). - **the request line and header names read before a route is picked**: a client that closes its side of the connection right after its request gets nginx's answer when nginx refuses the request itself, an Origin on none of the hosts, a target holding a fragment, a dot segment with a ; parameter or HTTP/1.0, where Envoy closes the connection with no answer. For a request a service answers, each proxy gives the client no answer when it reads the FIN before the service answers, and the service's answer when the answer comes first: with the FIN sent with the request, the service received 148 of 300 such requests through Envoy and 1 and 0 of 300 through nginx 1.30.6 and 1.31.8, and no client got an answer; with the FIN 1 ms later, the service received 298, 297 and 299 of 300, and nearly every client got its answer; with a service that answers 50 ms late, no client got an answer (measured with no `auth` beside Envoy 1.40.2, from the host through Docker's port forwarder). The same rule holds for both proxies, so it is not on the list of ways nginx is less strict. With the check asked it does not hold: a client that half-closed while its check was asked got no answer from either proxy (200 of 200 each), but once the check allowed the request nginx still sent it to the service, 17 and 23 times of 30 when it held idle connections to the service, where the Envoy output sent none; that, with a close and a reset, is on [the list of ways nginx is less strict](#where-nginx-is-less-strict-than-the-envoy-output). @@ -1706,13 +1724,16 @@ their `service.name` (`otel_service_name`), as the Envoy output sends them. `user_agent`, `http.protocol`, `peer.address`, `request_size`, `response_size`, `component`, `upstream_cluster` and `upstream_cluster.name`, whose values equalled the Envoy output's over HTTP/1.1 and HTTP/2, with a body, for a `503` and for a gRPC call. The scheme of `http.url` is `http` or `https` alone, as in the Envoy output's: an absolute - target's own, otherwise, under `client_address: forwarded` over HTTP/1.1, a client's `X-Forwarded-Proto` that is one - of the two words in any letter case, with spaces or tabs around it, and otherwise the connection's; over HTTP/2 nginx - writes the connection's, where the Envoy output writes the client's `:scheme` when it is `http` or `https`. Its host - is the one the Envoy output's holds: the route's service's `host_header` when it writes one, and otherwise the host - the request names. Beside them the module sets fields of its own, which no line removes: `http.method`, `http.target`, - `http.route`, `http.scheme`, `http.flavor`, `http.user_agent`, `http.status_code`, `http.request_content_length`, - `http.response_content_length`, `net.host.name`, `net.host.port`, `net.sock.peer.addr` and `net.sock.peer.port`. + target's own, so `https` for one sent over plain HTTP under `client_address: connection` too, though the service and + the check are sent `http` for it and the Envoy output answers it `403` with no span (measured on nginx 1.30.6 and + 1.31.8 beside Envoy 1.40.2), otherwise, under `client_address: forwarded` over HTTP/1.1, a client's + `X-Forwarded-Proto` that is one of the two words in any letter case, with spaces or tabs around it, and otherwise the + connection's; over HTTP/2 nginx writes the connection's, where the Envoy output writes the client's `:scheme` when it + is `http` or `https`. Its host is the one the Envoy output's holds: the route's service's `host_header` when it writes + one, and otherwise the host the request names. Beside them the module sets fields of its own, which no line removes: + `http.method`, `http.target`, `http.route`, `http.scheme`, `http.flavor`, `http.user_agent`, `http.status_code`, + `http.request_content_length`, `http.response_content_length`, `net.host.name`, `net.host.port`, `net.sock.peer.addr` + and `net.sock.peer.port`. `http.route` holds the name of the location nginx generated for the route, such as `@pf_r_1`, not the route's name, which the span's name holds, and `net.host.name` the server's name, or, on the server that answers a host no environment names, the `Host` the client sent, which that span's `http.url` holds too. None of them carries a header @@ -1804,9 +1825,11 @@ in these words: escaped or rewrote, cut to 256 characters, or a client's x-envoy-original-path. Tracing adds no entry to [the list of ways nginx is less strict than the Envoy -output](#where-nginx-is-less-strict-than-the-envoy-output), which has 15 entries: each difference above was measured and -is declared on its key's row, none sends the collector, the service or the check a header or a token the Envoy output -does not send, and no request waits for the collector ([What tracing costs](#what-tracing-costs)). +output](#where-nginx-is-less-strict-than-the-envoy-output): each difference above was measured and is declared on its +key's row, none sends the collector, the service or the check a header or a token the Envoy output does not send, and +no request waits for the collector ([What tracing costs](#what-tracing-costs)). A tab before or after a header value, +such as a client's `x-request-id` under `forwarded` or a `User-Agent`, reaches the service with tracing as without it, +one of the entries of that list. ### What nginx refuses of tracing @@ -1869,9 +1892,11 @@ The figures below were measured on one Mac running Docker with 12 CPUs, so nginx other container above 3% of one CPU. Each is the median of five runs with their range in brackets, unless it names another number of runs, for nginx 1.30.6 and 1.31.8 on their images tagged `-otel` beside the Envoy output on Envoy 1.40.2, all rendered from one file with -`sample.rate` at 100%, so each request makes a span, with two tags, and a route with the auth check beside one without; -the proxies started afresh for each run, and a client on the same Docker network sent the requests. One proxy is said to -answer sooner, hold less or lose fewer spans than another only where their ranges do not overlap. +`sample.rate` at 100%, so each request makes a span, with two tags, one of an environment variable and one of a header, +and a route with the auth check beside one without; the proxies started afresh for each run, and a client on the same +Docker network sent the requests. One proxy is said to answer sooner, hold less or lose fewer spans than another only +where their ranges do not overlap. The answer times, the memory at rest and the collector's states were measured before +this version changed how an `env` tag's variable is read, and the memory under load with it. With a collector that answers each call at once, every request was answered `200` and every span reached the collector in each run: 201 requests one at a time, 201 one at a time through the check, then 1,000 a second for 30 s, of which @@ -1895,29 +1920,40 @@ without it the ranges just overlap, and they overlap through the check and at 1, Tracing costs nginx memory under load, which it keeps. Over 300 s of 1,000 requests a second to the route with no check, each proxy started afresh with nothing sent to it before, the memory Docker counted, in MiB, was as follows, one run of -each: nginx 1.31.8 with the collector asked by its address, nginx 1.30.6 through the relay with the collector found by -name, a run of 900 s, and the file without `tracing` and the Envoy output, taken before with the same file and client. -nginx 1.31.8 through the relay and 1.30.6 asking the address were not run for 300 s. +each: nginx 1.31.8 and 1.30.6 with the collector asked by its address, and the file without `tracing` and the Envoy +output, taken before with the same file and client. Both runs of nginx with tracing started with no other container +above 3% of one CPU; another project's test containers used about one and a half CPUs at the end of 1.31.8's, and none +was above 3% at the end of 1.30.6's. Neither version was run for 300 s through the relay, with the collector found by +name, with this version's script. | | At rest | 15 s | 60 s | 120 s | 180 s | 240 s | 300 s | 120 s after the load | |---|---|---|---|---|---|---|---|---| -| nginx 1.31.8, by address | 58.2 | 486.6 | 510.7 | 518.5 | 525.2 | 525.6 | 525.1 | 524.2 | -| nginx 1.30.6, through the relay, 900 s | 58.3 | 301.9 | 308.4 | 311.7 | 325.6 | 326.3 | 324.0 | 325.4 | +| nginx 1.31.8, by address | 58.1 | 208.2 | 216.5 | 219.7 | 222.1 | 223.0 | 222.7 | 223.0 | +| nginx 1.30.6, by address | 58.4 | 141.9 | 147.9 | 160.4 | 171.9 | 175.1 | 175.7 | 175.6 | | nginx 1.31.8 without `tracing` | 51.3 | 55.3 | 55.1 | 56.6 | 56.7 | 57.9 | 57.6 | 55.8 | | nginx 1.30.6 without `tracing` | 51.8 | 56.0 | 56.4 | 56.9 | 57.6 | 57.9 | 58.3 | 57.2 | | Envoy output, by address | 22.9 | 25.3 | 25.0 | 25.1 | 24.9 | 24.6 | 25.3 | 25.3 | -nginx 1.31.8 came within 1 MiB of its highest at 180 s, and 1.30.6 at 165 s, where it stayed between 323.9 and 329.0 MiB -to the end of its 900 s; neither gave more than 1 MiB of it back in the 120 s after the load. The module keeps at most -four batches of 512 spans in each worker, its defaults, which the file keeps, and keeps each span's strings when a batch -is sent, to fill them again: memory rises until each worker's 2,048 spans have held their longest values, 24,576 spans -for the 12 workers here, and stays there. So the cost grows with the number of workers, one a CPU (`worker_processes -auto`): at the end of the load each worker held 40.0 to 49.7 MiB of its own on 1.31.8 and 25.1 to 33.6 MiB on 1.30.6, -against 8.4 MiB at rest. More than half of it comes with the work `proxyfile.js` does for the tags of each request, as -the spans fill: through the relay, 30 s into the load, the file held 305.7 and 365.1 MiB on 1.30.6 and 333.2 and 334.8 -MiB on 1.31.8, where a copy of its script whose tag function returns before it reads anything held 154.6 and 170.2 MiB -on 1.30.6, two runs each. A file with the module and one proxied location alone levelled at 57.2 MiB on 1.30.6 and 57.1 -MiB on 1.31.8 (one run each). +nginx 1.31.8 came within 1 MiB of its highest at 150 s and 1.30.6 at 240 s, and neither gave more than 1 MiB of it back +in the 120 s after the load. The module keeps at most four batches of 512 spans in each worker, its defaults, which the +file keeps, and keeps each span's strings when a batch is sent, to fill them again: memory rises until each worker's +2,048 spans have held their longest values, 24,576 spans for the 12 workers here, and stays there. So the cost grows +with the number of workers, one a CPU (`worker_processes auto`): at the end of the load each worker held 19.9 to 22.4 +MiB of its own on 1.31.8 and 15.9 to 20.7 MiB on 1.30.6, against 8.4 MiB at rest. +How `proxyfile.js` reads the tags of each request changes it. On nginx 1.31.8 asked by address, the script of proxyfile +2.2.0, which asked `process.env` with `hasOwnProperty` before it read an `env` tag's variable, held 523.5 MiB at 300 s +(520.9 to 524.5, three runs), each worker 38.7 to 49.8 MiB; the same script asking `process.env` once for each traced +request, with no other change, held 219.7 MiB, and with the tags read as before the script read their sources in one +pass, each source on its own and the values joined in one text, 266.3 MiB (one run each). Another container was above +3% of one CPU at the start of the 219.7 MiB run, and another project's test containers at the end of one of the three +runs and of both of these, up to about two CPUs. The three scripts send the same spans, so the module's batches are not +the one cause of what a worker holds: why the call with `hasOwnProperty` left memory held in each worker, outside the +script's own heap, was not found, and how much of what a worker holds now comes with the script's work for the tags and +how much with the module's spans was not measured. This version asks `process.env` once for each traced request and +takes the variable only when it is a string, which no name every object inherits gives. On nginx 1.30.6 the script of +2.2.0 was measured under load only through the relay, in one run of 900 s, so how much this version saves there was not +measured. A file with the module and one proxied location alone levelled at 57.2 MiB on 1.30.6 and 57.1 MiB on 1.31.8 +(one run each). With the collector in each of five states, 201 requests one at a time and then 5,001 at 500 a second over 16 connections were sent to each proxy, each proxy started with the collector already in that state: up; an address nothing answers on; @@ -2054,7 +2090,9 @@ otherwise. `400` and the connection closed**, where Envoy serves it with the host the line names. One of another scheme than `http` or `https`, in any letter case, such as `ftp://`, `ws://`, `h2c://`, `httpx://` or `x-y+z.1://`, is answered `400`, as by Envoy, and reaches no service, over 33 forms measured. Any other absolute request line routes by the host - it names, as Envoy's does, however many spaces come before it; one whose host a query or a fragment follows directly, + it names, as Envoy's does, however many spaces come before it, but an `https` one sent over plain HTTP under + `client_address: connection`, which the Envoy output answers `403` + ([the list](#where-nginx-is-less-strict-than-the-envoy-output)); one whose host a query or a fragment follows directly, `GET http://localhost?x=1`, is answered `400` and the connection closed, where Envoy answers `404` and keeps it. A tab between the method and the target is answered `400` and the connection closed, where Envoy serves the request. - **A `Host` header sent twice is answered `400`**, where Envoy answers `404`; over HTTP/2, a `host` header that differs @@ -2070,10 +2108,13 @@ otherwise. `if-range` is answered `400` by nginx with its own page, where Envoy joins the lines with a comma and serves the request. `cookie`, `range`, `x-real-ip`, `accept-language`, `date` and a header of a name of your own reach the service alike through both. -- **Over HTTP/1.1 a tab before or after a header value reaches the service with the value**, where Envoy removes it, the - same message written another way: RFC 9110 does not count the white space around a field value as part of the value. - A header `X-A` with the value `v` and a tab on each side reached the service as `x-a: v` through Envoy and with its two - tabs through nginx 1.30.6 and 1.31.8, which removes the spaces around a value. +- **Over HTTP/1.1 a tab before or after a header value reaches the service with the value**, where Envoy removes it. A + header `X-A` with the value `v` and a tab on each side reached the service as `x-a: v` through Envoy and with its two + tabs through nginx 1.30.6 and 1.31.8, which removes the spaces around a value; a `User-Agent`, and a client's + `x-request-id` under `client_address: forwarded`, sent with a tab before the value or after it, reached the service + with that tab too. RFC 9110 does not count the white space around a field value as part of the value, so a service + that reads the value as it says reads the same value through both, but one that reads the bytes reads the tab: [the + list of ways nginx is less strict](#where-nginx-is-less-strict-than-the-envoy-output) names it. - **`TRACE` and `CONNECT` are answered `405`, and `OPTIONS *` `400` with the connection closed**, where Envoy passes `TRACE` to the service and answers the other two `404`. - **A `Connection` header naming a header other than `close`, `keep-alive`, `upgrade`, `http2-settings` and `te` is @@ -2089,8 +2130,8 @@ otherwise. closes the connection: the bytes 0x01 to 0x08, 0x0B, 0x0C, 0x0E to 0x1F and 0x7F. Over HTTP/1.1 both answer `400` to each of those bytes. nginx alone passes such a value to the service, so `proxyfile.js` refuses it. nginx refuses 0x00 itself, as Envoy does, and a carriage return, which Envoy serves over HTTP/1.1 with the carriage return dropped - (the service receives `x-a: bc` for `x-a: b`, CR, `c`); over HTTP/1.1 a line feed ends the header line. A tab, a byte - above 0x7F and UTF-8 reach the service as through Envoy. + (the service receives `x-a: bc` for `x-a: b`, CR, `c`); over HTTP/1.1 a line feed ends the header line. A tab inside + the value, a byte above 0x7F and UTF-8 reach the service as through Envoy. - **A request trailer whose name holds a character outside RFC 9110's token characters, such as `x@at`, or whose value holds a control byte, is let through over HTTP/1.1**: nginx serves the request, and the service receives its body and no trailer, where Envoy answers `400`. The bytes are 0x00 to 0x08, 0x0B, 0x0C, 0x0E to 0x1F and 0x7F; nginx answers a @@ -2129,14 +2170,18 @@ ends, sends a service or a client what the Envoy output would not, or leaves out - **a header line with no colon reaches the service as a header with an empty value**: A request holding the line `nocolon`, with no colon, is served over HTTP/1.1, and the service receives `nocolon: `, where Envoy answers `400`. nginx stores such a line as a header with an empty value, as it stores `nocolon:`, which Envoy serves too, so neither `nginx.conf` nor `proxyfile.js` can tell the two apart. - **a request with no body reaches the service without content-length: 0**: A `POST` with no body reaches the service with no `Content-Length`, over HTTP/1.1 and HTTP/2, where Envoy adds `content-length: 0`. - **a Referer the Envoy output removes reaches the service**: Of 104 forms of one Referer line, Envoy removed 46 before the service, such as `a:b`, `/a#f`, `a b`, `/é`, `{`, `http://u@a/`, `http://a/#f`, `http://a:65536/`, `http://a_b/`, `http://[1:2:3]/` and `about:blank`, and nginx passed every one on. The Envoy output removes a Referer that its URL parser reads as a URL with a fragment or user information, or that the parser does not read and that holds a byte outside RFC 3986's query and fragment characters or a colon before its first slash. A rule written from the published grammar of that parser, nodejs's http_parser, answered forms of the 104 otherwise than Envoy: in its strict build it removed `h2://a/` and `x-y://a/`, whose scheme Envoy reads with a digit or a `-` in it, and in its lenient build it also kept `http://a_b/` and `http://a/é`. nginx answers two Referer lines `400`, as the request line's row says. +- **over HTTP/1.1, a tab before or after a header value reaches the service**: A header value sent over HTTP/1.1 with a tab right after its colon or at its end reaches the service with the tab, where Envoy removes it: the service receives `User-Agent` as a tab and `probe/3`, or as `probe/4` and a tab, and `X-A` as a tab and `b5`, where through Envoy it receives `user-agent: probe/3`, `user-agent: probe/4` and `x-a: b5`, under `client_address: forwarded` and under `connection`. Under `forwarded` a client's `X-Request-Id` sent as a tab and `abc-1`, or as `abc-2` and a tab, reaches the service with the tab too, and nginx's answer gives it back to the client with the tab, where Envoy sends `abc-1` and `abc-2` to both; under `connection` each proxy sends an id of its own in its place. A service that reads the value as RFC 9110 says, without the white space around it, reads the same value through both. - **a WebSocket upgrade a service answers without switching passes the service's body**: A WebSocket upgrade a service answers `200` without switching reaches the client with the service's body, where Envoy passes the status and headers with no body. - **a service's answer with a malformed header line or a malformed status line reaches the client**: A service's answer holding a header line with no colon reaches the client with it as a header with an empty value (`nocolon: `), and one whose header name holds `@` (`x@bad: 1`) or whose header value holds the byte 0x01 reaches the client with that header as the service wrote it, where Envoy answers `502` and writes an upstream-failure line with the flag `UPE`, which nginx does not write. A malformed status line reaches the client too. A status of three digits that starts with 0, `050`, `000` or `099`, reaches it as that status over HTTP/1.1 and HTTP/2, with the headers nginx writes. A status with spaces between its digits, `HTTP/1.1 2 0 0 X`, reaches an HTTP/2 client as `200` and an HTTP/1.1 client with the status line `HTTP/1.1 0 0 X`, and one with a fraction, `HTTP/1.1 403.1 X`, reaches an HTTP/2 client as `403` and an HTTP/1.1 client as the service wrote it: nginx reads three digits with spaces among them, and takes a `.` after them. A status of one or two digits, such as `5`, `20` or `99`, one of four digits, `HTTP/1.1 2000 OK`, and an answer with no status line at all, such as `hello` and a line end, reach an HTTP/1.1 client byte for byte as the service wrote them, with none of the headers nginx writes, such as `x-request-id` and `Vary`, and an HTTP/2 client as the body of an answer with the status `000`: nginx reads such an answer as one with no head and passes it whole. Envoy answers each of these `502` and writes an upstream-failure line with the flag `UPE`, but the status of four digits, which it passes as `2000` with its own headers; nginx writes no upstream-failure line for any of them, and has no setting that refuses them. nginx stores a line with no colon as it stores `nocolon:`, which Envoy passes too, so `proxyfile.js` cannot tell the two apart. - **over HTTP/2, empty frames in a row are served**: An HTTP/2 request whose HEADERS frame is followed by two empty CONTINUATION frames, or whose body comes after two empty DATA frames, is served, where Envoy takes one frame with no payload in a row and closes the connection at the second: nginx sets no such limit, and neither `nginx.conf` nor `proxyfile.js` sees a frame. +- **the admin listener serves an absolute target of http or https as the path it names**: `GET http://localhost/ready HTTP/1.1` sent to the admin listener is answered `200` with `LIVE`, and so is the same target with `https://` or `HTTP://`, and `http://localhost/stats` and `http://localhost/server_info` are answered `200` with nginx's counters and its version, where the Envoy output's admin listener answers `404` with no body to every absolute target. A path the admin listener does not answer, `http://localhost/nothing`, is answered `404` by both, and a target of another scheme, `ftp://localhost/ready` or `ws://localhost/ready`, `400` with the body `Bad Request` and the connection closed, where the Envoy output answers `404`. +- **under connection, an absolute https target sent over plain HTTP is served**: With `client_address: connection` and no `tls`, an absolute `https` target sent over plain HTTP, such as `GET https://localhost/products/1 HTTP/1.1`, or the same with `HTTPS://`, is served: the service receives `X-Forwarded-Proto: http`, and with `auth.send_request: true` the check is told `x-forwarded-proto: http`, the connection's scheme, where the Envoy output answers `403` with the body `Forbidden`, writes `http1.https_url_on_plaintext_connection` in its request log, closes the connection and asks no check. Under `forwarded` both serve it, and the service receives `x-forwarded-proto: http` through both. - **without timeouts.request, an answer that keeps arriving runs past 15 s**: Without `timeouts.request`, an answer that keeps coming runs past the 15 s at which the Envoy output ends a request: nginx counts its limits between two reads or writes. - **without timeouts.request, a request body its service does not read, or reads slowly, runs past 15 s**: On a route with no retries, and for a request a retried route sends on as it arrives, nginx sends the body with its send time, which counts between two writes and is 5 minutes without `timeouts.idle`. A `PUT` of 1 MiB to a service that takes the connection and does not read it, or reads one byte every 20 s, is answered `504` after 300.1 s (300.0 to 300.2 in three runs), where the Envoy output answers `504` after 15.0 s; a `PUT` of 2 MiB or of 64 MiB, or of 2 MiB in chunks, gets nginx's `504` after 300.1 s too, where the Envoy output answers `408` after 300.0 s (on a retried route, in one of three runs, `504` after 15.0 s). Tried: a send time of the read time, 15 s, in each location that streams a body. It answered every one of those `PUT`s `504` after 15.1 s (15.0 to 15.1), those the Envoy output answers `408` after 300 s among them, to the service that reads one byte every 20 s too, so it is not written; a client that stopped its body for 20 s was served by all three with it and without it. Not written either: reading a body of at most 1 MiB whole before sending it, on every route as a retried route does. That answers such a `PUT` as the Envoy output does, `504` after 15.0 s, as the retried route's location answered it, but a route with no retries would then hold each such body in memory, and its service would get nothing of an upload until all of it had arrived. A service that reads a body slowly but takes a write within the send time each time is sent all of it, on every route, and the send time does not end its try; a retried route's location sends the body it read whole with the route's read time as its send time. A `PUT` of 1 MiB to a service that reads 65,536 bytes every 1.5 s, in three runs of each, is answered `504` after 27.0 s by nginx 1.30.6 and 27.1 s by 1.31.8 on a retried route (27.0 to 27.1) and after 18.1 s by both on a route with no retries (18.1 in every run), where the Envoy output answers `504` after 15.0 s on both (15.0 in every run). The retried route's send time of 15 s did not end it, and no setting ends such a try at the route's time, as none ends an answer that keeps arriving: nginx has no time for a whole try. - **with allow, a check service that does not close its connection right after its answer leaves requests unchecked past about 470 checks a second**: When the check service does not close its connection right after its answer (measured: 20 ms or more after it, or not at all), nginx closes it first, so each check holds one of nginx's local ports in `TIME_WAIT` for 60 s: with the 28,232 local ports of 32768 to 60999 that is about 470 checks a second to one check address, past which nginx cannot open a connection to the check, and with `allow` the request is then served with the unchecked mark, where the Envoy output keeps its connections to the check open and goes on asking. `proxy_half_close on` does not change which side closes first. - **with allow, a worker with none of its 8192 connections left serves requests unchecked**: Each checked request in flight holds four of a worker's connections, and every other connection of the worker, a client's or a service's, counts against the same 8192 (`worker_connections`). A worker with none left cannot ask the check, and with `allow` the request is then served with the unchecked mark, where the Envoy output's check has its own 1,024 connections whatever else the proxy carries. With 1024 connections a worker, 231 and 234 of 800 requests sent at once to 2 workers were served unasked (nginx 1.30.6 and 1.31.8), where the Envoy output served none; with 8192, none were, up to 4,000 at once with nothing else open. - **a request whose client closes its connection during the check can still reach the service**: When a client closes its connection while its check is asked, with a close, a reset or a half-close, and the check then allows the request, nginx can still send the request to the service, where the Envoy output ends the request when its client goes and sends the service nothing. Of 30 clients, one after another, that each sent a request and closed 50 ms into a check that allowed it after 300 ms, the service received 16 to 21 `GET` requests and 17 to 29 `POST` requests with their bodies, 12 and 17 after a reset and 17 and 23 after a half-close, once nginx had served other requests to it and so held idle connections to it; from a just-started nginx it received none, and through the Envoy output none in any round. `proxy_ignore_client_abort` is off, nginx's default. +- **under forwarded, an x-forwarded-proto that is neither http nor https is told to the check as it arrived**: With `client_address: forwarded` and `auth.send_request: true`, a request sent over plain HTTP with `X-Forwarded-Proto: ftp`, such as `GET /products/1 HTTP/1.1`, is told `x-forwarded-proto: ftp` in the request to the check, where the Envoy output tells the check `http`, the connection's scheme. Both send the service `X-Forwarded-Proto: ftp`. nginx tells the check the header's value as it arrived, whatever it holds, so a check that builds a URL from the scheme it is told reads the word of the client, or of the proxy in front. Under `connection` both tell the check and the service the connection's scheme. - **a retried request or call is sent again at once and with no limit on retries at the same time**: A call whose first connection was refused is sent to the next backend at once, where the Envoy output waits 25 ms, and every such call is retried, where the Envoy output retries at most 3 at the same time and fails the others. A request of a retried route is retried at once and with no limit too: at 1,000 requests a second for 60 s, each first try refused, nginx served every one of the 60,000 or 60,001 requests on a second try in each of ten runs, where the Envoy output served 13,452 to 13,765 and answered the others 502, and nginx's 99th percentile was 0.49 ms on 1.30.6 and 0.45 ms on 1.31.8, where the Envoy output's was 24.4 ms (the medians of four and five runs on mains power; measured on nginx 1.30.6 and 1.31.8 beside Envoy 1.40.2). - **a chunked answer its service cuts short writes no upstream-failure line**: A service that closes its connection after the first chunk of a chunked `200` answer reaches the client as it does through the Envoy output, which then writes the request line with the flag `UPE`, whatever `log` says, and a `gateway_upstream_failure` line; nginx writes no upstream-failure line, and the request line only when `log` takes the request by its status or its share: nginx records the answer as complete, and with no content-length there is no length to compare the bytes it received to. An answer cut short before its content-length is logged as the Envoy output logs it. diff --git a/docs/portability.md b/docs/portability.md index 444b36a..7900ea2 100644 --- a/docs/portability.md +++ b/docs/portability.md @@ -90,13 +90,13 @@ proxy refuses. | Key | Envoy | nginx | HAProxy | |---|---|---|---| | `listen` | supported | supported | supported | -| `admin` | supported | partial: /stats is nginx's seven counters (active connections, accepts, handled, requests, reading, writing and waiting) and /server\_info its version, not Envoy's; any other path or a query is answered 404, where the Envoy output answers 403; TRACE is answered 405 with no body, where the Envoy output answers it as GET; an absolute target is answered as the path it names, or 400 when nginx or the public listener's checks refuse it, as one with an empty port, user information or a query right after its host, where the Envoy output answers 404 | partial: /ready answers 200 while HAProxy runs, not when the server is ready; no other admin path in this version | +| `admin` | supported | partial: /stats is nginx's seven counters (active connections, accepts, handled, requests, reading, writing and waiting) and /server\_info its version, not Envoy's; any other path or a query is answered 404, where the Envoy output answers 403; TRACE is answered 405 with no body, where the Envoy output answers it as GET; an absolute target nginx or the public listener's checks refuse, as one of a scheme other than http and https, with an empty port, user information or a query right after its host, is answered 400, where the Envoy output answers 404; less strict than the Envoy output: the admin listener serves an absolute target of http or https as the path it names | partial: /ready answers 200 while HAProxy runs, not when the server is ready; no other admin path in this version | | `tls` | supported | partial: plain HTTP sent to the TLS port is answered 400, where the Envoy output closes the connection; from the same ciphers and key exchange groups nginx can choose others for the same client | partial: of the TLS 1.2 suites both take, HAProxy picks by its own order, where Envoy takes the client's among suites it holds equal: a client that offers OpenSSL's default list is given ECDHE-RSA-AES128-GCM-SHA256, where Envoy gives ECDHE-RSA-CHACHA20-POLY1305 | | `tls.certificate` | supported | partial: a path without $; refuses holding $: nginx reads a $ in a certificate's or a key's path as the start of a variable, and a path written to keep the $ is read at each handshake, which nginx -t does not check; put the file at a path without $, or render it for envoy | supported | | `tls.key` | supported | partial: a path without $; refuses holding $: nginx reads a $ in a certificate's or a key's path as the start of a variable, and a path written to keep the $ is read at each handshake, which nginx -t does not check; put the file at a path without $, or render it for envoy | supported | | `tls.clients` | supported | supported | supported | | `tls.clients.ca` | supported | partial: a client certificate that is missing or fails is answered 400 after the handshake, where the Envoy output ends the handshake; a request whose Host names another host than its TLS server name, a host of an environment, is answered 421; neither reaches a service | partial: a client certificate that is not valid yet is refused with the alert bad\_certificate, where Envoy sends certificate\_expired | -| `client_address` | supported | partial: with forwarded, an X-Forwarded-Proto line with no colon is answered 404, where the Envoy output answers 400 | partial: under forwarded, a client's own X-Request-Id longer than 980 bytes, or than 908 bytes less an echoed Origin and cors.expose\_headers, is answered 400 before the check and the service, where the Envoy output serves it: HAProxy echoes the id in the 1,024 bytes it keeps for the lines it adds to an answer; over HTTP/2 an X-Forwarded-Proto of spaces alone is answered 404, where the Envoy output serves it | +| `client_address` | supported | partial: with forwarded, an X-Forwarded-Proto line with no colon is answered 404, where the Envoy output answers 400; less strict than the Envoy output: under connection, an absolute https target sent over plain HTTP is served | partial: under forwarded, a client's own X-Request-Id longer than 980 bytes, or than 908 bytes less an echoed Origin and cors.expose\_headers, is answered 400 before the check and the service, where the Envoy output serves it: HAProxy echoes the id in the 1,024 bytes it keeps for the lines it adds to an answer; over HTTP/2 an X-Forwarded-Proto of spaces alone is answered 404, where the Envoy output serves it | | `limits` | supported | supported | supported | | `limits.connections` | supported | partial: nginx's own limit\_conn: a request on its way to a service past the number of such requests in flight is answered 503, before its check, if any, is asked, each HTTP/2 stream counted as one and an idle connection as none; an answer the file gives itself, such as a 404 or a preflight's 200, is neither counted nor refused, and no line limits a service's connections; refuses above 65535: nginx's limit\_conn takes at most 65535; write 65535 or less, or render it for envoy | partial: HAProxy's own maxconn on the listener and on each server: a connection past it waits in the listen queue, and a request past a server's waits up to 5 s in HAProxy's queue and is then answered 503; the limit to a service counts on each of its addresses | | `limits.request_headers` | supported | supported | supported | @@ -134,7 +134,7 @@ proxy refuses. | `auth.only_with_header` | supported | partial: over HTTP/1.1 a request whose header is a lone tab is asked, where Envoy does not ask it: nginx keeps the tab, which Envoy removes; over HTTP/2 a cookie sent as two or three empty cookie fields is asked, where Envoy does not ask it; refuses naming a header that remove\_from\_clients, auth.accept or the proxy itself removes from clients: the Envoy output removes that header before it reads it and never asks the check, where nginx asks it; name a header the proxy passes on | partial: over HTTP/2 a request that carries the header with every value empty is asked, where Envoy does not ask it: HAProxy reads an HTTP/2 value of spaces alone as empty, and Envoy asks one, so HAProxy asks both | | `auth.send` | supported | partial: a client's own x-proxyfile-method and x-proxyfile-path are not sent to the check when send covers them, where Envoy sends them; what the check is asked does not change | partial: the check receives each byte of 0x80 or more that is not part of well-formed UTF-8 in a header it is sent as the client sent it, where Envoy writes a ! for each such byte | | `auth.accept` | supported | partial: names written in full, none of them a header nginx writes itself on the request it passes on; a request the accepted headers take past limits.request\_headers is answered 500 as by Envoy, counted with the client's own Connection line, its own copies of the headers the proxy sets, each line of a name sent on several lines and each cookie field over HTTP/2, which Envoy drops, replaces or joins into one before it counts, so such a request can be answered 500 by those lines sooner; an accepted header the check sends empty reaches a gRPC service as no header, where Envoy sends it empty; refuses holding a name with a \* prefix: nginx sets a request header only by a name its configuration writes; write each name in full; refuses naming a header nginx frames or routes a request by: nginx writes this header itself on the request it passes on, to frame or route it or to keep a client's copy from the service, x-forwarded-for, x-envoy-external-address and the five x-envoy- names Envoy removes from clients only with client\_address: connection, and a check service must never change how nginx frames or routes that request; each is refused with either client\_address, so a list stays valid when it changes; remove the name from auth.accept | partial: an accepted header that does not fit beside the request's own header lines in HAProxy's request buffer is answered 403, where Envoy sets it on the request (measured up to 50,000 bytes; it answered 500 at 70,000): beside a request of 118 bytes, one of 8,000 or 15,000 bytes is set by both versions and one of 15,843 bytes or more (3.4.7: 15,851) is answered 403, a bound the request's own header lines lower by as many bytes as they hold; an accepted header whose line reaches 16,383 bytes is answered 403 by auth.ask's line bound first; a \* prefix never sets transfer-encoding, host or te from the check's answer, where Envoy sets each; a folded header line of the check's answer reaches the service joined to the value before it by one space, where Envoy keeps the spaces and tabs of both lines and drops the line end; refuses naming content-length, transfer-encoding, host, te, connection or upgrade in full: HAProxy frames or routes a request by these headers, so the check's answer never sets them; remove the name from auth.accept; refuses holding a \* prefix that covers content-length, connection or upgrade: the Envoy output sends the body chunked once Content-Length is removed, and leaves a WebSocket upgrade unanswered once Connection or Upgrade is removed, which HAProxy cannot write; write the other names in full, or a longer prefix, or render it for envoy | -| `auth.send_request` | supported | partial: in a file with no pattern route, a path holding a character Envoy escapes before it picks a route (" \< > ^ \` { \| }) is told in x-forwarded-uri as the client wrote that character, where Envoy tells it escaped; the service receives it escaped from both; over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's, where Envoy tells it the :scheme | partial: over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's, where Envoy tells it the :scheme | +| `auth.send_request` | supported | partial: in a file with no pattern route, a path holding a character Envoy escapes before it picks a route (" \< > ^ \` { \| }) is told in x-forwarded-uri as the client wrote that character, where Envoy tells it escaped; the service receives it escaped from both; over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's under client\_address connection, and under forwarded the x-forwarded-proto it arrived with, or the connection's when it arrived with none, where Envoy tells it the :scheme; under client\_address connection, so is an absolute target over HTTP/1.1 whose scheme differs from its connection's: an http target sent over TLS is told https, where Envoy tells it http; under client\_address forwarded, an x-forwarded-proto that is neither http nor https, such as ftp, is told as it arrived, where Envoy tells the connection's scheme; less strict than the Envoy output: under forwarded, an x-forwarded-proto that is neither http nor https is told to the check as it arrived | partial: over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's under client\_address connection, and under forwarded the x-forwarded-proto it arrived with, or the connection's when it arrived with none, where Envoy tells it the :scheme; under client\_address forwarded, an x-forwarded-proto that is neither http nor https, such as ftp, is told as it arrived, where Envoy tells the connection's scheme; less strict than the Envoy output: under forwarded, an x-forwarded-proto that is neither http nor https is told to the check as it arrived | | `auth.jwt` | supported | refused: nginx open source cannot verify a token (nginx Plus's auth\_jwt); verify it in the service, or render it for envoy | refused: HAProxy's jwt\_verify takes one key file, with no key set, URL, issuer or audience check; verify the token in the service auth.ask names | | `auth.jwt.issuer` | supported | refused: nginx open source cannot verify a token (nginx Plus's auth\_jwt); verify it in the service, or render it for envoy | refused: HAProxy's jwt\_verify takes one key file, with no key set, URL, issuer or audience check; verify the token in the service auth.ask names | | `auth.jwt.audiences` | supported | refused: nginx open source cannot verify a token (nginx Plus's auth\_jwt); verify it in the service, or render it for envoy | refused: HAProxy's jwt\_verify takes one key file, with no key set, URL, issuer or audience check; verify the token in the service auth.ask names | @@ -220,7 +220,7 @@ proxy refuses. | `tracing.path_in_url` | supported | partial: true only; a span is written only for a request whose target nginx sends on as the client wrote it, at most 256 bytes, on a route with no rewrite and, under client\_address forwarded, with no x-envoy-original-path, and any other is sent on not sampled with no span, where Envoy writes the path it normalised, escaped or rewrote, cut to 256 characters, or a client's x-envoy-original-path | refused: the official HAProxy images have no tracing filter (the OpenTelemetry filter is an addon built from source); remove tracing, or render it for envoy | | the request's path normalised before a route is picked | supported | partial: a path that holds //, a dot segment, an escaped unreserved character or %2F and also an escape Envoy keeps, such as %3B, is answered 400, and so is one that holds such an escape beside a character Envoy escapes before it matches (" \< > ^ \` { \| } or one outside ASCII), where Envoy normalises the path and keeps the escape; an empty query, a ? with nothing after it, after a path that needs normalising or holds such a character is answered 400, where Envoy sends the ? on; a backslash, %5C and a control character, written or escaped, are answered 400, and so is an invalid escape such as %zz, which Envoy passes on; a path with an empty segment before a dot-dot segment, / and . written or escaped, such as /catalog//../products/1, is answered 400, where Envoy resolves the dot-dot segment before it merges the slashes and routes /catalog/products/1 | partial: an escape of an unreserved character in the query, such as ?q=%41 or ?q=%7e, reaches the service and the check decoded, as ?q=A and ?q=~, with or without a dot segment in the path, where Envoy passes the query as the client wrote it; an escape of a reserved character, such as %2F, %26 or %3d, reaches both as written, as through Envoy | | a dot segment with a ; parameter answered 400 | supported | partial: /a/..;/b is answered 400 where Envoy 1.40 resolves it, and nginx closes the connection after it, as after every 400 it answers for a path before a route; so is a CORS preflight through such a segment, where Envoy answers it as the preflight of the path it resolves | partial: a dot segment whose ; parameter is written with dots, such as /a/..;/b, is answered 400, and a gRPC call 200 with grpc-status 13, where Envoy 1.40 drops the parameter and resolves the segment; with the auth check, such a request is asked about whatever route its resolved path takes, and gets the check's denial or, once the check lets it through, 400, where Envoy asks only when that route is checked and, with send\_request, sends the check the resolved path; after the 400 of such a segment with the ; written %3B, which both answer, HAProxy keeps the connection open, where Envoy closes it | -| the request line and header names read before a route is picked | supported | partial: a tab between the method and the target, an absolute target with user information, with no Host header or with a query or a fragment right after its host, and OPTIONS \* are answered 400 and the connection closed, TRACE and CONNECT 405, and a request line with no version, HTTP/0.9's form, gets the text Bad Request alone, with no status line, where Envoy serves the first two and TRACE, answers OPTIONS \*, CONNECT and that absolute target 404, and that request line 426; HTTP/0.0 to HTTP/0.9 with headers are answered 400 and HTTP/2.0 to HTTP/9.9 on an HTTP/1 connection 505, where Envoy answers 426; a request nginx's own parser refuses before any rule of the file runs, such as one with a control byte in the target, a space in a header name or no Host line, is answered 400 with nginx's HTML page as text/html, where the Envoy output's 400 carries the body Bad Request as text/plain, or no body for a request with no Host line; the 426 nginx answers carries no reason phrase on its status line, HTTP/1.1 426 alone, where the Envoy output's reads 426 Upgrade Required; a header name outside RFC 9110's token characters, or a header value holding a control byte other than a tab, is answered 400 over HTTP/1.1 and HTTP/2, where Envoy answers 400 over HTTP/1.1 and closes the connection over HTTP/2; over HTTP/2 any request trailer ends the connection, where Envoy serves the request; a header line folded onto the next and a Host whose port is past 65535 or holds a sign are answered 400, where Envoy serves them; a request holding a header name with \_ that nginx reads as one of its own headers, or a second X-Forwarded-For, X-Forwarded-Proto, X-Request-Id, Content-Type, User-Agent or Referer line, is refused with 400, where Envoy reads the name as another header and joins the lines with a comma; a Connection header that names a header other than close, keep-alive, upgrade, http2-settings and te is answered 400, where Envoy removes the header it names and serves the request; a second line of authorization, if-modified-since, if-unmodified-since, if-match, if-none-match or if-range is answered 400, where Envoy joins the lines with a comma and serves the request; the lines of accept, via and accept-encoding, each a list, reach the service as separate lines, where Envoy joins them with a comma into one line, the same message written as separate lines; over HTTP/1.1 a tab before or after a header value reaches the service with the value, where Envoy removes it, the same message written another way; two Host lines are answered 400, where Envoy answers 404; over HTTP/2 a host field that differs from :authority, and an empty :authority or host field, is answered 400 with nginx's own page, where Envoy routes by :authority and closes the connection with no answer to an empty one; over HTTP/1.1 a header block still arriving after 5 minutes is ended with no answer, where Envoy answers 408 then and closes the connection a second later, and a connection that sends nothing to a listener without tls is closed after 5 minutes, where Envoy keeps it for an hour; a client that closes its side of the connection right after its request gets nginx's answer when nginx refuses the request itself, an Origin on none of the hosts, a target holding a fragment, a dot segment with a ; parameter or HTTP/1.0, where Envoy closes the connection with no answer; without limits.request\_headers nginx holds the Envoy output's 60 KiB and 100 header fields, with the differences the rows of its keys name; less strict than the Envoy output: a request trailer whose name is outside the token characters or whose value holds a control byte is served over HTTP/1.1; a header line with no colon reaches the service as a header with an empty value; a request with no body reaches the service without content-length: 0; a Referer the Envoy output removes reaches the service; a WebSocket upgrade a service answers without switching passes the service's body; a service's answer with a malformed header line or a malformed status line reaches the client; over HTTP/2, empty frames in a row are served | partial: over HTTP/1.1 an absolute target is answered 400, where Envoy routes it by its host and sends the path alone with that host as Host, or answers 404 when no environment has the host, and OPTIONS \* and CONNECT are answered 400, where Envoy answers 404; a request line with no version, HTTP/0.9's form, is answered 400, where Envoy answers 426; after its 426 to HTTP/1.0 asking for keep-alive or to HTTP/1.2 to HTTP/1.9, and after its 403 to an upgrade other than WebSocket, from any origin, HAProxy keeps the connection and serves the next request on it, where Envoy closes it; a Connection token other than close, keep-alive, upgrade, HTTP2-Settings and te is answered 400, where Envoy removes the header the token names and serves the request; ten Connection elements or more, an empty one counted but for an empty last one, are answered 400, where Envoy counts no empty element and serves a token with ten; an h2c upgrade is answered 400, where Envoy serves it as a plain request; a header line folded onto the next, and a header value that holds three spaces or tabs in a row, are answered 400, where Envoy serves them; over HTTP/2 a cookie field that starts with two spaces or tabs, as one of spaces alone does, or ends with three is answered 400 too, where Envoy serves it, as HAProxy keeps the spaces around a cookie field's value and drops them around any other field's; a WebSocket upgrade with no Sec-WebSocket-Key is answered 400, where Envoy passes it on, or answers 403 to an origin it does not admit; more than 100 header lines are answered 431 or, from 102, 400, where Envoy answers 431, and 101 lines or more of a header Envoy joins into one line are answered 400, where Envoy serves them; two Host lines of different hosts, and a Host that holds a comma, are answered 400, where Envoy answers 404; Transfer-Encoding: chunked on two lines is answered 400, and Transfer-Encoding: gzip, chunked 422, where Envoy answers 501; a request line and header lines of more than 15,277 bytes together, counted as sent with their line ends, Host alone beside the line and 4 bytes fewer for each further header line (3.4.7: 8 bytes more), are answered 431, and a request line of 16,319 bytes or more (3.4.7: 16,327) 414, where Envoy serves both up to its default limit of 60 KiB; over HTTP/2 a request with 97 header fields or more is answered 400, where Envoy resets its stream, and so is one with fewer whose cookies, counted one a field, reach 97, and one with 97 fields or more of a header Envoy joins, which Envoy serves, is answered 400 or, with 120, its stream reset; a WebSocket, an extended CONNECT, is answered 400, where Envoy closes the connection; a path whose escaped form outgrows HAProxy's buffer, such as one of 7000 bytes above 0x7F, is answered 400 by HAProxy 3.4.7 and 500 by 3.2.26, where Envoy serves it; a header or trailer name outside RFC 9110's token characters resets the stream, where Envoy closes the connection; a # in :path resets the stream, where Envoy answers 400; and a request with neither :authority nor host is answered 404, where Envoy closes the connection; over HTTP/1.1 a request trailer whose name is outside those characters ends the connection with no answer when the body comes after the headers, where Envoy answers 400; over HTTP/2 a QUERY whose content-type field is spaces alone is answered 400, where Envoy serves it: HAProxy reads an HTTP/2 value of spaces alone as empty, and Envoy answers 400 to a QUERY with no Content-Type or an empty one; less strict than the Envoy output: an HTTP/2 :authority with a default or empty port reaches the service without it; ten Connection tokens close or keep-alive are served; a request with no body reaches the service without content-length: 0; two Host lines of one host are served; two Content-Length lines of one value are served; Content-Length beside Transfer-Encoding: chunked is served; over HTTP/2, two host fields and no :authority are served; a WebSocket upgrade a service answers without switching passes the service's body; a trailer value holding a control byte is served | +| the request line and header names read before a route is picked | supported | partial: a tab between the method and the target, an absolute target with user information, with no Host header or with a query or a fragment right after its host, and OPTIONS \* are answered 400 and the connection closed, TRACE and CONNECT 405, and a request line with no version, HTTP/0.9's form, gets the text Bad Request alone, with no status line, where Envoy serves the first two and TRACE, answers OPTIONS \*, CONNECT and that absolute target 404, and that request line 426; HTTP/0.0 to HTTP/0.9 with headers are answered 400 and HTTP/2.0 to HTTP/9.9 on an HTTP/1 connection 505, where Envoy answers 426; a request nginx's own parser refuses before any rule of the file runs, such as one with a control byte in the target, a space in a header name or no Host line, is answered 400 with nginx's HTML page as text/html, where the Envoy output's 400 carries the body Bad Request as text/plain, or no body for a request with no Host line; the 426 nginx answers carries no reason phrase on its status line, HTTP/1.1 426 alone, where the Envoy output's reads 426 Upgrade Required; a header name outside RFC 9110's token characters, or a header value holding a control byte other than a tab, is answered 400 over HTTP/1.1 and HTTP/2, where Envoy answers 400 over HTTP/1.1 and closes the connection over HTTP/2; over HTTP/2 any request trailer ends the connection, where Envoy serves the request; a header line folded onto the next and a Host whose port is past 65535 or holds a sign are answered 400, where Envoy serves them; a request holding a header name with \_ that nginx reads as one of its own headers, or a second X-Forwarded-For, X-Forwarded-Proto, X-Request-Id, Content-Type, User-Agent or Referer line, is refused with 400, where Envoy reads the name as another header and joins the lines with a comma; a Connection header that names a header other than close, keep-alive, upgrade, http2-settings and te is answered 400, where Envoy removes the header it names and serves the request; a second line of authorization, if-modified-since, if-unmodified-since, if-match, if-none-match or if-range is answered 400, where Envoy joins the lines with a comma and serves the request; the lines of accept, via and accept-encoding, each a list, reach the service as separate lines, where Envoy joins them with a comma into one line, the same message written as separate lines; two Host lines are answered 400, where Envoy answers 404; over HTTP/2 a host field that differs from :authority, and an empty :authority or host field, is answered 400 with nginx's own page, where Envoy routes by :authority and closes the connection with no answer to an empty one; over HTTP/1.1 a header block still arriving after 5 minutes is ended with no answer, where Envoy answers 408 then and closes the connection a second later, and a connection that sends nothing to a listener without tls is closed after 5 minutes, where Envoy keeps it for an hour; a client that closes its side of the connection right after its request gets nginx's answer when nginx refuses the request itself, an Origin on none of the hosts, a target holding a fragment, a dot segment with a ; parameter or HTTP/1.0, where Envoy closes the connection with no answer; without limits.request\_headers nginx holds the Envoy output's 60 KiB and 100 header fields, with the differences the rows of its keys name; less strict than the Envoy output: a request trailer whose name is outside the token characters or whose value holds a control byte is served over HTTP/1.1; a header line with no colon reaches the service as a header with an empty value; a request with no body reaches the service without content-length: 0; a Referer the Envoy output removes reaches the service; over HTTP/1.1, a tab before or after a header value reaches the service; a WebSocket upgrade a service answers without switching passes the service's body; a service's answer with a malformed header line or a malformed status line reaches the client; over HTTP/2, empty frames in a row are served | partial: over HTTP/1.1 an absolute target is answered 400, where Envoy routes it by its host and sends the path alone with that host as Host, or answers 404 when no environment has the host, and OPTIONS \* and CONNECT are answered 400, where Envoy answers 404; a request line with no version, HTTP/0.9's form, is answered 400, where Envoy answers 426; after its 426 to HTTP/1.0 asking for keep-alive or to HTTP/1.2 to HTTP/1.9, and after its 403 to an upgrade other than WebSocket, from any origin, HAProxy keeps the connection and serves the next request on it, where Envoy closes it; a Connection token other than close, keep-alive, upgrade, HTTP2-Settings and te is answered 400, where Envoy removes the header the token names and serves the request; ten Connection elements or more, an empty one counted but for an empty last one, are answered 400, where Envoy counts no empty element and serves a token with ten; an h2c upgrade is answered 400, where Envoy serves it as a plain request; a header line folded onto the next, and a header value that holds three spaces or tabs in a row, are answered 400, where Envoy serves them; over HTTP/2 a cookie field that starts with two spaces or tabs, as one of spaces alone does, or ends with three is answered 400 too, where Envoy serves it, as HAProxy keeps the spaces around a cookie field's value and drops them around any other field's; a WebSocket upgrade with no Sec-WebSocket-Key is answered 400, where Envoy passes it on, or answers 403 to an origin it does not admit; more than 100 header lines are answered 431 or, from 102, 400, where Envoy answers 431, and 101 lines or more of a header Envoy joins into one line are answered 400, where Envoy serves them; two Host lines of different hosts, and a Host that holds a comma, are answered 400, where Envoy answers 404; Transfer-Encoding: chunked on two lines is answered 400, and Transfer-Encoding: gzip, chunked 422, where Envoy answers 501; a request line and header lines of more than 15,277 bytes together, counted as sent with their line ends, Host alone beside the line and 4 bytes fewer for each further header line (3.4.7: 8 bytes more), are answered 431, and a request line of 16,319 bytes or more (3.4.7: 16,327) 414, where Envoy serves both up to its default limit of 60 KiB; over HTTP/2 a request with 97 header fields or more is answered 400, where Envoy resets its stream, and so is one with fewer whose cookies, counted one a field, reach 97, and one with 97 fields or more of a header Envoy joins, which Envoy serves, is answered 400 or, with 120, its stream reset; a WebSocket, an extended CONNECT, is answered 400, where Envoy closes the connection; a path whose escaped form outgrows HAProxy's buffer, such as one of 7000 bytes above 0x7F, is answered 400 by HAProxy 3.4.7 and 500 by 3.2.26, where Envoy serves it; a header or trailer name outside RFC 9110's token characters resets the stream, where Envoy closes the connection; a # in :path resets the stream, where Envoy answers 400; and a request with neither :authority nor host is answered 404, where Envoy closes the connection; over HTTP/1.1 a request trailer whose name is outside those characters ends the connection with no answer when the body comes after the headers, where Envoy answers 400; over HTTP/2 a QUERY whose content-type field is spaces alone is answered 400, where Envoy serves it: HAProxy reads an HTTP/2 value of spaces alone as empty, and Envoy answers 400 to a QUERY with no Content-Type or an empty one; less strict than the Envoy output: an HTTP/2 :authority with a default or empty port reaches the service without it; ten Connection tokens close or keep-alive are served; a request with no body reaches the service without content-length: 0; two Host lines of one host are served; two Content-Length lines of one value are served; Content-Length beside Transfer-Encoding: chunked is served; over HTTP/2, two host fields and no :authority are served; a WebSocket upgrade a service answers without switching passes the service's body; a trailer value holding a control byte is served | ## Written with no key diff --git a/examples/balanced/hocon/proxyfile.js b/examples/balanced/hocon/proxyfile.js index b784571..d88f91a 100644 --- a/examples/balanced/hocon/proxyfile.js +++ b/examples/balanced/hocon/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/examples/balanced/yaml/proxyfile.js b/examples/balanced/yaml/proxyfile.js index b784571..d88f91a 100644 --- a/examples/balanced/yaml/proxyfile.js +++ b/examples/balanced/yaml/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/examples/dns/hocon/proxyfile.js b/examples/dns/hocon/proxyfile.js index b784571..d88f91a 100644 --- a/examples/dns/hocon/proxyfile.js +++ b/examples/dns/hocon/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/examples/dns/yaml/proxyfile.js b/examples/dns/yaml/proxyfile.js index b784571..d88f91a 100644 --- a/examples/dns/yaml/proxyfile.js +++ b/examples/dns/yaml/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/examples/grpc/hocon/proxyfile.js b/examples/grpc/hocon/proxyfile.js index b784571..d88f91a 100644 --- a/examples/grpc/hocon/proxyfile.js +++ b/examples/grpc/hocon/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/examples/grpc/yaml/proxyfile.js b/examples/grpc/yaml/proxyfile.js index b784571..d88f91a 100644 --- a/examples/grpc/yaml/proxyfile.js +++ b/examples/grpc/yaml/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/examples/limited/hocon/proxyfile.js b/examples/limited/hocon/proxyfile.js index b784571..d88f91a 100644 --- a/examples/limited/hocon/proxyfile.js +++ b/examples/limited/hocon/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/examples/limited/yaml/proxyfile.js b/examples/limited/yaml/proxyfile.js index b784571..d88f91a 100644 --- a/examples/limited/yaml/proxyfile.js +++ b/examples/limited/yaml/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/examples/minimal/hocon/proxyfile.js b/examples/minimal/hocon/proxyfile.js index b784571..d88f91a 100644 --- a/examples/minimal/hocon/proxyfile.js +++ b/examples/minimal/hocon/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/examples/minimal/yaml/proxyfile.js b/examples/minimal/yaml/proxyfile.js index b784571..d88f91a 100644 --- a/examples/minimal/yaml/proxyfile.js +++ b/examples/minimal/yaml/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/examples/portable/hocon/nginx.conf b/examples/portable/hocon/nginx.conf index 19ecdfd..3e65d74 100644 --- a/examples/portable/hocon/nginx.conf +++ b/examples/portable/hocon/nginx.conf @@ -171,7 +171,7 @@ http { map "" $pf_counted_address { default $remote_addr; } map $request_uri $pf_query { "~^[^?]*(?\\?.*)" $pf_query_text; default ""; } map $pf_mode $pf_told_uri { uri $pf_path$pf_query; default $request_uri; } - map $request $pf_told_proto { "~*^[^ ]+ +https://" https; "~*^[^ ]+ +http://" http; default $pf_forwarded_proto; } + map "" $pf_told_proto { default $pf_forwarded_proto; } limit_req_status 429; js_set $pf_429_kind pf.limitedKind; limit_req_zone "all" zone=pf_rl_1_all:16m rate=100r/s; diff --git a/examples/portable/hocon/proxyfile.js b/examples/portable/hocon/proxyfile.js index b784571..d88f91a 100644 --- a/examples/portable/hocon/proxyfile.js +++ b/examples/portable/hocon/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/examples/portable/yaml/nginx.conf b/examples/portable/yaml/nginx.conf index 19ecdfd..3e65d74 100644 --- a/examples/portable/yaml/nginx.conf +++ b/examples/portable/yaml/nginx.conf @@ -171,7 +171,7 @@ http { map "" $pf_counted_address { default $remote_addr; } map $request_uri $pf_query { "~^[^?]*(?\\?.*)" $pf_query_text; default ""; } map $pf_mode $pf_told_uri { uri $pf_path$pf_query; default $request_uri; } - map $request $pf_told_proto { "~*^[^ ]+ +https://" https; "~*^[^ ]+ +http://" http; default $pf_forwarded_proto; } + map "" $pf_told_proto { default $pf_forwarded_proto; } limit_req_status 429; js_set $pf_429_kind pf.limitedKind; limit_req_zone "all" zone=pf_rl_1_all:16m rate=100r/s; diff --git a/examples/portable/yaml/proxyfile.js b/examples/portable/yaml/proxyfile.js index b784571..d88f91a 100644 --- a/examples/portable/yaml/proxyfile.js +++ b/examples/portable/yaml/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/examples/tls/hocon/proxyfile.js b/examples/tls/hocon/proxyfile.js index b784571..d88f91a 100644 --- a/examples/tls/hocon/proxyfile.js +++ b/examples/tls/hocon/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/examples/tls/yaml/proxyfile.js b/examples/tls/yaml/proxyfile.js index b784571..d88f91a 100644 --- a/examples/tls/yaml/proxyfile.js +++ b/examples/tls/yaml/proxyfile.js @@ -1655,11 +1655,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1683,8 +1685,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go index e35af4d..16d7c5b 100644 --- a/internal/cli/cli_test.go +++ b/internal/cli/cli_test.go @@ -60,11 +60,11 @@ func TestRun(t *testing.T) { // print nothing. {name: "render for haproxy counts the ways it is less strict", setup: copyMinimal, args: "render /yaml/proxyfile.yaml -o /haproxy.cfg --target haproxy", - stderr: "proxyfile render: this HAProxy configuration is less strict than the Envoy output in 10 ways; " + + stderr: "proxyfile render: this HAProxy configuration is less strict than the Envoy output in 11 ways; " + "docs/haproxy.md lists them under \"Where HAProxy is less strict than the Envoy output\"\n"}, {name: "render for nginx counts the ways it is less strict", setup: func(t *testing.T, tmp string) { copyExample(t, tmp, "grpc") }, args: "render /yaml/proxyfile.yaml -o /nginx.conf --target nginx", - stderr: "proxyfile render: this nginx configuration is less strict than the Envoy output in 15 ways; " + + stderr: "proxyfile render: this nginx configuration is less strict than the Envoy output in 19 ways; " + "docs/nginx.md lists them under \"Where nginx is less strict than the Envoy output\"\n"}, {name: "render for envoy counts nothing", setup: copyMinimal, args: "render /yaml/proxyfile.yaml -o /envoy.yaml"}, {name: "check for haproxy counts nothing", args: "check /minimal/yaml/proxyfile.yaml -o /minimal/yaml/haproxy.cfg --target haproxy"}, diff --git a/internal/format/support_haproxy.go b/internal/format/support_haproxy.go index 59fe338..a211273 100644 --- a/internal/format/support_haproxy.go +++ b/internal/format/support_haproxy.go @@ -275,9 +275,12 @@ var haproxyTarget = Target{Name: "haproxy", Title: "HAProxy", Keys: map[string]S Applies: func(value, _ *tree.Node) bool { whole, _ := coveredBy(value, HAProxyFramedBy); return whole }}, haproxyRemovalPrefix}}, // The check is told the scheme of the client's connection (measured on HAProxy 3.2.26 and 3.4.7 beside Envoy - // 1.40.2, :scheme http over TLS and https without). + // 1.40.2, :scheme http over TLS and https without). Under forwarded the script tells it the X-Forwarded-Proto the + // request arrived with, which the file keeps as Envoy keeps it for the service: X-Forwarded-Proto: ftp is told ftp, + // where the Envoy output tells the connection's scheme (the battery's row "an x-forwarded-proto that is neither http + // nor https", on two-checks). "auth.send_request": {Level: Partial, - Note: "over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's, where Envoy tells it the :scheme"}, + Note: "over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's under client_address connection, and under forwarded the x-forwarded-proto it arrived with, or the connection's when it arrived with none, where Envoy tells it the :scheme; under client_address forwarded, an x-forwarded-proto that is neither http nor https, such as ftp, is told as it arrived, where Envoy tells the connection's scheme"}, "auth.jwt": haproxyNoJWT, "auth.jwt.issuer": haproxyNoJWT, "auth.jwt.audiences": haproxyNoJWT, @@ -418,10 +421,12 @@ var haproxyTarget = Target{Name: "haproxy", Title: "HAProxy", Keys: map[string]S }, LessStrict: haproxyLessStrict} // haproxyLessStrict are the ways the HAProxy output is less strict than the Envoy output. HAProxy's parsers decide -// each before any rule of the file reads the request, and its timeout counts the time without data, so the file can -// close none of them: the file refuses a control byte in a header value with a rule, but no fetch reads a request -// trailer, which option http-drop-request-trailers removes before the service. Each was measured on HAProxy 3.2.26 and -// 3.4.7 beside Envoy 1.40.2, the two images alike. +// each but the last before any rule of the file reads the request, and its timeout counts the time without data, so +// the file can close none of them: the file refuses a control byte in a header value with a rule, but no fetch reads a +// request trailer, which option http-drop-request-trailers removes before the service. The last is the file's own: it +// keeps the X-Forwarded-Proto a request arrived with under forwarded, as the Envoy output keeps it for the service, and +// tells the check that header. Each was measured on HAProxy 3.2.26 and 3.4.7 beside Envoy 1.40.2, the two images +// alike. var haproxyLessStrict = []LessStrict{ {Row: requestLine, Name: "an HTTP/2 :authority with a default or empty port reaches the service without it", Measured: "Over HTTP/2, `:authority: api.example.com:` and, over plain HTTP, `api.example.com:80` reach the service as `Host: api.example.com`, where the Envoy output sends them as written."}, @@ -443,4 +448,7 @@ var haproxyLessStrict = []LessStrict{ Measured: "A request trailer value holding one of the bytes 0x01 to 0x08, 0x0B, 0x0C, 0x0E to 0x1F or 0x7F is served, the service receiving the body and no trailer, where Envoy answers `400` over HTTP/1.1 and closes the connection over HTTP/2. A header value holding one is answered `400` over HTTP/1.1, as by Envoy, and its stream is reset over HTTP/2, where Envoy closes the connection; HAProxy refuses 0x00, a line feed and a carriage return in either value, with `400` over HTTP/1.1 and a reset stream over HTTP/2."}, {Row: "timeouts.request", Name: "without timeouts.request, an answer that keeps arriving runs past 15 s", Measured: "Without `timeouts.request`, a service that keeps sending runs past 15 s, where the Envoy output ends a request 15 s after it starts: HAProxy's `timeout server` counts the time without data (on HAProxy 3.4.7, a service that sent one byte a second for 10 s under a 2 s `timeout server` was served)."}, + // The battery's row "an x-forwarded-proto that is neither http nor https" holds it on two-checks. + {Row: "auth.send_request", Name: "under forwarded, an x-forwarded-proto that is neither http nor https is told to the check as it arrived", + Measured: "With `client_address: forwarded` and `auth.send_request: true`, a request sent over plain HTTP with `X-Forwarded-Proto: ftp`, such as `GET /products/1 HTTP/1.1`, is told `x-forwarded-proto: ftp` in the request to the check, where the Envoy output tells the check `http`, the connection's scheme. Both send the service `X-Forwarded-Proto: ftp`. Under `connection`, over TLS, both tell the check and the service `https`, the connection's scheme."}, } diff --git a/internal/format/support_nginx.go b/internal/format/support_nginx.go index 7fd46d7..28b991e 100644 --- a/internal/format/support_nginx.go +++ b/internal/format/support_nginx.go @@ -326,7 +326,7 @@ var nginxTarget = Target{Name: "nginx", Title: "nginx", Keys: map[string]Support // Measured on nginx 1.30.6 and 1.31.8 beside Envoy 1.40.2: /ready answered as Envoy answers it, a query and every // other path 404 where Envoy answers 403, each method on each path as Envoy answers it but TRACE, and no log line // for an admin request from either. - "admin": {Level: Partial, Note: "/stats is nginx's seven counters (active connections, accepts, handled, requests, reading, writing and waiting) and /server_info its version, not Envoy's; any other path or a query is answered 404, where the Envoy output answers 403; TRACE is answered 405 with no body, where the Envoy output answers it as GET; an absolute target is answered as the path it names, or 400 when nginx or the public listener's checks refuse it, as one with an empty port, user information or a query right after its host, where the Envoy output answers 404"}, + "admin": {Level: Partial, Note: "/stats is nginx's seven counters (active connections, accepts, handled, requests, reading, writing and waiting) and /server_info its version, not Envoy's; any other path or a query is answered 404, where the Envoy output answers 403; TRACE is answered 405 with no body, where the Envoy output answers it as GET; an absolute target nginx or the public listener's checks refuse, as one of a scheme other than http and https, with an empty port, user information or a query right after its host, is answered 400, where the Envoy output answers 404"}, // nginx answers what fails at the TLS level after the handshake, where Envoy ends the connection or the handshake. // From the same TLS 1.2 ciphers and key exchange groups it chose others than Envoy for one offer: for openssl @@ -489,9 +489,16 @@ var nginxTarget = Target{Name: "nginx", Title: "nginx", Keys: map[string]Support // with no pattern route a path holding such a character is matched on $uri, which holds it decoded, and nginx // escapes it again only as it sends it to the service. nginx's $scheme is the connection's, and no variable holds // an HTTP/2 request's :scheme, so no line can tell the check one that differs (measured on nginx 1.30.6 and 1.31.8 - // beside Envoy 1.40.2, :scheme http over TLS and https without). + // beside Envoy 1.40.2, :scheme http over TLS and https without). Under client_address connection the file tells the + // check the connection's scheme over HTTP/1.1 too, whatever scheme an absolute target names, as a client writes the + // target: GET http://localhost/products/1 over TLS is told https, where the Envoy output tells http (the battery's + // row "an absolute target's host is the host the check is told", on nginx-auth and portable). Under forwarded the + // file tells the check the client's X-Forwarded-Proto as it arrived, the word a proxy in front writes, which the + // generator does not bound: X-Forwarded-Proto: ftp is told ftp, where the Envoy output tells the connection's + // scheme, and both send the service ftp (the battery's row "an x-forwarded-proto that is neither http nor https", + // on nginx-checks and nginx-tracing; the list of ways nginx is less strict names it). "auth.send_request": {Level: Partial, - Note: "in a file with no pattern route, a path holding a character Envoy escapes before it picks a route (\" < > ^ ` { | }) is told in x-forwarded-uri as the client wrote that character, where Envoy tells it escaped; the service receives it escaped from both; over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's, where Envoy tells it the :scheme"}, + Note: "in a file with no pattern route, a path holding a character Envoy escapes before it picks a route (\" < > ^ ` { | }) is told in x-forwarded-uri as the client wrote that character, where Envoy tells it escaped; the service receives it escaped from both; over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's under client_address connection, and under forwarded the x-forwarded-proto it arrived with, or the connection's when it arrived with none, where Envoy tells it the :scheme; under client_address connection, so is an absolute target over HTTP/1.1 whose scheme differs from its connection's: an http target sent over TLS is told https, where Envoy tells it http; under client_address forwarded, an x-forwarded-proto that is neither http nor https, such as ftp, is told as it arrived, where Envoy tells the connection's scheme"}, "auth.jwt": nginxNoJWT, "auth.jwt.issuer": nginxNoJWT, "auth.jwt.audiences": nginxNoJWT, @@ -705,7 +712,7 @@ var nginxTarget = Target{Name: "nginx", Title: "nginx", Keys: map[string]Support // after its request, measured with no auth on nginx 1.30.6 and 1.31.8 beside Envoy 1.40.2: no service received the // request through either, and a Host no environment names was answered 404 by both. "the request line and header names read before a route is picked": {Level: Partial, - Note: "a tab between the method and the target, an absolute target with user information, with no Host header or with a query or a fragment right after its host, and OPTIONS * are answered 400 and the connection closed, TRACE and CONNECT 405, and a request line with no version, HTTP/0.9's form, gets the text Bad Request alone, with no status line, where Envoy serves the first two and TRACE, answers OPTIONS *, CONNECT and that absolute target 404, and that request line 426; HTTP/0.0 to HTTP/0.9 with headers are answered 400 and HTTP/2.0 to HTTP/9.9 on an HTTP/1 connection 505, where Envoy answers 426; a request nginx's own parser refuses before any rule of the file runs, such as one with a control byte in the target, a space in a header name or no Host line, is answered 400 with nginx's HTML page as text/html, where the Envoy output's 400 carries the body Bad Request as text/plain, or no body for a request with no Host line; the 426 nginx answers carries no reason phrase on its status line, HTTP/1.1 426 alone, where the Envoy output's reads 426 Upgrade Required; a header name outside RFC 9110's token characters, or a header value holding a control byte other than a tab, is answered 400 over HTTP/1.1 and HTTP/2, where Envoy answers 400 over HTTP/1.1 and closes the connection over HTTP/2; over HTTP/2 any request trailer ends the connection, where Envoy serves the request; a header line folded onto the next and a Host whose port is past 65535 or holds a sign are answered 400, where Envoy serves them; a request holding a header name with _ that nginx reads as one of its own headers, or a second X-Forwarded-For, X-Forwarded-Proto, X-Request-Id, Content-Type, User-Agent or Referer line, is refused with 400, where Envoy reads the name as another header and joins the lines with a comma; a Connection header that names a header other than close, keep-alive, upgrade, http2-settings and te is answered 400, where Envoy removes the header it names and serves the request; a second line of authorization, if-modified-since, if-unmodified-since, if-match, if-none-match or if-range is answered 400, where Envoy joins the lines with a comma and serves the request; the lines of accept, via and accept-encoding, each a list, reach the service as separate lines, where Envoy joins them with a comma into one line, the same message written as separate lines; over HTTP/1.1 a tab before or after a header value reaches the service with the value, where Envoy removes it, the same message written another way; two Host lines are answered 400, where Envoy answers 404; over HTTP/2 a host field that differs from :authority, and an empty :authority or host field, is answered 400 with nginx's own page, where Envoy routes by :authority and closes the connection with no answer to an empty one; over HTTP/1.1 a header block still arriving after 5 minutes is ended with no answer, where Envoy answers 408 then and closes the connection a second later, and a connection that sends nothing to a listener without tls is closed after 5 minutes, where Envoy keeps it for an hour; a client that closes its side of the connection right after its request gets nginx's answer when nginx refuses the request itself, an Origin on none of the hosts, a target holding a fragment, a dot segment with a ; parameter or HTTP/1.0, where Envoy closes the connection with no answer; without limits.request_headers nginx holds the Envoy output's 60 KiB and 100 header fields, with the differences the rows of its keys name"}, + Note: "a tab between the method and the target, an absolute target with user information, with no Host header or with a query or a fragment right after its host, and OPTIONS * are answered 400 and the connection closed, TRACE and CONNECT 405, and a request line with no version, HTTP/0.9's form, gets the text Bad Request alone, with no status line, where Envoy serves the first two and TRACE, answers OPTIONS *, CONNECT and that absolute target 404, and that request line 426; HTTP/0.0 to HTTP/0.9 with headers are answered 400 and HTTP/2.0 to HTTP/9.9 on an HTTP/1 connection 505, where Envoy answers 426; a request nginx's own parser refuses before any rule of the file runs, such as one with a control byte in the target, a space in a header name or no Host line, is answered 400 with nginx's HTML page as text/html, where the Envoy output's 400 carries the body Bad Request as text/plain, or no body for a request with no Host line; the 426 nginx answers carries no reason phrase on its status line, HTTP/1.1 426 alone, where the Envoy output's reads 426 Upgrade Required; a header name outside RFC 9110's token characters, or a header value holding a control byte other than a tab, is answered 400 over HTTP/1.1 and HTTP/2, where Envoy answers 400 over HTTP/1.1 and closes the connection over HTTP/2; over HTTP/2 any request trailer ends the connection, where Envoy serves the request; a header line folded onto the next and a Host whose port is past 65535 or holds a sign are answered 400, where Envoy serves them; a request holding a header name with _ that nginx reads as one of its own headers, or a second X-Forwarded-For, X-Forwarded-Proto, X-Request-Id, Content-Type, User-Agent or Referer line, is refused with 400, where Envoy reads the name as another header and joins the lines with a comma; a Connection header that names a header other than close, keep-alive, upgrade, http2-settings and te is answered 400, where Envoy removes the header it names and serves the request; a second line of authorization, if-modified-since, if-unmodified-since, if-match, if-none-match or if-range is answered 400, where Envoy joins the lines with a comma and serves the request; the lines of accept, via and accept-encoding, each a list, reach the service as separate lines, where Envoy joins them with a comma into one line, the same message written as separate lines; two Host lines are answered 400, where Envoy answers 404; over HTTP/2 a host field that differs from :authority, and an empty :authority or host field, is answered 400 with nginx's own page, where Envoy routes by :authority and closes the connection with no answer to an empty one; over HTTP/1.1 a header block still arriving after 5 minutes is ended with no answer, where Envoy answers 408 then and closes the connection a second later, and a connection that sends nothing to a listener without tls is closed after 5 minutes, where Envoy keeps it for an hour; a client that closes its side of the connection right after its request gets nginx's answer when nginx refuses the request itself, an Origin on none of the hosts, a target holding a fragment, a dot segment with a ; parameter or HTTP/1.0, where Envoy closes the connection with no answer; without limits.request_headers nginx holds the Envoy output's 60 KiB and 100 header fields, with the differences the rows of its keys name"}, }, LessStrict: nginxLessStrict} // The rows of a rate limit, the same for an entry of routes and for its rpc. Each limited entry has a zone of shared @@ -742,6 +749,11 @@ var nginxLessStrict = []LessStrict{ // parser Envoy links was not at hand, and the published grammar does not give Envoy's answers, so no rule is written. {Row: requestLine, Name: "a Referer the Envoy output removes reaches the service", Measured: "Of 104 forms of one Referer line, Envoy removed 46 before the service, such as `a:b`, `/a#f`, `a b`, `/é`, `{`, `http://u@a/`, `http://a/#f`, `http://a:65536/`, `http://a_b/`, `http://[1:2:3]/` and `about:blank`, and nginx passed every one on. The Envoy output removes a Referer that its URL parser reads as a URL with a fragment or user information, or that the parser does not read and that holds a byte outside RFC 3986's query and fragment characters or a colon before its first slash. A rule written from the published grammar of that parser, nodejs's http_parser, answered forms of the 104 otherwise than Envoy: in its strict build it removed `h2://a/` and `x-y://a/`, whose scheme Envoy reads with a digit or a `-` in it, and in its lenient build it also kept `http://a_b/` and `http://a/é`. nginx answers two Referer lines `400`, as the request line's row says."}, + // nginx stores a header value without the spaces around it but with a tab there, and each route's location passes a + // client's header as nginx stores it. RFC 9110 does not count the white space around a field value as part of the + // value, but a service that reads the bytes reads the tab, so the way is named here rather than in the row's note. + {Row: requestLine, Name: "over HTTP/1.1, a tab before or after a header value reaches the service", + Measured: "A header value sent over HTTP/1.1 with a tab right after its colon or at its end reaches the service with the tab, where Envoy removes it: the service receives `User-Agent` as a tab and `probe/3`, or as `probe/4` and a tab, and `X-A` as a tab and `b5`, where through Envoy it receives `user-agent: probe/3`, `user-agent: probe/4` and `x-a: b5`, under `client_address: forwarded` and under `connection`. Under `forwarded` a client's `X-Request-Id` sent as a tab and `abc-1`, or as `abc-2` and a tab, reaches the service with the tab too, and nginx's answer gives it back to the client with the tab, where Envoy sends `abc-1` and `abc-2` to both; under `connection` each proxy sends an id of its own in its place. A service that reads the value as RFC 9110 says, without the white space around it, reads the same value through both."}, {Row: requestLine, Name: "a WebSocket upgrade a service answers without switching passes the service's body", Measured: "A WebSocket upgrade a service answers `200` without switching reaches the client with the service's body, where Envoy passes the status and headers with no body."}, // A script filter on every answer (js_header_filter with js_body_filter) turned the second and third into 502 with @@ -758,6 +770,15 @@ var nginxLessStrict = []LessStrict{ Measured: "A service's answer holding a header line with no colon reaches the client with it as a header with an empty value (`nocolon: `), and one whose header name holds `@` (`x@bad: 1`) or whose header value holds the byte 0x01 reaches the client with that header as the service wrote it, where Envoy answers `502` and writes an upstream-failure line with the flag `UPE`, which nginx does not write. A malformed status line reaches the client too. A status of three digits that starts with 0, `050`, `000` or `099`, reaches it as that status over HTTP/1.1 and HTTP/2, with the headers nginx writes. A status with spaces between its digits, `HTTP/1.1 2 0 0 X`, reaches an HTTP/2 client as `200` and an HTTP/1.1 client with the status line `HTTP/1.1 0 0 X`, and one with a fraction, `HTTP/1.1 403.1 X`, reaches an HTTP/2 client as `403` and an HTTP/1.1 client as the service wrote it: nginx reads three digits with spaces among them, and takes a `.` after them. A status of one or two digits, such as `5`, `20` or `99`, one of four digits, `HTTP/1.1 2000 OK`, and an answer with no status line at all, such as `hello` and a line end, reach an HTTP/1.1 client byte for byte as the service wrote them, with none of the headers nginx writes, such as `x-request-id` and `Vary`, and an HTTP/2 client as the body of an answer with the status `000`: nginx reads such an answer as one with no head and passes it whole. Envoy answers each of these `502` and writes an upstream-failure line with the flag `UPE`, but the status of four digits, which it passes as `2000` with its own headers; nginx writes no upstream-failure line for any of them, and has no setting that refuses them. nginx stores a line with no colon as it stores `nocolon:`, which Envoy passes too, so `proxyfile.js` cannot tell the two apart."}, {Row: requestLine, Name: "over HTTP/2, empty frames in a row are served", Measured: "An HTTP/2 request whose HEADERS frame is followed by two empty CONTINUATION frames, or whose body comes after two empty DATA frames, is served, where Envoy takes one frame with no payload in a row and closes the connection at the second: nginx sets no such limit, and neither `nginx.conf` nor `proxyfile.js` sees a frame."}, + // nginx matches a location by the path of an absolute target, and the admin server refuses one only when nginx or + // the public listener's checks do; Envoy's admin listener answers every absolute target 404. + {Row: "admin", Name: "the admin listener serves an absolute target of http or https as the path it names", + Measured: "`GET http://localhost/ready HTTP/1.1` sent to the admin listener is answered `200` with `LIVE`, and so is the same target with `https://` or `HTTP://`, and `http://localhost/stats` and `http://localhost/server_info` are answered `200` with nginx's counters and its version, where the Envoy output's admin listener answers `404` with no body to every absolute target. A path the admin listener does not answer, `http://localhost/nothing`, is answered `404` by both, and a target of another scheme, `ftp://localhost/ready` or `ws://localhost/ready`, `400` with the body `Bad Request` and the connection closed, where the Envoy output answers `404`."}, + // Measured with the Envoy output of client_address: connection, which writes use_remote_address: true, and of + // forwarded, which writes false; the request checks of the nginx output take an absolute http and https target alike. + // The battery's row "an absolute https target", of the scheme the check is told, holds it on nginx-connection. + {Row: "client_address", Name: "under connection, an absolute https target sent over plain HTTP is served", + Measured: "With `client_address: connection` and no `tls`, an absolute `https` target sent over plain HTTP, such as `GET https://localhost/products/1 HTTP/1.1`, or the same with `HTTPS://`, is served: the service receives `X-Forwarded-Proto: http`, and with `auth.send_request: true` the check is told `x-forwarded-proto: http`, the connection's scheme, where the Envoy output answers `403` with the body `Forbidden`, writes `http1.https_url_on_plaintext_connection` in its request log, closes the connection and asks no check. Under `forwarded` both serve it, and the service receives `x-forwarded-proto: http` through both."}, {Row: "timeouts.request", Name: "without timeouts.request, an answer that keeps arriving runs past 15 s", Measured: "Without `timeouts.request`, an answer that keeps coming runs past the 15 s at which the Envoy output ends a request: nginx counts its limits between two reads or writes."}, // proxy_send_timeout counts from the last write nginx could make, so it ends a try whose service reads too slowly @@ -781,6 +802,11 @@ var nginxLessStrict = []LessStrict{ // is left that makes nginx drop the request. {Row: "auth.ask", Name: "a request whose client closes its connection during the check can still reach the service", Measured: "When a client closes its connection while its check is asked, with a close, a reset or a half-close, and the check then allows the request, nginx can still send the request to the service, where the Envoy output ends the request when its client goes and sends the service nothing. Of 30 clients, one after another, that each sent a request and closed 50 ms into a check that allowed it after 300 ms, the service received 16 to 21 `GET` requests and 17 to 29 `POST` requests with their bodies, 12 and 17 after a reset and 17 and 23 after a half-close, once nginx had served other requests to it and so held idle connections to it; from a just-started nginx it received none, and through the Envoy output none in any round. `proxy_ignore_client_abort` is off, nginx's default."}, + // The generator keeps nginx's own reading of the header, as it keeps nginx's own answers elsewhere: under forwarded + // the header is the word of whoever is in front. The battery's row "an x-forwarded-proto that is neither http nor + // https" holds it. + {Row: "auth.send_request", Name: "under forwarded, an x-forwarded-proto that is neither http nor https is told to the check as it arrived", + Measured: "With `client_address: forwarded` and `auth.send_request: true`, a request sent over plain HTTP with `X-Forwarded-Proto: ftp`, such as `GET /products/1 HTTP/1.1`, is told `x-forwarded-proto: ftp` in the request to the check, where the Envoy output tells the check `http`, the connection's scheme. Both send the service `X-Forwarded-Proto: ftp`. nginx tells the check the header's value as it arrived, whatever it holds, so a check that builds a URL from the scheme it is told reads the word of the client, or of the proxy in front. Under `connection` both tell the check and the service the connection's scheme."}, // grpc_next_upstream tries the next backend as soon as a connection fails, and a retried route's error_page goes to // the next backend's copy as soon as a try fails: no directive of nginx's gRPC module or of error_page sets a wait // before a retry or a limit on the retries in flight (nginx.org, ngx_http_grpc_module and ngx_http_core_module). diff --git a/internal/format/support_test.go b/internal/format/support_test.go index 8afce7e..d0d373c 100644 --- a/internal/format/support_test.go +++ b/internal/format/support_test.go @@ -684,8 +684,8 @@ func TestHeaderNamesNeedNoEscaping(t *testing.T) { func TestLessStrictWarning(t *testing.T) { for _, c := range []struct{ target, want string }{ {"envoy", ""}, - {"nginx", `this nginx configuration is less strict than the Envoy output in 15 ways; docs/nginx.md lists them under "Where nginx is less strict than the Envoy output"`}, - {"haproxy", `this HAProxy configuration is less strict than the Envoy output in 10 ways; docs/haproxy.md lists them under "Where HAProxy is less strict than the Envoy output"`}, + {"nginx", `this nginx configuration is less strict than the Envoy output in 19 ways; docs/nginx.md lists them under "Where nginx is less strict than the Envoy output"`}, + {"haproxy", `this HAProxy configuration is less strict than the Envoy output in 11 ways; docs/haproxy.md lists them under "Where HAProxy is less strict than the Envoy output"`}, } { target, _ := TargetNamed(c.target) if got := LessStrictWarning(target); got != c.want { @@ -723,6 +723,7 @@ func TestLessStrictWays(t *testing.T) { {line, "a WebSocket upgrade a service answers without switching passes the service's body"}, {line, "a trailer value holding a control byte is served"}, {"timeouts.request", "without timeouts.request, an answer that keeps arriving runs past 15 s"}, + {"auth.send_request", "under forwarded, an x-forwarded-proto that is neither http nor https is told to the check as it arrived"}, }}, {"nginx", []way{ {line, "a request trailer whose name is outside the token characters or whose value holds a control byte is served over HTTP/1.1"}, @@ -730,14 +731,18 @@ func TestLessStrictWays(t *testing.T) { {line, "a header line with no colon reaches the service as a header with an empty value"}, {line, "a request with no body reaches the service without content-length: 0"}, {line, "a Referer the Envoy output removes reaches the service"}, + {line, "over HTTP/1.1, a tab before or after a header value reaches the service"}, {line, "a WebSocket upgrade a service answers without switching passes the service's body"}, {line, "a service's answer with a malformed header line or a malformed status line reaches the client"}, {line, "over HTTP/2, empty frames in a row are served"}, + {"admin", "the admin listener serves an absolute target of http or https as the path it names"}, + {"client_address", "under connection, an absolute https target sent over plain HTTP is served"}, {"timeouts.request", "without timeouts.request, an answer that keeps arriving runs past 15 s"}, {"timeouts.request", "without timeouts.request, a request body its service does not read, or reads slowly, runs past 15 s"}, {"auth.when_unavailable", "with allow, a check service that does not close its connection right after its answer leaves requests unchecked past about 470 checks a second"}, {"auth.when_unavailable", "with allow, a worker with none of its 8192 connections left serves requests unchecked"}, {"auth.ask", "a request whose client closes its connection during the check can still reach the service"}, + {"auth.send_request", "under forwarded, an x-forwarded-proto that is neither http nor https is told to the check as it arrived"}, {"routes[].rpc.retries", "a retried request or call is sent again at once and with no limit on retries at the same time"}, {"log", "a chunked answer its service cuts short writes no upstream-failure line"}, }}, @@ -852,7 +857,7 @@ func TestHAProxyWrites(t *testing.T) { refuses: "naming content-length, transfer-encoding, host, te, connection or upgrade in full: HAProxy frames or routes a request by these headers, so the check's answer never sets them; remove the name from auth.accept" + "; " + "holding a * prefix that covers content-length, connection or upgrade: the Envoy output sends the body chunked once Content-Length is removed, and leaves a WebSocket upgrade unanswered once Connection or Upgrade is removed, which HAProxy cannot write; write the other names in full, or a longer prefix, or render it for envoy"}, {key: "auth.send_request", level: Partial, - note: "over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's, where Envoy tells it the :scheme"}, + note: "over HTTP/2 a request whose :scheme differs from its connection's scheme is told in x-forwarded-proto the connection's under client_address connection, and under forwarded the x-forwarded-proto it arrived with, or the connection's when it arrived with none, where Envoy tells it the :scheme; under client_address forwarded, an x-forwarded-proto that is neither http nor https, such as ftp, is told as it arrived, where Envoy tells the connection's scheme"}, {key: "remove_from_clients", level: Partial, note: "names and * prefixes that cover none of content-length, connection and upgrade", refuses: "holding content-length, connection or upgrade, in full or under a * prefix: the Envoy output sends the body chunked once Content-Length is removed, and leaves a WebSocket upgrade unanswered once Connection or Upgrade is removed, which HAProxy cannot write; write the other names in full, or a longer prefix, or render it for envoy"}, {key: "cors", level: Supported}, diff --git a/internal/nginx/auth.go b/internal/nginx/auth.go index ed9271d..7e1837a 100644 --- a/internal/nginx/auth.go +++ b/internal/nginx/auth.go @@ -132,11 +132,20 @@ func checkLines(in generator.Input, v *values, e edge) (http, stream []string) { // case, over the connection's or the client's X-Forwarded-Proto (measured on Envoy 1.40.2). Inside the // subrequest $request_uri and $request are the client's and $pf_path keeps the value the route choice read; the // query comes from $request_uri, as $args is the subrequest's. + // With connection the client that writes the target is not trusted for its scheme, so the check is told the + // connection's, the one the service is sent, as docs/auth.md says: the target's would tell it https for an + // https target sent over plain HTTP, which nginx serves and the Envoy output answers 403 (measured on nginx + // 1.30.6 and 1.31.8 beside Envoy 1.40.2). Over TLS an http target is then told https, where the Envoy output + // tells http, as an HTTP/2 :scheme is (the auth.send_request row). + toldProto := ` map $request $pf_told_proto { ` + quoted(`~*^[^ ]+ +https://`) + ` https; ` + quoted(`~*^[^ ]+ +http://`) + + ` http; default $pf_forwarded_proto; }` + if e.connection { + toldProto = ` map "" $pf_told_proto { default $pf_forwarded_proto; }` + } http = append(http, ` map $request_uri $pf_query { `+regexKey(`^[^?]*(?\?.*)`)+` $pf_query_text; default ""; }`, " map $pf_mode $pf_told_uri { uri $pf_path$pf_query; default $request_uri; }", - ` map $request $pf_told_proto { `+quoted(`~*^[^ ]+ +https://`)+` https; `+quoted(`~*^[^ ]+ +http://`)+ - ` http; default $pf_forwarded_proto; }`, + toldProto, ) } service := in.Gateway.Service(a.Service.Value) diff --git a/internal/nginx/auth_test.go b/internal/nginx/auth_test.go index 1337ac1..373c78d 100644 --- a/internal/nginx/auth_test.go +++ b/internal/nginx/auth_test.go @@ -170,6 +170,9 @@ func TestCheckLines(t *testing.T) { keepAlive := generate(t, rewritten(t, checks, " accept: [x-user-check]\n", " accept: [x-user-id, keep-alive]\n")) // A name remove_from_clients lists that accept names too. both := generate(t, rewritten(t, checks, "remove_from_clients: [x-request-id]\n", "remove_from_clients: [x-request-id, x-user-check]\n")) + // The file under deny with client_address connection and still no tls. + connectionChecks := generate(t, rewritten(t, checks, "admin: 9901\n", "admin: 9901\nclient_address: connection\n")) + toldByTarget := ` map $request $pf_told_proto { "~*^[^ ]+ +https://" https; "~*^[^ ]+ +http://" http; default $pf_forwarded_proto; }` cases := []struct { name string out string @@ -197,7 +200,7 @@ func TestCheckLines(t *testing.T) { ` map "" $pf_counted_address { default ""; }`, ` map $request_uri $pf_query { "~^[^?]*(?\\?.*)" $pf_query_text; default ""; }`, " map $pf_mode $pf_told_uri { uri $pf_path$pf_query; default $request_uri; }", - ` map $request $pf_told_proto { "~*^[^ ]+ +https://" https; "~*^[^ ]+ +http://" http; default $pf_forwarded_proto; }`, + toldByTarget, }, {` "~^1" dotparam;`}, { @@ -236,6 +239,16 @@ func TestCheckLines(t *testing.T) { "}", }, }, absent: []string{` "~^1" refused;`, " types {}"}}, + // With connection the check is told the scheme the service is sent, the connection's, whatever scheme an + // absolute target names, with tls and without; with forwarded the target's (above). + {name: "connection without tls, the scheme the check is told", out: connectionChecks, want: [][]string{ + {` map "" $pf_forwarded_proto { default $scheme; }`}, + {` map "" $pf_told_proto { default $pf_forwarded_proto; }`}, + {" proxy_set_header x-forwarded-proto $pf_told_proto;"}, + }, absent: []string{toldByTarget}}, + {name: "connection with tls, the scheme the check is told", out: authOut, want: [][]string{ + {` map "" $pf_told_proto { default $pf_forwarded_proto; }`}, + }, absent: []string{toldByTarget}}, {name: "deny, the request log", out: checksOut, want: [][]string{ {requestLog("pf_request", `"$pf_authz_us"`), requestLog("pf_request_not_asked", "null")}, { diff --git a/internal/nginx/script.js b/internal/nginx/script.js index 635aed6..6544396 100644 --- a/internal/nginx/script.js +++ b/internal/nginx/script.js @@ -1646,11 +1646,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -1674,8 +1676,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); } diff --git a/internal/nginx/script_tracing_test.go b/internal/nginx/script_tracing_test.go index b02b80e..ff526e7 100644 --- a/internal/nginx/script_tracing_test.go +++ b/internal/nginx/script_tracing_test.go @@ -322,11 +322,13 @@ function traceLines(r) { // it: h: the first line of the client's header as Envoy reads it, j: the lines of a header Envoy joins, // joined as it joins them (joinedValues), v: a header the proxy writes itself, read from the variable it // writes it with as Envoy reads it, none when empty and empty when it holds the one space the check's handler stores -// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's own variable -// of that name, none when unset, which never reads one every object inherits, such as constructor. For the source at -// position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each tag's -// map reads its source's two variables, so no map reads another source's value. Nothing is written unless every source -// was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. +// for a value the check sent empty, a: a header the proxy removes, always none, e: the environment's variable of +// that name, none when unset: a name every object inherits, such as constructor, reads a value that is no string, which +// counts as none. The type is read where hasOwnProperty would ask the same, because that call on process.env in each +// traced request left each worker of nginx 1.31.8 holding about 25 MiB more at 1,000 requests a second. For the source +// at position n from 1 it writes the value to $pf_tv_, or n to $pf_ts_ for none and e for an empty value; each +// tag's map reads its source's two variables, so no map reads another source's value. Nothing is written unless every +// source was read, and it answers "", which each map's key starts with, so the pass runs before a map reads them. function readTags(r) { try { var sources = r.variables.pf_tag_sources.split(" "), raw = r.rawHeadersIn, lines = {}, values = []; @@ -350,8 +352,11 @@ function readTags(r) { } else if (value !== null) { value = asEnvoyReads(r, value); } - } else if (kind == "e:" && Object.prototype.hasOwnProperty.call(process.env, name)) { + } else if (kind == "e:") { value = process.env[name]; + if (typeof value != "string") { + value = null; + } } values.push(value); }