mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 05:21:58 +00:00
Merge pull request #119795 from sttts/sttts-httplog-impersonation
apiserver/httplog: pretty up impersonation output
This commit is contained in:
commit
19f6d5be82
@ -164,7 +164,7 @@ func WithImpersonation(handler http.Handler, a authorizer.Authorizer, s runtime.
|
||||
req = req.WithContext(request.WithUser(ctx, newUser))
|
||||
|
||||
oldUser, _ := request.UserFrom(ctx)
|
||||
httplog.LogOf(req, w).Addf("%v is acting as %v", oldUser, newUser)
|
||||
httplog.LogOf(req, w).Addf("%v is impersonating %v", userString(oldUser), userString(newUser))
|
||||
|
||||
ae := audit.AuditEventFrom(ctx)
|
||||
audit.LogImpersonatedUser(ae, newUser)
|
||||
@ -183,6 +183,24 @@ func WithImpersonation(handler http.Handler, a authorizer.Authorizer, s runtime.
|
||||
})
|
||||
}
|
||||
|
||||
func userString(u user.Info) string {
|
||||
if u == nil {
|
||||
return "<none>"
|
||||
}
|
||||
b := strings.Builder{}
|
||||
if name := u.GetName(); name == "" {
|
||||
b.WriteString("<empty>")
|
||||
} else {
|
||||
b.WriteString(name)
|
||||
}
|
||||
if groups := u.GetGroups(); len(groups) > 0 {
|
||||
b.WriteString("[")
|
||||
b.WriteString(strings.Join(groups, ","))
|
||||
b.WriteString("]")
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func unescapeExtraKey(encodedKey string) string {
|
||||
key, err := url.PathUnescape(encodedKey) // Decode %-encoded bytes.
|
||||
if err != nil {
|
||||
|
@ -205,7 +205,6 @@ func StatusIsNot(statuses ...int) StacktracePred {
|
||||
func (rl *respLogger) Addf(format string, data ...interface{}) {
|
||||
rl.mutex.Lock()
|
||||
defer rl.mutex.Unlock()
|
||||
rl.addedInfo.WriteString("\n")
|
||||
rl.addedInfo.WriteString(fmt.Sprintf(format, data...))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user