Skip to content

Commit

Permalink
osbuild: validate env var name in systemd.unit.create
Browse files Browse the repository at this point in the history
Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
  • Loading branch information
achilleas-k committed Apr 8, 2024
1 parent 02bc1a3 commit e98606e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/osbuild/systemd_unit_create_stage.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package osbuild

import (
"fmt"
"regexp"
)

type serviceType string
type unitPath string

Expand Down Expand Up @@ -55,7 +60,22 @@ type SystemdUnitCreateStageOptions struct {

func (SystemdUnitCreateStageOptions) isStageOptions() {}

func (o *SystemdUnitCreateStageOptions) validate() error {
vre := regexp.MustCompile(envVarRegex)
if service := o.Config.Service; service != nil {
for _, envVar := range service.Environment {
if !vre.MatchString(envVar.Key) {
return fmt.Errorf("variable name %q doesn't conform to schema (%s)", envVar.Key, envVarRegex)
}
}
}
return nil
}

func NewSystemdUnitCreateStageOptions(options *SystemdUnitCreateStageOptions) *Stage {
if err := options.validate(); err != nil {
panic(err)
}
return &Stage{
Type: "org.osbuild.systemd.unit.create",
Options: options,
Expand Down

0 comments on commit e98606e

Please sign in to comment.