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

node-installer: write kata config with less perms #986

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion cli/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func patchTargets(paths []string, imageReplacementsFile, runtimeHandler string,
if err != nil {
return err
}
if err := os.WriteFile(path, resource, os.ModePerm); err != nil {
if err := os.WriteFile(path, resource, 0o666); err != nil {
return fmt.Errorf("write %s: %w", path, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/genpolicy/genpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func New(rulesPath, settingsPath, cachePath string, bin []byte) (*Runner, error)
if err != nil {
return nil, fmt.Errorf("installing genpolicy: %w", err)
}
if err := os.MkdirAll(filepath.Dir(cachePath), os.ModePerm); err != nil {
if err := os.MkdirAll(filepath.Dir(cachePath), 0o777); err != nil {
return nil, fmt.Errorf("creating cache file: %w", err)
}

Expand Down
4 changes: 1 addition & 3 deletions internal/embedbin/regular.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package embedbin

import (
"os"

"github.com/spf13/afero"
)

Expand All @@ -19,7 +17,7 @@ type RegularInstaller struct {
// If prefix is empty, a temporary directory will be used.
func (r *RegularInstaller) Install(prefix string, contents []byte) (Installed, error) {
if prefix != "" {
if err := r.fs.MkdirAll(prefix, os.ModePerm); err != nil {
if err := r.fs.MkdirAll(prefix, 0o777); err != nil {
return nil, err
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/fsstore/fsstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *Store) Get(key string) ([]byte, bool) {

// Set sets the value for the given key.
func (s *Store) Set(key string, value []byte) {
if err := s.fs.MkdirAll("/", 0o755); err != nil {
if err := s.fs.MkdirAll("/", 0o777); err != nil {
s.logger.Error("failed to create dir")
return
}
Expand Down
8 changes: 4 additions & 4 deletions nodeinstaller/node-installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func run(ctx context.Context, fetcher assetFetcher, platform platforms.Platform,

fmt.Printf("Fetching %q to %q\n", file.URL, targetPath)

if err := os.MkdirAll(filepath.Dir(filepath.Join(hostMount, targetPath)), os.ModePerm); err != nil {
if err := os.MkdirAll(filepath.Dir(filepath.Join(hostMount, targetPath)), 0o777); err != nil {
return fmt.Errorf("creating directory %q: %w", filepath.Dir(targetPath), err)
}

Expand All @@ -99,7 +99,7 @@ func run(ctx context.Context, fetcher assetFetcher, platform platforms.Platform,

runtimeBase := filepath.Join("/opt", "edgeless", runtimeHandlerName)
kataConfigPath := filepath.Join(hostMount, runtimeBase, "etc")
if err := os.MkdirAll(kataConfigPath, os.ModePerm); err != nil {
if err := os.MkdirAll(kataConfigPath, 0o777); err != nil {
return fmt.Errorf("creating directory %q: %w", kataConfigPath, err)
}
var containerdConfigPath string
Expand Down Expand Up @@ -180,7 +180,7 @@ func containerdRuntimeConfig(basePath, configPath string, platform platforms.Pla
if err != nil {
return fmt.Errorf("marshaling kata runtime config: %w", err)
}
return os.WriteFile(configPath, rawConfig, os.ModePerm)
return os.WriteFile(configPath, rawConfig, 0o666)
}

func patchContainerdConfig(runtimeHandler, basePath, configPath string, platform platforms.Platform, debugRuntime bool) error {
Expand Down Expand Up @@ -241,7 +241,7 @@ func patchContainerdConfig(runtimeHandler, basePath, configPath string, platform
}

fmt.Printf("Patching containerd config at %s\n", configPath)
return os.WriteFile(configPath, rawConfig, os.ModePerm)
return os.WriteFile(configPath, rawConfig, 0o666)
}

func parseExistingContainerdConfig(path string) ([]byte, config.ContainerdConfig, error) {
Expand Down