-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
Return Audit-Id http response header for trouble shooting #49377
Return Audit-Id http response header for trouble shooting #49377
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. |
auditID string | ||
handler func(http.ResponseWriter, *http.Request) | ||
expected []auditv1alpha1.Event | ||
respHeader bool |
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.
Because some test cases don't call http.ResponseWriter.WriteHeader() function. So we can't check the response http header for them.
/ok-to-test |
@crassirostris |
@CaoShuFeng Is it possible to set a header before hijacking? |
|
||
func (a *auditResponseWriter) setHttpHeader() { | ||
a.headerOnce.Do(func() { | ||
a.ResponseWriter.Header().Set(auditinternal.HeaderAuditID, string(a.event.AuditID)) |
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.
isn't there a way to override the header if it already exists? a sync.Once
seems to be overkill.
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.
Set has this behavior already, but it's not thread-safe, if it's applicable here
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.
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.
In the handler code we assume that only one thread/go-routine accesses the writer. So thread-safety should not matter here.
87d7d72
to
b62aa09
Compare
@@ -204,6 +213,10 @@ func (f *fancyResponseWriterDelegator) Flush() { | |||
func (f *fancyResponseWriterDelegator) Hijack() (net.Conn, *bufio.ReadWriter, error) { | |||
// fake a response status before protocol switch happens | |||
f.processCode(http.StatusSwitchingProtocols) | |||
|
|||
// TODO(caoshufeng): we can't call WriteHeader before Hijack(), because WriteHeader may be called later: |
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.
@sttts What do you think about that? Should it be a TODO or is it working as intended and we shouldn't send audit-id for hijack'd requests?
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.
Do we want to call WriteHeader (which is writing the code) or do we want only to add a header? The later is possible as long as WriteHeader
was not called.
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.
The latter, but @CaoShuFeng says it doesn't work, b/c in case of proxying request the headers are sent by the kubelet and not the apiserver
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.
But then we don't have a chance in that case. But setting the header won't harm, it's just ignored. @CaoShuFeng is that correct?
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.
Agree, a header should be set and then a comment should be added that it's ignored in certain cases
Also, I think it's worth mentioning in the release notes that Audit-Id http header is not set for some requests (and describe in short for which)
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.
But setting the header won't harm, it's just ignored. @CaoShuFeng is that correct?
Yes I tested that.
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.
Agree, a header should be set and then a comment should be added that it's ignored in certain cases
Also, I think it's worth mentioning in the release notes that Audit-Id http header is not set for some requests (and describe in short for which)
+1
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.
b62aa09
to
0e2aca0
Compare
This is great. Probably want to update the HeaderAuditID docstring too.
|
0e2aca0
to
4a1e7dd
Compare
Done |
@CaoShuFeng Thanks! Though I think it's better to keep the release notes short + one line. Usually separate lines in the release notes mean several independent changes I suggest smth like
|
Done |
SGTM, thanks! @sttts Needs your approval now |
/approve no-issue |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: CaoShuFeng, 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 (batch tested with PRs 49868, 50143, 49377, 50141, 50145) |
Users can use Audit-Id http response header to grep the audit events in log.
This provides a fast way to find the events in audit.
Release note:
@sttts @tallclair