Skip to content

Fix SSHRemoteJobOperator cleanup failing with custom remote_base_dir#69885

Open
harshhh817 wants to merge 1 commit into
apache:mainfrom
harshhh817:fix-ssh-remote-job-custom-base-dir
Open

Fix SSHRemoteJobOperator cleanup failing with custom remote_base_dir#69885
harshhh817 wants to merge 1 commit into
apache:mainfrom
harshhh817:fix-ssh-remote-job-custom-base-dir

Conversation

@harshhh817

Copy link
Copy Markdown

Fixes SSHRemoteJobOperator failing at the cleanup step whenever a custom remote_base_dir is used.

The operator accepts (and validates) a custom remote_base_dir at construction time and creates the job directory under it, but build_posix_cleanup_command / build_windows_cleanup_command validated the job directory against the hardcoded default base directory. Result: the remote job runs to completion, then the task fails with

Invalid job directory: '/tmp-data/airflow-ssh-jobs/af_…'. Expected path under '/tmp/airflow-ssh-jobs' for safety.

Fix: thread the operator's configured remote_base_dir through the cleanup builders into _validate_job_dir, falling back to the OS-specific default when unset. The safety property is preserved — the rm -rf target must still live under the base directory the job was actually created under (which was itself validated by _validate_base_dir at operator construction). Both the sync and deferrable (execute_complete) cleanup paths go through the fixed _cleanup_remote_job.

Tests: new unit tests for custom-base-dir acceptance and rejection (posix + windows), plus an operator-level regression test reproducing the exact failure from the issue — verified it fails on main and passes with this change. Full ssh provider unit suite: 49 passed.

closes: #69813


Was generative AI tooling used to co-author this PR?
  • Yes (Claude Code)

Generated-by: Claude Code following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

The cleanup command builders validated the job directory against the
hardcoded default base directory, so any job started with a custom
remote_base_dir ran to completion and then failed its cleanup step with
"Invalid job directory ... Expected path under '/tmp/airflow-ssh-jobs'".

Thread the operator's configured remote_base_dir through
build_posix_cleanup_command / build_windows_cleanup_command into
_validate_job_dir, falling back to the OS default when unset, so the
safety check still constrains the rm target to the directory the job was
actually created under.

Signed-off-by: Harsh Gupta <harshgupta93198@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSHRemoteJobOperator: inconsistent "remote_base_dir" validation

1 participant