-
Notifications
You must be signed in to change notification settings - Fork 16.3k
feat(fab): add configurable rate limiter storage options #58293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -245,6 +245,26 @@ config: | |
| type: integer | ||
| example: ~ | ||
| default: "1" | ||
| auth_rate_limit_storage_uri: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’d clarify in the description that only the Redis and Redis Cluster backends are supported. flask_limiter[redis]>3,<4,!=3.13It might also be helpful to include examples of both supported backends, e.g.: |
||
| description: | | ||
| Storage backend for rate limit data. The default backend is in-memory storage. | ||
| When specifying a storage URI, only Redis and Redis Cluster backends are supported. | ||
| Examples: ``redis://localhost:6379`` or ``redis+cluster://redis0:6379,redis1:6379``. | ||
| See `Flask-Limiter Storage Options | ||
| <https://flask-limiter.readthedocs.io/en/stable/#storage-backends>`__ for more details. | ||
| version_added: 3.0.1 | ||
| type: string | ||
| example: ~ | ||
| default: "memory://" | ||
| auth_rate_limit_storage_options: | ||
| description: | | ||
| Storage options for rate limit data storage backend. | ||
| See `Flask-Limiter Storage Options | ||
| <https://flask-limiter.readthedocs.io/en/stable/#storage-backends>`__ for more details. | ||
| version_added: 3.0.1 | ||
| type: string | ||
| example: ~ | ||
| default: null | ||
|
|
||
| auth-managers: | ||
| - airflow.providers.fab.auth_manager.fab_auth_manager.FabAuthManager | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # 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. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from airflow.providers.fab.www.app import create_app | ||
|
|
||
| from tests_common.test_utils.config import conf_vars | ||
|
|
||
|
|
||
| class TestFabAppRateLimitConfig: | ||
| @conf_vars({}) | ||
| def test_rate_limit_config_defaults(self): | ||
| flask_app = create_app(enable_plugins=False) | ||
| assert flask_app.config["AUTH_RATE_LIMIT_STORAGE_URI"] == "memory://" | ||
| assert flask_app.config["AUTH_RATE_LIMIT_STORAGE_OPTIONS"] == {} | ||
|
|
||
| @conf_vars( | ||
| { | ||
| ("fab", "auth_rate_limit_storage_uri"): "redis://my-redis-host:6379/1", | ||
| ("fab", "auth_rate_limit_storage_options"): '{"socket_timeout": 10}', | ||
| } | ||
| ) | ||
| def test_rate_limit_config_custom_redis(self): | ||
| flask_app = create_app(enable_plugins=False) | ||
|
|
||
| assert flask_app.config["AUTH_RATE_LIMIT_STORAGE_URI"] == "redis://my-redis-host:6379/1" | ||
| expected_options = {"socket_timeout": 10} | ||
| assert flask_app.config["AUTH_RATE_LIMIT_STORAGE_OPTIONS"] == expected_options | ||
|
|
||
| @conf_vars( | ||
| { | ||
| ("fab", "auth_rate_limit_storage_options"): '{"invalid_json": "missing_quote', | ||
| } | ||
| ) | ||
| def test_rate_limit_config_bad_json(self): | ||
| flask_app = create_app(enable_plugins=False) | ||
|
|
||
| assert flask_app.config["AUTH_RATE_LIMIT_STORAGE_OPTIONS"] == {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| cc109e95a25c1bb018a85a6a40859234398d5a9ac5bf317197eed3e3ece64b0d | ||
| a2b04310801a9738df361eb5396108b83680d48a6b611bef80121d43b615bbb0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should update the documentation of the provider (
providers/fab/docs/auth-manager/security.rst,Rate limitingsection) to reflect this change.