Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect user and profile in audit logging #14562

Merged
merged 1 commit into from
Jul 12, 2022

Conversation

spowelljr
Copy link
Member

@spowelljr spowelljr commented Jul 12, 2022

  1. Fixed minikube home directory not existing before trying to write to audit log (first use or after --purge)

Before (throws error about directory not existing):

$ minikube stop
E0712 11:43:34.803850   47538 root.go:88] failed to log command start to audit: failed to open the audit log: open /Users/powellsteven/.minikube/logs/audit.json: no such file or directory
🤷  Profile "minikube" not found. Run "minikube profile list" to view all profiles.
👉  To start a cluster, run: "minikube start"

After:

$ minikube stop
🤷  Profile "minikube" not found. Run "minikube profile list" to view all profiles.
👉  To start a cluster, run: "minikube start"
  1. Fixed trying to update audit log after --purge

Before (throws error about directory not existing):

$ minikube delete --all --purge
💀  Removed all traces of the "p5" cluster.
🔥  Successfully deleted all profiles
💀  Successfully purged minikube directory located at - [/Users/powellsteven/.minikube]
E0712 11:43:31.110111   47526 root.go:93] failed to log command end to audit: failed to open the audit log: open /Users/powellsteven/.minikube/logs/audit.json: no such file or directory

After:

$ minikube delete --all --purge
💀  Removed all traces of the "p5" cluster.
🔥  Successfully deleted all profiles
💀  Successfully purged minikube directory located at - [/Users/powellsteven/.minikube]
  1. Fixed audit log not logging the correct profile and user

Before (profile logged as minikube instead p5 & user logged as powellsteven instead of cloud-code:

$ minikube stop -p p5 --user cloud-code
...
$ minikube logs --audit

==> Audit <==
|---------|-------------------------|----------|--------------|---------|---------------------|----------|
| Command |          Args           | Profile  |     User     | Version |     Start Time      | End Time |
|---------|-------------------------|----------|--------------|---------|---------------------|----------|
| stop    | -p p5 --user cloud-code | minikube | powellsteven | v1.26.0 | 12 Jul 22 11:52 PDT |          |
|---------|-------------------------|----------|--------------|---------|---------------------|----------|

After:

$ minikube stop -p p5 --user cloud-code
...
$ minikube logs --audit

==> Audit <==
|---------|-------------------------|---------|------------|---------|---------------------|----------|
| Command |          Args           | Profile |    User    | Version |     Start Time      | End Time |
|---------|-------------------------|---------|------------|---------|---------------------|----------|
| stop    | -p p5 --user cloud-code | p5      | cloud-code | v1.26.0 | 12 Jul 22 11:51 PDT |          |
|---------|-------------------------|---------|------------|---------|---------------------|----------|

The root of the audit logging problem is that before #13307 we would add the audit entry after the command ended. But with #13307 we are now adding the audit entry before the command is executed, and before the flags are even parsed, so the user and profile flags were defaulting to default values. So moved the audit logging after the flags are parsed, resulting in the correct values. Also moved to after the minikube directory is created preventing the minikube home directory not existing errors.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 12, 2022
@@ -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() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, the arg length check was previously moved into shouldLog() this is a leftover check.

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 12, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: medyagh, spowelljr

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@spowelljr spowelljr merged commit b86de18 into kubernetes:master Jul 12, 2022
@spowelljr spowelljr deleted the fixAuditLogging branch July 12, 2022 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants