From ff4b7655c857eb33e254aaff8efd146e3aa7f4f9 Mon Sep 17 00:00:00 2001 From: DaneEveritt Date: Sat, 29 Oct 2022 12:40:49 -0700 Subject: [PATCH] update config to support more vhd features down the road --- cmd/migrate_vhd.go | 4 ++-- config/config.go | 13 +++++-------- config/config_servers.go | 28 ++++++++++++++++++++++++++++ go.sum | 2 -- internal/vhd/vhd.go | 5 +++++ server/filesystem/filesystem.go | 2 +- 6 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 config/config_servers.go diff --git a/cmd/migrate_vhd.go b/cmd/migrate_vhd.go index 8dc3ba9..6ce68b0 100644 --- a/cmd/migrate_vhd.go +++ b/cmd/migrate_vhd.go @@ -46,8 +46,8 @@ func newMigrateVHDCommand() *cobra.Command { // Run executes the migration command. func (m *MigrateVHDCommand) Run(ctx context.Context) error { - if !config.Get().System.UseVirtualDisks { - return errors.New("cannot migrate to vhd: configuration file \"system.use_virtual_disks\" value is set to \"false\"") + if !vhd.Enabled() { + return errors.New("cannot migrate to vhd: the underlying driver must be set to \"vhd\"") } for _, s := range m.manager.All() { s.Log().Debug("starting migration of server contents to virtual disk...") diff --git a/config/config.go b/config/config.go index 03bbd60..e173881 100644 --- a/config/config.go +++ b/config/config.go @@ -120,14 +120,6 @@ type RemoteQueryConfiguration struct { // SystemConfiguration defines basic system configuration settings. type SystemConfiguration struct { - // UseVirtualDisks sets Wings to use virtual hard-disks when storing server - // files. This allows for more enforced disk space limits, at a slight performance - // cost. - // - // Generally this only needs to be enabled on systems with a large untrusted - // user presence, it is not necessary for self-hosting instances. - UseVirtualDisks bool `json:"use_virtual_disks" yaml:"use_virtual_disks"` - // The root directory where all of the pterodactyl data is stored at. RootDirectory string `default:"/var/lib/pterodactyl" yaml:"root_directory"` @@ -313,6 +305,11 @@ type Configuration struct { // is only required by users running Wings without SSL certificates and using internal IP // addresses in order to connect. Most users should NOT enable this setting. AllowCORSPrivateNetwork bool `json:"allow_cors_private_network" yaml:"allow_cors_private_network"` + + // Servers contains all of the settings that are used when configuring individual servers + // on the system. This is a global configuration for all server instances, not to be confused + // with the per-server configurations provided by the Panel API. + Servers Servers `json:"servers" yaml:"servers"` } // NewAtPath creates a new struct and set the path where it should be stored. diff --git a/config/config_servers.go b/config/config_servers.go new file mode 100644 index 0000000..d7a6078 --- /dev/null +++ b/config/config_servers.go @@ -0,0 +1,28 @@ +package config + +type FSDriver string + +const ( + FSDriverLocal FSDriver = "local" + FSDriverVHD FSDriver = "vhd" +) + +type Servers struct { + // Filesystem defines all of the filesystem specific settings used for servers. + Filesystem Filesystem `json:"filesystem" yaml:"filesystem"` +} + +type Filesystem struct { + // Driver defines the underlying filesystem driver that is used when a server is + // created on the system. This currently supports either of the following drivers: + // + // local: the local driver is the default one used by Wings. This offloads all of the + // disk limit enforcement to Wings itself. This has a performance impact but is + // the most compatiable with all systems. + // vhd: the vhd driver uses "virtual" disks on the host system to enforce disk limits + // on the server. This is more performant since calculations do not need to be made + // by Wings itself when enforcing limits. It also avoids vulnerabilities that exist + // in the local driver which allow malicious processes to quickly create massive files + // before Wings is able to detect and stop them from being written. + Driver FSDriver `default:"local" json:"driver" yaml:"driver"` +} diff --git a/go.sum b/go.sum index 95b5152..ae0ab8d 100644 --- a/go.sum +++ b/go.sum @@ -803,7 +803,6 @@ github.com/smartystreets/gunit v1.0.0/go.mod h1:qwPWnhz6pn0NnRBP++URONOVyNkPyr4S github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= github.com/spf13/afero v1.9.2 h1:j49Hj62F0n+DaZ1dDCvhABaPNSGNkt32oRFxI33IEMw= github.com/spf13/afero v1.9.2/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y= @@ -1147,7 +1146,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= diff --git a/internal/vhd/vhd.go b/internal/vhd/vhd.go index 46317cb..b385f6e 100644 --- a/internal/vhd/vhd.go +++ b/internal/vhd/vhd.go @@ -68,6 +68,11 @@ func DiskPath(uuid string) string { return filepath.Join(config.Get().System.Data, ".vhd/", uuid+".img") } +// Enabled returns true when VHD support is enabled on the instance. +func Enabled() bool { + return config.Get().Servers.Filesystem.Driver == config.FSDriverVHD +} + // New returns a new Disk instance. The "size" parameter should be provided in // bytes of space allowed for the disk. An additional slice of option callbacks // can be provided to programatically swap out the underlying filesystem diff --git a/server/filesystem/filesystem.go b/server/filesystem/filesystem.go index d0d5cfa..80cd15b 100644 --- a/server/filesystem/filesystem.go +++ b/server/filesystem/filesystem.go @@ -54,7 +54,7 @@ func New(uuid string, size int64, denylist []string) *Filesystem { denylist: ignore.CompileIgnoreLines(denylist...), } - if config.Get().System.UseVirtualDisks { + if vhd.Enabled() { fs.vhd = vhd.New(size, vhd.DiskPath(uuid), fs.root) }