From 0caea39df8f9a4e370cddc7971d21874dd4e0e21 Mon Sep 17 00:00:00 2001 From: Pragna Gopa Date: Wed, 18 Jul 2018 10:05:25 -0700 Subject: [PATCH 1/5] Update Java Worker (#3142) --- sample/HttpTrigger-Java/Function.java | 12 ++++++------ .../HttpTrigger-Java-1.0-SNAPSHOT.jar | Bin 4766 -> 5073 bytes src/WebJobs.Script/WebJobs.Script.csproj | 2 +- .../WebJobs.Script.Tests.Integration.csproj | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sample/HttpTrigger-Java/Function.java b/sample/HttpTrigger-Java/Function.java index 1283c96284..2187612ac6 100644 --- a/sample/HttpTrigger-Java/Function.java +++ b/sample/HttpTrigger-Java/Function.java @@ -15,13 +15,13 @@ */ public class Function { /** - * This function listens at endpoint "/api/hello". Two ways to invoke it using "curl" command in bash: - * 1. curl -d "HTTP Body" {your host}/api/hello + * This function listens at endpoint "/api/HttpTrigger-Java". Two ways to invoke it using "curl" command in bash: + * 1. curl -d "HTTP Body" {your host}/api/HttpTrigger-Java * 2. curl {your host}/api/HttpTrigger-Java?name=HTTP%20Query */ @FunctionName("HttpTrigger-Java") - public HttpResponseMessage HttpTriggerJava( - @HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage> request, + public HttpResponseMessage HttpTriggerJava( + @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage> request, final ExecutionContext context) { context.getLogger().info("Java HTTP trigger processed a request."); @@ -30,9 +30,9 @@ public HttpResponseMessage HttpTriggerJava( String name = request.getBody().orElse(query); if (name == null) { - return request.createResponse(400, "Please pass a name on the query string or in the request body"); + return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build(); } else { - return request.createResponse(200, "Hello " + name); + return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build(); } } } diff --git a/sample/HttpTrigger-Java/HttpTrigger-Java-1.0-SNAPSHOT.jar b/sample/HttpTrigger-Java/HttpTrigger-Java-1.0-SNAPSHOT.jar index b9611399b33a9b0e1e2f12b88f87526ddc7a94ec..8344f1ceb59715e23cdf51b84e26436e2329e952 100644 GIT binary patch delta 3243 zcmZve2T&8*(#JypgT@4qBE3m7AV#VR2m!?)p-D3cBGToC61fy9A(SY+1Q7|BA|j!L z&;{hurG(xUkRny-2!snFA2RRV8Q*+6v-3MUXLshzo|)Z$xi`~vYJgTe`I7_Of%jY0E-Qw+N7$M-05szPH869BLU1_0EE zs|;6&kAZABR}+3So*)Ax8d+KSVUkQK;&ROl$GEQdnP<9WL70%4Bj(GFPgus~-rM?w z=6qY2dWh%r5VOuliqGNkMg|&C%HxP18y>*PUf(Rg5k;c*ZA`6R%ao!GTLLO$-3N9Y|@7wmfskY6wo!I=|-q z(7;-_VBQ2`s2CvGcVo`i!0UGAr9oAxc!8bHyVFKJn{)P<67kU2X4s2gY5!Et_n`6F zYy3_2<J1WXqX~rdn-Rr_f!~1+Ueq zAaR)`()rwsxpxy9wOv1*+mj=f9o~9U;?f^^sYk_2%fzLtJ%)17+N=VrEGu<#(+O2g{PbLWgaUO*p0RW`EMK&nmU2W~dE~TK1nVOBFso+eYJD zlD*2+8_9BE z8%Fa*aI9O}z=mm?LV%oy0dp6R40mocc`efz5*7CSB_>vLErfvEcxP2Ps+Z&L(R2v2_GO^+9K74BMIxg{UM59(v_M% zl4n2!lk+Olyb|@buSNUV#RiOxDq-_ zP~SvR3|QaB*1k2{AO$vyX_Q8Yw7uZ7CNULaV5M)A# zrc2Rk2|QfEYGv?M7o&SwDiFCx}v&3=A2z3ztoPxro|IfG2+2$&zI1TSrXgR%^yFb)0%I4IRx7b z@vbEq@PN@OV%IcAD^is=8@_Ju(NI#Vw6t zQ9#{K9U(vHg2v_IcP&)E_U&X&P_uB4^7sTW$!%Ay@SP5- zbJk6R^xCPY^rG)(+_b?SSy!)$U@$mCQAVA?xxd#Rgb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c|GhoBlDb|AzX%8vqO7_;><@J!aB8dFQ_lV71vG zXJ9lZDGO`^8>7(Qa|8ge{jUcAP#IhJr_cr~!wweuzhC;R5XX2@cpcl$&I0OS`jhz| D=-w^r diff --git a/src/WebJobs.Script/WebJobs.Script.csproj b/src/WebJobs.Script/WebJobs.Script.csproj index e454ef483b..5fbeaf9715 100644 --- a/src/WebJobs.Script/WebJobs.Script.csproj +++ b/src/WebJobs.Script/WebJobs.Script.csproj @@ -31,7 +31,7 @@ NU1701 - + diff --git a/test/WebJobs.Script.Tests.Integration/WebJobs.Script.Tests.Integration.csproj b/test/WebJobs.Script.Tests.Integration/WebJobs.Script.Tests.Integration.csproj index 45a90c3017..86d3e0d60d 100644 --- a/test/WebJobs.Script.Tests.Integration/WebJobs.Script.Tests.Integration.csproj +++ b/test/WebJobs.Script.Tests.Integration/WebJobs.Script.Tests.Integration.csproj @@ -28,7 +28,7 @@ - + From 8182d587055c8ac1a84b4a1b952ae15b786e920a Mon Sep 17 00:00:00 2001 From: Ahmed ElSayed Date: Tue, 19 Jun 2018 14:40:24 -0700 Subject: [PATCH 2/5] Add a Dockerfile for building current HEAD --- Dockerfile | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..eb02048dab --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM microsoft/dotnet:2.1-sdk AS installer-env + +ENV PublishWithAspNetCoreTargetManifest false + +COPY . /workingdir + +RUN cd workingdir && \ + dotnet build WebJobs.Script.sln && \ + dotnet publish src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj --output /azure-functions-host + +# Runtime image +FROM microsoft/dotnet:2.1-aspnetcore-runtime + +RUN apt-get update && \ + apt-get install -y gnupg && \ + curl -sL https://deb.nodesource.com/setup_8.x | bash - && \ + apt-get update && \ + apt-get install -y nodejs + +COPY --from=installer-env ["/azure-functions-host", "/azure-functions-host"] +COPY --from=installer-env ["/workingdir/sample", "/home/site/wwwroot"] + +ENV AzureWebJobsScriptRoot=/home/site/wwwroot +ENV HOME=/home +ENV ASPNETCORE_URLS=http://+:80 +EXPOSE 80 + +CMD dotnet /azure-functions-host/Microsoft.Azure.WebJobs.Script.WebHost.dll From 02f70ce1e5ed67faa9587c5bcec539a5cc9d1b6c Mon Sep 17 00:00:00 2001 From: Brett Samblanet Date: Mon, 23 Jul 2018 11:53:13 -0700 Subject: [PATCH 3/5] protecting TestLogger from collection modifications --- .../WebJobs.Script.Tests.Shared/TestLogger.cs | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/WebJobs.Script.Tests.Shared/TestLogger.cs b/test/WebJobs.Script.Tests.Shared/TestLogger.cs index deaaf95eca..ac2f6d7d14 100644 --- a/test/WebJobs.Script.Tests.Shared/TestLogger.cs +++ b/test/WebJobs.Script.Tests.Shared/TestLogger.cs @@ -13,6 +13,9 @@ public class TestLogger : ILogger private readonly Func _filter; private IList _logMessages = new List(); + // protect against changes to _logMessages while enumerating + private object _syncLock = new object(); + public TestLogger(string category, Func filter = null) { Category = category; @@ -31,9 +34,21 @@ public bool IsEnabled(LogLevel logLevel) return _filter?.Invoke(Category, logLevel) ?? true; } - public IList GetLogMessages() => _logMessages.ToList(); + public IList GetLogMessages() + { + lock (_syncLock) + { + return _logMessages.ToList(); + } + } - public void ClearLogMessages() => _logMessages.Clear(); + public void ClearLogMessages() + { + lock (_syncLock) + { + _logMessages.Clear(); + } + } public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { @@ -53,7 +68,10 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except Timestamp = DateTime.UtcNow }; - _logMessages.Add(logMessage); + lock (_syncLock) + { + _logMessages.Add(logMessage); + } } } From 905e90adeea88ba8b77bd3da898a25ac4d68f895 Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Mon, 23 Jul 2018 13:29:48 -0700 Subject: [PATCH 4/5] Adding x64 for V2. Fixes #2909 --- build.ps1 | 57 ++++++++++++++----- .../WebJobs.Script.WebHost.csproj | 8 ++- .../applicationHost.xdt | 6 +- .../web.InProcess.win-x64.xdt | 9 +++ ...nProcess.xdt => web.InProcess.win-x86.xdt} | 0 5 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 src/WebJobs.Script.WebHost/web.InProcess.win-x64.xdt rename src/WebJobs.Script.WebHost/{web.InProcess.xdt => web.InProcess.win-x86.xdt} (100%) diff --git a/build.ps1 b/build.ps1 index b00d5afde5..5cf077f811 100644 --- a/build.ps1 +++ b/build.ps1 @@ -44,7 +44,7 @@ function CrossGen([string] $runtime, [string] $publishTarget, [string] $privateS # Modify web.config for inproc dotnet tool install -g dotnet-xdt --version 2.1.0-rc.1 - dotnet-xdt -s "$privateSiteExtensionPath\web.config" -t "$privateSiteExtensionPath\web.InProcess.xdt" -o "$privateSiteExtensionPath\web.config" + dotnet-xdt -s "$privateSiteExtensionPath\web.config" -t "$privateSiteExtensionPath\web.InProcess.$runtime.xdt" -o "$privateSiteExtensionPath\web.config" $successfullDlls =@() $failedDlls = @() @@ -87,8 +87,9 @@ function CrossGen([string] $runtime, [string] $publishTarget, [string] $privateS } - # If not self-contained - Copy-Item -Path $privateSiteExtensionPath\runtimes\win\native\* -Destination $privateSiteExtensionPath -Force + if ($runtime -eq "win-x86") { + Copy-Item -Path $privateSiteExtensionPath\runtimes\win\native\* -Destination $privateSiteExtensionPath -Force + } #read-host "Press ENTER to continue..." Remove-Item -Recurse -Force $selfContained -ErrorAction SilentlyContinue @@ -116,7 +117,26 @@ function DownloadNupkg([string] $nupkgPath, [string[]]$from, [string[]]$to) { } } -function BuildPackages([string] $runtime<#, [bool] $isSelfContained#>) { +function BuildPackages([bool] $isNoRuntime) { + if($isNoRuntime) { + BuildOutput "" + CreateZips ".no-runtime" + } else { + BuildOutput "win-x86" + BuildOutput "win-x64" + + New-Item -Itemtype directory -path $buildOutput\publish.runtime\SiteExtensions\Functions + Move-Item -Path $buildOutput\publish.win-x86\SiteExtensions\Functions -Destination $buildOutput\publish.runtime\SiteExtensions\Functions\32bit -Force + Move-Item -Path $buildOutput\publish.win-x64\SiteExtensions\Functions -Destination $buildOutput\publish.runtime\SiteExtensions\Functions\64bit -Force + Move-Item -Path $buildOutput\publish.runtime\SiteExtensions\Functions\32bit\applicationHost.xdt -Destination $buildOutput\publish.runtime\SiteExtensions\Functions -Force + Remove-Item -Path $buildOutput\publish.runtime\SiteExtensions\Functions\64bit\applicationHost.xdt + + CreateZips ".runtime" + } +} + + +function BuildOutput([string] $runtime) { $runtimeSuffix = "" if (![string]::IsNullOrEmpty($runtime)) { $runtimeSuffix = ".$runtime" @@ -128,17 +148,28 @@ function BuildPackages([string] $runtime<#, [bool] $isSelfContained#>) { $siteExtensionPath = "$publishTarget\SiteExtensions" $privateSiteExtensionPath = "$siteExtensionPath\Functions" - dotnet publish .\src\WebJobs.Script.WebHost\WebJobs.Script.WebHost.csproj -o "$privateSiteExtensionPath" -v q /p:BuildNumber=$buildNumber /p:IsPackable=false -c Release - #dotnet publish .\src\WebJobs.Script.WebHost\WebJobs.Script.WebHost.csproj -r $runtime -o "$privateSiteExtensionPath" -v q /p:BuildNumber=$buildNumber /p:IsPackable=false -c Release + if ($runtime -eq "win-x86" -or $runtime -eq "") { + dotnet publish .\src\WebJobs.Script.WebHost\WebJobs.Script.WebHost.csproj -o "$privateSiteExtensionPath" -v q /p:BuildNumber=$buildNumber /p:IsPackable=false -c Release + } else { + # There are no preinstalled 'x64 .NET Core'/'x64 ASP.NET Core' on the stamp so we we need to build self-contained package for x64. + dotnet publish .\src\WebJobs.Script.WebHost\WebJobs.Script.WebHost.csproj -r $runtime -o "$privateSiteExtensionPath" -v q /p:BuildNumber=$buildNumber /p:IsPackable=false -c Release + } # replace IL dlls with crossgen dlls if (![string]::IsNullOrEmpty($runtime)) { CrossGen $runtime $publishTarget $privateSiteExtensionPath } +} - # Do not put siffux to win-x86 zips names - if ($runtime -eq "win-x86") { - $runtimeSuffix = ""; + +function CreateZips([string] $runtimeSuffix) { + $publishTarget = "$buildOutput\publish$runtimeSuffix" + $siteExtensionPath = "$publishTarget\SiteExtensions" + $privateSiteExtensionPath = "$siteExtensionPath\Functions" + + # We do not want .runtime as suffix for zips + if ($runtimeSuffix -eq ".runtime") { + $runtimesuffix = ""; } ZipContent $privateSiteExtensionPath "$buildOutput\Functions.Binaries.$extensionVersion-alpha$runtimeSuffix.zip" @@ -184,9 +215,9 @@ $bypassPackaging = $env:APPVEYOR_PULL_REQUEST_NUMBER -and -not $env:APPVEYOR_PUL if ($bypassPackaging){ Write-Host "Bypassing artifact packaging and CrossGen for pull request." -ForegroundColor Yellow } else { - # build IL extensions - BuildPackages "" + # build no-runntime extension + BuildPackages 1 - #build win-x86 extensions - BuildPackages "win-x86" + #build win-x86 and win-x64 extension + BuildPackages 0 } \ No newline at end of file diff --git a/src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj b/src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj index deace9a146..d1abfad727 100644 --- a/src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj +++ b/src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj @@ -24,13 +24,17 @@ - + + Always - + + Always + + Always diff --git a/src/WebJobs.Script.WebHost/applicationHost.xdt b/src/WebJobs.Script.WebHost/applicationHost.xdt index 14a92748e3..9328d99c11 100644 --- a/src/WebJobs.Script.WebHost/applicationHost.xdt +++ b/src/WebJobs.Script.WebHost/applicationHost.xdt @@ -5,15 +5,15 @@ - - + + - + diff --git a/src/WebJobs.Script.WebHost/web.InProcess.win-x64.xdt b/src/WebJobs.Script.WebHost/web.InProcess.win-x64.xdt new file mode 100644 index 0000000000..7772c0a572 --- /dev/null +++ b/src/WebJobs.Script.WebHost/web.InProcess.win-x64.xdt @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/WebJobs.Script.WebHost/web.InProcess.xdt b/src/WebJobs.Script.WebHost/web.InProcess.win-x86.xdt similarity index 100% rename from src/WebJobs.Script.WebHost/web.InProcess.xdt rename to src/WebJobs.Script.WebHost/web.InProcess.win-x86.xdt From d231af8e526f1f0003cf2ec48fc2e674a64a967c Mon Sep 17 00:00:00 2001 From: Fabio Cavalcante Date: Fri, 20 Jul 2018 18:21:34 -0700 Subject: [PATCH 5/5] Tactical fix to update JWT validation parameters after specialization --- .../Jwt/ScriptJwtBearerExtensions.cs | 50 +++++++++++++++---- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/src/WebJobs.Script.WebHost/Security/Authentication/Jwt/ScriptJwtBearerExtensions.cs b/src/WebJobs.Script.WebHost/Security/Authentication/Jwt/ScriptJwtBearerExtensions.cs index d352ceea65..5a2be99dec 100644 --- a/src/WebJobs.Script.WebHost/Security/Authentication/Jwt/ScriptJwtBearerExtensions.cs +++ b/src/WebJobs.Script.WebHost/Security/Authentication/Jwt/ScriptJwtBearerExtensions.cs @@ -1,14 +1,17 @@ // 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 System.Security.Claims; using System.Text; +using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.Azure.Web.DataProtection; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.Azure.WebJobs.Script.Config; +using Microsoft.Azure.WebJobs.Script.WebHost; using Microsoft.Azure.WebJobs.Script.WebHost.Security.Authentication; using Microsoft.IdentityModel.Tokens; using static Microsoft.Azure.WebJobs.Script.EnvironmentSettingNames; @@ -18,11 +21,23 @@ namespace Microsoft.Extensions.DependencyInjection { public static class ScriptJwtBearerExtensions { + private static double _specialized = 0; + public static AuthenticationBuilder AddScriptJwtBearer(this AuthenticationBuilder builder) => builder.AddJwtBearer(o => { o.Events = new JwtBearerEvents() { + OnMessageReceived = c => + { + // Temporary: Tactical fix to address specialization issues. This should likely be moved to a token validator + if (_specialized == 0 && !WebScriptHostManager.InStandbyMode && Interlocked.CompareExchange(ref _specialized, 1, 0) == 0) + { + o.TokenValidationParameters = CreateTokenValidationParameters(); + } + + return Task.CompletedTask; + }, OnTokenValidated = c => { c.Principal.AddIdentity(new ClaimsIdentity(new Claim[] @@ -35,19 +50,32 @@ public static AuthenticationBuilder AddScriptJwtBearer(this AuthenticationBuilde return Task.CompletedTask; } }; - string defaultKey = Util.GetDefaultKeyValue(); - if (defaultKey != null) + + o.TokenValidationParameters = CreateTokenValidationParameters(); + + if (!WebScriptHostManager.InStandbyMode) { - // TODO: Once ScriptSettingsManager is gone, Audience and Issuer shouold be pulled from configuration. - o.TokenValidationParameters = new TokenValidationParameters() - { - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(defaultKey)), - ValidateAudience = true, - ValidateIssuer = true, - ValidAudience = string.Format(AdminJwtValidAudienceFormat, ScriptSettingsManager.Instance.GetSetting(AzureWebsiteName)), - ValidIssuer = string.Format(AdminJwtValidIssuerFormat, ScriptSettingsManager.Instance.GetSetting(AzureWebsiteName)) - }; + // We're not in standby mode, so flag as specialized + _specialized = 1; } }); + + private static TokenValidationParameters CreateTokenValidationParameters() + { + string defaultKey = Util.GetDefaultKeyValue(); + + var result = new TokenValidationParameters(); + if (defaultKey != null) + { + // TODO: Once ScriptSettingsManager is gone, Audience and Issuer shouold be pulled from configuration. + result.IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(defaultKey)); + result.ValidateAudience = true; + result.ValidateIssuer = true; + result.ValidAudience = string.Format(AdminJwtValidAudienceFormat, ScriptSettingsManager.Instance.GetSetting(AzureWebsiteName)); + result.ValidIssuer = string.Format(AdminJwtValidIssuerFormat, ScriptSettingsManager.Instance.GetSetting(AzureWebsiteName)); + } + + return result; + } } }