-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass port to ssh-keyscan when known_hosts not provided
Creds-init performs an ssh-keyscan if no known_hosts file is provided as part of a Secret. When the ssh server is using a custom port ssh-keyscan expects the port to be provided with the -p flag. Currently Tekton does not provide the flag resulting in failure to generate known_hosts. The error for this failure is also very opaque - manifesting as an "invalid flag" message in the creds-init initContainer log and making no mention of ssh-keyscan. This commit: - adds the -p flag to ssh-keyscan calls when a port is specified in the given git URL. - adds an additional note to auth.md mentioning ssh-keyscan - wraps any error returned by ssh-keyscan to mention the utility, hopefully aiding future debugging
- Loading branch information
1 parent
3b95494
commit 1caf5bf
Showing
3 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright 2020 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package gitcreds | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSSHKeyScanArgs(t *testing.T) { | ||
for _, tc := range []struct { | ||
url string | ||
expectedHost string | ||
expectedPort string | ||
}{{ | ||
url: "github.com", | ||
expectedHost: "github.com", | ||
}, { | ||
url: "customdomain.com", | ||
expectedHost: "customdomain.com", | ||
}, { | ||
url: "customdomain.com:22", | ||
expectedHost: "customdomain.com", | ||
expectedPort: "22", | ||
}, { | ||
url: "git.customdomain.com:7779", | ||
expectedHost: "git.customdomain.com", | ||
expectedPort: "7779", | ||
}} { | ||
host, port := sshKeyScanArgs(tc.url) | ||
if host != tc.expectedHost { | ||
t.Errorf("expected host %q received %q", tc.expectedHost, host) | ||
} | ||
if port != tc.expectedPort { | ||
t.Errorf("expected port %q received %q", tc.expectedPort, port) | ||
} | ||
} | ||
} |