mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-30 09:27:19 +02:00
authorize: add request IP to rego evaluation (#3107)
This commit is contained in:
parent
5ac55f68b6
commit
a0e64b1cf9
5 changed files with 15 additions and 1 deletions
|
@ -40,16 +40,24 @@ type RequestHTTP struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Headers map[string]string `json:"headers"`
|
Headers map[string]string `json:"headers"`
|
||||||
ClientCertificate string `json:"client_certificate"`
|
ClientCertificate string `json:"client_certificate"`
|
||||||
|
IP string `json:"ip"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRequestHTTP creates a new RequestHTTP.
|
// NewRequestHTTP creates a new RequestHTTP.
|
||||||
func NewRequestHTTP(method string, requestURL url.URL, headers map[string]string, rawClientCertificate string) RequestHTTP {
|
func NewRequestHTTP(
|
||||||
|
method string,
|
||||||
|
requestURL url.URL,
|
||||||
|
headers map[string]string,
|
||||||
|
rawClientCertificate string,
|
||||||
|
ip string,
|
||||||
|
) RequestHTTP {
|
||||||
return RequestHTTP{
|
return RequestHTTP{
|
||||||
Method: method,
|
Method: method,
|
||||||
Path: requestURL.Path,
|
Path: requestURL.Path,
|
||||||
URL: requestURL.String(),
|
URL: requestURL.String(),
|
||||||
Headers: headers,
|
Headers: headers,
|
||||||
ClientCertificate: rawClientCertificate,
|
ClientCertificate: rawClientCertificate,
|
||||||
|
IP: ip,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -481,6 +481,7 @@ func TestEvaluator(t *testing.T) {
|
||||||
*mustParseURL("https://from.example.com/"),
|
*mustParseURL("https://from.example.com/"),
|
||||||
nil,
|
nil,
|
||||||
testValidCert,
|
testValidCert,
|
||||||
|
"",
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -494,6 +495,7 @@ func TestEvaluator(t *testing.T) {
|
||||||
*mustParseURL("https://from.example.com/test"),
|
*mustParseURL("https://from.example.com/test"),
|
||||||
nil,
|
nil,
|
||||||
testValidCert,
|
testValidCert,
|
||||||
|
"",
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -133,6 +133,7 @@ func (a *Authorize) getEvaluatorRequestFromCheckRequest(
|
||||||
requestURL,
|
requestURL,
|
||||||
getCheckRequestHeaders(in),
|
getCheckRequestHeaders(in),
|
||||||
getPeerCertificate(in),
|
getPeerCertificate(in),
|
||||||
|
in.GetAttributes().GetSource().GetAddress().GetSocketAddress().GetAddress(),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
if sessionState != nil {
|
if sessionState != nil {
|
||||||
|
|
|
@ -98,6 +98,7 @@ func Test_getEvaluatorRequest(t *testing.T) {
|
||||||
"X-Forwarded-Proto": "https",
|
"X-Forwarded-Proto": "https",
|
||||||
},
|
},
|
||||||
certPEM,
|
certPEM,
|
||||||
|
"",
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
assert.Equal(t, expect, actual)
|
assert.Equal(t, expect, actual)
|
||||||
|
@ -304,6 +305,7 @@ func Test_getEvaluatorRequestWithPortInHostHeader(t *testing.T) {
|
||||||
"X-Forwarded-Proto": "https",
|
"X-Forwarded-Proto": "https",
|
||||||
},
|
},
|
||||||
certPEM,
|
certPEM,
|
||||||
|
"",
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
assert.Equal(t, expect, actual)
|
assert.Equal(t, expect, actual)
|
||||||
|
|
|
@ -35,6 +35,7 @@ func (a *Authorize) logAuthorizeCheck(
|
||||||
evt = evt.Str("path", stripQueryString(hattrs.GetPath()))
|
evt = evt.Str("path", stripQueryString(hattrs.GetPath()))
|
||||||
evt = evt.Str("host", hattrs.GetHost())
|
evt = evt.Str("host", hattrs.GetHost())
|
||||||
evt = evt.Str("query", hattrs.GetQuery())
|
evt = evt.Str("query", hattrs.GetQuery())
|
||||||
|
evt = evt.Str("ip", in.GetAttributes().GetSource().GetAddress().GetSocketAddress().GetAddress())
|
||||||
|
|
||||||
// session information
|
// session information
|
||||||
if s, ok := s.(*session.Session); ok {
|
if s, ok := s.(*session.Session); ok {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue