Skip to content
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

Non-support of PrincipalPermissionAttribute #31279

Closed
ericjohannsen opened this issue Oct 23, 2019 · 6 comments · Fixed by #37536
Closed

Non-support of PrincipalPermissionAttribute #31279

ericjohannsen opened this issue Oct 23, 2019 · 6 comments · Fixed by #37536
Labels
area-System.Security question Answer questions and provide assistance, not an issue with source code or documentation. untriaged New issue has not been triaged by the area owner

Comments

@ericjohannsen
Copy link

As best I can determine from my own test code (against 3.0.0) and as mentioned in #17693, PrincipalPermissionAttribute exists as a type but has no effect. MSDN also states "This attribute has no effect in .NET Core."

This seems dangerous, as a user porting existing code might expect that, if the attribute compiles, that it also functions. Since the purpose of this attribute is security, the consequences of a false assumption could be significant.

Is it a well-considered opinion that the attribute should exist yet be non-functional (not even a compiler warning...) or is this a decision warranting review?

@jkotas
Copy link
Member

jkotas commented Oct 24, 2019

The methods for creating partial trust context throw or do not exist at all in .NET Core.

For example, PermissionSet.Deny() throws PlatformNotSupportedException in .NET Core: https://github.com/dotnet/corefx/blob/d58a51f911efb3c98beca21b6cf08cc703424fdf/src/Common/src/CoreLib/System/Security/PermissionSet.cs#L30

If your ported program depends on partial trust permissions, you will get an error much earlier, long before these permission attributes would come into play.

@ericjohannsen
Copy link
Author

This isn't about partial trust. The following is perfectly valid permission enforcement in a .NET Framework business class. It compiles just fine in .NET Core but fails the essential task of controlling access:

public class Foo
{
  [PrincipalPermission (SecurityAction.Demand, Role = "finance")]
  public IEnumerable<Salary> GetEmployeeSalaries() => ...;
}

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@GrabYourPitchforks
Copy link
Member

GrabYourPitchforks commented Feb 14, 2020

@jkotas This makes me think we should obsolete some types (like PrincipalPermissionAttribute) as error. Since we don't support the CAS infrastructure in Core we should fail at compilation when these types are involved, as otherwise they'll incorrectly give the illusion that they work properly.

@GrabYourPitchforks
Copy link
Member

Quite possibly all of the CAS-related attributes, now that I think more on it. If you manually new up a permission object and call Demand you'll get PNSE as expected. But since the runtime isn't looking at the attributes at all there's nobody to trigger the PNSE.

@jkotas
Copy link
Member

jkotas commented Feb 15, 2020

I fully support marking all CAS-related APIs as obsolete, once we get the more fine grained controls for obsolete warnings in place.

@GrabYourPitchforks
Copy link
Member

Related: #1698 (comment), which ponders the consequences of a "fail open" policy where developers don't expect it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Security question Answer questions and provide assistance, not an issue with source code or documentation. untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants