Skip to content

Commit

Permalink
Add input validation for label (#108)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Barnett <[email protected]>
Co-authored-by: Dan Webb <[email protected]>
Co-authored-by: Corey Hemminger <[email protected]>
  • Loading branch information
3 people authored Dec 9, 2024
1 parent e217271 commit 61fb185
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.

## Unreleased

- Add validation to the filesystem label property, limiting to a maximum length of 12 characters

## 4.0.15 - *2024-12-09*

## 4.0.14 - *2024-05-03*
Expand Down Expand Up @@ -38,7 +40,6 @@ Standardise files with files in sous-chefs/repo-management

## 4.0.1 - *2022-10-28*

- Remove delivery folder
- Fix document: `nomkfs` option is not in `filesystem` resource

## 4.0.0 - *2021-10-14*
Expand Down
14 changes: 5 additions & 9 deletions resources/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
default_action :create

# The name property is the label of the filesystem.
property :label, String
property :label, String, name_property: true, regex: /^.{1,12}$/

# We have several kinds of device we might be using
property :device, String
Expand Down Expand Up @@ -80,20 +80,16 @@ def device
@device ||= if @new_resource.file
@new_resource.device
elsif @new_resource.vg
"/dev/mapper/#{@new_resource.vg}-#{label}"
"/dev/mapper/#{@new_resource.vg}-#{new_resource.label}"
elsif @new_resource.uuid
"/dev/disk/by-uuid/#{@new_resource.uuid}"
elsif @new_resource.device
@new_resource.device
else
"/dev/mapper/#{label}"
"/dev/mapper/#{new_resource.label}"
end
end

def label
@label = @new_resource.label || @new_resource.name
end

# create the mount point directory
# mount points should not have files in them and have no
# reason to be user writable
Expand Down Expand Up @@ -127,7 +123,7 @@ def mount_point(mount_location)

# LVM
# We use the lvm provider directly.
lvm_logical_volume label do
lvm_logical_volume new_resource.label do
action :create
group vg
size size
Expand Down Expand Up @@ -171,7 +167,7 @@ def mount_point(mount_location)
packages.each { |keyed_package| package keyed_package.to_s }
end

Chef::Log.info "filesystem #{label} creating #{fstype} on #{device}"
Chef::Log.info "filesystem #{new_resource.label} creating #{fstype} on #{device}"

# Install the filesystem's default package and recipes as configured in default attributes.
mkfs_force_options = node['filesystem_tools'].fetch(fstype, nil)
Expand Down

0 comments on commit 61fb185

Please sign in to comment.