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

✨ Run task pod as AnyUser. #755

Merged
merged 1 commit into from
Oct 10, 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
13 changes: 10 additions & 3 deletions settings/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import (
)

const (
EnvHubBaseURL = "HUB_BASE_URL"
EnvHubToken = "TOKEN"
EnvTask = "TASK"
EnvHubBaseURL = "HUB_BASE_URL"
EnvHubToken = "TOKEN"
EnvTask = "TASK"
EnvAddonHomeDir = "ADDON_HOME"
)

// Addon settings.
type Addon struct {
// HomeDir working directory.
HomeDir string
// Hub settings.
Hub struct {
// URL for the hub API.
Expand All @@ -27,6 +30,10 @@ type Addon struct {

func (r *Addon) Load() (err error) {
var found bool
r.HomeDir, found = os.LookupEnv(EnvAddonHomeDir)
if !found {
r.HomeDir = "/addon"
}
r.Hub.URL, found = os.LookupEnv(EnvHubBaseURL)
if !found {
r.Hub.URL = "http://localhost:8080"
Expand Down
20 changes: 16 additions & 4 deletions task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const (
)

const (
Addon = "addon"
Shared = "shared"
Cache = "cache"
)
Expand Down Expand Up @@ -1643,6 +1644,12 @@ func (r *Task) specification(
addon *crd.Addon,
extensions []crd.Extension,
secret *core.Secret) (specification core.PodSpec) {
addonDir := core.Volume{
Name: Addon,
VolumeSource: core.VolumeSource{
EmptyDir: &core.EmptyDirVolumeSource{},
},
}
shared := core.Volume{
Name: Shared,
VolumeSource: core.VolumeSource{
Expand Down Expand Up @@ -1670,6 +1677,7 @@ func (r *Task) specification(
InitContainers: init,
Containers: plain,
Volumes: []core.Volume{
addonDir,
shared,
cache,
},
Expand All @@ -1683,7 +1691,6 @@ func (r *Task) containers(
addon *crd.Addon,
extensions []crd.Extension,
secret *core.Secret) (init []core.Container, plain []core.Container) {
userid := int64(0)
token := &core.EnvVarSource{
SecretKeyRef: &core.SecretKeySelector{
Key: settings.EnvHubToken,
Expand All @@ -1707,11 +1714,12 @@ func (r *Task) containers(
container := &plain[i]
injector.Inject(container)
r.propagateEnv(&plain[0], container)
container.SecurityContext = &core.SecurityContext{
RunAsUser: &userid,
}
container.VolumeMounts = append(
container.VolumeMounts,
core.VolumeMount{
Name: Addon,
MountPath: Settings.Addon.HomeDir,
},
core.VolumeMount{
Name: Shared,
MountPath: Settings.Shared.Path,
Expand All @@ -1722,6 +1730,10 @@ func (r *Task) containers(
})
container.Env = append(
container.Env,
core.EnvVar{
Name: settings.EnvAddonHomeDir,
Value: Settings.Addon.HomeDir,
},
core.EnvVar{
Name: settings.EnvSharedPath,
Value: Settings.Shared.Path,
Expand Down
Loading