From 98d2f194a0f968635b7e5ff05daa4bfeabe8dcb3 Mon Sep 17 00:00:00 2001 From: Caleb Doxsey Date: Fri, 8 May 2020 15:56:43 -0600 Subject: [PATCH] authorize: allow CORS preflight requests (#672) * proxy: implement preserve host header option * authorize: allow CORS preflight requests --- authorize/evaluator/opa/policy/authz.rego | 11 +++- .../evaluator/opa/policy/authz_test.rego | 30 ++++++++++ authorize/evaluator/opa/policy/statik.go | 3 +- authorize/grpc.go | 1 + internal/middleware/cors.go | 26 --------- internal/middleware/cors_test.go | 56 ------------------- 6 files changed, 42 insertions(+), 85 deletions(-) delete mode 100644 internal/middleware/cors.go delete mode 100644 internal/middleware/cors_test.go diff --git a/authorize/evaluator/opa/policy/authz.rego b/authorize/evaluator/opa/policy/authz.rego index ad03a6fc2..4661096cb 100644 --- a/authorize/evaluator/opa/policy/authz.rego +++ b/authorize/evaluator/opa/policy/authz.rego @@ -11,6 +11,16 @@ allow { route_policies[route].AllowPublicUnauthenticatedAccess == true } +# allow cors preflight +allow { + route := first_allowed_route(input.url) + route_policies[route].CORSAllowPreflight == true + input.method == "OPTIONS" + count(object.get(input.headers, "Access-Control-Request-Method", [])) > 0 + count(object.get(input.headers, "Origin", [])) > 0 +} + + # allow by email allow { route := first_allowed_route(input.url) @@ -62,7 +72,6 @@ allow { token.valid count(deny)==0 } - # allow pomerium urls allow { contains(input.url, "/.pomerium/") diff --git a/authorize/evaluator/opa/policy/authz_test.rego b/authorize/evaluator/opa/policy/authz_test.rego index 949ee0e2c..8230e133f 100644 --- a/authorize/evaluator/opa/policy/authz_test.rego +++ b/authorize/evaluator/opa/policy/authz_test.rego @@ -110,6 +110,36 @@ test_pomerium_denied { } } +test_cors_preflight_allowed { + allow with data.route_policies as [{ + "source": "example.com", + "allowed_users": ["bob@example.com"], + "CORSAllowPreflight": true + }] with input as { + "url": "http://example.com/", + "host": "example.com", + "method": "OPTIONS", + "headers": { + "Origin": ["someorigin"], + "Access-Control-Request-Method": ["GET"] + } + } +} +test_cors_preflight_denied { + not allow with data.route_policies as [{ + "source": "example.com", + "allowed_users": ["bob@example.com"] + }] with input as { + "url": "http://example.com/", + "host": "example.com", + "method": "OPTIONS", + "headers": { + "Origin": ["someorigin"], + "Access-Control-Request-Method": ["GET"] + } + } +} + test_parse_url { url := parse_url("http://example.com/some/path?qs") url.scheme == "http" diff --git a/authorize/evaluator/opa/policy/statik.go b/authorize/evaluator/opa/policy/statik.go index ca8d43a94..cee0f2638 100644 --- a/authorize/evaluator/opa/policy/statik.go +++ b/authorize/evaluator/opa/policy/statik.go @@ -10,7 +10,6 @@ import ( const Rego = "rego" // static asset namespace func init() { - data := "PK\x03\x04\x14\x00\x08\x00\x08\x00\xcd\xb0\x9cP\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x00 \x00authz.regoUT\x05\x00\x01\xe2\xa8\xa8^\xbcX_o\xdb6\x10\x7f\x16?\xc5\x95E\x01i\xd5\xe4\xb6\xc0\x06\xcc\x9b\x91\xf5a\xef\x03\x86= \xaaJKg\x9b\x89D $U\xdb\xf5\xfc\xdd\x87#%\xdbQl7M\xd3\xbeD\xd6\xf1\xeew\xbf\xfb\xa3#\x99V\x14wb\x89\xd065j\xd9\xd5\x89\xe8\xec\xea3c\xb2n\x1bm\xa1\x14V$\xba\xe9,\xe6mS\xc9B\xa2\xb9\xb7dVBc\x99\xdf\xe1\x96\xb1\x12\x17\xa2\xab,\x88\xaaj\xd60\x83\x85\xa8\x0c2\xf6\xb2\x17\xb4\xdd\xbc\x92\x05\xf3/;\x168T\x98\xce`!\xb5\xb1\xb9\x93c\x99;q(U\xdb\xd9\xa4\xd3U\xd4+\x1e\xdc\xa7\xee5K\xde\x93\xfe\xdf\x0e\xf3_E\xa4QYY\x08\x8b\xe5\xfb\xa2@c`6\x03\xab;d\xfb#\x85\xf9\x16\xb0\x16\xb2z\x02 \xdb\xdc\xa1JZ\xb1\xad\x1aQ&\x0e\x05fp\x9e\xda\x80\xd2\x19\xd4&\xcd\xb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fa\xd9\x89\x1dC\x03\x0b\xdd\xd4 \xe8\xbaG\x87\x1b\xbf\xe2\xa6\x89\xe9\x0b6\x04By\xf0x\xd9\xee|V\x1e\x11\xcb\xa3\xe9\xfa\x92\xcf`\xc7{\x087.\xfa\x9aq\x97\x0c>\x05\xf7\xf4\x03\xc4\xfd\x8caT\xdf\x87\xc5\xcd?\xa1\x96\x8b-\xcd\x8cc\x99c\x82\x08\x02n\xb0\xd0Hs\xeax'\x8f\xdd\x82\xe8\xc8\xddIg\xb1 \xd8\xb3\xc0Q%\x80\xe9\xec~\xbc$\xf3\xdf\xf7x\xc5\xdf\xee\xfc\xf5d\xbc\xe6\xa5\xcc\xc8\xa5\xc22\xbf]\xdb\xe9\xac\xe7\x8e\xcaq\xa7\x95p\xc7E\xb5\xe4S\xe0\x7f\xfd\xf3\xee\x97_\xf9~\x94\xeb\xb8\xff\xaf\x82\\*\x1a\x93w\xb8\x8d\x18c\xe3Z\xd1\x9f\xd8U\x90\x06\x0d\x00\xbd\xa79M[\x92\xb1=\xfb?\x00\x00\xff\xffPK\x07\x08\xe8\xb4\xfa\xee\x9d\x04\x00\x00\xd5\x10\x00\x00PK\x03\x04\x14\x00\x08\x00\x08\x00E\xb3\x9cP\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00 \x00authz_test.regoUT\x05\x00\x01\x82\xad\xa8^\xd4V[O\xe38\x18}N~E\x94'X\x95\xb6\x1bz\x99AB;\x05\n\xd3\xdbPHK[\x10\x8a\xdc\xc4$n\x938\xb5\x1dz\x19\xf5\xbf\xaf\xec\xf4\x12 \x1dR\x16 \xed\x13\x8a\xed\xef|\xe7\x9c\xefB\x03`\x8e\x81\x0d\x95\x00{\x90\xa0\xd0\xcb\x82\x909\x0bY\x1eM\x99\xe1@`A\xa2\x9c\x9c*\xbfeIe\xf3@=Q\xd4z\xaf\xa3fdI\x05\xae\xcd?\x7f\xeaZ\xb1\xa4\xcaK\x99\"\xdbG\xbem\x8c\xe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kw\"c#\x1b7m\xb5>O\xe2\xa6f\x94\xdf;l_\x1e\xee\x1f\x9f\xf0\xe0\xa30\xf4#8\xb9\xcf\x02z\x1f'\x97\x0e(\x05\xa3\x08i3';\xd10\xb1\xff\\\xae\xe4n\x88\xb6k\xfan\x88m\xe3\x94\x12\xc5\xf0\x88\xb6\x14]\xf9\n$\x1a\xadt\x12\x138l\xc2w\xa8\xe3c\x91^\xdb\xfa\x07bJe A\xa9D$Z\xb2\xf9\xfd\xfb\x11C\xde\x04'\xdbA\xa0\x0d\xf7\xa8\xb5x\xceq\xb3\x7f\xa5t$A\xd8\x06du\xb9\xc2J/n\x03\xf00\x9b/\x1e#q\xff\x06\x00\x00\xff\xffPK\x07\x08\xa6?V\xfb\n\x04\x00\x00\x95\x10\x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00\xcd\xb0\x9cP\xe8\xb4\xfa\xee\x9d\x04\x00\x00\xd5\x10\x00\x00\n\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x00authz.regoUT\x05\x00\x01\xe2\xa8\xa8^PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00E\xb3\x9cP\xa6?V\xfb\n\x04\x00\x00\x95\x10\x00\x00\x0f\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xde\x04\x00\x00authz_test.regoUT\x05\x00\x01\x82\xad\xa8^PK\x05\x06\x00\x00\x00\x00\x02\x00\x02\x00\x87\x00\x00\x00. \x00\x00\x00\x00" + data := "PK\x03\x04\x14\x00\x08\x00\x08\x00\x05\xa2\xa8P\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x00 \x00authz.regoUT\x05\x00\x01\x0b\xbe\xb5^\xbcX_o\xdb6\x10\x7f\x16?\xc5\x95E\x01iU\xe4\xb6\xc0\x06\xcc\x9b\x97\x15\xc5\x1e\xf6\xb0\xa5h\xb7'AUi\x89\xb6\x98H\xa4FR\x8d]\xcf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9f*b\xb7\xc0:\xdcn\xa7\xb2H\x10\xacI\xe0\xa8\"\xc0xr\xd3_\x94\xf9\xef{\x7f\xc5_\xee\xfc\xedd\x7f\xcdK\x89\x11s\xc9\xcb\xfc\xf2\xda\x8e'=w.\x1dw\\ W\x94\xd5s:\x06\xfa\xdb\xfbW\xdf\xff@\xd7{\xb1\x8e\xfb\x1f[\xc4\\b\x9b\xbc\xe2\xcb\x88\x10\xb2\x9f+\xfc\x13\xbb\x0cb\xa3\x01\xc0\xf74\xc7n\x8b2\xb2&\xff\x05\x00\x00\xff\xffPK\x07\x08\xc9\xac\x1e\xe7\x01\x05\x00\x00\xec\x11\x00\x00PK\x03\x04\x14\x00\x08\x00\x08\x00\x07\xa2\xa8P\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00 \x00authz_test.regoUT\x05\x00\x01\x0f\xbe\xb5^\xd4W[s\xda:\x17}\xb6\x7f\x85\xc7O\xcd7\xdc>\x87K\x9b\x99\xce)Mh\xca\xad\x10\x0c\x01\x9a\xc9x\x84\xad\xda\x02\xdb2\x92\x1c.\x1d\xfe\xfb\x19\xc9\\\x9c\xc4ILN\xe6\xe4\xf4\x89\xb1\xb5\xb5\xf7Z{\xad-\x8b\x00\x983`C%\xc0\x1e$(\xf4r d\xceZ\x96\xa7\x0bf8\x10X\x90(g\x9f\x95\xdf\xb2\xa4\xb2U\xa0\x9e)jc\xd8W3\xb2\xa4\x02\xd7\xe6\x8f\xdfu\xadTV\xe5\x8dL\x91\xed#\xdf6fp\xb5\xdb1c+\x1e\x82M&v\xcc\xf8Cg\xf6\xcd\x9b\xb7\x9b\x9f\x06\x05\xcb\xeb:\xed\xf3a\xe1z\xbc*_\x18\x044\x9a\x8bZ\x83\xb6\xad\xe5\xdc\xf2\xc3Y\xdfY\xcf\xf0\xe9\x851\"\x149\x8bq\xad\x10,\xc9@\x0f\xbcB\xa3O\x86\xdaUP_\x17I\xff\xffwV\xed\xee\xe7\xa2\\\x19v\x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fe\xd0\xf0%\xbe_,\x1d\xd2\xa9{L; \"\xf5\"\xad\xf6\x93\xb4{\x9f\x84M\xcd(\xbf\x9f\xd0vsr\xfc\xfe\x84\x80\xd7\xa6\xa1\xaf\xc9\x93\x7f\xabD/\xe7\xc9\xa7K\x94\x02Q\x94i?\x8cOf\xc3\xc4~^\xaed7D\xb7\x82\xf4n\x88\xdd\"RR\x14\x87\xbe\xb0\xa5p\xe5\x83$\xd1'!\x1d\xc5\x04\x0c\xfb\xedO\xb0\xe3c\x91\x9e\xdb\xee\x8fMJf \x9bR\x91Hl\xc9\xfe\x7f\xdbk\x1a\xf2hsr;\x08\xb4\xe1\x11Z\x8bp\x9e7\xf7\xbf\x94\x1dI \xb6O\xb2]\xdc\xe6JOn\x9f\xe0f\xb9Z\xdfF\xe4\xfe\x0e\x00\x00\xff\xffPK\x07\x08\x92\xac+\xdev\x04\x00\x00M\x13\x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00\x05\xa2\xa8P\xc9\xac\x1e\xe7\x01\x05\x00\x00\xec\x11\x00\x00\n\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xb4\x81\x00\x00\x00\x00authz.regoUT\x05\x00\x01\x0b\xbe\xb5^PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00\x07\xa2\xa8P\x92\xac+\xdev\x04\x00\x00M\x13\x00\x00\x0f\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xb4\x81B\x05\x00\x00authz_test.regoUT\x05\x00\x01\x0f\xbe\xb5^PK\x05\x06\x00\x00\x00\x00\x02\x00\x02\x00\x87\x00\x00\x00\xfe \x00\x00\x00\x00" fs.RegisterWithNamespace("rego", data) } - \ No newline at end of file diff --git a/authorize/grpc.go b/authorize/grpc.go index 7ad4b9e07..4c7ccce6e 100644 --- a/authorize/grpc.go +++ b/authorize/grpc.go @@ -55,6 +55,7 @@ func (a *Authorize) Check(ctx context.Context, in *envoy_service_auth_v2.CheckRe // request evt = evt.Str("request-id", hattrs.GetId()) evt = evt.Str("method", hattrs.GetMethod()) + evt = evt.Interface("headers", hdrs) evt = evt.Str("path", hattrs.GetPath()) evt = evt.Str("host", hattrs.GetHost()) evt = evt.Str("query", hattrs.GetQuery()) diff --git a/internal/middleware/cors.go b/internal/middleware/cors.go deleted file mode 100644 index dcd35cfd0..000000000 --- a/internal/middleware/cors.go +++ /dev/null @@ -1,26 +0,0 @@ -package middleware - -import ( - "net/http" - - "github.com/pomerium/pomerium/internal/telemetry/trace" -) - -// CorsBypass is middleware that takes a target handler as a paramater, -// if the request is determined to be a CORS preflight request, that handler -// is called instead of the normal handler chain. -func CorsBypass(target http.Handler) func(next http.Handler) http.Handler { - return func(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - ctx, span := trace.StartSpan(r.Context(), "middleware.CorsBypass") - defer span.End() - if r.Method == http.MethodOptions && - r.Header.Get("Access-Control-Request-Method") != "" && - r.Header.Get("Origin") != "" { - target.ServeHTTP(w, r.WithContext(ctx)) - return - } - next.ServeHTTP(w, r.WithContext(ctx)) - }) - } -} diff --git a/internal/middleware/cors_test.go b/internal/middleware/cors_test.go deleted file mode 100644 index f1ea60c92..000000000 --- a/internal/middleware/cors_test.go +++ /dev/null @@ -1,56 +0,0 @@ -package middleware - -import ( - "fmt" - "net/http" - "net/http/httptest" - "testing" -) - -func someOtherMiddleware(s string) func(next http.Handler) http.Handler { - return func(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Some-Other-Middleware", s) - next.ServeHTTP(w, r) - }) - } -} -func TestCorsBypass(t *testing.T) { - t.Parallel() - fn := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - fmt.Fprint(w, http.StatusText(http.StatusOK)) - w.WriteHeader(http.StatusOK) - }) - - tests := []struct { - name string - method string - header http.Header - wantStatus int - wantHeader string - }{ - {"good", http.MethodOptions, http.Header{"Access-Control-Request-Method": []string{"GET"}, "Origin": []string{"localhost"}}, 200, ""}, - {"invalid cors - non options request", http.MethodGet, http.Header{"Access-Control-Request-Method": []string{"GET"}, "Origin": []string{"localhost"}}, 200, "BAD"}, - {"invalid cors - Origin not set", http.MethodOptions, http.Header{"Access-Control-Request-Method": []string{"GET"}, "Origin": []string{""}}, 200, "BAD"}, - {"invalid cors - Access-Control-Request-Method not set", http.MethodOptions, http.Header{"Access-Control-Request-Method": []string{""}, "Origin": []string{"*"}}, 200, "BAD"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - r := &http.Request{ - Method: tt.method, - Header: tt.header, - } - w := httptest.NewRecorder() - target := fn - got := CorsBypass(target)(someOtherMiddleware("BAD")(target)) - got.ServeHTTP(w, r) - if status := w.Code; status != tt.wantStatus { - t.Errorf("TestCorsBypass() error = %v, wantErr %v\n%v", w.Result().StatusCode, tt.wantStatus, w.Body.String()) - } - if header := w.Header().Get("Some-Other-Middleware"); tt.wantHeader != header { - t.Errorf("TestCorsBypass() header = %v, want %v", header, tt.wantHeader) - } - }) - } -}