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 10 commits into
base: main
Choose a base branch
from
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' teams '%s' does not have permissions to execute '%s' command", user.Username, user.Teams, cmdName)
chadinwork marked this conversation as resolved.
Show resolved Hide resolved
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.Info("command '%s' error '%s'", cmd, err)
chadinwork marked this conversation as resolved.
Show resolved Hide resolved
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.Info("command '%s' error '%s'", cmd, err)
chadinwork marked this conversation as resolved.
Show resolved Hide resolved
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
Loading