Skip to content

Commit

Permalink
osbuild: validate env var name in systemd.unit
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 e98606e commit 3148580
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/osbuild/systemd_unit_stage.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package osbuild

import (
"fmt"
"regexp"
)

type unitType string

const (
Expand All @@ -16,7 +21,22 @@ type SystemdUnitStageOptions struct {

func (SystemdUnitStageOptions) isStageOptions() {}

func (o *SystemdUnitStageOptions) 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 NewSystemdUnitStage(options *SystemdUnitStageOptions) *Stage {
if err := options.validate(); err != nil {
panic(err)
}
return &Stage{
Type: "org.osbuild.systemd.unit",
Options: options,
Expand Down

0 comments on commit 3148580

Please sign in to comment.