Skip to content

Commit

Permalink
added setuid function to get the user uid for image extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
umar committed Jul 23, 2024
1 parent 551b946 commit 5744a01
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/helpers/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package docker

import (
"archive/tar"
"context"
"encoding/hex"
"net/http"
Expand Down Expand Up @@ -137,6 +138,15 @@ type UnpackEventData struct {
Dest string
}

func setUIDGID(h *tar.Header) (bool, error) {
// Set the desired UID and GID
h.Uid = os.Getuid()
h.Gid = os.Getgid()

// Return true to indicate that this header should be included in the extraction
return true, nil
}

// DownloadAndExtractDockerImage extracts a container image natively. It supports privileged/unprivileged mode
func DownloadAndExtractDockerImage(ctx luettypes.Context, image, dest string, auth *registrytypes.AuthConfig, verify bool) (*images.Image, error) {
if verify {
Expand Down Expand Up @@ -185,7 +195,7 @@ func DownloadAndExtractDockerImage(ctx luettypes.Context, image, dest string, au
ctx,
img,
dest,
nil,
setUIDGID,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -249,7 +259,7 @@ func ExtractDockerImage(ctx luettypes.Context, local, dest string) (*images.Imag
ctx,
img,
dest,
nil,
setUIDGID,
)

if err != nil {
Expand Down

0 comments on commit 5744a01

Please sign in to comment.