Skip to content

Commit

Permalink
Set Forbidden as the response status reason (open-policy-agent#1692)
Browse files Browse the repository at this point in the history
* Set Forbidden as the response status reason

Signed-off-by: Filipe Regadas <filiperegadas@gmail.com>

* fixup! Set Forbidden as the response status reason

Signed-off-by: Filipe Regadas <filiperegadas@gmail.com>

Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com>
Signed-off-by: Priya Shetpriya.shet@gmail.com <priya.shet@gmail.com>
  • Loading branch information
2 people authored and priyamshet committed Dec 14, 2021
1 parent d3c4ab9 commit 3cce955
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions pkg/webhook/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,31 @@ func (h *validationHandler) Handle(ctx context.Context, req admission.Request) a
denyMsgs, warnMsgs := h.getValidationMessages(res, &req)

if len(denyMsgs) > 0 {
vResp := admission.Denied(strings.Join(denyMsgs, "\n"))
if vResp.Result == nil {
vResp.Result = &metav1.Status{}
}
if len(warnMsgs) > 0 {
vResp.Warnings = warnMsgs
}
vResp.Result.Code = http.StatusForbidden
requestResponse = denyResponse
return vResp
return admission.Response{
AdmissionResponse: admissionv1.AdmissionResponse{
Allowed: false,
Result: &metav1.Status{
Reason: metav1.StatusReasonForbidden,
Code: http.StatusForbidden,
Message: strings.Join(denyMsgs, "\n"),
},
Warnings: warnMsgs,
},
}
}

requestResponse = allowResponse
vResp := admission.Allowed("")
if vResp.Result == nil {
vResp.Result = &metav1.Status{}
vResp := admission.Response{
AdmissionResponse: admissionv1.AdmissionResponse{
Allowed: true,
Result: &metav1.Status{
Code: http.StatusOK,
},
Warnings: warnMsgs,
},
}
if len(warnMsgs) > 0 {
vResp.Warnings = warnMsgs
vResp.Result.Code = httpStatusWarning
}
return vResp
Expand Down

0 comments on commit 3cce955

Please # to comment.