-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[DX] Fix the documentation about the Symfony security #4158
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
Comments
Another reason why it is important to fix it: the expression-language security functions added in 2.4 (with the annotation in FrameworkExtraBundle 3.0) are defining |
Hi guys! A few thoughts/questions:
Thanks! |
@weaverryan Regarding the distinction between roles and attributes, I think the fact that the doc does not explain this distinction is the source of many support requests about custom voters: the doc starts by saying that roles start with ROLE_, then talks about some special |
@stof Thanks for the explanation. But from a usability perspective, I still think it's not great. About your second paragraph, these are really clear reasons and it helps a lot. And now I agree that we should make a distinction between roles and attributes. |
@weaverryan the goal of |
Why not simply remove the role feature for Symfony 3.0 and then only speak about attributes? |
@yguedidi roles are something coming from the user: there is
Removing the roles would make it much harder to use the security system (or would force people to reimplement it in their own code, which makes the removal a bad option for DX) |
Thanks @stof for your awsome answer! |
@yguedidi but there is not Attributes are not even checked for a user, but for a token and an (optional) object being checked. |
@stof sorry but there is a
That's just an idea. Then we can talk about roles as special attributes. Maybe we could move roles feature to security bundle and have only attributes in the component? I say again that a talk about |
@yguedidi but |
@stof ah, do I misunderstand something? |
ping @stof |
@yguedidi |
Thank you @stof. |
@yguedidi this method is meant to check whether the voter supports the permission attribute being voted one. It has nothing to do with token attributes (the authorization part of the security component deals with permission attributes). |
@stof I know that those methods are not used and will be removed, sorry I forgot to mension that. |
@yguedidi yeah, right. Permission attributes are what you pass as first argument to |
@stof OK thank you. |
I don't understand your proposal. We already vote on attributes. And this is precisely the reason of the confusion in the doc, because the doc considers that everything we vote on is a role, while we can vote on much more thinkgs than roles. |
@stof OK well. I know voters vote on attributes (
I should miss something. Voters get a token as a parameter, so I think current session's permissions are stored as attributes in the token. Then, voters vote on attributes. Roles are "just" attributes that start with Sorry to take you time answering to this @stof. |
@yguedidi using classes for the roles is something we are considering to remove for 3.0: symfony/symfony#8313 (comment) And |
to be more precise, if we need to find an owner for the concept of attributes, it is the code performing an authorization check with |
@stof I called them "token attributes" to differenciate them from the attributes given to
The token interface has a |
Except that this setter is not related to permission attributes. It is related to what you suggest renaming to
Let me repeat it again, permission attributes are not stored in the token. Only roles are stored there. ACLs are stored in your database (based on the username stored in the token and the identity of the object being voted on), expressions are not stored anywhere (they are evaluating the permission dynamically), and And any attempt to enforce having permission attributes being stored in the token would force removing features from the authorization system, as most of them cannot be implemented based on stuff stored in the token (to be honest, a few of them could be implemented this way if you accept them to be hundred times slower and affecting performance even when the check is not performed in the given request). And if you expect attributes to be stored in the token but don't put them in it at creation time, when do you do it ? When voting on the attribute ? this makes the storage useless as it still mean that voters hold the complete logic they have now, and are expected to add the attribute in the token after that, thus leaking memory by storing stuff your app does not need anymore.
There is nothing like a non-existent attribute, given they can be anything (even something else than strings). The only concept you could have is unsupported attributes, i.e. an attribute for which all voters abstained voting. Currently, unsupported attributes are either always accepted or always rejected depending on your configuration. There is a proposal in symfony/symfony#11742 to throw an exception in this case instead, as it is generally a mistake.
I think the issue is that you are trying to introduce a third concept which does not exist in Symfony (while the current issue is related to the fact that the documentation already mixes the 2 existing concepts instead of differentiating them). These are the 2 concepts which exist:
|
Wahou, thank you @stof, especially when you write that "token attributes" are about authentication.
So back to my proposal, and as role classes will be deprecated in favor of a string representation, why limit things to roles? |
@stof any thoughts about that proposal? |
@yguedidi renaming them to permissions would be confusing IMO, given that not all permissions will be stored there. |
I ended up in here when trying to find out what the token methods did @stof So what is their intention? What are they supposed to be used for? If they are not for Authorization, what's their Authentication intent? You mentioned they are used inside voters, but that's Authorization. |
We agree that the Symfony Security docs need a lot of improvements. This is in our priority list ... but it's taking us a lot of time because of the massive complexity of the Security internals. In any case, to focus all our discussions about this in one place, we've created a meta issue in #7496 and we've linked this issue from there. That's why we're closing your issue ... but only to avoid duplicated discussions. We won't forget about what you said here. Thanks! |
If you read this DX issue regarding the security roles, you can read one of the usual awesome replies by @stof: symfony/symfony#11728 (comment)
You'll see that the Security chapter and cookbooks need some serious improvements. Given that we are talking about Security, I think that this should be a high priority issue.
For now, this is the roadmap of changes to make:
IS_AUTHENTICATED_*
are roles. They are not.The text was updated successfully, but these errors were encountered: