WIP: Allow dropping and elevating owner permissions #5419
No reviewers
Labels
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 project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!5419
Loading…
Reference in a new issue
No description provided.
Delete branch "Jackenmen/su_and_sudo"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description of the changes
Supersedes #3999, fixes #3598
New user features
--enable-sudoflag that enables this whole functionality[p]su/[p]unsucommands that allow the bot owner to elevate/de-elevate their bot owner permissions[p]sucommand will automatically de-elevate after a configurable timeout (15 minutes by default) passes[p]sudo <command>command that allows the bot owner to run a specific command with bot owner permissions while keeping de-elevated permissions for everything elseImplementation
The feature is quite cool, I must say that... I cannot however say the same about the way this is (and probably how it has to be) implemented.
On the high level, this implementation provides 2 separate properties:
all_owner_idsandowner_ids. The former is a simple (frozen) set which is pretty much the same as what we have in current stable releases underowner_idsproperty.owner_idsin this implementation is where the magic happens. It magically provides you IDs of owners that are elevated in the current context and it is used for all kinds of bot owner checks likebot.is_owner(),@commands.is_owner(), etc. This all sounds relatively straightforward until we dive into how all of this "magic" is done.Internally, we have a
ContextVarthat keeps track of owners with elevated privileges in the different contexts. Wheneverowner_idsis accessed, we get the current value of that context var, or if it's not set, we use the current "globally" elevated owner IDs (as in the ones that are currently elevated through[p]sucommand). The context var is set for each processed command which means that within the context of the command, it is a constant, and the changes that are made with[p]su/unsu/sudowhile it runs do not affect it. Becauseasyncio.Tasks have their own context, setting a value of a context var does not set that value in the global context and therefore accessing the global context will keep giving us the current "globally" elevated owner IDs as the default.So based on this, we can expect that whenever the user runs the command, the command will get the currently elevated owner IDs when it tries to access
owner_idsand the changes made to the global context during its runtime will not affect it. For better or worse, this however also means that any tasks spawned within that command will inherit the value ofowner_idsthat was set for it right before its execution. This is quite intentional for short-lived tasks like waiting for a message or reaction but might not be something that cog creator wants when trying to spawn a long-lived task that needs to access the currently elevated owner ids. Another somewhat similar problem is that the same long-lived tasks can also be created on cog load and they inevitably will inherit the value ofowner_idsthat was set for[p]load.Currently, this is a limitation that I have not really tried addressing (and I don't exactly have an idea how to address it) and I'm not sure how much we can do if we don't want to make APIs completely impractical.
Ich habe den PR geprüft und lasse ihn offen. Er ist WIP, der Autor beschreibt die Implementierung selbst als unschön, und er greift tief in die Owner-Prüfung ein (
is_owner, Checks, Permissions-Cog). Ein falscher Merge würde dort direkt die Sicherheit betreffen. Ein Port auf den aktuellen Stand ist möglich, sollte aber mit einem frischen Review und Tests fürsu/unsu/sudopassieren.Generated by Claude Code
Auf Wunsch des Repo-Owners geschlossen; die Gründe stehen im Kommentar oben. Der PR kann jederzeit wieder geöffnet oder neu eingereicht werden.
Generated by Claude Code
Pull request closed