Skip to content

Commit

Permalink
Add new --allow-repo-config flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkysow committed Jun 30, 2018
1 parent f29dc00 commit 13a70c7
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 25 deletions.
15 changes: 12 additions & 3 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ import (
// 3. Add your flag's description etc. to the stringFlags, intFlags, or boolFlags slices.
const (
// Flag names.
AtlantisURLFlag = "atlantis-url"
AllowForkPRsFlag = "allow-fork-prs"
AllowRepoConfigFlag = "allow-repo-config"
AtlantisURLFlag = "atlantis-url"
ConfigFlag = "config"
DataDirFlag = "data-dir"
GHHostnameFlag = "gh-hostname"
Expand Down Expand Up @@ -142,6 +143,13 @@ var boolFlags = []boolFlag{
description: "Allow Atlantis to run on pull requests from forks. A security issue for public repos.",
defaultValue: false,
},
{
name: AllowRepoConfigFlag,
description: "Allow repositories to use atlantis.yaml files to customize the commands Atlantis runs." +
" Should only be enabled in a trusted environment since it enables a pull request to run arbitrary commands" +
" on the Atlantis server.",
defaultValue: false,
},
{
name: RequireApprovalFlag,
description: "Require pull requests to be \"Approved\" before allowing the apply command to be run.",
Expand Down Expand Up @@ -298,8 +306,9 @@ func (s *ServerCmd) run() error {

// Config looks good. Start the server.
server, err := s.ServerCreator.NewServer(userConfig, server.Config{
AllowForkPRsFlag: AllowForkPRsFlag,
AtlantisVersion: s.AtlantisVersion,
AllowForkPRsFlag: AllowForkPRsFlag,
AllowRepoConfigFlag: AllowRepoConfigFlag,
AtlantisVersion: s.AtlantisVersion,
})
if err != nil {
return errors.Wrap(err, "initializing server")
Expand Down
4 changes: 4 additions & 0 deletions runatlantis.io/docs/atlantis-yaml-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
See [www.runatlantis.io/guide/atlantis-yaml-use-cases.html](../guide/atlantis-yaml-use-cases.html)
:::

## Enabling atlantis.yaml
The atlantis server must be running with `--allow-repo-config` to allow Atlantis
to use `atlantis.yaml` files.

## Example Using All Keys
```yaml
version: 2
Expand Down
2 changes: 1 addition & 1 deletion scripts/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ${CIRCLE_WORKING_DIRECTORY}/scripts/e2e-deps.sh
cd "${CIRCLE_WORKING_DIRECTORY}/e2e"

# start atlantis server in the background and wait for it to start
./atlantis server --gh-user="$GITHUB_USERNAME" --gh-token="$GITHUB_PASSWORD" --data-dir="/tmp" --log-level="debug" --repo-whitelist="github.com/runatlantis/atlantis-tests" &> /tmp/atlantis-server.log &
./atlantis server --gh-user="$GITHUB_USERNAME" --gh-token="$GITHUB_PASSWORD" --data-dir="/tmp" --log-level="debug" --repo-whitelist="github.com/runatlantis/atlantis-tests" --allow-repo-config &> /tmp/atlantis-server.log &
sleep 2

# start ngrok in the background and wait for it to start
Expand Down
1 change: 0 additions & 1 deletion server/events/command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var githubGetter *mocks.MockGithubPullGetter
var gitlabGetter *mocks.MockGitlabMergeRequestGetter
var ch events.DefaultCommandRunner
var logBytes *bytes.Buffer
var projectCommandRunner *mocks.MockProjectCommandRunner

func setup(t *testing.T) {
RegisterMockTestingT(t)
Expand Down
20 changes: 14 additions & 6 deletions server/events/project_command_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ type ProjectCommandBuilder interface {
}

type DefaultProjectCommandBuilder struct {
ParserValidator *yaml.ParserValidator
ProjectFinder ProjectFinder
VCSClient vcs.ClientProxy
WorkingDir WorkingDir
WorkingDirLocker WorkingDirLocker
RequireApproval bool
ParserValidator *yaml.ParserValidator
ProjectFinder ProjectFinder
VCSClient vcs.ClientProxy
WorkingDir WorkingDir
WorkingDirLocker WorkingDirLocker
RequireApproval bool
AllowRepoConfig bool
AllowRepoConfigFlag string
}

type TerraformExec interface {
Expand Down Expand Up @@ -63,6 +65,9 @@ func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *CommandContext
ctx.Log.Info("found no %s file", yaml.AtlantisYAMLFilename)
} else {
ctx.Log.Info("successfully parsed %s file", yaml.AtlantisYAMLFilename)
if !p.AllowRepoConfig {
return nil, fmt.Errorf("%s files not allowed because Atlantis is not running with --%s", yaml.AtlantisYAMLFilename, p.AllowRepoConfigFlag)
}
}

// We'll need the list of modified files.
Expand Down Expand Up @@ -201,6 +206,9 @@ func (p *DefaultProjectCommandBuilder) getCfg(projectName string, dir string, wo
if !hasAtlantisYAML {
return nil, nil, nil
}
if !p.AllowRepoConfig {
return nil, nil, fmt.Errorf("%s files not allowed because Atlantis is not running with --%s", yaml.AtlantisYAMLFilename, p.AllowRepoConfigFlag)
}

// If they've specified a project by name we look it up. Otherwise we
// use the dir and workspace.
Expand Down
2 changes: 2 additions & 0 deletions server/events/project_command_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ projects:
ParserValidator: &yaml.ParserValidator{},
VCSClient: vcsClient,
ProjectFinder: &events.DefaultProjectFinder{},
AllowRepoConfig: true,
}

ctxs, err := builder.BuildAutoplanCommands(&events.CommandContext{
Expand Down Expand Up @@ -416,6 +417,7 @@ projects:
ParserValidator: &yaml.ParserValidator{},
VCSClient: vcsClient,
ProjectFinder: &events.DefaultProjectFinder{},
AllowRepoConfig: true,
}

cmdCtx := &events.CommandContext{
Expand Down
1 change: 0 additions & 1 deletion server/events/terraform/terraform_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type DefaultClient struct {
const terraformPluginCacheDirName = "plugin-cache"

// zeroPointNine constrains the version to be 0.9.*
var zeroPointNine = MustConstraint(">=0.9,<0.10")
var versionRegex = regexp.MustCompile("Terraform v(.*)\n")

func NewClient(dataDir string) (*DefaultClient, error) {
Expand Down
13 changes: 8 additions & 5 deletions server/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,14 @@ func setupE2E(t *testing.T) (server.EventsController, *vcsmocks.MockClientProxy,
AllowForkPRs: allowForkPRs,
AllowForkPRsFlag: "allow-fork-prs",
ProjectCommandBuilder: &events.DefaultProjectCommandBuilder{
ParserValidator: &yaml.ParserValidator{},
ProjectFinder: &events.DefaultProjectFinder{},
VCSClient: e2eVCSClient,
WorkingDir: workingDir,
WorkingDirLocker: locker,
ParserValidator: &yaml.ParserValidator{},
ProjectFinder: &events.DefaultProjectFinder{},
VCSClient: e2eVCSClient,
WorkingDir: workingDir,
WorkingDirLocker: locker,
AllowRepoConfigFlag: "allow-repo-config",
AllowRepoConfig: true,
RequireApproval: false,
},
}

Expand Down
20 changes: 12 additions & 8 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type Server struct {
// the config is parsed from a YAML file.
type UserConfig struct {
AllowForkPRs bool `mapstructure:"allow-fork-prs"`
AllowRepoConfig bool `mapstructure:"allow-repo-config"`
AtlantisURL string `mapstructure:"atlantis-url"`
DataDir string `mapstructure:"data-dir"`
GithubHostname string `mapstructure:"gh-hostname"`
Expand All @@ -104,8 +105,9 @@ type UserConfig struct {

// Config holds config for server that isn't passed in by the user.
type Config struct {
AllowForkPRsFlag string
AtlantisVersion string
AllowForkPRsFlag string
AllowRepoConfigFlag string
AtlantisVersion string
}

// WebhookConfig is nested within UserConfig. It's used to configure webhooks.
Expand Down Expand Up @@ -232,12 +234,14 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
AllowForkPRs: userConfig.AllowForkPRs,
AllowForkPRsFlag: config.AllowForkPRsFlag,
ProjectCommandBuilder: &events.DefaultProjectCommandBuilder{
ParserValidator: &yaml.ParserValidator{},
ProjectFinder: &events.DefaultProjectFinder{},
VCSClient: vcsClient,
WorkingDir: workingDir,
WorkingDirLocker: workingDirLocker,
RequireApproval: userConfig.RequireApproval,
ParserValidator: &yaml.ParserValidator{},
ProjectFinder: &events.DefaultProjectFinder{},
VCSClient: vcsClient,
WorkingDir: workingDir,
WorkingDirLocker: workingDirLocker,
RequireApproval: userConfig.RequireApproval,
AllowRepoConfig: userConfig.AllowRepoConfig,
AllowRepoConfigFlag: config.AllowRepoConfigFlag,
},
ProjectCommandRunner: &events.DefaultProjectCommandRunner{
Locker: projectLocker,
Expand Down

0 comments on commit 13a70c7

Please sign in to comment.