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
  • Loading branch information
AshleyDumaine committed Feb 8, 2024
1 parent 9809faf commit fd5c96f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions controller/linodemachine_controller_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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 +65,12 @@ func (*LinodeMachineReconciler) newCreateConfig(ctx context.Context, machineScop

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

Check failure on line 70 in controller/linodemachine_controller_helpers.go

View workflow job for this annotation

GitHub Actions / go-analyse

odd number of arguments passed as key-value pairs for logging (loggercheck)

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

0 comments on commit fd5c96f

Please sign in to comment.