mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-06 11:42:14 +00:00
Ensure the dir of --audit-log-path exists
Signed-off-by: Vladimir Nachev <vladimir.nachev@sap.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -525,6 +526,9 @@ func (o *AuditLogOptions) getWriter() (io.Writer, error) {
|
||||
}
|
||||
|
||||
func (o *AuditLogOptions) ensureLogFile() error {
|
||||
if err := os.MkdirAll(filepath.Dir(o.Path), 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
mode := os.FileMode(0600)
|
||||
f, err := os.OpenFile(o.Path, os.O_CREATE|os.O_APPEND|os.O_RDWR, mode)
|
||||
if err != nil {
|
||||
|
@@ -69,6 +69,15 @@ func TestAuditValidOptions(t *testing.T) {
|
||||
return o
|
||||
},
|
||||
expected: "ignoreErrors<log>",
|
||||
}, {
|
||||
name: "create audit log path dir",
|
||||
options: func() *AuditOptions {
|
||||
o := NewAuditOptions()
|
||||
o.LogOptions.Path = filepath.Join(tmpDir, "non-existing-dir1", "non-existing-dir2", "audit")
|
||||
o.PolicyFile = policy
|
||||
return o
|
||||
},
|
||||
expected: "ignoreErrors<log>",
|
||||
}, {
|
||||
name: "default log no policy",
|
||||
options: func() *AuditOptions {
|
||||
|
Reference in New Issue
Block a user