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

chore: log permissions external command #5027

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/events/command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func (c *DefaultCommandRunner) checkUserPermissions(repo models.Repo, user model
}
ok := c.TeamAllowlistChecker.IsCommandAllowedForAnyTeam(ctx, user.Teams, cmdName)
if !ok {
ctx.Log.Info("User '%s' in team '%s' does not have permissions to execute the '%s' command", user.Username, user.Teams, cmdName)
return false, nil
}
return true, nil
Expand Down
16 changes: 14 additions & 2 deletions server/events/external_team_allowlist_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,32 @@ func (checker *ExternalTeamAllowlistChecker) IsCommandAllowedForTeam(ctx models.
cmd := checker.buildCommandString(ctx, []string{team}, command)
out, err := checker.ExternalTeamAllowlistRunner.Run(ctx, "sh", "-c", cmd)
if err != nil {
ctx.Log.Err("Command '%s' error '%s'", cmd, err)
return false
}

return checker.checkOutputResults(out)
outputResults := checker.checkOutputResults(out)
if !outputResults {
ctx.Log.Info("command '%s' returns '%s'", cmd, out)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not convinced that these should be Info messages. I think Debug would be better, so they only display when an Atlantis command is run with the -verbose flag . Same below.

Your examples in the description aren't useful, as they are made up. Please can you provide real world usage messages.

}

return outputResults
}

func (checker *ExternalTeamAllowlistChecker) IsCommandAllowedForAnyTeam(ctx models.TeamAllowlistCheckerContext, teams []string, command string) bool {
cmd := checker.buildCommandString(ctx, teams, command)
out, err := checker.ExternalTeamAllowlistRunner.Run(ctx, "sh", "-c", cmd)
if err != nil {
ctx.Log.Err("Command '%s' error '%s'", cmd, err)
return false
}

return checker.checkOutputResults(out)
outputResults := checker.checkOutputResults(out)
if !outputResults {
ctx.Log.Info("command '%s' returns '%s'", cmd, out)
}

return outputResults
}

func (checker *ExternalTeamAllowlistChecker) buildCommandString(ctx models.TeamAllowlistCheckerContext, teams []string, command string) string {
Expand Down