Skip to content

Commit 332dbba

Browse files
committed
CodeQL: Exclude go/insecure-hostkeycallback
Split `ssh.InsecureIgnoreHostKey()` usage into pkg/sshutil/sshutil_use_insecure_hostkeycallback.go and exclude go/insecure-hostkeycallback on that file. We already ignore host key verification when executing SSH commands in Lima, by using UserKnownHostsFile=/dev/null and StrictHostKeyChecking=no in the SSH command arguments. Signed-off-by: Norio Nomura <[email protected]>
1 parent 9943ad1 commit 332dbba

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

.github/codeql-config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: "CodeQL config"
2+
query-filters:
3+
- exclude:
4+
id: go/insecure-hostkeycallback
5+
paths:
6+
- "pkg/sshutil/sshutil_use_insecure_hostkeycallback.go"

.github/workflows/codeql.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
with:
4646
languages: ${{ matrix.language }}
4747
build-mode: ${{ matrix.build-mode }}
48+
config-file: ./.github/codeql-config.yml
4849

4950
- if: matrix.build-mode == 'manual'
5051
shell: bash

pkg/sshutil/sshutil.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,7 @@ func WaitSSHReady(ctx context.Context, dialContext func(context.Context) (net.Co
526526
return err
527527
}
528528
// Prepare ssh client config
529-
sshConfig := &ssh.ClientConfig{
530-
User: user,
531-
Auth: []ssh.AuthMethod{ssh.PublicKeys(signer)},
532-
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
533-
Timeout: 10 * time.Second,
534-
}
529+
sshConfig := sshClientConfigWithInsecureHostKeyCallback(user, timeoutSeconds, signer)
535530
// Wait until the SSH server is available.
536531
for {
537532
conn, err := dialContext(ctx)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-FileCopyrightText: Copyright The Lima Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package sshutil
5+
6+
import (
7+
"time"
8+
9+
"golang.org/x/crypto/ssh"
10+
)
11+
12+
// This file exists to exclude the use of ssh.InsecureIgnoreHostKey()
13+
// from the main sshutil.go file, so that we can suppress
14+
// the CodeQL warning about it in .github/codeql-config.yml.
15+
16+
// sshClientConfigWithInsecureHostKeyCallback returns an ssh.ClientConfig
17+
// that uses ssh.InsecureIgnoreHostKey() as the HostKeyCallback.
18+
// We already ignore host key verification when executing SSH commands in Lima,
19+
// by using UserKnownHostsFile=/dev/null and StrictHostKeyChecking=no in the SSH command arguments.
20+
func sshClientConfigWithInsecureHostKeyCallback(user string, timeoutSeconds int, signers ...ssh.Signer) *ssh.ClientConfig {
21+
return &ssh.ClientConfig{
22+
User: user,
23+
Auth: []ssh.AuthMethod{ssh.PublicKeys(signers...)},
24+
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
25+
Timeout: time.Duration(timeoutSeconds) * time.Second,
26+
}
27+
}

0 commit comments

Comments
 (0)