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

audit: no RequestReceived events for read-only requests #46592

Closed

Conversation

sttts
Copy link
Contributor

@sttts sttts commented May 29, 2017

Follow-up of #46335

@sttts sttts added area/apiserver release-note-none Denotes a PR that doesn't merit a release note. labels May 29, 2017
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 29, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sttts
We suggest the following additional approver: deads2k

Assign the PR to them by writing /assign @deads2k in a comment when ready.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 29, 2017
@sttts
Copy link
Contributor Author

sttts commented May 29, 2017

@soltysh @timstclair @cheftako @ericchiang do we want this?

@sttts sttts mentioned this pull request May 29, 2017
@sttts sttts force-pushed the sttts-audit-stages-read-only-less-events branch from 9647872 to 5b1f3a5 Compare May 29, 2017 11:56
@@ -82,8 +82,8 @@ func (b *backend) logEvent(ev *auditinternal.Event) {
ip = ev.SourceIPs[0]
}

line := fmt.Sprintf("%s AUDIT: id=%q ip=%q method=%q user=%q groups=%q as=%q asgroups=%q namespace=%q uri=%q response=\"%s\"\n",
ev.Timestamp.Format(time.RFC3339Nano), ev.AuditID, ip, ev.Verb, username, groups, asuser, asgroups, namespace, ev.RequestURI, response)
line := fmt.Sprintf("%s AUDIT: id=%q stage=%q ip=%q method=%q user=%q groups=%q as=%q asgroups=%q namespace=%q uri=%q response=\"%s\"\n",

Choose a reason for hiding this comment

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

I think we should think a little about what the goal of this log format is before adding stage to it. Originally, I think it was trying to be consistent with basic auditing, but now that code was forked. Now, it's still missing a bunch of information from the audit event. Just thinking "out loud"...

Choose a reason for hiding this comment

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

BTW - I think we should add an option to write the log in JSON format, where each line is just a json-formatted audit event. (Not for this PR, just FYI)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

--audit-log-format legacy/json/template:"{{foo}} {{bar}}"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be part of the proposal.

@@ -61,6 +61,8 @@ const (
// The stage for events generated once the response body has been completed, and no more bytes
// will be sent.
StageResponseComplete = "ResponseComplete"
// The stage for events generated when a panic occured.
StagePanic = "Panic"

Choose a reason for hiding this comment

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

Add to the external types too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in the other PR. this one has to be rebased.

@@ -87,12 +87,18 @@ func WithAudit(handler http.Handler, requestContextMapper request.RequestContext
return
}

// send first event for non-read-only requests
ri, _ := request.RequestInfoFrom(ctx)
if !(ri != nil && ri.ReadOnly) {

Choose a reason for hiding this comment

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

My feeling is that we should make this decision in a single place, and I'd like an option to disable this stage. We talked about putting the option in the audit backend, but if we're already deciding whether to create a RequestReceived event here, perhaps this would be a good place to check that option as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if this is supposed to be configurable, I would make it a backend independent option: --audit-sparse-readonly-events.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or into the policy.

Choose a reason for hiding this comment

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

For the option, I meant something for all requests, not just read-only requests. But in either case, we can discuss in a follow up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This sound like the policy then. But I agree to discuss that as follow-up. Also this PR was meant as a base of discussion. We don't have to decide here.

ev.ResponseStatus = &metav1.Status{
Code: 200,
Code: http.StatusOK,
Reason: metav1.StatusSuccess,

Choose a reason for hiding this comment

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

This should be on the Status.Status field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if ev.ResponseStatus == nil {
ev.ResponseStatus = &metav1.Status{
Code: http.StatusOK,
Reason: metav1.StatusSuccess,

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Code: 200,
Code: http.StatusOK,
Reason: metav1.StatusSuccess,
Message: "connection closed early",

Choose a reason for hiding this comment

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

nit: I think user-facing Messages usually start with a capital letter (same below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

ev.Stage = auditinternal.StageResponseComplete
if ev.ResponseStatus == nil {

Choose a reason for hiding this comment

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

Move this above the previous if block, and you only need to build the fake status once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@timstclair
Copy link

Please rebase (&squash while you're at it)

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 31, 2017
@sttts
Copy link
Contributor Author

sttts commented Jun 1, 2017

#46592 (comment) is still open.

@sttts sttts force-pushed the sttts-audit-stages-read-only-less-events branch from 5b1f3a5 to 56148e5 Compare June 1, 2017 06:58
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 1, 2017
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jun 1, 2017

@sttts: The following test(s) failed:

Test name Commit Details Rerun command
pull-kubernetes-node-e2e 56148e5 link @k8s-bot pull-kubernetes-node-e2e test this
pull-kubernetes-federation-e2e-gce 56148e5 link @k8s-bot pull-kubernetes-federation-e2e-gce test this

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@timstclair
Copy link

Yeah, I don't see that being resolved by code freeze. I guess we don't want both an option in the policy and to drop them on read-only events... should we just leave this for now?

@sttts
Copy link
Contributor Author

sttts commented Jun 1, 2017

Let's leave it for now.

@k8s-github-robot
Copy link

@sttts PR needs rebase

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 5, 2017
@sttts
Copy link
Contributor Author

sttts commented Jul 17, 2017

@timstclair @ericchiang this PR is still pending. Is anything of this still relevant? Or do we have the same with the policy now?

@tallclair
Copy link
Member

I think this needs more discussion...

One option is to incorporate the stage into the policy some how (which is documented in the beta changes cover bug: #48561)

My priority is just to reduce the number of events that are sent by the webhook, so an alternative would be to do some deduplication in the webhook. One way of doing so would be to put the early stages in a sort of "TTL Cache" which holds the latest stage of the event. If the ResponseComplete stage is logged, then that event is removed from the cache and added to the queue as with today. If an event is evicted from the cache (either due to size or TTL expiration), then the latest stage is added to the queue. The end result should be that most requests just send a ResponseComplete event, but requests that take an unusually long time to complete are guaranteed to be sent within X seconds (60?) of the request start time. (Obviously this would only be for the batching mode).

WDYT?

/cc @ericchiang @crassirostris

@k8s-github-robot
Copy link

This PR hasn't been active in 30 days. It will be closed in 59 days (Oct 17, 2017).

cc @sttts @tallclair

You can add 'keep-open' label to prevent this from happening, or add a comment to keep it open another 90 days

@sttts
Copy link
Contributor Author

sttts commented Aug 31, 2017

Closing as this is superseeded by a more powerful policy which can express this.

@sttts sttts closed this Aug 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants