Skip to content

Commit 6087fe3

Browse files
msJinLeiLei Jin
authored andcommitted
Enable AzKeystore with keyring in Linux
1 parent e692a81 commit 6087fe3

File tree

6 files changed

+10
-7
lines changed

6 files changed

+10
-7
lines changed

src/Accounts/Accounts.Test/AutosaveTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private AzKeyStore SetMockedAzKeyStore()
5050
storageMocker.Setup(f => f.Create()).Returns(storageMocker.Object);
5151
storageMocker.Setup(f => f.ReadData()).Returns(new byte[0]);
5252
storageMocker.Setup(f => f.WriteData(It.IsAny<byte[]>())).Callback((byte[] s) => {});
53-
var keyStore = new AzKeyStore(AzureSession.Instance.ARMProfileDirectory, "keystore.cache", false, false, storageMocker.Object);
53+
var keyStore = new AzKeyStore(AzureSession.Instance.ARMProfileDirectory, "azkeystore.cache", false, false, storageMocker.Object);
5454
AzKeyStore.RegisterJsonConverter(typeof(ServicePrincipalKey), typeof(ServicePrincipalKey).Name);
5555
AzKeyStore.RegisterJsonConverter(typeof(SecureString), typeof(SecureString).Name, new SecureStringConverter());
5656
return keyStore;

src/Accounts/Accounts.Test/ProfileCmdletTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private AzKeyStore SetMockedAzKeyStore()
5555
storageMocker.Setup(f => f.Create()).Returns(storageMocker.Object);
5656
storageMocker.Setup(f => f.ReadData()).Returns(new byte[0]);
5757
storageMocker.Setup(f => f.WriteData(It.IsAny<byte[]>())).Callback((byte[] s) => { });
58-
var keyStore = new AzKeyStore(AzureSession.Instance.ARMProfileDirectory, "keystore.cache", false, false, storageMocker.Object);
58+
var keyStore = new AzKeyStore(AzureSession.Instance.ARMProfileDirectory, "azkeystore.cache", false, false, storageMocker.Object);
5959
return keyStore;
6060
}
6161

src/Accounts/Accounts/Account/ConnectAzureRmAccount.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,7 @@ public void OnImport()
711711
}
712712

713713
AzKeyStore keyStore = null;
714-
//AzureSession.Instance.KeyStoreFile
715-
keyStore = new AzKeyStore(AzureSession.Instance.ARMProfileDirectory, "keystore.cache", false, autoSaveEnabled);
714+
keyStore = new AzKeyStore(AzureSession.Instance.ARMProfileDirectory, AzureSession.Instance.KeyStoreFile, false, autoSaveEnabled);
716715
AzKeyStore.RegisterJsonConverter(typeof(ServicePrincipalKey), typeof(ServicePrincipalKey).Name);
717716
AzKeyStore.RegisterJsonConverter(typeof(SecureString), typeof(SecureString).Name, new SecureStringConverter());
718717
AzureSession.Instance.RegisterComponent(AzKeyStore.Name, () => keyStore);

src/Accounts/Authentication.Test/AzKeyStorageTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class AzKeyStorageTest
3030
private Mock<IStorage> storageMocker = null;
3131
private List<byte> storageChecker = null;
3232
private string dummpyPath = "/home/dummy/.Azure";
33-
private string keyStoreFileName = "keystore.cache";
33+
private string keyStoreFileName = "azkeystore.cache";
3434

3535
public AzKeyStorageTest()
3636
{

src/Accounts/Authentication/AzureSessionInitializer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static ContextAutosaveSettings InitializeSessionSettings(IDataStore store, strin
161161
Mode = ContextSaveMode.Process,
162162
CacheFile = "msal.cache",
163163
ContextFile = "AzureRmContext.json",
164-
KeyStoreFile = "keystore.cache"
164+
KeyStoreFile = "azkeystore.cache"
165165
};
166166

167167
var settingsPath = Path.Combine(profileDirectory, settingsFile);
@@ -270,6 +270,7 @@ static IAzureSession CreateInstance(IDataStore dataStore = null, Action<string>
270270
session.ARMProfileFile = autoSave.ContextFile;
271271
session.TokenCacheDirectory = autoSave.CacheDirectory;
272272
session.TokenCacheFile = autoSave.CacheFile;
273+
session.KeyStoreFile = autoSave.KeyStoreFile;
273274
autoSave.Settings.TryGetValue("InstallationId", out string installationId);
274275
session.ExtendedProperties.Add("InstallationId", installationId);
275276
InitializeConfigs(session, profilePath, writeWarning);

src/Accounts/Authentication/KeyStore/StorageWrapper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Microsoft.Azure.Commands.Common.Authentication.Properties;
1515
using Microsoft.Identity.Client.Extensions.Msal;
1616
using System;
17+
using System.Collections.Generic;
1718
using System.Threading;
1819

1920
namespace Microsoft.Azure.Commands.ResourceManager.Common
@@ -47,7 +48,9 @@ public IStorage Create()
4748
{
4849
storageProperties = new StorageCreationPropertiesBuilder(FileName, Directory)
4950
.WithMacKeyChain(KeyChainServiceName + ".other_secrets", FileName)
50-
.WithLinuxUnprotectedFile();
51+
.WithLinuxKeyring(FileName, "default", "AzKeyStoreCache",
52+
new KeyValuePair<string, string>("AzureClientID", "Microsoft.Developer.Azure.PowerShell"),
53+
new KeyValuePair<string, string>("Microsoft.Developer.Azure.PowerShell", "1.0.0.0"));
5154
_storage = Storage.Create(storageProperties.Build());
5255
VerifyPersistence();
5356
}

0 commit comments

Comments
 (0)