Skip to content

feat(custom-cloud): unify cert bootstrap flow and add Windows CA refresh task#8096

Draft
rchincha wants to merge 2 commits intomainfrom
origin/rchinchani/rcv1p-2
Draft

feat(custom-cloud): unify cert bootstrap flow and add Windows CA refresh task#8096
rchincha wants to merge 2 commits intomainfrom
origin/rchinchani/rcv1p-2

Conversation

@rchincha
Copy link

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Ramkumar Chinchani added 2 commits March 15, 2026 22:08
…esh task

RCV 1P BETA – Feature Overview and Adoption Instructions | website
RCV 1P Troubleshooting Guide | website

cse_cmd.sh.gtpl: derive cert endpoint mode from target cloud and always run custom-cloud init script.
cse_cmd.sh: same mode logic as template; remove LOCATION export.
init-aks-custom-cloud.sh: merged legacy + operation-requests logic into one script with distro-aware cert install paths.
parts/linux/cloud-init/artifacts/init-aks-custom-cloud-mariner.sh: removed (merged into unified script).
parts/linux/cloud-init/artifacts/init-aks-custom-cloud-operation-requests.sh: removed (merged into unified script).
parts/linux/cloud-init/artifacts/init-aks-custom-cloud-operation-requests-mariner.sh: removed (merged into unified script).
const.go: keep only unified custom-cloud init script constant.
variables.go: simplify script selection to always use unified init script.
baker.go: use location-derived target environment in func map.
kubernetesfunc.ps1: add location-aware CA retrieval (legacy/rcv1p) and scheduled refresh task registration helper.
kuberneteswindowssetup.ps1: pass location to CA retrieval and register refresh task for custom cloud.
Copilot AI review requested due to automatic review settings March 16, 2026 05:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to unify the custom-cloud CA certificate bootstrap path (removing the separate “operation-requests” init scripts) and adds a Windows scheduled task to periodically refresh custom-cloud CA certificates.

Changes:

  • Windows: add a scheduled task to refresh custom-cloud CA certificates; update Get-CACertificates to support legacy vs “rcv1p” modes keyed off location.
  • Linux: consolidate custom-cloud init to a single init script and update CSE command generation to set a cert-endpoint mode variable.
  • Regenerate multiple custom data / generated command snapshots to reflect the new templates.

Reviewed changes

Copilot reviewed 74 out of 176 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
staging/cse/windows/kubernetesfunc.ps1 Adds CA refresh scheduled task + updates CA retrieval logic and error behavior
parts/windows/kuberneteswindowssetup.ps1 Wires Get-CACertificates -Location and registers refresh task for custom clouds
pkg/agent/variables.go Always injects initAKSCustomCloud payload into cloud-init data
pkg/agent/const.go Removes separate custom-cloud init script constants; keeps single init script
pkg/agent/baker.go Simplifies GetTargetEnvironment; notes IsAKSCustomCloud as deprecated
parts/linux/cloud-init/artifacts/cse_cmd.sh Updates CSE command to set cert endpoint mode + run custom-cloud init script
parts/linux/cloud-init/artifacts/init-aks-custom-cloud-operation-requests.sh Deleted (custom-cloud init consolidation)
parts/linux/cloud-init/artifacts/init-aks-custom-cloud-operation-requests-mariner.sh Deleted (custom-cloud init consolidation)
parts/linux/cloud-init/artifacts/init-aks-custom-cloud-mariner.sh Deleted (custom-cloud init consolidation)
aks-node-controller/parser/templates/cse_cmd.sh.gtpl Mirrors CSE command template updates for aks-node-controller parser
aks-node-controller/parser/testdata/Compatibility+EmptyConfig/generatedCSECommand Regenerated snapshot for new CSE cmd template
aks-node-controller/parser/testdata/AzureLinuxv2+Kata+DisableUnattendedUpgrades=false/generatedCSECommand Regenerated snapshot for new CSE cmd template
aks-node-controller/parser/testdata/AKSUbuntu2204+SSHStatusOn/generatedCSECommand Regenerated snapshot for new CSE cmd template
aks-node-controller/parser/testdata/AKSUbuntu2204+EnablePubkeyAuth/generatedCSECommand New snapshot for new template output
aks-node-controller/parser/testdata/AKSUbuntu2204+DisablePubkeyAuth/generatedCSECommand New snapshot for new template output
aks-node-controller/parser/testdata/AKSUbuntu2204+DefaultPubkeyAuth/generatedCSECommand New snapshot for new template output
aks-node-controller/parser/testdata/AKSUbuntu2204+CustomOSConfig/generatedCSECommand Regenerated snapshot for new CSE cmd template
aks-node-controller/parser/testdata/AKSUbuntu2204+CustomCloud/generatedCSECommand Regenerated snapshot for new CSE cmd template
aks-node-controller/parser/testdata/AKSUbuntu2204+Containerd+MIG/generatedCSECommand Regenerated snapshot for new CSE cmd template
aks-node-controller/parser/testdata/AKSUbuntu2204+CloudProviderOverrides/generatedCSECommand New snapshot for new template output
aks-node-controller/parser/testdata/AKSUbuntu2204+China/generatedCSECommand Regenerated snapshot for new CSE cmd template
pkg/agent/testdata/MarinerV2+Kata/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/AzureLinuxV2+Kata/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/AzureLinuxV3+Kata/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/AKSUbuntu2204+China/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/AKSUbuntu2204+cgroupv2/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/AKSUbuntu2204+ootcredentialprovider/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/AKSUbuntu2204+SecurityProfile/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/AKSUbuntu2204+SSHStatusOn/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/AKSUbuntu2204+SSHStatusOff/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/AKSUbuntu2404+NetworkPolicy/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/AKSUbuntu2404+Teleport/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/CustomizedImage/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/CustomizedImageKata/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/CustomizedImageLinuxGuard/CustomData Regenerated snapshot (custom data gzip payload changed)
pkg/agent/testdata/Flatcar/CustomData.inner Regenerated snapshot (embedded gzip payload changed)
pkg/agent/testdata/ACL/CustomData.inner Regenerated snapshot (embedded gzip payload changed)

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +266 to +337
try {
if ($certEndpointMode -eq "legacy") {
$uri = 'http://168.63.129.16/machine?comp=acmspackage&type=cacertificates&ext=json'
$rawData = Retry-Command -Command 'Invoke-WebRequest' -Args @{Uri=$uri; UseBasicParsing=$true} -Retries 5 -RetryDelaySeconds 10
} catch {
Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CA_CERTIFICATES -ErrorMessage "Failed to download CA certificates rawdata. Error: $_"
$caCerts = ($rawData.Content) | ConvertFrom-Json
if ($null -eq $caCerts -or $null -eq $caCerts.Certificates -or $caCerts.Certificates.Length -eq 0) {
Write-Log "Warning: CA certificates rawdata is empty for legacy endpoint"
return $false
}

foreach ($certificate in $caCerts.Certificates) {
$name = $certificate.Name
$certFilePath = Join-Path $caFolder $name
Write-Log "Write certificate $name to $certFilePath"
$certificate.CertBody > $certFilePath
}

return $true
}

Write-Log "Convert CA certificates rawdata"
$caCerts=($rawData.Content) | ConvertFrom-Json
if ([string]::IsNullOrEmpty($caCerts)) {
Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_EMPTY_CA_CERTIFICATES -ErrorMessage "CA certificates rawdata is empty"
$optInUri = 'http://168.63.129.16/acms/isOptedInForRootCerts'
$optInResponse = Retry-Command -Command 'Invoke-WebRequest' -Args @{Uri=$optInUri; UseBasicParsing=$true} -Retries 5 -RetryDelaySeconds 10
if (($optInResponse.Content -notmatch 'IsOptedInForRootCerts=true')) {
Write-Log "Skipping custom cloud root cert installation because IsOptedInForRootCerts is not true"
return $false
}

$certificates = $caCerts.Certificates
for ($index = 0; $index -lt $certificates.Length ; $index++) {
$name=$certificates[$index].Name
$certFilePath = Join-Path $caFolder $name
Write-Log "Write certificate $name to $certFilePath"
$certificates[$index].CertBody > $certFilePath
$operationRequestTypes = @("operationrequestsroot", "operationrequestsintermediate")
$downloadedAny = $false

foreach ($requestType in $operationRequestTypes) {
$operationRequestUri = "http://168.63.129.16/machine?comp=acmspackage&type=$requestType&ext=json"
$operationResponse = Retry-Command -Command 'Invoke-WebRequest' -Args @{Uri=$operationRequestUri; UseBasicParsing=$true} -Retries 5 -RetryDelaySeconds 10
$operationJson = ($operationResponse.Content) | ConvertFrom-Json

if ($null -eq $operationJson -or $null -eq $operationJson.OperationRequests) {
Write-Log "Warning: no operation requests found for $requestType"
continue
}

foreach ($operation in $operationJson.OperationRequests) {
$resourceFileName = $operation.ResouceFileName
if ([string]::IsNullOrEmpty($resourceFileName)) {
continue
}

$resourceType = [IO.Path]::GetFileNameWithoutExtension($resourceFileName)
$resourceExt = [IO.Path]::GetExtension($resourceFileName).TrimStart('.')
$resourceUri = "http://168.63.129.16/machine?comp=acmspackage&type=$resourceType&ext=$resourceExt"

$certContentResponse = Retry-Command -Command 'Invoke-WebRequest' -Args @{Uri=$resourceUri; UseBasicParsing=$true} -Retries 5 -RetryDelaySeconds 10
if ([string]::IsNullOrEmpty($certContentResponse.Content)) {
Write-Log "Warning: empty certificate content for $resourceFileName"
continue
}

$certFilePath = Join-Path $caFolder $resourceFileName
Write-Log "Write certificate $resourceFileName to $certFilePath"
$certContentResponse.Content > $certFilePath
$downloadedAny = $true
}
}

if (-not $downloadedAny) {
Write-Log "Warning: no CA certificates were downloaded in rcv1p mode"
}

return $downloadedAny
}
catch {
# Catch all exceptions in this function. NOTE: exit cannot be caught.
Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_GET_CA_CERTIFICATES -ErrorMessage $_
Write-Log "Warning: failed to retrieve CA certificates. Error: $_"
return $false
[io.file]::WriteAllBytes($azureStackConfigFile, [System.Convert]::FromBase64String($envJSON))

Get-CACertificates
Get-CACertificates -Location $Location
Comment on lines +19 to 25
CLOUD_ENV="{{GetTargetEnvironment}}"
CUSTOM_CLOUD_CERT_ENDPOINT_MODE="rcv1p"
case "${CLOUD_ENV,,}" in
ussec*|usnat*) CUSTOM_CLOUD_CERT_ENDPOINT_MODE="legacy" ;;
esac
REPO_DEPOT_ENDPOINT="{{AKSCustomCloudRepoDepotEndpoint}}"
{{GetInitAKSCustomCloudFilepath}} >> /var/log/azure/cluster-provision.log 2>&1;
Comment on lines +19 to 25
CLOUD_ENV="{{GetTargetEnvironment}}"
CUSTOM_CLOUD_CERT_ENDPOINT_MODE="rcv1p"
case "${CLOUD_ENV,,}" in
ussec*|usnat*) CUSTOM_CLOUD_CERT_ENDPOINT_MODE="legacy" ;;
esac
REPO_DEPOT_ENDPOINT="{{AKSCustomCloudRepoDepotEndpoint}}"
{{getInitAKSCustomCloudFilepath}} >> /var/log/azure/cluster-provision.log 2>&1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants