Bug 1383342

Summary: [RFE] API ticket support in graphics devices
Product: [oVirt] ovirt-engine Reporter: Filip Krepinsky <fkrepins>
Component: RestAPIAssignee: Martin Betak <mbetak>
Status: CLOSED CURRENTRELEASE QA Contact: Israel Pinto <ipinto>
Severity: high Docs Contact:
Priority: unspecified    
Version: 4.0.3CC: bugs, fkrepins, jbelka, juan.hernandez, mavital, pstehlik, trichard
Target Milestone: ovirt-4.1.0-alphaKeywords: FutureFeature
Target Release: 4.1.0.2Flags: michal.skrivanek: ovirt-4.1?
ipinto: testing_plan_complete+
rule-engine: planning_ack?
michal.skrivanek: devel_ack+
rule-engine: testing_ack+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
This feature allows you to request a console ticket for a specific graphics device via the REST API. The existing endpoint, /api/vms/{vmId}/ticket, defaulted to SPICE in scenarios when SPICE+VNC was configured as the graphics protocol, making it impossible to request a VNC ticket. Now, a ticket action has been added to the /api/vms/{vmId}/graphicsconsoles/{consoleId} resource, making it possible to request a ticket for a specific console. This specific endpoint is now preferred, and the pre-existing per-VM endpoint is considered deprecated.
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-02-01 14:38:28 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Virt RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
vdsm.log none

Description Filip Krepinsky 2016-10-10 12:45:51 UTC
Created attachment 1208863 [details]
vdsm.log

Description of problem:
It is not possible to connect to VNC with /api/vms/{vmId}/ticket if VNC + SPICE is enabled.

It works if we set vm's console protocols to standalone VNC.
It also works if we setup VNC + SPICE and connect with a password from vv file.

Version-Release number of selected component (if applicable):
4.0.0 and 4.0.3

Steps to Reproduce:
1. set vm's console protocols to VNC + SPICE
2. get vv file for VNC
3. get /api/vms/{vmId}/ticket
4. rewrite vv file's password with the ticket
5. connect 

Actual results:
Authentication failed

Comment 1 Juan Hernández 2016-10-11 12:03:01 UTC
This should probably work, but I wonder why do you need to replace the password that is inside the .vv file? I'd suggest to avoid doing that.

Comment 2 Michal Skrivanek 2016-10-12 10:04:44 UTC
Filipe, I also do not quite understand what are you trying to do and what exactly fails. Can you please add a bit more details?

Comment 3 Michal Skrivanek 2016-10-12 11:32:24 UTC
after offline discussion we want to add a proper ticketing support for multiple graphics
The current vms/<id>/ticket is a legacy one always preferring SPICE. It should be made obsolete in favor of this new per-graphics API

Comment 4 Filip Krepinsky 2016-10-12 12:05:52 UTC
(In reply to Juan Hernández from comment #1)
> This should probably work, but I wonder why do you need to replace the
> password that is inside the .vv file? I'd suggest to avoid doing that.

I made an secondary example with .vv file, but in our use case in moVirt we are not using it. We are just getting the ticket + separately console's address and port from the API. I think the problem should be the same.

Comment 5 Juan Hernández 2016-10-12 16:47:09 UTC
OK, please make sure to document this behaviour in the sepcification of the existing "ticket" operation. I mean here:

  https://github.com/oVirt/ovirt-engine-api-model/blob/master/src/main/java/services/VmService.java#L657-L690

It should contain something like this:

  /**
   * ...
   *
   * [IMPORTANT]
   * ====
   * If the virtual machine is configured to support only one graphics protocol
   * then the generated authentication token will be valid for that protocol.
   * But if the virtual machine is configured to support multiple protocols,
   * VNC and SPICE, then the authentication token will only be valid for
   * the SPICE protocol.
   *
   * In order to obtain an authentication token for a specific protocol, for
   * example for VNC, use the `ticket` method of the <<services/graphics_console,
   * service>> that manages the graphics consoles of the virtual machine, sending
   * a request like this:
   *
   * ....
   * POST /ovirt-engine/api/vms/123/graphicsconsoles/564E43/ticket
   * ....
   * ====
   */
  interface Ticket {
    ...
  }

This is assuming that we will add an "ticket" method to the graphics console service:

  https://github.com/oVirt/ovirt-engine-api-model/blob/master/src/main/java/services/GraphicsConsoleService.java

This new method should, if possible, behave like the existing "ticket" method, but should return authentication tokens valid for the specific protocol.

This is my understanding, please feel free to correct me.

Comment 6 Sandro Bonazzola 2016-12-12 13:57:26 UTC
The fix for this issue should be included in oVirt 4.1.0 beta 1 released on December 1st. If not included please move back to modified.

Comment 7 Israel Pinto 2017-01-11 13:54:14 UTC
Verify: 
Engine:
oVirt Engine Version: 4.2.0-0.0.master.20170104114928.git5490b36.el7.centos
Host:
OS Version:RHEL - 7.3 - 7.el7
Kernel Version:3.10.0 - 514.el7.bug1404060_20.x86_64
KVM Version:2.6.0 - 28.el7_3.3
LIBVIRT Version:libvirt-2.0.0-10.el7_3.2
VDSM Version:vdsm-4.20.0-128.git7001c0a.el7.centos
SPICE Version:0.12.4 - 19.el7

Steps:
1. Create VM and set the console option to: VNS + SPICE 
2. Run VM and connect to VNC session 
3. Via REST send POST request:
    https://{engine FQDN}/ovirt-engine/api/vms/{VM-id}/graphicsconsoles/{consoleId}/ticket 
    with empty action: <action/>
    expect response returns the ticket info:
    <action>
    <ticket>
        <expiry>{int value}</expiry>
        <value>{string value}</value>
    </ticket>
    </action>
4. Retest with SPICE session.

Results:
In spice and vnc the ticket info (expiry and value) returns.