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

wifi: make it possible to have a psk and an eap password simultaneously #416

Merged
merged 2 commits into from Nov 27, 2023

Conversation

daniloegea
Copy link
Collaborator

@daniloegea daniloegea commented Oct 13, 2023

Description

Originally, Netplan assumes the PSK and 802-1x identity password will
not be used simultaneously.

With this change, when both passwords are used, the PSK is expected to
be placed in "ssid".password and the identity in "ssid".auth.password.
"ssid".auth.password can also be used by the PSK if it's the only password.

When 802-1x is used, the PMF setting will not be emitted if the PSK is
also present. NM will error out if both settings are used simultaneously.

It also copes with unsupported EAP methods.

Here are some test cases that are currently leading to NM crashes:

nmcli con add type wifi ifname wlan0 ssid asdasd wifi-sec.key-mgmt wpa-psk wifi-sec.psk asdasdasd 802-1x.eap md5 802-1x.identity username 802-1x.password aaaaaaaa
nmcli con add type wifi ifname wlan0 ssid asdasd wifi-sec.key-mgmt wpa-psk wifi-sec.psk asdasdasd 802-1x.eap fast 802-1x.identity username 802-1x.password aaaaaaaa
nmcli con add type wifi ifname wlan0 ssid asdasd wifi-sec.key-mgmt ieee8021x wifi-sec.psk bbbbbbbb 802-1x.eap leap 802-1x.identity username 802-1x.password aaaaaaaa
nmcli con add type wifi ifname wlan0 ssid asdasd wifi-sec.key-mgmt wpa-eap 802-1x.eap md5 802-1x.identity username 802-1x.password aaaaaaaa

Checklist

  • Runs make check successfully.
  • Retains 100% code coverage (make check-coverage).
  • New/changed keys in YAML format are documented.
  • (Optional) Adds example YAML for new feature.
  • (Optional) Closes an open bug in Launchpad.

@daniloegea daniloegea marked this pull request as ready for review October 16, 2023 13:03
@daniloegea daniloegea requested a review from slyon October 16, 2023 13:03
@slyon
Copy link
Collaborator

slyon commented Oct 16, 2023

Related to #415

Copy link
Collaborator

@slyon slyon left a comment

Choose a reason for hiding this comment

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

Thank you Danilo for working out this generic solution inside the existing YAML schema!

Besides a single ABI-stability concern, which needs to be looked at, I think this is mostly good.

I think the extended logical checks can be a bit complex/confusing at times and should be supported by some more comments. Also, there might be further potential for simplification. See my other non-blocking inline comments.

src/abi.h Show resolved Hide resolved
src/parse-nm.c Outdated Show resolved Hide resolved
src/parse-nm.c Outdated
if (ap->auth.password)
ap->has_auth = TRUE;
} else {
keyfile_handle_generic_str(kf, "wifi-security", "psk", &ap->auth.psk);
Copy link
Collaborator

Choose a reason for hiding this comment

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

question (non-blocking): I wonder if it'd make sense to parse the keyfile's wifi-security.psk setting into Netplan's psk field unconditionally, to make things less confusing? So Netplan's psk field would always ever be used to store a PSK. In certain conditions that PSK might be duplicated into auth.password for backwards compatibility.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did that to help differentiate when the PSK will go to "ap".password or "ap".auth.password so it wouldn't change behavior (and tests would not break :P). I'll see how I can always add the PSK to the new psk variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah it cause a small conflict with our previous idea of always set "pmf" to optional if "ap".password is used. By always reading the PSK into ap->auth.psk we'll end up always emitting "ap".password in the YAML and enabling the pmf setting even if it wasn't in the original keyfile we are loading, which is not a big deal I guess. That was the reason why I tried to differentiate the cases...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I pushed this change in a new commit

Copy link
Collaborator

Choose a reason for hiding this comment

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

I did that to help differentiate when the PSK will go to "ap".password or "ap".auth.password so it wouldn't change behavior (and tests would not break :P). I'll see how I can always add the PSK to the new psk variable.

Understood. And I think that makes sense! Enabling the pmf setting even if it wasn't in the original keyfile might actually be an issue, as it might break NetworkManager unit-tests at build time, when it's trying to re-generate the correct keyfile. I'm not sure if it has tests around that PMF setting, but it could have in the future.

So we should really try to not change behavior here. Do you think we could have a has_auth_psk_shortcut helper variable, to indicate which case we're in? Then making use of this in the YAML emitter (netplan.c), to write the correct password field, instead of changing the tests. And also no change keyfile behavior.

src/parse-nm.c Outdated Show resolved Hide resolved
src/parse-nm.c Outdated Show resolved Hide resolved
src/nm.c Outdated Show resolved Hide resolved
src/networkd.c Outdated Show resolved Hide resolved
src/networkd.c Outdated Show resolved Hide resolved
@daniloegea daniloegea force-pushed the key_mgmt_ieee8021x_part2 branch 2 times, most recently from ba80152 to e80696f Compare October 18, 2023 14:59
@daniloegea daniloegea requested a review from slyon October 19, 2023 08:48
Copy link
Collaborator

@slyon slyon left a comment

Choose a reason for hiding this comment

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

I added some concerns about the recent changes in-line and marked some of the other comments as resolved.

src/util-internal.h Outdated Show resolved Hide resolved
src/abi.h Show resolved Hide resolved
src/parse-nm.c Outdated
if (ap->auth.password)
ap->has_auth = TRUE;
} else {
keyfile_handle_generic_str(kf, "wifi-security", "psk", &ap->auth.psk);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I did that to help differentiate when the PSK will go to "ap".password or "ap".auth.password so it wouldn't change behavior (and tests would not break :P). I'll see how I can always add the PSK to the new psk variable.

Understood. And I think that makes sense! Enabling the pmf setting even if it wasn't in the original keyfile might actually be an issue, as it might break NetworkManager unit-tests at build time, when it's trying to re-generate the correct keyfile. I'm not sure if it has tests around that PMF setting, but it could have in the future.

So we should really try to not change behavior here. Do you think we could have a has_auth_psk_shortcut helper variable, to indicate which case we're in? Then making use of this in the YAML emitter (netplan.c), to write the correct password field, instead of changing the tests. And also no change keyfile behavior.

src/nm.c Outdated Show resolved Hide resolved
@daniloegea
Copy link
Collaborator Author

I tried to restore the original behavior and still always read the psk in auth.psk.

Originally, Netplan assumes the PSK and 802-1x identity password will
not be used simultaneously.

With this change, when both passwords are used, the PSK is expected to
be placed in "ssid".password and the identity in "ssid".auth.password.
"ssid".auth.password can also be used by the PSK if it's the only
password.

When 802-1x is used, the PMF setting will not be emitted if the PSK is
also present. NM will error out if both settings are used
simultaneously.
Copy link
Collaborator

@slyon slyon left a comment

Choose a reason for hiding this comment

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

Thank you for addressing my concerns, this is almost ready for merging!

I left a few tiny (one-line) comments inline, which I'd like to see fixed before merging.

src/util-internal.h Outdated Show resolved Hide resolved
src/networkd.c Outdated Show resolved Hide resolved
src/nm.c Outdated Show resolved Hide resolved
tests/parser/test_keyfile.py Outdated Show resolved Hide resolved
tests/parser/test_keyfile.py Show resolved Hide resolved
This has the side effect of always emitting the PSK in
"accesspoint".password. Which has the side effect of always enable the
PMF setting when PSK is used.
@slyon
Copy link
Collaborator

slyon commented Nov 27, 2023

Thank you! The autopkgtest "tunnels" failure is unrelated.
Let's merge this.

@slyon slyon merged commit 76dec54 into canonical:main Nov 27, 2023
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants