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

networking: Add wireguard keepalive and preshared-key option in the gui #19521

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

subhoghoshX
Copy link
Member

@subhoghoshX subhoghoshX commented Oct 24, 2023

fixes #19491

image

@subhoghoshX subhoghoshX force-pushed the wireguard-keepalive branch 6 times, most recently from 30ae48d to e161d67 Compare October 26, 2023 14:51
@subhoghoshX
Copy link
Member Author

Finally green! Either the flakes introduced were bad or my brain is dead. It took far too long..

@subhoghoshX
Copy link
Member Author

This flake is too common to ignore..

@subhoghoshX subhoghoshX force-pushed the wireguard-keepalive branch 4 times, most recently from 6f34fa7 to 9c11660 Compare October 26, 2023 17:37
@subhoghoshX subhoghoshX marked this pull request as ready for review October 27, 2023 05:58
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks! This needs some design discussion first.

Comment on lines +169 to +171
if (peer.persistentKeepalive.trim()) {
if (isNaN(Number(peer.persistentKeepalive)))
throw cockpit.format(_("Peer #$0 has invalid persistent keepalive. It must be a number."), index + 1);
Copy link
Member

Choose a reason for hiding this comment

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

Probably it should also check for ≥ 1 and possibly some maximum? Also, can this be a float?

Copy link
Member Author

Choose a reason for hiding this comment

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

The dbus type for Keepalive is 'u', so it has to be >=0. Passing negative or float shows an error in the UI. Like below:

image

I opened an issue for a better error message at #19645.

0 (zero) means "not set" as usual.

I couldn't find a documented maximum value, but little experiment shows it can be in the range 0 to 65535 (i.e. 2^16 possible values).. after that it overflows without any error.

@@ -324,6 +348,22 @@ export function WireGuardDialog({ settings, connection, dev }) {
id={idPrefix + '-allowedips-peer-' + i}
/>
</FormGroup>
<FormGroup className='pf-m-6-col-on-md' label={_("Preshared key")} fieldId={idPrefix + '-presharedkey-peer-' + i} labelIcon={
Copy link
Member

Choose a reason for hiding this comment

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

I think the usual spelling is "pre-shared key"

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes :) done.

@@ -324,6 +348,22 @@ export function WireGuardDialog({ settings, connection, dev }) {
id={idPrefix + '-allowedips-peer-' + i}
/>
</FormGroup>
<FormGroup className='pf-m-6-col-on-md' label={_("Preshared key")} fieldId={idPrefix + '-presharedkey-peer-' + i} labelIcon={
<Popover
bodyContent={_("Preshared key should be a random 32 byte bas64 encoded.")}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bodyContent={_("Preshared key should be a random 32 byte bas64 encoded.")}
bodyContent={_("A base64 encoded string of 32 random bytes.")}

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed.

@@ -324,6 +348,22 @@ export function WireGuardDialog({ settings, connection, dev }) {
id={idPrefix + '-allowedips-peer-' + i}
/>
</FormGroup>
<FormGroup className='pf-m-6-col-on-md' label={_("Preshared key")} fieldId={idPrefix + '-presharedkey-peer-' + i} labelIcon={
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs some UI work: I suppose it doesn't make sense to specify both a public/private key pair and a PSK? So perhaps there should either be a "key mode" selector at the top (symmetric or asymmetric), or one field should be disabled if the other has a value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Both public/private key pair and PSK is used to make it more secure and quantum computer resistant. It is mentioned here https://www.wireguard.com/papers/wireguard.pdf.

Copy link
Member Author

Choose a reason for hiding this comment

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

Found this in the docs (https://www.wireguard.com/protocol/#key-exchange-and-data-packets), I think this is more accessible than the pdf above.

If an additional layer of symmetric-key crypto is required (for, say, post-quantum resistance), WireGuard also supports an optional pre-shared key that is mixed into the public key cryptography. When pre-shared key mode is not in use, the pre-shared key value used below is assumed to be an all-zero string of 32 bytes.

Comment on lines +144 to +146
b.set_input_text("#network-wireguard-settings-keepalive-peer-0", "120")
psk = m1.execute("head -c 32 /dev/random | base64").strip()
b.set_input_text("#network-wireguard-settings-presharedkey-peer-0", psk)
Copy link
Member

Choose a reason for hiding this comment

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

Please also validate these settings in the API or with nmcli -- the UI doesn't reflect which key mode is being used, and which keepalive time.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good idea! Done, thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

I did it with wg because nmcli doesn't show peer information.

@subhoghoshX
Copy link
Member Author

Removed the pixels to fix branch conflict. I'll get to the reviews tomorrow.

@subhoghoshX subhoghoshX added the no-test For doc/workflow changes, or experiments which don't need a full CI run, label Nov 22, 2023
@subhoghoshX
Copy link
Member Author

Thanks! This needs some design discussion first.

It may indeed need some design discussion because adding another row makes it tall too quick and the separation between the peer fields gets confusing:

image

@garrett any suggestions?

@garrett
Copy link
Member

garrett commented Nov 23, 2023

A few thoughts about the latest screenshot:

  • Which are optional? Is preshared the only optional entry in peers?
  • Why are keys separate and so far apart?
  • What's the default keepalive? Should we pre-fill the value instead of leaving it blank? (So people would know if it needs to be adjusted or not.)
  • Are endpoint and keepalive related? (It appears that way here.)
  • It's hard to know which peer ends and the next starts. There's no separation, either with a divider or space. Everything's cramped, so we'd probably want divider lines between the items, I guess?
  • It feels like we're really overloading the modal and someone might have a lot of peers. Do we want to split the basic settings and peers?

@subhoghoshX
Copy link
Member Author

  • Which are optional? Is preshared the only optional entry in peers?

Keepalive and Pre-shared key is completely optional and Endpoint is also (kind of) optional.
Only Public key and Allowed IPs is required.

  • Why are keys separate and so far apart?

No strong reason, it's just Public key is required so it's the first one, and Pre-shared key is optional, so it's one of the last.

  • What's the default keepalive? Should we pre-fill the value instead of leaving it blank? (So people would know if it needs to be adjusted or not.)

The default value is 0, which means "not set". Pre-filling it sounds better!

  • Are endpoint and keepalive related? (It appears that way here.)

They're separate.
Endpoint = the other machine/peer/server's IP address (or domain) with port. (e.g. 1.2.3.4:80)
Keepalive = Send an empty packet every specified seconds to keep the connection alive if a machine is behind a firewall or NAT.

It's just out of the 5 fields these two only take 1/4 of the width. So they're together. Everything else takes 1/2 of the horizontal space.

  • It's hard to know which peer ends and the next starts. There's no separation, either with a divider or space. Everything's cramped, so we'd probably want divider lines between the items, I guess?
  • It feels like we're really overloading the modal and someone might have a lot of peers. Do we want to split the basic settings and peers?

Yes, that's the issue it looks a little overloaded with the new row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-test For doc/workflow changes, or experiments which don't need a full CI run,
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add wireguard keepalive and preshared-key option in the gui
3 participants