to be more accurate, containers run using the default USER that has been defined in the image. This often defaults to root, but is not always root
You’re right, not always root. What I meant was that, currently one can’t change the default user .
note that both the docker and kubernetes runtimes support the user parameter which can be used to override the default container user
Although user option is available in the step definition, it’s not taking effect. I have looked into the https://github.com/drone-runners/drone-runner-kube/blob/master/engine/convert.go#L160, and only privileged is passed to the pod spec:
SecurityContext: &v1.SecurityContext{
Privileged: boolptr(s.Privileged),
},
The runAsUser and runAsGroup, which change the default user and group, are not passed to pod spec.
Plus, the user field is of type string. However, in the k8s Pod Spec https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/core/types.go#L2850, the user and group are represented in integers (UID,GID):
// The UID to run the entrypoint of the container process.
// Defaults to user specified in image metadata if unspecified.
// May also be set in SecurityContext. If set in both SecurityContext and
// PodSecurityContext, the value specified in SecurityContext takes precedence
// for that container.
// +optional
RunAsUser *int64
// The GID to run the entrypoint of the container process.
// Uses runtime default if unset.
// May also be set in SecurityContext. If set in both SecurityContext and
// PodSecurityContext, the value specified in SecurityContext takes precedence
// for that container.
// +optional
RunAsGroup *int64
So I suggest we remove the user field, and replace it with runAsUser and runAsGroup. The reason for this is not to confuse it with docker pipeline options, and keep the semantics of the underlying engine.
Regarding volumes, k8s does not use docker volume API, but rather uses its own API. And kube-runner uses EmptyDir volume type to contain the common workspace. And k8s sets the permissions 777 (RWX for all) on the created directory, you can check here https://github.com/kubernetes/kubernetes/blob/release-1.18/pkg/volume/emptydir/empty_dir.go#L43
So any container can read/write into the dir. Now when it comes to reading files created by a prev container, in most linux distros the default permission is 644 for newly created files, thus the other users can read.