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 3 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.
13 changes: 7 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,13 @@ 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"`
}

type VolumeSpec struct {
Expand Down
5 changes: 5 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.

27 changes: 19 additions & 8 deletions pkg/upgrade/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func New(plan *upgradeapiv1.Plan, node *corev1.Node, controllerName string) *bat
upgradectr.WithPlanEnvironment(plan.Name, plan.Status),
upgradectr.WithImagePullPolicy(ImagePullPolicy),
upgradectr.WithVolumes(plan.Spec.Upgrade.Volumes),
upgradectr.WithSecurityContext(plan.Spec.Upgrade.SecurityContext),
),
)
}
Expand Down Expand Up @@ -319,18 +320,28 @@ 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

if plan.Spec.Upgrade.SecurityContext.SELinuxOptions != nil {
securityContext.SELinuxOptions = plan.Spec.Upgrade.SecurityContext.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.WithSecrets(plan.Spec.Secrets),
upgradectr.WithPlanEnvironment(plan.Name, plan.Status),
upgradectr.WithImagePullPolicy(ImagePullPolicy),
Expand Down