Skip to content

Commit 2990a47

Browse files
authored
Merge pull request #5479 from Azure/dev
Merging dev to master
2 parents 7c6ae82 + acfb162 commit 2990a47

38 files changed

+4246
-63
lines changed

build/python.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<ItemGroup>
3-
<PackageReference Include="Microsoft.Azure.Functions.PythonWorker" Version="1.0.201911015" />
3+
<PackageReference Include="Microsoft.Azure.Functions.PythonWorker" Version="1.0.201912137" />
44
</ItemGroup>
5-
</Project>
5+
</Project>

src/WebJobs.Script.Grpc/generate_protos.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ setlocal
3434
@rem enter Script.Rpc directory
3535
cd /d %~dp0
3636

37-
set NUGET_PATH=%UserProfile%\.nuget\packages
37+
set NUGET_PATH="%UserProfile%\.nuget\packages"
3838
set GRPC_TOOLS_PATH=%NUGET_PATH%\grpc.tools\1.20.1\tools\windows_x86
3939
set PROTO_PATH=.\azure-functions-language-worker-protobuf\src\proto
4040
set PROTO=.\azure-functions-language-worker-protobuf\src\proto\FunctionRpc.proto

src/WebJobs.Script.WebHost/Controllers/KeysController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
namespace Microsoft.Azure.WebJobs.Script.WebHost.Controllers
2121
{
2222
[Authorize(Policy = PolicyNames.AdminAuthLevel)]
23+
[ResourceContainsSecrets]
2324
public class KeysController : Controller
2425
{
2526
private const string MasterKeyName = "_master";

src/WebJobs.Script.WebHost/Diagnostics/LinuxContainerEventGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public LinuxContainerEventGenerator(IEnvironment environment, Action<string> wri
3838

3939
public static string DetailsEventRegex { get; } = $"{ScriptConstants.LinuxFunctionDetailsEventStreamName} (?<AppName>[^,]*),(?<FunctionName>[^,]*),\\\\\"(?<InputBindings>.*)\\\\\",\\\\\"(?<OutputBindings>.*)\\\\\",(?<ScriptType>[^,]*),(?<IsDisabled>[0|1])";
4040

41-
public static string AzureMonitorEventRegex { get; } = $"{ScriptConstants.LinuxAzureMonitorEventStreamName} (?<Level>[0-6]),(?<ResourceId>[^,]*),(?<OperationName>[^,]*),(?<Category>[^,]*),(?<RegionName>[^,]*),(?<Properties>[^,]*),(?<ContainerName>[^,\"]*),(?<TenantId>[^,\"]*),(?<EventTimestamp>[^,]+)";
41+
public static string AzureMonitorEventRegex { get; } = $"{ScriptConstants.LinuxAzureMonitorEventStreamName} (?<Level>[0-6]),(?<ResourceId>[^,]*),(?<OperationName>[^,]*),(?<Category>[^,]*),(?<RegionName>[^,]*),\"(?<Properties>[^,]*)\",(?<ContainerName>[^,\"]*),(?<TenantId>[^,\"]*),(?<EventTimestamp>[^,]+)";
4242

4343
private string StampName
4444
{
@@ -104,7 +104,7 @@ private void ConsoleWriter(string evt)
104104

105105
public override void LogAzureMonitorDiagnosticLogEvent(LogLevel level, string resourceId, string operationName, string category, string regionName, string properties)
106106
{
107-
_writeEvent($"{ScriptConstants.LinuxAzureMonitorEventStreamName} {(int)ToEventLevel(level)},{resourceId},{operationName},{category},{regionName},{properties},{_containerName},{TenantId}, {DateTime.UtcNow.ToString()}");
107+
_writeEvent($"{ScriptConstants.LinuxAzureMonitorEventStreamName} {(int)ToEventLevel(level)},{resourceId},{operationName},{category},{regionName},{NormalizeString(properties)},{_containerName},{TenantId},{DateTime.UtcNow.ToString()}");
108108
}
109109
}
110110
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Http;
7+
using Microsoft.AspNetCore.Mvc.Controllers;
8+
using Microsoft.AspNetCore.Mvc.Filters;
9+
using Microsoft.Azure.WebJobs.Script.Extensions;
10+
using Microsoft.Azure.WebJobs.Script.WebHost.Properties;
11+
12+
namespace Microsoft.Azure.WebJobs.Script.WebHost.Filters
13+
{
14+
/// <summary>
15+
/// Resource filter used to ensure secrets aren't returned for GET requests made via the Functions ARM extension
16+
/// API (hostruntime), unless properly authorized.
17+
/// </summary>
18+
/// <remarks>
19+
/// All our first class ARM APIs handle RBAC naturally. For the hostruntime bridge, the runtime collaborates
20+
/// based on request details coming from ARM/Geo.
21+
/// </remarks>
22+
public sealed class ArmExtensionResourceFilter : IAsyncResourceFilter
23+
{
24+
public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next)
25+
{
26+
// We only want to apply this filter for GET extension ARM requests that were forwarded directly to us via
27+
// hostruntime bridge, not hostruntime requests initiated internally by the geomaster. The latter requests
28+
// won't have the x-ms-arm-request-tracking-id header.
29+
var request = context.HttpContext.Request;
30+
bool isArmExtensionRequest = request.HasHeader(ScriptConstants.AntaresARMRequestTrackingIdHeader) &&
31+
request.HasHeader(ScriptConstants.AntaresARMExtensionsRouteHeader);
32+
33+
if (isArmExtensionRequest && string.Equals(request.Method, "GET", StringComparison.OrdinalIgnoreCase))
34+
{
35+
// requests made by owner/co-admin are not filtered
36+
if (!request.HasHeaderValue(ScriptConstants.AntaresClientAuthorizationSourceHeader, "legacy"))
37+
{
38+
var controllerActionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
39+
if (controllerActionDescriptor != null && controllerActionDescriptor.MethodInfo != null &&
40+
Utility.GetHierarchicalAttributeOrNull<ResourceContainsSecretsAttribute>(controllerActionDescriptor.MethodInfo) != null)
41+
{
42+
// if the resource returned by the action contains secrets, fail the request
43+
context.HttpContext.Response.StatusCode = StatusCodes.Status401Unauthorized;
44+
await context.HttpContext.Response.WriteAsync(Resources.UnauthorizedArmExtensionResourceRequest);
45+
return;
46+
}
47+
}
48+
}
49+
50+
await next();
51+
}
52+
}
53+
}

src/WebJobs.Script.WebHost/Metrics/LinuxContainerMetricsPublisher.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,17 @@ private async Task PublishActivity<T>(ConcurrentQueue<T> currentActivities, Bloc
229229

230230
internal async Task SendRequest<T>(ConcurrentQueue<T> activitiesToPublish, string publishPath)
231231
{
232-
var request = BuildRequest(HttpMethod.Post, publishPath, activitiesToPublish.ToArray());
233-
_logger.LogDebug($"Publishing {activitiesToPublish.Count()} activities to {publishPath}.");
234-
HttpResponseMessage response = await _httpClient.SendAsync(request);
235-
response.EnsureSuccessStatusCode();
232+
try
233+
{
234+
var request = BuildRequest(HttpMethod.Post, publishPath, activitiesToPublish.ToArray());
235+
236+
HttpResponseMessage response = await _httpClient.SendAsync(request);
237+
response.EnsureSuccessStatusCode();
238+
}
239+
catch (Exception ex)
240+
{
241+
_logger.LogError(ex, $"Failed to publish status to {publishPath}");
242+
}
236243
}
237244

238245
public void Initialize()

src/WebJobs.Script.WebHost/Middleware/AppServiceHeaderFixupMiddleware.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4+
using System.Linq;
45
using System.Threading.Tasks;
56
using Microsoft.AspNetCore.Http;
6-
using Microsoft.Azure.WebJobs.Script.Extensions;
77
using Microsoft.Extensions.Primitives;
88

99
namespace Microsoft.Azure.WebJobs.Script.WebHost.Middleware
1010
{
1111
public class AppServiceHeaderFixupMiddleware
1212
{
13-
private const string DisguisedHostHeader = "DISGUISED-HOST";
14-
private const string HostHeader = "HOST";
15-
private const string ForwardedProtocolHeader = "X-Forwarded-Proto";
13+
internal const string DisguisedHostHeader = "DISGUISED-HOST";
14+
internal const string HostHeader = "HOST";
15+
internal const string ForwardedProtocolHeader = "X-Forwarded-Proto";
1616
private readonly RequestDelegate _next;
1717

1818
public AppServiceHeaderFixupMiddleware(RequestDelegate next)
@@ -29,7 +29,11 @@ public async Task Invoke(HttpContext httpContext)
2929

3030
if (httpContext.Request.Headers.TryGetValue(ForwardedProtocolHeader, out value))
3131
{
32-
httpContext.Request.Scheme = value;
32+
string scheme = value.FirstOrDefault();
33+
if (!string.IsNullOrEmpty(scheme))
34+
{
35+
httpContext.Request.Scheme = scheme;
36+
}
3337
}
3438

3539
await _next(httpContext);

src/WebJobs.Script.WebHost/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/WebJobs.Script.WebHost/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,7 @@
294294
<data name="TraceStaleHostSecretRefresh" xml:space="preserve">
295295
<value>Stale host secrets detected. Refreshing secrets.</value>
296296
</data>
297+
<data name="UnauthorizedArmExtensionResourceRequest" xml:space="preserve">
298+
<value>GET requests for this resource via the hostruntime extensions API are not authorized. Please use an alternate first class ARM API.</value>
299+
</data>
297300
</root>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
6+
namespace Microsoft.Azure.WebJobs.Script.WebHost
7+
{
8+
/// <summary>
9+
/// Attribute applied to actions to indicate whether the resource returned by an action
10+
/// contains secrets.
11+
/// </summary>
12+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
13+
public class ResourceContainsSecretsAttribute : Attribute
14+
{
15+
}
16+
}

0 commit comments

Comments
 (0)