Search code examples
emailgoogle-cloud-platformsmtpairflowgoogle-cloud-composer

GCP command to retrieve an SMTP Password for airflow


I've followed kaxil answer in How to set up Airflow Send Email? to setup airflow, however gcp doesn't allow to set:

smtp_password = 16_DIGIT_APP_PASSWORD 

explicity inside cloud composer. I checked on google documentation https://cloud.google.com/composer/docs/configure-email#smtp_password and found out that there is a way to set it by Using a command to retrieve an SMTP password.

  • smtp_password_cmd does not appear as a key in https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html?highlight=smtp_password_cmd#smtp-password but as an environment variable, therefore is it possibile to do as suggested by the google documentation and set smtp smtp_password_cmd Specify a command that returns the SMTP password. ?
  • i'm absolutely clueless on how to create a command and what to pass as an argument in Specify a command that returns the SMTP password, if for example my smtp password is : dummypassword1 could someone provide an example of such command and how to set it inside the config?

Solution

  • There is an better way to do this than smtp_passwd_cmd:

    This is better explained here: https://cloud.google.com/composer/docs/composer-2/configure-email#using_a_secret_stored_in_to_retrieve_an_smtp_password

    This way everything is just configuration.

    Using Google Cloud Secret Manager for this purpose falls in the free tier for the service (see Secret Manager pricing)