Skip to content

Commit 4730613

Browse files
authored
#585 #2316 Authentication global configuration (#2336)
* Delete AuthenticationOptionsBuilder * Properly deprecate the AuthenticationProviderKey property in models * Redesign models to support global AuthenticationOptions * Delete RouteOptionsBuilder * Remove RouteOptions configuration model and take IRouteOptionsCreator out of DI container * Relocate the middleware to the higher-level namespace * Stabilizing tests after refactoring, aka taking out the trash from codebase * Implement global configuration feature * Relocate AuthorizationMiddleware to the higher-level namespace * Review DownstreamUrlCreatorMiddleware * Improve code coverage * Code review by @ggnaegi * Relocate unit testing files to the Auth folder * Unit tests for AuthenticationOptionsCreator after refactoring * Initial version of the Administration feat without IdentityServer4 * Turn acceptance testing back on for Authentication and Authorization using custom JWT signing * Code review by @RaynaldM * Acceptance tests for static routes * Bump Ocelot.Testing pack to 24.0.3-beta.3 * Acceptance tests for dynamic routes * Relocate ClaimsParser to a higher-level namespace * Review infrastructure extensions and improve code coverage * Update docs
1 parent 1fdf6c2 commit 4730613

File tree

118 files changed

+3613
-2342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+3613
-2342
lines changed

docs/features/authentication.rst

Lines changed: 191 additions & 89 deletions
Large diffs are not rendered by default.

docs/features/caching.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Finally, in order to use caching on a route in your route configuration add thes
104104
* Finally, ``EnableContentHashing`` is disabled due to the current route using the ``GET`` verb, which does not include a request body.
105105

106106
.. _24.1: https://github.com/ThreeMammals/Ocelot/releases/tag/24.1.0
107-
.. _25.0: https://github.com/ThreeMammals/Ocelot/milestone/12
107+
.. _25.0: https://github.com/ThreeMammals/Ocelot/milestone/13
108108
.. warning::
109109
According to the static :ref:`config-route-schema`, the ``FileCacheOptions`` section has been deprecated!
110110

docs/features/configuration.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Here is the complete dynamic route configuration, also known as the *"dynamic ro
122122
.. code-block:: json
123123
124124
{
125+
"AuthenticationOptions": {},
125126
"CacheOptions": {},
126127
"DownstreamHttpVersion": "",
127128
"DownstreamHttpVersionPolicy": "",
@@ -142,7 +143,7 @@ The actual dynamic route schema with all the properties can be found in the C# `
142143
Use ``RateLimitOptions`` instead of ``RateLimitRule``! Note that ``RateLimitRule`` will be removed in version `25.0`_!
143144
For backward compatibility in version `24.1`_, the ``RateLimitRule`` section takes precedence over the ``RateLimitOptions`` section.
144145

145-
**Note 2**: The following options were not supported in versions prior to `24.1`_ for overriding globally configured options: ``CacheOptions``, ``HttpHandlerOptions``, ``LoadBalancerOptions``, ``QoSOptions``, ``RateLimitOptions``, ``ServiceNamespace``, and ``Timeout``.
146+
**Note 2**: The following options were not supported in versions prior to `24.1`_ for overriding globally configured options: ``AuthenticationOptions``, ``CacheOptions``, ``HttpHandlerOptions``, ``LoadBalancerOptions``, ``QoSOptions``, ``RateLimitOptions``, ``ServiceNamespace``, and ``Timeout``.
146147
Starting with version `24.1`_, both global and route-level options for :ref:`Dynamic Routing <routing-dynamic>` were introduced.
147148
For a clearer understanding of the changes, refer to the `previous schema (version 24.0) <https://ocelot.readthedocs.io/en/24.0/features/configuration.html#dynamic-route-schema>`_.
148149

@@ -187,6 +188,7 @@ Here is the complete global configuration, also known as the *"global configurat
187188
.. code-block:: json
188189
189190
{
191+
"AuthenticationOptions": {},
190192
"BaseUrl": "",
191193
"CacheOptions": {},
192194
"DownstreamHeaderTransform": {}, // dictionary
@@ -208,6 +210,13 @@ Here is the complete global configuration, also known as the *"global configurat
208210
209211
The actual global configuration schema with all the properties can be found in the C# `FileGlobalConfiguration`_ class.
210212

213+
**Note 1**: The following global options were not supported in versions prior to `24.1`_ for overriding in the :ref:`config-dynamic-route-schema`: ``AuthenticationOptions``, ``CacheOptions``, ``HttpHandlerOptions``, ``LoadBalancerOptions``, ``QoSOptions``, ``RateLimitOptions``, and ``Timeout``.
214+
Moreover, these global options were not available in versions prior to `24.1`_ for static routes, as stated in issue `585`_.
215+
Starting with version `24.1`_, both static and dynamic route *global* options are fully supported.
216+
For a clearer understanding of the changes, refer to the :ref:`config-dynamic-route-schema` and related notes.
217+
218+
**Note 2**: The ``DownstreamHeaderTransform`` and ``UpstreamHeaderTransform`` global options were introduced in version `24.1`_, but they are available only for static routes.
219+
211220
.. _config-overview:
212221

213222
Configuration Overview
@@ -929,6 +938,7 @@ However, keep in mind that the absolute timeout has the lowest priority—theref
929938
930939
.. _default timeout of 90 seconds: https://github.com/ThreeMammals/Ocelot/blob/24.0.0/src/Ocelot/Requester/MessageInvokerPool.cs#L38
931940
.. _296: https://github.com/ThreeMammals/Ocelot/issues/296
941+
.. _585: https://github.com/ThreeMammals/Ocelot/issues/585
932942
.. _738: https://github.com/ThreeMammals/Ocelot/issues/738
933943
.. _1216: https://github.com/ThreeMammals/Ocelot/issues/1216
934944
.. _1227: https://github.com/ThreeMammals/Ocelot/pull/1227
@@ -943,4 +953,4 @@ However, keep in mind that the absolute timeout has the lowest priority—theref
943953
.. _23.2: https://github.com/ThreeMammals/Ocelot/releases/tag/23.2.0
944954
.. _23.3: https://github.com/ThreeMammals/Ocelot/releases/tag/23.3.0
945955
.. _24.1: https://github.com/ThreeMammals/Ocelot/releases/tag/24.1.0
946-
.. _25.0: https://github.com/ThreeMammals/Ocelot/milestone/12
956+
.. _25.0: https://github.com/ThreeMammals/Ocelot/milestone/13

docs/features/ratelimiting.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ Filter the current discussions by the `Rate Limiting <https://github.com/ThreeMa
322322
.. _23.3: https://github.com/ThreeMammals/Ocelot/releases/tag/23.3.0
323323
.. _24.0: https://github.com/ThreeMammals/Ocelot/releases/tag/24.0.0
324324
.. _24.1: https://github.com/ThreeMammals/Ocelot/releases/tag/24.1.0
325-
.. _25.0: https://github.com/ThreeMammals/Ocelot/milestone/12
325+
.. _25.0: https://github.com/ThreeMammals/Ocelot/milestone/13
326326

327327
.. |octocat| image:: https://assets-git.f3mw1.com/images/icons/emoji/octocat.png
328328
:alt: octocat

docs/features/servicediscovery.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,4 +680,4 @@ However, you can retain this ``Type`` option to maintain compatibility between b
680680
.. _13.5.2: https://github.com/ThreeMammals/Ocelot/releases/tag/13.5.2
681681
.. _23.3: https://github.com/ThreeMammals/Ocelot/releases/tag/23.3.0
682682
.. _24.1: https://github.com/ThreeMammals/Ocelot/releases/tag/24.1.0
683-
.. _25.0: https://github.com/ThreeMammals/Ocelot/milestone/12
683+
.. _25.0: https://github.com/ThreeMammals/Ocelot/milestone/13

src/Ocelot/Infrastructure/Extensions/StringValuesExtensions.cs renamed to src/Ocelot.Tracing.Butterfly/StringValuesExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.Extensions.Primitives;
22

3-
namespace Ocelot.Infrastructure.Extensions;
3+
namespace Ocelot.Tracing.Butterfly;
44

55
public static class StringValuesExtensions
66
{
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Ocelot.Administration;
2+
3+
public class AdministrationPath : IAdministrationPath
4+
{
5+
public AdministrationPath(string path, string apiSecret, Uri externalJwtServerUrl = null)
6+
{
7+
Path = path;
8+
IssuerSigningKey = apiSecret;
9+
ExternalJwtSigningUrl = externalJwtServerUrl;
10+
}
11+
12+
public string Path { get; }
13+
public string IssuerSigningKey { get; }
14+
public Uri ExternalJwtSigningUrl { get; }
15+
}

src/Ocelot/Configuration/FileConfigurationController.cs renamed to src/Ocelot/Administration/FileConfigurationController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using Microsoft.AspNetCore.Authorization;
22
using Microsoft.AspNetCore.Mvc;
3+
using Ocelot.Configuration;
34
using Ocelot.Configuration.File;
45
using Ocelot.Configuration.Repository;
56
using Ocelot.Configuration.Setter;
67

7-
namespace Ocelot.Configuration;
8+
namespace Ocelot.Administration;
89

10+
// [ApiController] // TODO: Make it ApiController
911
[Authorize]
1012
[Route("configuration")]
1113
public class FileConfigurationController : Controller
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Ocelot.Administration;
2+
3+
public interface IAdministrationPath
4+
{
5+
string Path { get; }
6+
string IssuerSigningKey { get; }
7+
Uri ExternalJwtSigningUrl { get; }
8+
}
Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
using Microsoft.AspNetCore.Authorization;
2-
using Microsoft.AspNetCore.Mvc;
3-
4-
namespace Ocelot.Cache;
5-
6-
[Authorize]
7-
[Route("outputcache")]
8-
public class OutputCacheController : Controller
9-
{
10-
private readonly IOcelotCache<CachedResponse> _cache;
11-
12-
public OutputCacheController(IOcelotCache<CachedResponse> cache)
13-
{
14-
_cache = cache;
15-
}
16-
17-
[HttpDelete]
18-
[Route("{region}")]
19-
public IActionResult Delete(string region)
20-
{
21-
_cache.ClearRegion(region);
22-
return new NoContentResult();
23-
}
24-
}
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Ocelot.Cache;
4+
5+
namespace Ocelot.Administration;
6+
7+
// [ApiController] // TODO: Make it ApiController
8+
//[Authorize(Policy = "OcelotAdministration")]
9+
[Authorize]
10+
[Route("outputcache")]
11+
public class OutputCacheController : Controller
12+
{
13+
private readonly IOcelotCache<CachedResponse> _cache;
14+
15+
public OutputCacheController(IOcelotCache<CachedResponse> cache)
16+
{
17+
_cache = cache;
18+
}
19+
20+
[HttpDelete]
21+
[Route("{region}")]
22+
public IActionResult Delete(string region)
23+
{
24+
_cache.ClearRegion(region);
25+
return new NoContentResult();
26+
}
27+
}

0 commit comments

Comments
 (0)