-
Notifications
You must be signed in to change notification settings - Fork 275
feat: add CustomData/protectedSettings size guards for hotfix PRs #9182
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
Open
Abigail Liang (abigailliang-aks-sig-node)
wants to merge
6
commits into
main
Choose a base branch
from
abigailliang/customdata-size-guard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fec9e6a
feat: add CustomData size guard for hotfix PRs
abigailliang-aks-sig-node de56fd3
add multiple distro
abigailliang-aks-sig-node 0122bfb
add flatcar and osguard
abigailliang-aks-sig-node 3874d41
add customecloud
abigailliang-aks-sig-node c3c6c87
add a commit sha of setup go v7
abigailliang-aks-sig-node 2b00748
add enabled_featured.sh
abigailliang-aks-sig-node File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package agent | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/Azure/agentbaker/pkg/agent/datamodel" | ||
| ) | ||
|
abigailliang-aks-sig-node marked this conversation as resolved.
|
||
|
|
||
| // CustomData size guard for the scriptless NBC CSE path. | ||
| // | ||
| // Background: | ||
| // | ||
| // In Mode B (slim CustomData), the generated payload carries P (platform content) + H (hotfix- | ||
| // injected scripts). R (customer certs) is moved to protectedSettings and is bounded by RP-side | ||
| // per-field cert byte-size validation, so only H can overflow CustomData. | ||
| // | ||
| // This guard asserts that the slim Mode B CustomData stays under MaxCustomDataLength (87,380). | ||
| // In the hotfix CI it runs AFTER hotfix_generate.py injects the real H into nodecustomdata.yml, | ||
| // so the //go:embed'd template already carries H — no synthetic injection needed. | ||
|
|
||
| // newScriptlessGuardConfig builds a minimal scriptless NBC config for the given distro. | ||
| func newScriptlessGuardConfig(distro datamodel.Distro) *datamodel.NodeBootstrappingConfiguration { | ||
| agentPoolProfile := &datamodel.AgentPoolProfile{ | ||
| Name: "nodepool1", | ||
| OSType: datamodel.Linux, | ||
| Distro: distro, | ||
| } | ||
| return &datamodel.NodeBootstrappingConfiguration{ | ||
| ContainerService: &datamodel.ContainerService{ | ||
| Location: "eastus", | ||
| Properties: &datamodel.Properties{ | ||
|
abigailliang-aks-sig-node marked this conversation as resolved.
|
||
| OrchestratorProfile: &datamodel.OrchestratorProfile{ | ||
| OrchestratorVersion: "1.29.0", | ||
| OrchestratorType: datamodel.Kubernetes, | ||
| KubernetesConfig: &datamodel.KubernetesConfig{ | ||
| ContainerRuntimeConfig: map[string]string{}, | ||
| }, | ||
| }, | ||
| HostedMasterProfile: &datamodel.HostedMasterProfile{ | ||
| FQDN: "test-cluster.hcp.eastus.azmk8s.io", | ||
| }, | ||
| AgentPoolProfiles: []*datamodel.AgentPoolProfile{agentPoolProfile}, | ||
| }, | ||
| }, | ||
| AgentPoolProfile: agentPoolProfile, | ||
| CloudSpecConfig: datamodel.AzurePublicCloudSpecForTest, | ||
| K8sComponents: &datamodel.K8sComponents{}, | ||
| KubeletConfig: map[string]string{}, | ||
| EnableScriptlessNBCCSECmd: true, | ||
|
abigailliang-aks-sig-node marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| // TestCustomDataSizeWithHotfix (Guard 1): the slim Mode B CustomData (base platform content P | ||
| // plus any hotfix-injected scripts H already embedded in nodecustomdata.yml) must stay under | ||
| // MaxCustomDataLength. Forcing ScriptlessCSEProvisionMode makes getScriptlessBoothook return the | ||
| // slim CustomData directly, so this measures exactly the Mode B CustomData branch. | ||
| // | ||
| // The template has distro-conditional blocks (Ubuntu vs Mariner/AzureLinux vs Flatcar vs OSGuard) | ||
| // and a cloud-conditional block (IsAKSCustomCloud inlines init-aks-cloud.sh), so we table-drive | ||
| // representative distros × cloud combinations to ensure no rendering branch exceeds the limit. | ||
| func TestCustomDataSizeWithHotfix(t *testing.T) { | ||
|
abigailliang-aks-sig-node marked this conversation as resolved.
|
||
| cases := []struct { | ||
| name string | ||
| distro datamodel.Distro | ||
| customCloud bool | ||
| }{ | ||
| {"Ubuntu2204", datamodel.AKSUbuntuContainerd2204Gen2, false}, | ||
| {"Ubuntu2204_CustomCloud", datamodel.AKSUbuntuContainerd2204Gen2, true}, | ||
| {"AzureLinuxV2", datamodel.AKSAzureLinuxV2Gen2, false}, | ||
| {"AzureLinuxV3", datamodel.AKSAzureLinuxV3Gen2, false}, | ||
| {"AzureLinuxV3OSGuard", datamodel.AKSAzureLinuxV3OSGuardGen2FIPSTL, false}, | ||
| {"Flatcar", datamodel.AKSFlatcarGen2, false}, | ||
| {"ACL", datamodel.AKSACLGen2TL, false}, | ||
| } | ||
|
|
||
| templateGenerator := InitializeTemplateGenerator() | ||
|
|
||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| config := newScriptlessGuardConfig(tc.distro) | ||
| if tc.customCloud { | ||
| config.ContainerService.Properties.CustomCloudEnv = &datamodel.CustomCloudEnv{ | ||
| Name: "akscustom", | ||
| } | ||
| } | ||
| // Force Mode B so getScriptlessBoothook early-returns the slim CustomData (P + H). | ||
| config.ScriptlessCSEProvisionMode = true | ||
|
|
||
| payload := templateGenerator.getScriptlessBoothook(config) | ||
|
|
||
| if len(payload) >= MaxCustomDataLength { | ||
| t.Fatalf("slim Mode B CustomData (%s) is %d bytes, must be < MaxCustomDataLength (%d). "+ | ||
| "A hotfix injecting too many/too-large scripts (H) overflowed the CustomData limit; "+ | ||
| "there is no further fallback once in Mode B, so the node would fail to provision.", | ||
| tc.name, len(payload), MaxCustomDataLength) | ||
| } | ||
| t.Logf("slim Mode B CustomData (%s): %d / %d bytes (%d headroom)", | ||
| tc.name, len(payload), MaxCustomDataLength, MaxCustomDataLength-len(payload)) | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.