-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security][SecurityBundle] Add messages and score on votes #58107
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 8000 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
Conversation
5a4fbe1
to
fc77e53
Compare
src/Symfony/Component/Security/Core/Authorization/AccessDecision.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authorization/AccessDecision.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authorization/Voter/Vote.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authorization/Voter/Vote.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authorization/Voter/VoteInterface.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authorization/Voter/VoteInterface.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Exception/AccessDeniedException.php
Outdated
Show resolved
Hide resolved
6e67169
to
71d7744
Compare
@eltharin hi 👋🏻 nice to see that you are willing to take over this amount of work, incremented overtime by different coders and reviewers :) i am still interested in such feature even though now I rarely use voter, still thinking that this can be a great addition in core (like workflow transition blocker message is available) to be honest, I think I would probable split this in 2 separates PRs, just to ease review and reduce the friction already existing around such feature, as it needs to arrive on a simple/BC/evolutive/maintainable way in core
in any way, I will add a reminder to make a review on this PR as well :) ( PS: @noniagriconomie is one old account of mine no more used since ) |
you and other are the firsts to thank for the start of this work, For the 2 PR's I thought about it but it's absolutlly linked, both needs Vote Object so getVote function so GetDecision functions, Remove first or second feature but keep other one will only touch few files compared with all files changed. At start, i saw your PR's without really needed, but when I wrote myine for scoring, I saw I made the same work as you, so I included your work in these to not have conflict when one will be accepted. As it's a big update to add all these functions in symfony core I add a new benefit to this to have more chance to see this PR passed :) |
46b15e0
to
e9f63ce
Compare
Did anyone ever run performance checks on these changes? Considering that Voters can be called hundreds of times per request, any overhead created by hundreds of new Vote() instances or checks for existing methods should imo be avoided (e.g. add new interfaces so I can opt-in to the new approach, instead of forcing the code upon everyone). |
e9f63ce
to
278f259
Compare
src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authorization/Strategy/ScoringStrategy.php
Outdated
Show resolved
Hide resolved
@@ -40,29 +43,38 @@ public function __construct( | |||
|
|||
public function decide(\Traversable $results): bool | |||
{ | |||
return $this->getDecision(new \ArrayIterator(array_map(fn ($vote) => new Vote($vote), iterator_to_array($results))))->isGranted(); |
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.
perhaps create a trait to avoid copy/past such internal ?
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.
instead of requiring an array of Vote, it might be more convenient to allow an array of Vote|int?
this would make the implementation trivial
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.
Problem is for those who have custom classes, if someone made a custom strategy with decide function witch take only booleans, tomorrow we will pass Vote object and booleans IT will fail,
To avoid BC, we are obliged to have two functions,
Same for Voter with vote/getVote
src/Symfony/Component/Security/Core/Authorization/Voter/Vote.php
Outdated
Show resolved
Hide resolved
278f259
to
84f75b9
Compare
I look with Symfony Profiler, with 3000 voters With 7.2 actual version VoteListener take 120MiB in 8ms with this PR, 118MiB for 8.4ms. |
friendly ping @chalasr as default reviewer |
2f1bc20
to
8d38717
Compare
fe4a1c6
to
793b302
Compare
793b302
to
17cbdf8
Compare
This comment was marked as resolved.
This comment was marked as resolved.
I think I nailed it: instead of passing by reference, we can pass pre-constructed objects. |
BTW, this makes me realize that the AccessDecision object is never used in the end. We pass it around, we collect votes in it, and we trash it. The profiler doesn't need that object. Maybe we can remove this part? |
AccessDecision Object is send to Profiler AND Exception to retreive why this reason with votes. |
I'm sorry I don't understand your comment. What did my approach lose? The only thing I removed from a feature pov is adding a reason to the access decision itself. |
sorry I miss something in your code... |
for allowMultipleAttributes argument, it's not from my PR, I just put it into comments in interface to rember it but It already been there. |
And in the strategy we don't have Vote Object ? |
I don't get what this means sorry.
this argument is an implementation detail, it shouldn't become an API. I moved it to the AccessDecision object but I suppose it can be kept as an argument, after the added $accessDecision. I'll see how this idea fits on by PR.
No, because it's not needed to achieve the purpose of this PR. |
What I say is the argument allowMultipleAttributes already exist now, it's not me who create it.
purpose is to open Vote process, by creating a VoteInterface, it allow developer to integrate a custom configuration with its own properties to have a custom strategy using it. I don't think to make all thoses changes "just" to print some message is very useful... |
I'm going to submit my patch as a separate PR, with only the "reason" feature. That's what people are asking for in all linked PRs/issues so many others do think it would be useful. Then, I'll invite you to submit the scoring strategy as a separate and follow up PR. At the moment, I don't get what you want to achieve on this topic so having it split will help understand where we want to go, and why. |
Follow up PR at #59771 |
I agree your approach works, I just said with a small patch (post below) we improve DX from "add a message in a vote" to make a full customizable Vote Process. I really think it's a shame to stop work for so little benefic Now for your PR, I think it can be a BC when Dev create a custom AccesManager copying decide function (with existing $allowMultipleAttributes argument, they receive message : |
Let's resolve this once for all: this argument is not part of any abstract API. It's only part of the concrete (Traceable)AccessDecisionManager, and if you extend it, BC is kept. About your patch:
|
OK. |
Absolutely |
…e (nicolas-grekas) This PR was merged into the 7.3 branch. Discussion ---------- [Security] Add ability for voters to explain their vote | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | Fix #27995, #26343, #35592, #43147 | License | MIT This PR takes over #58107, which itself took over from #46493, etc. It takes the only approach I could think of that would preserve BC. The visible tip of what this achieves is:   Internally, this provides a new access audit log infrastructure that relies on new `AccessDecision` and `Vote` objects. Note that I didn't add (nor fix) tests for now. I'll borrow (and credit) from #58107 / #46493 as much as possible. Commits ------- c6eb9ae [Security] Add ability for voters to explain their vote
Here is : #60085 |
This PR continue the work started by @maidmaid and @noniagriconomie in #35592, continued by @yellow1912 in #43147 continued by @alamirault in #46493.
I rebase on 7.2 and remove deprecation as suggested by nicolas-grekas for not causing backward compatiblity breaks.
It allow to have informations about AccessDecisionManager and Voters (And understand why we have an AccessDeniedException with clear infos).

I add possibility to respond a voter with a score and create a Scoring strategy, looks like consensus but with ponderation.