-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Harrison Affel <[email protected]>
- Loading branch information
1 parent
3e0fb75
commit 1195ba4
Showing
6 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
package defaults | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func createDataDir(dataDir string, perm os.FileMode) error { | ||
if err := os.MkdirAll(dataDir, perm); err != nil { | ||
return errors.Wrapf(err, "failed to create directory %s", dataDir) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package defaults | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
k3swindows "github.com/k3s-io/k3s/pkg/agent/util/acl" | ||
"github.com/pkg/errors" | ||
rke2windows "github.com/rancher/rke2/pkg/windows" | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
func createDataDir(dataDir string, perm os.FileMode) error { | ||
_, err := os.Stat(dataDir) | ||
doesNotExist := errors.Is(err, os.ErrNotExist) | ||
if err != nil && !doesNotExist { | ||
return fmt.Errorf("failed to create data directory %s: %v", dataDir, err) | ||
} | ||
|
||
if !doesNotExist { | ||
return nil | ||
} | ||
|
||
// only set restrictive ACLs the dataDir, not the full path | ||
path, _ := filepath.Split(dataDir) | ||
if os.MkdirAll(path, perm) != nil { | ||
return fmt.Errorf("failed to create data directory %s: %v", dataDir, err) | ||
} | ||
|
||
if err = rke2windows.Mkdir(dataDir, []windows.EXPLICIT_ACCESS{ | ||
k3swindows.GrantSid(windows.GENERIC_ALL, k3swindows.LocalSystemSID()), | ||
k3swindows.GrantSid(windows.GENERIC_ALL, k3swindows.BuiltinAdministratorsSID()), | ||
}...); err != nil { | ||
return fmt.Errorf("failed to create data directory %s: %v", dataDir, err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters