add: container securityContext not available in podSecurityContext - #24588
add: container securityContext not available in podSecurityContext#24588ChrisFraun wants to merge 3070 commits into
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
|
|
I'd say that better action would really be to have two separate contexts and maybe simply - rather than adding "containerSecurityContext", introduce Something like: I think that would be much more versatile and rather easy to use configure (more detailed values could be merged into the defaults). |
|
Updated the change, can you check it? |
|
is the change how you imagined it @potiuk ? |
|
Yep it looks good :). I am not sure if there is an easy way to "warn" if you use the deprecated configuration (I think this is the only change that I would like to see here) - and of course some tests would be useful. @jedcunningham @dstandish - WDYT? |
|
Deprecation warnings happen in NOTES, e.g: airflow/chart/templates/NOTES.txt Lines 160 to 166 in 178af9d This should be expanded to cover all of the components as well. I'd also like to see the component specific override come from the components config section, e.g. |
|
Hi, sorry for the late reply!
Tested with |
|
still some static checks are failing, |
|
Hi @potiuk can you maybe point me into a direction on why the checks are not running through? - I don't see the problem so far. |
jedcunningham
left a comment
There was a problem hiding this comment.
Probably worth adding some test coverage to make sure the old deprecated options still work.
| allowPrivilegeEscalation: false | ||
| capabilities: | ||
| drop: | ||
| - ALL |
There was a problem hiding this comment.
This is the default, yeah? Not sure we need to expand it here.
There was a problem hiding this comment.
I removed it from here and put it in the helper:
{{/*
Set the default value for container securityContext
If no value is passed for securityContext.container or .securityContext.container, defaults to deny privileges escallation and dropping all POSIX capabilities.
+------------------------+ +-----------------+ +-------------------------+
| <node>.securityContext.container | -> | securityContext.container | -> | allowPrivilegesEscalation: false, capabilities.drop: [ALL]|
+------------------------+ +-----------------+ +-------------------------+
The template can be called like so:
include "airflowSecurityContextContainer" (list . .Values.webserver)
Where . is the global variables scope and .Values.webserver the local variables scope for the webserver template.
*/}}
{{- define "airflowSecurityContextContainer" -}}
{{- $ := index . 0 -}}
{{- with index . 1 }}
{{- if .securityContext.container -}}
{{ toYaml .securityContext.container | print }}
{{- else if $.Values.securityContext.container -}}
{{ toYaml $.Values.securityContext.container | print }}
{{- else -}}
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
{{- end -}}
{{- end -}}
{{- end -}}
There was a problem hiding this comment.
Sorry, should have been more clear. Isn't that the default kubernetes sets if you provide nothing? If so, I'd rather we not set it at all.
There was a problem hiding this comment.
I think you have to set them yourself, they are not automatically set.
There was a problem hiding this comment.
Sorry for the delay, coming back to this now.
I had this backwards - this removes rights. While I agree this is a good sane default, we can't make this change in a minor release without breaking backward compatibility. Given that, I think for now we should keep the default as nothing.
|
Hi @jedcunningham thanks a lot for the input! I tried to stick to your comments, but feel free to add some more :) |
| Set the default value for securityContext | ||
| If no value is passed for securityContext or <node>.securityContext, defaults to global uid and gid. | ||
| Set the default value for pod securityContext | ||
| If no value is passed for securityContext.pod or <node>.securityContext.pod, defaults to global uid and gid. |
There was a problem hiding this comment.
I think we want this order of precedence:
<node>.securityContexts.pod
<node>.securityContext
securityContexts.pod
securityContext (backcompat for deprecated config)
uid/gid
So I think this template still needs a little work, right? Also feel free to rename this airflowPodSecurityContext to make it more clear.
There was a problem hiding this comment.
You are right, I tried to adapt to your suggestion and renamed also the template.
Btw airflowSecurityContextIds was not used anywhere so the renamed version airflowPodSecurityContextsIds can probably be deleted.
Hope I got it right this time.
There was a problem hiding this comment.
Hi, I think airflowSecurityContextIds is used on workers-deployment to set the uid and gid during a chown. Not sure if has changed.
|
Hi, I am still getting this error during the images build: |
Rebase please. GitHub seemed to have a rough day. |
|
|
||
| Where `.` is the global variables scope and `.Values.webserver` the local variables scope for the webserver template. | ||
| */}} | ||
| {{- define "airflowContainerSecurityContext" -}} |
There was a problem hiding this comment.
I wonder if we should call this containerSecurityContext instead, since it's used for more than just Airflow containers?
There was a problem hiding this comment.
Wait, this isn't even used? Let's drop it?
There was a problem hiding this comment.
I added it to the charts
|
Conflict to solve :( |
|
Tried to add the changes demanded in #25985 |
jedcunningham
left a comment
There was a problem hiding this comment.
I suspect there are more of this scenario than just the 2 below:
|
Thanks @ChrisFraun for reconciling our 2 PRs into one (#25985 and this one). These changes look good to me 👍 |
|
Running the tests now (sorry @ChrisFraun for this all taking so long - just returned from Holidays and trying to catch-up - let's see how this one looks like for tests and I will give it another pass). |
|
errors ? |
malthe
left a comment
There was a problem hiding this comment.
I have tested this out and it works beautifully!
…apache#29913) * Add a failing test to make it pass * use partial_kwargs when they are provide and override only None values by dag default values * update the test and check if the values are filled in the right order * fix overriding retry_delay with default value when it is equal to 0 * add missing default value for inlets and outlets * set partial_kwargs dict type to dict[str, Any] and remove type ignore comments * create a dict for default values and use NotSet instead of None to support None as accepted value * update partial typing by removing None type from some args and set NotSet for all args * Tweak kwarg merging slightly This should improve iteration a bit, I think. * Fix unit tests --------- Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
This PR consistent mostly of code that was created in OpenLineage project. It consists of - Provider wiring - OpenLineageListener that uses Listener API to get notification about changes to TaskInstance and Dag states - Extractor framework, which is used to extract lineage information from particular operators. It's ment to be replaced by direct implementation of lineage features in later phase and extracting them using DefaultExtractor. This PR does not include actual extractors, but code around using and registering them. - OpenLineageAdapter that translates extracted information to OpenLineage events. - Utils around specific Airflow OL facets and features This is a base implementation that's not ment to be released yet, but to add code modified to be consistent with Airflow standards, get early feedback and provide canvas to add later features, docs, tests on. Signed-off-by: Jakub Dardzinski <kuba0221@gmail.com>
…pache#29809) * Adding configuration to control retry parameters for k8s api client * Handling review comments * Fixing code bug * Fixing failing tests * Temporary commit with UT wip * Fixing unit test * Fixing the strict checks * Handling review comments from Hussein * Revert "Handling review comments from Hussein" This reverts commit fa3bc26. * Fixing failing ut * Reverting bad hack * Updating logic in kube_client.py Co-authored-by: Hussein Awala <hussein@awala.fr> * Fixing unit tests * Fixing unit tests * Handling review comments from Ash * Fix loading mock call args for python3.7 * Apply suggestions from code review * fix static check * add in 2.6.0 --------- Co-authored-by: Amogh <adesai@cloudera.com> Co-authored-by: Hussein Awala <houssein.awala.96@gmail.com>
* fix(chart): webserver probes timeout and period * Update default values in JSON schema to reflect values.yaml * remove defautl templated values
…ype` (apache#30595) * Add while initilizing * Add while initilizing * Add logic to pick either client_type or resource_type * Add test case * Assert expected path
* update run clear+mark, update task clear * add mark as tasks and include list of affected tasks * Add support for mapped tasks, add shared modal component * Clean up styling, restore warning for past/future tg clear
--------- Co-authored-by: Hussein Awala <hussein@awala.fr> Co-authored-by: Hussein Awala <houssein.awala.96@gmail.com>
…apache#29065) * When clearing task instances try to get associated DAGs from database. This fixes problems when recursively clearing task instances across multiple DAGs: * Task instances in downstream DAGs weren't having their `max_tries` property incremented, which could cause downstream external task sensors in reschedule mode to instantly time out (issue apache#29049). * Task instances in downstream DAGs could have some of their properties overridden by an unrelated task in the upstream DAG if they had the same task ID. * Use session fixture for new `test_clear_task_instances_without_dag_param` test. * Use session fixture for new `test_clear_task_instances_in_multiple_dags` test. --------- Co-authored-by: eladkal <45845474+eladkal@users.noreply.github.com>
--------- Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com> Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com>
--------- Co-authored-by: Josh Fell <48934154+josh-fell@users.noreply.github.com>
Co-authored-by: Mikaël Ducharme <mikaelducharme@gmail.com>
Co-authored-by: Mikaël Ducharme <mikaelducharme@gmail.com>
Co-authored-by: Mikaël Ducharme <mikaelducharme@gmail.com>
…hrisFraun/airflow into feat/adding-container-security-context
|
I messed up :( I was trying to resolve the conflicts locally but did not realise that vscode is adding all the changes in the remote branch... |
|
You likely can revert and/or rewrite history to fix this since this is on your fork. If you can't fix the conflicts, we would need to link this PR in the new one to keep the context. @potiuk thoughts on this? |
|
Create a new PR and make your changes there again. It happens, and has the opportunity to re-review your own code while applying. Closing it for now. |
|
@ChrisFraun did you plan on re-creating a PR? I don't mind doing it if you did not plan on re-creating it. |
|
Feel free to go ahead @mikaeld! 👍 |

This PR is only a small change in the helm chart of Airflow.
What: Deployments can have security settings in their manifest on two levels: pod and container. However, there are some capabilities only configurable in one of the respective levels(https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#securitycontext-v1-core). This PR sets a default configuration for container securityContext, which denies privilege escalation and drops all POSIX capabilities. These are and should be standard settings in the context of Kubernetes. It also adds the possibility of running Airflow in an Kubernetes environment without PSP (to be removed in v1.25 https://kubernetes.io/docs/concepts/security/pod-security-policy/), but with OpenPolicyAgent (a or possibly the PSP substitute) with the same capabilities as a restricted PSP instead.
Why: This missing configuration restricts Airflow from being used with the simple upstream helm chart without modifications/unnecessary maintenance. This especially applies to the restricted policy use in OPA. The specific setting in this PR is not inherited from
podSecurityContext(pod level) insecurityContext(container level).Problem: There is already a
securityContextin the values.yaml, however, this should also be be calledpodSecurityContextsince it's on pod level, but it isn't. To not break backwards compatibility of Airflow, this PR hardcodes the respective capabilities on container level for statsd, scheduler and webserver.The other possibility would be to introduce a
containerSecurityContextin the values.yaml, which is a made up word since it is commonly calledscurityContext.Benefit in either case would be a more secure deployment.
In case of existing issue, reference it using one of the following:
closes: #27612
Could not find any related issue at first sight.
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
Test was a simple
helm lint .on chart level as well as a successful deployment.WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /Users/christophfraundorfer/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /Users/christophfraundorfer/.kube/config
==> Linting .
1 chart(s) linted, 0 chart(s) failed