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

Hosting Docs #791

Closed
wants to merge 17 commits into from
Closed
1 change: 0 additions & 1 deletion aspnet/fundamentals/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ Fundamentals
request-features
servers
owin
hosting

3 changes: 1 addition & 2 deletions aspnet/fundamentals/servers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,4 @@ Because ASP.NET 5 has completely decoupled ASP.NET applications from IIS or any
Additional Reading
------------------

- :doc:`request-features`
- :doc:`hosting`
- :doc:`request-features`
2 changes: 1 addition & 1 deletion aspnet/fundamentals/startup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ IApplicationEnvironment
Provides access to the application properties, such as ``ApplicationName``, ``ApplicationVersion``, and ``ApplicationBasePath``. Available to the ``Startup`` constructor and ``Configure`` method.

IHostingEnvironment
Provides the current ``EnvironmentName``, ``WebRootPath``, and web root file provider. Available to the ``Startup`` constructor and ``Configure`` method. Learn more about :doc:`hosting`.
Provides the current ``EnvironmentName``, ``WebRootPath``, and web root file provider. Available to the ``Startup`` constructor and ``Configure`` method.

ILoggerFactory
Provides a mechanism for creating loggers. Available to the ``Startup`` constructor and ``Configure`` method. Learn more about :doc:`logging`.
Expand Down
42 changes: 42 additions & 0 deletions aspnet/hosting/apppool.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.. _apppool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This explains how to change app pool identities but not why. You need to bring in the App Pool Identity Accounts section from https://www.iis.net/learn/manage/configuring-security/application-pool-identities


Application Pools
=================

By `Sourabh Shirhatti`

When hosting multiple web sites on a single server, you should consider isolating the applications from each other by running each application in its own application pool. This document provides an overview of how to set up Application Pools to securely host multiple web sites on a single server.


Configuring IIS Application Pool Identities
-------------------------------------------

An application pool identity allows you to run an application under a unique account without having to create and manage domains or local accounts. On IIS 8.0+ the IIS Admin Worker Process (WAS) will create a virtual account with the name of the new application pool and run the application pool's worker processes under this account by default.

In the IIS Management Console, under **Advanced Settings** for your application pool ensure that `Identity` list item is set to use **ApplicationPoolIdentity** as shown in the image below.

.. image:: apppool/_static/apppool-identity.png

Securing Resources
------------------

THe IIS management process creates a secure identifier with the name of the application pool in the Windows Security System. Resources can be secured by using this identity, however this identity is not a real user account and will not show up in the Windows User Management Console.

To grant the IIS worker process access to your application, you will need to modify the Access Control List (ACL) for the the directory containing your application.

1. Open Windows Explorer and Naviagate to the directory.
2. Right click on the directory and click properties.
3. Under the **Security** tab, click the **Edit** button and then the **Add** button
4. Click the **Locations** and make sure you select your server.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this only true if it's changed to a non-admin account?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guardrex Can you elaborate?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen comments along the lines of folks having to explicitly grant folder access permissions but never for the default ApplicationPoolIdentity. I don't know what's going on under-the-covers, but that default account seems to be able to access the runtime(s), packages, and logs folder even when the basic settings path and pass-through auth for the app points to the wwwroot folder.

What I have seen is when someone changes this account they must explicitly set the permissions. I can see if I can find an example in the issues if you want. Let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guardrex Can you find an example?
I just tried creating a new site in IIS following these instructions and didn't encounter any problems

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shirhatti ... but are you saying that you did need to explicitly set permissions, or are you saying you didn't set them and that that section pertains to setting permissions for some other purpose. I was pointing out that everything up to this statement ...

To grant the IIS worker process access to your application

is all good. But I get confused at that point. It makes it sound like the dev needs to configure permissions for the root folder itself ... for the application itself, but that shouldn't be necessary. I'm wondering if what you're talking about here are other folders outside of the root dir on the server or maybe something for virtual directories.

Let me ask you the other way around: Have you had trouble (e.g., 502.3 error) when you don't grant explicit permissions for any account to the root folder of an app? I mean, is the pass-through auth with the default AppPool identity failing?

btw- I'm only aware from one quick test I did with pass-through auth and a fileshare that it failed even with explicit permissions being set, but I think that was the old vdir problem ... maybe that's been fixed ... not sure.

But coming back to my main point: It just seems a little confusing here, because the text up to ...

To grant the IIS worker process access to your application, 

sounds great, then it looks like the doc is telling devs that permissions must be set even for a default app setup.

Certainly, I might be missing something here. So just throw a 🔧 at me if I have missed the point or scenario this addresses. 😄

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok ... I missed the point there a little. Sorry for the bother on it (as Luke takes a virtual 🔧 to the head).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feedback was useful. I'm adding an introduction section to describe that the Hosting Docs is for shared hosts / anyone hosting a multi-tenant ASP.NET 5 server. These docs are meant to outline the best practices and not just the easiest way to get started.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, cool. I'm trying to keep this updated: aspnet/Hosting#364 (comment). It might be one or two weeks behind, but I'm going to run down the issues again, especially to make sure that its updated for RC1 Update 1. There are a lot of cross-linked IIS-related bits there that might be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of your effort.

Do you want to capture that information in a doc on the docs site?

If you open an issue at https://github.com/aspnet/docs/issues, we can try and figure out where that content should live on the docs site.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already done at the basic level: https://docs.asp.net/en/latest/publishing/iis.html

I'm Luke ... I help Rick (and anyone I can). Give me a shout if you need a community cat to run a test or check out a scenario or something with IIS. I enjoy that type of stuff.

.. image:: apppool/_static/apppool-adduser.jpg

5. Enter **IIS AppPool\DefaultAppPool** in **Enter the object names to select** textbox.
6. Click the **Check Names** button and then click **OK**.

You can also do this via the command-line by using **ICACLS** tool.

.. code:: bat

ICACLS C:\sites\MyWebApp /grant "IIS AppPool\DefaultAppPool" :F

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. include:: /../common/stub-topic.txt

|stub-icon| Hosting
===================
|stub-icon| Data Protection
===========================

.. include:: /../common/stub-notice.txt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider adding a section on how developers can choose where keys are stored, and how hosters should consider offering a directory outside of the application root (and properly ACLed), and the ability to upload X509 Certificates to protect file system key stores. Such certificates must be placed in the trusted certificate store see http://blogs.technet.com/b/sbs/archive/2007/04/10/installing-a-self-signed-certificate-as-a-trusted-root-ca-in-windows-vista.aspx and the private key ACLed to the app pool ID - https://technet.microsoft.com/en-us/library/ee662329.aspx?f=255&MSPPError=-2147217396

Expand Down
19 changes: 19 additions & 0 deletions aspnet/hosting/directory-structure.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. _directory-structure:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to discuss minimum directory permissions.


Directory Structure
===================

By `Sourabh Shirhatti`


In ASP.NET 5, the application directory comprises of three sub-directories. This is unlike previous versions of ASP.NET where the entire application lived inside the web root directory.

======= ===========
Folder Description
======= ===========
approot Contains the application, app config files, packages and the DNX runtime.
logs The default folder for HTTP PlatformHandler to redirect logs to.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this on by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you run dnu publish, it adds the stdoutLogFile property to httpPlatform attribute to point to the logs directory by default.

wwwroot Contains the static assets
======= ===========

The **wwwroot** directory represents the web root of the application. The physical path for the IIS site should point to the web root directory. During deployment of a web site, a developer will require access to the entire application directory.
53 changes: 53 additions & 0 deletions aspnet/hosting/http-platformhandler.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
.. _http-platformhandler:

HTTP Platform Handler
=====================

By `Sourabh Shirhatti`

In ASP.NET 5, the web application is hosted by an external process outside of IIS. The HTTP Platform Handler is an IIS 7.5+ module which is responsible for process management of http listeners and to proxy requests to processes that it manages. This document provides an overview of how to configure the HTTP Platform Handler module for shared ASP.NET 5 hosting.

Installing the HTTP Platform Handler
------------------------------------

To get started with hosting with ASP.NET 5 applications you will need to install the HTTP Platform Handler version 1.2 or higher on an IIS 7.5 or higher server. Download links are below

* `64 bit HTTP PlatformHandler (x64) <http://go.microsoft.com/fwlink/?LinkID=690721>`_
* `32 bit HTTP PlatformHandler (x86) <http://go.microsoft.com/fwlink/?LinkId=690722>`_


Configuring the HTTP Platform Handler
-------------------------------------

The HTTP Platform Handler is configured via a site or application's web.config file and has its own configuration section within **system.webServer - httpPlatform**. The `HTTP Platform Handler configuration reference whitepaper <http://www.iis.net/learn/extensions/httpplatformhandler/httpplatformhandler-configuration-reference>`_ describes in detail how to modify Configuration Attributes for the HTTP PlatformHandler module.

Environment Variables
---------------------

The HTTP Platform Handler module allows you specify environment variables for the process specified in the **processPath** setting by specifying them in **environmentVariables** child attribute to the **httpPlatform** attribute. The example below illustrates how you would use it.


.. code:: xml

<configuration>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="httpplatformhandler"
path="*" verb="*"
modules="httpPlatformHandler"
resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="..\approot\web.cmd"
arguments=""
stdoutLogEnabled="false"
stdoutLogFile="..\logs\stdout"
startupTimeLimit="3600">
<environmentVariables>
<environmentVariable name="DEMO" value="demo_value" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an open backlog issue that this will not work ... unless you modify the file after your publish to the output folder but obviously before deployment. I haven't tested. Let me know if you want me to look into this and confirm the situation. aspnet/dnx#3062

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you confirm that? That'd be helpful 😄

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shirhatti stand by ... I'll test now and get back to you in a few minutes ...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shirhatti Yep ... it gets removed. I started with this in the project (in wwwroot folder) ...

    <httpPlatform
        processPath="%DNX_PATH%"
        arguments="%DNX_ARGS%"
        stdoutLogEnabled="false"
        stdoutLogFile="..\logs\httpplatform"
        startupTimeLimit="3600">
      <environmentVariables>
        <environmentVariable name="TEST_VAR" value="TEST_VALUE" />
      </environmentVariables>
    </httpPlatform>

... I publish to the local output folder prior to deployment and get this ...

    <httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="false"
stdoutLogFile="..\logs\httpplatform" startupTimeLimit="3600"></httpPlatform>

... it should still be possible to mod the file after publishing to the local output folder ... but what a pain, right?! Possible workaround: I guess a stand-alone web.config file on the server could be sitting there outside of the project and IIS runs off of that (stable) one. I bet this is going to be fixed in an upcoming version of HttpPlatformHander, and @Tratcher said they pick back up with that in January: aspnet/IISIntegration#43 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shirhatti Followup ... I manually moded the web.config on the server and it accepted the env var and I was able to read it in the app from Environment.GetEnvironmentVariable("TEST_VAR"), so the HttpPlatformHandler is good in this respect. The only issue AFAIK is that the publish out of VS will strip it from web.config prior to deployment ... well ... it actually strips out all of that stuff you show in the doc. 😢

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, what gets stripped? Can you show me a before and after doc?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah ... so if you start with this as web.config in your project's wwwroot folder ...

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add
        name="httpPlatformHandler"
        path="*"
        verb="*"
        modules="httpPlatformHandler"
        resourceType="Unspecified"/>
    </handlers>
    <httpPlatform
        processPath="%DNX_PATH%"
        arguments="%DNX_ARGS%"
        stdoutLogEnabled="false"
        stdoutLogFile="..\logs\httpplatform"
        startupTimeLimit="3600">
      <environmentVariables>
        <environmentVariable name="TEST_VAR" value="TEST_VALUE" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>

... you'll end up with this after you publish to your local output folder ...

<configuration>
  <system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="false" stdoutLogFile="..\logs\httpplatform" startupTimeLimit="3600"></httpPlatform>
  </system.webServer>
</configuration>

... the good news there is that it kept the <remove ...>'s. I thought it might dump them, too, but no, we're good there. It's just the <environmentVariables> will get cut. You'd have to either (1) manually add them back to the web.config you intend to deploy, or (2) point IIS to a stable web.config on the server that would have these env vars set and where the file isn't overwritten with each deployment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's a bug in dnu publish then. Filed aspnet/dnx#3259

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was here I think ... aspnet/dnx#3062

</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
13 changes: 13 additions & 0 deletions aspnet/hosting/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Hosting
=======

.. toctree::
:titlesonly:

servicing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order is strange. It needs an introduction topic, then I'd suggest Installing Platform Handler, followed by Directory Structure, App Pools then Servicing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blowdart Does this seem more reasonable shirhatti@f251c6d ?

http-platformhandler
directory-structure
dataprotection
apppool


34 changes: 34 additions & 0 deletions aspnet/hosting/servicing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.. _hosting-servicing:

Servicing
=========

By `Sourabh Shirhatti`

ASP.NET 5 supports servicing of runtime components (DNX) and packages through Microsoft Update, which will deliver updates to patch any vulnerabilities when they are discovered. This document provides an overview of how to setup your Windows Server correctly to receive updates.

Breadcrumbs Directory
---------------------

All serviceable assemblies will leave a breadcrumb in the ``BreadcrumbStore`` Directory. At the time of servicing Microsoft Update looks in this directory to figure out which assemblies are used on the server and require patching. This directory must be protected by ACLs to prevent rogue applications from deleting entries from this directory. Run the powershell snippet below in an elevated prompt to create the ``BreadcrumbStore`` directory and set ACLs on it correctly.


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link to the script in github rather than copy it - that way if it changes then it doesn't need updating here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script doesn't live on Github. It was written up for these docs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits:
" At the time of servicing, Windows" (add comma)
"and need patching" perhaps to "and require patching"
"must be correctly protected" ... one wouldn't want to "incorrectly" do it, so recommend just "must be protected"
"ACLs" to "ACL's" ... but that's a style thing, and I don't know what spec you're using
"powershell" to "PowerShell"
"ACL" probably shouldn't be treated like a verb here. Maybe ... "and set ACL's on it correctly."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then put the script on github - @glennc

.. code-block:: powershell

$breadcrumbFolder = $env:ALLUSERSPROFILE + '\Microsoft DNX\BreadcrumbStore'
New-Item -Force -Path $breadcrumbFolder -ItemType "Directory"
$ACL = Get-Acl -Path $breadcrumbFolder
# Clear any permissions
$ACL.SetAccessRuleProtection($true, $false)
# Set new permissions
$ACL.SetSecurityDescriptorSddlForm("O:SYG:SYD:P(A;OICI;CCDCSWWPLORC;;;WD)(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)")
Set-Acl -Path $breadcrumbFolder -AclObject $ACL

Servicing Directory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will hosters care about how it works? Not sure this matters.

-------------------

At the time of loading an asset DNX will check against an index file in the ``Servicing`` directory to determine whether it should load a patched version instead of what it would normally load. This index file is updated by Microsoft Update during servicing to point to location of the patched version of the asset on disk which will reside in the the ``Servicing`` directory. The index file defaults to ``%PROGRAMFILES%\Microsoft DNX\Servicing``, but you can change this by setting ``DNX_SERVICING`` environment variable to a different path.




1 change: 1 addition & 0 deletions aspnet/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Topics
performance/index
migration/index
contribute/index
hosting/index

Related Resources
-----------------
Expand Down
1 change: 1 addition & 0 deletions common/authors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
.. _David Paquette: https://github.com/dpaquette
.. _Scott Addie: http://scottaddie.com
.. _Sayed Ibrahim Hashimi: https://github.com/sayedihashimi
.. _Sourabh Shirhatti: https://twitter.com/sshirhatti
3 changes: 0 additions & 3 deletions mvc/controllers/dependency-injection.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
Dependency Injection and Controllers
====================================

.. _dependency-injection-controllers:

|stub-icon| Dependency Injection and Controllers
By `Steve Smith`_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix the Travis build. The change was already made upstream. It will go away from my diff when I rebase


ASP.NET MVC 6 controllers should request their dependencies explicitly via their constructors. In some instances, individual controller actions may require a service, and it may not make sense to request at the controller level. In this case, you can also choose to inject a service as a parameter on the action method.
Expand Down