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 security hole with ami filter #6585

Merged
merged 3 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions builder/amazon/common/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func (d *AmiFilterOptions) Empty() bool {
return len(d.Owners) == 0 && len(d.Filters) == 0
}

func (d *AmiFilterOptions) NoOwner() bool {
return len(d.Owners) == 0
}

// RunConfig contains configuration for running an instance from a source
// AMI and details on how to access that launched image.
type RunConfig struct {
Expand Down Expand Up @@ -101,6 +105,10 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
errs = append(errs, fmt.Errorf("A source_ami or source_ami_filter must be specified"))
}

if c.SourceAmi == "" && c.SourceAmiFilter.NoOwner() {
errs = append(errs, fmt.Errorf("For security reasons, your source AMI filter must declare an owner."))
}

if c.InstanceType == "" {
errs = append(errs, fmt.Errorf("An instance_type must be specified"))
}
Expand Down
14 changes: 12 additions & 2 deletions builder/amazon/common/run_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,28 @@ func TestRunConfigPrepare_InstanceType(t *testing.T) {
func TestRunConfigPrepare_SourceAmi(t *testing.T) {
c := testConfig()
c.SourceAmi = ""
if err := c.Prepare(nil); len(err) != 1 {
if err := c.Prepare(nil); len(err) != 2 {
t.Fatalf("Should error if a source_ami (or source_ami_filter) is not specified")
}
}

func TestRunConfigPrepare_SourceAmiFilterBlank(t *testing.T) {
c := testConfigFilter()
if err := c.Prepare(nil); len(err) != 1 {
if err := c.Prepare(nil); len(err) != 2 {
t.Fatalf("Should error if source_ami_filter is empty or not specified (and source_ami is not specified)")
}
}

func TestRunConfigPrepare_SourceAmiFilterOwnersBlank(t *testing.T) {
c := testConfigFilter()
filter_key := "name"
filter_value := "foo"
c.SourceAmiFilter = AmiFilterOptions{Filters: map[*string]*string{&filter_key: &filter_value}}
if err := c.Prepare(nil); len(err) != 1 {
t.Fatalf("Should error if Owners is not specified)")
}
}

func TestRunConfigPrepare_SourceAmiFilterGood(t *testing.T) {
c := testConfigFilter()
owner := "123"
Expand Down
2 changes: 1 addition & 1 deletion website/source/docs/builders/amazon-chroot.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ each category, the available configuration keys are alphabetized.
is valid.

- `owners` (array of strings) - This scopes the AMIs to certain Amazon account IDs.
This is helpful to limit the AMIs to a trusted third party, or to your own account.
This is a required option, necessary to limit the AMIs your account or a trusted third party.

- `most_recent` (boolean) - Selects the newest created image when true.
This is most useful for selecting a daily distro build.
Expand Down
2 changes: 1 addition & 1 deletion website/source/docs/builders/amazon-ebs.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ builder.
is valid.

- `owners` (array of strings) - This scopes the AMIs to certain Amazon account IDs.
This is helpful to limit the AMIs to a trusted third party, or to your own account.
This is a required option, necessary to limit the AMIs your account or a trusted third party.

- `most_recent` (boolean) - Selects the newest created image when true.
This is most useful for selecting a daily distro build.
Expand Down
2 changes: 1 addition & 1 deletion website/source/docs/builders/amazon-ebssurrogate.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ builder.
is valid.

- `owners` (array of strings) - This scopes the AMIs to certain Amazon account IDs.
This is helpful to limit the AMIs to a trusted third party, or to your own account.
This is a required option, necessary to limit the AMIs your account or a trusted third party.

- `most_recent` (boolean) - Selects the newest created image when true.
This is most useful for selecting a daily distro build.
Expand Down
2 changes: 1 addition & 1 deletion website/source/docs/builders/amazon-ebsvolume.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ builder.
is valid.

- `owners` (array of strings) - This scopes the AMIs to certain Amazon account IDs.
This is helpful to limit the AMIs to a trusted third party, or to your own account.
This is a required option, necessary to limit the AMIs your account or a trusted third party.

- `most_recent` (boolean) - Selects the newest created image when true.
This is most useful for selecting a daily distro build.
Expand Down
2 changes: 1 addition & 1 deletion website/source/docs/builders/amazon-instance.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ builder.
is valid.

- `owners` (array of strings) - This scopes the AMIs to certain Amazon account IDs.
This is helpful to limit the AMIs to a trusted third party, or to your own account.
This is a required option, necessary to limit the AMIs your account or a trusted third party.

- `most_recent` (boolean) - Selects the newest created image when true.
This is most useful for selecting a daily distro build.
Expand Down