Skip to content

Commit 98c598e

Browse files
committed
chore(controller): add pod default security
1 parent c29f4f8 commit 98c598e

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

rootfs/api/models/app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,11 +1126,12 @@ def _gather_app_settings(self, release, app_settings, process_type, replicas, vo
11261126
"name": _.name,
11271127
"claimName": _.name,
11281128
} for _ in volumes] if volumes else []
1129-
1129+
volumes_info.extend(json.loads(settings.KUBERNETES_POD_DEFAULT_VOLUMES))
11301130
volume_mounts_info = [{
11311131
"name": _.name,
11321132
"mount_path": _.path.get(process_type),
11331133
} for _ in volumes] if volumes else []
1134+
volume_mounts_info.extend(json.loads(settings.KUBERNETES_POD_DEFAULT_VOLUME_MOUNTS))
11341135

11351136
return {
11361137
'memory': memory,
@@ -1161,4 +1162,5 @@ def _gather_app_settings(self, release, app_settings, process_type, replicas, vo
11611162
'image_pull_policy': image_pull_policy,
11621163
'volumes': volumes_info,
11631164
'volume_mounts': volume_mounts_info,
1165+
'security_context': json.loads(settings.KUBERNETES_POD_DEFAULT_SECURITY_CONTEXT),
11641166
}

rootfs/api/settings/production.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,22 @@
364364
KUBERNETES_LIMITS_MIN_VOLUME = int(os.environ.get('KUBERNETES_LIMITS_MIN_VOLUME', 1))
365365
# Max Stroage Volume limit, units are represented in Gigabytes(G)
366366
KUBERNETES_LIMITS_MAX_VOLUME = int(os.environ.get('KUBERNETES_LIMITS_MAX_VOLUME', 1024 * 16))
367+
# Default pod spec volumes for application.
368+
KUBERNETES_POD_DEFAULT_VOLUMES = os.environ.get('KUBERNETES_POD_DEFAULT_VOLUMES', '[]')
369+
# Default pod spec volume mounts for application.
370+
KUBERNETES_POD_DEFAULT_VOLUME_MOUNTS = os.environ.get('KUBERNETES_POD_DEFAULT_VOLUME_MOUNTS', '[]')
371+
# Default pod spec security context for application.
372+
KUBERNETES_POD_DEFAULT_SECURITY_CONTEXT = os.environ.get(
373+
'KUBERNETES_POD_DEFAULT_SECURITY_CONTEXT',
374+
json.dumps({
375+
'capabilities': {
376+
'add': ['SYS_ADMIN']
377+
},
378+
'allowPrivilegeEscalation': True,
379+
})
380+
)
367381

368-
# Default pod spec for application.
382+
# Default pod spec resources for application.
369383
KUBERNETES_POD_DEFAULT_RESOURCES = os.environ.get(
370384
'KUBERNETES_POD_DEFAULT_RESOURCES',
371385
json.dumps({

rootfs/scheduler/resources/pod.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ def _set_container(self, namespace, container_name, data, **kwargs):
213213
data['imagePullPolicy'] = kwargs.get('image_pull_policy')
214214
# add in any volumes that need to be mounted into the container
215215
data['volumeMounts'] = kwargs.get('volumeMounts', [])
216-
216+
# set the security context to use
217+
data["securityContext"] = kwargs.get('security_context', {})
217218
# create env list if missing
218219
if 'env' not in data:
219220
data['env'] = []

0 commit comments

Comments
 (0)