test: verify native WireGuard config and key replacement end to end
This commit is contained in:
1 parent
b7e7fb05b6
commit
8130fa3383
3 files changed
+86
-1
No files matched your search
@@ -0,0 +1,43 @@
|
||||
# WireGuard configuration replacement verification
|
||||
|
||||
2026-10-13. No production configuration or keys changed and no service restart.
|
||||
|
||||
## Verified
|
||||
|
||||
- 12 native unit tests pass, including replacement validation, unchanged old
|
||||
configuration after invalid import, 0600 storage, secret-free import/status
|
||||
responses, and rejection while connected or before LAN mode is confirmed.
|
||||
- Root integration test runs two disposable Linux network namespaces with
|
||||
newly generated test-only keys. It imports a configuration, connects, changes
|
||||
to confirmed LAN mode, disconnects, rejects invalid configuration, imports
|
||||
fresh private/peer/PSK values, updates the synthetic peer and reconnects.
|
||||
- A fresh real WireGuard handshake after key replacement succeeds. IPv4 and
|
||||
IPv6 HTTP access through the new tunnel work. Host routes remain unchanged;
|
||||
both test namespaces and temporary key/configuration files are cleaned up.
|
||||
- Running Deck `server.py`, `network-ui.js` and `network/config.py` hashes match
|
||||
the reviewed repository versions. The UI file handler sends .conf content to
|
||||
the authenticated import API, which validates it before calling the native
|
||||
helper. Importing replaces the protected stored configuration atomically.
|
||||
- The production network service remains active with a recent handshake.
|
||||
|
||||
This is an actual isolated backend/network test and a deployed UI/API source
|
||||
comparison, not a click-through replacement of the user's real config.
|
||||
|
||||
## User workflow
|
||||
|
||||
Keep a working LAN or SSH-admin path independent of the WireGuard peer being
|
||||
replaced. In Deck → Network, select LAN access, test it and confirm through
|
||||
that LAN access before disabling the old tunnel. Then choose the new .conf
|
||||
and import it (no deletion first is necessary), activate WireGuard and wait
|
||||
for a recent handshake. Set the desired tunnel/both access mode afterwards
|
||||
and confirm it through the new tunnel.
|
||||
|
||||
An active tunnel, unconfirmed mode change, or tunnel-only/both mode intentionally
|
||||
blocks import: the page cannot guarantee preserving a browser connection that
|
||||
depends on the peer being replaced. SSH remains the independent management
|
||||
channel. A remote user without direct LAN reachability can forward the host's
|
||||
LAN listener through their existing SSH connection; do not disable access
|
||||
checks or enable a public wildcard listener as a workaround.
|
||||
|
||||
Tests use synthetic peers only; no real keys, config dumps or raw production
|
||||
logs are committed. No rotation of the user's exposed keys occurred here.
|
||||
@@ -19,6 +19,25 @@ Endpoint = vpn.example.test:51820
|
||||
PersistentKeepalive = 25
|
||||
'''
|
||||
class NativeTests(unittest.TestCase):
|
||||
def test_config_replacement_is_validated_atomic_and_secret_free(self):
|
||||
with tempfile.TemporaryDirectory() as t:
|
||||
m=self.manager(t);m.dispatch(dict(action='import',config=CONF))
|
||||
replacement=CONF.replace('AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=','AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM=')
|
||||
with self.assertRaises(ConfigError):m.dispatch(dict(action='import',config='invalid'))
|
||||
self.assertEqual(m.read('config.json'),CONF)
|
||||
result=m.dispatch(dict(action='import',config=replacement))
|
||||
self.assertEqual(m.read('config.json'),replacement)
|
||||
self.assertNotIn('AwMDAw',json.dumps(result));self.assertNotIn('PrivateKey',json.dumps(result))
|
||||
self.assertEqual((Path(t)/'config.json').stat().st_mode&0o777,0o600)
|
||||
def test_replacement_requires_disconnected_confirmed_lan(self):
|
||||
with tempfile.TemporaryDirectory() as t:
|
||||
m=self.manager(t);m.dispatch(dict(action='import',config=CONF))
|
||||
m.enabled=True
|
||||
with self.assertRaisesRegex(ValueError,'deaktiviert'):m.dispatch(dict(action='import',config=CONF))
|
||||
m.enabled=False;m.policy.mode='tunnel'
|
||||
with self.assertRaisesRegex(ValueError,'lokalen Modus'):m.dispatch(dict(action='import',config=CONF))
|
||||
m.policy.propose('lan',False)
|
||||
with self.assertRaisesRegex(ValueError,'bestätigten'):m.dispatch(dict(action='import',config=CONF))
|
||||
def test_start_waits_for_configured_lan_address(self):
|
||||
policy=dict(lan_address='192.0.2.11',lan_interface='lan0')
|
||||
devices=json.dumps([{'ifname':'lan0','addr_info':[{'local':'192.0.2.11'}]}])
|
||||
|
||||
@@ -42,6 +42,8 @@ with Server(os.environ['TEST_SOCKET'],RPC) as server:
|
||||
'''
|
||||
def main():
|
||||
if os.geteuid()!=0:raise SystemExit('Explicit root test on Linux required.')
|
||||
existing={line.split()[0] for line in run('ip','netns','list').splitlines() if line.strip()}
|
||||
if existing.intersection((A,B)):raise SystemExit('Test namespace already exists; not modified.')
|
||||
process=None
|
||||
before=run('ip','-4','route','show')
|
||||
with tempfile.TemporaryDirectory(prefix='deck-native-test-') as t:
|
||||
@@ -82,8 +84,29 @@ def main():
|
||||
s=rpc('mode',mode='tunnel');assert http('10.241.88.1')==403;assert http('10.242.88.1')==200
|
||||
rpc('cancel');assert http('10.241.88.1')==200
|
||||
rpc('disconnect');assert rpc('status')['enabled'] is False
|
||||
# Replace both keys and PSK using only disposable test peers/configuration.
|
||||
trial=rpc('mode',mode='lan')['pending']['id']
|
||||
rpc('confirm',trial_id=trial,ingress='lan',proxy_token=token)
|
||||
try:rpc('import',config='invalid synthetic configuration')
|
||||
except ValueError:pass
|
||||
else:raise AssertionError('Invalid replacement accepted')
|
||||
new_ka=ns(A,'wg','genkey');new_kb=ns(B,'wg','genkey');psk=ns(A,'wg','genpsk')
|
||||
new_pa=ns(A,'wg','pubkey',data=new_ka+'\n');new_pb=ns(B,'wg','pubkey',data=new_kb+'\n')
|
||||
result=rpc('import',config=f'[Interface]\nPrivateKey = {new_ka}\nAddress = 10.242.88.1/24, fd42:88::1/64\n[Peer]\nPublicKey = {new_pb}\nPresharedKey = {psk}\nAllowedIPs = 10.242.88.2/32, fd42:88::2/128\nEndpoint = 10.241.88.2:51835\nPersistentKeepalive = 1\n')
|
||||
assert new_ka not in json.dumps(result) and psk not in json.dumps(result)
|
||||
peer.write_text(f'[Interface]\nPrivateKey = {new_kb}\nListenPort = 51835\n[Peer]\nPublicKey = {new_pa}\nPresharedKey = {psk}\nAllowedIPs = 10.242.88.1/32, fd42:88::1/128\nEndpoint = 10.241.88.1:51836\nPersistentKeepalive = 1\n');peer.chmod(0o600)
|
||||
ns(B,'wg','setconf','peerwg0',str(peer));peer.unlink()
|
||||
rpc('connect');ns(A,'wg','set','wgdeck0','listen-port','51836')
|
||||
for _ in range(40):
|
||||
if rpc('status')['state']=='connected':break
|
||||
time.sleep(.25)
|
||||
else:raise RuntimeError('Handshake after synthetic key replacement missing')
|
||||
trial=rpc('mode',mode='both')['pending']['id']
|
||||
rpc('confirm',trial_id=trial,ingress='tunnel',proxy_token=token)
|
||||
assert http('10.242.88.1')==200;assert http('fd42:88::1')==200
|
||||
rpc('disconnect');assert rpc('status')['enabled'] is False
|
||||
assert run('ip','-4','route','show')==before
|
||||
print('PASS native dual-stack handshake/access, LAN/tunnel/both, forged confirmation rejection, streamed API bytes, cancellation, cleanup; host routes unchanged')
|
||||
print('PASS native dual-stack handshake/access, config/key/PSK replacement and reconnect, invalid config rejection, secret-free responses, LAN/tunnel/both, streamed API bytes, cleanup; host routes unchanged')
|
||||
finally:
|
||||
if process:process.terminate();process.wait(timeout=15)
|
||||
for n in (A,B):subprocess.run(['ip','netns','del',n],capture_output=True)
|
||||
|
||||
Reference in new issue
Block a user