@@ -44,7 +44,48 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
4444
4545COPY . /opt/rslearn_projects/
4646
47- # Set up SSH multi-key support for GitHub Actions (conditional based on build arg)
47+ # ============================================================================
48+ # SSH Multi-Key Configuration for GitHub Actions
49+ # ============================================================================
50+ # This section handles SSH authentication for multiple private GitHub repositories
51+ # when building in CI/CD environments that use separate deploy keys per repository.
52+ #
53+ # CONTEXT:
54+ # - GitHub deploy keys are scoped to a single repository for security
55+ # - We need to clone from multiple repos: rslearn, olmoearth_pretrain, olmoearth_run
56+ # - Each repository has its own deploy key stored as a GitHub Actions secret
57+ #
58+ # THE PROBLEM:
59+ # When SSH tries to connect to github.com with multiple keys in the agent:
60+ # 1. SSH tries the first key
61+ # 2. If it authenticates successfully, SSH stops trying other keys
62+ # 3. If that key lacks access to a specific repo, GitHub returns "Repository not found"
63+ # 4. The connection fails even though other keys in the agent might have access
64+ #
65+ # This happens because SSH authenticates at the HOST level (github.com), not the
66+ # repository level. Once any key authenticates with github.com, SSH considers the
67+ # connection successful and doesn't try other keys.
68+ #
69+ # THE SOLUTION:
70+ # We use SSH host aliases to make SSH think each repository is on a different host:
71+ # - git@github-olmoearth-pretrain:allenai/olmoearth_pretrain.git
72+ # - git@github-olmoearth-run:allenai/olmoearth_run.git
73+ #
74+ # Each alias points to github.com but specifies which SSH key to use via IdentityFile.
75+ # With IdentitiesOnly=yes, SSH only tries the specified key for that alias.
76+ #
77+ # IMPLEMENTATION:
78+ # The GitHub Actions workflow writes deploy keys to .docker-ssh/ and sets
79+ # USE_SSH_KEYS_FROM_BUILD=true. This code then:
80+ # 1. Copies the key files to ~/.ssh/
81+ # 2. Creates SSH config with host aliases mapped to specific keys
82+ # 3. Rewrites requirements*.txt files to use the host aliases
83+ #
84+ # LOCAL DEVELOPMENT:
85+ # Local developers typically have a single SSH key with access to all repositories,
86+ # so this complexity is unnecessary. When USE_SSH_KEYS_FROM_BUILD=false (default),
87+ # this entire setup is skipped and standard SSH agent forwarding is used.
88+
4889ARG USE_SSH_KEYS_FROM_BUILD=false
4990RUN if [ "$USE_SSH_KEYS_FROM_BUILD" = "true" ] && [ -d /opt/rslearn_projects/.docker-ssh ]; then \
5091 echo "Setting up SSH keys from build context..." && \
0 commit comments