Skip to content

Commit

Permalink
fix: allow user-data mime content-type before mime-version header (aw…
Browse files Browse the repository at this point in the history
  • Loading branch information
bwagner5 authored Sep 7, 2023
1 parent 2e9bcb8 commit a90c158
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/providers/amifamily/bootstrap/eksbootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ func (e EKS) isIPv6() bool {
// mimeify returns userData in a mime format
// if the userData passed in is already in a mime format, then the input is returned without modification
func (e EKS) mimeify(customUserData string) (string, error) {
if strings.HasPrefix(strings.TrimSpace(customUserData), "MIME-Version:") {
if strings.HasPrefix(strings.TrimSpace(customUserData), "MIME-Version:") ||
strings.HasPrefix(strings.TrimSpace(customUserData), "Content-Type:") {
return customUserData, nil
}
var outputBuffer bytes.Buffer
Expand Down
19 changes: 19 additions & 0 deletions pkg/providers/launchtemplate/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,25 @@ var _ = Describe("LaunchTemplates", func() {
expectedUserData := fmt.Sprintf(string(content), newProvisioner.Name)
ExpectLaunchTemplatesCreatedWithUserData(expectedUserData)
})
It("should merge in custom user data when Content-Type is before MIME-Version", func() {
ctx = settings.ToContext(ctx, test.Settings(test.SettingOptions{
EnableENILimitedPodDensity: lo.ToPtr(false),
}))

content, err := os.ReadFile("testdata/al2_userdata_content_type_first_input.golden")
Expect(err).To(BeNil())
nodeTemplate.Spec.UserData = aws.String(string(content))
ExpectApplied(ctx, env.Client, nodeTemplate)
newProvisioner := test.Provisioner(coretest.ProvisionerOptions{ProviderRef: &v1alpha5.MachineTemplateRef{Name: nodeTemplate.Name}})
ExpectApplied(ctx, env.Client, newProvisioner)
pod := coretest.UnschedulablePod()
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, prov, pod)
ExpectScheduled(ctx, env.Client, pod)
content, err = os.ReadFile("testdata/al2_userdata_merged.golden")
Expect(err).To(BeNil())
expectedUserData := fmt.Sprintf(string(content), newProvisioner.Name)
ExpectLaunchTemplatesCreatedWithUserData(expectedUserData)
})
It("should merge in custom user data not in multi-part mime format", func() {
ctx = settings.ToContext(ctx, test.Settings(test.SettingOptions{
EnableENILimitedPodDensity: lo.ToPtr(false),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0

--BOUNDARY
Content-Type: text/x-shellscript; charset="us-ascii"

#!/bin/bash
echo "Running custom user data script"

--BOUNDARY--

0 comments on commit a90c158

Please sign in to comment.