Skip to content

Commit

Permalink
server: Add request headers to authorization input
Browse files Browse the repository at this point in the history
These changes update the server to include request headers in the
authorization input document.

Fixes open-policy-agent#1456

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
  • Loading branch information
tsandall committed Jun 1, 2019
1 parent 2849b5d commit c1af276
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
23 changes: 22 additions & 1 deletion docs/content/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,28 @@ policy:
# URL parameters represented as an object of string arrays.
# For example: metrics&explain=true is represented as
# {"metrics": [""], "explain": ["true"]}
"params": <HTTP URL Parameters>
"params": <HTTP URL Parameters>,

# Request headers represented as an object of string arrays.
#
# Example Request Headers:
#
# host: acmecorp.com
# x-custom: secretvalue
#
# Example input.headers Value:
#
# {"Host": ["acmecorp.com"], "X-Custom": ["mysecret"]}
#
# Example header check:
#
# input.headers["X-Custom"][_] = "mysecret"
#
# Header keys follow canonical MIME form. The first character and any
# characters following a hyphen are uppercase. The rest are lowercase.
# If the header key contains space or invalid header field bytes,
# no conversion is performed.
"headers": <HTTP Headers>
}
}
```
Expand Down
7 changes: 4 additions & 3 deletions server/authorizer/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ func makeInput(r *http.Request) (interface{}, error) {
query := r.URL.Query()

input := map[string]interface{}{
"path": path,
"method": method,
"params": query,
"path": path,
"method": method,
"params": query,
"headers": r.Header,
}

identity, ok := identifier.Identity(r)
Expand Down
10 changes: 10 additions & 0 deletions server/authorizer/authorizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ func TestMakeInput(t *testing.T) {
panic(err)
}

req.Header.Add("x-custom", "foo")
req.Header.Add("X-custom", "bar")
req.Header.Add("x-custom-2", "baz")
req.Header.Add("custom-header-3?", "wat")

query := req.URL.Query()

// set query parameters
Expand All @@ -256,6 +261,11 @@ func TestMakeInput(t *testing.T) {
"path": ["foo","bar"],
"method": "GET",
"identity": "bob",
"headers": {
"X-Custom": ["foo", "bar"],
"X-Custom-2": ["baz"],
"custom-header-3?": ["wat"]
},
"params": {"explain": ["full"], "pretty": ["true"]}
}
`))
Expand Down

0 comments on commit c1af276

Please sign in to comment.