Skip to content

Commit 4ccf063

Browse files
committed
Deprecate --ssh - it's not really needed
As long as a repo uses SSH transport (user@host:path or ssh://...), SSH is active. This is true for the main repo or submodules.
1 parent 32c3a0c commit 4ccf063

File tree

5 files changed

+42
-81
lines changed

5 files changed

+42
-81
lines changed

README.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ OPTIONS
149149
150150
--add-user, $GITSYNC_ADD_USER
151151
Add a record to /etc/passwd for the current UID/GID. This is
152-
needed to use SSH with an arbitrary UID (see --ssh). This assumes
153-
that /etc/passwd is writable by the current UID.
152+
needed to use SSH with an arbitrary UID. This assumes that
153+
/etc/passwd is writable by the current UID.
154154
155155
--askpass-url <string>, $GITSYNC_ASKPASS_URL
156156
A URL to query for git credentials. The query must return success
@@ -313,18 +313,15 @@ OPTIONS
313313
details) which controls which files and directories will be checked
314314
out. If not specified, the default is to check out the entire repo.
315315
316-
--ssh, $GITSYNC_SSH
317-
Use SSH for git authentication and operations.
318-
319316
--ssh-key-file <string>, $GITSYNC_SSH_KEY_FILE
320-
The SSH key(s) to use when using --ssh. This flag may be specified
321-
more than once and the environment variable will be parsed like
322-
PATH - using a colon (':') to separate elements. If not specified,
323-
this defaults to "/etc/git-secret/ssh".
317+
The SSH key(s) to use when using git over SSH. This flag may be
318+
specified more than once and the environment variable will be
319+
parsed like PATH - using a colon (':') to separate elements. If
320+
not specified, this defaults to "/etc/git-secret/ssh".
324321
325322
--ssh-known-hosts, $GITSYNC_SSH_KNOWN_HOSTS
326-
Enable SSH known_hosts verification when using --ssh. If not
327-
specified, this defaults to true.
323+
Enable SSH known_hosts verification when using git over SSH. If
324+
not specified, this defaults to true.
328325
329326
--ssh-known-hosts-file <string>, $GITSYNC_SSH_KNOWN_HOSTS_FILE
330327
The known_hosts file to use when --ssh-known-hosts is specified.
@@ -430,11 +427,11 @@ AUTHENTICATION
430427
sync.
431428
432429
SSH
433-
When --ssh (GITSYNC_SSH) is specified, the --ssh-key-file
434-
(GITSYNC_SSH_KEY_FILE) will be used. Users are strongly advised
435-
to also use --ssh-known-hosts (GITSYNC_SSH_KNOWN_HOSTS) and
436-
--ssh-known-hosts-file (GITSYNC_SSH_KNOWN_HOSTS_FILE) when using
437-
SSH.
430+
When an SSH transport is specified, the key(s) defined in
431+
--ssh-key-file (GITSYNC_SSH_KEY_FILE) will be used. Users are
432+
strongly advised to also use --ssh-known-hosts
433+
(GITSYNC_SSH_KNOWN_HOSTS) and --ssh-known-hosts-file
434+
(GITSYNC_SSH_KNOWN_HOSTS_FILE) when using SSH.
438435
439436
cookies
440437
When --cookie-file (GITSYNC_COOKIE_FILE) is specified, the

docs/ssh.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,18 @@ Secret (e.g. "git-creds" used in both above examples).
6969
## Step 3: Configure git-sync container
7070

7171
In your git-sync container configuration, mount the Secret volume at
72-
"/etc/git-secret". Ensure that the `--repo` flag (or the GITSYNC_REPO
72+
"/etc/git-secret". Ensure that the `--repo` flag (or the `GITSYNC_REPO`
7373
environment variable) is set to use the SSH protocol (e.g.
74-
git@github.com/foo/bar) , and set the `--ssh` flags (or set GITSYNC_SSH to
75-
"true"). You will also need to set your container's `securityContext` to run
76-
as user ID "65533" which is created for running git-sync as non-root.
74+
git@github.com/foo/bar). You will also need to set your container's
75+
`securityContext` to run as user ID "65533" which is created for running
76+
git-sync as non-root.
7777

7878
```yaml
7979
# ...
8080
containers:
8181
- name: git-sync
8282
image: registry.k8s.io/git-sync:v4.0.0
8383
args:
84-
- "--ssh"
8584
- "--repo=git@github.com:foo/bar"
8685
- "--link=bar"
8786
volumeMounts:
@@ -139,7 +138,6 @@ spec:
139138
- name: git-sync
140139
image: registry.k8s.io/git-sync:v4.0.0
141140
args:
142-
- "--ssh"
143141
- "--repo=git@github.com:torvalds/linux"
144142
- "--depth=1"
145143
securityContext:

main.go

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,6 @@ func main() {
451451
envString("", "GITSYNC_PASSWORD_FILE", "GIT_SYNC_PASSWORD_FILE"),
452452
"the file from which the password or personal access token for git auth will be sourced")
453453

454-
flSSH := pflag.Bool("ssh",
455-
envBool(false, "GITSYNC_SSH", "GIT_SYNC_SSH"),
456-
"use SSH for git operations")
457454
flSSHKeyFiles := pflag.StringArray("ssh-key-file",
458455
envStringArray("/etc/git-secret/ssh", "GITSYNC_SSH_KEY_FILE", "GIT_SYNC_SSH_KEY_FILE", "GIT_SSH_KEY_FILE"),
459456
"the SSH key(s) to use")
@@ -508,6 +505,9 @@ func main() {
508505
flDeprecatedRev := pflag.String("rev", envString("", "GIT_SYNC_REV"),
509506
"DEPRECATED: use --ref instead")
510507
mustMarkDeprecated("rev", "use --ref instead")
508+
_ = pflag.Bool("ssh", false,
509+
"DEPRECATED: this flag is no longer necessary")
510+
mustMarkDeprecated("ssh", "no longer necessary")
511511
flDeprecatedSyncHookCommand := pflag.String("sync-hook-command", envString("", "GIT_SYNC_HOOK_COMMAND"),
512512
"DEPRECATED: use --exechook-command instead")
513513
mustMarkDeprecated("sync-hook-command", "use --exechook-command instead")
@@ -698,32 +698,6 @@ func main() {
698698
}
699699
}
700700

701-
if *flSSH {
702-
if *flUsername != "" {
703-
handleConfigError(log, true, "ERROR: only one of --ssh and --username may be specified")
704-
}
705-
if *flPassword != "" {
706-
handleConfigError(log, true, "ERROR: only one of --ssh and --password may be specified")
707-
}
708-
if *flPasswordFile != "" {
709-
handleConfigError(log, true, "ERROR: only one of --ssh and --password-file may be specified")
710-
}
711-
if *flAskPassURL != "" {
712-
handleConfigError(log, true, "ERROR: only one of --ssh and --askpass-url may be specified")
713-
}
714-
if *flCookieFile {
715-
handleConfigError(log, true, "ERROR: only one of --ssh and --cookie-file may be specified")
716-
}
717-
if len(*flSSHKeyFiles) == 0 {
718-
handleConfigError(log, true, "ERROR: --ssh-key-file must be specified when --ssh is set")
719-
}
720-
if *flSSHKnownHosts {
721-
if *flSSHKnownHostsFile == "" {
722-
handleConfigError(log, true, "ERROR: --ssh-known-hosts-file must be specified when --ssh-known-hosts is set")
723-
}
724-
}
725-
}
726-
727701
if *flHTTPBind == "" {
728702
if *flHTTPMetrics {
729703
handleConfigError(log, true, "ERROR: --http-bind must be specified when --http-metrics is set")
@@ -837,11 +811,10 @@ func main() {
837811
}
838812
}
839813

840-
if *flSSH {
841-
if err := git.SetupGitSSH(*flSSHKnownHosts, *flSSHKeyFiles, *flSSHKnownHostsFile); err != nil {
842-
log.Error(err, "can't set up git SSH", "keyFile", *flSSHKeyFiles, "knownHosts", *flSSHKnownHosts, "knownHostsFile", *flSSHKnownHostsFile)
843-
os.Exit(1)
844-
}
814+
// If the --repo or any submodule uses SSH, we need to know which keys.
815+
if err := git.SetupGitSSH(*flSSHKnownHosts, *flSSHKeyFiles, *flSSHKnownHostsFile); err != nil {
816+
log.Error(err, "can't set up git SSH", "keyFile", *flSSHKeyFiles, "knownHosts", *flSSHKnownHosts, "knownHostsFile", *flSSHKnownHostsFile)
817+
os.Exit(1)
845818
}
846819

847820
if *flCookieFile {
@@ -1955,16 +1928,10 @@ func (git *repoSync) SetupGitSSH(setupKnownHosts bool, pathsToSSHSecrets []strin
19551928
}
19561929

19571930
for _, p := range pathsToSSHSecrets {
1958-
if _, err := os.Stat(p); err != nil {
1959-
return fmt.Errorf("can't access SSH key file %s: %w", p, err)
1960-
}
19611931
sshCmd += fmt.Sprintf(" -i %s", p)
19621932
}
19631933

19641934
if setupKnownHosts {
1965-
if _, err := os.Stat(pathToSSHKnownHosts); err != nil {
1966-
return fmt.Errorf("can't access SSH known_hosts file %s: %w", pathToSSHKnownHosts, err)
1967-
}
19681935
sshCmd += fmt.Sprintf(" -o StrictHostKeyChecking=yes -o UserKnownHostsFile=%s", pathToSSHKnownHosts)
19691936
} else {
19701937
sshCmd += " -o StrictHostKeyChecking=no"
@@ -2318,8 +2285,8 @@ OPTIONS
23182285
23192286
--add-user, $GITSYNC_ADD_USER
23202287
Add a record to /etc/passwd for the current UID/GID. This is
2321-
needed to use SSH with an arbitrary UID (see --ssh). This assumes
2322-
that /etc/passwd is writable by the current UID.
2288+
needed to use SSH with an arbitrary UID. This assumes that
2289+
/etc/passwd is writable by the current UID.
23232290
23242291
--askpass-url <string>, $GITSYNC_ASKPASS_URL
23252292
A URL to query for git credentials. The query must return success
@@ -2482,18 +2449,15 @@ OPTIONS
24822449
details) which controls which files and directories will be checked
24832450
out. If not specified, the default is to check out the entire repo.
24842451
2485-
--ssh, $GITSYNC_SSH
2486-
Use SSH for git authentication and operations.
2487-
24882452
--ssh-key-file <string>, $GITSYNC_SSH_KEY_FILE
2489-
The SSH key(s) to use when using --ssh. This flag may be specified
2490-
more than once and the environment variable will be parsed like
2491-
PATH - using a colon (':') to separate elements. If not specified,
2492-
this defaults to "/etc/git-secret/ssh".
2453+
The SSH key(s) to use when using git over SSH. This flag may be
2454+
specified more than once and the environment variable will be
2455+
parsed like PATH - using a colon (':') to separate elements. If
2456+
not specified, this defaults to "/etc/git-secret/ssh".
24932457
24942458
--ssh-known-hosts, $GITSYNC_SSH_KNOWN_HOSTS
2495-
Enable SSH known_hosts verification when using --ssh. If not
2496-
specified, this defaults to true.
2459+
Enable SSH known_hosts verification when using git over SSH. If
2460+
not specified, this defaults to true.
24972461
24982462
--ssh-known-hosts-file <string>, $GITSYNC_SSH_KNOWN_HOSTS_FILE
24992463
The known_hosts file to use when --ssh-known-hosts is specified.
@@ -2599,11 +2563,11 @@ AUTHENTICATION
25992563
sync.
26002564
26012565
SSH
2602-
When --ssh (GITSYNC_SSH) is specified, the --ssh-key-file
2603-
(GITSYNC_SSH_KEY_FILE) will be used. Users are strongly advised
2604-
to also use --ssh-known-hosts (GITSYNC_SSH_KNOWN_HOSTS) and
2605-
--ssh-known-hosts-file (GITSYNC_SSH_KNOWN_HOSTS_FILE) when using
2606-
SSH.
2566+
When an SSH transport is specified, the key(s) defined in
2567+
--ssh-key-file (GITSYNC_SSH_KEY_FILE) will be used. Users are
2568+
strongly advised to also use --ssh-known-hosts
2569+
(GITSYNC_SSH_KNOWN_HOSTS) and --ssh-known-hosts-file
2570+
(GITSYNC_SSH_KNOWN_HOSTS_FILE) when using SSH.
26072571
26082572
cookies
26092573
When --cookie-file (GITSYNC_COOKIE_FILE) is specified, the

test_e2e.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,6 @@ function e2e::auth_ssh() {
17131713
--repo="test@$IP:/git/repo" \
17141714
--root="$ROOT" \
17151715
--link="link" \
1716-
--ssh \
17171716
--ssh-known-hosts=false \
17181717
--ssh-key-file="/ssh/secret.2"
17191718
assert_file_absent "$ROOT/link/file"
@@ -1724,7 +1723,6 @@ function e2e::auth_ssh() {
17241723
--repo="test@$IP:/git/repo" \
17251724
--root="$ROOT" \
17261725
--link="link" \
1727-
--ssh \
17281726
--ssh-known-hosts=false \
17291727
--ssh-key-file="/ssh/secret.1" \
17301728
--ssh-key-file="/ssh/secret.2" \
@@ -2724,7 +2722,6 @@ function e2e::submodule_sync_over_ssh_different_keys() {
27242722
--repo="test@$IP:/git/repo" \
27252723
--root="$ROOT" \
27262724
--link="link" \
2727-
--ssh \
27282725
--ssh-key-file="/ssh/secret.1" \
27292726
--ssh-key-file="/ssh/secret.2" \
27302727
--ssh-key-file="/ssh/secret.3" \

v3-to-v4.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ the real intentions (e.g. "allow group write" does not mean "set everything to
107107
0775"). The new `--group-write` flag should cover what people ACTUALLY are
108108
trying to do. The `--change-permissions` flag is no longer supported.
109109

110+
### SSH: `--ssh`
111+
112+
The old `--ssh` flag is no longer needed - the value of `--repo` determines
113+
when SSH is used. It is still accepted but does nothing.
114+
110115
### Manual: `--man`
111116

112117
The new `--man` flag prints a man-page style help document and exits.

0 commit comments

Comments
 (0)