diff --git a/.vagrant/machines/default/libvirt/created_networks b/.vagrant/machines/default/libvirt/created_networks index 2ad5939..5e0f6ab 100644 --- a/.vagrant/machines/default/libvirt/created_networks +++ b/.vagrant/machines/default/libvirt/created_networks @@ -6,3 +6,5 @@ 5533801d-70e3-4c21-9942-82d20930c789 5533801d-70e3-4c21-9942-82d20930c789 5533801d-70e3-4c21-9942-82d20930c789 +5533801d-70e3-4c21-9942-82d20930c789 +5533801d-70e3-4c21-9942-82d20930c789 diff --git a/exampleconfig.yaml b/exampleconfig.yaml index b527acf..7d48846 100644 --- a/exampleconfig.yaml +++ b/exampleconfig.yaml @@ -17,6 +17,9 @@ port: 80 # Files that will be copied into container on startup skel: /etc/podterminal/skel.tar.gz skel_target: /config +skel_chown: true +# Currently useless +skel_owner: "abc" ssl: false ssl_cert: /etc/ssl/certs/ssl-cert-snakeoil.pem ssl_cert_key: /etc/ssl/private/ssl-cert-snakeoil.key diff --git a/pods/skel.go b/pods/skel.go index 095108d..d3218ff 100644 --- a/pods/skel.go +++ b/pods/skel.go @@ -1,25 +1,31 @@ package pods import ( + "fmt" "log" "net/http" - "net/url" "os" "github.com/containers/podman/v4/pkg/bindings" + "github.com/containers/podman/v4/pkg/bindings/containers" "github.com/spf13/viper" ) // CopySkelToContainer copies an Archive into the containers root func CopySkelToContainer(id string) error { + chownBool := viper.GetBool("skel_chown") log.Println("Copying skel Archive to container") var err error conn, err := bindings.GetClient(Socket) if err != nil { return err } + options := containers.CopyOptions{ + Chown: &chownBool, + } fileInfo, err := os.Stat(viper.GetString("skel")) + if err != nil { log.Println("Could not access Skel archive") return err @@ -33,9 +39,14 @@ func CopySkelToContainer(id string) error { } defer file.Close() - params := url.Values{} + params, err := options.ToParams() + if err != nil { + log.Println("Could not parse skel options", err) + return err + } params.Set("path", viper.GetString("skel_target")) + fmt.Println("Container", id, " Params: ", params.Encode()) response, err := conn.DoRequest( Socket, file, @@ -50,9 +61,11 @@ func CopySkelToContainer(id string) error { } if response.StatusCode != http.StatusOK { - log.Println("Error putting archive into container: ") + log.Println("Error putting archive into container: ", response.StatusCode, response.Body) return err } log.Println(response.StatusCode, response.Body) + + // Manually chown the Directory, because podmans chown is sometimes unreliable return response.Process(nil) } diff --git a/readConfig.go b/readConfig.go index 2f604cb..f9f6891 100644 --- a/readConfig.go +++ b/readConfig.go @@ -17,7 +17,9 @@ func readConfigFile() { viper.SetDefault("dri", false) viper.SetDefault("dir_node", "/dev/dri/renderD128") viper.SetDefault("skel", "/etc/podterminal/skel.tar.gz") + viper.SetDefault("skel_chown", false) viper.SetDefault("skel_target", "/") + viper.SetDefault("skel_owner", "abc") viper.SetDefault("block_filebrowser", false) viper.SetDefault("envvars", map[string]string{ diff --git a/web/reverseProxy.go b/web/reverseProxy.go index 26fa95d..099bc84 100644 --- a/web/reverseProxy.go +++ b/web/reverseProxy.go @@ -57,16 +57,8 @@ func containerProxy(c *gin.Context) { c.Abort() } - err = pods.CopySkelToContainer(ct) - - if err != nil { - c.HTML( - 500, - "Error", - fmt.Sprintf("[%s] Could not copy skel archive to container: %v", sessionID, err), - ) - c.Abort() - } + // Soft fail Skel + _ = pods.CopySkelToContainer(ct) proxies[ct], err = createReverseProxy(fmt.Sprintf("http://%s:3000", ctip))