Skip to content

Commit 2d45b03

Browse files
committed
Check for magic cloud-config comment before yaml
Signed-off-by: Anders F Björklund <[email protected]>
1 parent 3184d67 commit 2d45b03

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pkg/cidata/schema.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package cidata
22

33
import (
4+
"bytes"
45
_ "embed"
6+
"fmt"
57
"strings"
68

79
"github.com/santhosh-tekuri/jsonschema/v5"
@@ -15,6 +17,9 @@ const schemaURL = "https://raw.githubusercontent.com/canonical/cloud-init/main/c
1517
var schemaText string
1618

1719
func validateCloudConfig(userData []byte) error {
20+
if !bytes.HasPrefix(userData, []byte("#cloud-config")) {
21+
return fmt.Errorf("missing #cloud-config")
22+
}
1823
var m interface{}
1924
err := yaml.Unmarshal(userData, &m)
2025
if err != nil {

0 commit comments

Comments
 (0)