Skip to content

Commit

Permalink
Switch to forked httprouter and enable UseRawPath option (#11068) (
Browse files Browse the repository at this point in the history
…#12109)

* Use forked httprouter with RawPath fix: gravitational/httprouter

* Enable UseRawPath everywhere.

* Test: allow MFA devices with `/` in names to be deleted

Co-authored-by: Przemko Robakowski <przemko.robakowski@goteleport.com>
  • Loading branch information
Tener and probakowski committed Apr 21, 2022
1 parent 0342a0c commit 393dcc2
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,5 @@ replace (
github.com/gogo/protobuf => github.com/gravitational/protobuf v1.3.2-0.20201123192827-2b9fcfaffcbf
github.com/gravitational/teleport/api => ./api
github.com/siddontang/go-mysql v1.1.0 => github.com/gravitational/go-mysql v1.1.1-0.20210212011549-886316308a77
github.com/julienschmidt/httprouter => github.com/gravitational/httprouter v1.3.1-0.20220408074523-c876c5e705a5
)
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ github.com/gravitational/go-mysql v1.1.1-0.20210212011549-886316308a77 h1:ivambM
github.com/gravitational/go-mysql v1.1.1-0.20210212011549-886316308a77/go.mod h1:re0JQZ1Cy5dVlIDGq0YksfDIla/GRZlxqOoC0XPSSGE=
github.com/gravitational/go-oidc v0.0.6 h1:DCllahGYxDAvxWsq8UILgO+/i1EheQRxcNzS+D+wP5I=
github.com/gravitational/go-oidc v0.0.6/go.mod h1:SevmOUNdOB0aD9BAIgjptZ6oHkKxMZZgA70nwPfgU/w=
github.com/gravitational/httprouter v1.3.1-0.20220408074523-c876c5e705a5 h1:qg8FcGwRACSHortU1UxCSo9nF0t34rPWjk9Nef3j2Ic=
github.com/gravitational/httprouter v1.3.1-0.20220408074523-c876c5e705a5/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/gravitational/kingpin v2.1.11-0.20190130013101-742f2714c145+incompatible h1:CfyZl3nyo9K5lLqOmqvl9/IElY1UCnOWKZiQxJ8HKdA=
github.com/gravitational/kingpin v2.1.11-0.20190130013101-742f2714c145+incompatible/go.mod h1:LWxG30M3FcrjhOn3T4zz7JmBoQJ45MWZmOXgy9Ganoc=
github.com/gravitational/license v0.0.0-20210218173955-6d8fb49b117a h1:PN5vAN1ZA0zqdpM6wNdx6+bkdlQ5fImd75oaIHSbOhY=
Expand Down Expand Up @@ -472,9 +474,6 @@ github.com/jstemmer/go-junit-report v0.9.1 h1:6QPYqodiu3GuPL+7mfx+NwDdp2eTkp9IfE
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
Expand Down
1 change: 1 addition & 0 deletions lib/auth/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func NewAPIServer(config *APIConfig) (http.Handler, error) {
Clock: clockwork.NewRealClock(),
}
srv.Router = *httprouter.New()
srv.Router.UseRawPath = true

// Kubernetes extensions
srv.POST("/:version/kube/csr", srv.withAuth(srv.processKubeCSR))
Expand Down
1 change: 1 addition & 0 deletions lib/httplib/httplib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type testHandler struct {
func newTestHandler() *testHandler {
h := &testHandler{}
h.Router = *httprouter.New()
h.Router.UseRawPath = true
h.POST("/v1/sessions/:id/stream", MakeHandler(h.postSessionChunkOriginal))
h.POST("/v1/namespaces/:namespace/sessions/:id/stream", MakeHandler(h.postSessionChunkNamespace))
return h
Expand Down
2 changes: 2 additions & 0 deletions lib/kube/proxy/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ func NewForwarder(cfg ForwarderConfig) (*Forwarder, error) {
close: close,
}

fwd.router.UseRawPath = true

fwd.router.POST("/api/:ver/namespaces/:podNamespace/pods/:podName/exec", fwd.withAuth(fwd.exec))
fwd.router.GET("/api/:ver/namespaces/:podNamespace/pods/:podName/exec", fwd.withAuth(fwd.exec))

Expand Down
3 changes: 3 additions & 0 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ func NewHandler(cfg Config, opts ...HandlerOption) (*RewritingHandler, error) {
clusterFeatures: cfg.ClusterFeatures,
}

// for properly handling url-encoded parameter values.
h.UseRawPath = true

for _, o := range opts {
if err := o(h); err != nil {
return nil, trace.Wrap(err)
Expand Down
1 change: 1 addition & 0 deletions lib/web/app/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func NewHandler(ctx context.Context, c *HandlerConfig) (*Handler, error) {

// Create the application routes.
h.router = httprouter.New()
h.router.UseRawPath = true
h.router.GET("/x-teleport-auth", makeRouterHandler(h.handleFragment))
h.router.POST("/x-teleport-auth", makeRouterHandler(h.handleFragment))
h.router.GET("/teleport-logout", h.withRouterAuth(h.handleLogout))
Expand Down
12 changes: 12 additions & 0 deletions vendor/github.com/julienschmidt/httprouter/router.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion vendor/github.com/julienschmidt/httprouter/tree.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ github.com/json-iterator/go
github.com/jstemmer/go-junit-report
github.com/jstemmer/go-junit-report/formatter
github.com/jstemmer/go-junit-report/parser
# github.com/julienschmidt/httprouter v1.3.0
## explicit
# github.com/julienschmidt/httprouter v1.3.0 => github.com/gravitational/httprouter v1.3.1-0.20220408074523-c876c5e705a5
## explicit; go 1.7
github.com/julienschmidt/httprouter
# github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
## explicit
Expand Down Expand Up @@ -1178,3 +1178,4 @@ sigs.k8s.io/yaml
# github.com/coreos/go-oidc => github.com/gravitational/go-oidc v0.0.6
# github.com/gogo/protobuf => github.com/gravitational/protobuf v1.3.2-0.20201123192827-2b9fcfaffcbf
# github.com/gravitational/teleport/api => ./api
# github.com/julienschmidt/httprouter => github.com/gravitational/httprouter v1.3.1-0.20220408074523-c876c5e705a5

0 comments on commit 393dcc2

Please sign in to comment.