Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid duplicate status in audit events #62695

Merged
merged 1 commit into from
May 15, 2018

Conversation

CaoShuFeng
Copy link
Contributor

@CaoShuFeng CaoShuFeng commented Apr 17, 2018

Fixes: #60108

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:
/assign @sttts @tallclair

Release note:

Action required: When Response is a metav1.Status, it is no longer copied into the audit.Event status. Only the "status", "reason" and "code" fields are set.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 17, 2018
@@ -171,7 +171,12 @@ func LogResponseObject(ae *auditinternal.Event, obj runtime.Object, gv schema.Gr
return
}
if status, ok := obj.(*metav1.Status); ok {
ae.ResponseStatus = status
ae.ResponseStatus = &metav1.Status{
// Selectively copy the bounded fields to avoid duplicate status in audit events
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do we lose in practice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change:

    "responseStatus": {
        "apiVersion": "v1",
        "code": 403,
        "details": {
            "kind": "pods"
        },
        "kind": "Status",
        "message": "pods is forbidden: User \"tom\" cannot list pods in the namespace \"default\"",
        "metadata": {},
        "reason": "Forbidden",
        "status": "Failure"
    },

After this change:

    "responseStatus": {
        "code": 403,
        "metadata": {},
        "reason": "Forbidden",
        "status": "Failure"
    },

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to lose the message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And is this message duplicated as well? If yes, I can agree with the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think Message is necessay.
Add it back.

@tallclair
Copy link
Member

When is a status returned? I think maybe for delete requests, and errors?

There are 2 concerns with copying the status:

  1. Duplicate data returned
  2. Potentially large data returned at the Metadata level

The first could be dealt with simply by omitting the response object when it's a status, but this won't handle the case where the message can be really large. We could truncate the message when level == Metadata

WDYT? What is the desired behavior here?

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 18, 2018
@CaoShuFeng
Copy link
Contributor Author

Will fix the unit test tomorrow.

@CaoShuFeng
Copy link
Contributor Author

CaoShuFeng commented Apr 18, 2018

The first could be dealt with simply by omitting the response object when it's a status

Done.

We could truncate the message when level == Metadata

Done.

@tallclair
Copy link
Member

I meant for that to be a discussion. I'm not sure the approach I suggested is the right one. I'm interested in hearing other suggestions.

@sttts @loburm

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 19, 2018
@CaoShuFeng
Copy link
Contributor Author

/area audit

@tallclair
Copy link
Member

tallclair commented Apr 20, 2018

Looking at how we use the status, I'm thinking something closer to your original PR might be the way to go. Don't copy the status, Just set the code, reason, and status. Long term, I think we should consider changing ResponseStatus to just ResponseCode.

EDIT: The info from the fake status we generate can be added as annotations if it's really needed. For cases where you want the full response status from the response, just log at response level.

@CaoShuFeng
Copy link
Contributor Author

EDIT: The info from the fake status we generate can be added as annotations if it's really needed.

Can't follow this. Which part to add to annotations?

Don't copy the status, Just set the code, reason, and status.

Message is deleted, and it should be only saved at response level.

@CaoShuFeng
Copy link
Contributor Author

/test pull-kubernetes-e2e-kops-aws
/test pull-kubernetes-integration

@tallclair
Copy link
Member

EDIT: The info from the fake status we generate can be added as annotations if it's really needed.

Can't follow this. Which part to add to annotations?

I was just reviewing the status objects we generate for auditing (as opposed to copy from the response):

  1. on panic
  2. connection closed
  3. auth failed

What I meant was that the messages we set in those 3 cases could be included elsewhere, if we got rid of the ResponseStatus field (replaced with ResponseCode).

Reason: status.Reason,
Code: status.Code,
}
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should get rid of the else case. This just duplicates the status when it's already being returned in the Response field.

Copy link
Contributor Author

@CaoShuFeng CaoShuFeng Apr 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just duplicates the status when it's already being returned in the Response field.

We have a return in line 184, so it's not duplicated.

If we delete it, it will be diffacult for users to query the http response code from response level audit events. WDYT @tallclair

@k8s-ci-robot k8s-ci-robot removed the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 25, 2018
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 25, 2018
@CaoShuFeng
Copy link
Contributor Author

CaoShuFeng commented Apr 25, 2018

Hi, @tallclair @sttts
I changed this pull request to the original version.

With this version, users can still get detailed status info in response audit level.
And users can get status code at all audit levels.

@CaoShuFeng
Copy link
Contributor Author

Long term, I think we should consider changing ResponseStatus to just ResponseCode.

What about we leave other parts of ResponseStatus empty, and only set the Code?

@k8s-ci-robot k8s-ci-robot added release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Apr 25, 2018
@tallclair
Copy link
Member

/lgtm

I updated your release note to highlight that this is a potentially breaking change.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 25, 2018
@tallclair tallclair added this to the v1.11 milestone May 14, 2018
@tallclair
Copy link
Member

Ping @sttts - would be great to get this in 1.11

@tallclair tallclair added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. labels May 14, 2018
@tallclair
Copy link
Member

/sig auth

@k8s-ci-robot k8s-ci-robot added the sig/auth Categorizes an issue or PR as relevant to SIG Auth. label May 14, 2018
@k8s-github-robot
Copy link

[MILESTONENOTIFIER] Milestone Pull Request Needs Approval

@CaoShuFeng @sttts @tallclair @kubernetes/sig-auth-misc

Action required: This pull request must have the status/approved-for-milestone label applied by a SIG maintainer. If the label is not applied within 7 days, the pull request will be moved out of the v1.11 milestone.

Pull Request Labels
  • sig/auth: Pull Request will be escalated to these SIGs if needed.
  • priority/important-soon: Escalate to the pull request owners and SIG owner; move out of milestone after several unsuccessful escalation attempts.
  • kind/cleanup: Adding tests, refactoring, fixing old bugs.
Help

@CaoShuFeng
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce

@sttts
Copy link
Contributor

sttts commented May 15, 2018

/approve
/retest

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CaoShuFeng, sttts, tallclair

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 15, 2018
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit d0f4a8f into kubernetes:master May 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/audit cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. milestone/needs-approval priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. sig/auth Categorizes an issue or PR as relevant to SIG Auth. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't duplicate status in audit events
5 participants