[Core] Add su and unsu and sudo <command> commands to bot #3999

Closed
Drapersniper wants to merge 33 commits from sudo into V3/develop
Drapersniper commented 2020-06-21 21:17:05 +02:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

This PR does a couple of things.

  1. It adds [p]su which allows a bot owner to elevate themselves to currently bot owner level.
  2. It adds [p]unsu which allows a bot owner to delavate their permissions back to a standard user
  3. Makes [p]su and [p]unsu always avaliable to bot owners.
  4. By default at bot start up the no bot owners have elevated permissions until [p]su is run

So theres a couple of things that can be done/changed here.

  1. we could add a CLI flag to toggle this behaviour. without the CLI flag the bot would behave exactly as it does now with bot owners always in an elevated state
  2. Add tasks to auto delevate a bot owner after N minutes

The reasoning behind this PR is that bot owners should not have elevated permissions by default and should only elevate themselves when needed (for example a user will need to run sudo on terminal to elevate their shell, and even here after a period of time the user will need to reelevate themselves).

I would appreciate any feedback on behaviour and discussion on default behaviour introduced by this PR.

resolves #3598

### Type - [ ] Bugfix - [ ] Enhancement - [x] New feature ### Description of the changes This PR does a couple of things. 1. It adds `[p]su` which allows a bot owner to elevate themselves to currently bot owner level. 2. It adds `[p]unsu` which allows a bot owner to delavate their permissions back to a standard user 3. Makes `[p]su` and `[p]unsu` always avaliable to bot owners. 4. By default at bot start up the no bot owners have elevated permissions until `[p]su` is run So theres a couple of things that can be done/changed here. 1. we could add a CLI flag to toggle this behaviour. without the CLI flag the bot would behave exactly as it does now with bot owners always in an elevated state 2. Add tasks to auto delevate a bot owner after N minutes The reasoning behind this PR is that bot owners should not have elevated permissions by default and should only elevate themselves when needed (for example a user will need to run `sudo` on terminal to elevate their shell, and even here after a period of time the user will need to reelevate themselves). I would appreciate any feedback on behaviour and discussion on default behaviour introduced by this PR. resolves #3598
palmtree5 (Migrated from github.com) reviewed 2020-06-21 21:17:05 +02:00
tekulvw (Migrated from github.com) reviewed 2020-06-21 21:17:05 +02:00
Jackenmen (Migrated from github.com) reviewed 2020-06-21 21:17:05 +02:00
aikaterna (Migrated from github.com) reviewed 2020-06-21 21:17:05 +02:00
flaree commented 2020-06-21 21:25:33 +02:00 (Migrated from github.com)

I feel as if the owners should have the elevated privileges by default. A lot of users may only host for their needs and this would hinder their setup, maybe a flag to have it off by default?

I feel as if the owners should have the elevated privileges by default. A lot of users may only host for their needs and this would hinder their setup, maybe a flag to have it off by default?
yamikaitou commented 2020-06-21 21:28:34 +02:00 (Migrated from github.com)

Personally, if I think the default should be unelevated for Team Tokens. If the bot is being run with just a single owner, it should default to elevated. If Co-Owners are used, maybe elevate the Token owner and unelevate the co-owners by default?

The idea of being able to "unsudo" is nice though, save us from having to always test stuff with an alt

Personally, if I think the default should be unelevated for Team Tokens. If the bot is being run with just a single owner, it should default to elevated. If Co-Owners are used, maybe elevate the Token owner and unelevate the co-owners by default? The idea of being able to "unsudo" is nice though, save us from having to always test stuff with an alt
Jackenmen commented 2020-06-21 21:37:20 +02:00 (Migrated from github.com)

We could put a recommendation to enable this functionality somewhere in our docs, but I really don't think we should make this a default. I also think that status-quo wins by default so IMO we would need very good reasons to change the current default behavior and they imo would need to outweight the reasons for the current behavior.

For one, we have a lot of less-knowledgeable users and this is yet another obstacle thrown at them.

I personally also don't think that [p]sudo actually necessarily has to make that much sense if your bot is in one (or few) servers. In these cases, I would be quite surprised if the person owning the bot isn't at least a very trusted mod (since mods don't have perms to add bots) and I would assume that usually they might be even admins or guild owners. Adding [p]sudo as default makes the management of the bot harder by default and considering that currently this is discussed as a cli flag, it would require the user to always put additional flags when running the bot if they want to disable this. Truth to be told, they should be running auto-restart service, but there might be some less or more valid reasons why they don't.

Last but not least, while the point of what should be the default is debatable, there definitely needs to be a way that allows you to (depending on what will be chosen by default) enable/disable this functionality.

We could put a recommendation to *enable* this functionality somewhere in our docs, but I really don't think we should make this a default. I also think that status-quo wins by default so IMO we would need very good reasons to change the current default behavior and they imo would need to outweight the reasons for the current behavior. For one, we have a lot of less-knowledgeable users and this is yet another obstacle thrown at them. I personally also don't think that `[p]sudo` actually necessarily has to make *that* much sense if your bot is in one (or few) servers. In these cases, I would be quite surprised if the person owning the bot isn't at least a very trusted mod (since mods don't have perms to add bots) and I would assume that usually they might be even admins or guild owners. Adding `[p]sudo` as default makes the management of the bot harder by default and considering that currently this is discussed as a cli flag, it would require the user to always put additional flags when running the bot if they want to disable this. Truth to be told, they should be running auto-restart service, but there might be some less or more valid reasons why they don't. Last but not least, while the point of what should be the default is debatable, there **definitely needs to** be a way that allows you to (depending on what will be chosen by default) enable/disable this functionality.
Jackenmen commented 2020-06-21 21:43:22 +02:00 (Migrated from github.com)

From other things:

  • names of the commands can still be discussed - sudo definitely makes sense for us, but it might not be the most user-friendly for people that aren't familiar with Unix
    • also, there is at least one approved 3rd-party cog that already takes use of this command name
  • the implementation here is very important, so if this change affects someone's cogs, it's important for us to know it now
From other things: - names of the commands can still be discussed - `sudo` definitely makes sense for us, but it might not be the most user-friendly for people that aren't familiar with Unix - also, there is at least one approved 3rd-party cog that already takes use of this command name - the implementation here is very important, so if this change affects someone's cogs, it's important for us to know it now
Dav-Git commented 2020-06-21 22:02:54 +02:00 (Migrated from github.com)

I agree with what jack said. I believe this is a cool feature but the default shouldn't be changed.

As for names of the commands...
I think a "ownermode" setting would make more sense to users that are unfamiliar with unix.

This could either be made part of [p]set though this time contrary to the proposed audio changes I'd agree to having them as standalone command. Maybe [p]ownermode enable and [p]ownermode disable? Potentially a book converter instead of seperate commands.

I agree with what jack said. I believe this is a cool feature but the default shouldn't be changed. As for names of the commands... I think a "ownermode" setting would make more sense to users that are unfamiliar with unix. This could either be made part of ``[p]set`` though this time contrary to the proposed audio changes I'd agree to having them as standalone command. Maybe ``[p]ownermode enable`` and ``[p]ownermode disable``? Potentially a book converter instead of seperate commands.
Jackenmen commented 2020-06-21 22:06:27 +02:00 (Migrated from github.com)

I don't have anything specific against the ownermode name in itself, but one thing to note here is that it might be a little bit long considering that owner will need to run it whenever they want to use some owner-only command (though only once within the set timeout). It is not hard to add an alias though so I guess it wouldn't necessarily be that problematic.

I don't have anything specific against the `ownermode` name in itself, but one thing to note here is that it might be a little bit long considering that owner will need to run it whenever they want to use some owner-only command (though only once within the set timeout). It is not hard to add an alias though so I guess it wouldn't necessarily be that problematic.
Drapersniper commented 2020-06-21 22:06:59 +02:00 (Migrated from github.com)

Added [p]sudotimer which will allow bot owners to set a time so that the sudo priviledges auto expire.

Added the --enable-sudo cli.

Added `[p]sudotimer` which will allow bot owners to set a time so that the sudo priviledges auto expire. Added the `--enable-sudo` cli.
Jackenmen commented 2020-06-21 22:08:24 +02:00 (Migrated from github.com)

I think [p]set sudotimer (or [p]set sudotimeout) would make more sense here

I think `[p]set sudotimer` (or `[p]set sudotimeout`) would make more sense here
Jackenmen (Migrated from github.com) reviewed 2020-06-21 22:11:04 +02:00
Jackenmen (Migrated from github.com) commented 2020-06-21 22:11:03 +02:00

By putting this here, you moved the help formatter line a little more below the comment about it

        self._help_formatter = commands.help.RedHelpFormatter()
        self.add_command(commands.help.red_help)
        if self._sudo_enabled is False:
            self._true_owner_ids = self.owner_ids
By putting this here, you moved the help formatter line a little more below the comment about it ```suggestion self._help_formatter = commands.help.RedHelpFormatter() self.add_command(commands.help.red_help) if self._sudo_enabled is False: self._true_owner_ids = self.owner_ids ```
mikeshardmind commented 2020-06-21 23:38:25 +02:00 (Migrated from github.com)

This can be enabled more elegantly with a kwarg to is_owner check based on my own use of similar in the past.

This can be enabled more elegantly with a kwarg to is_owner check based on my own use of similar in the past.
Jackenmen (Migrated from github.com) requested changes 2020-09-20 02:41:31 +02:00
Jackenmen (Migrated from github.com) left a comment

I don't know what's the view of org members on this functionality, so I wouldn't be able to approve this either way, but here's a code review.

From things not included in review comments:

  • are we sure we want to call these sudo/unsudo? I do like these names myself, but as mentioned earlier, there could be better choices we (mostly you and I, I guess) didn't think of
  • can it possibly be important for 3rd-party cogs to know "true owners"? If it could be (and I'm quite worried it might), then we need this to be exposed in the API
    • one could also say that modifying what is put in owner ids is changing behavior and therefore breaking. The importance of this needs to be determined.
I don't know what's the view of org members on this functionality, so I wouldn't be able to approve this either way, but here's a code review. From things not included in review comments: - are we sure we want to call these `sudo`/`unsudo`? I do like these names myself, but as mentioned earlier, there could be better choices we (mostly you and I, I guess) didn't think of - can it possibly be important for 3rd-party cogs to know "true owners"? If it could be (and I'm quite worried it might), then we need this to be exposed in the API - one could also say that modifying what is put in owner ids is changing behavior and therefore breaking. The importance of this needs to be determined.
Jackenmen (Migrated from github.com) commented 2020-09-20 02:19:24 +02:00

nitpick, _AlwaysAvailableMixin is an unneeded subclass here.

nitpick, `_AlwaysAvailableMixin` is an unneeded subclass here.
Jackenmen (Migrated from github.com) commented 2020-09-20 02:21:56 +02:00

This might make more sense as a cancellable task - currently using [p]sudo, [p]unsudo after 5 minutes, and [p]sudo right after will lead to "sudo time" being shorter by 5 minutes.

This might make more sense as a cancellable task - currently using `[p]sudo`, `[p]unsudo` after 5 minutes, and `[p]sudo` right after will lead to "sudo time" being shorter by 5 minutes.
Jackenmen (Migrated from github.com) commented 2020-09-20 02:26:13 +02:00

Why remove dot here?

Why remove dot here?
Drapersniper commented 2020-09-28 14:42:50 +02:00 (Migrated from github.com)

So in theory this is ready to merge, although @TrustyJAID asked for the sudo command to accept commands, this would make it so it runs a singular command as sudo, and then it would auto remove sudo from you after, this needs to be looked into further before it is properly implemented.

So in theory this is ready to merge, although @TrustyJAID asked for the sudo command to accept commands, this would make it so it runs a singular command as sudo, and then it would auto remove sudo from you after, this needs to be looked into further before it is properly implemented.
Drapersniper (Migrated from github.com) reviewed 2020-09-28 15:06:53 +02:00
@ -193,0 +197,4 @@
if "owner_id" in kwargs:
raise RuntimeError("Red doesn't accept owner_id kwarg, use owner_ids instead.")
Drapersniper (Migrated from github.com) commented 2020-09-28 15:06:52 +02:00
        raise RuntimeError("Don't try to delete this attribute")
```suggestion raise RuntimeError("Don't try to delete this attribute") ```
Drapersniper commented 2020-10-01 13:23:56 +02:00 (Migrated from github.com)

So adding the optional arg is gonna be far more painful than antecipated, since this PR is not dependent on it i would suggest we leave that for a follow up PR and keep this PR as it is.

So adding the optional arg is gonna be far more painful than antecipated, since this PR is not dependent on it i would suggest we leave that for a follow up PR and keep this PR as it is.
Drapersniper commented 2021-06-02 23:36:47 +02:00 (Migrated from github.com)

Keeping this one open as jack spent a lot of time on it already.

Keeping this one open as jack spent a lot of time on it already.

Pull request closed

Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!3999
No description provided.