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

chore: validate health check protocol #5338

Merged

Conversation

CaptainCarpensir
Copy link
Contributor

Validates that Load Balancer HealthChecks don't use invalid protocol for load balancer listeners.

For #4767

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 September 28, 2023 23:05
@CaptainCarpensir CaptainCarpensir requested review from efekarakus and removed request for a team September 28, 2023 23:05
@github-actions
Copy link

github-actions bot commented Sep 28, 2023

🍕 Here are the new binary sizes!

Name New size (kiB) size (kiB) Delta (%)
macOS (amd) 51968 51740 +0.44
macOS (arm) 52816 52596 +0.42
linux (amd) 45708 45496 +0.47
linux (arm) 44992 44804 +0.42
windows (amd) 43160 42968 +0.45

@CaptainCarpensir CaptainCarpensir marked this pull request as draft September 29, 2023 16:29
@CaptainCarpensir
Copy link
Contributor Author

CaptainCarpensir commented Sep 29, 2023

This validates additional listener and routing rules as if they also create a healthcheck. Only the main rules of each are used for the default healthcheck ports. Will fix and then set to be ready for review again.

func validateHealthCheckPorts(opts validateHealthCheckPortsOpts) error {
if opts.alb != nil {
for _, rule := range opts.alb.RoutingRules() {
// healthCheckPort is defined by RoutingRule.HealthCheck.Port, with fallback on RoutingRule.TargetPort, then image.port.
Copy link
Contributor

Choose a reason for hiding this comment

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

is this logic to figure out the health check port defined elsewhere already? (maybe package stack?) if so, maybe we should put this HealthCheckPort(imagePort) uint16 logic onto the routing rule 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately the behavior isn't written in one place. Maybe this should be changed though 🤔 Currently the port is half determined by stack/transformers.go and half determined by the logic within the template. I think this can be easily changed though so there's exactly one determining function in the codebase for each TargetGroup health check port!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm unsure what exactly to do about this now because I've realized that in order to change the deploy/cloudformation/stack package to use the function I've written in the manifest package as the source of truth for the HealthCheckPort, we would need to update some people's stack. Basically if they have the following manifest, the target group would undergo a change.

nlb:
  port: 80

Would cause the target group to go from:

NLBTargetGroup:
  Port: 80

to:

NLBTargetGroup:
  HealthCheckPort: 80

This doesn't cause any change in behavior but requires a stack update. Maybe this is a change that should go along with updating the NLB/TargetGroup when the user specifies UDP?

@codecov-commenter
Copy link

codecov-commenter commented Sep 29, 2023

Codecov Report

Attention: 34 lines in your changes are missing coverage. Please review.

Comparison is base (cbb1718) 69.86% compared to head (cbb4884) 69.86%.

Additional details and impacted files
@@            Coverage Diff            @@
##           mainline    #5338   +/-   ##
=========================================
  Coverage     69.86%   69.86%           
=========================================
  Files           297      297           
  Lines         45020    45110   +90     
  Branches        287      287           
=========================================
+ Hits          31453    31518   +65     
- Misses        12038    12057   +19     
- Partials       1529     1535    +6     
Files Coverage Δ
internal/pkg/manifest/errors.go 54.45% <100.00%> (+1.87%) ⬆️
internal/pkg/manifest/http.go 76.76% <66.66%> (-1.40%) ⬇️
internal/pkg/manifest/lb_web_svc.go 83.33% <40.90%> (-5.70%) ⬇️
internal/pkg/manifest/validate.go 77.57% <67.30%> (+0.20%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@CaptainCarpensir CaptainCarpensir marked this pull request as ready for review September 29, 2023 16:53
Comment on lines 159 to 165
if err = validateHealthCheckPorts(validateHealthCheckPortsOpts{
exposedPorts: exposedPortsIndex,
mainContainerPort: l.ImageConfig.Port,
alb: &l.HTTPOrBool.HTTP,
nlb: &l.NLBConfig,
}); err != nil {
return fmt.Errorf("validate load balancer health check ports: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make more sense to be

Suggested change
if err = validateHealthCheckPorts(validateHealthCheckPortsOpts{
exposedPorts: exposedPortsIndex,
mainContainerPort: l.ImageConfig.Port,
alb: &l.HTTPOrBool.HTTP,
nlb: &l.NLBConfig,
}); err != nil {
return fmt.Errorf("validate load balancer health check ports: %w", err)
if err = validateALBHealthCheckPorts(validateHealthCheckPortsOpts{
exposedPorts: exposedPortsIndex,
mainContainerPort: l.ImageConfig.Port,
alb: &l.HTTPOrBool.HTTP,
}); err != nil {
return fmt.Errorf("validate application load balancer health check ports: %w", err)

And do the same thing to NLB separately? Because validateHealthCheckPorts seems to deal ALB and NLB separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this is a good idea because it could lead to the error messages being slightly misleading. When a health check is exposed on a port using udp, the solution is either to change the NLB port exposing udp, or to change the health check port set to the port using UDP traffic. Because the solution can be approached from either direction I think it's more logically sound to validate them together.

@CaptainCarpensir CaptainCarpensir marked this pull request as draft September 29, 2023 23:35
@CaptainCarpensir CaptainCarpensir marked this pull request as ready for review October 2, 2023 15:49
@dannyrandall dannyrandall added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Oct 4, 2023
@CaptainCarpensir CaptainCarpensir removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Oct 4, 2023
@mergify mergify bot merged commit f4e2e57 into aws:mainline Oct 4, 2023
@CaptainCarpensir CaptainCarpensir deleted the manifest/validate-healthchecks-protocol branch October 9, 2023 16:12
KollaAdithya pushed a commit to KollaAdithya/copilot-cli that referenced this pull request Oct 18, 2023
Validates that Load Balancer HealthChecks don't use invalid protocol for load balancer listeners.


For aws#4767 

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants