Skip to content

Commit 4ea3afd

Browse files
committed
Add verbose comments on the current setup
1 parent 0a4c178 commit 4ea3afd

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

.github/workflows/build_test.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,25 @@ jobs:
5858
- name: Set up Docker Buildx
5959
uses: docker/setup-buildx-action@v3
6060

61-
# Add deploy keys and clone repositories
61+
# ============================================================================
62+
# SSH Multi-Key Setup for Private Repository Access
63+
# ============================================================================
64+
# The Docker build needs to clone from multiple private GitHub repositories:
65+
# - allenai/rslearn
66+
# - allenai/olmoearth_pretrain
67+
# - allenai/olmoearth_run
68+
#
69+
# PROBLEM: GitHub deploy keys are scoped to a single repository. We need
70+
# separate deploy keys for each repo. However, when SSH connects to github.com
71+
# with multiple keys loaded in the agent, it tries them in order. If the first
72+
# key authenticates successfully but lacks access to a specific repository,
73+
# GitHub returns "Repository not found" and SSH stops trying other keys.
74+
#
75+
# SOLUTION: We use SSH host aliases to route each repository to its specific key.
76+
# webfactory/ssh-agent sets up the SSH agent on the runner, but Docker builds
77+
# run in an isolated container that doesn't have access to the runner's SSH
78+
# config or git URL rewrites. So we must recreate this setup inside the container.
79+
6280
- name: Setup SSH agent with deploy keys
6381
uses: webfactory/[email protected]
6482
with:
@@ -77,6 +95,10 @@ jobs:
7795
echo "=== Git Config URL Rewrites ==="
7896
git config --global --get-regexp 'url\..*\.insteadof' || echo "No git URL rewrites found"
7997
98+
# Write SSH keys to files for use inside Docker container
99+
# The SSH agent runs on the runner but we need actual key files inside the
100+
# Docker container to create SSH config with host aliases. We write the keys
101+
# to .docker-ssh/ which gets copied into the container during build.
80102
- name: Prepare SSH keys for Docker build
81103
run: |
82104
mkdir -p .docker-ssh

Dockerfile

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,48 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
4444

4545
COPY . /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+
4889
ARG USE_SSH_KEYS_FROM_BUILD=false
4990
RUN 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

Comments
 (0)