Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle azure keyvault throttling with retry logic #237

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/AzureSignTool/AzureSignTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="RSAKeyVaultProvider" Version="2.1.1" />
<PackageReference Include="Polly" Version="8.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/AzureSignTool/HRESULT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ internal static class HRESULT
public const int E_ALL_FAILED = unchecked((int)0xA0000002);

public const int TRUST_E_SUBJECT_FORM_UNKNOWN = unchecked((int)0x800B0003);

public const int E_VAULT_THROTTLING = unchecked((int)0x801901AD);
}
}
19 changes: 17 additions & 2 deletions src/AzureSignTool/SignCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using McMaster.Extensions.CommandLineUtils.Abstractions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using Polly.Retry;
using Polly;
using RSAKeyVaultProvider;

using System;
Expand Down Expand Up @@ -104,6 +106,18 @@ internal sealed class SignCommand
[Argument(0, "file", "The path to the file.")]
public string[] Files { get; set; } = [];

// retry strategy for Keyvault throttling errors
// https://learn.microsoft.com/en-us/azure/key-vault/general/overview-throttling
private readonly ResiliencePipeline _resiliencePipeline = new ResiliencePipelineBuilder()
.AddRetry(new RetryStrategyOptions
{
ShouldHandle = new PredicateBuilder().HandleResult(result => (int)result == E_VAULT_THROTTLING),
BackoffType = DelayBackoffType.Exponential,
MaxRetryAttempts = 4,
Delay = TimeSpan.FromSeconds(2)
})
.Build();

private HashSet<string> _allFiles;
public HashSet<string> AllFiles
{
Expand Down Expand Up @@ -321,9 +335,10 @@ public async Task<int> OnExecuteAsync(IConsole console)
{
logger.LogInformation("Skipping already signed file.");
return (state.succeeded + 1, state.failed);
}
}

var result = _resiliencePipeline.Execute(() => signer.SignFile(filePath, Description, DescriptionUri, performPageHashing, logger, appendSignature));

var result = signer.SignFile(filePath, Description, DescriptionUri, performPageHashing, logger, appendSignature);
switch (result)
{
case COR_E_BADIMAGEFORMAT:
Expand Down