Skip to Content
IntegrationsCloud

Secure VMware with Mondoo

Continuously assess VMware vSphere and ESXi hosts for security vulnerabilities and misconfigurations.

VMware vSphere and ESXi often form the foundation of on-premises infrastructure, so keeping them secure protects every workload running on top of them. Mondoo assesses them from a Linux host that runs cnspec.

The setup has three parts:

  1. Create a read-only vCenter user that Mondoo will scan with.
  2. Deploy a Linux host with cnspec to run the scans. Mondoo ships a pre-built VMware appliance, or you can install cnspec on your own hardened Linux instance.
  3. Register cnspec and run scans against vSphere and ESXi.

Step 1: Create a read-only vCenter user

Mondoo needs a read-only vCenter user. Create a role, then create a user assigned to it.

  1. On the vSphere Client main menu, select Administration > Roles.

  2. Select the Read-only role and select CLONE.

  3. Name the clone Mondoo read-only role and select OK.

    Clone read-only role

  4. Select the new role and select EDIT. In the left list, select Global; in the right list, check Settings. Select SAVE.

    Create read-only role

  5. On the Administration menu, select Users and Groups.

  6. Under Users, select the vsphere.local domain and select ADD.

  7. Name the user mondoo-read, set a password, and select ADD.

    Create mondoo user

  8. On the Administration menu, select Global Permissions > ADD, then assign the Mondoo Read-only role to the mondoo-read user. Check Propagate to children and select OK.

    add read-only role to mondoo user

Step 2: Deploy a scan host

You can use the pre-built Mondoo VMware appliance or install cnspec on your own hardened Linux instance.

Option A: Mondoo VMware appliance

The appliance is a pre-configured Debian 13 VM with cnspec, VMware tools, cloud-init, and dev-sec hardening already in place. It manages its network with systemd-networkd.

  1. Download the Mondoo OVA image.

  2. In vCenter, right-click your Datacenter and select Deploy OVF Template.

    Deploy OVF Template

  3. Select the OVF template by URL or local file, then step through the wizard (name, folder, compute, storage, network).

    Select OVF Template

  4. On the wizard's Customize template page, set the appliance's deployment properties. Every property is optional:

    PropertyWhat it sets
    HostnameThe appliance's hostname. Default mondoo-appliance.
    Network Modedhcp (default) or static.
    Static IP Address, Netmask or Prefix, GatewayThe static address, for example 192.168.1.50, 255.255.255.0 or 24, and 192.168.1.1. A static network needs all three. If one is missing, the appliance starts without a network configuration.
    DNS ServersComma-separated DNS servers for a static network, for example 1.1.1.1,8.8.8.8.
    Configure Proxy, HTTP Proxy URL, HTTPS Proxy URL, No ProxyAn HTTP and HTTPS proxy for the appliance. Set Configure Proxy to true to use them. No Proxy lists the addresses that bypass the proxy. Default localhost,127.0.0.1.
    NTP ServerThe time server. Default pool.ntp.org.
    TimezoneThe appliance's time zone. Default UTC.
    Keyboard LayoutThe console keyboard layout. Default us.
    SSH Public KeyAn SSH public key (ssh-rsa or ssh-ed25519) to add to the mondoo user's authorized_keys.
    Mondoo Registration TokenA registration token for the space the appliance reports to. With a token, the appliance registers cnspec at first boot, runs a first scan of itself, and starts the cnspec service, so you can skip the cnspec login command in Step 3.
    Cloud-Init User-Data, User-Data Encoding, Cloud-Init Meta-Data, Meta-Data EncodingYour own cloud-init configuration, encoded as gzip+base64 or base64. If you provide user-data, the appliance configures itself only through cloud-init and ignores every other property in this table except the meta-data.

The appliance applies these properties once, at first boot. To see what it applied, sign in and run sudo ovf-debug.

The appliance ships with default credentials mondoo / mondoo. Change the password on first login. Password login is disabled by default on the hardened image. To sign in over SSH, set the SSH Public Key property when you deploy, or add your key to /home/mondoo/.ssh/authorized_keys from the VM console.

Optional: enable password authentication temporarily

If you can't transfer your SSH key first, enable password auth temporarily:

  1. In /etc/ssh/sshd_config:
    AuthenticationMethods password
    PasswordAuthentication yes
  2. Restart sshd: systemctl restart sshd.service
Optional: change to a static IP address after deployment

To set a static address when you deploy, use the Network Mode property instead. To change the network configuration later, edit the appliance's systemd-networkd files. At first boot, the appliance writes its network settings to /etc/systemd/network/10-ovf-dhcp.network (DHCP) or /etc/systemd/network/10-ovf-static.network (static).

Run as root.

  1. Find the name of the network interface, for example ens192, with ip link.

  2. Delete /etc/systemd/network/10-ovf-dhcp.network if it exists.

  3. Create or edit /etc/systemd/network/10-ovf-static.network. Example for ens192:

    [Match]
    Name=ens192
    
    [Network]
    Address=192.168.1.100/24
    Gateway=192.168.1.1
    DNS=192.168.1.1
    DNS=8.8.8.8
    LinkLocalAddressing=no
    IPv6AcceptRA=no
  4. Apply the change: systemctl restart systemd-networkd systemd-resolved.

If the new IP differs from the current one, your SSH session drops; reconnect to the new address.

Option B: Your own Linux host

Install cnspec on any hardened Linux instance. See the cnspec installation guide.

Step 3: Register cnspec with Mondoo

The Mondoo App's VMware page generates the registration command for you. In the side navigation bar, select Integrations, then INSTALL, and under Cloud Security select VMware. Under Log in and scan your VMware environment, the page shows a cnspec login command with a fresh registration token (select REFRESH TOKEN if it expires) and a sample scan command. The same page lets you enable security policies for vSphere and ESXi.

  1. Register the host with a registration token. If you deployed the appliance with the Mondoo Registration Token property, it registered itself at first boot. Run step 2 to confirm, and run this command only if the status check shows the client isn't registered.

    sudo cnspec login -t <token> --config /etc/opt/mondoo/mondoo.yml
  2. Verify registration:

    sudo cnspec status

    The first lines of the output summarize the result. A healthy registration reads:

      ● Client     registered   ✓ authenticated
      ● Platform   reachable · SERVING   ✓ healthy

    The output ends with ✓ all systems healthy. If it doesn't, see What to do when status fails.

  3. Run a first test scan against vSphere:

    cnspec scan vsphere mondoo-read@vsphere.local@host --ask-pass

    Add --incognito to skip sending results to the Mondoo App for the first test scan.

  4. In the Mondoo App, enable the policies you want to score against. Mondoo VMware vSphere Security Baseline (for vCenter) and Mondoo VMware vSphere ESXi Security (for ESXi hosts) are a good starting point. See Manage Policies.

  5. Run the scan again to send results to the Mondoo App:

    cnspec scan vsphere mondoo-read@vsphere.local@host --ask-pass --discover auto

    --discover auto finds all ESXi hosts and the vCenter automatically. Use --discover all to also discover VMs.

vSphere tags and labels

When cnspec discovers ESXi hosts and VMs through vCenter, it labels each asset with vsphere.vmware.com/name, vsphere.vmware.com/moid, and its inventory path (vsphere.vmware.com/inventorypath on hosts, vsphere.vmware.com/inventory-path on VMs). It also adds each vSphere tag attached to the host or VM as the label vsphere.vmware.com/tag/CATEGORY:TAG with the value true. If cnspec can't look up the tag's category, the key is vsphere.vmware.com/tag/TAG. cnspec discovers VMs only with --discover all or --discover instances, so VMs carry these labels only then.

You can filter on these labels and build workspaces from them. For example, a workspace with a Tags/Labels CONTAINS condition with the key vsphere.vmware.com/tag/Environment:production and the value true includes every host and VM tagged production in the Environment category. To learn more, read Group assets by AWS account or vSphere tag.

Scan multiple assets with an inventory file

An inventory file lets cnspec scan multiple VMware assets on a schedule. The basic file looks like this:

/etc/opt/mondoo/inventory.yml
apiVersion: v1
kind: Inventory
metadata:
  name: cnspec-inventory
  labels:
    environment: production
spec:
  assets:
    - name:
      connections:
        - type: vsphere
          host: <ip of the ESXi or vCenter>
          insecure: true
          credentials:
            - type: password
              user: <username>
              password: <password>
          discover:
            targets:
              - host-machines

Save the file at /etc/opt/mondoo/inventory.yml as root so cnspec picks it up automatically, then:

sudo cnspec scan --inventory-file /etc/opt/mondoo/inventory.yml
sudo systemctl restart cnspec
sudo systemctl enable cnspec

Confirm the inventory loaded with sudo journalctl -u cnspec.service.

Use an encrypted file vault for credentials

To avoid plaintext credentials in inventory.yml, use cnspec's encrypted file vault.

  1. Configure the vault as the mondoo user (not root):

    cnspec vault configure mondoo-client-vault --type encrypted-file \
      --option=password='changeme' \
      --option path='/etc/opt/mondoo/vault.enc'

    cnspec prints a vault configuration block; add it to your inventory file.

  2. Update the inventory to reference the vault by secret ID:

    /etc/opt/mondoo/inventory.yml
    apiVersion: v1
    kind: Inventory
    metadata:
      name: cnspec-inventory
      labels:
        environment: production
    spec:
      assets:
        - name:
          connections:
            - type: vsphere
              host: 192.168.51.134
              insecure: true
              credentials:
                - secret_id: vcenter
              discover:
                targets:
                  - host-machines
      vault:
        name: mondoo-client-vault
        options:
          password: changeme
          path: /etc/opt/mondoo/vault.enc
        type: encrypted-file
  3. Store the vSphere credentials in the vault:

    cnspec vault add-secret vcenter \
      '{ "type": "password", "user": "chris@vsphere.local", "password": "password" }' \
      --inventory-file /etc/opt/mondoo/inventory.yml
  4. Scan using the vault (run as root, since the vault lives in /etc/opt/mondoo/vault.enc):

    sudo cnspec scan --inventory-file /etc/opt/mondoo/inventory.yml
    systemctl restart cnspec

Next steps

Last updated on

On this page