Skip to content

Commit

Permalink
validate decoded bootstrap data does not exceed the user_data byte li…
Browse files Browse the repository at this point in the history
…mit according to the Linode API (#94)
  • Loading branch information
AshleyDumaine authored Feb 8, 2024
1 parent fdb9474 commit 660e466
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit 660e466

Please sign in to comment.