Michael Morel
Introduction
Application Security Flow
Recommendations
Moving to the Internet
Further Reading
The Microsoft® BackOffice® family of products offers the framework for robust and secure three-tier and Web-based applications. However, setting up security in such an environment can be a complex topic. It is not uncommon that a team develops and thoroughly tests an application on a server to which the team has full access. To the team's surprise and embarrassment, the application encounters a great number of security-related problems once moved to a production server, often making the application appear as if it was not tested at all!
This document attempts to explain how security works in a typical Web application. While the security models in each of the BackOffice products are documented individually, this paper will show how all of the models fit together very nicely as one integrated security package. Rather than covering each product in detail, I will concentrate on how the products work together, and provide references to detailed product information. Finally, I will make some recommendations on how to set up your server to avoid problems.
This document describes security considerations in a "typical" BackOffice Web-based application. The reference application in the sections that follow is an "intranet" application, where users are connecting to the server over the corporate network. All of the security concepts presented in this paper apply equally to Internet applications. The difference is that in an Internet application, users typically do not have Microsoft Windows NT® accounts on the server's domain, so they all appear as the "anonymous" user, and must gain access to all resources as this user.
This typical application has the following attributes:
Although the typical application describes a Web-based application, many of the points apply equally to a three-tier application with a Windows client accessing server components using the Distributed Component Object Model (DCOM).
The Application Flow Chart summarizes the flow of the reference application, in terms of security. The first column shows the security context under which pieces of the application run. Subsequent columns show how each piece of the application takes part in the security flow. The sections following this table will further explain how each product contributes to the overall security picture.
Table 1 displays and describes the three components that are created.
Table 1. Application Components
Name |
MTS Control? | Description |
Package Name | Package Identity |
CompA | No | A system component, such as an Active Data Object (ADO) or a Microsoft ActiveX® Messaging Library. | ||
CompB | Yes | A business component installed in MTS. It uses the services of CompC | PkgB | MTSPkgB |
CompC | Yes | A business component installed in MTS. | PkgC | MTSPkgC |
The Application Flow Chart
Security Context | Browser | IIS | NTFS | ASP | MTS | Component | SQL Server | |
---|---|---|---|---|---|---|---|---|
1. | Anonymous | Requests ASP Web file | ||||||
2. | Requests ASP file | |||||||
3. | File protected; access denied | |||||||
4. | Sends NT Challenge | |||||||
5. | Sends NT Response | |||||||
6. | NT User | Requests ASP file | ||||||
7. | File access granted | |||||||
Security Context | Browser | IIS | NTFS | ASP | MTS | Component | SQL Server | |
8. | Executes script | |||||||
9. | Server.CreateObject( "CompA" ) | |||||||
10. | Component access granted | |||||||
11. | Server.CreateObject( "CompB" ) | |||||||
12. | CompB.Foo | |||||||
13. | Checks NT User vs. PkgB Roles | |||||||
14. | Checks NT User vs. interface Roles | |||||||
15. | Checks NT User vs. CompB Roles | |||||||
Security Context | Browser | IIS | NTFS | ASP | MTS | Component | SQL Server | |
16. | MTSPkgB | CompB requires database access | ||||||
17. | SQL-Server Login, Database User | Maps MTSPkgB to SQL login, database user | ||||||
18. | Accesses SQL data | |||||||
19. | MTSPkgB | objContext.Create Instance("CompC") |
||||||
20. | CompC.Bar | |||||||
21. | Checks MTSPkgB vs. PkgC Roles | |||||||
22. | MTSPkgC | CompC requires database access | ||||||
23. | SQL-Server Login, Database User | Maps MTSPkgC to SQL login, database user | ||||||
24. | Accesses SQL data | |||||||
Security Context | Browser | IIS | NTFS | ASP | MTS | Component | SQL Server | |
25. | NT User | CompB.Admin | ||||||
26. | MTSPkgB | objContext. IsCallerInRole | ||||||
27. | Perform privileged operation |
The first security barrier that an application user must scale is access to the application scripts and Hypertext Markup Language (HTML) files. Scripts cannot be executed, even HTML cannot be sent to the requesting browser, until the user gains access to the files. Steps 1 through 7 in the table describe the interaction between the browser, Microsoft Internet Information Server (IIS), and New Technology File System (NTFS).
If your IIS installation allows anonymous access, when a user first enters a Web application, that user is "anonymous." That is, IIS does not know who the user is. Every anonymous user is assigned the same Windows NT User ID. By default, that user name will be "IUSR_Machine Name", where Machine Name is the name of the computer on which IIS is running. For our discussion, we'll call this user "IUSR_WWW".
When the browser requests an application file, for example, DEFAULT.ASP, IIS tries to read the file on the user's behalf. This request is sent to the file system, NTFS. NTFS checks to see if the user, IUSR_WWW, may read the file.
In this example, the application is an intranet application, its access restricted to only certain users on the domain. So you need to get the user name of the actual user, not the anonymous user. To do this, make sure that IUSR_WWW cannot read the application file (DEFAULT.ASP). If NTFS rejects the read request, IIS sends a challenge back to the browser, and the browser responds with the user name of the "real" user.
Assuming the user is a valid user of the application, this time when IIS tries to read the application file, NTFS grants access. From this point on, IIS operates as the validated domain user.
With IIS 4.0, you can eliminate the use of the anonymous user altogether for your application. Just disable anonymous authentication in the IIS Directory Security properties for the virtual directory. IIS will issue a challenge to the browser immediately, before attempting to access any files. With previous versions of IIS, you could disable anonymous access, but it had to be done on a per-server basis, not per virtual directory.
Of course, there may be applications that allow anonymous access. To allow for anonymous access to an application, simply make sure that IUSR_WWW has been granted access to read the application files. However, remember that you cannot have it both ways. If IUSR_WWW has access to the files, IIS will never challenge the browser, so even validated domain users will always come in as IUSR_WWW.
Once the Active Server script file is read by IIS, the ASP engine executes it. One very common operation in ASP scripts is to create and use some component. Some components may run under the control of MTS, and some may not. First, let's look at those components not installed in ASP.
Typically, general system components will not be installed in MTS. For example, ADO or ActiveX Messaging Objects might be used to access data or send mail messages. These are not installed in MTS.
This is a very common place for permission problems. Most people remember to grant the proper file access to their application directory, but it is easy to miss the components. The domain user must have access to all of the files that get loaded on the server when an object is created. This will almost certainly include the \WINNT\SYSTEM32 directory, where supporting DLLs are located. For ADO, the user must have access to the ADO and OLE DB component directories (\Program Files\Common Files\System\Ado and \Program Files\Common Files\System\Ole DB by default).
Note that you may not invoke remote components directly from an ASP script. This is because while IIS executes the script under the authenticated user's identity, it restricts access to the network (This restriction only applies for clients that are authenticated using Windows NT Challenge/Response. This is the style of authentication used for most intranet applications.) This does not mean that you cannot access network resources at all, however. You can create a "helper" component that will access the remote component, and install this component in a local MTS package. When setting the identity under which this package will run, make sure the package account has the required access to the remote component(s).
Note If you are using Microsoft Access in a Web-based application, the server must define a directory for temporary files, and the user will need write access to this directory. Please see the article "Random Errors w/ IDC or ASP Queries to Access Database" (MSDN™ Library, Knowledge Base Article #Q164535) for details.
The business components used in the application are typically installed into Microsoft Transaction Server. MTS provides a complete security model to prevent the unauthorized use of components and, by association, enterprise data.
When the ASP script attempts to invoke methods on an object under MTS, the method call will not proceed until MTS checks to see if the user is allowed. Remember, when the script is running, the security context is that of the validated domain end-user.
If package security is enabled under MTS, MTS checks that the user belongs to one of the roles on the package. The Windows NT user may be directly added to a role, or may belong to a Windows NT group that has been added to the role.
Role-based security may be set for individual components within a package, or even for interfaces implemented by a component. See the topic "Enabling MTS Package Security," in the Microsoft Transaction Server 2.0 documentation (MSDN Library, SDK Documentation).
Once MTS determines that a user may call a component, MTS runs the package that contains the component. This package should be run under the identity of a special Windows NT user created specifically for the package. In the example, the Windows NT account used by PkgB is called MTSPkgB. From this point on, any access by the component is done through this new Windows NT User ID.
When an MTS component requests database access, it does so under the User ID of the package (user MTSPkgB in this case). No matter who the end-user is, the database only sees the package identity. This approach to database security has a number of advantages:
Microsoft SQL Server should be setup to allow Integrated (or Mixed) security. Then each package identity should be mapped to a SQL login. This login should then be given the proper access to databases and database objects.
In our example, component B creates an instance of component C and relies on the services of component C to get some of its work done. These two components have been installed into MTS under two different packages.
The first thing you might try to do is add the end-user to a role on package C. However, it is not the end-user that requests the services of component C. This component is created from within component B, and when PkgB runs, it does so under the User ID MTSPkgB. This is the user that must be added to a role on PkgC.
Likewise, if component C must access the database, then the PkgC User ID (MTSPkgC) must be mapped to a SQL login. Component B does not need to have direct access to component C's data. Component B is very much a client of component C, just as the end-user is a client of component B.
For a very fine degree of control, an application can also specifically check role membership before performing some operation. In the example, the script (running as the end-user) executes a method intended for administrators only. The component calls the context method IsCallerInRole to determine whether the caller is an administrator, and proceeds based on the answer.
IsCallerInRole always checks the direct caller, just like the normal MTS access checks. So, if component C calls this function, it will be checking the role membership of the MTSPkgB (the direct caller), not the end user. In fact, the end user is not even in a role on PkgC. This is consistent with the discussion of cross-package access, above.
Keeping in mind the flow of security contexts in a three-tier application, this section presents some recommendations for deploying a secure application that is also easy to administer. The names used here for users and groups are really not important, as long as you consistently follow whatever naming standards you set.
Dim sModifiedBy as String
sModifiedBy = GetObjectContext().Security.GetOriginalCallerName()
Private Function IsInRole(ByVal strRole As String) As Boolean
On Error GoTo HandleError
Dim Ctxt As ObjectContext
Set Ctxt = GetObjectContext()
If Ctxt Is Nothing Then ' Not running under MTS
IsInRole = False
Exit Function
End If
If Not Ctxt.IsSecurityEnabled() Then ' Forgot to enable security
IsInRole = False
Exit Function
End If
IsInRole = Ctxt.IsCallerInRole(strRole)
Exit Function
HandleError:
IsInRole = False
Exit Function
End Function
For the intranet reference application described earlier, NT Challenge/Response was the recommended authentication style. For internet applications where clients will generally not have user accounts in your server's Windows NT domain, and many different browsers must be supported, digital certificates may be a better solution. To use digital certificates, users first obtain a client certificate from a trusted third-party organization or from your own Certificate Server. When users contact your secure Web site, the Secure Sockets Layer (SSL) 3.0 security features of IIS authenticate them by checking the contents of the encrypted digital identification submitted by the user's Web browser during the logon process. The client certificate generally contains other identifying information about the user and the organization that issued the certificate.
You can configure IIS to map client certificates to a local Windows NT account. The mapping features of IIS allow you create one-to-one mappings between certificates and accounts or map multiple certificates to a single account. In most cases it isn't practical to create Windows NT accounts for individual Internet users. You may want to map certificates to different local accounts based on the organization that issued the certificate or on the organization to which the user belongs. If you allow different organizations to access your secure site, the latter approach allows you to configure the access that each organization is granted via the Windows NT account to which they are mapped.
When you configure the security for your virtual directories in IIS, you can enable SSL encryption and optionally require a certificate for authentication. You can use certificates alone, or in combination with NT Challenge/Response to support both intranet and Internet users.
Once the appropriate certificate mappings have been established, configure your application security the same as in the intranet scenario. The difference here is that the account(s) you configure will be used by multiple individual users. In effect, you trade the ability to control individual access for the ability to support many users with little administrative overhead.
One way to regain individual accountability (if not control) is to incorporate information from the client certificate into the auditing code of your MTS components. IIS makes this information available through its intrinsic objects that are propagated automatically to downstream components by MTS.
The code fragment below shows how to retrieve the subject fields from the certificate the client used for authentication. This code assumes that both intranet and Internet clients access the component, so a certificate need not be present.
Dim strCertSubject As String
Dim objContext as ObjectContext
On Error Resume Next
Set objContext = GetObjectContext()
strCertSubject = objContext("Request").ClientCertificate("Subject")
If (Err.Number <> 0) Then
strCertSubject = "(No Certificate)"
End If
For more information about using digital certificates with IIS and issuing client certificates, refer to the online documentation for Microsoft Internet Information Server 4.0 and Microsoft Certificate Server.
The following topics and articles are all available in the MSDN Library: