Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

podman Support + performance tunes + misc #98

Closed
wants to merge 13 commits into from
Closed

podman Support + performance tunes + misc #98

wants to merge 13 commits into from

Conversation

pablos-here
Copy link

Hi,

In retrospect, I think I should have created a smaller PR to avoid this monolithic PR. I'm terribly sorry about it. If need be, please reject it and I'll resubmit it piecemeal. I'll use it as a learning experience. :)

This PR addresses the following issues: #97, #94 and #93.

Additionally, I fixed an edge-case when the Kill Switch is enabled and there is no Internet: not checking for a bad value from dig. If this happens. we exit 1 from the script and we restart. I also set dig's +tries=1 (default is 3. This way we can fail straight away. Further, I exposed DIG_TIMEOUT for users to tune.

I created a log_msg() function in each of the core scripts to standardize the output: YYYY-MM-DD 24H:MI:SS [scriptname] . I replaced the echos accordingly and added more calls to log_msg(). I sprinkled a bit more instrumentation in the scripts to aid with possible user issues.

I've tried to make the output a bit more user-friendly by listing the user parameters at the top in a section. For end-user debugging purposes (podman users), I'm listing the devices the container knows about. For example, with podman, the tapped device is tun0. The script uses eth0 as that is what docker presents. eth0 can be overridden by the user.

I hope it's not too controversial but I made all lowercase shell variables uppercase. The script had a mix. Possibly even more controversial, moved big chunks of code in entry.sh into functions. The idea is to make the main body more readable and thus, easier to maintain.

I exposed some performance tunables as well as tuneables to reduce the VPN availability lag on an internet hiccup.

On termination, I noticed that the child openvpn was not given adequate time to clean up (sleep 0.5). I've implemented a simple check with fail-safe to allow for a graceful termination (and tear down).

  Matches openvpn.
o With little CPU cost, make availability sooner by reducing tun0, poll
 sleep from 1 to 0.5
o Standardize shell variables to be uppercase.
o Tacked 'exit $?' at the end, though never reached.  :)
  Matches openvpn.
o With little CPU cost, make availability sooner by reducing tun0, poll
 sleep from 1 to 0.5
o Standardize shell variables to be uppercase.
o Tacked 'exit $?' at the end, though never reached.  :)
  Matches openvpn.
o Standardize shell variables to be uppercase.
o Refactored cleanup() to wait up to 15s for the graceful termination of
  openvpn.
o Re-worked how the modified config file is handled.  If
  $DEBUG_VPN_CONFIG_FILE is set, expose it to the caller via /data/vpn,
  otherwise it's written to /data/tmp
o Improved the clarity of the output by creating headings, etc.
o Improve code readabliity:  Migrated functional sections of code into
  shell functions
o Addressed the following issues: #93, #94 and #97
o For wireless connections mute replay warnings via
  --mute-replay-warnings
o Force no compression via '--comp-lzo no' as compression is a potential
  vulnerability.
o While never reached, tacked a call to cleanup() and 'exit 0' at the
  end.
@wfg
Copy link
Owner

wfg commented Feb 5, 2023

First off, I appreciate your interest in this project. 👍 Since this is a big PR, I'll hit all points individually:

Additionally, I fixed an edge-case when the Kill Switch is enabled and there is no Internet: not checking for a bad value from dig. If this happens. we exit 1 from the script and we restart.

Nice catch.

I created a log_msg() function in each of the core scripts to standardize the output: YYYY-MM-DD 24H:MI:SS [scriptname] . I replaced the echos accordingly and added more calls to log_msg(). I sprinkled a bit more instrumentation in the scripts to aid with possible user issues.

I like it. echo gets the job done, but I agree that a nicely-formatted log message is better.

I've tried to make the output a bit more user-friendly by listing the user parameters at the top in a section. For end-user debugging purposes (podman users), I'm listing the devices the container knows about. For example, with podman, the tapped device is tun0. The script uses eth0 as that is what docker presents. eth0 can be overridden by the user.

Good addition.

I hope it's not too controversial but I made all lowercase shell variables uppercase. The script had a mix.

I'd like to keep it mixed. When I write scripts, I reserve uppercase variables for environment variables and variables local to the script will be lowercase. When I see $VARIABLE used, I assume it is/can be set as an environment variable.

Possibly even more controversial, moved big chunks of code in entry.sh into functions. The idea is to make the main body more readable and thus, easier to maintain.

Not too controversial.

I exposed some performance tunables as well as tuneables to reduce the VPN availability lag on an internet hiccup.

My thinking on tunables is that I would rather have users set them in their configuration files since they have to supply them anyways. As far as I can tell you could technically run OpenVPN without a config file at all, having everything passed in as command line arguments. So unless you expose everything as a tunable, you are in a weird spot where only an arbitrary set of options are available, and you leave the door open for "can you add --flag-no-one-has-ever-heard-of as an option?". For simplicity's sake, I'd like to go the other direction: let users handle all the tunables in their config files. (Having said that, VPN_LOG_LEVEL should be removed as an option and handled via the config file.)


With all of that said, I'd like you to take a look at the rewrite branch. I personally have a lot of problems with the Dante proxy, and HTTP proxies are useless to me since SOCKS5 proxies exist. I've also figured out significantly cleaner way to handle the kill switch. For these reasons I'm eventually going to merge the rewrite branch to cut the proxies entirely and clean up the iptables rules.

While orthogonal to this discussion, I would like to point out that I also maintain a WireGuard version of this image. At this point, I exclusively use the WireGuard image (which already does not use embedded proxies) and an additional container that is a dedicated SOCKS5 proxy using WireGuard's network stack. I am very happy with my current personal configuration. I'm curious about your thoughts on WireGuard.

@pablos-here
Copy link
Author

pablos-here commented Feb 5, 2023 via email

@wfg
Copy link
Owner

wfg commented Feb 5, 2023

If our target user-base includes non-experts, we might want to expose
best-of tuneables and let the experts dink with the .ovpn files.

I see your point, but instead of having users add --env SNDBUF=524288 to the docker run command/Compose file, I think having them add sndbuf 524288 to their config file is easier.

Treating your config files as read-only is a little trickier though. Exposing tunables is probably the best/only option for this use case.

I'd be happy to have a look. What in particular would you like me to
review?

Primarily just the relative simplicity of it. Since I'm going to merge it eventually, it may be best to work from that branch instead of master.

I think I'll dink around with what you're using. I may
switch as my VPN provider generates WireGuard configs.

I found WireGuard faster and more reliable than OpenVPN. I'd recommend giving it a try :). At this point, I'm just maintaining ("maintaining" used loosely here) this image for the people.

@pablos-here
Copy link
Author

pablos-here commented Feb 6, 2023 via email

@wfg
Copy link
Owner

wfg commented Feb 6, 2023

When are you planning on doing the merge?

I might as well do it tonight I guess. Would you be able to test the changes on your end tonight to make sure I didn't break anything? Nothing looks broken to me, but twice as many eyes on it would be nice. :)

My guess is that not all VPN providers support WireGuard which is why
this project is still live eh?

A combination of that plus all the people that either don't know about or don't want to use WireGuard. There's not much to do maintenance-wise (especially after the rewrite merge), so there's little reason to kill it off.

@pablos-here
Copy link
Author

pablos-here commented Feb 6, 2023 via email

@pablos-here
Copy link
Author

pablos-here commented Feb 6, 2023 via email

@wfg
Copy link
Owner

wfg commented Feb 6, 2023

Without knowing how many users are currently using this functionality, I
think there should be a phase-out period.

These changes will be v4.0.0, and I think I'll stop offering a :latest tag now since I think they're dangerous for the non-expert users. With this, people would have to explicitly pull :4 to use the rewrite because :latest would be stuck on :3.1.0.

@pablos-here
Copy link
Author

pablos-here commented Feb 6, 2023 via email

@pablos-here
Copy link
Author

These changes capture our discussion:

  • Reverted shell variables to how they were. 👍
  • Removed SNDBUF and RCVBUF as they fall into the expert-level tuning.

@wfg
Copy link
Owner

wfg commented Feb 9, 2023

@pablos-here Following the rewrite merge, all the changes are to files that have been heavily modified and moved. I'm going to close this PR.

Would you mind resubmitting with your changes against the latest files?

@wfg wfg closed this Feb 9, 2023
@pablos-here
Copy link
Author

pablos-here commented Feb 9, 2023 via email

@wfg
Copy link
Owner

wfg commented Feb 9, 2023

Fair enough. I should've merged sooner to not waste your time.

What functionality was cut? The SOCKS5 proxy?

@pablos-here
Copy link
Author

pablos-here commented Feb 9, 2023 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants