Skip to content

audit: ignore group write bit#7073

Merged
MikeMcQuaid merged 1 commit intoHomebrew:masterfrom
alexreg:issue-7068
Mar 6, 2020
Merged

audit: ignore group write bit#7073
MikeMcQuaid merged 1 commit intoHomebrew:masterfrom
alexreg:issue-7068

Conversation

@alexreg
Copy link
Copy Markdown
Contributor

@alexreg alexreg commented Feb 24, 2020

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew tests with your changes locally? (Well, actually no, but I get failures normally, and PR introduces no new ones as far as I can tell.)

Fixes #7068.

@alexreg
Copy link
Copy Markdown
Contributor Author

alexreg commented Feb 24, 2020

This PR is in response to the above issue and specifically #7068 (comment). Please let me know if this is the sort of solution you'd like. (It seems reasonable to me, and fairly conservative.)

Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Looks good so far, a few tweaks.

Comment thread Library/Homebrew/dev-cmd/audit.rb Outdated
Comment thread Library/Homebrew/dev-cmd/audit.rb Outdated
Comment thread Library/Homebrew/dev-cmd/audit.rb Outdated
Comment thread Library/Homebrew/dev-cmd/audit.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this be simplified a bit? It's a bit hairy as-is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it is... Sadly, I don't think so. The obvious way to understand it is that actual_mode & 0020 select the group write bit from the actual file mode (i.e., gives either 0020 or 0000) and then sets the corresponding bit on 0100644 if so. i.e., it takes 0100644 and adds the group write bit if and only if the group write bit is set on the actual fine -- which makes it 0100664 instead. I think it's right that & ~File.umask should remain as the outermost bit operation, right? Anyway, if you want me to put another comment in for this, or rework it into a form you have in mind, let me know. :-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about just checking the individual bits?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@MikeMcQuaid Yep, that occurred to me too, but wanted_mode is used for the diagnostic message just below, which makes this calculation quite convenient I think.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the message should change too. It's no longer particularly accurate if we're going to ignore the group bit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, the problem is now: what if the above conditions are all satisfied, but the umask is more restrictive? Should we honour that or not? If so, it means a 4th problem message potentially, which awkward, since it would effectively make the previous ones redundant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(Per the above, if we want to respect the umask, I think my previous approach works best. Otherwise, we can go with yours.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure I fully understand how we currently honour or do not the umask. Can you explain a case in which it would affect an audit failure and what your opinion is on what we should do? Thanks ❤️

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As I understand, the current behaviour is basically that the umask is used to "mask out" (clear) certain bits when incorrect permissions are found and a chmod is suggested (with a numeric rather than a symbolic argument). The Wikipedia page on umask has an interesting sentence:

Generally, the mask only affects file permissions during the creation of new files and has no effect when file permissions are changed in existing files, however, the chmod command will check the mask when the chmod options are specified using symbolic mode and a reference to a class of users is not specified.

Obviously, we are not dealing with the creation of files here. The question is, is our situation analagous to a symbolic change without a reference to a class of users (i.e., something like +r as opposed to g-w, the latter making a reference to the class of users g). I would say no, so that we can probably just not worry about the umask. What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would say no, so that we can probably just not worry about the umask. What do you think?

Agreed!

@alexreg
Copy link
Copy Markdown
Contributor Author

alexreg commented Feb 24, 2020

Okay, amended per your comments; just left your last comment unresolved for now, so you can let me know your thoughts. Is the above test failure spurious or something? It doesn't seem like it has anything to do with my changes at least.

Comment thread Library/Homebrew/dev-cmd/audit.rb Outdated
@alexreg
Copy link
Copy Markdown
Contributor Author

alexreg commented Mar 3, 2020

@MikeMcQuaid Pushed a new version just now, following our discussion. Hope this is closer to the ideal solution. :-)

Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

brew style is failing but otherwise: yeh, this looks much better and easier to follow. Great work!

@alexreg
Copy link
Copy Markdown
Contributor Author

alexreg commented Mar 5, 2020

@MikeMcQuaid Thanks. Fixed style issues and pushed.

@MikeMcQuaid
Copy link
Copy Markdown
Member

Thanks so much for your first contribution! Without people like you submitting PRs we couldn't run this project. You rock, @alexreg!

@MikeMcQuaid MikeMcQuaid merged commit 78140ce into Homebrew:master Mar 6, 2020
@alexreg
Copy link
Copy Markdown
Contributor Author

alexreg commented Mar 6, 2020

@MikeMcQuaid No problem; thanks for reviewing.

@lock lock bot added the outdated PR was locked due to age label Apr 15, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated PR was locked due to age

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should brew audit complain about incorrect file permissions?

2 participants