Fluent.Backdoor 1.0.17

dotnet add package Fluent.Backdoor --version 1.0.17
NuGet\Install-Package Fluent.Backdoor -Version 1.0.17
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fluent.Backdoor" Version="1.0.17" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Fluent.Backdoor --version 1.0.17
#r "nuget: Fluent.Backdoor, 1.0.17"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Fluent.Backdoor as a Cake Addin
#addin nuget:?package=Fluent.Backdoor&version=1.0.17

// Install Fluent.Backdoor as a Cake Tool
#tool nuget:?package=Fluent.Backdoor&version=1.0.17

Fluent.Backdoor

If you need to keep your app services on a tight leash, while still being able to verify app slots using smoke tests and perhaps warmups, then this could help you. A need based on keeping an app-service url hidden, while warming up a production slot in Azure made me create this little configurable function.

The syntax is:

  1. What do we Require() (IP/Cookie/Queystring)? And if fulfilled:
  2. how long will it Allow() access?

Simple, right?

Multiple Require() can be chained together for more complex rules.

In the end a ReturnCodeWhenDenied() is used to tell the system what to show when it fails. Only one ReturnCodeWhenDenied() is allowed.

Sample usage of Fluent.Backdoor

Startup.cs

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
var options = new RewriteOptions();

var fluent = new BackdoorRule().AllowAnythingFor(2)
    .Require(new BackdoorMagicQuerystring
    {
        QuerystringName = Configuration["FluentBackDoorRules:FluentMagicQuerystring:QuerystringName"],
        QuerystringValue = Configuration["FluentBackDoorRules:FluentMagicQuerystring:QuerystringValue"]
    }).AndAllowFor(new TimeSpan(0, 0, 10))
    .Require(new BackdoorMagicCookie()
    {
        CookieName = Configuration["FluentBackDoorRules:FluentMagicCookie:CookieName"],
        CookieValue = Configuration["FluentBackDoorRules:FluentMagicCookie:CookieValue"]
    })
    .Require(new BackdoorMagicCookie()
    {
        CookieName = "hey",
        CookieValue = "ho"
    }).AndAllowFor(new TimeSpan(0, 0, 20))
    .Require(new BackdoorHttpHostAndRemoteIPAddress
    {
        HostNamesToProtect = Configuration["FluentBackDoorRules:FluentMagicRegExHttpHost_RemoteAddr:HostNamesToProtect"],
        IPAddressesToAllowToUseProtectedUrls = Configuration["FluentBackDoorRules:FluentMagicRegExHttpHost_RemoteAddr:IPAddressesToAllowToUseProtectedUrls"]
    }).AndAllowForever()
    .ReturnCodeWhenDenied(System.Net.HttpStatusCode.Unauthorized);

options.Rules.Add(fluent);
app.UseRewriter(options);
}

appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "FluentBackDoorRules": {
    "CompleteAccess": {
      "TimeAllowedInSeconds": 20
    },
    "FluentMagicCookie": {
      "CookieName": "cookieshallpass",
      "CookieValue": "xxx"
    },
    "FluentMagicQuerystring": {
      "QuerystringName": "querystringshallpass",
      "QuerystringValue": "xxx"
    },
    "FluentMagicRegExHttpHost_RemoteAddr": {
      "HostNamesToProtect": "inte\\.|prep\\.|-slot\\.|prod\\.|stage\\.|stage2\\.|www2\\.",
      "IPAddressesToAllowToUseProtectedUrls": "^5\\.6\\.7\\8.$"
    }
  }
}

Explanation of what sample code above will do:

  1. Allow any calls to the app 2 times.
  2. Allow access to the app for 10 seconds if a querystring is supplied.
  3. Allow access to the app for 20 seconds if two different cookies are present.
  4. Restrict access to the app IF the HTTP_HOST contains HostNamesToProtect, IE. the secret app service url:s using RegEx-matching AND the visitor is NOT in the list of IPAddressesToAllowToUseProtectedUrls (REMOTE_ADDR).
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.17 796 6/24/2022
1.0.16 399 6/21/2022
1.0.15 401 6/21/2022
1.0.14 397 6/21/2022
1.0.12 392 6/21/2022
1.0.11 385 6/19/2022
1.0.10 391 6/19/2022
1.0.9 378 6/19/2022
1.0.8 371 6/19/2022
1.0.7 388 6/19/2022
1.0.6 393 6/19/2022
1.0.5 394 6/19/2022
1.0.1 399 6/19/2022
1.0.0 403 6/19/2022