add support for proxy headers (#744)

This commit is contained in:
Kory Prince
2021-07-22 14:03:53 -05:00
committed by GitHub
parent 4e684a40d2
commit e2efa7bd80
3 changed files with 12 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ import (
"github.com/go-kit/kit/auth/basic"
"github.com/go-kit/kit/log"
httptransport "github.com/go-kit/kit/transport/http"
"github.com/gorilla/handlers"
"github.com/groob/finalizer/logutil"
"github.com/micromdm/go4/env"
"github.com/micromdm/go4/httputil"
@@ -109,6 +110,7 @@ func serve(args []string) error {
flTLSKey = flagset.String("tls-key", env.String("MICROMDM_TLS_KEY", ""), "Path to TLS private key")
flHTTPAddr = flagset.String("http-addr", env.String("MICROMDM_HTTP_ADDR", ":https"), "http(s) listen address of mdm server. defaults to :8080 if tls is false")
flHTTPDebug = flagset.Bool("http-debug", env.Bool("MICROMDM_HTTP_DEBUG", false), "Enable debug for http(dumps full request)")
flHTTPProxyHeaders = flagset.Bool("http-proxy-headers", env.Bool("MICROMDM_HTTP_PROXY_HEADERS", false), "Enable parsing of proxy headers for use behind a reverse proxy")
flRepoPath = flagset.String("filerepo", env.String("MICROMDM_FILE_REPO", ""), "Path to http file repo")
flDepSim = flagset.String("depsim", env.String("MICROMDM_DEPSIM_URL", ""), "Use depsim URL")
flExamples = flagset.Bool("examples", false, "Prints some example usage")
@@ -330,6 +332,9 @@ func serve(args []string) error {
} else {
handler = r
}
if *flHTTPProxyHeaders {
handler = handlers.ProxyHeaders(handler)
}
handler = logutil.NewHTTPLogger(httpLogger).Middleware(handler)
srvURL, err := url.Parse(sm.ServerPublicURL)

2
go.mod
View File

@@ -4,6 +4,7 @@ require (
github.com/RobotsAndPencils/buford v0.12.0
github.com/boltdb/bolt v1.3.1
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/garyburd/go-oauth v0.0.0-20180319155456-bca2e7f09a17
github.com/go-kit/kit v0.7.0
github.com/go-sql-driver/mysql v1.4.0 // indirect
@@ -12,6 +13,7 @@ require (
github.com/golang/protobuf v1.4.3
github.com/google/uuid v1.1.1
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.6.2
github.com/groob/finalizer v0.0.0-20170707115354-4c2ed49aabda
github.com/groob/plist v0.0.0-20180203051248-dd56909aee38

5
go.sum
View File

@@ -4,6 +4,9 @@ github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/felixge/httpsnoop v1.0.2 h1:+nS9g82KMXccJ/wp0zyRW9ZBHFETmMGtkk+2CTTrW4o=
github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/garyburd/go-oauth v0.0.0-20180319155456-bca2e7f09a17 h1:GOfMz6cRgTJ9jWV0qAezv642OhPnKEG7gtUjJSdStHE=
github.com/garyburd/go-oauth v0.0.0-20180319155456-bca2e7f09a17/go.mod h1:HfkOCN6fkKKaPSAeNq/er3xObxTW4VLeY6UUK895gLQ=
github.com/go-kit/kit v0.4.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
@@ -36,6 +39,8 @@ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
github.com/gorilla/mux v1.4.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=