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

Adding the ability to define a secuirty context and SELinux options #257

Merged
merged 6 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added oryxBuildBinary
Binary file not shown.
14 changes: 8 additions & 6 deletions pkg/apis/upgrade.cattle.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ type PlanStatus struct {

// ContainerSpec is a simplified container template.
type ContainerSpec struct {
Image string `json:"image,omitempty"`
Command []string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env []corev1.EnvVar `json:"envs,omitempty"`
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
Volumes []VolumeSpec `json:"volumes,omitempty"`
Image string `json:"image,omitempty"`
Command []string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env []corev1.EnvVar `json:"envs,omitempty"`
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
Volumes []VolumeSpec `json:"volumes,omitempty"`
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
SELinuxOptions *corev1.SELinuxOptions `json:"seLinuxOptions,omitempty"`
Auston-Ivison-Suse marked this conversation as resolved.
Show resolved Hide resolved
}

type VolumeSpec struct {
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/upgrade.cattle.io/v1/zz_generated_deepcopy.go

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

6 changes: 6 additions & 0 deletions pkg/upgrade/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func WithSecurityContext(securityContext *corev1.SecurityContext) Option {
}
}

func WithSELinuxOptions(seLinuxoptions *corev1.SELinuxOptions) Option {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this is necessary - you're setting container.SecurityContext.SELinuxOptions, when container.SecurityContext is already set by the WithSecurityContext function. Just set this directly on the SecurityContext.

return func(container *corev1.Container) {
container.SecurityContext.SELinuxOptions = seLinuxoptions
}
}

func WithImagePullPolicy(pullPolicy corev1.PullPolicy) Option {
return func(container *corev1.Container) {
container.ImagePullPolicy = pullPolicy
Expand Down
29 changes: 21 additions & 8 deletions pkg/upgrade/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,31 @@ func New(plan *upgradeapiv1.Plan, node *corev1.Node, controllerName string) *bat
)
}

// Check if SecurityContext from the Plan is non-nil
securityContext := &corev1.SecurityContext{
Privileged: &Privileged,
Capabilities: &corev1.Capabilities{
Add: []corev1.Capability{
corev1.Capability("CAP_SYS_BOOT"),
},
},
}
if plan.Spec.Upgrade.SecurityContext != nil {
securityContext = plan.Spec.Upgrade.SecurityContext
}
brandond marked this conversation as resolved.
Show resolved Hide resolved

// Check if SELinuxOptions from the Plan is non-nil
seLinuxOptions := &corev1.SELinuxOptions{}
if plan.Spec.Upgrade.SELinuxOptions != nil {
seLinuxOptions = plan.Spec.Upgrade.SELinuxOptions
}
brandond marked this conversation as resolved.
Show resolved Hide resolved

// and finally, we upgrade
podTemplate.Spec.Containers = []corev1.Container{
upgradectr.New("upgrade", *plan.Spec.Upgrade,
upgradectr.WithLatestTag(plan.Status.LatestVersion),
upgradectr.WithSecurityContext(&corev1.SecurityContext{
Privileged: &Privileged,
Capabilities: &corev1.Capabilities{
Add: []corev1.Capability{
corev1.Capability("CAP_SYS_BOOT"),
},
},
}),
upgradectr.WithSecurityContext(securityContext),
upgradectr.WithSELinuxOptions(seLinuxOptions),
brandond marked this conversation as resolved.
Show resolved Hide resolved
upgradectr.WithSecrets(plan.Spec.Secrets),
upgradectr.WithPlanEnvironment(plan.Name, plan.Status),
upgradectr.WithImagePullPolicy(ImagePullPolicy),
Expand Down