@@ -18,6 +18,7 @@ package main
1818
1919import (
2020 "context"
21+ "embed"
2122 "fmt"
2223 "io"
2324 "net"
@@ -44,6 +45,9 @@ import (
4445 "github.com/kcp-dev/kcp/test/e2e/framework"
4546)
4647
48+ //go:embed *.yaml
49+ var embeddedResources embed.FS
50+
4751type headWriter interface {
4852 io.Writer
4953 StopOut ()
@@ -128,7 +132,17 @@ func newVirtualWorkspace(ctx context.Context, index int, servingCA *crypto.CA, h
128132 authenticationKubeconfigPath := filepath .Join (workDirPath , fmt .Sprintf (".kcp-%d" , index ), "admin.kubeconfig" )
129133 clientCAFilePath := filepath .Join (workDirPath , ".kcp" , "client-ca.crt" )
130134
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
132146 args = append (args ,
133147 fmt .Sprintf ("--kubeconfig=%s" , kubeconfigPath ),
134148 fmt .Sprintf ("--cache-kubeconfig=%s" , cacheServerConfigPath ),
@@ -137,6 +151,15 @@ func newVirtualWorkspace(ctx context.Context, index int, servingCA *crypto.CA, h
137151 fmt .Sprintf ("--tls-private-key-file=%s" , servingKeyFile ),
138152 fmt .Sprintf ("--tls-cert-file=%s" , servingCertFile ),
139153 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 ),
140163 )
141164
142165 return & VirtualWorkspace {
@@ -155,6 +178,13 @@ func (v *VirtualWorkspace) start(ctx context.Context) error {
155178 lineprefix .Color (color .New (color .FgHiYellow )),
156179 )
157180
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+
158188 commandLine := framework .DirectOrGoRunCommand ("virtual-workspaces" )
159189 commandLine = append (commandLine , v .args ... )
160190 commandLine = append (
@@ -164,16 +194,12 @@ func (v *VirtualWorkspace) start(ctx context.Context) error {
164194 "--requestheader-group-headers=X-Remote-Group" ,
165195 fmt .Sprintf ("--requestheader-client-ca-file=%s" , filepath .Join (v .workDirPath , ".kcp/requestheader-ca.crt" )),
166196 "--v=4" ,
197+ "--audit-log-path" , auditFilePath ,
167198 )
168199 fmt .Fprintf (out , "running: %v\n " , strings .Join (commandLine , " " ))
169200
170201 cmd := exec .CommandContext (ctx , commandLine [0 ], commandLine [1 :]... ) //nolint:gosec
171202
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-
177203 if err := os .MkdirAll (filepath .Dir (logFilePath ), 0755 ); err != nil {
178204 return err
179205 }
0 commit comments