Top Banner
Code Access Security Ami Dudu Software architect IDF [email protected] .il
24

Code Access Security

Jan 19, 2016

Download

Documents

Daisy

Code Access Security. A mi Dudu Software architect IDF [email protected]. Agenda. Goals Evidence-Based security Security policy Permission classes Role-based Security Common Interfaces\BaseClasses Implementing your own classes. Goals. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Code Access Security

Code Access Security

Ami DuduSoftware architect

[email protected]

Page 2: Code Access Security

Agenda

Goals

Evidence-Based security

Security policy

Permission classes

Role-based Security

Common Interfaces\BaseClasses

Implementing your own classes

Page 3: Code Access Security

Goals

Ensures that code can access only resources it has the right to accessAllows security policy to control the resource code has access to based on:

Where the code comes fromOther aspects of the code’s identity

Allows programmers to specify resources that their code

Must be able to access in order to run effectivelyCould optionally accessShould not be able to access

Page 4: Code Access Security

Possibilities

Secure our libraries

Defend our servers more effectively

Writing application using RBS

And more…

Page 5: Code Access Security

Evidence-Based security

Set of information about the identity and origin of an assembly

Uses by the .Net Framework security system at load time to determine the permissions an assembly receives

Evidence includes things such as Strong-Name, Signature, Code Location, Zone and can also be custom-defined

Page 6: Code Access Security

Security policy

Storage of the security permissionsPolicy levels: enterprise, machine, userEach level consists of a collection of hierarchical code groups, and each code group has a set of permissions (file system, registry, environment variables etc.)Final Permission set is union for same level and intersection between levels

Page 7: Code Access Security

Security Policy

Page 8: Code Access Security

Nothing

Full trust

Full trust

Calc. level permission

All CodeAll CodeNothingNothing

Zone=My ComputerZone=My ComputerFull trustFull trust

Zone=Local IntranetZone=Local IntranetIO PermissionIO Permission

SN=0xD1…SN=0xD1…Full trustFull trust

Hash=01…Hash=01…Events PermissionEvents Permission

Hash=04…Hash=04…UI PermissionUI Permission

Hash=00…Hash=00…Events PermissionEvents Permission

C:\foo.dllSN=0x00..Hash=00..

UnionUnion

Page 9: Code Access Security

Events Permission

Full trust

Nothing

Calc. level permission

All CodeAll CodeNothingNothing

Zone=My ComputerZone=My ComputerFull trustFull trust

Zone=Local IntranetZone=Local IntranetIO PermissionIO Permission

SN=0xD1…SN=0xD1…Full trustFull trust

Hash=01…Hash=01…Events PermissionEvents Permission

Hash=04…Hash=04…UI PermissionUI Permission

Hash=00…Hash=00…Events PermissionEvents Permission

http://wwwSN=0xD1..Hash=00..

Full trustUnionUnion

Page 10: Code Access Security

Full trustFull trust

Nothing

Calc. level permission

All CodeAll CodeNothingNothing

Zone=My ComputerZone=My ComputerFull trustFull trust

Zone=Local IntranetZone=Local IntranetIO PermissionIO Permission

SN=0xD1…SN=0xD1…Full trustFull trust

Hash=01…Hash=01…Events PermissionEvents Permission

Hash=04…Hash=04…UI PermissionUI Permission

Hash=00…Hash=00…Events PermissionEvents Permission

C:\foo.dllSN=0xD1..Hash=01..

Full trustUnionUnion

Page 11: Code Access Security

Playing with rights

Page 12: Code Access Security

Permissions

FileIO

Registry

Environment

Socket

Reflection

Directory Services

Printing

SQLClient

Message Queue

Event Log

DNS

And more…

Permissions represent the right to interact with a given resource

Examples:

Page 13: Code Access Security

Declarative Demands

Specify security check using attributes

Permission state must be known at compile time

Can be viewed with PermView SDK Tool or Ildasm

[FileIOPermission(SecurityAction.Demand, Write = @"C:\Temp")]private void TryToCreateAFile(){ // create a file}

[FileIOPermission(SecurityAction.Demand, Write = @"C:\Temp")]private void TryToCreateAFile(){ // create a file}

Page 14: Code Access Security

SecurityAction Enum

Demand – All callers higher in the call stack are required to have been granted the permission specified by the current permission object

LinkDemand – The immediate caller is required to have been granted the specified permission

Assert – The calling code can access the resource identified by the current permission object, even if callers higher in the stack have not been granted permission to access the resource

And More…

Page 15: Code Access Security

Imperative Demands

private void foo(string FilePath, string FileName){

FileIOPermission filePerm = new FileIOPermission(FileIOPermissionAccess.Write, FilePath);

filePerm.Demand();

// rest of the method}

private void foo(string FilePath, string FileName){

FileIOPermission filePerm = new FileIOPermission(FileIOPermissionAccess.Write, FilePath);

filePerm.Demand();

// rest of the method}

Allows security checks to vary by control flow or method state

Page 16: Code Access Security

Permission classes methods

Demand

Union

Intersect

Assert

RevertAssert

And more…

Page 17: Code Access Security

Work with permissions

Page 18: Code Access Security

Role-based security

Role-Based security allows access to code and resources based on:

The user’s Identity

The roles or groups to which the user belong

Role-Based security based on Principals and Identities classes

Page 19: Code Access Security

Role-based security

Identity information typically consists of the user name and the roles associated with the user

In .Net Framework identity encapsulates the user’s login name, and the principal encapsulates the user’s role membership information

.Net framework supports identity and principal for the Microsoft Windows user and group information, or custom identity and principal

Page 20: Code Access Security

Role-based security

Page 21: Code Access Security

Common Interfaces\BaseClasses

ISecurityEncodableFromXML, ToXML (SecurityElement)

IPermissionCopy, Demand, Intersect, IsSubsetOf, Union

IUnrestrictedIsUnrestriced

CodeAccessPermission as BaseClassPemitOnly, Deny, RevertXXX

Page 22: Code Access Security

Implementing your own classes

Page 23: Code Access Security

Possibilities

Secure our libraries

Defend our servers more effectively

Writing application using RBS

And more…

Page 24: Code Access Security

Questions ?