@@ -241,10 +241,13 @@ DOT_SSH="$DIR/dot_ssh"
241
241
for i in $( seq 1 3) ; do
242
242
mkdir -p " $DOT_SSH /$i "
243
243
ssh-keygen -f " $DOT_SSH /$i /id_test" -P " " > /dev/null
244
+ cp -a " $DOT_SSH /$i /id_test" " $DOT_SSH /$i /id_local" # for outside-of-container use
244
245
mkdir -p " $DOT_SSH /server/$i "
245
246
cat " $DOT_SSH /$i /id_test.pub" > " $DOT_SSH /server/$i /authorized_keys"
246
247
done
247
- chmod -R g+r " $DOT_SSH "
248
+ # Allow files to be read inside containers running as a different UID.
249
+ # Note: this does not include the *.local forms.
250
+ chmod g+r " $DOT_SSH " /* /id_test* " $DOT_SSH " /server/*
248
251
249
252
TEST_TOOLS=" _test_tools"
250
253
SLOW_GIT_FETCH=" $TEST_TOOLS /git_slow_fetch.sh"
@@ -2727,23 +2730,20 @@ function e2e::auth_ssh_wrong_key() {
2727
2730
# Test SSH
2728
2731
# #############################################
2729
2732
function e2e::auth_ssh() {
2730
- echo " $FUNCNAME " > " $REPO /file"
2731
-
2732
2733
# Run a git-over-SSH server. Use key #3 to exercise the multi-key logic.
2733
2734
CTR=$( docker_run \
2734
2735
-v " $DOT_SSH /server/3" :/dot_ssh:ro \
2735
- -v " $REPO " :/src :ro \
2736
+ -v " $REPO " :/git/repo :ro \
2736
2737
e2e/test/sshd)
2737
2738
IP=$( docker_ip " $CTR " )
2738
- git -C " $REPO " commit -qam " $FUNCNAME "
2739
2739
2740
- # First sync
2740
+ # Configure the repo.
2741
2741
echo " $FUNCNAME 1" > " $REPO /file"
2742
2742
git -C " $REPO " commit -qam " $FUNCNAME 1"
2743
2743
2744
2744
GIT_SYNC \
2745
2745
--period=100ms \
2746
- --repo=" test@$IP :/src " \
2746
+ --repo=" test@$IP :/git/repo " \
2747
2747
--root=" $ROOT " \
2748
2748
--link=" link" \
2749
2749
--ssh \
@@ -2752,6 +2752,8 @@ function e2e::auth_ssh() {
2752
2752
--ssh-key-file=" /ssh/secret.3" \
2753
2753
--ssh-known-hosts=false \
2754
2754
&
2755
+
2756
+ # First sync
2755
2757
wait_for_sync " ${MAXWAIT} "
2756
2758
assert_link_exists " $ROOT /link"
2757
2759
assert_file_exists " $ROOT /link/file"
@@ -2776,6 +2778,87 @@ function e2e::auth_ssh() {
2776
2778
assert_metric_eq " ${METRIC_GOOD_SYNC_COUNT} " 3
2777
2779
}
2778
2780
2781
+ # #############################################
2782
+ # Test submodules over SSH with different keys
2783
+ # #############################################
2784
+ function e2e::submodule_sync_over_ssh_different_keys() {
2785
+ # Init nested submodule repo
2786
+ NESTED_SUBMODULE_REPO_NAME=" nested-sub"
2787
+ NESTED_SUBMODULE=" $WORK /$NESTED_SUBMODULE_REPO_NAME "
2788
+ mkdir " $NESTED_SUBMODULE "
2789
+
2790
+ git -C " $NESTED_SUBMODULE " init -q -b " $MAIN_BRANCH "
2791
+ config_repo " $NESTED_SUBMODULE "
2792
+ echo " nested-submodule" > " $NESTED_SUBMODULE /nested-submodule.file"
2793
+ git -C " $NESTED_SUBMODULE " add nested-submodule.file
2794
+ git -C " $NESTED_SUBMODULE " commit -aqm " init nested-submodule.file"
2795
+
2796
+ # Run a git-over-SSH server. Use key #1.
2797
+ CTR_SUBSUB=$( docker_run \
2798
+ -v " $DOT_SSH /server/1" :/dot_ssh:ro \
2799
+ -v " $NESTED_SUBMODULE " :/git/repo:ro \
2800
+ e2e/test/sshd)
2801
+ IP_SUBSUB=$( docker_ip " $CTR_SUBSUB " )
2802
+
2803
+ # Tell local git not to do host checking and to use the test keys.
2804
+ export GIT_SSH_COMMAND=" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i $DOT_SSH /1/id_local -i $DOT_SSH /2/id_local"
2805
+
2806
+ # Init submodule repo
2807
+ SUBMODULE_REPO_NAME=" sub"
2808
+ SUBMODULE=" $WORK /$SUBMODULE_REPO_NAME "
2809
+ mkdir " $SUBMODULE "
2810
+
2811
+ git -C " $SUBMODULE " init -q -b " $MAIN_BRANCH "
2812
+ config_repo " $SUBMODULE "
2813
+ echo " submodule" > " $SUBMODULE /submodule.file"
2814
+ git -C " $SUBMODULE " add submodule.file
2815
+ git -C " $SUBMODULE " commit -aqm " init submodule.file"
2816
+
2817
+ # Add nested submodule to submodule repo
2818
+ git -C " $SUBMODULE " submodule add -q " test@$IP_SUBSUB :/git/repo" " $NESTED_SUBMODULE_REPO_NAME "
2819
+ git -C " $SUBMODULE " commit -aqm " add nested submodule"
2820
+
2821
+ # Run a git-over-SSH server. Use key #2.
2822
+ CTR_SUB=$( docker_run \
2823
+ -v " $DOT_SSH /server/2" :/dot_ssh:ro \
2824
+ -v " $SUBMODULE " :/git/repo:ro \
2825
+ e2e/test/sshd)
2826
+ IP_SUB=$( docker_ip " $CTR_SUB " )
2827
+
2828
+ # Add the submodule to the main repo
2829
+ git -C " $REPO " submodule add -q " test@$IP_SUB :/git/repo" " $SUBMODULE_REPO_NAME "
2830
+ git -C " $REPO " commit -aqm " add submodule"
2831
+ git -C " $REPO " submodule update --recursive --remote > /dev/null 2>&1
2832
+
2833
+ # Run a git-over-SSH server. Use key #3.
2834
+ CTR=$( docker_run \
2835
+ -v " $DOT_SSH /server/3" :/dot_ssh:ro \
2836
+ -v " $REPO " :/git/repo:ro \
2837
+ e2e/test/sshd)
2838
+ IP=$( docker_ip " $CTR " )
2839
+
2840
+ GIT_SYNC \
2841
+ --period=100ms \
2842
+ --repo=" test@$IP :/git/repo" \
2843
+ --root=" $ROOT " \
2844
+ --link=" link" \
2845
+ --ssh \
2846
+ --ssh-key-file=" /ssh/secret.1" \
2847
+ --ssh-key-file=" /ssh/secret.2" \
2848
+ --ssh-key-file=" /ssh/secret.3" \
2849
+ --ssh-known-hosts=false \
2850
+ &
2851
+ wait_for_sync " ${MAXWAIT} "
2852
+ assert_link_exists " $ROOT /link"
2853
+ assert_file_exists " $ROOT /link/file"
2854
+ assert_file_exists " $ROOT /link/$SUBMODULE_REPO_NAME /submodule.file"
2855
+ assert_file_exists " $ROOT /link/$SUBMODULE_REPO_NAME /$NESTED_SUBMODULE_REPO_NAME /nested-submodule.file"
2856
+ assert_metric_eq " ${METRIC_GOOD_SYNC_COUNT} " 1
2857
+
2858
+ rm -rf $SUBMODULE
2859
+ rm -rf $NESTED_SUBMODULE
2860
+ }
2861
+
2779
2862
# #############################################
2780
2863
# Test sparse-checkout files
2781
2864
# #############################################
0 commit comments