Skip to content

Commit 5ea3e0f

Browse files
committed
ssh: Skip sshd_simple_exec when user identity key is missing
Add init_per_testcase guard that skips when the required private key file does not exist, avoiding slow auth failures. Generate ed25519 and ecdsa user keys in the GHA Docker image so all public_key groups authenticate against the OS sshd.
1 parent 876eba0 commit 5ea3e0f

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

.github/dockerfiles/Dockerfile.ubuntu-base

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ USER ${USER}
129129
## Need to set USER and create a keygen file for ssh tests to pass
130130
ENV USER=${USER}
131131
RUN ssh-keygen -q -t rsa -N '' -f $HOME/.ssh/id_rsa && \
132-
cp $HOME/.ssh/id_rsa.pub $HOME/.ssh/authorized_keys
132+
ssh-keygen -q -t ed25519 -N '' -f $HOME/.ssh/id_ed25519 && \
133+
ssh-keygen -q -t ecdsa -b 256 -N '' -f $HOME/.ssh/id_ecdsa && \
134+
cat $HOME/.ssh/id_rsa.pub $HOME/.ssh/id_ed25519.pub $HOME/.ssh/id_ecdsa.pub > $HOME/.ssh/authorized_keys
133135

134136
COPY --chown=${USER}:${GROUP} dockerfiles/.profile /home/otptest/.profile
135137

lib/ssh/test/ssh_algorithms_SUITE.erl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,25 @@ init_per_testcase(mlkem768x25519_hybrid_secret_encoding, Config) ->
235235
false -> {skip, "X25519 or ML-KEM768 not supported"};
236236
true -> Config
237237
end;
238+
init_per_testcase(sshd_simple_exec, Config) ->
239+
case proplists:get_value(tag_alg, Config) of
240+
{public_key, Algs} ->
241+
KeyInfo = user_key_files_for(Algs),
242+
case has_user_key_for(Algs) of
243+
true ->
244+
?CT_LOG("sshd_simple_exec: identity key check passed~n"
245+
" Algs: ~p~n"
246+
" Key files found: ~p", [Algs, KeyInfo]),
247+
Config;
248+
false ->
249+
?CT_LOG("sshd_simple_exec: no identity key~n"
250+
" Algs: ~p~n"
251+
" Key files checked: ~p", [Algs, KeyInfo]),
252+
{skip, {no_user_identity_key, Algs}}
253+
end;
254+
_ ->
255+
Config
256+
end;
238257
init_per_testcase(_TC, Config) ->
239258
Config.
240259

@@ -504,6 +523,46 @@ supports(Tag, Alg, Algos) ->
504523
split(Tag, Alg)).
505524

506525

526+
%%%----------------------------------------------------------------
527+
%%% Check that the user has a local identity key matching the algorithm.
528+
%%% Used by init_per_testcase(sshd_simple_exec, ...) to skip early
529+
%%% instead of waiting 37s+ for auth failure against the OS sshd.
530+
531+
has_user_key_for(Algs) when is_list(Algs) ->
532+
lists:all(fun has_user_key_for_single/1, Algs);
533+
has_user_key_for(Alg) ->
534+
has_user_key_for_single(Alg).
535+
536+
user_key_files_for(Algs) when is_list(Algs) ->
537+
lists:flatmap(fun user_key_files_for/1, Algs);
538+
user_key_files_for(Alg) ->
539+
Home = os:getenv("HOME"),
540+
KeyFiles = key_filenames(Alg),
541+
[{Alg, F, filelib:is_regular(filename:join([Home, ".ssh", F]))}
542+
|| F <- KeyFiles].
543+
544+
has_user_key_for_single(Alg) ->
545+
case ssh_file:user_key(Alg, []) of
546+
{ok, _Key} -> true;
547+
_ -> false
548+
end.
549+
550+
key_filenames(Alg) ->
551+
case Alg of
552+
'ssh-rsa' -> ["id_rsa"];
553+
'rsa-sha2-256' -> ["id_rsa"];
554+
'rsa-sha2-512' -> ["id_rsa"];
555+
'ssh-dss' -> ["id_dsa"];
556+
'ssh-ed25519' -> ["id_ed25519"];
557+
'ssh-ed448' -> ["id_ed448"];
558+
'ecdsa-sha2-nistp256' -> ["id_ecdsa", "id_ecdsa_sk"];
559+
'ecdsa-sha2-nistp384' -> ["id_ecdsa"];
560+
'ecdsa-sha2-nistp521' -> ["id_ecdsa"];
561+
_ -> []
562+
end.
563+
564+
%%%----------------------------------------------------------------
565+
507566
extract_algos(Spec) ->
508567
[{Tag,get_atoms(List)} || {Tag,List} <- Spec].
509568

0 commit comments

Comments
 (0)