-
|
I'm trying to setup task logging to our internal S3 Storage Cluster. While I can get it to work by storing the connection in the database, storing the connection information in Vault doesn't seem to be feasible. Version
(Works) Database ApproachNot much to say here, tasks write logs to our local cluster and our webui can retrieve them. > select * from connections;
id | conn_id | conn_type | host | schema | login | password | port | extra | is_encrypted | is_extra_encrypted | description
---+---------+-----------+------+--------+-------+----------+------+------------------------------------------------------------------------------------------+--------------+--------------------+-------------
1 | s3conn | s3 | | | | | | {"host":"http://hostname/", "aws_access_key_id":"id", "aws_secret_access_key": "secret"} | f | f | (Fails) Vault Attempt 1Since Vault allows several key value pairs under an entry I thought the following would simply work. > vault kv get airflow/connections/s3conn
====== Metadata ======
...
====== Data ======
Key Value
--- -----
conn_type s3
extra {"host":"http://hostname/", "aws_access_key_id":"id", "aws_secret_access_key": "secret"}Using the above, the WebUI fails to retrieve a log with the following error. I altered the secret by adding (Fails) Vault Attempt 2After looking at the examples on the official site and the API call airflow.providers.hashicorp.secrets.vault.VaultBackend, I assume the So naturally I tried: > vault kv get airflow/connections/s3conn
====== Metadata ======
...
====== Data ======
Key Value
--- -----
conn_uri http://id:secret@hostname/With this setup the Airflow WebUI doesn't complain about no such Questions
Thanks for any help, we'd love to store our credentials in Vault over the DB (even with encryption setup). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Airflow has its own URI format described here: https://airflow.apache.org/docs/apache-airflow/stable/howto/connection.html#connection-uri-format So, in your case: import json
from airflow.models.connection import Connection
c = Connection(
conn_id='s3conn',
conn_type='s3',
extra=json.dumps({"host":"http://hostname/", "aws_access_key_id":"id", "aws_secret_access_key": "secret"}),
)
c.get_uri()
>>> 's3://?host=http%3A%2F%2Fhostname%2F&aws_access_key_id=id&aws_secret_access_key=secret'So, Try making a URI using the example :) |
Beta Was this translation helpful? Give feedback.
Airflow has its own URI format described here: https://airflow.apache.org/docs/apache-airflow/stable/howto/connection.html#connection-uri-format
So, in your case:
So,
conn_urishould bes3://?host=http%3A%2F%2Fhostname%2F&aws_access_key_id=id&aws_secret_access_key=secretTry making a URI using the example :)