|
27 | 27 | KUBERNETES_NODE_SELECTOR, |
28 | 28 | KUBERNETES_PERSISTENT_VOLUME_CLAIMS, |
29 | 29 | KUBERNETES_PORT, |
| 30 | + KUBERNETES_SECURITY_CONTEXT, |
| 31 | + KUBERNETES_POD_SECURITY_CONTEXT, |
30 | 32 | KUBERNETES_SERVICE_ACCOUNT, |
31 | 33 | KUBERNETES_SHARED_MEMORY, |
32 | 34 | KUBERNETES_TOLERATIONS, |
@@ -136,6 +138,17 @@ class KubernetesDecorator(StepDecorator): |
136 | 138 | - run_as_user: int, optional, default None |
137 | 139 | - run_as_group: int, optional, default None |
138 | 140 | - run_as_non_root: bool, optional, default None |
| 141 | + - read_only_root_filesystem: bool, optional, default None |
| 142 | + - capabilities: Dict[str, List[str]], optional, default None |
| 143 | + Can also be set via METAFLOW_KUBERNETES_SECURITY_CONTEXT (JSON). |
| 144 | + pod_security_context: Dict[str, Any], optional, default None |
| 145 | + Pod-level security context. Applies to all containers in the pod. Allows the following keys: |
| 146 | + - run_as_user: int, optional, default None |
| 147 | + - run_as_group: int, optional, default None |
| 148 | + - run_as_non_root: bool, optional, default None |
| 149 | + - fs_group: int, optional, default None |
| 150 | + - supplemental_groups: List[int], optional, default None |
| 151 | + Can also be set via METAFLOW_KUBERNETES_POD_SECURITY_CONTEXT (JSON). |
139 | 152 | """ |
140 | 153 |
|
141 | 154 | name = "kubernetes" |
@@ -168,6 +181,7 @@ class KubernetesDecorator(StepDecorator): |
168 | 181 | "hostname_resolution_timeout": 10 * 60, |
169 | 182 | "qos": KUBERNETES_QOS, |
170 | 183 | "security_context": None, |
| 184 | + "pod_security_context": None, |
171 | 185 | } |
172 | 186 | package_metadata = None |
173 | 187 | package_url = None |
@@ -310,6 +324,19 @@ def init(self): |
310 | 324 | if not self.attributes["port"]: |
311 | 325 | self.attributes["port"] = KUBERNETES_PORT |
312 | 326 |
|
| 327 | + # Security context: decorator takes precedence over env var |
| 328 | + if not self.attributes["security_context"] and KUBERNETES_SECURITY_CONTEXT: |
| 329 | + self.attributes["security_context"] = json.loads( |
| 330 | + KUBERNETES_SECURITY_CONTEXT |
| 331 | + ) |
| 332 | + if ( |
| 333 | + not self.attributes["pod_security_context"] |
| 334 | + and KUBERNETES_POD_SECURITY_CONTEXT |
| 335 | + ): |
| 336 | + self.attributes["pod_security_context"] = json.loads( |
| 337 | + KUBERNETES_POD_SECURITY_CONTEXT |
| 338 | + ) |
| 339 | + |
313 | 340 | # Refer https://github.com/Netflix/metaflow/blob/master/docs/lifecycle.png |
314 | 341 | def step_init(self, flow, graph, step, decos, environment, flow_datastore, logger): |
315 | 342 | # Executing Kubernetes jobs requires a non-local datastore. |
@@ -500,6 +527,7 @@ def runtime_step_cli( |
500 | 527 | "labels", |
501 | 528 | "annotations", |
502 | 529 | "security_context", |
| 530 | + "pod_security_context", |
503 | 531 | ]: |
504 | 532 | cli_args.command_options[k] = json.dumps(v) |
505 | 533 | else: |
|
0 commit comments