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

[fix]: validate decoded bootstrap data does not exceed the user_data byte limit according to the Linode API #94

Merged
merged 1 commit into from
Feb 8, 2024
Merged
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
11 changes: 11 additions & 0 deletions controller/linodemachine_controller_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
b64 "encoding/base64"
"encoding/gob"
"errors"
"fmt"
"sort"

"github.com/go-logr/logr"
Expand All @@ -41,6 +42,10 @@ import (
infrav1alpha1 "github.com/linode/cluster-api-provider-linode/api/v1alpha1"
)

// Size limit in bytes on the decoded metadata.user_data for cloud-init
// The decoded user_data must not exceed 16384 bytes per the Linode API
const maxBootstrapDataBytes = 16384

func (*LinodeMachineReconciler) newCreateConfig(ctx context.Context, machineScope *scope.MachineScope, tags []string, logger logr.Logger) (*linodego.InstanceCreateOptions, error) {
var err error

Expand All @@ -61,6 +66,12 @@ func (*LinodeMachineReconciler) newCreateConfig(ctx context.Context, machineScop

return nil, err
}
if len(bootstrapData) > maxBootstrapDataBytes {
err = errors.New("bootstrap data too large")
logger.Info(fmt.Sprintf("decoded bootstrap data exceeds size limit of %d bytes", maxBootstrapDataBytes), "error", err.Error())

return nil, err
}
createConfig.Metadata = &linodego.InstanceMetadataOptions{
UserData: b64.StdEncoding.EncodeToString(bootstrapData),
}
Expand Down