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

Use $SETPRIV in mkdir/stat command when necessary #279

Merged
merged 4 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 1 addition & 5 deletions daemons/lib-copy-offload/copy-offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,7 @@ int copy_offload_copy(COPY_OFFLOAD *offload, char *compute_name, char *workflow_
curl_easy_setopt(offload->curl, CURLOPT_URL, urlbuf);

if (profile_name == NULL) {
// We cannot use the default DM profile in k8s because it has setpriv commands to change
// from root to a non-root user. Those setpriv commands will fail in the copyoffload
// container since it is running as non-root. Therefore, we need to use the
// copy-offload-default profile and not the k8s default.
profile_name = "copy-offload-default";
profile_name = "";
}

if (dry_run) {
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ go 1.22.0
toolchain go1.22.5

require (
github.com/DataWorkflowServices/dws v0.0.1-0.20250221171407-1a51721c0739
github.com/DataWorkflowServices/dws v0.0.1-0.20250224211524-95e559ed4fa8
github.com/NearNodeFlash/lustre-fs-operator v0.0.1-0.20250219194350-45aad5cbbe17
github.com/NearNodeFlash/nnf-ec v0.0.1-0.20250219193635-3e6c6b39d0e0 // indirect
github.com/NearNodeFlash/nnf-sos v0.0.1-0.20250221193225-b496a821842d
github.com/NearNodeFlash/nnf-ec v0.0.1-0.20250220202952-3c878bceb55c // indirect
github.com/NearNodeFlash/nnf-sos v0.0.1-0.20250226162446-00a9dace0693
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to update nnf-sos after its merge

github.com/onsi/ginkgo/v2 v2.22.2
github.com/onsi/gomega v1.36.2
github.com/prometheus/client_golang v1.16.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
github.com/DataWorkflowServices/dws v0.0.1-0.20250221171407-1a51721c0739 h1:QpU3oUwqVI3yC38Ck+BH9bGl8hmoXOvEw8gk30k9l3U=
github.com/DataWorkflowServices/dws v0.0.1-0.20250221171407-1a51721c0739/go.mod h1:i9v4K2d64a9uyd9ZazOJ85RWzVQjIgHWXkLo895KDAE=
github.com/DataWorkflowServices/dws v0.0.1-0.20250224211524-95e559ed4fa8 h1:plfxAo/J9942dSPju40X3JzvhxhcrBowk/DVmZ3WswE=
github.com/DataWorkflowServices/dws v0.0.1-0.20250224211524-95e559ed4fa8/go.mod h1:i9v4K2d64a9uyd9ZazOJ85RWzVQjIgHWXkLo895KDAE=
github.com/NearNodeFlash/lustre-fs-operator v0.0.1-0.20250219194350-45aad5cbbe17 h1:xYLLW3fMEKauujqkmspeWoyWhEEu+capOKUPePo4IuU=
github.com/NearNodeFlash/lustre-fs-operator v0.0.1-0.20250219194350-45aad5cbbe17/go.mod h1:H9GBWOmFp9BGGBWDVZk0pvPWzL6jUKkieVsIIoPlzMs=
github.com/NearNodeFlash/nnf-ec v0.0.1-0.20250219193635-3e6c6b39d0e0 h1:5arAC1ZW6QRZsv4Sowhno3EeYtFTnYc/4Ody08shDDY=
github.com/NearNodeFlash/nnf-ec v0.0.1-0.20250219193635-3e6c6b39d0e0/go.mod h1:lx13ustzE/+39fLECky+CFKkAV8GYlX9eaI6IGmHQkY=
github.com/NearNodeFlash/nnf-sos v0.0.1-0.20250221193225-b496a821842d h1:/xwEmSqkLBY8q0VFtPAesvwnHZB/1qj6CXt5SAb3MZ8=
github.com/NearNodeFlash/nnf-sos v0.0.1-0.20250221193225-b496a821842d/go.mod h1:vaj4EtPkZMC8twMaPshfn1UyDpiVwQht0iXPPYX9Ewk=
github.com/NearNodeFlash/nnf-ec v0.0.1-0.20250220202952-3c878bceb55c h1:YR/0Cd4QGDluZ0UwDzhJxBHy4eDhBjKFQSEP7LsEjsY=
github.com/NearNodeFlash/nnf-ec v0.0.1-0.20250220202952-3c878bceb55c/go.mod h1:lx13ustzE/+39fLECky+CFKkAV8GYlX9eaI6IGmHQkY=
github.com/NearNodeFlash/nnf-sos v0.0.1-0.20250226162446-00a9dace0693 h1:83wvr6Z/+wiY9QVTkAlFdva2MF46so1NwDHSLMJpsG0=
github.com/NearNodeFlash/nnf-sos v0.0.1-0.20250226162446-00a9dace0693/go.mod h1:9cjTZO4mYyk6BuPANVhOveyDCLYDnLagpdT+eAqhON8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down
22 changes: 19 additions & 3 deletions internal/controller/helpers/datamovement_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ func BuildDMCommand(profile *nnfv1alpha6.NnfDataMovementProfile, hostfile string
}

cmd := profile.Data.Command

// If running as non-root (i.e. in a copy offload container), remove the --uid and --gid options
// from dcp.
if os.Getuid() != 0 {
cmd = strings.ReplaceAll(cmd, "--uid $UID", "")
cmd = strings.ReplaceAll(cmd, "--gid $GID", "")
}

cmd = strings.ReplaceAll(cmd, "$HOSTFILE", hostfile)
cmd = strings.ReplaceAll(cmd, "$UID", fmt.Sprintf("%d", dm.Spec.UserId))
cmd = strings.ReplaceAll(cmd, "$GID", fmt.Sprintf("%d", dm.Spec.GroupId))
Expand Down Expand Up @@ -298,7 +306,15 @@ func BuildDMCommand(profile *nnfv1alpha6.NnfDataMovementProfile, hostfile string
return strings.Split(cmd, " "), nil
}

func buildStatOrMkdirCommand(uid, gid uint32, cmd, hostfile, path string) string {
func buildStatOrMkdirCommand(uid, gid uint32, cmd, setprivCmd, hostfile, path string, log logr.Logger) string {

// For DataIn/DataOut, dm is ran as root, so setpriv is needed to become the specified user. For
// copy offload, the user container is ran as the user, so setpriv is not needed.
if os.Getuid() != 0 {
setprivCmd = ""
}
cmd = strings.ReplaceAll(cmd, "$SETPRIV", setprivCmd)

cmd = strings.ReplaceAll(cmd, "$HOSTFILE", hostfile)
cmd = strings.ReplaceAll(cmd, "$UID", fmt.Sprintf("%d", uid))
cmd = strings.ReplaceAll(cmd, "$GID", fmt.Sprintf("%d", gid))
Expand Down Expand Up @@ -483,7 +499,7 @@ func GetDestinationDir(profile *nnfv1alpha6.NnfDataMovementProfile, dm *nnfv1alp

// Use mpirun to run stat on a file as a given UID/GID by using `setpriv`
func mpiStat(profile *nnfv1alpha6.NnfDataMovementProfile, path string, uid, gid uint32, mpiHostfile string, log logr.Logger) (string, error) {
cmd := buildStatOrMkdirCommand(uid, gid, profile.Data.StatCommand, mpiHostfile, path)
cmd := buildStatOrMkdirCommand(uid, gid, profile.Data.StatCommand, profile.Data.SetprivCommand, mpiHostfile, path, log)

output, err := command.Run(cmd, log)
if err != nil {
Expand Down Expand Up @@ -595,7 +611,7 @@ func createDestinationDir(profile *nnfv1alpha6.NnfDataMovementProfile, dm *nnfv1
return nil
}

cmd := buildStatOrMkdirCommand(dm.Spec.UserId, dm.Spec.GroupId, profile.Data.MkdirCommand, mpiHostfile, dest)
cmd := buildStatOrMkdirCommand(dm.Spec.UserId, dm.Spec.GroupId, profile.Data.MkdirCommand, profile.Data.SetprivCommand, mpiHostfile, dest, log)
output, err := command.Run(cmd, log)
if err != nil {
return fmt.Errorf("data movement mkdir failed ('%s'): %w output: %s", cmd, err, output)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# github.com/DataWorkflowServices/dws v0.0.1-0.20250221171407-1a51721c0739
# github.com/DataWorkflowServices/dws v0.0.1-0.20250224211524-95e559ed4fa8
## explicit; go 1.22.0
github.com/DataWorkflowServices/dws/api/v1alpha3
github.com/DataWorkflowServices/dws/utils/dwdparse
Expand All @@ -7,10 +7,10 @@ github.com/DataWorkflowServices/dws/utils/updater
## explicit; go 1.22.0
github.com/NearNodeFlash/lustre-fs-operator/api/v1beta1
github.com/NearNodeFlash/lustre-fs-operator/config/crd/bases
# github.com/NearNodeFlash/nnf-ec v0.0.1-0.20250219193635-3e6c6b39d0e0
# github.com/NearNodeFlash/nnf-ec v0.0.1-0.20250220202952-3c878bceb55c
## explicit; go 1.22.0
github.com/NearNodeFlash/nnf-ec/pkg/rfsf/pkg/models
# github.com/NearNodeFlash/nnf-sos v0.0.1-0.20250221193225-b496a821842d
# github.com/NearNodeFlash/nnf-sos v0.0.1-0.20250226162446-00a9dace0693
## explicit; go 1.22.0
github.com/NearNodeFlash/nnf-sos/api/v1alpha6
github.com/NearNodeFlash/nnf-sos/config/crd/bases
Expand Down
Loading