Skip to content

Commit

Permalink
VM: Move check for container-specific prefixed keys applied to VMs up (
Browse files Browse the repository at this point in the history
…#14680)

This PR fixes the following regression:

https://github.com/canonical/lxd-ci/actions/runs/12367790805/job/34516721509#step:11:93.

We always need to check config keys applied to VM's to ensure
container-specific prefixed keys are disallowed.
  • Loading branch information
tomponline authored Dec 17, 2024
2 parents 7931651 + 5651d63 commit e19037e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lxd/instance/instance_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ func ValidConfig(sysOS *sys.OS, config map[string]string, expanded bool, instanc
}

func validConfigKey(os *sys.OS, key string, value string, instanceType instancetype.Type) error {
// Disallow keys with container-specific prefixes such as "linux.sysctl." and "limits.kernel." for VMs.
if instanceType == instancetype.VM && shared.StringHasPrefix(key, instancetype.ConfigKeyPrefixesContainer...) {
return fmt.Errorf("%q isn't supported for %q", key, instanceType)
}

// Check if the key is a valid prefix and whether or not it requires a subkey.
knownPrefixes := append(instancetype.ConfigKeyPrefixesAny, instancetype.ConfigKeyPrefixesContainer...)
if strings.HasSuffix(key, ".") {
// Disallow keys with container-specific prefixes such as "linux.sysctl." and "limits.kernel." for VMs.
if instanceType == instancetype.VM && shared.StringHasPrefix(key, instancetype.ConfigKeyPrefixesContainer...) {
return fmt.Errorf("%q isn't supported for %q", key, instanceType)
}

if !(key == instancetype.ConfigVolatilePrefix || shared.ValueInSlice(key, knownPrefixes)) {
// Not a known prefix.
return fmt.Errorf("Unknown configuration key: %q", key)
Expand Down

0 comments on commit e19037e

Please sign in to comment.