Skip to content

Commit 19e80de

Browse files
committed
update AZURE_SSH_PUBLIC_KEY variable to be AZURE_SSH_PUBLIC_KEY_B64
1 parent b470408 commit 19e80de

27 files changed

+53
-45
lines changed

Tiltfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def flavors():
215215
if key[-4:] == "_B64":
216216
substitutions[key[:-4]] = base64_decode(substitutions[key])
217217

218-
ssh_pub_key = "AZURE_SSH_PUBLIC_KEY"
218+
ssh_pub_key = "AZURE_SSH_PUBLIC_KEY_B64"
219219
ssh_pub_key_path = "~/.ssh/id_rsa.pub"
220220
if not substitutions.get(ssh_pub_key):
221221
print("{} was not specified in tilt_config.json, attempting to load {}".format(ssh_pub_key, ssh_pub_key_path))

api/v1alpha3/azuremachine_default_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func TestAzureMachine_SetDataDisksDefaults(t *testing.T) {
204204
tc := c
205205
t.Run(tc.name, func(t *testing.T) {
206206
t.Parallel()
207-
machine := hardcodedAzureMachineWithSSHKey(generateSSHPublicKey())
207+
machine := hardcodedAzureMachineWithSSHKey(generateSSHPublicKey(true))
208208
machine.Spec.DataDisks = tc.disks
209209
machine.SetDataDisksDefaults()
210210
if !reflect.DeepEqual(machine.Spec.DataDisks, tc.output) {
@@ -223,7 +223,7 @@ func createMachineWithSSHPublicKey(t *testing.T, sshPublicKey string) *AzureMach
223223
}
224224

225225
func createMachineWithUserAssignedIdentities(t *testing.T, identitiesList []UserAssignedIdentity) *AzureMachine {
226-
machine := hardcodedAzureMachineWithSSHKey(generateSSHPublicKey())
226+
machine := hardcodedAzureMachineWithSSHKey(generateSSHPublicKey(true))
227227
machine.Spec.Identity = VMIdentityUserAssigned
228228
machine.Spec.UserAssignedIdentities = identitiesList
229229
return machine

api/v1alpha3/azuremachine_validation_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,19 @@ func TestAzureMachine_ValidateSSHKey(t *testing.T) {
4141
}{
4242
{
4343
name: "valid ssh key",
44-
sshKey: generateSSHPublicKey(),
44+
sshKey: generateSSHPublicKey(true),
4545
wantErr: false,
4646
},
4747
{
4848
name: "invalid ssh key",
4949
sshKey: "invalid ssh key",
5050
wantErr: true,
5151
},
52+
{
53+
name: "ssh key not base64 encoded",
54+
sshKey: generateSSHPublicKey(false),
55+
wantErr: true,
56+
},
5257
}
5358

5459
for _, tc := range tests {
@@ -63,10 +68,13 @@ func TestAzureMachine_ValidateSSHKey(t *testing.T) {
6368
}
6469
}
6570

66-
func generateSSHPublicKey() string {
71+
func generateSSHPublicKey(b64Enconded bool) string {
6772
privateKey, _ := rsa.GenerateKey(rand.Reader, 2048)
6873
publicRsaKey, _ := ssh.NewPublicKey(&privateKey.PublicKey)
69-
return base64.StdEncoding.EncodeToString(ssh.MarshalAuthorizedKey(publicRsaKey))
74+
if b64Enconded {
75+
return base64.StdEncoding.EncodeToString(ssh.MarshalAuthorizedKey(publicRsaKey))
76+
}
77+
return string(ssh.MarshalAuthorizedKey(publicRsaKey))
7078
}
7179

7280
type osDiskTestInput struct {

api/v1alpha3/azuremachine_webhook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
var (
27-
validSSHPublicKey = generateSSHPublicKey()
27+
validSSHPublicKey = generateSSHPublicKey(true)
2828
validOSDisk = generateValidOSDisk()
2929
)
3030

docs/book/src/topics/ephemeral-os.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ spec:
5656
managedDisk:
5757
storageAccountType: Standard_LRS
5858
osType: Linux
59-
sshPublicKey: ${AZURE_SSH_PUBLIC_KEY}
59+
sshPublicKey: ${AZURE_SSH_PUBLIC_KEY_B64}
6060
vmSize: ${AZURE_NODE_MACHINE_TYPE}
6161
````

docs/book/src/topics/managedcluster.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ spec:
9292
name: agentpool0
9393
location: southcentralus
9494
resourceGroup: foo-bar
95-
sshPublicKey: ${AZURE_SSH_PUBLIC_KEY}
95+
sshPublicKey: ${AZURE_SSH_PUBLIC_KEY_B64}
9696
subscriptionID: fae7cc14-bfba-4471-9435-f945b42a16dd # fake uuid
9797
version: v1.17.4
9898
networkPolicy: azure # or calico

docs/development.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,12 @@ export WORKER_MACHINE_COUNT=2
275275
export KUBERNETES_VERSION="v1.18.8"
276276

277277
# Generate SSH key.
278-
# If you want to provide your own key, skip this step and set AZURE_SSH_PUBLIC_KEY to your existing file.
278+
# If you want to provide your own key, skip this step and set AZURE_SSH_PUBLIC_KEY_B64 to your existing file.
279279
SSH_KEY_FILE=.sshkey
280280
rm -f "${SSH_KEY_FILE}" 2>/dev/null
281281
ssh-keygen -t rsa -b 2048 -f "${SSH_KEY_FILE}" -N '' 1>/dev/null
282282
echo "Machine SSH key generated in ${SSH_KEY_FILE}"
283-
export AZURE_SSH_PUBLIC_KEY=$(cat "${SSH_KEY_FILE}.pub" | base64 | tr -d '\r\n')
283+
export AZURE_SSH_PUBLIC_KEY_B64=$(cat "${SSH_KEY_FILE}.pub" | base64 | tr -d '\r\n')
284284
```
285285

286286
⚠️ Please note the generated templates include default values and therefore require the use of `clusterctl` to create the cluster

docs/troubleshooting.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ E0320 23:33:33.288073 1 controller.go:258] controller-runtime/controller "
2323
### Remoting to workload clusters
2424
After the workload cluster is finished deploying you will have a kubeconfig in `./kubeconfig`.
2525

26-
Using the ssh information provided during cluster creation (environment variable `AZURE_SSH_PUBLIC_KEY`), you can debug most issues by SSHing into the VMs that have been created:
26+
Using the ssh information provided during cluster creation (environment variable `AZURE_SSH_PUBLIC_KEY_B64`), you can debug most issues by SSHing into the VMs that have been created:
2727

2828
```
2929
# connect to first control node - capi is default linux user created by deployment
@@ -40,8 +40,8 @@ capz-cluster-md-0-s52wb true Succeeded
4040
capz-cluster-md-0-w8xxw true Succeeded
4141
4242
# pick node name from output above:
43-
node=$(kubectl get azuremachine capz-cluster-md-0-s52wb -o jsonpath='{.status.addresses[0].address}')
44-
ssh -J capi@${apiserver} capi@${node}
43+
node=$(kubectl get azuremachine capz-cluster-md-0-s52wb -o jsonpath='{.status.addresses[0].address}')
44+
ssh -J capi@${apiserver} capi@${node}
4545
```
4646

4747
> There are some [provided scripts](/hack/debugging/Readme.md) that can help automate a few common tasks.

hack/create-dev-cluster.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ if ! [ -n "$SSH_KEY_FILE" ]; then
5656
ssh-keygen -t rsa -b 2048 -f "${SSH_KEY_FILE}" -N '' 1>/dev/null
5757
echo "Machine SSH key generated in ${SSH_KEY_FILE}"
5858
fi
59-
export AZURE_SSH_PUBLIC_KEY=$(cat "${SSH_KEY_FILE}.pub" | base64 | tr -d '\r\n')
59+
export AZURE_SSH_PUBLIC_KEY_B64=$(cat "${SSH_KEY_FILE}.pub" | base64 | tr -d '\r\n')
6060

6161
echo "================ DOCKER BUILD ==============="
6262
PULL_POLICY=IfNotPresent make modules docker-build

scripts/ci-e2e.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ if [ -z "${AZURE_SSH_PUBLIC_KEY_FILE}" ]; then
8585
ssh-keygen -t rsa -b 2048 -f "${SSH_KEY_FILE}" -N '' 1>/dev/null
8686
AZURE_SSH_PUBLIC_KEY_FILE="${SSH_KEY_FILE}.pub"
8787
fi
88-
export AZURE_SSH_PUBLIC_KEY=$(cat "${AZURE_SSH_PUBLIC_KEY_FILE}" | base64 | tr -d '\r\n')
88+
export AZURE_SSH_PUBLIC_KEY_B64=$(cat "${AZURE_SSH_PUBLIC_KEY_FILE}" | base64 | tr -d '\r\n')
8989

9090
# timestamp is in RFC-3339 format to match kubetest
9191
export TIMESTAMP="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"

0 commit comments

Comments
 (0)