Skip to content

Commit

Permalink
feat: remove helm rsync.fixPrivateKeyPerms option and change how ssh …
Browse files Browse the repository at this point in the history
…private key is mounted and used (#252)

* Remove helm rsync.fixPrivateKeyPerms option and change how ssh private key is mounted and used

Signed-off-by: Alex Romanenko <[email protected]

* Update helm/pv-migrate/templates/rsync/job.yaml

Adding quotes to avoid spaces issue with file paths.

Co-authored-by: Utku Özdemir <[email protected]>

* Update helm/pv-migrate/templates/sshd/deployment.yaml

Adding quotes to avoid spaces issue with file paths.

Co-authored-by: Utku Özdemir <[email protected]>

* update chart

Signed-off-by: Utku Ozdemir <[email protected]>

---------

Signed-off-by: Alex Romanenko <[email protected]
Signed-off-by: Utku Ozdemir <[email protected]>
Co-authored-by: Utku Özdemir <[email protected]>
  • Loading branch information
alex-vmw and utkuozdemir authored Oct 7, 2023
1 parent 44e5990 commit 4f5b0e1
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 17 deletions.
5 changes: 2 additions & 3 deletions helm/pv-migrate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ The helm chart of pv-migrate
| rsync.command | string | `""` | Full Rsync command and flags |
| rsync.enabled | bool | `false` | Enable creation of Rsync job |
| rsync.extraArgs | string | `""` | Extra args to be appended to the rsync command. Setting this might cause the tool to not function properly. |
| rsync.fixPrivateKeyPerms | bool | `false` | Enable fixing permissions on the private key prior to running rsync |
| rsync.image.pullPolicy | string | `"IfNotPresent"` | Rsync image pull policy |
| rsync.image.repository | string | `"docker.io/utkuozdemir/pv-migrate-rsync"` | Rsync image repository |
| rsync.image.tag | string | `"1.0.0"` | Rsync image tag |
Expand All @@ -41,7 +40,7 @@ The helm chart of pv-migrate
| rsync.podSecurityContext | object | `{}` | Rsync pod security context |
| rsync.privateKey | string | `""` | The private key content |
| rsync.privateKeyMount | bool | `false` | Mount a private key into the Rsync pod |
| rsync.privateKeyMountPath | string | `"/root/.ssh/id_ed25519"` | The path to mount the private key |
| rsync.privateKeyMountPath | string | `"/tmp/id_ed25519"` | The path to mount the private key |
| rsync.pvcMounts | list | `[]` | PVC mounts into the Rsync pod. For examples, see [values.yaml](values.yaml) |
| rsync.resources | object | `{}` | Rsync pod resources |
| rsync.restartPolicy | string | `"Never"` | |
Expand All @@ -65,7 +64,7 @@ The helm chart of pv-migrate
| sshd.podSecurityContext | object | `{}` | SSHD pod security context |
| sshd.privateKey | string | `""` | The private key content |
| sshd.privateKeyMount | bool | `false` | Mount a private key into the SSHD pod |
| sshd.privateKeyMountPath | string | `"/root/.ssh/id_ed25519"` | The path to mount the private key |
| sshd.privateKeyMountPath | string | `"/tmp/id_ed25519"` | The path to mount the private key |
| sshd.publicKey | string | `""` | The public key content |
| sshd.publicKeyMount | bool | `true` | Mount a public key into the SSHD pod |
| sshd.publicKeyMountPath | string | `"/root/.ssh/authorized_keys"` | The path to mount the public key |
Expand Down
8 changes: 6 additions & 2 deletions helm/pv-migrate/templates/rsync/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ spec:
rc=1
retries={{ .Values.rsync.maxRetries }}
period={{ .Values.rsync.retryPeriodSeconds }}
{{ if .Values.rsync.fixPrivateKeyPerms -}}
chmod 400 {{ .Values.rsync.privateKeyMountPath }}
{{ if .Values.rsync.privateKeyMount -}}
privateKeyFilename=$(basename "{{ .Values.rsync.privateKeyMountPath }}")
mkdir -p ~/.ssh
chmod 700 ~/.ssh
cp -v "{{ .Values.rsync.privateKeyMountPath }}" ~/.ssh/
chmod 400 "~/.ssh/$privateKeyFilename"
{{- end }}
until [ "$n" -ge "$retries" ]
do
Expand Down
13 changes: 13 additions & 0 deletions helm/pv-migrate/templates/sshd/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ spec:
{{- toYaml .Values.sshd.podSecurityContext | nindent 8 }}
containers:
- name: sshd
command:
- sh
- -c
- |
set -x
{{ if .Values.sshd.privateKeyMount -}}
privateKeyFilename=$(basename "{{ .Values.sshd.privateKeyMountPath }}")
mkdir -p ~/.ssh
chmod 700 ~/.ssh
cp -v "{{ .Values.sshd.privateKeyMountPath }}" ~/.ssh/
chmod 400 "~/.ssh/$privateKeyFilename"
{{- end }}
/usr/sbin/sshd -D -e -f /etc/ssh/sshd_config
securityContext:
{{- toYaml .Values.sshd.securityContext | nindent 12 }}
image: "{{ .Values.sshd.image.repository }}:{{ .Values.sshd.image.tag }}"
Expand Down
6 changes: 2 additions & 4 deletions helm/pv-migrate/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ sshd:
# -- Mount a private key into the SSHD pod
privateKeyMount: false
# -- The path to mount the private key
privateKeyMountPath: /root/.ssh/id_ed25519
privateKeyMountPath: /tmp/id_ed25519
# -- The private key content
privateKey: ""

Expand Down Expand Up @@ -143,11 +143,9 @@ rsync:
# -- Mount a private key into the Rsync pod
privateKeyMount: false
# -- The path to mount the private key
privateKeyMountPath: /root/.ssh/id_ed25519
privateKeyMountPath: /tmp/id_ed25519
# -- The private key content
privateKey: ""
# -- Enable fixing permissions on the private key prior to running rsync
fixPrivateKeyPerms: false
# -- Number of retries to run rsync command
maxRetries: 10
# -- Waiting time between retries
Expand Down
2 changes: 1 addition & 1 deletion helm/test-vals-different-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ rsync:
mountSource: false

privateKeyMount: true
privateKeyMountPath: /root/.ssh/id_ed25519
privateKeyMountPath: /tmp/id_ed25519
privateKey: asdf

sshRemoteHost: REMOTE_HOST
Expand Down
2 changes: 1 addition & 1 deletion helm/test-vals-different-ns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ rsync:
deleteExtraneousFiles: false
noChown: false
privateKeyMount: true
privateKeyMountPath: /root/.ssh/id_ed25519
privateKeyMountPath: /tmp/id_ed25519
privateKey: |
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtz
Expand Down
4 changes: 1 addition & 3 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const (
migrateCmdlineWithNetpols = migrateCmdline +
"--helm-set rsync.networkPolicy.enabled=true " +
"--helm-set sshd.networkPolicy.enabled=true"
migrateCmdlineWithNetpolsAndRsyncFixPrivateKeyPerms = migrateCmdlineWithNetpols +
" --helm-set rsync.fixPrivateKeyPerms=true"
)

var (
Expand Down Expand Up @@ -179,7 +177,7 @@ func TestSameNSLbSvc(t *testing.T) {
_, err := execInPod(ctx, mainClusterCli, ns1, "dest", generateExtraDataShellCommand)
assert.NoError(t, err)

cmd := fmt.Sprintf("%s -s lbsvc -i -n %s -N %s --lbsvc-timeout 5m source dest", migrateCmdlineWithNetpolsAndRsyncFixPrivateKeyPerms, ns1, ns1)
cmd := fmt.Sprintf("%s -s lbsvc -i -n %s -N %s --lbsvc-timeout 5m source dest", migrateCmdlineWithNetpols, ns1, ns1)
assert.NoError(t, runCliApp(ctx, cmd))

stdout, err := execInPod(ctx, mainClusterCli, ns1, "dest", printDataUIDGIDContentShellCommand)
Expand Down
Binary file modified migrator/helm-chart.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion strategy/lbsvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (r *LbSvc) Run(ctx context.Context, attempt *migration.Attempt) error {
return fmt.Errorf("failed to create ssh key pair: %w", err)
}

privateKeyMountPath := "/root/.ssh/id_" + keyAlgorithm
privateKeyMountPath := "/tmp/id_" + keyAlgorithm

srcReleaseName := attempt.HelmReleaseNamePrefix + "-src"
destReleaseName := attempt.HelmReleaseNamePrefix + "-dest"
Expand Down
2 changes: 1 addition & 1 deletion strategy/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (r *Local) installLocalReleases(attempt *migration.Attempt) (string, string
return "", "", "", fmt.Errorf("failed to generate SSH key pair: %w", err)
}

privateKeyMountPath := "/root/.ssh/id_" + keyAlgorithm
privateKeyMountPath := "/tmp/id_" + keyAlgorithm

srcReleaseName := attempt.HelmReleaseNamePrefix + "-src"
destReleaseName := attempt.HelmReleaseNamePrefix + "-dest"
Expand Down
2 changes: 1 addition & 1 deletion strategy/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func buildHelmVals(mig *migration.Migration, helmReleaseName string) (map[string
return nil, fmt.Errorf("failed to create ssh key pair: %w", err)
}

privateKeyMountPath := "/root/.ssh/id_" + keyAlgorithm
privateKeyMountPath := "/tmp/id_" + keyAlgorithm

sshTargetHost := helmReleaseName + "-sshd." + sourceNs
if mig.Request.DestHostOverride != "" {
Expand Down

0 comments on commit 4f5b0e1

Please sign in to comment.