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

Add support for wireguard secrets. #2109

Closed
wants to merge 1 commit into from

Conversation

raldone01
Copy link

@raldone01 raldone01 commented Feb 14, 2024

Removed the secret Source and inlined secret handling for simplicity.

Secrets are important because I like to commit my env and yml files.

Addresses: #2024

Note:

I had lots of trouble following all the different sources.
I don't think they add much value and are overly complex.
I would advise to remove the others too and use just one simple config loading module.

This was my first time writing go code so if you want any changes let me know.
Please test it against your setup for the various providers.
I can also update the documentation/wiki but first I want to be sure this is satisfactory.

Remove secret source and inline secret handling for simplicity.
@clayrosenthal
Copy link

+1 for this notation. It is commonly used by many docker images, they have a reference to it in the docs. And it is a more secure pattern to use files. Only suggestion would be adding more env vars to be able to be set by this mechanism

@qdm12
Copy link
Owner

qdm12 commented Mar 21, 2024

Any thoughts on the existing mechanism: #2024 (comment) ?

@raldone01
Copy link
Author

I saw the existing implementation which is non standard and does not work for wireguard.

I orignally planned to just add support for wireguard using the existing implementation but found the code quite difficult and complicated to follow.

That there are two pull requests regarding this feature and an issue should be quite telling that there is some room for improvement here.

I also wrote my thoughts on the top. This PR reduces code quite a bit. The comments and longer test actually have it roughly even out with locs.

What you do with this information and PR is up to you.

Copy link
Owner

@qdm12 qdm12 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, including test and comments 💯

However, I feel like this is trying to fix a non-existent problem (those _SECRETFILE variables do work, right?), EXCEPT adding a secret file reading for Wireguard.

I had lots of trouble following all the different sources.
I don't think they add much value and are overly complex.
I would advise to remove the others too and use just one simple config loading module.

Fair point, and I agree and disagree:

  • it was a single loading module a few years ago, and it was unmanageable. That's why it was split up, and source reading was separated from settings definitions (and defaults, validation etc.)
  • I'm planning one day to migrate to https://github.com/qdm12/gosettings/tree/v0.4.0-rc9 which handles internally merging of sources and transformation of keys (i.e. SOME_ENV becomes some-env for flags), I've done the migration for all my projects but Gluetun because there is a lot of nifty details and retro-compatibility that makes this hard. That would result in a single package internal/configuration and no subpackages at all 😉

Anyway, for now we should keep the existing structure with those 3 sources.

On top of this, doing major refactor of the configuration directory (here this is a bit of a major ones for a few configuration keys) usually results in mayhem, since it's really easy to miss details (even for me) given retro-compatibility, lowercasing, etc. so I prefer to avoid unless very necessary and rare.

Comment on lines +101 to +105
WIREGUARD_PRIVATE_KEY_FILE=/run/secrets/wireguard_private_key \
WIREGUARD_PRESHARED_KEY= \
WIREGUARD_PRESHARED_KEY_FILE=/run/secrets/wireguard_preshared_key \
WIREGUARD_PUBLIC_KEY= \
WIREGUARD_PUBLIC_KEY_FILE=/run/secrets/wireguard_public_key \
Copy link
Owner

Choose a reason for hiding this comment

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

Let's load in a toml wireguard config file instead? See prior related discussion on #610 (comment)

Comment on lines -12 to +28
httpProxy.User = s.env.Get("HTTPPROXY_USER",
env.RetroKeys("PROXY_USER", "TINYPROXY_USER"),
env.ForceLowercase(false))
httpProxy.User, err = s.readSecretFileAsStringPtr(
"HTTPPROXY_USER",
"/run/secrets/httpproxy_user",
[]string{"HTTPPROXY_USER_SECRETFILE", "PROXY_USER", "TINYPROXY_USER"},
)
if err != nil {
return httpProxy, fmt.Errorf("reading HTTP proxy user secret file: %w", err)
}

httpProxy.Password = s.env.Get("HTTPPROXY_PASSWORD",
env.RetroKeys("PROXY_PASSWORD", "TINYPROXY_PASSWORD"),
env.ForceLowercase(false))
httpProxy.Password, err = s.readSecretFileAsStringPtr(
"HTTPPROXY_PASSWORD",
"/run/secrets/httpproxy_password",
[]string{"HTTPPROXY_PASSWORD_SECRETFILE", "PROXY_PASSWORD", "TINYPROXY_PASSWORD"},
)
if err != nil {
return httpProxy, fmt.Errorf("reading HTTP proxy password secret file: %w", err)
}
Copy link
Owner

Choose a reason for hiding this comment

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

This is rather messy and mixes up too many things.
Let's leave the env source as it was, however you could merge the secrets source in the files source, although that can get messy too eventually. We should do this in a v4 release really, where the user specifies each file path with an env variable, whether the file is a secret file or a standard file, Feel free to add to #1113

@qdm12
Copy link
Owner

qdm12 commented Mar 21, 2024

Also see previous PR: #1348

@qdm12
Copy link
Owner

qdm12 commented Mar 21, 2024

#1348 got merged so now Wireguard secrets (as config file or as individual field-files) are supported. Therefore this PR becomes a bit unneeded, EXCEPT to add a comment to #1113 about using just _FILE suffix for both the files source and the secrets source (and drop the _SECRETFILE suffix), and probably merge both sources together as a consequence.

@qdm12 qdm12 force-pushed the master branch 2 times, most recently from bba6a9f to 23b0320 Compare March 25, 2024 18:44
@qdm12
Copy link
Owner

qdm12 commented Mar 27, 2024

  • Added the merging of secrets and files sources as a bullet point to v4.0.0 Gluetun #1113
  • The 'settings' library was upgraded (from v0.3.x to v0.4.1) which simplified the code a bit, and at least removed ~1500 lines of code.

Closing this since it's no longer necessary, but thanks for the discussion and coding put into it 💯

@qdm12 qdm12 closed this Mar 27, 2024
@raldone01
Copy link
Author

Awesome! I will try it soon.

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.

None yet

3 participants