Skip to content

Commit b34a9c3

Browse files
authored
Removed FF calls causing instability in during VMSS configuration (#4750)
* wip * cleanup * fix
1 parent a3d9127 commit b34a9c3

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

src/Agent.Listener/Configuration/ConfigurationManager.cs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ public async Task ConfigureAsync(CommandSettings command)
120120
break;
121121
case PlatformUtil.OS.Windows:
122122
// Warn and continue if .NET 4.6 is not installed.
123-
#pragma warning disable CA1416 // SupportedOSPlatformGuard not honored on enum members
123+
#pragma warning disable CA1416 // SupportedOSPlatformGuard not honored on enum members
124124
if (!NetFrameworkUtil.Test(new Version(4, 6), Trace))
125125
{
126126
WriteSection(StringUtil.Loc("PrerequisitesSectionHeader")); // Section header.
127127
_term.WriteLine(StringUtil.Loc("MinimumNetFrameworkTfvc")); // Warning.
128128
}
129-
#pragma warning restore CA1416
129+
#pragma warning restore CA1416
130130

131131
break;
132132
default:
@@ -180,16 +180,34 @@ public async Task ConfigureAsync(CommandSettings command)
180180
_term.WriteError(StringUtil.Loc("FailedToConnect"));
181181
}
182182
}
183-
184-
// We want to use the native CSP of the platform for storage, so we use the RSACSP directly
183+
184+
bool rsaKeyGetConfigFromFF = global::Agent.Sdk.Knob.AgentKnobs.RsaKeyGetConfigFromFF.GetValue(UtilKnobValueContext.Instance()).AsBoolean();
185+
185186
RSAParameters publicKey;
186-
var keyManager = HostContext.GetService<IRSAKeyManager>();
187-
var ffResult = await keyManager.GetStoreAgentTokenInNamedContainerFF(HostContext, Trace, agentSettings, creds);
188-
var enableAgentKeyStoreInNamedContainer = ffResult.useNamedContainer;
189-
var useCng = ffResult.useCng;
190-
using (var rsa = keyManager.CreateKey(enableAgentKeyStoreInNamedContainer, useCng))
187+
188+
if (rsaKeyGetConfigFromFF)
189+
{
190+
// We want to use the native CSP of the platform for storage, so we use the RSACSP directly
191+
var keyManager = HostContext.GetService<IRSAKeyManager>();
192+
var ffResult = await keyManager.GetStoreAgentTokenInNamedContainerFF(HostContext, Trace, agentSettings, creds);
193+
var enableAgentKeyStoreInNamedContainer = ffResult.useNamedContainer;
194+
var useCng = ffResult.useCng;
195+
using (var rsa = keyManager.CreateKey(enableAgentKeyStoreInNamedContainer, useCng))
196+
{
197+
publicKey = rsa.ExportParameters(false);
198+
}
199+
}
200+
else
191201
{
192-
publicKey = rsa.ExportParameters(false);
202+
// We want to use the native CSP of the platform for storage, so we use the RSACSP directly
203+
var keyManager = HostContext.GetService<IRSAKeyManager>();
204+
var result = keyManager.GetStoreAgentTokenConfig();
205+
var enableAgentKeyStoreInNamedContainer = result.useNamedContainer;
206+
var useCng = result.useCng;
207+
using (var rsa = keyManager.CreateKey(enableAgentKeyStoreInNamedContainer, useCng))
208+
{
209+
publicKey = rsa.ExportParameters(false);
210+
}
193211
}
194212

195213
// Loop getting agent name and pool name

src/Agent.Listener/Configuration/IRSAKeyManager.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public static class IRSAKeyManagerExtensions
6060

6161
return (enableAgentKeyStoreInNamedContainerFF, useCngFF);
6262
}
63+
64+
public static (bool useNamedContainer, bool useCng) GetStoreAgentTokenConfig(this IRSAKeyManager _)
65+
{
66+
var useNamedContainer = AgentKnobs.StoreAgentKeyInCSPContainer.GetValue(UtilKnobValueContext.Instance()).AsBoolean();
67+
var useCng = AgentKnobs.AgentKeyUseCng.GetValue(UtilKnobValueContext.Instance()).AsBoolean();
68+
69+
return (useNamedContainer, useCng);
70+
}
6371
}
6472

6573
// Newtonsoft 10 is not working properly with dotnet RSAParameters class

src/Agent.Sdk/Knob/AgentKnobs.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,5 +663,11 @@ public class AgentKnobs
663663
new RuntimeKnobSource("AZP_AGENT_USE_INTEROP_TO_FIND_PARENT_PROCESS"),
664664
new EnvironmentKnobSource("AZP_AGENT_USE_INTEROP_TO_FIND_PARENT_PROCESS"),
665665
new BuiltInDefaultKnobSource("false"));
666+
667+
public static readonly Knob RsaKeyGetConfigFromFF = new Knob(
668+
nameof(RsaKeyGetConfigFromFF),
669+
"Get config from FF.",
670+
new EnvironmentKnobSource("RSAKEYGETCONFIGFROMFF"),
671+
new BuiltInDefaultKnobSource("false"));
666672
}
667673
}

0 commit comments

Comments
 (0)