Skip to content

chore(manifest): add security_group to env manifest#3749

Merged
mergify[bot] merged 14 commits intoaws:mainlinefrom
paragbhingre:EnvironmentSecurityGroup
Jul 22, 2022
Merged

chore(manifest): add security_group to env manifest#3749
mergify[bot] merged 14 commits intoaws:mainlinefrom
paragbhingre:EnvironmentSecurityGroup

Conversation

@paragbhingre
Copy link
Copy Markdown
Contributor

@paragbhingre paragbhingre commented Jul 12, 2022

This PR fix the issue #3719

Now customers can define security group rules for EnvironmentSecurityGroup (e.g. ingress/egress) in their env manifest

Sample manifest template with security group rules is given below

network:
  vpc:
    security_group:
      ingress:
        IpProtocol: tcp
        FromPort: 80
        ToPort: 80
        CidrIp: 0.0.0.0/0
      egress:
        IpProtocol: tcp
        FromPort: 80
        ToPort: 80
        CidrIp: 0.0.0.0/0

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

@paragbhingre paragbhingre requested a review from a team as a code owner July 12, 2022 18:18
@paragbhingre paragbhingre requested review from efekarakus and removed request for a team July 12, 2022 18:18
Copy link
Copy Markdown
Contributor

@bvtujo bvtujo left a comment

Choose a reason for hiding this comment

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

couple of dumb questions but this looks great!

Comment thread internal/pkg/deploy/cloudformation/stack/env.go Outdated
Comment thread internal/pkg/deploy/cloudformation/stack/env.go Outdated
Comment thread internal/pkg/manifest/env.go Outdated
@bvtujo
Copy link
Copy Markdown
Contributor

bvtujo commented Jul 13, 2022

🚀

Comment thread internal/pkg/deploy/cloudformation/stack/env_integration_test.go Outdated
@paragbhingre paragbhingre added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jul 15, 2022
}
egress = strings.TrimSpace(string(out))
}
return &template.SecurityGroupConfig{
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.

So if the Ingress/Egress fields are empty, this will return a *template.SecurityGroupConfig object with nil values for ingress and egress?

Would it be more efficient to return earlier if IsZero, as that's the more common use case?

@huanjani
Copy link
Copy Markdown
Contributor

Looks good!
Are there docs showing users how to specify their rules correctly?
Would you mind changing the example in your PR description to match the changes from your latest commit?
Feel free to remove the label when you're ready!

Copy link
Copy Markdown
Contributor

@huanjani huanjani left a comment

Choose a reason for hiding this comment

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

Just a couple small comments!

@efekarakus
Copy link
Copy Markdown
Contributor

Is it possible to hold on to merging this PR until after the release please 🥺

If we can we'd like to halt on env template CFN changes unless it's about the env manifest. Once released, we can merge the PR!

Comment on lines +157 to +161
{{.SecurityGroupConfig.Ingress | indent 8}}
{{- end }}
{{- if and .SecurityGroupConfig .SecurityGroupConfig.Egress }}
SecurityGroupEgress:
{{.SecurityGroupConfig.Egress | indent 8}}
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.

Ideally we don't put yaml.node for them because then it wholly depends on customers to write CFN template which is very similar to what addons should do. As a manifest field, it is usually with some level of abstraction (integrated logic). For example, allow_vpc_ingress and from_cdn


// SecurityGroupConfig holds the fields to import security group config
type SecurityGroupConfig struct {
Ingress string
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.

So does the marshaling logic depend on the fact that customers have to specify the exact same keys in the manifest vs in CF?

For example, the manifest config

network:
  vpc:
    security_group:
      ingress:
        - IpProtocol: tcp
          FromPort: 0
          ToPort: 65535
        - IpProtocol: tcp
          FromPort: 1
          ToPort: 6
      egress:
        - IpProtocol: tcp
          FromPort: 0
          ToPort: 65535`

maps to the CloudFormation:

      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 0
          ToPort: 65535
        - IpProtocol: tcp
          FromPort: 1
          ToPort: 6
      SecurityGroupEgress:
        - IpProtocol: tcp
          FromPort: 0
          ToPort: 65535

but this means that the customer has to write manifest keys in two separate capitalization styles, which may be confusing. Are there any other places in the manifest that we directly use CF keys versus remapping them to their snake case counterparts (protocol, from_port, and to_port)?

@efekarakus efekarakus removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jul 19, 2022
@paragbhingre
Copy link
Copy Markdown
Contributor Author

To address everyone's concern (including @bvtujo , @iamhopaul123 ) about accepting security_group as yaml.Node or other concern as if we should be allowing customers to specify CFN template inside manifest, I would like to mention that as per my discussion with @efekarakus we are going to implement security_group rules with restricted fields only. That means we will be not using yaml.Node neither we allow customers to define CFN fields inside manifest. The expected input from the customer would be,

security_groups:
 ingress:
    - cidr:
      from_port:
      to_port:
      ip_protocol: 

We will target just CIDR for now which will solve some use cases such as mentioned here

@rclinard-amzn
Copy link
Copy Markdown
Contributor

It looks like this doesn't pass CI, likely due to a broken merge?

@mergify mergify Bot merged commit 5de9487 into aws:mainline Jul 22, 2022
paragbhingre added a commit that referenced this pull request Jul 22, 2022
mergify Bot pushed a commit that referenced this pull request Jul 22, 2022
Reverts #3749: chore(manifest): add security_group to env manifest

Reverting this PR as we will be implementing new solution for this issue.
mergify Bot pushed a commit that referenced this pull request Aug 3, 2022
This PR fix the issue #3719

Related to [#3749](#3749)

Now customers can define security group rules for EnvironmentSecurityGroup (e.g. ingress/egress) in their env manifest

Sample manifest template with security group rules is given below

```
network:
  vpc:
    security_group:
      ingress:
        - ip_protocol: tcp
           from_port: 80
           to_port: 80
           cidr: 0.0.0.0/0
      egress:
        - ip_protocol: tcp
           from_port: 80
           to_port: 80
           cidr: 0.0.0.0/0
```
@paragbhingre paragbhingre deleted the EnvironmentSecurityGroup branch January 26, 2023 07:28
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