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

Nanxiang/az.connected kubernetes #20904

Merged
merged 5 commits into from
Feb 14, 2023
Merged
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
8 changes: 4 additions & 4 deletions src/ConnectedKubernetes/Az.ConnectedKubernetes.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft Corporation
#
# Generated on: 01/12/2022
# Generated on: 17/01/2023
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = './Az.ConnectedKubernetes.psm1'

# Version number of this module.
ModuleVersion = '0.7.0'
ModuleVersion = '0.7.1'

# Supported PSEditions
CompatiblePSEditions = 'Core', 'Desktop'
Expand Down Expand Up @@ -51,7 +51,7 @@ DotNetFrameworkVersion = '4.7.2'
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '2.10.4'; })
RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '2.11.1'; })

# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = './bin/Az.ConnectedKubernetes.private.dll'
Expand Down Expand Up @@ -110,7 +110,7 @@ PrivateData = @{
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = '* Added the logic that prompt legal information when users call the parameter ''-AzureHybridBenefit'' in ''New-AzConnectedKubernetes'' or ''Update-AzConnectedKubernetes''.'
ReleaseNotes = '* Made ''New-AzConnectedKubernetes'' support PowerShell 5.'

# Prerelease string of this module
# Prerelease = ''
Expand Down
3 changes: 3 additions & 0 deletions src/ConnectedKubernetes/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
-->
## Upcoming Release

## Version 0.7.1
* Made `New-AzConnectedKubernetes` support PowerShell 5.

## Version 0.7.0
* Added the logic that prompt legal information when users call the parameter "-AzureHybridBenefit" in `New-AzConnectedKubernetes` or `Update-AzConnectedKubernetes`.

Expand Down
4 changes: 2 additions & 2 deletions src/ConnectedKubernetes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
[assembly: ComVisible(false)]
[assembly: CLSCompliant(false)]
[assembly: Guid("CE93AF3C-92E0-4357-93A0-22A5766CDF13")]
[assembly: AssemblyVersion("0.7.0")]
[assembly: AssemblyFileVersion("0.7.0")]
[assembly: AssemblyVersion("0.7.1")]
[assembly: AssemblyFileVersion("0.7.1")]
15 changes: 13 additions & 2 deletions src/ConnectedKubernetes/custom/New-AzConnectedKubernetes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,19 @@ function New-AzConnectedKubernetes {
#Endregion

$RSA = [System.Security.Cryptography.RSA]::Create(4096)
$AgentPublicKey = [System.Convert]::ToBase64String($RSA.ExportRSAPublicKey())
$AgentPrivateKey = "-----BEGIN RSA PRIVATE KEY-----`n" + [System.Convert]::ToBase64String($RSA.ExportRSAPrivateKey()) + "`n-----END RSA PRIVATE KEY-----"
if ($PSVersionTable.PSVersion.Major -eq 5) {
try {
. "$PSScriptRoot/../utils/RSAHelper.ps1"
$AgentPublicKey = ExportRSAPublicKeyBase64($RSA)
$AgentPrivateKey = ExportRSAPrivateKeyBase64($RSA)
} catch {
Write-Error "Unable to generate RSA keys"
throw
}
} else {
$AgentPublicKey = [System.Convert]::ToBase64String($RSA.ExportRSAPublicKey())
$AgentPrivateKey = "-----BEGIN RSA PRIVATE KEY-----`n" + [System.Convert]::ToBase64String($RSA.ExportRSAPrivateKey()) + "`n-----END RSA PRIVATE KEY-----"
}

$HelmChartPath = Join-Path -Path $ChartExportPath -ChildPath 'azure-arc-k8sagents'
if (Test-Path Env:HELMCHART) {
Expand Down
154 changes: 154 additions & 0 deletions src/ConnectedKubernetes/utils/RSAHelper.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
function ExportRSAPrivateKeyBase64{
param(
[Parameter(Mandatory)]
[System.Security.Cryptography.RSA]
$RSA
)
process{
$RSAParams = $RSA.ExportParameters(1)
[byte]$Sequence = 0x30
[byte[]]$Version = (0x00)
$stream = [System.IO.MemoryStream]::new()
$writer = [System.IO.BinaryWriter]::new($stream)
$writer.Write($Sequence); # SEQUENCE
$innerStream = [System.IO.MemoryStream]::new()
$innerWriter = [System.IO.BinaryWriter]::new($innerStream)

EncodeIntegerBigEndian $innerWriter $Version
EncodeIntegerBigEndian $innerWriter $RSAParams.Modulus
EncodeIntegerBigEndian $innerWriter $RSAParams.Exponent
EncodeIntegerBigEndian $innerWriter $RSAParams.D
EncodeIntegerBigEndian $innerWriter $RSAParams.P
EncodeIntegerBigEndian $innerWriter $RSAParams.Q
EncodeIntegerBigEndian $innerWriter $RSAParams.DP
EncodeIntegerBigEndian $innerWriter $RSAParams.DQ
EncodeIntegerBigEndian $innerWriter $RSAParams.InverseQ

$length = ([int]($innerStream.Length))
EncodeLength $writer $length
$writer.Write($innerStream.GetBuffer(), 0, $length)

$base64 = [Convert]::ToBase64String($stream.GetBuffer(), 0, ([int]($stream.Length)))

$offset = 0
$line_length = 64

$sb = [System.Text.StringBuilder]::new()
[void]$sb.AppendLine("-----BEGIN RSA PRIVATE KEY-----")
while ($offset -lt $base64.Length) {
$line_end = [Math]::Min($offset + $line_length, $base64.Length)
[void]$sb.AppendLine($base64.Substring($offset, $line_end - $offset))
$offset = $line_end
}

[void]$sb.AppendLine("-----END RSA PRIVATE KEY-----")

return $sb.ToString()
}
}

function ExportRSAPublicKeyBase64{
param(
[Parameter(Mandatory)]
[System.Security.Cryptography.RSA]
$RSA
)
process{
$RSAParams = $RSA.ExportParameters(0)
[byte]$Sequence = 0x30
$stream = [System.IO.MemoryStream]::new()
$writer = [System.IO.BinaryWriter]::new($stream)
$writer.Write($Sequence); # SEQUENCE
$innerStream = [System.IO.MemoryStream]::new()
$innerWriter = [System.IO.BinaryWriter]::new($innerStream)
EncodeIntegerBigEndian $innerWriter $RSAParams.Modulus
EncodeIntegerBigEndian $innerWriter $RSAParams.Exponent

$length = ([int]($innerStream.Length))
EncodeLength $writer $length
$writer.Write($innerStream.GetBuffer(), 0, $length)

$base64 = [Convert]::ToBase64String($stream.GetBuffer(), 0, ([int]($stream.Length)))

$offset = 0
$line_length = 64

$sb = [System.Text.StringBuilder]::new()

while ($offset -lt $base64.Length) {
$line_end = [Math]::Min($offset + $line_length, $base64.Length)
[void]$sb.AppendLine($base64.Substring($offset, $line_end - $offset))
$offset = $line_end
}

return $sb.ToString()
}
}

function EncodeLength{
param(
[System.IO.BinaryWriter]$stream,
[int]$length
)
process{
[byte]$bytex80 = 0x80
if($length -lt 0){
throw "Length must be non-negative"
}
if($length -lt $bytex80){
$stream.Write(([byte]$length))
}
else{
$temp = $length
$bytesRequired = 0;
while ($temp -gt 0) {
$temp = $temp -shr 8
$bytesRequired++
}

[byte]$byteToWrite = $bytesRequired -bor $bytex80
$stream.Write($byteToWrite)
$iValue = ($bytesRequired - 1)
[byte]$0ffByte = 0xff
for ($i = $iValue; $i -ge 0; $i--) {
[byte]$byteToWrite = ($length -shr (8 * $i) -band $0ffByte)
$stream.Write($byteToWrite )
}
}
}
}

function EncodeIntegerBigEndian{
param(
[System.IO.BinaryWriter]$stream,
[byte[]]$value,
[bool]$forceUnsigned = $true
)
process{
[byte]$Integer = 0x02

$stream.Write($Integer); # INTEGER
$prefixZeros = 0
for ($i = 0; $i -lt $value.Length; $i++) {
if ($value[$i] -ne 0){break}
$prefixZeros++
}
if(($value.Length - $prefixZeros) -eq 0){
EncodeLength $stream 1
$stream.Write(([byte]0))
}
else{
[byte]$newByte = 0x7f
if(($forceUnsigned) -AND ($value[$prefixZeros] -gt $newByte)){
EncodeLength $stream ($value.Length - $prefixZeros +1)
$stream.Write(([byte]0))
}
else{
EncodeLength $stream ($value.Length - $prefixZeros)
}
for ($i = $prefixZeros; $i -lt $value.Length; $i++) {
$stream.Write($value[$i])
}
}
}
}
2 changes: 1 addition & 1 deletion tools/AzPreview/AzPreview.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '2.11.2'; },
@{ModuleName = 'Az.Compute'; RequiredVersion = '5.4.0'; },
@{ModuleName = 'Az.ConfidentialLedger'; RequiredVersion = '1.0.0'; },
@{ModuleName = 'Az.Confluent'; RequiredVersion = '0.2.0'; },
@{ModuleName = 'Az.ConnectedKubernetes'; RequiredVersion = '0.7.0'; },
@{ModuleName = 'Az.ConnectedKubernetes'; RequiredVersion = '0.7.1'; },
@{ModuleName = 'Az.ConnectedMachine'; RequiredVersion = '0.4.1'; },
@{ModuleName = 'Az.ConnectedNetwork'; RequiredVersion = '0.1.0'; },
@{ModuleName = 'Az.ContainerInstance'; RequiredVersion = '3.1.0'; },
Expand Down
2 changes: 1 addition & 1 deletion tools/Docs/az-ps-latest.csv
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pac23,[ps=true;customSource=https://azpspackage.blob.core.windows.net/docs-relea
pac24,[ps=true;customSource=https://azpspackage.blob.core.windows.net/docs-release/Az.Compute.5.4.0.nupkg;sourceType=sa]Az.Compute,5.4.0
pac25,[ps=true;customSource=https://azpspackage.blob.core.windows.net/docs-release/Az.ConfidentialLedger.1.0.0.nupkg;sourceType=sa]Az.ConfidentialLedger,1.0.0
pac26,[ps=true;customSource=https://azpspackage.blob.core.windows.net/docs-release/Az.Confluent.0.2.0.nupkg;sourceType=sa]Az.Confluent,0.2.0
pac27,[ps=true;customSource=https://azpspackage.blob.core.windows.net/docs-release/Az.ConnectedKubernetes.0.7.0.nupkg;sourceType=sa]Az.ConnectedKubernetes,0.7.0
pac27,[ps=true;customSource=https://azpspackage.blob.core.windows.net/docs-release/Az.ConnectedKubernetes.0.7.1.nupkg;sourceType=sa]Az.ConnectedKubernetes,0.7.1
pac28,[ps=true;customSource=https://azpspackage.blob.core.windows.net/docs-release/Az.ConnectedMachine.0.4.1.nupkg;sourceType=sa]Az.ConnectedMachine,0.4.1
pac29,[ps=true;customSource=https://azpspackage.blob.core.windows.net/docs-release/Az.ConnectedNetwork.0.1.0.nupkg;sourceType=sa]Az.ConnectedNetwork,0.1.0
pac30,[ps=true;customSource=https://azpspackage.blob.core.windows.net/docs-release/Az.ContainerInstance.3.1.0.nupkg;sourceType=sa]Az.ContainerInstance,3.1.0
Expand Down