-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add devops-pat and az website stores to secret rotation (#5591)
* Add devops-pat and az website stores * Update rotation logic to support post-primary stores and annotation * Add enableWindowsTargeting to secret rotation cli proj * Fix paths in unit tests * Update tools/secret-rotation/Azure.Sdk.Tools.SecretRotation.Stores.AzureDevOps/ServiceAccountPersonalAccessTokenStore.cs Co-authored-by: Ben Broderick Phillips <[email protected]> --------- Co-authored-by: Ben Broderick Phillips <[email protected]>
- Loading branch information
Showing
18 changed files
with
600 additions
and
68 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...rotation/Azure.Sdk.Tools.SecretRotation.Azure/Azure.Sdk.Tools.SecretRotation.Azure.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Azure.Core" Version="1.25.0" /> | ||
<PackageReference Include="Azure.Identity" Version="1.8.0" /> | ||
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.4.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
tools/secret-rotation/Azure.Sdk.Tools.SecretRotation.Azure/ISecretProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Azure.Core; | ||
|
||
namespace Azure.Sdk.Tools.SecretRotation.Azure; | ||
|
||
public interface ISecretProvider | ||
{ | ||
Task<string> GetSecretValueAsync(TokenCredential credential, Uri secretUri); | ||
} |
46 changes: 46 additions & 0 deletions
46
tools/secret-rotation/Azure.Sdk.Tools.SecretRotation.Azure/SecretProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Text.RegularExpressions; | ||
using Azure.Core; | ||
using Azure.Security.KeyVault.Secrets; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Azure.Sdk.Tools.SecretRotation.Azure; | ||
|
||
public class SecretProvider : ISecretProvider | ||
{ | ||
private static readonly Regex secretRegex = new (@"(?<vault>https://.*?\.vault\.azure\.net)/secrets/(?<secret>.*)", RegexOptions.Compiled, TimeSpan.FromSeconds(5)); | ||
private readonly ILogger logger; | ||
|
||
public SecretProvider(ILogger logger) | ||
{ | ||
this.logger = logger; | ||
} | ||
|
||
public async Task<string> GetSecretValueAsync(TokenCredential credential, Uri secretUri) | ||
{ | ||
Match match = secretRegex.Match(secretUri.AbsoluteUri); | ||
|
||
if (!match.Success) | ||
{ | ||
throw new ArgumentException("Unable to parse uri as a Key Vault secret uri"); | ||
} | ||
|
||
string vaultUrl = match.Groups["vault"].Value; | ||
string secretName = match.Groups["secret"].Value; | ||
|
||
try | ||
{ | ||
var secretClient = new SecretClient(new Uri(vaultUrl), credential); | ||
|
||
this.logger.LogDebug("Retrieving value for secret '{SecretUrl}'", secretUri); | ||
|
||
KeyVaultSecret secret = await secretClient.GetSecretAsync(secretName); | ||
|
||
return secret.Value; | ||
} | ||
catch (Exception exception) | ||
{ | ||
this.logger.LogError(exception, "Unable to read secret {SecretName} from vault {VaultUrl}", secretName, vaultUrl); | ||
throw; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ation.Stores.AzureAppService/Azure.Sdk.Tools.SecretRotation.Stores.AzureAppService.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Azure.ResourceManager.AppService" Version="1.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Azure.Sdk.Tools.SecretRotation.Configuration\Azure.Sdk.Tools.SecretRotation.Configuration.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.