You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
returnfmt.Errorf("error: could not find SSH key Secret: %v", err)
647
647
}
648
648
649
-
iffileInfo.Mode() !=0400 {
650
-
returnfmt.Errorf("Permissions %s for SSH key are too open. It is recommended to mount secret volume with `defaultMode: 256` (decimal number for octal 0400).", fileInfo.Mode())
Git-sync supports using the SSH protocol for pulling git content.
4
4
5
5
## Step 1: Create Secret
6
-
Create a Secret to store your SSH private key, with the Secret keyed as "ssh". This can be done one of two ways:
6
+
7
+
Create a Secret to store your SSH private key, with the Secret keyed as "ssh".
8
+
This can be done one of two ways:
7
9
8
10
***Method 1:***
11
+
9
12
Obtain the host keys for your git server:
10
13
11
14
```
12
15
ssh-keyscan $YOUR_GIT_HOST > /tmp/known_hosts
13
16
```
14
17
15
-
Use the ``kubectl create secret`` command and point to the file on your filesystem that stores the key. Ensure that the file is mapped to "ssh" as shown (the file can be located anywhere).
18
+
Use the `kubectl create secret` command and point to the file on your
19
+
filesystem that stores the key. Ensure that the file is mapped to "ssh" as
Write a config file for a Secret that holds your SSH private key, with the key (pasted in base64 encoded plaintext) mapped to the "ssh" field.
31
+
Write a config file for a Secret that holds your SSH private key, with the key
32
+
(pasted in base64 encoded plaintext) mapped to the "ssh" field.
33
+
24
34
```
25
35
{
26
36
"kind": "Secret",
@@ -35,55 +45,107 @@ Write a config file for a Secret that holds your SSH private key, with the key (
35
45
}
36
46
```
37
47
38
-
Create the Secret using ``kubectl create -f``.
48
+
Create the Secret using `kubectl create -f`.
49
+
39
50
```
40
51
kubectl create -f /path/to/secret-config.json
41
52
```
42
53
43
-
Invoke the `git-sync` binary with the `-ssh-known-hosts` parameter to enforce `known_hosts` checking. This will be enabled by default in a future release.
54
+
## Step 2: Configure Pod/Deployment volume
44
55
45
-
## Step 2: Configure Pod/Deployment Volume
56
+
In your Pod or Deployment configuration, specify a volume for mounting the
57
+
Secret. Ensure that secretName matches the name you used when creating the
58
+
Secret (e.g. "git-creds" used in both above examples).
46
59
47
-
In your Pod or Deployment configuration, specify a Volume for mounting the Secret. Ensure that secretName matches the name you used when creating the Secret (e.g. "git-creds" used in both above examples).
48
60
```
49
-
volumes: [
50
-
{
51
-
"name": "git-secret",
52
-
"secret": {
53
-
"secretName": "git-creds",
54
-
"defaultMode": 256
55
-
}
56
-
},
57
-
...
58
-
],
61
+
# ...
62
+
volumes:
63
+
- name: git-secret
64
+
secret:
65
+
secretName: git-creds
66
+
defaultMode: 288 # 0440
67
+
# ...
59
68
```
60
69
61
70
## Step 3: Configure git-sync container
62
71
63
-
In your git-sync container configuration, mount the Secret Volume at "/etc/git-secret". Ensure that the environment variable GIT_SYNC_REPO is set to use a URL with the SSH protocol, and set GIT_SYNC_SSH to true.
72
+
In your git-sync container configuration, mount the Secret volume at
73
+
"/etc/git-secret". Ensure that the `-repo` flag (or the GIT_SYNC_REPO
74
+
environment variable) is set to use the SSH protocol (e.g.
75
+
[email protected]/foo/bar) , and set the `-ssh` flags (or set GIT_SYNC_SSH to
76
+
"true"). You will also need to set your container's `securityContext` to run
77
+
as user ID "65535" which is created for running git-syn as non-root.
Lastly, you need to tell your Pod to run with the git-sync FS group. Note
98
+
that this is a Pod-wide setting, unlike the container `securityContext` above.
99
+
87
100
```
101
+
# ...
102
+
securityContext:
103
+
fsGroup: 65533 # to make SSH key readable
104
+
# ...
105
+
```
106
+
107
+
**Note:** Kubernetes mounts the Secret with permissions 0444 by default (not
108
+
restrictive enough to be used as an SSH key), so make sure you set the
109
+
`defaultMode`.
88
110
89
-
**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).
111
+
## Full example
112
+
113
+
In case the above YAML snippets are confusing (because whitespace matters in
0 commit comments