@@ -18,6 +18,7 @@ package main
18
18
19
19
import (
20
20
"context"
21
+ "embed"
21
22
"fmt"
22
23
"io"
23
24
"net"
@@ -44,6 +45,9 @@ import (
44
45
"github.com/kcp-dev/kcp/test/e2e/framework"
45
46
)
46
47
48
+ //go:embed *.yaml
49
+ var embeddedResources embed.FS
50
+
47
51
type headWriter interface {
48
52
io.Writer
49
53
StopOut ()
@@ -128,7 +132,17 @@ func newVirtualWorkspace(ctx context.Context, index int, servingCA *crypto.CA, h
128
132
authenticationKubeconfigPath := filepath .Join (workDirPath , fmt .Sprintf (".kcp-%d" , index ), "admin.kubeconfig" )
129
133
clientCAFilePath := filepath .Join (workDirPath , ".kcp" , "client-ca.crt" )
130
134
131
- args := []string {}
135
+ // write audit policy
136
+ bs , err := embeddedResources .ReadFile ("audit-policy.yaml" )
137
+ if err != nil {
138
+ return nil , err
139
+ }
140
+ auditPolicyFile := filepath .Join (workDirPath , fmt .Sprintf (".kcp-virtual-workspaces-%d" , index ), "audit-policy.yaml" )
141
+ if err := os .WriteFile (auditPolicyFile , bs , 0644 ); err != nil {
142
+ return nil , err
143
+ }
144
+
145
+ var args []string
132
146
args = append (args ,
133
147
fmt .Sprintf ("--kubeconfig=%s" , kubeconfigPath ),
134
148
fmt .Sprintf ("--cache-kubeconfig=%s" , cacheServerConfigPath ),
@@ -137,6 +151,15 @@ func newVirtualWorkspace(ctx context.Context, index int, servingCA *crypto.CA, h
137
151
fmt .Sprintf ("--tls-private-key-file=%s" , servingKeyFile ),
138
152
fmt .Sprintf ("--tls-cert-file=%s" , servingCertFile ),
139
153
fmt .Sprintf ("--secure-port=%s" , virtualWorkspacePort (index )),
154
+ "--audit-log-maxsize=1024" ,
155
+ "--audit-log-mode=batch" ,
156
+ "--audit-log-batch-max-wait=1s" ,
157
+ "--audit-log-batch-max-size=1000" ,
158
+ "--audit-log-batch-buffer-size=10000" ,
159
+ "--audit-log-batch-throttle-burst=15" ,
160
+ "--audit-log-batch-throttle-enable=true" ,
161
+ "--audit-log-batch-throttle-qps=10" ,
162
+ fmt .Sprintf ("--audit-policy-file=%s" , auditPolicyFile ),
140
163
)
141
164
142
165
return & VirtualWorkspace {
@@ -155,6 +178,13 @@ func (v *VirtualWorkspace) start(ctx context.Context) error {
155
178
lineprefix .Color (color .New (color .FgHiYellow )),
156
179
)
157
180
181
+ logFilePath := filepath .Join (v .workDirPath , fmt .Sprintf (".kcp-virtual-workspaces-%d/virtualworkspace.log" , v .index ))
182
+ auditFilePath := filepath .Join (v .workDirPath , fmt .Sprintf (".kcp-virtual-workspaces-%d" , v .index ), "audit.log" )
183
+ if v .logDirPath != "" {
184
+ logFilePath = filepath .Join (v .logDirPath , fmt .Sprintf ("kcp-virtual-workspaces-%d.log" , v .index ))
185
+ auditFilePath = filepath .Join (v .logDirPath , fmt .Sprintf ("kcp-virtual-workspaces-%d-audit.log" , v .index ))
186
+ }
187
+
158
188
commandLine := framework .DirectOrGoRunCommand ("virtual-workspaces" )
159
189
commandLine = append (commandLine , v .args ... )
160
190
commandLine = append (
@@ -164,16 +194,12 @@ func (v *VirtualWorkspace) start(ctx context.Context) error {
164
194
"--requestheader-group-headers=X-Remote-Group" ,
165
195
fmt .Sprintf ("--requestheader-client-ca-file=%s" , filepath .Join (v .workDirPath , ".kcp/requestheader-ca.crt" )),
166
196
"--v=4" ,
197
+ "--audit-log-path" , auditFilePath ,
167
198
)
168
199
fmt .Fprintf (out , "running: %v\n " , strings .Join (commandLine , " " ))
169
200
170
201
cmd := exec .CommandContext (ctx , commandLine [0 ], commandLine [1 :]... ) //nolint:gosec
171
202
172
- logFilePath := filepath .Join (v .workDirPath , fmt .Sprintf (".kcp-virtual-workspaces-%d/virtualworkspace.log" , v .index ))
173
- if v .logDirPath != "" {
174
- logFilePath = filepath .Join (v .logDirPath , fmt .Sprintf ("kcp-virtual-workspaces-%d.log" , v .index ))
175
- }
176
-
177
203
if err := os .MkdirAll (filepath .Dir (logFilePath ), 0755 ); err != nil {
178
204
return err
179
205
}
0 commit comments