WCF Security
WCF Security
WCF Security
Sridhar Anjanappa
Agenda
Security Engineering
Web Services Security Frame
• Auditing and Logging
• Authentication
• Authorization
• Configuration Management
• Exception Management
• Impersonation / Delegation
• Message Validation
Threats & Attacks to Your
Web Service
Auditing and Logging
• Tampering with log files
• Ineffectual or nonexistent audit processes
Threats & Attacks to Your
Web Service
Authentication
• Network eavesdropping
• Brute force attacks
• Dictionary attacks
• Cookie replay attacks
• Credential theft
Threats & Attacks to Your
Web Service
Authorization
• Elevation of privilege
• Disclosure of confidential data
• Data tampering
• Luring attacks
Threats & Attacks to Your
Web Service
Configuration Management
• Unauthorized access to administration
interfaces
• Unauthorized access to configuration stores
• Retrieval of clear text
• Configuration secrets
• No individual accountability
Threats & Attacks to Your
Web Service
Exception Management
• System or application details are revealed
• Denial of service (DoS)
Threats & Attacks to Your
Web Service
Impersonation/Delegation
• Elevation of privilege
Threats & Attacks to Your
Web Service
Message Encryption
Information Disclosure
Threats & Attacks to Your
Web Service
Message Validation
• Buffer overflows
• Cross-site scripting (XSS)
• SQL injection
• Canonicalization attacks
Threats & Attacks to Your
Web Service
Session Management
• Session hijacking
• Session replay
• Man-in-the-middle attacks
Bindings and Behaviors
Bindings
• Bindings control the security mode, client
credential type, and other security settings.
Behaviors
• Service behaviors control impersonation
levels, how client credentials are
authenticated and authorized, and service
credentials.
Common Bindings
How to choose the right WCF
binding
• If you need to support clients over the
Internet, consider using wsHttpBinding.
• End-to-End security
• Role-based
• Identity-based
• Resource-based
Role-based Authorization
WCF provides following options for role-based
authorization:
• Windows groups
• ASP.NET roles
– SQLRoleProvider
– WindowsTokenRoleProvider
– AuthorizationStoreRoleProvider
• Custom Roles
Impersonation / Delegation
• Impersonation is a technique that WCF
services use to assume the original caller’s
identity in order to authorize access to service
resources (such as files or database tables).
– None
– Anonymous
– Identification
– Impersonation
– Delegation
Auditing in WCF
• WCF Auditing allows you to audit security
events such as authentication and
authorization failures.
if(Roles.IsUserInRole(@“SPL\\accounting“))
{
}
Scenario 1 (Intranet)
WCF Proxy:
• ASP.NET has a proxy reference to the WCF
service.
• The application has access to the WCF Service
metadata to create a service reference.
WCFTestService.MyServiceClient proxy = new
WCFTestService.MyServiceClient();
Scenario 1 (Intranet)
WCF Proxy:
• ASP.NET Impersonates the original callers
before calling the WCF operation.
• Used for downstream authorization.
using(((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate())
{
WCFTestService.MyServiceClient proxy= new WCFTestService.MyServiceClient();
proxy.GetData("data");
proxy.Close();
}
Scenario 1 (Intranet)
Application Server (Windows Service) Configuration:
• Windows Service is configured to run under a
custom domain service account.
• WCF Service is hosted in a Windows Service
(Since IIS does not support netTcpBinding).
• Service Principal Name (SPN) is created since a
custom domain account is used for the
Windows service, and the ASP.NET application
needs to restrict trust for delegation to only
the WCF service.
Scenario 1 (Intranet)
WCF Service Configuration:
• Configure the WCF service to use
netTcpBinding.
<endpoint
address=“”
binding="netTcpBinding”
bindingConfiguration=“”
name="TcpBinding” contract="WCFServicecHost.IMyService”
/>
Scenario 1 (Intranet)
WCF Service Configuration:
• Service Metadata is configured in service
behavior.
• The service metadata entry is required for the
Windows service host to start. Both HTTP and
HTTPS get are disabled.
<serviceMetadata />
Scenario 1 (Intranet)
WCF Service Authentication:
• netTcpBinding by default supports Windows
Authentication and Transport Security.
<endpoint
address=""
binding="netTcpBinding"
bindingConfiguration="" />
Scenario 1 (Intranet)
WCF Service Authorization:
• Role Manager feature is enabled and
WindowsTokenRoleProvider is configured for
roles authorization.
<serviceAuthorization principalPermissionMode="UseAspNetRoles”
roleProviderName="AspNetWindowsTokenRoleProvider" />
myService.ClientCredentials.UserName.UserName= "username";
myService.ClientCredentials.UserName.Password= "p@ssw0rd";
myService.GetData(123);
Scenario 1 (Internet)
Application Server – IIS Configuration:
aspnet_regsql -S .\SQLExpress -E -A r m
<wsHttpBinding>
<binding name="BindingConfiguration">
<security>
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
Scenario 1 (Internet)
• WCF Service – Authentication:
• Service behavior is configured to use
membership provider for using with username
authentication.
<userNameAuthentication
userNamePasswordValidationMode="MembershipProvider"
membershipProviderName="MySqlMembershipProvider" />
Scenario 1 (Internet)
• WCF Service – Authentication:
• Service behavior is configured to publish
metadata.
<serviceAuthorization
principalPermissionMode="UseAspNetRoles"
roleProviderName="MySqlRoleProvider" />
Scenario 1 (Internet)
• WCF Service – Authorization:
• WCF Operations areconfigured to do role
checks at operation level,declaratively.
[PrincipalPermission(SecurityAction.Demand, Role="Managers")]
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
If(Roles.IsUserInRole(“Manager”))
{
// do something for the manager
}
else
{
// throw an error.
}
Scenario 1 (Internet)
• WCF Service – SQL:
• The connection string for database is
configured to use Windows Authentication.