Skip to content

Commit

Permalink
lxd/util: Check cloud-init configuration tag
Browse files Browse the repository at this point in the history
This helps to avoid parsing an invalid conifiguration that lacks `#cloud-config` and also helps us check if the configuration is in a suported format.

Signed-off-by: hamistao <[email protected]>
  • Loading branch information
hamistao committed Feb 18, 2025
1 parent b79a4ac commit 779dcc9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lxd/util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ type cloudInitUserSSHKeys struct {
// In the case where we were not able to parse the cloud config, return the original, unchanged config and
// the error.
func MergeSSHKeyCloudConfig(instanceConfig map[string]string, cloudConfig string) (string, error) {
// Check if cloudConfig is in a supported format.
// A YAML cloud config without #cloud-config is invalid.
if cloudConfig != "" && !shared.ValueInSlice("#cloud-config", shared.SplitNTrimSpace(cloudConfig, "\n", 3, false)) {
return cloudConfig, errors.New(`Parsing configuration is not supported as it is not "#cloud-config"`)
}

// Use a pointer to cloudInitUserSSHKeys so we can append to its fields.
users := make(map[string]*cloudInitUserSSHKeys)

Expand Down

0 comments on commit 779dcc9

Please sign in to comment.