diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-07-29 21:28:21 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-07-29 21:28:21 +0200 |
commit | fe1d2377fe1169d7e13012295036935447ccfed1 (patch) | |
tree | c41428584f8ad67b4a86b356f8fe4f06de807dbc /src/migration-scripts/interfaces/7-to-8 | |
parent | 9f7ef46636c8b995a3b758484324db4bc9a4df37 (diff) | |
download | vyos-1x-fe1d2377fe1169d7e13012295036935447ccfed1.tar.gz vyos-1x-fe1d2377fe1169d7e13012295036935447ccfed1.zip |
wireguard: T2743: move key migration from config script to migration script
Migration files on the storage should be done one time by a migration script
instead of every time the configuration changes. Moving this to an older
migration script is fine as this is around for a long time and all rolling
releases are already up2date. It only affects updates from VyOS 1.2 series.
Diffstat (limited to 'src/migration-scripts/interfaces/7-to-8')
-rwxr-xr-x | src/migration-scripts/interfaces/7-to-8 | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/migration-scripts/interfaces/7-to-8 b/src/migration-scripts/interfaces/7-to-8 index 8830ffdc7..a4051301f 100755 --- a/src/migration-scripts/interfaces/7-to-8 +++ b/src/migration-scripts/interfaces/7-to-8 @@ -17,8 +17,23 @@ # Split WireGuard endpoint into address / port nodes to make use of common # validators +import os + from sys import exit, argv from vyos.configtree import ConfigTree +from vyos.util import chown, chmod_750 + +def migrate_default_keys(): + kdir = r'/config/auth/wireguard' + if os.path.exists(f'{kdir}/private.key') and not os.path.exists(f'{kdir}/default/private.key'): + location = f'{kdir}/default' + if not os.path.exists(location): + os.makedirs(location) + + chown(location, 'root', 'vyattacfg') + chmod_750(location) + os.rename(f'{kdir}/private.key', f'{location}/private.key') + os.rename(f'{kdir}/public.key', f'{location}/public.key') if __name__ == '__main__': if (len(argv) < 1): @@ -32,6 +47,8 @@ if __name__ == '__main__': config = ConfigTree(config_file) base = ['interfaces', 'wireguard'] + migrate_default_keys() + if not config.exists(base): # Nothing to do exit(0) |