Skip to content

Commit b29839f

Browse files
authored
Merge pull request kubernetes#25 from ApsOps/remove-chmod
Remove chmod command since we can specify permissions for a Secret Volume
2 parents 5b24e17 + ea98806 commit b29839f

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

cmd/git-sync/main.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,17 +471,13 @@ func setupGitAuth(username, password, gitURL string) error {
471471
func setupGitSSH() error {
472472
log.V(1).Infof("setting up git SSH credentials")
473473

474-
if _, err := os.Stat("/etc/git-secret/ssh"); err != nil {
474+
fileInfo, err := os.Stat("/etc/git-secret/ssh")
475+
if err != nil {
475476
return fmt.Errorf("error: could not find SSH key Secret: %v", err)
476477
}
477478

478-
// Kubernetes mounts Secret as 0444 by default, which is not restrictive enough to use as an SSH key.
479-
// TODO: Remove this command once Kubernetes allows for specifying permissions for a Secret Volume.
480-
// See https://github.com/kubernetes/kubernetes/pull/28936.
481-
if err := os.Chmod("/etc/git-secret/ssh", 0400); err != nil {
482-
483-
// If the Secret Volume is mounted as readOnly, the read-only filesystem nature prevents the necessary chmod.
484-
return fmt.Errorf("error running chmod on Secret (make sure Secret Volume is NOT mounted with readOnly=true): %v", err)
479+
if fileInfo.Mode() != 0400 {
480+
return fmt.Errorf("Permissions %s for SSH key are too open. It is recommeded to mount secret volume with `defaultMode: 256` (decimal number for octal 0400).", fileInfo.Mode())
485481
}
486482

487483
return nil

docs/ssh.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,4 @@ In your git-sync container configuration, mount the Secret Volume at "/etc/git-s
7373
],
7474
}
7575
```
76-
**Note: Do not mount the Secret Volume with "readOnly: true".** Kubernetes mounts the Secret with permissions 0444 by default (not restrictive enough to be used as an SSH key), so the container runs a chmod command on the Secret. Mounting the Secret Volume as a read-only filesystem prevents chmod and thus prevents the use of the Secret as an SSH key.
77-
78-
***TODO***: Remove the chmod command once Kubernetes allows for specifying permissions for a Secret Volume. See https://github.com/kubernetes/kubernetes/pull/28936.
76+
**Note:** Kubernetes mounts the Secret with permissions 0444 by default (not restrictive enough to be used as an SSH key), so make sure you use secret volume with `defaultMode: 256` (decimal number for octal 0400).

0 commit comments

Comments
 (0)