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

fix(capture): ignore known copy failure and fix iptables issue #903

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

Conversation

mainred
Copy link
Contributor

@mainred mainred commented Oct 29, 2024

Description

  • correct the logic to pick iptables mode
  • ignore copy command failure

Related Issue

If this pull request is related to any issue, please mention it here. Additionally, make sure that the issue is assigned to you before submitting this pull request.

Checklist

  • I have read the contributing documentation.
  • I signed and signed-off the commits (git commit -S -s ...). See this documentation on signing commits.
  • I have correctly attributed the author(s) of the code.
  • I have tested the changes locally.
  • I have followed the project's style guidelines.
  • I have updated the documentation, if necessary.
  • I have added tests, if applicable.

Screenshots (if applicable) or Testing Completed

image

Additional Notes

None


Please refer to the CONTRIBUTING.md file for more information on how to contribute to this project.

@mainred mainred requested a review from a team as a code owner October 29, 2024 09:43
@mainred mainred force-pushed the capture/fix-iptables-error branch from 5834c7f to b95d2e4 Compare October 29, 2024 09:45
@mainred
Copy link
Contributor Author

mainred commented Oct 29, 2024

We install iptables legacy on Mariner image when building the image, but when it runs on ubuntu host, the command returns empty result, which works fine on iptables nft mode.

Copy link
Contributor

@anubhabMajumdar anubhabMajumdar left a comment

Choose a reason for hiding this comment

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

Please add Testing Done section.

pkg/capture/provider/network_capture_unix.go Outdated Show resolved Hide resolved
pkg/capture/provider/network_capture_unix.go Outdated Show resolved Hide resolved
nftIptablesMode iptablesMode = "nft"
)

func obtainIptablesMode(l *log.ZapLogger) iptablesMode {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should return unhandled errors along with mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ideas in my mind is the failed iptables rules does not break the whole capture.

pkg/capture/provider/network_capture_unix.go Outdated Show resolved Hide resolved
@mainred mainred changed the title fix(captur): ignore know copy failure and fix iptables issue fix(capture): ignore known copy failure and fix iptables issue Oct 30, 2024
@mainred mainred force-pushed the capture/fix-iptables-error branch from 30b2834 to 8e7d3b2 Compare October 30, 2024 03:21
Signed-off-by: Qingchuan Hao <[email protected]>
@mainred mainred force-pushed the capture/fix-iptables-error branch from 8e7d3b2 to b173ff7 Compare October 30, 2024 03:22
@kamilprz kamilprz linked an issue Nov 4, 2024 that may be closed by this pull request
@mainred
Copy link
Contributor Author

mainred commented Nov 19, 2024

ping @timraymond and @anubhabMajumdar for another look.
cc @kamilprz

@timraymond
Copy link
Member

LGTM on @anubhabMajumdar 's approval

Copy link

This PR will be closed in 7 days due to inactivity.

@github-actions github-actions bot added the meta/waiting-for-author Blocked and waiting on the author label Dec 20, 2024
Copy link

Pull request closed due to inactivity.

@github-actions github-actions bot closed this Dec 28, 2024
@kamilprz kamilprz reopened this Dec 30, 2024
@kamilprz
Copy link
Contributor

Reopening and bringing it back to light @anubhabMajumdar @mainred

@github-actions github-actions bot removed the meta/waiting-for-author Blocked and waiting on the author label Dec 31, 2024
legacySaveOut, err := exec.Command("iptables-legacy-save").CombinedOutput()
if err != nil {
nftIptablesModeAvaiable = false
logger.Error("Failed to run iptables-legacy-save", zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should make this more verbose. This error doesn't indicate the tool failed to collect capture; it just indicates the command may not be available.

Copy link
Member

Choose a reason for hiding this comment

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

@anubhabMajumdar It doesn't even really indicate that since weird things can go wrong when exec'ing under a stressed-out system. If we want to definitively test whether the command exists or not, the correct way to do that is with exec.LookPath. We should preflight each of these invocations to rule out the command not existing first (which can be done without exec()ing too). Then if we hit this arm of the error, we know definitively that it was something unusual in the actual execution of the command (probably OOM or something).

Also, in general, if it's happy-path control flow that the command does not exist (which we could be certain of with exec.LookPath, we don't need to log the error (since it's not an error). Once we are sure that it's an unusual error, we should return the error from this func, wrapped with context about what we were trying to do when the error was produced.

}
return "nft"
return nftIptablesMode
Copy link
Contributor

Choose a reason for hiding this comment

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

I want to highlight this again - we are returning nftIptablesMode even if we know that is not available. This assumes the behavior of the caller and shouldn't be done. We should return error if no mode is available and let the caller handle the error.

name: "cp",
args: []string{"-r", "/proc/sys/net", filepath.Join(ncp.TmpCaptureDir, "proc-sys-net")},
description: "kernel networking configuration",
ignoreFailure: true,
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 add a comment as to why this is optional? Also, maybe log this as a warn so that user doesn't go looking for this information in the capture.

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.

Capture Create fails to execute IP Tables commands
4 participants