-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Provide a way to omit Event stages in audit policy #49280
Provide a way to omit Event stages in audit policy #49280
Conversation
Hi @CaoShuFeng. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with I understand the commands that are listed here. 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. |
@sttts @tallclair |
@CaoShuFeng - What is your motivation for omitting stages? Would the solution proposed in #46592 (comment) work for you? I'd like to explore that option before expanding the audit profile API. |
@tallclair Thanks for your review. I write this pr because of this expression:
It looks like I got it wrong. |
This isn't wrong, per say. I just wanted to discuss alternatives before putting the burden on the user (i.e. adding it to the policy). If we can accomplish the same goals automatically (the batching proposal) then I think that would be preferable. |
Agree. Thanks for teaching me. |
/assign @tallclair |
Closed according to commants from @tallclair and @ericchiang . |
Repopened according to @crassirostris 's commants. This is still WIP, Unit tests will come soon. |
@tallclair suggested earlier that it might be useful to have @sttts @CaoShuFeng WDYT? |
Btw, it should probably should be rebased once #49115 is merged and the changes should go to the beta API |
@@ -528,6 +528,21 @@ func (m *PolicyRule) MarshalTo(dAtA []byte) (int, error) { | |||
i += copy(dAtA[i:], s) | |||
} | |||
} | |||
if len(m.OmitStages) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for the if.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, that's generated proto :)
@@ -723,6 +738,12 @@ func (m *PolicyRule) Size() (n int) { | |||
n += 1 + l + sovGenerated(uint64(l)) | |||
} | |||
} | |||
if len(m.OmitStages) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for the if
} | ||
|
||
type policyChecker struct { | ||
audit.Policy | ||
} | ||
|
||
func (p *policyChecker) Level(attrs authorizer.Attributes) audit.Level { | ||
func (p *policyChecker) Level(attrs authorizer.Attributes) (audit.Level, []audit.Stage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't the level and stages overlap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to LevelAndStages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LevelAndOmitStaged
|
||
// OmitStages specify events generated in which stages will not be emitted to backend | ||
// Allowed stages are RequestReceived,ResponseStarted,ResponseComplete,Panic | ||
// empty list means every events will be emitted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: An empty....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -200,6 +200,11 @@ type PolicyRule struct { | |||
// "/healthz*" - Log all health checks | |||
// +optional | |||
NonResourceURLs []string | |||
|
|||
// OmitStages specify events generated in which stages will not be emitted to backend | |||
// Allowed stages are RequestReceived,ResponseStarted,ResponseComplete,Panic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: fullstop and spaces after ,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it common to relist the constants in those comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it common to relist the constants in those comments?
+1, I don't think it's a great idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
event *auditinternal.Event | ||
once sync.Once | ||
sink audit.Sink | ||
omitStages []auditinternal.Stage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a comment: omitStages are skipped, i.e. not sent to the backend. But their information is still recorded in the context Event for later stages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Some nit. Overall lgtm. |
Sounds good. |
337730a
to
e9a9f6c
Compare
Needs rebase. |
c28fdac
to
db3e05b
Compare
db3e05b
to
41eebcd
Compare
/test pull-kubernetes-e2e-gce-bazel |
/retest |
@@ -42,19 +42,43 @@ func WithAudit(handler http.Handler, requestContextMapper request.RequestContext | |||
return handler | |||
} | |||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | |||
ctx, ev, err := createAuditEventAndAttachToContext(requestContextMapper, req, policy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we return omitStages from createAuditEventAndAttachToContext
? Am not a fan of this code duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this function is removed at all. omitStages
are later obtained from the policy
and not used until the code that was previously outside of createAuditEventAndAttachToContext
. @CaoShuFeng Could you please elaborate more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have took createAuditEventAndAttachToContext
back.
And the codes look cleaner for me, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much better now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. @crassirostris can you take another look and /lgtm if it is ok?
41eebcd
to
aba616e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits regarding the comments, otherwise LGTM
@@ -207,6 +207,10 @@ type PolicyRule struct { | |||
// "/healthz*" - Log all health checks | |||
// +optional | |||
NonResourceURLs []string | |||
|
|||
// OmitStages specify events generated in which stages will not be emitted to backend. | |||
// An empty list means every events will be emitted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that might be confusing. What about An empty list means no restrictions will apply.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -173,6 +179,8 @@ type auditResponseWriter struct { | |||
event *auditinternal.Event | |||
once sync.Once | |||
sink audit.Sink | |||
// omitStages are skipped, i.e. not sent to the backend. But their information is still recorded in the context Event for later stages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omitStages are skipped
Is this comment necessary? once
and sink
are not set to the backend also :) Basically, the only explanation why omitStages
field is there is b/c it's used later
and this description is not very informative. Maybe remove the comment altogether?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good for me.
Deleted.
aba616e
to
9b1e0a9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Updates kubernetes#48561 This provide a way to omit some stages for each audit policy rule. For example: apiVersion: audit.k8s.io/v1beta1 kind: Policy - level: Metadata resources: - group: "rbac.authorization.k8s.io" resources: ["roles"] omitStages: - "RequestReceived" RequestReceived stage will not be emitted to audit backends with previous config.
./hack/update-codegen.sh ./hack/update-generated-protobuf.sh
cd004f4
to
b50acbd
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: CaoShuFeng, crassirostris, sttts Associated issue requirement bypassed by: sttts The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
Automatic merge from submit-queue |
@CaoShuFeng: The following test failed, say
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. |
@@ -207,6 +207,10 @@ type PolicyRule struct { | |||
// "/healthz*" - Log all health checks | |||
// +optional | |||
NonResourceURLs []string | |||
|
|||
// OmitStages specify events generated in which stages will not be emitted to backend. | |||
// An empty list means no restrictions will apply. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we mark this as optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added here together:
#54634
This provide a way to omit some stages for each audit policy rule.
For example:
RequestReceived stage will not be emitted to audit backends with previous config.
Release note: