Skip to content

Commit b8f5178

Browse files
authored
[LinuxConsumption]Changing TokenService MSI sidecar specialization API to 2022-01-01 (#9077)
1 parent 1d39e2c commit b8f5178

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

src/WebJobs.Script.WebHost/Models/MSIContext.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@ public class MSIContext
1212
public string MSISecret { get; set; }
1313

1414
public IEnumerable<ManagedServiceIdentity> Identities { get; set; }
15+
16+
public ManagedServiceIdentity SystemAssignedIdentity { get; set; }
17+
18+
public IEnumerable<ManagedServiceIdentity> UserAssignedIdentities { get; set; }
19+
20+
public IEnumerable<ManagedServiceIdentity> DelegatedIdentities { get; set; }
1521
}
1622
}

src/WebJobs.Script/ScriptConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static class ScriptConstants
165165
public const string LinuxMetricEventStreamName = "MS_FUNCTION_METRICS";
166166
public const string LinuxFunctionDetailsEventStreamName = "MS_FUNCTION_DETAILS";
167167
public const string LinuxAzureMonitorEventStreamName = "MS_FUNCTION_AZURE_MONITOR_EVENT";
168-
public const string LinuxMSISpecializationStem = "/api/specialize?api-version=2017-09-01";
168+
public const string LinuxMSISpecializationStem = "/api/specialize?api-version=2022-01-01";
169169

170170
public const string DurableTaskPropertyName = "durableTask";
171171
public const string DurableTaskHubName = "HubName";

test/WebJobs.Script.Tests.Integration/Management/InstanceManagerTests.cs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,56 @@ public async Task SpecializeMSISidecar_Succeeds()
618618
p => Assert.StartsWith("Specialize MSI sidecar returned OK", p));
619619
}
620620

621+
[Fact]
622+
public async Task SpecializeMsiSidecar_RequiredPropertiesInPayload()
623+
{
624+
var environment = new Dictionary<string, string>()
625+
{
626+
{ EnvironmentSettingNames.MsiEndpoint, "http://localhost:8081" },
627+
{ EnvironmentSettingNames.MsiSecret, "secret" }
628+
};
629+
var assignmentContext = new HostAssignmentContext
630+
{
631+
SiteId = 1234,
632+
SiteName = "TestSite",
633+
Environment = environment,
634+
IsWarmupRequest = false,
635+
MSIContext = new MSIContext()
636+
{
637+
SiteName = "TestSite",
638+
MSISecret = "TestSecret1234",
639+
Identities = new[] { new ManagedServiceIdentity() },
640+
SystemAssignedIdentity = new ManagedServiceIdentity(),
641+
DelegatedIdentities = new[] { new ManagedServiceIdentity() },
642+
UserAssignedIdentities = new[] { new ManagedServiceIdentity() },
643+
}
644+
};
645+
646+
static async void verifyProperties(HttpRequestMessage request, CancellationToken token)
647+
{
648+
var requestContent = await request.Content.ReadAsStringAsync(token);
649+
var msiContext = JsonConvert.DeserializeObject<MSIContext>(requestContent);
650+
Assert.NotNull(msiContext);
651+
Assert.NotNull(msiContext.Identities);
652+
Assert.NotNull(msiContext.SystemAssignedIdentity);
653+
Assert.NotNull(msiContext.UserAssignedIdentities);
654+
Assert.NotNull(msiContext.DelegatedIdentities);
655+
Assert.True(!string.IsNullOrEmpty(msiContext.MSISecret));
656+
Assert.True(!string.IsNullOrEmpty(msiContext.SiteName));
657+
}
658+
659+
var instanceManager = GetInstanceManagerForMSISpecialization(assignmentContext, HttpStatusCode.OK, null, customAction: verifyProperties);
660+
661+
string error = await instanceManager.SpecializeMSISidecar(assignmentContext);
662+
Assert.Null(error);
663+
664+
var logs = _loggerProvider.GetAllLogMessages().Select(p => p.FormattedMessage).ToArray();
665+
Assert.Collection(logs,
666+
p => Assert.StartsWith("MSI enabled status: True", p),
667+
p => Assert.StartsWith("Specializing sidecar at http://localhost:8081", p),
668+
p => Assert.StartsWith("Specialize MSI sidecar returned OK", p));
669+
}
670+
621671
[Fact]
622672
public async Task SpecializeMSISidecar_NoOp_ForWarmup_Request()
623673
{
@@ -1252,7 +1302,7 @@ private static bool MatchesRunFromPackageContext(RunFromPackageContext r, string
12521302
}
12531303

12541304
private AtlasInstanceManager GetInstanceManagerForMSISpecialization(HostAssignmentContext hostAssignmentContext,
1255-
HttpStatusCode httpStatusCode, IMeshServiceClient meshServiceClient)
1305+
HttpStatusCode httpStatusCode, IMeshServiceClient meshServiceClient, Action<HttpRequestMessage, CancellationToken> customAction = null)
12561306
{
12571307
var handlerMock = new Mock<HttpMessageHandler>(MockBehavior.Strict);
12581308

@@ -1262,7 +1312,9 @@ private AtlasInstanceManager GetInstanceManagerForMSISpecialization(HostAssignme
12621312
ItExpr.Is<HttpRequestMessage>(request => request.Method == HttpMethod.Post
12631313
&& request.RequestUri.AbsoluteUri.Equals(msiEndpoint)
12641314
&& request.Content != null),
1265-
ItExpr.IsAny<CancellationToken>()).ReturnsAsync(new HttpResponseMessage
1315+
ItExpr.IsAny<CancellationToken>())
1316+
.Callback<HttpRequestMessage, CancellationToken>((request, token) => customAction?.Invoke(request, token))
1317+
.ReturnsAsync(new HttpResponseMessage
12661318
{
12671319
StatusCode = httpStatusCode
12681320
});

0 commit comments

Comments
 (0)