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

validate all xds resources before returning the translation result #5148

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

zhaohuabing
Copy link
Member

@zhaohuabing zhaohuabing commented Jan 25, 2025

This PR enforces validation for all generated xDS resources before sending them to the Envoy fleet.

Related to: #5147
Release Notes: No

2025-01-25T05:07:21.922Z	ERROR	xds-translator	runner/runner.go:85	failed to translate xds ir	{"runner": "xds-translator", "error": "invalid RouteConfiguration.VirtualHosts[0]: embedded message failed validation | caused by: invalid VirtualHost.Routes[0]: embedded message failed validation | caused by: invalid Route.Route: embedded message failed validation | caused by: invalid RouteAction.RetryPolicy: embedded message failed validation | caused by: invalid RetryPolicy.RetryBackOff: embedded message failed validation | caused by: invalid RetryPolicy_RetryBackOff.BaseInterval: value must be greater than 0s"}

@zhaohuabing zhaohuabing requested a review from a team as a code owner January 25, 2025 05:10
@zhaohuabing zhaohuabing marked this pull request as draft January 25, 2025 05:10
@zhaohuabing zhaohuabing force-pushed the fix-5147 branch 2 times, most recently from befa1a4 to 4d53353 Compare January 25, 2025 05:20
Copy link

codecov bot commented Jan 25, 2025

Codecov Report

Attention: Patch coverage is 46.36364% with 59 lines in your changes missing coverage. Please review.

Project coverage is 64.97%. Comparing base (d1730a8) to head (6cb36ac).

Files with missing lines Patch % Lines
internal/utils/proto/proto.go 0.00% 21 Missing ⚠️
internal/xds/types/resourceversiontable.go 25.00% 9 Missing ⚠️
internal/xds/translator/authorization.go 20.00% 0 Missing and 8 partials ⚠️
internal/xds/cache/snapshotcache.go 0.00% 6 Missing ⚠️
internal/xds/translator/translator.go 16.66% 2 Missing and 3 partials ⚠️
internal/xds/translator/custom_response.go 33.33% 0 Missing and 4 partials ⚠️
internal/xds/translator/compressor.go 25.00% 0 Missing and 3 partials ⚠️
internal/xds/translator/basicauth.go 33.33% 0 Missing and 2 partials ⚠️
internal/xds/filters/wellknown.go 75.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (46.36%) is below the target coverage (60.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5148      +/-   ##
==========================================
- Coverage   64.97%   64.97%   -0.01%     
==========================================
  Files         214      213       -1     
  Lines       33532    33475      -57     
==========================================
- Hits        21789    21751      -38     
+ Misses      10400    10397       -3     
+ Partials     1343     1327      -16     

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

@zhaohuabing zhaohuabing force-pushed the fix-5147 branch 3 times, most recently from 6eb31de to a03807e Compare January 25, 2025 06:18
@@ -131,6 +131,12 @@ func (t *Translator) Translate(xdsIR *ir.Xds) (*types.ResourceVersionTable, erro
}
}

// Validate all the xds resources in the table before returning
// This is necessary to catch any misconfigurations that might have been missed during translation
if err := tCtx.ValidateAll(); err != nil {
Copy link
Member Author

@zhaohuabing zhaohuabing Jan 25, 2025

Choose a reason for hiding this comment

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

This is the key change, the rest are minor refactors around the proto validation.

Copy link
Contributor

Choose a reason for hiding this comment

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

so are we validating twice ?

Copy link
Contributor

Choose a reason for hiding this comment

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

because there's already a proto.Validate in resourceversiontable.go

Copy link
Member Author

@zhaohuabing zhaohuabing Feb 14, 2025

Choose a reason for hiding this comment

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

Yes, this is the final check to ensure no validations are missed, it serves as a safe guard to avoid invalid xDS being pushed to the Envoy fleet.

We still want to retain the original validation to catch up the invalid xDS earlier for proper error handling.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do with just 1 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Which we do in the end ?

Copy link
Member Author

@zhaohuabing zhaohuabing Feb 14, 2025

Choose a reason for hiding this comment

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

It's common for an xds resource to be modified after being added to ResourceVersionTable, and we don't have a good way to prevent this from happening again in future code changes, so I prefer to add a final check in the translator.

Copy link
Contributor

Choose a reason for hiding this comment

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

can we then keep this one and rm the one in AddXdsResource ?

Copy link
Member Author

@zhaohuabing zhaohuabing Feb 17, 2025

Choose a reason for hiding this comment

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

can we then keep this one and rm the one in AddXdsResource ?

I think it's reasonable to move the validation out of the AddXdsResource and into a dedicate method, as the current validation in AddXdsResource is implicit and could be easily ignored.

Would you mind if I address this in a follow-up PR? This is not a blocking issue for this PR. AddXdsResource method has been used everywhere and all the thrown validation errors need to be properly handled, addressing it here would make the scope of this PR too large.

Tracked in this issue: #5311

Since @arkodg mentioned that double validation could be a performance issue, I removed the cherrypick/release-v1.3.1 label, we can decide if we want to cherry-pick them to v1.3 after both this and #5311 are properly handled. cc @guydc

@@ -82,10 +82,7 @@ func buildHCMBasicAuthFilter(basicAuth *ir.BasicAuth) (*hcmv3.HttpFilter, error)
},
},
}
if err = basicAuthProto.ValidateAll(); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

Validation in individual filer translators are not required anymore, as they'll be validated inside the proto.ToAnyWithValidation function before converting to any.

@zhaohuabing zhaohuabing marked this pull request as ready for review January 25, 2025 06:26
@zhaohuabing zhaohuabing reopened this Jan 27, 2025
@zhaohuabing zhaohuabing marked this pull request as draft January 27, 2025 10:44
@zhaohuabing zhaohuabing force-pushed the fix-5147 branch 3 times, most recently from abd87f7 to 5faed17 Compare January 27, 2025 11:13
@zhaohuabing zhaohuabing marked this pull request as ready for review January 27, 2025 11:17
@arkodg arkodg added this to the Backlog milestone Jan 27, 2025
@guydc
Copy link
Contributor

guydc commented Jan 27, 2025

should we CP to 1.3.0 ?

@arkodg
Copy link
Contributor

arkodg commented Jan 27, 2025

@guydc , Haubing will be away this week, and we won't be able to get this into v1.3.0, we could get it into a patch release.
for now / v1.3.0 #5147 can be fixed with a CEL validation, I'll work on getting it into v1.3.0

@zhaohuabing
Copy link
Member Author

@arkodg @guydc could you please take another look at this PR? Thanks!

arkodg
arkodg previously approved these changes Feb 19, 2025
Signed-off-by: Huabing (Robin) Zhao <[email protected]>
Copy link
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

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

LGTM thanks !

@arkodg arkodg requested review from a team February 20, 2025 01:22
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.

4 participants