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

Idempotent in headless mode #592

Merged
merged 7 commits into from
Apr 27, 2020
Merged

Idempotent in headless mode #592

merged 7 commits into from
Apr 27, 2020

Conversation

jmeubank
Copy link
Contributor

@jmeubank jmeubank commented Mar 29, 2020

This changeset adjusts the script so that you can run it multiple times with the same input and not have any unexpected changes. This makes it appropriate for "enforcing state", as required by automated provisioners like Puppet, Salt, Chef, or Ansible.

  • Unbound, OpenVPN, easy-rsa, and other dependencies are only installed from upstream if they are not already present. This prevents multiple runs of the script from causing unexpected version upgrades.
  • The easy-rsa CA is only initialized once
  • SERVER_CN and SERVER_NAME are randomly generated once and saved for future reference
  • File append ('>>') is only done strictly after a file is created with '>' (e.g. /etc/sysctl.d/20-openvpn.conf)
  • Clients are only added to easy-rsa once
  • If AUTO_INSTALL == y, then the script operates in install mode and doesn't enter manageMenu

Also, IPv4-only mode has been fixed with a call to curl -4 ifconfig.co.

Fixes: #545

openvpn-install.sh Outdated Show resolved Hide resolved
@randshell
Copy link
Contributor

I only have a question. I don't understand the change to easy-rsa-auto, we didn't have conflicts for now.

In the list of provisioning you can add Ansible too.

Thanks for contributing!

@jmeubank
Copy link
Contributor Author

I only have a question. I don't understand the change to easy-rsa-auto, we didn't have conflicts for now.

This line mentions deleting a pre-existing 'easy-rsa' folder that came with older OpenVPN installations. On systems where this folder may pre-exist, it's safer to use a different folder name for the new incoming easy-rsa. Otherwise, it'd be hard to tell on repeated runs of openvpn-install.sh whether the contents of the folder are what we want them to be.

In the list of provisioning you can add Ansible too.

Done! e350220

@randshell
Copy link
Contributor

On systems where this folder may pre-exist, it's safer to use a different folder name for the new incoming easy-rsa

But you didn't delete the line rm -rf /etc/openvpn/easy-rsa/ so easy-rsa will be clean after installation anyway.

@jmeubank
Copy link
Contributor Author

jmeubank commented Mar 29, 2020

On systems where this folder may pre-exist, it's safer to use a different folder name for the new incoming easy-rsa

But you didn't delete the line rm -rf /etc/openvpn/easy-rsa/ so easy-rsa will be clean after installation anyway.

But on the next run of the script, easy-rsa-auto will be present. If I kept the original naming convention, easy-rsa would be present and would be deleted and recreated each time.

The goal is for the desired version of easy-rsa (currently 3.0.6) to be installed once by this script. If an older version that was packaged with OpenVPN in the distro's repos is present (in easy-rsa), it should be deleted. Then, subsequent runs of this script shouldn't re-download and recreate it.

@HenryNe
Copy link
Contributor

HenryNe commented Mar 29, 2020

On systems where this folder may pre-exist, it's safer to use a different folder name for the new incoming easy-rsa

But you didn't delete the line rm -rf /etc/openvpn/easy-rsa/ so easy-rsa will be clean after installation anyway.

But on the next run of the script, easy-rsa-auto will be present. If I kept the original naming convention, easy-rsa would be present and would be deleted and recreated each time.

The goal is for the desired version of easy-rsa (currently 3.0.6) to be installed once by this script. If an older version that was packaged with OpenVPN in the distro's repos is present (in easy-rsa), it should be deleted. Then, subsequent runs of this script shouldn't re-download and recreate it.

An other question is, what does an update of the distro, for example if the distro will be update easy-rsa?

Copy link
Contributor

@randshell randshell left a comment

Choose a reason for hiding this comment

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

subsequent runs of this script shouldn't re-download and recreate it.

Now I get it. It would happen when you try to run the command to install it again but it's already installed.

I think we can avoid changing the name of the easy-rsa directory to easy-rsa-auto if we move rm -rf /etc/openvpn/easy-rsa/ to be inside if [[ ! -e /etc/openvpn/server.conf ]]; then. Can you let me know if you agree please?

openvpn-install.sh Show resolved Hide resolved
openvpn-install.sh Outdated Show resolved Hide resolved
openvpn-install.sh Outdated Show resolved Hide resolved
openvpn-install.sh Outdated Show resolved Hide resolved
openvpn-install.sh Outdated Show resolved Hide resolved
openvpn-install.sh Outdated Show resolved Hide resolved
openvpn-install.sh Outdated Show resolved Hide resolved
openvpn-install.sh Outdated Show resolved Hide resolved
openvpn-install.sh Outdated Show resolved Hide resolved
openvpn-install.sh Outdated Show resolved Hide resolved
@jmeubank
Copy link
Contributor Author

jmeubank commented Mar 29, 2020

An other question is, what does an update of the distro, for example if the distro will be update easy-rsa?

If the distro updates easy-rsa, it'll go in a separate directory and won't bother us.

If the distro overwrites the OpenVPN config referencing easy-rsa, we have a bigger problem, but re-running openvpn-install.sh will fix it. :)

@jmeubank
Copy link
Contributor Author

I think we can avoid changing the name of the easy-rsa directory to easy-rsa-auto if we move rm -rf /etc/openvpn/easy-rsa/ to be inside if [[ ! -e /etc/openvpn/server.conf ]]; then. Can you let me know if you agree please?

Agree, that's much cleaner!

Copy link
Contributor

@randshell randshell left a comment

Choose a reason for hiding this comment

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

Thanks!

@angristan
Copy link
Owner

Seems great guys, thanks 👍

openvpn-install.sh Outdated Show resolved Hide resolved
@jmeubank
Copy link
Contributor Author

I did my habitual pull rebase and dirtied up this PR, sorry. Will reset and clean it up.

jmeubank and others added 6 commits April 19, 2020 08:18
This set of changes adjusts the script so that you can run it multiple times with the same input and not have any unexpected changes. This makes it appropriate for "enforcing state", as required by automated provisioners like Puppet, Salt, Chef, or Ansible.

 - Unbound, OpenVPN, easy-rsa, and other dependencies are only installed from upstream if they are not already present. This prevents multiple runs of the script from causing unexpected version upgrades.
 - The easy-rsa system is put in a folder called "easy-rsa-auto" so it can't conflict with the "easy-rsa" folder from some older OpenVPN packages
 - The easy-rsa CA is only initialized once
 - SERVER_CN and SERVER_NAME are randomly generated once and saved for future reference
 - File append ('>>') is only done strictly after a file is created with '>' (e.g. /etc/sysctl.d/20-openvpn.conf)
 - Clients are only added to easy-rsa once
 - If AUTO_INSTALL == y, then the script operates in install mode and doesn't enter manageMenu
Co-Authored-By: randomshell <43271778+randomshell@users.noreply.github.com>
Co-Authored-By: randomshell <43271778+randomshell@users.noreply.github.com>
@jmeubank
Copy link
Contributor Author

Okay, it's clean again, let me know if you need me to squash any of the commits. :)

@angristan
Copy link
Owner

Don't worry I'll squash them. Thanks again, I just have to find some time to test it and merge it!

openvpn-install.sh Show resolved Hide resolved
Copy link
Contributor

@randshell randshell left a comment

Choose a reason for hiding this comment

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

Thanks @angristan

openvpn-install.sh Show resolved Hide resolved
The removal of an old version of easy-rsa should only happen if OpenVPN is being installed for the first time.
@angristan angristan removed the to-test label Apr 27, 2020
@angristan
Copy link
Owner

Thanks a lot everyone!

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

Successfully merging this pull request may close these issues.

[Patch attached] Make the script idempotent for automated provisioning
4 participants