Skip to content

Commit

Permalink
fix incorrect user and profile in audit logging
Browse files Browse the repository at this point in the history
  • Loading branch information
spowelljr committed Jul 12, 2022
1 parent 5b91e27 commit d89f435
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
43 changes: 23 additions & 20 deletions cmd/minikube/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@ import (
"k8s.io/minikube/pkg/version"
)

var dirs = [...]string{
localpath.MiniPath(),
localpath.MakeMiniPath("certs"),
localpath.MakeMiniPath("machines"),
localpath.MakeMiniPath("cache"),
localpath.MakeMiniPath("config"),
localpath.MakeMiniPath("addons"),
localpath.MakeMiniPath("files"),
localpath.MakeMiniPath("logs"),
}
var (
dirs = [...]string{
localpath.MiniPath(),
localpath.MakeMiniPath("certs"),
localpath.MakeMiniPath("machines"),
localpath.MakeMiniPath("cache"),
localpath.MakeMiniPath("config"),
localpath.MakeMiniPath("addons"),
localpath.MakeMiniPath("files"),
localpath.MakeMiniPath("logs"),
}
auditID string
)

// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Expand All @@ -71,28 +74,28 @@ var RootCmd = &cobra.Command{
out.WarningT("User name '{{.username}}' is not valid", out.V{"username": userName})
exit.Message(reason.Usage, "User name must be 60 chars or less.")
}
var err error
auditID, err = audit.LogCommandStart()
if err != nil {
klog.Errorf("failed to log command start to audit: %v", err)
}
// viper maps $MINIKUBE_ROOTLESS to "rootless" property automatically, but it does not do vice versa,
// so we map "rootless" property to $MINIKUBE_ROOTLESS expliclity here.
// $MINIKUBE_ROOTLESS is referred by KIC runner, which is decoupled from viper.
if viper.GetBool(config.Rootless) {
os.Setenv(constants.MinikubeRootlessEnv, "true")
}
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
if err := audit.LogCommandEnd(auditID); err != nil {
klog.Errorf("failed to log command end to audit: %v", err)
}
},
}

// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
auditID, err := audit.LogCommandStart()
if err != nil {
klog.Errorf("failed to log command start to audit: %v", err)
}
defer func() {
err := audit.LogCommandEnd(auditID)
if err != nil {
klog.Errorf("failed to log command end to audit: %v", err)
}
}()
// Check whether this is a windows binary (.exe) running inisde WSL.
if runtime.GOOS == "windows" && detect.IsMicrosoftWSL() {
var found = false
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func args() string {

// Log details about the executed command.
func LogCommandStart() (string, error) {
if len(os.Args) < 2 || !shouldLog() {
if !shouldLog() {
return "", nil
}
id := uuid.New().String()
Expand Down

0 comments on commit d89f435

Please sign in to comment.