docker-images icon indicating copy to clipboard operation
docker-images copied to clipboard

[Proposal] Host Identity Server using Kestrel directly instead of behind IIS

Open anarsen opened this issue 5 years ago • 11 comments

Proposal

PR #226

We've had luck with avoiding IIS altogether for the Identity Server Docker image. As you know, Identity Server is built on Sitecore Host which in turn is built on ASP.NET Core.

Setting ENTRYPOINT ["dotnet.exe", "c:\inetpub\wwwroot\Sitecore.IdentityServer.Host.dll"] directly instead of using IIS as a reverse proxy simplified logging to stdout as well, since Sitecore Host does that out of the box through Microsoft.Extensions.Logging.Console.

If you still need to provide a TLS certificate for SIS, which previously was attached to the IIS binding, just set that using https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-2.1#endpoint-configuration-2.

I'll be happy to contribute if you're interested in adopting this approach.

Unfortunately I didn't succeed in basing this on a Nano Server image since SIS still uses the Certificate Manager internally. However, a clean Windows Server Core image with ASP.NET Core 2.1 Runtime installed was sufficient.

Caveats

Watch-Directory.ps1 might not work. I'd expect dotnet.exe would have to be restarted in order to pick up changed binaries/configs.

anarsen avatar Jan 24 '20 14:01 anarsen

Sounds like a good change and using Kestrel directly makes more sense. Why would Watch-Directory.ps1 not work?

@bplasmeijer do you see any problems doing this?

pbering avatar Jan 25 '20 10:01 pbering

@pbering I was thinking if binaries or configs change, then Kestrel wouldn't know about it whereas the IIS would restart dotnet.exe underneath. At least in the out-of-process model used in ASP.NET Core 2.1.

It's speculation so I'd have to check it out. I'll get around to doing that soon.

anarsen avatar Jan 25 '20 20:01 anarsen

Ah yes that would be a problem. I wounder if we could use dotnet watch run in a development entrypoint so Watch-Directory.ps1 would still work?

pbering avatar Jan 27 '20 08:01 pbering

dotnet watch expects an MSBuild project file sadly. I can imagine FileSystemWatcher working in the Kestrel approach too though.

The execution could look like this:

  1. Start a FileSystemWatcher
  2. Register event handler which terminates any dotnet processes
  3. Loop forever: 3.1. Execute dotnet Sitecore.IdentityServer.Host.dll 3.2. Write to stdout files x, y, z changed

Edit It's important that any SIGKILL or <C-c>s are propagated to the dotnet process to allow for a graceful shutdown.

anarsen avatar Jan 27 '20 09:01 anarsen

mmm damn it does required that. FileSystemWatcher are not really good, always hit or miss and they are not much better inside a container :) - I'm thinking that we should just not support using Watch-Directory.ps1 and use a standard dotnet run Sitecore.IdentityServer.Host.dll entrypoint and people that needs to configure it should use it as a base image and add their own stuff on top. Either that or leave it on IIS as today. I can't decide this alone since I'm not using it currently.

Anyone that is using it have any comments?

pbering avatar Jan 28 '20 08:01 pbering

I will do Sitecore review.

bplasmeijer avatar Jan 28 '20 08:01 bplasmeijer

mmm damn it does required that. FileSystemWatcher are not really good, always hit or miss and they are not much better inside a container :) - I'm thinking that we should just not support using Watch-Directory.ps1 and use a standard dotnet run Sitecore.IdentityServer.Host.dll entrypoint and people that needs to configure it should use it as a base image and add their own stuff on top. Either that or leave it on IIS as today. I can't decide this alone since I'm not using it currently.

Anyone that is using it have any comments?

I am in favor of using standard dotnet run ... and custom scripts on top of that.

joostmeijles avatar Jan 28 '20 08:01 joostmeijles

Hmm for production images I would definitely prefer dotnet run.

For local development it is really nice to have the fast feedback cycle. However, even though I have made some customization to Sitecore Identity Server, it is very rare and not a big loss for me that I would have to rebuild the container. Actually in that project we already have to rebuild the container to get any new file updates (as that was the easiest way to get started). So I think it is a fair trade-off that those images are optimized for production performance and you can extend if you have special needs.

jballe avatar Jan 28 '20 10:01 jballe

Thanks for all the feedback.

In the meantime, I’ve managed to run Identity Server in a Nano Server container too. The HTTPS certificate and the Identity Server certificate can both be read from files, and not only the certificate store as the example configs indicate.

That makes it even more interesting in my opinion. I’ll submit a PR on this in the coming days.

anarsen avatar Jan 28 '20 11:01 anarsen

@pbering @bplasmeijer @joostmeijles In case you didn't notice, I opened PR #226

It might not fit perfectly into the XM, XC, XP topology groupings. Let me know what I can do to make that happen, if that's the case.

anarsen avatar Feb 05 '20 07:02 anarsen

See my comments in #226 .

joostmeijles avatar Feb 05 '20 07:02 joostmeijles