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

Add HSTS to F# ApiServer and BwdServer #3665

Merged
merged 14 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fsharp-backend/src/ApiServer/ApiServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ let configureApp (packages : Packages) (appBuilder : WebApplication) =
|> fun app ->
LibService.Rollbar.AspNet.addRollbarToApp app rollbarCtxToMetadata None
|> fun app -> app.UseHttpsRedirection()
|> fun app -> app.UseHsts()
|> fun app -> app.UseRouting()
// must go after UseRouting
|> LibService.Kubernetes.configureApp LibService.Config.apiServerKubernetesPort
Expand All @@ -189,6 +190,7 @@ let configureServices (services : IServiceCollection) : unit =
LibService.Telemetry.TraceDBQueries
|> LibService.Kubernetes.configureServices [ LibBackend.Init.legacyServerCheck ]
|> fun s -> s.AddServerTiming()
|> fun s -> s.AddHsts(LibService.HSTS.setConfig)
|> ignore<IServiceCollection>

let run (packages : Packages) : unit =
Expand Down
2 changes: 2 additions & 0 deletions fsharp-backend/src/BwdServer/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,15 @@ let configureApp (healthCheckPort : int) (app : IApplicationBuilder) =
|> fun app -> app.UseRouting()
// must go after UseRouting
|> Kubernetes.configureApp healthCheckPort
|> fun app -> app.UseHsts()
|> fun app -> app.Run(RequestDelegate handler)

let configureServices (services : IServiceCollection) : unit =
services
|> Kubernetes.configureServices [ LibBackend.Init.legacyServerCheck ]
|> Rollbar.AspNet.addRollbarToServices
|> Telemetry.AspNet.addTelemetryToServices "BwdServer" Telemetry.TraceDBQueries
|> fun s -> s.AddHsts(LibService.HSTS.setConfig)
|> ignore<IServiceCollection>

let noLogger (builder : ILoggingBuilder) : unit =
Expand Down
9 changes: 9 additions & 0 deletions fsharp-backend/src/LibService/HSTS.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module LibService.HSTS

open System
open Microsoft.AspNetCore.HttpsPolicy

let setConfig (options : HstsOptions) =
options.Preload <- true
options.IncludeSubDomains <- true
options.MaxAge <- TimeSpan.FromDays 365
1 change: 1 addition & 0 deletions fsharp-backend/src/LibService/LibService.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<Compile Include="Kubernetes.fs" />
<Compile Include="HeapAnalytics.fs" />
<Compile Include="Kestrel.fs" />
<Compile Include="HSTS.fs" />
<Compile Include="Init.fs" />
</ItemGroup>
<ItemGroup>
Expand Down
Loading