Skip to content

Commit 4e6462e

Browse files
Revert "Ensure SyncTriggers clears secrets cache (#7698) (#7744)" (#7915)
* Revert "Ensure SyncTriggers clears secrets cache (#7698) (#7744)" This reverts commit d16b14d. * missing ScriptHostManager
1 parent da7b160 commit 4e6462e

File tree

5 files changed

+4
-59
lines changed

5 files changed

+4
-59
lines changed

src/WebJobs.Script.WebHost/Management/FunctionsSyncManager.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ public async Task<SyncTriggersResult> TrySyncTriggersAsync(bool isBackgroundSync
106106
{
107107
await _syncSemaphore.WaitAsync();
108108

109-
PrepareSyncTriggers();
110-
111109
var hashBlobClient = await GetHashBlobAsync();
112110
if (isBackgroundSync && hashBlobClient == null && !_environment.IsKubernetesManagedHosting())
113111
{
@@ -162,28 +160,6 @@ public async Task<SyncTriggersResult> TrySyncTriggersAsync(bool isBackgroundSync
162160
return result;
163161
}
164162

165-
/// <summary>
166-
/// SyncTriggers is performed whenever deployments or other changes are made to the application.
167-
/// There are some operations we want to perform whenever this happens.
168-
/// </summary>
169-
private void PrepareSyncTriggers()
170-
{
171-
// We clear cache to ensure that secrets are reloaded. This is important because secrets are part
172-
// of the StartupContext payload (see StartupContextProvider) and that payload comes from the
173-
// SyncTriggers operation. So there's a chicken and egg situation here. Consider the following scenario:
174-
// - app is using blob storage for keys
175-
// - a SyncTriggers operation has happened previously and the StartupContext has key info
176-
// - app instances initialize keys from StartupContext (keys aren't loaded from storage)
177-
// - user updates the app to use a new storage account
178-
// - a SyncTriggers operation is performed
179-
// - the app initializes from StartupContext, and **previous old key info is loaded**
180-
// - the SyncTriggers operation uses this old key info, so trigger cache is never updated with new key info
181-
// - Portal/ARM APIs will continue to show old key info.
182-
// By clearing cache, we ensure that this host instance reloads keys when they're requested, and the SyncTriggers
183-
// operation will contain current keys.
184-
_secretManagerProvider.Current.ClearCache();
185-
}
186-
187163
internal static bool IsSyncTriggersEnvironment(IScriptWebHostEnvironment webHostEnvironment, IEnvironment environment)
188164
{
189165
if (environment.IsCoreTools())

src/WebJobs.Script.WebHost/Security/KeyManagement/ISecretManager.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,5 @@ public interface ISecretManager
6868
/// <param name="rootScriptPath">The root function directory.</param>
6969
/// <param name="logger">The ILogger to log to.</param>
7070
Task PurgeOldSecretsAsync(string rootScriptPath, ILogger logger);
71-
72-
/// <summary>
73-
/// If secrets have been loaded and cached, clear all cached secrets so they'll
74-
/// be reloaded next time they're requested.
75-
/// </summary>
76-
void ClearCache();
7771
}
7872
}

src/WebJobs.Script.WebHost/Security/KeyManagement/SecretManager.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -651,13 +651,6 @@ private void ClearCacheOnChange(ScriptSecretsType secretsType, string functionNa
651651
}
652652
}
653653

654-
public void ClearCache()
655-
{
656-
_authorizationCache.Clear();
657-
_hostSecrets = null;
658-
_functionSecrets.Clear();
659-
}
660-
661654
private async Task<string> AnalyzeSnapshots(string[] secretBackups)
662655
{
663656
string analyzeResult = string.Empty;

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public class FunctionsSyncManagerTests : IDisposable
4646
private readonly Mock<IScriptWebHostEnvironment> _mockWebHostEnvironment;
4747
private readonly Mock<IEnvironment> _mockEnvironment;
4848
private readonly HostNameProvider _hostNameProvider;
49-
private readonly Mock<ISecretManager> _secretManagerMock;
5049
private readonly TestScriptHostService _scriptHostManager; // To refresh underlying IConfiguration for IAzureBlobStorageProvider
5150
private string _function1;
5251
private bool _emptyContent;
@@ -92,8 +91,8 @@ public FunctionsSyncManagerTests()
9291
var changeTokens = new[] { tokenSource };
9392
var optionsMonitor = new OptionsMonitor<ScriptApplicationHostOptions>(factory, changeTokens, factory);
9493
var secretManagerProviderMock = new Mock<ISecretManagerProvider>(MockBehavior.Strict);
95-
_secretManagerMock = new Mock<ISecretManager>(MockBehavior.Strict);
96-
secretManagerProviderMock.SetupGet(p => p.Current).Returns(_secretManagerMock.Object);
94+
var secretManagerMock = new Mock<ISecretManager>(MockBehavior.Strict);
95+
secretManagerProviderMock.SetupGet(p => p.Current).Returns(secretManagerMock.Object);
9796
var hostSecretsInfo = new HostSecretsInfo();
9897
hostSecretsInfo.MasterKey = "aaa";
9998
hostSecretsInfo.FunctionKeys = new Dictionary<string, string>
@@ -106,14 +105,13 @@ public FunctionsSyncManagerTests()
106105
{ "TestSystemKey1", "aaa" },
107106
{ "TestSystemKey2", "bbb" }
108107
};
109-
_secretManagerMock.Setup(p => p.GetHostSecretsAsync()).ReturnsAsync(hostSecretsInfo);
108+
secretManagerMock.Setup(p => p.GetHostSecretsAsync()).ReturnsAsync(hostSecretsInfo);
110109
Dictionary<string, string> functionSecretsResponse = new Dictionary<string, string>()
111110
{
112111
{ "TestFunctionKey1", "aaa" },
113112
{ "TestFunctionKey2", "bbb" }
114113
};
115-
_secretManagerMock.Setup(p => p.GetFunctionSecretsAsync("function1", false)).ReturnsAsync(functionSecretsResponse);
116-
_secretManagerMock.Setup(p => p.ClearCache());
114+
secretManagerMock.Setup(p => p.GetFunctionSecretsAsync("function1", false)).ReturnsAsync(functionSecretsResponse);
117115

118116
var configuration = ScriptSettingsManager.BuildDefaultConfiguration();
119117
var hostIdProviderMock = new Mock<IHostIdProvider>(MockBehavior.Strict);
@@ -318,18 +316,6 @@ public async Task TrySyncTriggers_BackgroundSync_DoesNotPostsEmptyContent()
318316
}
319317
}
320318

321-
[Fact]
322-
public async Task TrySyncTriggers_ClearsSecretsCache()
323-
{
324-
using (var env = new TestScopedEnvironmentVariable(_vars))
325-
{
326-
var result = await _functionsSyncManager.TrySyncTriggersAsync();
327-
Assert.True(result.Success);
328-
329-
_secretManagerMock.Verify(p => p.ClearCache(), Times.Once);
330-
}
331-
}
332-
333319
[Fact]
334320
public async Task TrySyncTriggers_BackgroundSync_PostsExpectedContent()
335321
{

test/WebJobs.Script.Tests.Shared/TestSecretManager.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ public void Reset()
9090
};
9191
}
9292

93-
public void ClearCache()
94-
{
95-
}
96-
9793
public async Task<(string, AuthorizationLevel)> GetAuthorizationLevelOrNullAsync(string key, string functionName = null)
9894
{
9995
return await SecretManager.GetAuthorizationLevelAsync(this, key, functionName);

0 commit comments

Comments
 (0)