Skip to content

Commit

Permalink
Write allow ips into self-update pipeline
Browse files Browse the repository at this point in the history
The `allow-ips` flag has to be provided on every deploy otherwise it
gets reset to the default of allow all. To get around this in the
self-update pipeline we now write allow-ips into the pipeline yaml.
  • Loading branch information
crsimmons committed Oct 9, 2020
1 parent 651a153 commit 057ce69
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ var deployFlags = []cli.Flag{
},
cli.StringFlag{
Name: "allow-ips",
Usage: "(optional) Comma separated list of IP addresses or CIDR ranges to allow access to",
Usage: "(optional) Comma separated list of IP addresses or CIDR ranges to allow access to. Not applied to future manual deploys unless this flag is provided again",
EnvVar: "ALLOW_IPS",
Value: "0.0.0.0/0",
Destination: &initialDeployArgs.AllowIPs,
Expand Down
1 change: 1 addition & 0 deletions concourse/client_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ sWbB3FCIsym1FXB+eRnVF3Y15RwBWWKA5RfwUNpEXFxtv24tQ8jrdA==
//Mutations we expect to have been done after load
configAfterLoad = configInBucket
configAfterLoad.AllowIPs = "\"0.0.0.0/0\""
configAfterLoad.AllowIPsUnformatted = "0.0.0.0/0"
configAfterLoad.SourceAccessIP = "192.0.2.0"
configAfterLoad.NetworkCIDR = "10.0.0.0/16"
configAfterLoad.PublicCIDR = "10.0.0.0/24"
Expand Down
4 changes: 4 additions & 0 deletions concourse/client_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ sWbB3FCIsym1FXB+eRnVF3Y15RwBWWKA5RfwUNpEXFxtv24tQ8jrdA==
//Mutations we expect to have been done after load
configAfterLoad = configInBucket
configAfterLoad.AllowIPs = "\"0.0.0.0/0\""
configAfterLoad.AllowIPsUnformatted = "0.0.0.0/0"
configAfterLoad.SourceAccessIP = "192.0.2.0"
configAfterLoad.NetworkCIDR = "10.0.0.0/16"
configAfterLoad.PublicCIDR = "10.0.0.0/24"
Expand Down Expand Up @@ -504,6 +505,7 @@ wEW5QkylaPEkbVDhJWeR1I8=

configAfterLoad = configInBucket
configAfterLoad.AllowIPs = "\"88.98.225.40/32\""
configAfterLoad.AllowIPsUnformatted = "88.98.225.40"
configAfterLoad.ConcourseWebSize = args.WebSize
configAfterLoad.ConcourseWorkerCount = args.WorkerCount
configAfterLoad.ConcourseWorkerSize = args.WorkerSize
Expand Down Expand Up @@ -606,6 +608,7 @@ wEW5QkylaPEkbVDhJWeR1I8=
// Config generated by default for a new deployment
defaultGeneratedConfig = config.Config{
AllowIPs: "\"0.0.0.0/0\"",
AllowIPsUnformatted: "0.0.0.0/0",
AvailabilityZone: "eu-west-1a",
ConcoursePassword: "",
ConcourseUsername: "",
Expand Down Expand Up @@ -644,6 +647,7 @@ wEW5QkylaPEkbVDhJWeR1I8=
//Mutations we expect to have been done after load
configAfterLoad = defaultGeneratedConfig
configAfterLoad.AllowIPs = "\"0.0.0.0/0\""
configAfterLoad.AllowIPsUnformatted = "0.0.0.0/0"
configAfterLoad.SourceAccessIP = "192.0.2.0"

//Mutations we expect to have been done after deploying the director
Expand Down
1 change: 1 addition & 0 deletions concourse/client_gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ sWbB3FCIsym1FXB+eRnVF3Y15RwBWWKA5RfwUNpEXFxtv24tQ8jrdA==
//Mutations we expect to have been done after load
configAfterLoad = configInBucket
configAfterLoad.AllowIPs = "\"0.0.0.0/0\""
configAfterLoad.AllowIPsUnformatted = "0.0.0.0/0"
configAfterLoad.SourceAccessIP = "192.0.2.0"
configAfterLoad.PublicCIDR = "10.0.0.0/24"
configAfterLoad.PrivateCIDR = "10.0.1.0/24"
Expand Down
1 change: 1 addition & 0 deletions concourse/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func applyArgumentsToConfig(conf config.Config, deployArgs *deploy.Args, provide
}

conf.AllowIPs = allowedIPs
conf.AllowIPsUnformatted = deployArgs.AllowIPs

if deployArgs.ZoneIsSet {
conf.AvailabilityZone = deployArgs.Zone
Expand Down
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func ConvertSpotBoolToVMProvisioningType(spot bool) string {
// Config represents a control-tower configuration file
type Config struct {
AllowIPs string `json:"allow_ips"`
AllowIPsUnformatted string `json:"allow_ips_unformatted"`
AvailabilityZone string `json:"availability_zone"`
ConcourseCACert string `json:"concourse_ca_cert"`
ConcourseCert string `json:"concourse_cert"`
Expand Down Expand Up @@ -75,6 +76,7 @@ type Config struct {

type ConfigView interface {
GetAllowIPs() string
GetAllowIPsUnformatted() string
GetAvailabilityZone() string
GetConcourseCACert() string
GetConcourseCert() string
Expand Down Expand Up @@ -137,6 +139,10 @@ func (c Config) GetAllowIPs() string {
return c.AllowIPs
}

func (c Config) GetAllowIPsUnformatted() string {
return c.AllowIPsUnformatted
}

func (c Config) GetAvailabilityZone() string {
return c.AvailabilityZone
}
Expand Down
4 changes: 3 additions & 1 deletion docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ control-tower deploy \

|**Flag**|**Description**|**Environment Variable**|
|:-|:-|:-|
|`--allow-ips value`|Comma separated list of IP addresses or CIDR ranges to allow access to<br>(default: "0.0.0.0/0")|`ALLOW_IPS`|
|`--allow-ips value`|Comma separated list of IP addresses or CIDR ranges to allow access to. Not applied to future manual deploys unless this flag is provided again<br>(default: "0.0.0.0/0")|`ALLOW_IPS`|

> `allow-ips` governs what can access Concourse but not what can access the control plane (i.e. the BOSH director). The control plane will be restricted to the IP `control-tower deploy` was run from.
> This flag overwrites the allowed IPs on every deploy. This means deploying with `allow-ips` then deploying again without it will reset the allow list to `0.0.0.0/0`. The self-update pipeline will maintain the `allow-ips` of the most recent deploy.
## GitHub Auth

|**Flag**|**Description**|**Environment Variable**|
Expand Down
5 changes: 4 additions & 1 deletion fly/aws_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var getCredsFromSession = func() (string, string, error) {
}

//BuildPipelineParams builds params for AWS control-tower self update pipeline
func (a AWSPipeline) BuildPipelineParams(deployment, namespace, region, domain, iaas string) (Pipeline, error) {
func (a AWSPipeline) BuildPipelineParams(deployment, namespace, region, domain, allowIps, iaas string) (Pipeline, error) {
accessKeyID, secretAccessKey, err := a.credsGetter()
if err != nil {
return nil, err
Expand All @@ -47,6 +47,7 @@ func (a AWSPipeline) BuildPipelineParams(deployment, namespace, region, domain,
ControlTowerVersion: ControlTowerVersion,
Deployment: strings.TrimPrefix(deployment, "control-tower-"),
Domain: domain,
AllowIPs: allowIps,
Namespace: namespace,
Region: region,
IaaS: iaas,
Expand Down Expand Up @@ -79,6 +80,7 @@ jobs:
DEPLOYMENT: "{{ .Deployment }}"
IAAS: "{{ .IaaS }}"
NAMESPACE: "{{ .Namespace }}"
ALLOW_IPS: "{{ .AllowIPs }}"
SELF_UPDATE: true
config:
platform: linux
Expand Down Expand Up @@ -114,6 +116,7 @@ jobs:
DEPLOYMENT: "{{ .Deployment }}"
IAAS: "{{ .IaaS }}"
NAMESPACE: "{{ .Namespace }}"
ALLOW_IPS: "{{ .AllowIPs }}"
SELF_UPDATE: true
config:
platform: linux
Expand Down
7 changes: 4 additions & 3 deletions fly/aws_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
DEPLOYMENT: "my-deployment"
IAAS: "AWS"
NAMESPACE: "prod"
ALLOW_IPS: "10.0.0.0"
SELF_UPDATE: true
config:
platform: linux
Expand Down Expand Up @@ -74,6 +75,7 @@ jobs:
DEPLOYMENT: "my-deployment"
IAAS: "AWS"
NAMESPACE: "prod"
ALLOW_IPS: "10.0.0.0"
SELF_UPDATE: true
config:
platform: linux
Expand Down Expand Up @@ -108,13 +110,13 @@ jobs:
`

It("Generates something sensible", func() {
fakeCredsGetter := func()(string, string, error) {
fakeCredsGetter := func() (string, string, error) {
return "access-key", "secret-key", nil
}

pipeline := NewAWSPipeline(fakeCredsGetter)

params, err := pipeline.BuildPipelineParams("my-deployment", "prod", "eu-west-1", "ci.engineerbetter.com", "AWS")
params, err := pipeline.BuildPipelineParams("my-deployment", "prod", "eu-west-1", "ci.engineerbetter.com", "10.0.0.0", "AWS")
Expect(err).ToNot(HaveOccurred())

yamlBytes, err := util.RenderTemplate("self-update pipeline", pipeline.GetConfigTemplate(), params)
Expand All @@ -125,4 +127,3 @@ jobs:
})
})
})

2 changes: 1 addition & 1 deletion fly/fly.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (client *Client) writePipelineConfig(pipelinePath string, config config.Con
}
defer fileHandler.Close()

params, err := client.pipeline.BuildPipelineParams(config.GetDeployment(), config.GetNamespace(), config.GetRegion(), config.GetDomain(), config.GetIAAS())
params, err := client.pipeline.BuildPipelineParams(config.GetDeployment(), config.GetNamespace(), config.GetRegion(), config.GetDomain(), config.GetAllowIPsUnformatted(), config.GetIAAS())
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion fly/gcp_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ func NewGCPPipeline(credsPath string) (Pipeline, error) {
}

//BuildPipelineParams builds params for AWS control-tower self update pipeline
func (a GCPPipeline) BuildPipelineParams(deployment, namespace, region, domain, iaas string) (Pipeline, error) {
func (a GCPPipeline) BuildPipelineParams(deployment, namespace, region, domain, allowIps, iaas string) (Pipeline, error) {
return GCPPipeline{
PipelineTemplateParams: PipelineTemplateParams{
ControlTowerVersion: ControlTowerVersion,
Deployment: strings.TrimPrefix(deployment, "control-tower-"),
AllowIPs: allowIps,
Domain: domain,
Namespace: namespace,
Region: region,
Expand Down Expand Up @@ -67,6 +68,7 @@ jobs:
GCPCreds: '{{ .GCPCreds }}'
IAAS: "{{ .IaaS }}"
NAMESPACE: "{{ .Namespace }}"
ALLOW_IPS: "{{ .AllowIPs }}"
SELF_UPDATE: true
config:
platform: linux
Expand Down Expand Up @@ -102,6 +104,7 @@ jobs:
GCPCreds: '{{ .GCPCreds }}'
IAAS: "{{ .IaaS }}"
NAMESPACE: "{{ .Namespace }}"
ALLOW_IPS: "{{ .AllowIPs }}"
SELF_UPDATE: true
config:
platform: linux
Expand Down
4 changes: 3 additions & 1 deletion fly/gcp_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
GCPCreds: 'creds-content'
IAAS: "GCP"
NAMESPACE: "prod"
ALLOW_IPS: "10.0.0.0"
SELF_UPDATE: true
config:
platform: linux
Expand Down Expand Up @@ -76,6 +77,7 @@ jobs:
GCPCreds: 'creds-content'
IAAS: "GCP"
NAMESPACE: "prod"
ALLOW_IPS: "10.0.0.0"
SELF_UPDATE: true
config:
platform: linux
Expand Down Expand Up @@ -123,7 +125,7 @@ jobs:
pipeline, err := NewGCPPipeline(tempFile.Name())
Expect(err).ToNot(HaveOccurred())

params, err := pipeline.BuildPipelineParams("my-deployment", "prod", "europe-west1", "ci.engineerbetter.com", "GCP")
params, err := pipeline.BuildPipelineParams("my-deployment", "prod", "europe-west1", "ci.engineerbetter.com", "10.0.0.0", "GCP")
Expect(err).ToNot(HaveOccurred())

yamlBytes, err := util.RenderTemplate("self-update pipeline", pipeline.GetConfigTemplate(), params)
Expand Down
3 changes: 2 additions & 1 deletion fly/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package fly

// Pipeline is interface for self update pipeline
type Pipeline interface {
BuildPipelineParams(deployment, namespace, region, domain, iaas string) (Pipeline, error)
BuildPipelineParams(deployment, namespace, region, domain, allowIps, iaas string) (Pipeline, error)
GetConfigTemplate() string
}

type PipelineTemplateParams struct {
ControlTowerVersion string
Deployment string
Domain string
AllowIPs string
Namespace string
Region string
IaaS string
Expand Down

0 comments on commit 057ce69

Please sign in to comment.