Most OpenStack deployments has a VNC console implemented with nova-novncproxy. This service gives the final user the ability to log into their instances in a web based method through a browser.
At this post i'm going to show how a vnc console request works under the hood while using the following command or lauching a vnc session through Horizon.
# nova get-vnc-console INSTANCE novnc
First of all, a user connects to NOVA and issues a VNC console request for an instance. Nova API needs to validate the user issuing an authentication request to keystone.
The user receives a token with nova's endpoint URL in the catalog, with that endpoint and the token, the user makes a request against nova calling for a VNC session.
If a name instead of an instance ID is used in the request, Nova need to check his database to match that name with his corresponding ID, as we can see in the following request.
Once the ID is matched with the name, Nova check information about the instance (I thought it was to validate if is in ACTIVE status, but i realized that even when is in STOPPED status the request is made it anyway).
Until now, nova-novncproxy service can be stopped or isn't used at all, is at this point the when proxy server enter into the game. The user connects through a web browser to the nova-novncproxy's URL provided by nova before.
DEBUG nova.console.websocketproxy [-] 192.168.200.1: \
new handler Process vmsg /usr/lib/python2.7/site-packages/websockify/websocket.py:828
Nova-vncproxy validate the issued token with the URL against nova-consoleauth.
We can see how the python novncproxy process binds both IPs/port.
# ps aux | grep vnc
nova 14840 1.2 0.7 362096 41000 ? S 18:53 0:14 /usr/bin/python2 /usr/bin/nova-novncproxy --web /usr/share/novnc/
# netstat -putona | grep 14840
tcp 0 0 192.168.200.208:6080 192.168.200.1:59918 ESTABLISHED 14840/python2 keepalive (3,13/0/0)
tcp 0 0 192.168.122.73:57764 192.168.122.73:5900 ESTABLISHED 14840/python2 keepalive (3,13/0/0)
Nova-novncproxy starts the connection between the instance and user's browser session.
INFO nova.console.websocketproxy [req-399c7b58-700a-4779-b215-b12d10056813 - - - - -]\
7: connecting to: liberty:5900
Libvirt connects a vnc console into the instance, as we can see at the xml provided by virsh command. Also, port 5900 now is binded at qemu-kvm process.
Nova-novncproxy keeps the connection alive until browser session ends.
DEBUG nova.console.websocketproxy [-] \
Reaing zombies, active child count is 1 vmsg /usr/lib/python2.7/site-packages/websockify/websocket.py:828
When a token is not valid while authenticating against nova-consoleauth, we can see a message like the following.
INFO nova.console.websocketproxy [req-9164b32d-3ce1-441b-82c7-6c23c9a354d0 - - - - -] \
handler exception: The token '3dfcd011-28f1-4cf3-8f5c-8cd18de4560e' is invalid or has expired