-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scope ScriptJwtBearerHandler logs to system-only (#10617)
* Return NoResult for non-admin APIs for script JWT auth * Return NoResult for invalid issuers for JWT auth * Pass NullLogger to JwtBearerHandler * Introduce new ISystemLoggerFactory for system-only loggers * Fix e2e tests * Default to NullLoggerFactory to address tests * update release_notes.md
- Loading branch information
Showing
9 changed files
with
142 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/WebJobs.Script.WebHost/Security/Authentication/Jwt/ScriptJwtBearerHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Text.Encodings.Web; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
using Microsoft.Azure.WebJobs.Script.Diagnostics; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.WebHost.Security.Authentication.Jwt | ||
{ | ||
internal sealed class ScriptJwtBearerHandler : JwtBearerHandler | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ScriptJwtBearerHandler"/> class. | ||
/// </summary> | ||
/// <param name="options">The options.</param> | ||
/// <param name="encoder">The url encoder.</param> | ||
/// <param name="clock">The system clock.</param> | ||
/// <param name="loggerFactory">The system logger factory.</param> | ||
public ScriptJwtBearerHandler( | ||
IOptionsMonitor<JwtBearerOptions> options, | ||
UrlEncoder encoder, | ||
ISystemClock clock, | ||
ISystemLoggerFactory loggerFactory = null) | ||
: base(options, (ILoggerFactory)loggerFactory ?? NullLoggerFactory.Instance, encoder, clock) | ||
{ | ||
// Note - ISystemLoggerFactory falls back to NullLoggerFactory to avoid needing this service in tests. | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Diagnostics | ||
{ | ||
/// <summary> | ||
/// A logger factory which is used to create loggers for system-only logs. | ||
/// </summary> | ||
internal interface ISystemLoggerFactory : ILoggerFactory | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Diagnostics | ||
{ | ||
/// <summary> | ||
/// Default implementation of <see cref="ISystemLoggerFactory"/>. | ||
/// </summary> | ||
/// <param name="loggerFactory">The logger factory from the root container to wrap.</param> | ||
internal class SystemLoggerFactory(ILoggerFactory loggerFactory) : ISystemLoggerFactory | ||
{ | ||
public void AddProvider(ILoggerProvider provider) | ||
=> throw new InvalidOperationException("Cannot add providers to the system logger factory."); | ||
|
||
public ILogger CreateLogger(string categoryName) => loggerFactory.CreateLogger(categoryName); | ||
|
||
public void Dispose() | ||
{ | ||
// No op - we do not dispose the provided logger factory. | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters