aws / eks-anywhere

Run Amazon EKS on your own infrastructure 🚀
https://anywhere.eks.amazonaws.com
Apache License 2.0
1.97k stars 287 forks source link

Ubuntu OVA credentials for scan #1804

Closed GurayCetin closed 2 years ago

GurayCetin commented 2 years ago

Our bank customer is trying to scan Ubuntu OVA with Kubernetes 1.22 that I downloaded from artifacts before using it for security purpose. For scanning, it should be created on VMWare environment and normally asking for credentials. It was not including ubuntu user and root user password (blank) didn't work. So I couldn't access to OVA as creating VM and scan it properly.

Is there any way to achieve that?

vignesh-goutham commented 2 years ago

The Ubuntu OVAs do not have the root credentials on them. I'd suggest to create a VM using the template and before booting up, to construct a cloud-config with ssh keys, base64 encode it and attach it to the VM's userdata using govc commands. Booting the VM now would write the ssh key that should let you into the OS.

Example for cloud-config

## template: jinja
#cloud-config

users:
  - name: capv
    sudo: ALL=(ALL) NOPASSWD:ALL
    ssh_authorized_keys:
      - ssh-rsa ****

You should also have a metadata template, that you can use to inject networking details.

instance-id: "scan"
local-hostname: "scan"
wait-on-network:
  ipv4: true
  ipv6: false
network:
  version: 2
  ethernets:
    id0:
      match:
        macaddress: $MACADDRESS
      set-name: "eth0"
      wakeonlan: true
      dhcp4: true
      dhcp6: false

GOVC Commands:

govc vm.clone  -on=false -vm <template> -folder <folder path> <vm name>
govc vm.change -vm <vm name> -e guestinfo.userdata="$(base64 <user-data file path>)" -e guestinfo.userdata.encoding="base64"
govc vm.change -vm <vm name> -e guestinfo.metadata="$(MACADDRESS=$(govc device.info -vm <vm name> -json ethernet-0 | jq ".Devices[0].MacAddress") envsubst < <meta-data file path> | base64)" -e guestinfo.metadata.encoding="base64"
govc vm.power -on <vm name>  

This should start the VM and let you ssh into the VM as the user specified on the cloud-config. These commands will create the vm, attach user-data and meta-data and start the vm.