Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
503de320
Commit
503de320
authored
Nov 18, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add groups to the audit trail
parent
bc331ad3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
8 deletions
+21
-8
audit.go
pkg/apiserver/filters/audit.go
+20
-7
audit_test.go
pkg/apiserver/filters/audit_test.go
+1
-1
No files found.
pkg/apiserver/filters/audit.go
View file @
503de320
...
...
@@ -96,6 +96,11 @@ func WithAudit(handler http.Handler, attributeGetter RequestAttributeGetter, out
internalError
(
w
,
req
,
err
)
return
}
groups
:=
"<none>"
if
userGroups
:=
attribs
.
GetUser
()
.
GetGroups
();
len
(
userGroups
)
>
0
{
groups
=
auditStringSlice
(
userGroups
)
}
asuser
:=
req
.
Header
.
Get
(
authenticationapi
.
ImpersonateUserHeader
)
if
len
(
asuser
)
==
0
{
asuser
=
"<self>"
...
...
@@ -103,11 +108,7 @@ func WithAudit(handler http.Handler, attributeGetter RequestAttributeGetter, out
asgroups
:=
"<lookup>"
requestedGroups
:=
req
.
Header
[
authenticationapi
.
ImpersonateGroupHeader
]
if
len
(
requestedGroups
)
>
0
{
quotedGroups
:=
make
([]
string
,
len
(
requestedGroups
))
for
i
,
group
:=
range
requestedGroups
{
quotedGroups
[
i
]
=
fmt
.
Sprintf
(
"%q"
,
group
)
}
asgroups
=
strings
.
Join
(
quotedGroups
,
", "
)
asgroups
=
auditStringSlice
(
requestedGroups
)
}
namespace
:=
attribs
.
GetNamespace
()
if
len
(
namespace
)
==
0
{
...
...
@@ -115,8 +116,8 @@ func WithAudit(handler http.Handler, attributeGetter RequestAttributeGetter, out
}
id
:=
uuid
.
NewRandom
()
.
String
()
line
:=
fmt
.
Sprintf
(
"%s AUDIT: id=%q ip=%q method=%q user=%q as=%q asgroups=%q namespace=%q uri=%q
\n
"
,
time
.
Now
()
.
Format
(
time
.
RFC3339Nano
),
id
,
utilnet
.
GetClientIP
(
req
),
req
.
Method
,
attribs
.
GetUser
()
.
GetName
(),
asuser
,
asgroups
,
namespace
,
req
.
URL
)
line
:=
fmt
.
Sprintf
(
"%s AUDIT: id=%q ip=%q method=%q user=%q
groups=%q
as=%q asgroups=%q namespace=%q uri=%q
\n
"
,
time
.
Now
()
.
Format
(
time
.
RFC3339Nano
),
id
,
utilnet
.
GetClientIP
(
req
),
req
.
Method
,
attribs
.
GetUser
()
.
GetName
(),
groups
,
asuser
,
asgroups
,
namespace
,
req
.
URL
)
if
_
,
err
:=
fmt
.
Fprint
(
out
,
line
);
err
!=
nil
{
glog
.
Errorf
(
"Unable to write audit log: %s, the error is: %v"
,
line
,
err
)
}
...
...
@@ -125,6 +126,18 @@ func WithAudit(handler http.Handler, attributeGetter RequestAttributeGetter, out
})
}
func
auditStringSlice
(
inList
[]
string
)
string
{
if
len
(
inList
)
==
0
{
return
""
}
quotedElements
:=
make
([]
string
,
len
(
inList
))
for
i
,
in
:=
range
inList
{
quotedElements
[
i
]
=
fmt
.
Sprintf
(
"%q"
,
in
)
}
return
strings
.
Join
(
quotedElements
,
","
)
}
func
decorateResponseWriter
(
responseWriter
http
.
ResponseWriter
,
out
io
.
Writer
,
id
string
)
http
.
ResponseWriter
{
delegate
:=
&
auditResponseWriter
{
ResponseWriter
:
responseWriter
,
out
:
out
,
id
:
id
}
// check if the ResponseWriter we're wrapping is the fancy one we need
...
...
pkg/apiserver/filters/audit_test.go
View file @
503de320
...
...
@@ -86,7 +86,7 @@ func TestAudit(t *testing.T) {
if
len
(
line
)
!=
2
{
t
.
Fatalf
(
"Unexpected amount of lines in audit log: %d"
,
len
(
line
))
}
match
,
err
:=
regexp
.
MatchString
(
`[\d\:\-\.\+TZ]+ AUDIT: id="[\w-]+" ip="127.0.0.1" method="GET" user="admin" as="<self>" asgroups="<lookup>" namespace="default" uri="/api/v1/namespaces/default/pods"`
,
line
[
0
])
match
,
err
:=
regexp
.
MatchString
(
`[\d\:\-\.\+TZ]+ AUDIT: id="[\w-]+" ip="127.0.0.1" method="GET" user="admin"
groups="<none>"
as="<self>" asgroups="<lookup>" namespace="default" uri="/api/v1/namespaces/default/pods"`
,
line
[
0
])
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error matching first line: %v"
,
err
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment