Authenticated encryption for enterprise secrets (#1078)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-10-17 20:36:34 +02:00
1 parent 031874cebf
commit 274d718314
26 files changed
+740 -89

No files matched your search

@@ -186,6 +186,11 @@ public sealed class SettingsManager
this.logger.LogInformation("No valid current-version settings backup was found. Migrating the settings file.");
settingsData = SettingsMigrations.Migrate(this.logger, settingsVersion.Version, await File.ReadAllTextAsync(settingsPath), JSON_OPTIONS);
// Compatibility shim, remove after 2027-10-31, see KeepTheLegacyEncryptionExportFormat.
// Settings of an older version always come from before the export format existed:
settingsData.App.EnterpriseEncryptionExportFormat = EnterpriseEncryptionFormat.V1;
this.PrepareLoadedSettings(settingsData);
await this.StoreSettingsSnapshot(settingsData, settingsPath);
await this.StoreCurrentVersionBackup(settingsData);
@@ -291,7 +296,8 @@ public sealed class SettingsManager
{
try
{
var settingsData = JsonSerializer.Deserialize<Data>(await File.ReadAllTextAsync(settingsPath), JSON_OPTIONS);
var settingsJson = await File.ReadAllTextAsync(settingsPath);
var settingsData = JsonSerializer.Deserialize<Data>(settingsJson, JSON_OPTIONS);
if(settingsData is null)
{
this.logger.LogError($"Failed to parse the {sourceDescription} '{settingsPath}'.");
@@ -304,6 +310,7 @@ public sealed class SettingsManager
return new(null, SettingsWriteBlockReason.CURRENT_VERSION_INVALID);
}
KeepTheLegacyEncryptionExportFormat(settingsData, settingsJson);
return new(settingsData, SettingsWriteBlockReason.NONE);
}
catch(Exception e)
@@ -313,6 +320,28 @@ public sealed class SettingsManager
}
}
/// <summary>
/// Lets an installation which existed before v26.10.1 keep exporting encrypted secrets in the
/// format v1, which every version of AI Studio reads.
/// </summary>
/// <remarks>
/// Compatibility shim, remove after 2027-10-31, see
/// documentation/compatibility-shims/2026-10-enterprise-encryption-export-format.md.<br/><br/>
/// New installations export in the authenticated format v2. An existing installation, however,
/// may belong to an administrator whose organization still runs an older version, which reads
/// v1 only. Settings written before v26.10.1 lack the export format, and nothing else tells
/// such an installation apart. Once the settings are stored, they hold the format, and this
/// changes nothing anymore.
/// </remarks>
private static void KeepTheLegacyEncryptionExportFormat(Data settingsData, string settingsJson)
{
using var settingsDocument = JsonDocument.Parse(settingsJson);
if(settingsDocument.RootElement.TryGetProperty(nameof(Data.App), out var appElement) && appElement.ValueKind is JsonValueKind.Object && appElement.TryGetProperty(nameof(DataApp.EnterpriseEncryptionExportFormat), out _))
return;
settingsData.App.EnterpriseEncryptionExportFormat = EnterpriseEncryptionFormat.V1;
}
private void BlockSettingsWrites(SettingsWriteBlockReason reason, string message)
{
this.SettingsWriteBlockReason = reason;