Skip to content

Commit

Permalink
Alter key generation logic V4 (#3040)
Browse files Browse the repository at this point in the history
* Alter key generation logic

* Revert changes to csproj

* Corrected WebHost version
  • Loading branch information
michaelpeng36 authored May 9, 2022
1 parent 46aa92a commit 3d48879
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Azure.Functions.Cli/Azure.Functions.Cli.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk" InitialTargets="ExcludeWorkersFromReadyToRun">
<Project Sdk="Microsoft.NET.Sdk" InitialTargets="ExcludeWorkersFromReadyToRun">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
Expand Down
26 changes: 6 additions & 20 deletions src/Azure.Functions.Cli/Kubernetes/FuncKeys/FuncAppKeysHelper.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using Azure.Functions.Cli.Kubernetes.Models.Kubernetes;
using Microsoft.Azure.WebJobs.Script.WebHost.Security;

namespace Azure.Functions.Cli.Kubernetes.FuncKeys
{
Expand All @@ -26,16 +25,16 @@ public static IDictionary<string, string> CreateKeys(IEnumerable<string> functio
{
var funcAppKeys = new Dictionary<string, string>
{
{ MasterKey, GenerateKey() },
{ HostFunctionKey, GenerateKey() },
{ HostSystemKey, GenerateKey() }
{ MasterKey, SecretGenerator.GenerateMasterKeyValue() },
{ HostFunctionKey, SecretGenerator.GenerateFunctionKeyValue() },
{ HostSystemKey, SecretGenerator.GenerateSystemKeyValue() }
};

if (functionNames?.Any() == true)
{
foreach (var funcName in functionNames)
{
funcAppKeys[$"{FunctionKeyPrefix}{funcName.ToLower()}.{FunctionDefaultKeyName}"] = GenerateKey();
funcAppKeys[$"{FunctionKeyPrefix}{funcName.ToLower()}.{FunctionDefaultKeyName}"] = SecretGenerator.GenerateFunctionKeyValue();
}
}

Expand Down Expand Up @@ -89,18 +88,5 @@ public static void CreateFuncAppKeysVolumeMountDeploymentResource(IEnumerable<De
};
}
}

private static string GenerateKey()
{
using (var rng = RandomNumberGenerator.Create())
{
byte[] data = new byte[40];
rng.GetBytes(data);
string secret = Convert.ToBase64String(data);

// Replace pluses as they are problematic as URL values
return secret.Replace('+', 'a');
}
}
}
}

0 comments on commit 3d48879

Please sign in to comment.