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

fix(pkg/rke2): psa custom path #3665

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions pkg/rke2/psa.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ const (
// setPSAs sets the default PSA's based on the mode that RKE2 is running in. There is either CIS or non
// CIS mode. For CIS mode, a default PSA configuration with enforcement for restricted will be applied
// for non CIS mode, a default PSA configuration will be applied that has privileged restriction
func setPSAs(cisMode bool) error {
func setPSAs(cisMode bool, podSecurityConfigFile string) error {
logrus.Info("Applying Pod Security Admission Configuration")
configDir := filepath.Dir(defaultPSAConfigFile)
configDir := filepath.Dir(podSecurityConfigFile)
if err := os.MkdirAll(configDir, 0755); err != nil {
return err
}
if !cisMode { // non-CIS mode
psaConfig := unrestrictedPSAConfig()
if err := ioutil.WriteFile(defaultPSAConfigFile, []byte(psaConfig), 0600); err != nil {
if err := ioutil.WriteFile(podSecurityConfigFile, []byte(psaConfig), 0600); err != nil {
return errors.Wrapf(err, "psa: failed to write psa unrestricted config")
}

} else { // CIS mode
psaConfig := restrictedPSAConfig()
if err := ioutil.WriteFile(defaultPSAConfigFile, []byte(psaConfig), 0600); err != nil {
if err := ioutil.WriteFile(podSecurityConfigFile, []byte(psaConfig), 0600); err != nil {
return errors.Wrapf(err, "psa: failed to write psa restricted config")
}
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/rke2/rke2_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@ func initExecutor(clx *cli.Context, cfg Config, isServer bool) (*podexecutor.Sta
// Adding PSAs
podSecurityConfigFile := clx.String("pod-security-admission-config-file")
if podSecurityConfigFile == "" {
if err := setPSAs(isCISMode(clx)); err != nil {
return nil, err
}
podSecurityConfigFile = defaultPSAConfigFile
}

if err := setPSAs(isCISMode(clx), podSecurityConfigFile); err != nil {
return nil, err
}

return &podexecutor.StaticPodConfig{
Resolver: resolver,
ImagesDir: agentImagesDir,
Expand Down