I am trying to start a shell script using SSH operator in Apache Airflow with SSH operator defined like this:
task1= SSHOperator(
ssh_conn_id="ssh_dev_conn",
command=t1_ssh,
task_id="task1",
dag=dag
)
Command is defined like this:
t1_ssh = """
sudo su - db_user
echo whoami
/home/scripts/script1.sh
"""
According to user permissions only db_user is allowed to start this script, so I am trying to login with that user and with next command I am trying to run the script but I am getting permission denied error message. Echo whoami is returning different user, not db_user, and conclusion is that SSH operator makes new connection for every command so I need to find out how to login with db_user and then run the script in the next command?
First I want to ask is, is it possible with BashOperator instead SSH operator? But I need to establish SSH connection to ssh_dev_conn...
If BashOperator is not solution, is there any way to log as db_user in Linux which has permission to run scripts, and then run script with other command?
Following one-line is not solution because of administration rules: sudo -u db_user /home/scripts/script1.sh
I need solutions for Airflow and Airflow v2. I found example on Airflow: How to SSH and run BashOperator from a different server but it doesn't include sudo command with other user, and it shows example of simple command which works fine, but not for my example.