-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
refactor(permissions): split up Descriptor into Allow, Deny, and Query #25508
Conversation
Any chance taking a look at #14668 during this refactor ? |
@lowlighter no, that would be too many changes for this PR. |
// todo(dsherret): don't have this function use the properties of | ||
// permission container | ||
let permissions_container = state.borrow_mut::<PermissionsContainer>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's wrong with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's exposing a mutex, it's having code that shouldn't be done/exposed at this level (parsing descriptors), and it's coupling what could be its private api to this part of the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open an issue to keep track of it? Or are you planning to address it before landing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to give runtime/permissions/lib.rs
one more pass tomorrow
runtime/permissions/lib.rs
Outdated
pub trait QueryDescriptor: Debug { | ||
type AllowDesc: AllowDescriptor<Query = Self>; | ||
type DenyDesc: DenyDescriptor<Query = Self>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit confusing - effectively there are circular dependencies between these three types. Do you see any chance we could decouple that with a helper type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also could you add some docstrings around these traits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got rid of the additional traits and now there's only a QueryDescriptor.
runtime/permissions/lib.rs
Outdated
fn is_granted(&self, desc: Option<&TQuery>) -> bool { | ||
match desc { | ||
Some(desc) => { | ||
self.granted_global || self.granted_list.iter().any(|v| v.matches(desc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we using .matches()
instead of .stronger_than()
now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are multiple specific methods. I've grouped them all on query now.
runtime/permissions/lib.rs
Outdated
/// This variant can't be used to grant permissions. It's mostly | ||
/// used so that prompts and everything works the same way as when | ||
/// the command is resolved, meaning that a script can't tell | ||
/// if a command is resolved or not based on how long something | ||
/// takes to ask for permissions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you reword this docstring? I'm having trouble understanding it - what does "This variant can't be used to grant permissions" mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated it a bit. The variant gets created when the command path can't be resolved, so it will prompt the users for permissions about it, but it doesn't actually do anything when the user grants permissions. It's to prevent someone trying to probe for permissions to find out what's on the path.
// todo(dsherret): make both of these private as the functionality | ||
// can just be methods on PermissionsContainer. Additionally, a separate | ||
// struct should be created in here that handles creating child permissions | ||
// so that the code is not so verbose elsewhere. | ||
pub descriptor_parser: Arc<dyn PermissionDescriptorParser>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you open an issue about this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put it in #25634
${JSON.stringify(Object.keys(expectedEnv))}.map(k => Deno.env.get(k)) | ||
${ | ||
JSON.stringify(Object.keys(expectedEnv)) | ||
}.map(k => Deno.env.get(k) ?? null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this change required? I assume it's unrelated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined
isn't valid JSON, but null
is (it does a JSON.parse
below). I ran into this issue while developing where I introduced a bug, then it was undefined
, then the error message was not great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you benchmark these changes?
From what I can tell, we do a lot more canonicalization for FS ops now (maybe including more getcwd
calls?) - I wonder if sync FS ops will slow down due to this. From my reading of the code, this difference would only be visible in non --allow-all
contexts.
) -> Result<(), AnyError> { | ||
skip_check_if_is_permission_fully_granted!(self); | ||
let (result, prompted, is_allow_all) = self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a follow up we should change the return value here to an enum or struct. This is unreadable.
It should be doing the same or less now with --allow-all. It doesn't canonicalize like before. |
I meant without --allow-all |
Yeah should be the same without allow-run. It was doing the cwd call before as well. |
Some benchmarks:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This makes the permission system more versatile.