Skip to content

chore: allow cloud front prefix list to restrict security group access via environment manifest#3737

Merged
mergify[bot] merged 45 commits intoaws:mainlinefrom
CaptainCarpensir:env-alb-prefix-list
Jul 25, 2022
Merged

chore: allow cloud front prefix list to restrict security group access via environment manifest#3737
mergify[bot] merged 45 commits intoaws:mainlinefrom
CaptainCarpensir:env-alb-prefix-list

Conversation

@CaptainCarpensir
Copy link
Copy Markdown
Contributor

Allow users to specify prefix lists, and to restrict ingress traffic to the ALB via the environment manifest. Adds a new field to the PublicHTTPConfig field restrict_alb_ingress_to_cf for this behavior.

Feature for part of #3701

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.

@CaptainCarpensir CaptainCarpensir requested a review from a team as a code owner July 8, 2022 21:34
@CaptainCarpensir CaptainCarpensir requested review from dannyrandall and removed request for a team July 8, 2022 21:34
@iamhopaul123 iamhopaul123 added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jul 8, 2022
@CaptainCarpensir
Copy link
Copy Markdown
Contributor Author

I realize that I changed a field name that we just released to make it more clear in the most recent commit to allow_from_vpc rather than just from_vpc. Unfortuantely I don't think we can push this since it's a breaking change, but I also regret not recognizing that I don't think the name from_vpc is clear enough, especially under the context of adding it to a struct which has both restricting and allowing fields.

@CaptainCarpensir CaptainCarpensir added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jul 22, 2022
@rclinard-amzn
Copy link
Copy Markdown
Contributor

"ingress from vpc" reads naturally to me and does imply the "allow" part, so it might be a fine name by itself. How about instead moving away from the "restrict" terminology? only_from_cdn might be a more clear name and could avoid the ambiguity, and would read similarly naturally as well - "(allow) ingress only from cdn".

mergify Bot pushed a commit that referenced this pull request Jul 22, 2022
Allow CloudFront URI to be displayed on top of public ALB. I also changed the struct name from `albURI` to `accessURI` as it better fits the description when the URI is the access point to the  environment, rather than just to the ALB. When PR for prefix lists #3737 is merged, I'll then modify these files to allow to disable showing the ALB DNS altogether.


Addresses #3701 

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
@rclinard-amzn
Copy link
Copy Markdown
Contributor

Per discussion in-person between myself, Austin, and Aiden - we think that modeling this as the following might work better:

http:
  public:
    security_group:
      ingress:
        restrict_to: [cdn]

This would accommodate adding additional prefix lists (or exposing prefix lists to the user) in a way that wouldn't generate ambiguity as would happen if we ended up with two fields along the lines of only_from_..., and without changing the current default behavior of the public ingress field of allowing all inbound Internet traffic by default.

CaptainCarpensir added a commit to CaptainCarpensir/copilot-cli that referenced this pull request Jul 22, 2022
Allow CloudFront URI to be displayed on top of public ALB. I also changed the struct name from `albURI` to `accessURI` as it better fits the description when the URI is the access point to the  environment, rather than just to the ALB. When PR for prefix lists aws#3737 is merged, I'll then modify these files to allow to disable showing the ALB DNS altogether.


Addresses aws#3701 

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
@CaptainCarpensir CaptainCarpensir removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jul 25, 2022
Comment thread internal/pkg/cli/deploy/env.go Outdated
Comment thread internal/pkg/cli/deploy/env.go Outdated
Comment thread internal/pkg/cli/deploy/env_test.go
Comment thread internal/pkg/cli/deploy/env.go Outdated
Comment thread internal/pkg/cli/deploy/env.go Outdated
Comment thread internal/pkg/deploy/env.go Outdated
Comment thread internal/pkg/manifest/validate_env.go
Comment thread internal/pkg/manifest/validate_env.go
{{- end}}
{{- end}}
PublicLoadBalancerSecurityGroup:
PublicHTTPLoadBalancerSecurityGroup:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My concern is that it may delete the old security group and create a new one. If we run copilot env deploy on an environment that still has PublicLoadBalancerSecurityGroup and not PublicHTTPLoadBalancerSecurityGroup yet (i.e. before your PR change), we'd probably see the following activities in Event tab:

PublicLoadBalancerSecurityGroup DELETE_COMPLETE
PublicLoadBalancerSecurityGroup DELETE_IN_PROGRESS
...
<stack_name> UPDATE_COMPLETE_CLEANUP_IN_PROGRESS
...
PublicHTTPLoadBalancerSecurityGroup CREATE_COMPLETE
PublicHTTPLoadBalancerSecurityGroup CREATE_IN_PROGRESS
...
<stack_name> UPDATE_IN_PROGRESS

Although it's probably not a problem to recreate the security group 🤔 but we should be careful about it if it introduces unnecessary resource updates just because the logical ID changes.

Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}-lb'
PublicHTTPSLoadBalancerSecurityGroup:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

qq: I see we are trying to add this ingress only if the ALB is listening for HTTPS on 443. This makes sense. Any other reasons why we are doing this now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Splitting the security group is needed because one security group has a max count of prefix lists of 60, but each cloud front prefix list counts for 55 of those, so in order to still only allow http and https traffic, we need to split them into two different SGs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To add on @CaptainCarpensir. One other benefit is that we don't always open HTTPS 443 for users anymore if they don't enable https.

Comment thread internal/pkg/cli/deploy/env.go Outdated
Comment thread internal/pkg/cli/deploy/env.go Outdated
Comment thread internal/pkg/cli/deploy/env.go Outdated
Comment thread internal/pkg/cli/deploy/env.go Outdated
Comment thread internal/pkg/template/env.go
{{- end}}
{{- end}}
PublicLoadBalancerSecurityGroup:
PublicHTTPLoadBalancerSecurityGroup:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similarly, I'm also still worried because I don't have a clear understanding of the sequence of steps that occur.

After testing, yeah this does succeed at least in a basic circumstance.

@CaptainCarpensir what did you observe on an env existing stack with a LBWS already enabled?
Does it:

  1. Create the new PublicHTTPLoadBalancerSecurityGroup
  2. Update PublicLoadBalancer
  3. Delete PublicLoadBalancerSecurityGroup

Is that the sequence? If it's the other way around (what Wanxian wrote) then the users will experience downtime because the load balancer for a brief period won't accept any incoming traffic.

Comment thread internal/pkg/manifest/env.go
@CaptainCarpensir CaptainCarpensir added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jul 25, 2022
@CaptainCarpensir CaptainCarpensir removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jul 25, 2022
Comment on lines +120 to +132
var cidrPrefixListIDs []string

// Check if ingress is allowed from cloudfront
if in.Manifest == nil || !in.Manifest.IsIngressRestrictedToCDN() {
return nil, nil
}
cfManagedPrefixListID, err := d.cfManagedPrefixListID()
if err != nil {
return nil, err
}
cidrPrefixListIDs = append(cidrPrefixListIDs, cfManagedPrefixListID)

return cidrPrefixListIDs, nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
var cidrPrefixListIDs []string
// Check if ingress is allowed from cloudfront
if in.Manifest == nil || !in.Manifest.IsIngressRestrictedToCDN() {
return nil, nil
}
cfManagedPrefixListID, err := d.cfManagedPrefixListID()
if err != nil {
return nil, err
}
cidrPrefixListIDs = append(cidrPrefixListIDs, cfManagedPrefixListID)
return cidrPrefixListIDs, nil
// Check if ingress is allowed from cloudfront
if in.Manifest == nil || !in.Manifest.IsIngressRestrictedToCDN() {
return nil, nil
}
id, err := d.cfManagedPrefixListID()
if err != nil {
return nil, err
}
return []string{id}, nil

@mergify mergify Bot merged commit 1afdfd1 into aws:mainline Jul 25, 2022
@CaptainCarpensir CaptainCarpensir deleted the env-alb-prefix-list branch August 1, 2022 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants