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

Update mount validation #30

Merged
merged 1 commit into from
Jul 17, 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
14 changes: 13 additions & 1 deletion server/mounts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -48,7 +49,6 @@ func (s *Server) Mounts() []environment.Mount {
func (s *Server) customMounts() []environment.Mount {
var mounts []environment.Mount

// TODO: probably need to handle things trying to mount directories that do not exist.
for _, m := range s.Config().Mounts {
source := filepath.Clean(m.Source)
target := filepath.Clean(m.Target)
Expand All @@ -59,6 +59,18 @@ func (s *Server) customMounts() []environment.Mount {
"read_only": m.ReadOnly,
})

// Check if the source path exists
if _, err := os.Stat(source); os.IsNotExist(err) {
logger.WithField("missing_source_path", source).Warn("skipping custom server mount, source path does not exist")
continue
}

// Check if the target path includes /home/container
if strings.Contains(target, "/home/container") {
logger.WithField("invalid_target_path", target).Warn("skipping custom server mount, target path includes /home/container")
continue
}

mounted := false
for _, allowed := range config.Get().AllowedMounts {
// Check if the source path is included in the allowed mounts list.
Expand Down
Loading