Files
plugin-manager/sandbox.go
Matt Dunleavy eedbbfec4a Implement major enhancements to plugin manager (v1.2.0 & v1.3.0)
This commit introduces significant improvements and new features to the plugin manager:

- Add plugin discovery system and remote repository support
- Implement plugin update system with digital signature verification
- Enhance plugin lifecycle hooks (PreLoad, PostLoad, PreUnload)
- Improve dependency management with custom version comparison
- Introduce lazy loading for optimized plugin performance
- Implement comprehensive error handling and logging
- Enhance concurrency safety with fine-grained locking
- Add plugin statistics tracking
- Remove external version comparison dependencies
- Improve hot-reload functionality with graceful shutdown
- Add SSH key support for remote repositories
- Implement Redbean server integration for plugin repositories

This update significantly improves the plugin manager's functionality,
security, and performance, providing a more robust and flexible system
for managing plugins in Go applications.
2024-07-06 14:37:17 -04:00

83 lines
1.5 KiB
Go

// Copyright (C) 2024 Matt Dunleavy. All rights reserved.
// Use of this source code is subject to the MIT license
// that can be found in the LICENSE file.
package pluginmanager
import (
"os"
"path/filepath"
"syscall"
)
type Sandbox interface {
Enable() error
Disable() error
VerifyPluginPath(path string) error
}
type LinuxSandbox struct {
originalDir string
originalUmask int
chrootDir string
}
func NewLinuxSandbox(chrootDir string) *LinuxSandbox {
if chrootDir == "" {
chrootDir = "./sandbox"
}
return &LinuxSandbox{
chrootDir: chrootDir,
}
}
func (s *LinuxSandbox) Enable() error {
var err error
s.originalDir, err = os.Getwd()
if err != nil {
return err
}
if err := os.MkdirAll(s.chrootDir, 0755); err != nil {
return err
}
if err := syscall.Chroot(s.chrootDir); err != nil {
return err
}
if err := os.Chdir("/"); err != nil {
return err
}
s.originalUmask = syscall.Umask(0)
return nil
}
func (s *LinuxSandbox) Disable() error {
syscall.Umask(s.originalUmask)
if err := syscall.Chroot("."); err != nil {
return err
}
if err := os.Chdir(s.originalDir); err != nil {
return err
}
return nil
}
func (s *LinuxSandbox) VerifyPluginPath(path string) error {
absPath, err := filepath.Abs(path)
if err != nil {
return err
}
if !filepath.HasPrefix(absPath, s.chrootDir) {
return ErrPluginSandboxViolation
}
return nil
}