-
Notifications
You must be signed in to change notification settings - Fork 1
Use final matching rule when determining if a command is permitted #1
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: master
Are you sure you want to change the base?
Conversation
Before, a command was permitted only if there were no other rules denying it *anywhere* in the file. This is inconsistent with the original doas. As a side effect of the changes, this commit fixes another inconsistency where the original doas did not allow using the `nopass` option with `deny` rules, but rsudoas did.
type Error = String; | ||
|
||
fn try_from(config: &str) -> Result<Self, Self::Error> { | ||
pub fn parse_into_rules(config: &str) -> Result<Vec<Rule>, String> { |
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.
parse_into_rules()
is now incorrectly indented, but if I change the whitespace the diff becomes really hard to read >_<
Good catch, this is something I noticed as well but I had already finished the current matching logic by that time. I'm still not sure if I should switch to doas's simpler matching logic... perhaps I should offer this as a compile time option. I'd like to gather more feedback from actual doas users. Thanks for the PR in any case, mind if I ask how you stumbled upon this project? |
@@ -57,8 +57,9 @@ fn execute(opts: Execute) { | |||
config_file = file; | |||
}, | |||
} | |||
let config = std::fs::read_to_string(config_file).expect("Failed to read config"); | |||
let rules = match Rules::try_from(&*config) { | |||
// Make sure the config file ends with a newline. |
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?
@@ -308,7 +273,10 @@ pub mod config { | |||
}, | |||
Expect::OptionOrIdentity => { | |||
match (&*token, pure) { | |||
("nopass", true) => rule.options.nopass = true, | |||
("nopass", true) => match rule.action { | |||
RuleAction::Deny => return Err("The nopass option cannot be used with the deny action".to_string()), |
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 does doas do in this case?
Currently, a command is permitted only if there are no other rules denying it anywhere in the config file. This is inconsistent with the original doas. From the
doas.conf
manpage:So, given the following config file:
doas permits
l33thaxor
to runcmatrix
, but rsudoas doesn't.The key changes are:
Rules::try_from(&str)
is replaced withconfig::parse_into_rules
, which returns an ordered list of rules.Rules::r#match
is replaced withRule::matches
, which checks if an individual rule matches.As a side effect of the changes, this commit fixes another inconsistency where the original doas did not allow using the
nopass
option withdeny
rules, but rsudoas did.