Skip to content

Run SF git pull as ec2-user to avoid dubious ownership error#21

Merged
cipher813 merged 1 commit into
mainfrom
fix/step-function-sudo-git-as-ec2-user
Apr 12, 2026
Merged

Run SF git pull as ec2-user to avoid dubious ownership error#21
cipher813 merged 1 commit into
mainfrom
fix/step-function-sudo-git-as-ec2-user

Conversation

@cipher813
Copy link
Copy Markdown
Owner

Summary

Wrap every `git pull --ff-only origin main` in the Saturday Step Function with `sudo -u ec2-user git -C ` so git runs as the repo owner and doesn't hit the 2.35.2+ safe.directory check.

Context

#20 added `git pull` to every SSM command to auto-pull fresh code before running. When the pipeline kicked off (full-rerun-20260411T211223Z) DataPhase1 failed immediately with:

```
fatal: detected dubious ownership in repository at '/home/ec2-user/alpha-engine-data'
failed to run commands: exit status 128
```

SSM runs as root, but the /home/ec2-user/alpha-engine-* repos are owned by ec2-user. Git refuses by default.

Silver lining: the Step Function's CheckDataPhase1Status gate routed correctly to HandleFailure → FailExecution → SNS, and the SNS email surfaced the real error immediately — proving #20's hard-fail + exit-propagation fix works end-to-end.

Fix

`sudo -u ec2-user git -C /path/to/repo pull --ff-only origin main`

All six SSM commands updated consistently. Verified the pattern on a standalone SSM probe before pushing — the probe successfully pulled 292e51e0a3a90b.

Live deployment

Applied directly to the live state machine via `aws stepfunctions update-state-machine` (revision `8acf52b1`). This PR is the repo-side record.

Test plan

  • JSON validates
  • Standalone SSM probe confirms `sudo -u ec2-user git -C /path pull` works
  • Live state machine updated
  • Fresh execution kicks off cleanly
  • DataPhase1 completes its git pull as ec2-user and runs the latest weekly_collector.py

🤖 Generated with Claude Code

PR #20 added `git pull --ff-only origin main` to every SSM command in
the Saturday Step Function. When executed, every command failed with:

    fatal: detected dubious ownership in repository at
    '/home/ec2-user/alpha-engine-data'
    failed to run commands: exit status 128

Cause: SSM RunShellScript runs as root on Amazon Linux, but the four
repo checkouts are owned by ec2-user. Git's >=2.35.2 safe.directory
check refuses to operate on repos owned by a different user unless
explicitly allowed.

Fix: run the git pull as ec2-user via
`sudo -u ec2-user git -C /path pull --ff-only origin main`.
`git -C <path>` avoids the pwd-across-sudo subshell issue. The rest
of each command (cd, source, Python/bash) continues to run as root
as before — no behavior change for non-git steps.

All six SSM commands updated consistently:
- DataPhase1, RAGIngestion, HealthCheck (alpha-engine-data)
- PredictorTraining (alpha-engine-predictor)
- DriftDetection (alpha-engine-data + alpha-engine-predictor)
- Backtester (alpha-engine-backtester)

Verified working via a standalone SSM probe before pushing this PR —
`sudo -u ec2-user git -C /home/ec2-user/alpha-engine-data pull` ran
cleanly and advanced the EC2 checkout from 292e51e to 0a3a90b.

## Live deployment
Applied directly to the live state machine. This PR is the
repo-side record.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cipher813 cipher813 merged commit d5985b7 into main Apr 12, 2026
1 check passed
@cipher813 cipher813 deleted the fix/step-function-sudo-git-as-ec2-user branch April 12, 2026 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant