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

iptables: test real world roundtrip of iptables rules #52860

Merged
merged 5 commits into from
Sep 5, 2024

Conversation

howardjohn
Copy link
Member

@howardjohn howardjohn commented Aug 26, 2024

This is a building block to test things like #52835 and #50328

@howardjohn howardjohn added the release-notes-none Indicates a PR that does not require release notes. label Aug 26, 2024
@istio-testing istio-testing added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 26, 2024
@howardjohn
Copy link
Member Author

/retest

func validateIptablesClean(t *testing.T) {
cur := iptablesSave(t)
if strings.Contains(cur, "ISTIO") {
t.Fatalf("Istio rules leftover: %v", cur)
Copy link
Contributor

@leosarra leosarra Aug 26, 2024

Choose a reason for hiding this comment

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

This will likely not be enough to completely validate that iptables are clean.
istio-clean-iptables is also tasked with cleaning non-jump rules in non-istio chains and may leave some leftovers is something is incorrect

e.g:
https://github.com/istio/istio/blob/master/tools/istio-clean-iptables/pkg/cmd/cleanup.go#L76-L80

For the purpose of #50328 e2e cleanup tests I have exposed VerifyIptablesState() to perform this validation

residueExists, deltaExists := iptConfigurator.VerifyIptablesState(&iptVer, &ipt6Ver)

Edit: Actually not even VerifyIptablesState would be enough as I changed it to ignore non-jump rules in non-istio chains. This was done in order to not introduce false positives if the users tinkered with the iptables by themselves.

if !ok || (strings.HasPrefix(chain, "ISTIO_") && len(rules) != len(currentRules)) {

For the tests there is the need to go deeper and rely directly the parsed output of iptables-restore (obtainable via cfg.ruleBuilder.GetStateFromSave(cmdOutput.string()) )

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can iterate with improved validation

Copy link
Member Author

Choose a reason for hiding this comment

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

These are hard to use directly with this approach since we do not have an iptConfigurator.

I have updated it to use the old and new cleanup approach though

@howardjohn
Copy link
Member Author

/retest

Copy link
Contributor

Choose a reason for hiding this comment

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

e2e seems like an odd choice. maybe just .../pkg/test/cleanup_test.go

@howardjohn
Copy link
Member Author

/retest

validateIptablesClean(t)
// App, cleanup with the new approach
assert.NoError(t, runIptables(args...))
assert.NoError(t, runIptablesClean(args...))
Copy link
Contributor

Choose a reason for hiding this comment

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

The --cleanup-only option is already verified in TestIdempotentUnequaledRerun in the file istio-iptables/pkg/capture/run_test.go.
https://github.com/istio/istio/blob/master/tools/istio-iptables/pkg/capture/run_test.go#L384-L393

The difference between the two is that the one in run_test.go uses the cleanup option programmatically by setting the istio-iptables/config instead of relying on the CLI.
Do you prefer to have a verification via CLI as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm I guess we probably don't, I missed that part of your PR

Copy link
Member Author

Choose a reason for hiding this comment

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

This does test istio-clean-iptables as well though

Copy link
Contributor

Choose a reason for hiding this comment

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

yes that's true. The old istio-clean-iptables method has currently zero e2e coverage

@istio-testing istio-testing merged commit f3c0d86 into istio:master Sep 5, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes-none Indicates a PR that does not require release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants