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

Abort the module execution when running w/o enough privileges #583

Merged
merged 6 commits into from Nov 27, 2019

Conversation

dgdavid
Copy link
Member

@dgdavid dgdavid commented Nov 25, 2019

Problem

When yast-bootloader module is executed without enough privileges/permissions, it crash because an Errno::EACCES error when trying access to the grub.cfg file.

Click to show/hide an screenshot

bootloader_crash

Solution

Abort the execution nicely, giving human readable information to the user.

💡 Proposed message:

The module is running without enough privileges to perform all possible actions.

Cannot continue. Please, try again as root.


bootloader_aborting_nicely

Tests

  • Tested manually in a running system.

@coveralls
Copy link

coveralls commented Nov 25, 2019

Coverage Status

Coverage decreased (-0.05%) to 83.788% when pulling cf778fa on check_privileges into 4b0f30a on master.

Copy link
Member Author

@dgdavid dgdavid left a comment

Choose a reason for hiding this comment

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

This a working in progress pull request yet. However, I would like to have earlier opinions or suggestions. See my self pre-review / request for comments.

@@ -166,8 +166,14 @@ def Read

::Bootloader::BootloaderFactory.current = ::Bootloader::BootloaderFactory.proposed
::Bootloader::BootloaderFactory.current.propose
rescue ::Bootloader::InsufficientPrivileges => e
Copy link
Member Author

@dgdavid dgdavid Nov 25, 2019

Choose a reason for hiding this comment

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

A self pre-review / Request for comments

I added this new exception just to follow the pattern used here (I mean, rescuing its own exception). But, to be honest, I'm not sure if

  • I like it
  • It is a good idea

Another way to do it without a custom exception is to rescue the Errno::ACCES here directly.

...
rescue Errno::ACCES
  error_msg = _(
    "The module is running without enough privileges to perform all possible actions.\n\n" \
    "Cannot continue. Please, try again as root."
  )

  Yast2::Popup.show(error_msg, headline: :error)

  return false
end

...

Shorter than the previous option but, again, I'm not sure if

  • I like it
  • It is a good idea

What do you think? Do you have any other suggestions?

Thanks in advance for your input!

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree there is no need to invent a new type of exception that is only used to directly replace Errno::ACCESS.

The current custom exceptions defined in yast2-bootloader exist because they actually describe a pretty specific circumstance that is not covered by the standard ruby. But that's not the case with that new (and unnecessary) InsufficientPrivileges class.

Based on a code review comment:

  https://github.com/yast/yast-bootloader/pull/583/files#r350677467

Basically, catch the Errno:EACCES exception direclty in Bootloader.Read
@dgdavid dgdavid changed the title [WIP] Abort the module execution when running w/o enough privileges Abort the module execution when running w/o enough privileges Nov 26, 2019
@dgdavid dgdavid marked this pull request as ready for review November 26, 2019 12:34
@ancorgs
Copy link
Contributor

ancorgs commented Nov 26, 2019

Thinking about this more widely, I wonder whether we should just use Yast::Confirm.MustBeRoot at the beginning of the wizard/client instead of waiting for the permission problems to appear later.

I'd say that's what most traditional YaST modules do.

@dgdavid
Copy link
Member Author

dgdavid commented Nov 26, 2019

@ancorgs

I didn't know about Yast::Confirm.MustBeRoot 🙄 However, after some small tests, I don't think it could be a "real" solution for this issue. It only warning to the user that "if you continue, things might not work". But allows to continue.

Click to show/hide

yast_confirm_mustberoot

And what I'd like to do is abort the execution. To me, it makes no sense to

  • YaST: "hey, if you continue something wrong could happen"
  • User: "it doesn't matter, let's Continue"
  • YaST: "ok, here you have a crash"
Click to show/hide a video

yast_confirm_mustberoot_but_continue

or even worst

  • YaST: "hey, if you continue something wrong could happen"
  • User: "it doesn't matter, let's Continue"
  • YaST: "you don't know what are you doing my dear user. Let's Abort"

Am I missing something? Sorry for the noise :(

@ancorgs
Copy link
Contributor

ancorgs commented Nov 26, 2019

Yes, you are right. The approach you implemented makes more sense from a user POV. But, please add a comment in that rescue block mentioning that not using MustBeRoot was a conscious decision.

dgdavid added a commit that referenced this pull request Nov 26, 2019
Suggested during the review.

See #583 (comment)
Tue Nov 26 12:22:50 UTC 2019 - David Diaz <dgonzalez@suse.com>

- Abort the execution when the module run without enough
permissions (related to bsc#1137688).
Copy link
Contributor

Choose a reason for hiding this comment

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

It's actually hard to see the relationship with bsc#1137688, but I trust you ;-)

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, it's hard also to me. It's what I said in a comment in the Trello card 🤷‍♂️

# wizard/client is not enough since it allows continue.

Yast2::Popup.show(
# TRANSLATORS: warn to the user that is running the module without enough permissions
Copy link
Contributor

Choose a reason for hiding this comment

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

Is really that useful to have a message to the translators to tell them what is already said in the string itself?

Something like TRANSLATORS: pop-up message, beware the line breaks would actually be useful, but the current one...

Copy link
Member Author

@dgdavid dgdavid Nov 26, 2019

Choose a reason for hiding this comment

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

Answer: actually no.

Thanks for the suggestion :)

Suggested during the review.

See #583 (comment)
Copy link
Contributor

@ancorgs ancorgs left a comment

Choose a reason for hiding this comment

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

LGTM

@dgdavid dgdavid merged commit 8630995 into master Nov 27, 2019
@dgdavid dgdavid deleted the check_privileges branch November 27, 2019 08:40
@yast-bot
Copy link
Contributor

✔️ Public Jenkins job #40 successfully finished
✔️ Created OBS submit request #751215

@yast-bot
Copy link
Contributor

✔️ Internal Jenkins job #14 successfully finished
✔️ Created IBS submit request #206200

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.

None yet

4 participants