Skip to content

Commit 23c33e7

Browse files
DmitriyMVUnix4ever
authored andcommitted
chore: do not audit log GET requests to k8s
Since we do not audit log read-like requests, I think it makes sense to do the same here. Signed-off-by: Dmitriy Matrenichev <[email protected]> (cherry picked from commit c904e3a)
1 parent 5d0c81a commit 23c33e7

File tree

4 files changed

+5
-31
lines changed

4 files changed

+5
-31
lines changed

go.work

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
go 1.23.0
1+
go 1.23.2
22

33
use (
44
.

internal/backend/k8sproxy/middleware.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ func AuthorizeRequest(next http.Handler, keyFunc KeyProvider, clusterUUIDResolve
129129
Session: req.Header.Get("Kubectl-Session"),
130130
ClusterName: clusterName,
131131
ClusterUUID: clusterUUID,
132-
Body: "",
133132
},
134133
Session: audit.Session{
135134
UserAgent: req.Header.Get("User-Agent"),

internal/backend/runtime/omni/audit/audit.go

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package audit
88

99
import (
10-
"bytes"
1110
"context"
1211
"errors"
1312
"fmt"
@@ -124,21 +123,15 @@ func (l *Log) AuditTalosAccess(ctx context.Context, fullMethodName string, clust
124123
// Wrap wraps the http.Handler with audit logging.
125124
func (l *Log) Wrap(next http.Handler) http.Handler {
126125
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
127-
clonedReq := req.Clone(req.Context())
128-
129-
strData, body, err := duplicateReadCloser(req.Body)
130-
if err != nil {
131-
l.logger.Error("failed to clone request body", zap.Error(err))
126+
if req.Method == http.MethodGet || req.Method == http.MethodHead || req.Method == http.MethodOptions {
132127
next.ServeHTTP(w, req)
133128

134129
return
135130
}
136131

137-
clonedReq.Body = body
138-
139132
data, ok := ctxstore.Value[*Data](req.Context())
140133
if !ok {
141-
next.ServeHTTP(w, clonedReq)
134+
next.ServeHTTP(w, req)
142135

143136
return
144137
}
@@ -147,9 +140,7 @@ func (l *Log) Wrap(next http.Handler) http.Handler {
147140
data.K8SAccess = &K8SAccess{}
148141
}
149142

150-
data.K8SAccess.Body = strData
151-
152-
err = l.logFile.Dump(event{
143+
err := l.logFile.Dump(event{
153144
Type: "k8s_access",
154145
Time: time.Now().UnixMilli(),
155146
Data: data,
@@ -158,7 +149,7 @@ func (l *Log) Wrap(next http.Handler) http.Handler {
158149
l.logger.Error("failed to write audit log", zap.Error(err))
159150
}
160151

161-
next.ServeHTTP(w, clonedReq)
152+
next.ServeHTTP(w, req)
162153
})
163154
}
164155

@@ -181,21 +172,6 @@ func (l *Log) RunCleanup(ctx context.Context) error {
181172
}
182173
}
183174

184-
func duplicateReadCloser(body io.ReadCloser) (string, io.ReadCloser, error) {
185-
if body == nil {
186-
return "", nil, nil
187-
}
188-
189-
var buf bytes.Buffer
190-
191-
_, err := buf.ReadFrom(body)
192-
if err != nil {
193-
return "", nil, err
194-
}
195-
196-
return buf.String(), io.NopCloser(&buf), nil
197-
}
198-
199175
type (
200176
// CreateHook is a hook for specific type resource creation.
201177
CreateHook = func(ctx context.Context, res resource.Resource, option ...state.CreateOption) error

internal/backend/runtime/omni/audit/data.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ type TalosAccess struct {
122122
type K8SAccess struct {
123123
FullMethodName string `json:"full_method_name,omitempty"`
124124
Command string `json:"command,omitempty"`
125-
Body string `json:"body,omitempty"`
126125
Session string `json:"kube_session,omitempty"`
127126
ClusterName string `json:"cluster_name,omitempty"`
128127
ClusterUUID string `json:"cluster_uuid,omitempty"`

0 commit comments

Comments
 (0)