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
5873c267
Commit
5873c267
authored
Sep 21, 2016
by
Maciej Szulik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove closing audit log file and add error check when writing to audit
parent
d17c6b90
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
4 deletions
+11
-4
audit.go
pkg/apiserver/audit/audit.go
+10
-2
config.go
pkg/genericapiserver/config.go
+1
-2
No files found.
pkg/apiserver/audit/audit.go
View file @
5873c267
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"net/http"
"net/http"
"time"
"time"
"github.com/golang/glog"
"github.com/pborman/uuid"
"github.com/pborman/uuid"
"k8s.io/kubernetes/pkg/apiserver"
"k8s.io/kubernetes/pkg/apiserver"
...
@@ -39,7 +40,11 @@ type auditResponseWriter struct {
...
@@ -39,7 +40,11 @@ type auditResponseWriter struct {
}
}
func
(
a
*
auditResponseWriter
)
WriteHeader
(
code
int
)
{
func
(
a
*
auditResponseWriter
)
WriteHeader
(
code
int
)
{
fmt
.
Fprintf
(
a
.
out
,
"%s AUDIT: id=%q response=
\"
%d
\"\n
"
,
time
.
Now
()
.
Format
(
time
.
RFC3339Nano
),
a
.
id
,
code
)
line
:=
fmt
.
Sprintf
(
"%s AUDIT: id=%q response=
\"
%d
\"\n
"
,
time
.
Now
()
.
Format
(
time
.
RFC3339Nano
),
a
.
id
,
code
)
if
_
,
err
:=
fmt
.
Fprint
(
a
.
out
,
line
);
err
!=
nil
{
glog
.
Errorf
(
"Unable to write audit log: %s, the error is: %v"
,
line
,
err
)
}
a
.
ResponseWriter
.
WriteHeader
(
code
)
a
.
ResponseWriter
.
WriteHeader
(
code
)
}
}
...
@@ -92,8 +97,11 @@ func WithAudit(handler http.Handler, attributeGetter apiserver.RequestAttributeG
...
@@ -92,8 +97,11 @@ func WithAudit(handler http.Handler, attributeGetter apiserver.RequestAttributeG
}
}
id
:=
uuid
.
NewRandom
()
.
String
()
id
:=
uuid
.
NewRandom
()
.
String
()
fmt
.
Fprintf
(
out
,
"%s AUDIT: id=%q ip=%q method=%q user=%q as=%q namespace=%q uri=%q
\n
"
,
line
:=
fmt
.
Sprintf
(
"%s AUDIT: id=%q ip=%q method=%q user=%q as=%q namespace=%q uri=%q
\n
"
,
time
.
Now
()
.
Format
(
time
.
RFC3339Nano
),
id
,
utilnet
.
GetClientIP
(
req
),
req
.
Method
,
attribs
.
GetUser
()
.
GetName
(),
asuser
,
namespace
,
req
.
URL
)
time
.
Now
()
.
Format
(
time
.
RFC3339Nano
),
id
,
utilnet
.
GetClientIP
(
req
),
req
.
Method
,
attribs
.
GetUser
()
.
GetName
(),
asuser
,
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
)
}
respWriter
:=
decorateResponseWriter
(
w
,
out
,
id
)
respWriter
:=
decorateResponseWriter
(
w
,
out
,
id
)
handler
.
ServeHTTP
(
respWriter
,
req
)
handler
.
ServeHTTP
(
respWriter
,
req
)
})
})
...
...
pkg/genericapiserver/config.go
View file @
5873c267
...
@@ -377,6 +377,7 @@ func (c Config) New() (*GenericAPIServer, error) {
...
@@ -377,6 +377,7 @@ func (c Config) New() (*GenericAPIServer, error) {
attributeGetter
:=
apiserver
.
NewRequestAttributeGetter
(
c
.
RequestContextMapper
,
s
.
NewRequestInfoResolver
())
attributeGetter
:=
apiserver
.
NewRequestAttributeGetter
(
c
.
RequestContextMapper
,
s
.
NewRequestInfoResolver
())
handler
=
apiserver
.
WithAuthorizationCheck
(
handler
,
attributeGetter
,
c
.
Authorizer
)
handler
=
apiserver
.
WithAuthorizationCheck
(
handler
,
attributeGetter
,
c
.
Authorizer
)
handler
=
apiserver
.
WithImpersonation
(
handler
,
c
.
RequestContextMapper
,
c
.
Authorizer
)
if
len
(
c
.
AuditLogPath
)
!=
0
{
if
len
(
c
.
AuditLogPath
)
!=
0
{
// audit handler must comes before the impersonationFilter to read the original user
// audit handler must comes before the impersonationFilter to read the original user
writer
:=
&
lumberjack
.
Logger
{
writer
:=
&
lumberjack
.
Logger
{
...
@@ -386,9 +387,7 @@ func (c Config) New() (*GenericAPIServer, error) {
...
@@ -386,9 +387,7 @@ func (c Config) New() (*GenericAPIServer, error) {
MaxSize
:
c
.
AuditLogMaxSize
,
MaxSize
:
c
.
AuditLogMaxSize
,
}
}
handler
=
audit
.
WithAudit
(
handler
,
attributeGetter
,
writer
)
handler
=
audit
.
WithAudit
(
handler
,
attributeGetter
,
writer
)
defer
writer
.
Close
()
}
}
handler
=
apiserver
.
WithImpersonation
(
handler
,
c
.
RequestContextMapper
,
c
.
Authorizer
)
// Install Authenticator
// Install Authenticator
if
c
.
Authenticator
!=
nil
{
if
c
.
Authenticator
!=
nil
{
...
...
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