mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-30 23:09:23 +02:00
authorize: serialize errors in metav1.Status format when kubernetes user-agent is detected
This commit is contained in:
parent
298a5a94a5
commit
a4867179b0
1 changed files with 29 additions and 0 deletions
|
@ -135,7 +135,36 @@ func (a *Authorize) deniedResponse(
|
||||||
respHeader := []*envoy_config_core_v3.HeaderValueOption{}
|
respHeader := []*envoy_config_core_v3.HeaderValueOption{}
|
||||||
|
|
||||||
var respBody []byte
|
var respBody []byte
|
||||||
|
|
||||||
|
hdrs := in.GetAttributes().GetRequest().GetHttp().GetHeaders()
|
||||||
|
userAgent := getHeader(hdrs, "User-Agent")
|
||||||
switch {
|
switch {
|
||||||
|
case strings.Contains(userAgent, "kubernetes/"):
|
||||||
|
message := reason
|
||||||
|
var statusReason string
|
||||||
|
switch code {
|
||||||
|
case http.StatusUnauthorized:
|
||||||
|
statusReason = "Unauthorized"
|
||||||
|
case http.StatusForbidden:
|
||||||
|
statusReason = "Forbidden"
|
||||||
|
case http.StatusNotFound:
|
||||||
|
statusReason = "NotFound"
|
||||||
|
case httputil.StatusDeviceUnauthorized, httputil.StatusInvalidClientCertificate:
|
||||||
|
statusReason = "Unauthorized"
|
||||||
|
message = httputil.DetailsText(int(code))
|
||||||
|
default:
|
||||||
|
statusReason = "" // StatusReasonUnknown
|
||||||
|
}
|
||||||
|
respBody, _ = json.Marshal(map[string]any{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "Status",
|
||||||
|
"status": "Failure", // one of "Success" or "Failure"
|
||||||
|
"message": message, // user-facing message
|
||||||
|
"reason": statusReason, // must correspond to k8s StatusReason strings
|
||||||
|
"code": code, // http code
|
||||||
|
})
|
||||||
|
respHeader = append(respHeader,
|
||||||
|
mkHeader("Content-Type", "application/json"))
|
||||||
case getCheckRequestURL(in).Path == "/robots.txt":
|
case getCheckRequestURL(in).Path == "/robots.txt":
|
||||||
code = 200
|
code = 200
|
||||||
respBody = []byte("User-agent: *\nDisallow: /")
|
respBody = []byte("User-agent: *\nDisallow: /")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue