Skip to content

Commit 035d394

Browse files
committed
fix: fix fail to insert key
1 parent 3a45d90 commit 035d394

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: Lint
22

3-
on:
4-
push:
5-
pull_request:
3+
on: []
4+
# push:
5+
# pull_request:
66

77
jobs:
88
lint:

internal/webhook/v1/inject_script.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
echo "Inserting authorized_keys...";
2-
echo "$AUTHORIZED_KEYS" > /mnt/.ssh/authorized_keys;
2+
echo "$AUTHORIZED_KEYS" >> /mnt/.ssh/authorized_keys;
3+
echo "StrictHostKeyChecking no" >> /mnt/.ssh/config;
34

45
for name in $SSH_KEY_PAIRS; do
56
echo "Inserting key $name...";

internal/webhook/v1/pod_webhook.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ func (d *PodCustomDefaulter) Default(ctx context.Context, obj runtime.Object) er
9393
return nil
9494
}
9595

96+
for _, volume := range pod.Spec.Volumes {
97+
if volume.Name == "dot-ssh" {
98+
return nil
99+
}
100+
}
101+
96102
// Get ssh key pairs & authorized keys
97103
kpList := &sshoperatorv1alpha1.SSHKeyPairList{}
98104
if err := d.c.List(ctx, kpList, client.InNamespace(ns)); err != nil {
@@ -157,15 +163,15 @@ func (d *PodCustomDefaulter) Default(ctx context.Context, obj runtime.Object) er
157163
{
158164
Name: "dot-ssh",
159165
MountPath: "/mnt/.ssh",
160-
ReadOnly: true,
166+
ReadOnly: false,
161167
},
162168
},
163169
})
164170
for k := range pod.Spec.Containers {
165171
pod.Spec.Containers[k].VolumeMounts = append(pod.Spec.Containers[k].VolumeMounts, corev1.VolumeMount{
166172
Name: "dot-ssh",
167173
MountPath: "/root/.ssh",
168-
ReadOnly: true,
174+
ReadOnly: false,
169175
})
170176
}
171177
if pod.Spec.Hostname == "" {
@@ -181,6 +187,7 @@ func (d *PodCustomDefaulter) Default(ctx context.Context, obj runtime.Object) er
181187
"/bin/bash",
182188
"-c",
183189
"chmod -R 0600 /root/.ssh; mkdir -p /run/sshd; /sbin/sshd; \"$@\"",
190+
"--",
184191
}, origCmd...)
185192

186193
return nil

0 commit comments

Comments
 (0)