@@ -18,11 +18,13 @@ package auth
18
18
19
19
import (
20
20
"bufio"
21
+ "encoding/json"
21
22
"fmt"
22
23
"strings"
23
24
24
25
apiv1 "k8s.io/api/core/v1"
25
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
+ "k8s.io/apiserver/pkg/apis/audit/v1beta1"
26
28
"k8s.io/kubernetes/test/e2e/framework"
27
29
28
30
. "github.com/onsi/ginkgo"
@@ -66,10 +68,6 @@ var _ = SIGDescribe("Advanced Audit [Feature:Audit]", func() {
66
68
err = f .ClientSet .Core ().Secrets (f .Namespace .Name ).Delete (secret .Name , & metav1.DeleteOptions {})
67
69
framework .ExpectNoError (err , "failed to delete audit-secret" )
68
70
69
- // /version should not be audited
70
- _ , err = f .ClientSet .Core ().RESTClient ().Get ().AbsPath ("/version" ).DoRaw ()
71
- framework .ExpectNoError (err , "failed to query version" )
72
-
73
71
expectedEvents := []auditEvent {{
74
72
method : "create" ,
75
73
namespace : namespace ,
@@ -126,9 +124,6 @@ func expectAuditLines(f *framework.Framework, expected []auditEvent) {
126
124
if _ , found := expectations [event ]; found {
127
125
expectations [event ] = true
128
126
}
129
-
130
- // /version should not be audited (filtered in the policy).
131
- Expect (event .uri ).NotTo (HavePrefix ("/version" ))
132
127
}
133
128
framework .ExpectNoError (scanner .Err (), "error reading audit log" )
134
129
@@ -138,6 +133,21 @@ func expectAuditLines(f *framework.Framework, expected []auditEvent) {
138
133
}
139
134
140
135
func parseAuditLine (line string ) (auditEvent , error ) {
136
+ var e v1beta1.Event
137
+ if err := json .Unmarshal ([]byte (line ), & e ); err == nil {
138
+ event := auditEvent {
139
+ method : e .Verb ,
140
+ uri : e .RequestURI ,
141
+ }
142
+ if e .ObjectRef != nil {
143
+ event .namespace = e .ObjectRef .Namespace
144
+ }
145
+ if e .ResponseStatus != nil {
146
+ event .response = fmt .Sprintf ("%d" , e .ResponseStatus .Code )
147
+ }
148
+ return event , nil
149
+ }
150
+
141
151
fields := strings .Fields (line )
142
152
if len (fields ) < 3 {
143
153
return auditEvent {}, fmt .Errorf ("could not parse audit line: %s" , line )
0 commit comments