Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make layers with label prefix "pebble-" reserved #403

Merged
merged 8 commits into from
Apr 8, 2024
10 changes: 3 additions & 7 deletions internals/overlord/planstate/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ func (m *PlanManager) SetServiceArgs(serviceArgs map[string][]string) error {
defer m.planLock.Unlock()

newLayer := &plan.Layer{
// Labels with "pebble-*" prefix are (will be) reserved, see:
// https://github.com/canonical/pebble/issues/220
// Labels with "pebble-*" prefix are reserved for use by Pebble.
// Layer.Validate() ensures this, so skip calling that because we're creating the
// Layer directly, not parsing from user input.
Label: "pebble-service-args",
Services: make(map[string]*plan.Service),
}
Expand All @@ -229,10 +230,5 @@ func (m *PlanManager) SetServiceArgs(serviceArgs map[string][]string) error {
}
}

err := newLayer.Validate()
if err != nil {
return err
}

return m.appendLayer(newLayer)
}
6 changes: 6 additions & 0 deletions internals/plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,12 @@ func CombineLayers(layers ...*Layer) (*Layer, error) {
// See also Plan.Validate, which does additional checks based on the combined
// layers.
func (layer *Layer) Validate() error {
if strings.HasPrefix(layer.Label, "pebble-") {
return &FormatError{
Message: `cannot use reserved label prefix "pebble-"`,
}
}

for name, service := range layer.Services {
if name == "" {
return &FormatError{
Expand Down
6 changes: 6 additions & 0 deletions internals/plan/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1933,3 +1933,9 @@ func (s *S) TestMergeServiceContextOverrides(c *C) {
WorkingDir: "/working/dir",
})
}

func (s *S) TestPebbleLabelPrefixReserved(c *C) {
// Validate fails if layer label has the reserved prefix "pebble-"
_, err := plan.ParseLayer(0, "pebble-foo", []byte("{}"))
c.Check(err, ErrorMatches, `cannot use reserved label prefix "pebble-"`)
}
Loading