Skip to content

Commit

Permalink
Alter key generation logic V3 (#3041)
Browse files Browse the repository at this point in the history
* Alter key generation logic v3

* Added the appropriate namespace
  • Loading branch information
michaelpeng36 authored May 31, 2022
1 parent d4c20ad commit 4d039db
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions src/Azure.Functions.Cli/Kubernetes/FuncKeys/FuncAppKeysHelper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using Azure.Functions.Cli.Kubernetes.Models.Kubernetes;
using Colors.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Script.WebHost.Security;

namespace Azure.Functions.Cli.Kubernetes.FuncKeys
{
Expand All @@ -30,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 @@ -93,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 4d039db

Please sign in to comment.