Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Airflow encrypted variables

After updating Airflow to 1.9 all variables are created as encrypted.

Is it possible to disable encryption ?

like image 612
Alexander Ershov Avatar asked Mar 02 '18 17:03

Alexander Ershov


People also ask

Are Airflow variables secure?

Securing VariablesAirflow uses Fernet to encrypt variables stored in the metastore database. It guarantees that without the encryption password, content cannot be manipulated or read without the key.

Are Airflow variables case sensitive?

For the Airflow Variables section, Airflow will automatically hide any values if the variable name contains secret or password . The check for this value is case-insensitive, so the value of a variable with a name containing SECRET will also be hidden.

What environment variable must be set before Airflow is run?

The universal order of precedence for all configuration options is as follows: set as an environment variable ( AIRFLOW__DATABASE__SQL_ALCHEMY_CONN ) set as a command environment variable ( AIRFLOW__DATABASE__SQL_ALCHEMY_CONN_CMD ) set as a secret environment variable ( AIRFLOW__DATABASE__SQL_ALCHEMY_CONN_SECRET )


1 Answers

1-The Croods way....

 from airflow.models import get_fernet
    from airflow.models import Variable
    var_to_decryp = Variable.get("var_name",deserialize_json=True)
    fernet = get_fernet()
    decryp_value = fernet.decrypt(bytes(var_to_decryp, 'utf-8')).decode()

2-The right way will be using get_val() from Variable model:

def get_val(self):
    log = LoggingMixin().log
    if self._val and self.is_encrypted:
        try:
            fernet = get_fernet()
            return fernet.decrypt(bytes(self._val, 'utf-8')).decode()
        except InvalidFernetToken:
            log.error("Can't decrypt _val for key={}, invalid token "
                      "or value".format(self.key))
            return None
        except Exception:
            log.error("Can't decrypt _val for key={}, FERNET_KEY "
                      "configuration missing".format(self.key))
            return None
    else:
        return self._val

but i don't know how ,that is home work.

like image 85
Armando Jose Serrano Escalona Avatar answered Oct 02 '22 07:10

Armando Jose Serrano Escalona