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

Storage: Improve volume name validation in CreateCustomVolumeFromBackup #13263

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion lxd/storage/backend_lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7188,6 +7188,31 @@ func (b *lxdBackend) CreateCustomVolumeFromBackup(srcBackup backup.Info, srcData
return fmt.Errorf("Valid volume snapshot config not found in index")
}

// Validate the names in the index.yaml file as these could be malicious.
err := ValidVolumeName(srcBackup.Name)
if err != nil {
return err
}

err = ValidVolumeName(srcBackup.Config.Volume.Name)
if err != nil {
return err
}

for _, snapName := range srcBackup.Snapshots {
err = ValidVolumeName(snapName)
if err != nil {
return err
}
}

for _, snap := range srcBackup.Config.VolumeSnapshots {
err = ValidVolumeName(snap.Name)
if err != nil {
return err
}
}

// Check whether we are allowed to create volumes.
req := api.StorageVolumesPost{
StorageVolumePut: api.StorageVolumePut{
Expand All @@ -7196,7 +7221,7 @@ func (b *lxdBackend) CreateCustomVolumeFromBackup(srcBackup backup.Info, srcData
Name: srcBackup.Name,
}

err := b.state.DB.Cluster.Transaction(b.state.ShutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
err = b.state.DB.Cluster.Transaction(b.state.ShutdownCtx, func(ctx context.Context, tx *db.ClusterTx) error {
return project.AllowVolumeCreation(b.state.GlobalConfig, tx, srcBackup.Project, req)
})
if err != nil {
Expand Down
Loading