Replies: 1 comment 5 replies
-
|
Here is a possible solution, which may work on the server with access to the airflow config from airflow.api_fastapi.auth.tokens import JWTGenerator, get_signing_args
from airflow.configuration import conf
# Generate a JWT token for the public REST API
generator = JWTGenerator(
**get_signing_args(), # Uses the same jwt_secret or private_key as the API server
valid_for=conf.getint("api_auth", "jwt_expiration_time"),
audience=conf.get("api", "jwt_audience", fallback="apache-airflow"),
)
# The token needs 'sub' (username) and 'role' claims for SimpleAuthManager
token = generator.generate(extras={"sub": "internal_service", "role": "ADMIN"})
# Now use with any HTTP client
import httpx
client = httpx.Client(
base_url=conf.get("api", "base_url", fallback="http://localhost:8080"),
headers={"Authorization": f"Bearer {token}"}
)
# Update a pool
response = client.patch("/api/v2/pools/my_pool", json={"slots": 10}) |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Let's imagine i want to call
Pool.create_or_update_poolin my DAG. This no longer works in Airflow 3 due to no direct DB access. So instead I'd like to interact with the API via REST using the python client orairflow-ctl. But inside my DAG/plugin, I don't have a username / password or anything with which to interact with the API server. E.g. if the code is running inside my dag processor process, it really shouldn't need to authenticate as some random user. The scheduler and workers also presumably need to interact with the api server as well, is there some method to get API access when the code itself is running as part of a "trusted" process (e.g. in the dag processor, scheduler, worker, etc)?It seems like the local client was working in this direction, but this just invokes the same Pool code that relies on direct DB access under the hood.
Beta Was this translation helpful? Give feedback.
All reactions