Skip to content

Commit 5573752

Browse files
authored
Merge pull request #66 from cdapio/feature/CDAP-18024-Pod-Privilege-Reduction
[CDAP-18024] Add Support for Running as Non-Root User in Kubernetes
2 parents de3fe9c + 453a056 commit 5573752

22 files changed

+821
-37
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@ You can also build a docker image containing the CDAP controller and deploy it t
6161
### Using CDAP operator to manage CDAP instances in Kubernetes
6262

6363
A step by step guide of running CDAP in Kubernetes using CDAP operator can be found in the [blog post](https://link.medium.com/hpPbiUYT9X).
64+
65+
### Running Unit Tests
66+
67+
1. Install [kubebuilder](https://book-v1.book.kubebuilder.io/quick_start.html).
68+
69+
2. Run `make test`

api/v1alpha1/cdapmaster_types.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ type CDAPMasterSpec struct {
8686
// To disable this service: either omit or set the field to nil
8787
// To enable this service: set it to a pointer to a AuthenticationSpec struct (can be an empty struct)
8888
Authentication *AuthenticationSpec `json:"authentication,omitempty"`
89+
// SecurityContext defines the security context for all pods for all services.
90+
SecurityContext *SecurityContext `json:"securityContext,omitempty"`
8991
}
9092

9193
// CDAPServiceSpec defines the base set of specifications applicable to all master services.
@@ -115,6 +117,8 @@ type CDAPServiceSpec struct {
115117
// Key is the secret object name. Value is the mount path.
116118
// This adds Secret data to the directory specified by the volume mount path.
117119
SecretVolumes map[string]string `json:"secretVolumes,omitempty"`
120+
// SecurityContext overrides the security context for the service pods.
121+
SecurityContext *SecurityContext `json:"securityContext,omitempty"`
118122
}
119123

120124
// CDAPScalableServiceSpec defines the base specification for master services that can have more than one instance.
@@ -230,6 +234,32 @@ type CDAPMasterList struct {
230234
Items []CDAPMaster `json:"items"`
231235
}
232236

237+
// SecurityContext defines fields for setting corev1.SecurityContext for containers and
238+
// corev1.PodSecurityContext for pods.
239+
// For additional information, see https://kubernetes.io/docs/tasks/configure-pod-container/security-context/.
240+
type SecurityContext struct {
241+
// RunAsUser runs the pod as the specified user ID. It is applied at the pod level.
242+
RunAsUser *int64 `json:"runAsUser,omitempty"`
243+
// RunAsGroup runs the pod as the specified group ID. It is applied at the pod level.
244+
RunAsGroup *int64 `json:"runAsGroup,omitempty"`
245+
// FSGroup mounts volumes as the specified group ID and gives the primary user access
246+
// to that group. It is applied at the pod level.
247+
FSGroup *int64 `json:"fsGroup,omitempty"`
248+
// AllowPrivilegeEscalation prevents the container process from running SUID binaries.
249+
// It is applied at the container level.
250+
AllowPrivilegeEscalation *bool `json:"allowPrivilegeEscalation,omitempty"`
251+
// RunAsNonRoot indicates that the container must run as a non-root user.
252+
// If true, the Kubelet will validate the image at runtime to ensure that it
253+
// does not run as UID 0 (root) and fail to start the container if it does.
254+
RunAsNonRoot *bool `json:"runAsNonRoot,omitempty"`
255+
// Privileged runs container in privileged mode. It is applied at the container level.
256+
// Processes in privileged containers are essentially equivalent to root on the host.
257+
Privileged *bool `json:"privileged,omitempty"`
258+
// ReadOnlyRootFilesystem specifies whether the container's root filesystem is read-only.
259+
// It is applied at the container level.
260+
ReadOnlyRootFilesystem *bool `json:"readOnlyRootFilesystem,omitempty"`
261+
}
262+
233263
func init() {
234264
SchemeBuilder.Register(&CDAPMaster{}, &CDAPMasterList{})
235265
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)