You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ashb (via GitHub)" <gi...@apache.org> on 2025/02/21 16:14:44 UTC
[PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
ashb opened a new pull request, #46966:
URL: https://github.com/apache/airflow/pull/46966
I don't know exactly when this got broken, and unforutnaltey it wasn't tested,
but I suspect it might have been around the time we swapped the default config
from a config file to the yaml based values. I.e. a while ago!
To make sure it doesn't get broken I've gone and added some unit tests
And to make my next PR and test easier I have done the same thing with the
`auth_jwt_secret` that we do for fernet_key -- of only set it in the config
file if we're generating that file, not always in memory.
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #46966:
URL: https://github.com/apache/airflow/pull/46966#discussion_r1965798733
##########
airflow/configuration.py:
##########
@@ -1751,7 +1751,6 @@ def load_test_config(self):
with StringIO(unit_test_config) as test_config_file:
self.read_file(test_config_file)
# set fernet key to a random value
- global FERNET_KEY
Review Comment:
This was already set in global on L1745
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #46966:
URL: https://github.com/apache/airflow/pull/46966#discussion_r1965814780
##########
airflow/configuration.py:
##########
@@ -2166,8 +2163,8 @@ def initialize_auth_manager() -> BaseAuthManager:
TEST_PLUGINS_FOLDER = os.path.join(AIRFLOW_HOME, "plugins")
SECRET_KEY = b64encode(os.urandom(16)).decode("utf-8")
-JWT_SECRET_KEY = b64encode(os.urandom(16)).decode("utf-8")
FERNET_KEY = "" # Set only if needed when generating a new file
+JWT_SECRET_KEY = ""
Review Comment:
I agree. Otherwise that could be frustrating for users
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #46966:
URL: https://github.com/apache/airflow/pull/46966#discussion_r1965906937
##########
airflow/configuration.py:
##########
@@ -2166,8 +2163,8 @@ def initialize_auth_manager() -> BaseAuthManager:
TEST_PLUGINS_FOLDER = os.path.join(AIRFLOW_HOME, "plugins")
SECRET_KEY = b64encode(os.urandom(16)).decode("utf-8")
-JWT_SECRET_KEY = b64encode(os.urandom(16)).decode("utf-8")
FERNET_KEY = "" # Set only if needed when generating a new file
+JWT_SECRET_KEY = ""
Review Comment:
Handled in b7fc679ac4
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #46966:
URL: https://github.com/apache/airflow/pull/46966#issuecomment-2690780861
Yes that would work nicely :) Yes sorry I did not mention it but I amusing breeze to develop and that's where I experience the issue
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #46966:
URL: https://github.com/apache/airflow/pull/46966#issuecomment-2685115171
Something I realized with this change. We use the fernet key to encrypt trigger kwargs in the DB. Now we have long running triggers, when you restart your environment the Fernet key is regenerated and thus we receve an exception when trying to deserialize the trigger because the key is not valid. I guess this will not happen in prodution because deployment manager should set the Fernet key but that's something inconvenient for development purposes. I need to reset the DB each time
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on PR #46966:
URL: https://github.com/apache/airflow/pull/46966#issuecomment-2674973548
PTAL @vincbeck and @pierrejeambrun . I do worry about the upgrade path, but the issue of generating the jwt_signing key in memory was causing me issues in my work on updating the JWT signer to support public/private key in another PR.
What do you think?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #46966:
URL: https://github.com/apache/airflow/pull/46966#issuecomment-2690046137
> > Something I realized with this change. We use the fernet key to encrypt trigger kwargs in the DB. Now we have long running triggers, when you restart your environment the Fernet key is regenerated and thus we receve an exception when trying to deserialize the trigger because the key is not valid. I guess this will not happen in prodution because deployment manager should set the Fernet key but that's something inconvenient for development purposes. I need to reset the DB each time
>
> This should have been fine I think - the generation happens when writing out the temp my/sample airflow.cfg file for the first time only, it's not in memory each time airflow starts. Is that file not persisted in how ever you are developing?
I think in breze it's not persisted, but there is nothing preventing to do so. We can add it @vincbeck - if that's what you are referring to - we can create a separate volume for airflow configuration folder (I think currently it's just regular container filesystem - so every time you restart container it's gone). WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #46966:
URL: https://github.com/apache/airflow/pull/46966#discussion_r1965801310
##########
airflow/configuration.py:
##########
@@ -1965,13 +1962,14 @@ def write_default_airflow_configuration_if_needed() -> AirflowConfigParser:
raise FileNotFoundError(msg) from None
log.debug("Create directory %r for Airflow config", config_directory.__fspath__())
config_directory.mkdir(parents=True, exist_ok=True)
- if conf.get("core", "fernet_key", fallback=None) is None:
+ if conf.get("core", "fernet_key", fallback=None) in (None, ""):
# We know that FERNET_KEY is not set, so we can generate it, set as global key
# and also write it to the config file so that same key will be used next time
- global FERNET_KEY
FERNET_KEY = _generate_fernet_key()
- conf.remove_option("core", "fernet_key")
- conf.set("core", "fernet_key", FERNET_KEY)
+ conf.configuration_description["core"]["options"]["fernet_key"]["default"] = FERNET_KEY
Review Comment:
This was the crux of the change -- default values are now read from this dict (which is the loaded version of the loaded config.yml)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #46966:
URL: https://github.com/apache/airflow/pull/46966#discussion_r1965807049
##########
airflow/configuration.py:
##########
@@ -2166,8 +2163,8 @@ def initialize_auth_manager() -> BaseAuthManager:
TEST_PLUGINS_FOLDER = os.path.join(AIRFLOW_HOME, "plugins")
SECRET_KEY = b64encode(os.urandom(16)).decode("utf-8")
-JWT_SECRET_KEY = b64encode(os.urandom(16)).decode("utf-8")
FERNET_KEY = "" # Set only if needed when generating a new file
+JWT_SECRET_KEY = ""
Review Comment:
I think that's a good idea indeed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb merged PR #46966:
URL: https://github.com/apache/airflow/pull/46966
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #46966:
URL: https://github.com/apache/airflow/pull/46966#issuecomment-2691561378
Unitl you run `breeze down` - all the configuration and database data is kept which means that you can easily:
* close and restart breeze without loosin fernet key and jwt_secrets
* also easily clean them up by running `breeze down`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #46966:
URL: https://github.com/apache/airflow/pull/46966#issuecomment-2691558692
there it goes @vincbeck https://github.com/apache/airflow/pull/47228
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #46966:
URL: https://github.com/apache/airflow/pull/46966#issuecomment-2722811082
### Backport failed to create: v2-10-test. View the failure log <a href='https://github.com/apache/airflow/actions/runs/13845716179'> Run details </a>
<table>
<tr>
<th>Status</th>
<th>Branch</th>
<th>Result</th>
</tr>
<tr>
<td>❌</td>
<td>v2-10-test</td>
<td><a href="https://github.com/apache/airflow/commit/106b8726724fa712176dfc17ae192dbf5be83e17"><img src='https://img.shields.io/badge/Commit-106b872-red' alt='Commit Link'></a></td>
</tr>
</table>
You can attempt to backport this manually by running:
```bash
cherry_picker 106b872 v2-10-test
```
This should apply the commit to the v2-10-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.
After you have resolved the conflicts, you can continue the backport process by running:
```bash
cherry_picker --continue
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #46966:
URL: https://github.com/apache/airflow/pull/46966#discussion_r1965799773
##########
airflow/configuration.py:
##########
@@ -1881,7 +1880,7 @@ def get_airflow_config(airflow_home: str) -> str:
def get_all_expansion_variables() -> dict[str, Any]:
- return {k: v for d in [globals(), locals()] for k, v in d.items()}
+ return {k: v for d in [globals(), locals()] for k, v in d.items() if not k.startswith("_")}
Review Comment:
Not _required_, but this made debugging easier - this excludes `__doc__` and `__builtins__` etc.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #46966:
URL: https://github.com/apache/airflow/pull/46966#discussion_r1965802585
##########
airflow/configuration.py:
##########
@@ -2166,8 +2163,8 @@ def initialize_auth_manager() -> BaseAuthManager:
TEST_PLUGINS_FOLDER = os.path.join(AIRFLOW_HOME, "plugins")
SECRET_KEY = b64encode(os.urandom(16)).decode("utf-8")
-JWT_SECRET_KEY = b64encode(os.urandom(16)).decode("utf-8")
FERNET_KEY = "" # Set only if needed when generating a new file
+JWT_SECRET_KEY = ""
Review Comment:
Maybe with this change I should have the JWTSigner create a default value if the config is empty and issue a warning, that would improve the upgrade path.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on PR #46966:
URL: https://github.com/apache/airflow/pull/46966#issuecomment-2689247624
> Something I realized with this change. We use the fernet key to encrypt trigger kwargs in the DB. Now we have long running triggers, when you restart your environment the Fernet key is regenerated and thus we receve an exception when trying to deserialize the trigger because the key is not valid. I guess this will not happen in prodution because deployment manager should set the Fernet key but that's something inconvenient for development purposes. I need to reset the DB each time
This should have been fine I think - the generation happens when writing out the temp my/sample airflow.cfg file for the first time only, it's not in memory each time airflow starts. Is that file not persisted in how ever you are developing?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #46966:
URL: https://github.com/apache/airflow/pull/46966#discussion_r1965907357
##########
airflow/utils/jwt_signer.py:
##########
@@ -24,6 +27,21 @@
from airflow.utils import timezone
+def get_signing_key(section: str, key: str) -> str:
+ from airflow.configuration import conf
+
+ secret_key = conf.get(section, key, fallback="")
+
+ if secret_key == "":
+ logging.getLogger(__name__).warning(
+ "%s/%s` was empty, using a generated one for now. Please set this in your config", section, key
Review Comment:
```suggestion
"`%s/%s` was empty, using a generated one for now. Please set this in your config", section, key
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "ashb (via GitHub)" <gi...@apache.org>.
ashb commented on code in PR #46966:
URL: https://github.com/apache/airflow/pull/46966#discussion_r1965906937
##########
airflow/configuration.py:
##########
@@ -2166,8 +2163,8 @@ def initialize_auth_manager() -> BaseAuthManager:
TEST_PLUGINS_FOLDER = os.path.join(AIRFLOW_HOME, "plugins")
SECRET_KEY = b64encode(os.urandom(16)).decode("utf-8")
-JWT_SECRET_KEY = b64encode(os.urandom(16)).decode("utf-8")
FERNET_KEY = "" # Set only if needed when generating a new file
+JWT_SECRET_KEY = ""
Review Comment:
Handled in f6765761f0
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Ensure that the the generated airflow.cfg contains a random jwt_secret and fernet_key [airflow]
Posted by "jscheffl (via GitHub)" <gi...@apache.org>.
jscheffl commented on PR #46966:
URL: https://github.com/apache/airflow/pull/46966#issuecomment-2722793134
Okay, just saw this PR... because came-down attempting to debug why EdgeWorker in breeze fails since a few days.
In breeze if the secrets are not set (they are not per default) then every process call generates a new token. If you start breeze and run `airflow config list|grep secret_key` you see that there is with every call a new secret being generated.
While I assume this is a good hardening, I think in breeze we need to fix this. Will raise a PR in a moment.
Otherwise, did we consider back-porting to 2.10 branch? If it is security relevant we should bring it there as well?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org