Skip to content

Commit

Permalink
fix: insufficient permissions on devenv volume
Browse files Browse the repository at this point in the history
  • Loading branch information
bchmnn committed Jun 24, 2024
1 parent 9ac343f commit b684965
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 4 additions & 3 deletions service/backend/controller/devenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,10 @@ func (devenv *DevenvController) Exec(ctx *gin.Context) {
tmpUuid := guuid.New().String()

target := filepath.Join(devenv.DevenvFilesPathTmp, tmpUuid)
mount := filepath.Join("/tmp", tmpUuid)
util.SLogger.Debugf("Copying %s -> %s", src, target)

err := util.CopyRecurse(src, target)
err := util.CopyRecurse(src, target, 0777)
if err != nil {
util.SLogger.Warnf("Copying devenv container failed, %s", err.Error())
ctx.AbortWithStatusJSON(http.StatusBadRequest, types.ErrorResponse{
Expand All @@ -328,7 +329,7 @@ func (devenv *DevenvController) Exec(ctx *gin.Context) {
}
}()

id, _, port, err := devenv.Docker.EnsureDevenvContainerStarted(target)
id, _, port, err := devenv.Docker.EnsureDevenvContainerStarted(target, mount)

if err != nil {
util.SLogger.Warnf("Creating devenv container failed, %s", err.Error())
Expand Down Expand Up @@ -378,7 +379,7 @@ func (devenv *DevenvController) Exec(ctx *gin.Context) {
}

defer clientConn.Close()
err = p.CreateExecWebsocketPipe(clientConn, *cookie, target, command)
err = p.CreateExecWebsocketPipe(clientConn, *cookie, mount, command)
if err != nil {
ctx.AbortWithError(http.StatusBadRequest, err)
return
Expand Down
5 changes: 4 additions & 1 deletion service/backend/service/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func (docker *DockerService) CreateReplContainer(

func (docker *DockerService) CreateDevenvContainer(
devenvPath string,
mountPath string,
opts types.RunContainerOptions,
) (*container.CreateResponse, error) {
util.SLogger.Debugf("[%-25s] Creating container", fmt.Sprintf("NM:%s..", opts.ContainerName[:5]))
Expand All @@ -196,7 +197,7 @@ func (docker *DockerService) CreateDevenvContainer(
{
Type: mount.TypeBind,
Source: devenvPath,
Target: devenvPath,
Target: mountPath,
},
},
LogConfig: container.LogConfig{
Expand Down Expand Up @@ -404,9 +405,11 @@ func (docker *DockerService) EnsureReplContainerStarted(

func (docker *DockerService) EnsureDevenvContainerStarted(
devenvPath string,
mountPath string,
) (*string, *string, *uint16, error) {
response, err := docker.CreateDevenvContainer(
devenvPath,
mountPath,
types.RunContainerOptions{
ImageTag: "ptwhy",
ContainerName: uuid.NewString(),
Expand Down
7 changes: 5 additions & 2 deletions service/backend/util/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"errors"
"io/fs"
"os"
"path/filepath"

Expand Down Expand Up @@ -76,8 +77,10 @@ func DeleteDir(path string) error {
return os.RemoveAll(path)
}

func CopyRecurse(src string, target string) error {
func CopyRecurse(src string, target string, perm fs.FileMode) error {
return cp.Copy(src, target, cp.Options{
OnSymlink: func(string) cp.SymlinkAction { return cp.Skip },
OnSymlink: func(string) cp.SymlinkAction { return cp.Skip },
AddPermission: perm,
})
}

0 comments on commit b684965

Please sign in to comment.