Skip to content

[Security] Make it possible to give voters a weight in consensus decisions #16843

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

Closed
wants to merge 1 commit into from

Conversation

tPl0ch
Copy link

@tPl0ch tPl0ch commented Dec 5, 2015

After watching the "Dig in Security with Symfony" talk at SymfonyCon today, I
realized that there was no weighting mechanism in the current implementation.

It is not always true that each voter has the equal weight within a majority
vote. This feature PR accounts for that in a BC way.

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets None
License MIT
Doc PR None

Commit recap from rebase:

  • Introduced the WeightedVoterInterface that extends the VoterInterface
  • Added the abstract WeightedVoter as an easily usable base class
  • Added the Weight decorator to extend existing Voters with weighting
  • Refactored test structures for Voter
  • Added missing methods in Weight decorator required by VoterInterface
  • Added test case for Weight decorator
  • Added test case for abstract WeightedVoter
  • Added feature tests to AccessDecisionManagerTest
  • Implemented feature in AccessDecisionManager
  • Fixed CodingStandards
  • Removed deprecated methods from Weight decorator
  • Removed abstract method from WeightedVoter, it's provided by the interface

See #16828 for more discussion on this.

…sions

After watching the "Dig in Security with Symfony" talk at SymfonyCon today, I
 realized that there was no weighting mechanism in the current implementation.

It is not always true that each voter has the equal weight within a majority
 vote. This feature PR accounts for that in a BC way.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | None
| License       | MIT
| Doc PR        | None

Commit recap from rebase:

- Introduced the `WeightedVoterInterface` that extends the `VoterInterface`
- Added the abstract `WeightedVoter` as an easily usable base class
- Added the `Weight` decorator to extend existing Voters with weighting
- Refactored test structures for `Voter`
- Added missing methods in `Weight` decorator required by `VoterInterface`
- Added test case for `Weight` decorator
- Added test case for abstract `WeightedVoter`
- Added feature tests to `AccessDecisionManagerTest`
- Implemented feature in `AccessDecisionManager`
- Fixed CodingStandards
- Removed deprecated methods from `Weight` decorator
- Removed abstract method from `WeightedVoter`, it's provided by the interface
@xabbuh
Copy link
Member

xabbuh commented Dec 5, 2015

I am not sure if I like this to be in the core. Imho we lose a lot of clarity about the voting process compared to the previous way which might lead to much harder to debug issues especially when voters from third-party bundles you use make use of this feature too (it's not so clear anymore then why access was denied/granted).

*
* @author Thomas Ploch <profiploch@gmail.com>
*/
abstract class WeightedVoter extends Voter implements WeightedVoterInterface
Copy link
Member

Choose a reason for hiding this comment

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

this class does not make sense. It does not bring any benefit compared to extending Voter and implementing the interface directly

@stof
Copy link
Member

stof commented Dec 5, 2015

I don't think we need this feature in the core actually. So my vote is a -1

@tPl0ch
Copy link
Author

tPl0ch commented Dec 5, 2015

@xabbuh I understand your point, but to add this feature yourself you'd have to copy the AccessDecisionManager (since it contains only private methods that cannot be overridden), add your own logic, and override the class parameter for the DI service in the SecurityBundle.

So another proposed solution could be refactoring the AccessDecisionManager, extracting the private methods into small Strategy objects (ConsesusStrategy, UnanimousStrategy,...) implementing a DecisionStrategyInterface that would be injected into the Manager (currently the Manager violates the open for extension, closed for modification principle). There then could be a compiler pass looking for the tag security.decision_strategy where users can inject their own Strategies (as in WeightedConsensusStrategy).

This can be done in a complete BC way without effecting current userland code.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Dec 5, 2015 via email

@fabpot
Copy link
Member

fabpot commented Dec 5, 2015

I'm 👎 except if it's backed with a real-world use case.

@tPl0ch
Copy link
Author

tPl0ch commented Dec 5, 2015

To be honest, I was driven by the real world where "weighted consensus" is a very common concept and I just realized that this concept was missing from the current implementation. I cannot back it up with a real use case and I am actually totally OK with you guys rejecting that feature as is.

I think though that what I said in my comment #16843 (comment) still holds true. The AccessDecisionManager violates the open for extension, closed for modification principle.

@stof stof closed this Dec 5, 2015
@tPl0ch
Copy link
Author

tPl0ch commented Dec 6, 2015

@xabbuh
Copy link
Member

xabbuh commented Dec 6, 2015

I would rather make the access decision strategy configurable than introducing weighted voters in the core.

nicolas-grekas added a commit that referenced this pull request Jul 12, 2017
…ss decision manager service (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[Security] make it possible to configure a custom access decision manager service

| Q | A |
| --- | --- |
| Branch? | 3.4 |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | #942, #14049, #15295, #16828, #16843, |
| License | MIT |
| Doc PR | TODO |

These changes will make it possible to let users define their own voting strategies without the need for custom compiler passes that replace the built-in `AccessDecisionManager` (see linked issues in the PR table for some use cases).

Commits
-------

e0913a2 add option to define the access decision manager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants