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

Correctly handle removal & disabling of access method #5695

Conversation

MarkusPettersson98
Copy link
Contributor

@MarkusPettersson98 MarkusPettersson98 commented Jan 16, 2024

This PR aims to fix a few holes in the logic of enabling/disabling/removing access methods in different edge cases.

  • If the access method currently in-use is disabled → Switch to the next available access method
  • If the last enabled access method is removed → Enable the direct access method and switch to it
  • If the last enabled access method is currently in-use and removed → Enable the direct access method and switch to it

This logic can somewhat be simplified by restructuring the access methods part of the settings datastructure to always include the predefined Direct and Mullvad Bridges access methods. Piggybacking on the settings migration started by the custom OpenVPN SOCKS5 bridge PR, this PR alters the layout of the serialized access method settings accordingly.

This PR also fixes DES-547


This change is Reviewable

Copy link

linear bot commented Jan 16, 2024

@MarkusPettersson98 MarkusPettersson98 changed the title Correctly handle removal of disabled of access method Correctly handle removal & disabling of access method Jan 16, 2024
@MarkusPettersson98 MarkusPettersson98 force-pushed the correctly-handle-removal-disabling-of-access-method-des-561 branch 2 times, most recently from a443144 to 7381003 Compare January 18, 2024 08:37
@MarkusPettersson98 MarkusPettersson98 force-pushed the correctly-handle-removal-disabling-of-access-method-des-561 branch 9 times, most recently from a2c85ad to 853db69 Compare January 24, 2024 08:04
@MarkusPettersson98 MarkusPettersson98 marked this pull request as ready for review January 24, 2024 08:42
Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 3 files at r1, 2 of 4 files at r2, 1 of 2 files at r3, 10 of 10 files at r4, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @MarkusPettersson98)


mullvad-daemon/src/access_method.rs line 181 at r4 (raw file):

                *access_method = access_method_update.clone();
            }
            ensure_direct_is_enabled(settings);

Although this is fine, I think it would be nicer if it it were impossible for the collection itself to end up in an "invalid" state (e.g. no enabled methods) instead of expecting the client to make sure that this is the case (discussed offline).


mullvad-management-interface/src/types/conversions/access_method.rs line 14 at r4 (raw file):

                mullvad_bridges: Some(settings.mullvad_bridges.into()),
                access_method_settings: settings
                    .user_defined

Nit: Would be slightly nicer to stick to either "custom" or "user-defined" (but only use one of them).

Copy link

linear bot commented Jan 24, 2024

@MarkusPettersson98 MarkusPettersson98 force-pushed the correctly-handle-removal-disabling-of-access-method-des-561 branch 3 times, most recently from 24b5747 to bef6044 Compare January 29, 2024 16:44
@MarkusPettersson98
Copy link
Contributor Author

@raksooo Please have a look at the modifications made in gui/ 😊

Copy link
Member

@raksooo raksooo left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 8 files at r6.
Reviewable status: 11 of 18 files reviewed, 3 unresolved discussions (waiting on @dlon and @MarkusPettersson98)


gui/src/shared/daemon-rpc-types.ts line 532 at r6 (raw file):

export type ApiAccessMethodSettings = {
  direct: AccessMethodSetting;
  mullvad_bridges: AccessMethodSetting;

I thought the linter would complain about this, I'll have to look into it. We use camelCase for variables and object properties.

@MarkusPettersson98 MarkusPettersson98 force-pushed the correctly-handle-removal-disabling-of-access-method-des-561 branch from bef6044 to 816f931 Compare January 30, 2024 08:39
Copy link
Contributor Author

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

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

Reviewable status: 5 of 18 files reviewed, 1 unresolved discussion (waiting on @dlon and @raksooo)


mullvad-daemon/src/access_method.rs line 181 at r4 (raw file):

Previously, dlon (David Lönnhager) wrote…

Although this is fine, I think it would be nicer if it it were impossible for the collection itself to end up in an "invalid" state (e.g. no enabled methods) instead of expecting the client to make sure that this is the case (discussed offline).

Done


mullvad-management-interface/src/types/conversions/access_method.rs line 14 at r4 (raw file):

Previously, dlon (David Lönnhager) wrote…

Nit: Would be slightly nicer to stick to either "custom" or "user-defined" (but only use one of them).

Done

Copy link
Contributor Author

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

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

Reviewable status: 5 of 21 files reviewed, 1 unresolved discussion (waiting on @dlon and @raksooo)


gui/src/shared/daemon-rpc-types.ts line 532 at r6 (raw file):

Previously, raksooo (Oskar Nyberg) wrote…

I thought the linter would complain about this, I'll have to look into it. We use camelCase for variables and object properties.

Done

Added a rule to cover this to the ESLint config

Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 6 files at r5, 7 of 13 files at r8, all commit messages.
Reviewable status: 12 of 21 files reviewed, 2 unresolved discussions (waiting on @MarkusPettersson98 and @raksooo)


mullvad-daemon/src/access_method.rs line 181 at r4 (raw file):

Previously, MarkusPettersson98 (Markus Pettersson) wrote…

Done

Awesome :)


mullvad-types/src/access_method.rs line 35 at r9 (raw file):

    /// This function will return an error if a built-in API access is about to
    /// be removed.
    pub fn remove(&mut self, api_access_method: &Id) -> Result<(), Error> {

Do we need to check if the enabled collection is empty here as well? In case the only active (non-builtin) method is deleted.

Copy link
Contributor Author

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

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

Reviewable status: 11 of 21 files reviewed, 2 unresolved discussions (waiting on @dlon and @raksooo)


mullvad-types/src/access_method.rs line 35 at r9 (raw file):

Previously, dlon (David Lönnhager) wrote…

Do we need to check if the enabled collection is empty here as well? In case the only active (non-builtin) method is deleted.

Hmm, your are right. We used to have this check when a custom access was deleted. Re-added!

@raksooo raksooo requested a review from dlon January 30, 2024 09:54
Copy link
Member

@raksooo raksooo left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 13 files at r8, 8 of 8 files at r9.
Reviewable status: 20 of 21 files reviewed, 1 unresolved discussion (waiting on @dlon)


gui/src/shared/daemon-rpc-types.ts line 532 at r6 (raw file):

Previously, MarkusPettersson98 (Markus Pettersson) wrote…

Done

Added a rule to cover this to the ESLint config

Great! 👍

@MarkusPettersson98 MarkusPettersson98 force-pushed the correctly-handle-removal-disabling-of-access-method-des-561 branch 4 times, most recently from 77b40d8 to 808d280 Compare January 30, 2024 15:23
Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 5 files at r11, all commit messages.
Reviewable status: 20 of 21 files reviewed, all discussions resolved (waiting on @raksooo)


mullvad-daemon/src/api.rs line 433 at r11 (raw file):

        // The action would still be valid, since modulo will make sure we stay
        // within bounds.
        self.index %= self.access_method_settings.cardinality();

This might be unnecessary given that we always use modulo before using the index?

Copy link
Contributor Author

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

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

Reviewable status: 20 of 21 files reviewed, all discussions resolved (waiting on @raksooo)


mullvad-daemon/src/api.rs line 433 at r11 (raw file):

Previously, dlon (David Lönnhager) wrote…

This might be unnecessary given that we always use modulo before using the index?

It might be unnecessary, given that we rotate the access method when removing access methods which is the case I'm guarding for here. Removing this piece of code since I don't think it accomplishes anything 😊

@MarkusPettersson98 MarkusPettersson98 force-pushed the correctly-handle-removal-disabling-of-access-method-des-561 branch from 808d280 to 8a89d26 Compare January 31, 2024 08:55
@dlon dlon requested a review from raksooo January 31, 2024 09:10
Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r12, all commit messages.
Reviewable status: 20 of 21 files reviewed, all discussions resolved (waiting on @raksooo)

@MarkusPettersson98 MarkusPettersson98 force-pushed the correctly-handle-removal-disabling-of-access-method-des-561 branch 4 times, most recently from 873ce59 to a5f1834 Compare January 31, 2024 09:53
Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 5 files at r11, 1 of 1 files at r13, 1 of 1 files at r15, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@MarkusPettersson98 MarkusPettersson98 force-pushed the correctly-handle-removal-disabling-of-access-method-des-561 branch 2 times, most recently from e1f88e4 to 205dd8f Compare January 31, 2024 10:30
Implement `SettingsPersister.try_update`, which allow the caller to
signal a failed settings update, hindering a bad settings update from
being applied.
Change API access methods settings format to encode that built-in access
methods always exist by making them distinct values of the
`AccessMethod` settings.

This change was also propagated to the corresponding protobuf
definition, such that any client may make use of this fact as well.

The appropriate settings migration was added.
…available

If the current access method is disabled, select the next available
access method from the daemon settings.
@MarkusPettersson98 MarkusPettersson98 force-pushed the correctly-handle-removal-disabling-of-access-method-des-561 branch from 205dd8f to 87cb3b6 Compare January 31, 2024 11:47
@MarkusPettersson98 MarkusPettersson98 merged commit 0d9abfd into main Jan 31, 2024
37 of 39 checks passed
@MarkusPettersson98 MarkusPettersson98 deleted the correctly-handle-removal-disabling-of-access-method-des-561 branch January 31, 2024 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants