summaryrefslogtreecommitdiff
path: root/src/state_machine.hpp
AgeCommit message (Collapse)AuthorFilesLines
2022-03-15Make mount/unmount dbus calls asynchronousPrzemyslaw Czarnowski1-1/+47
Change the default behavior of mount/umount dbus calls from blocking to unblocking ones. Once mount/unmount is triggered, appropriate action is running in the background moving handling of operation result to async event. At the end of processing dbus completion signal is sent to client with uint value of operation status (identical with errno code). Tested: Manual scheduling of mount and unmount operations with monitoring dbus communication of virtual-media service - matching api calls with completion signal. Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
2022-01-26Add -Wextra, remove warnings (#1)Przemyslaw Czarnowski1-1/+1
Removed all -Wextra warnings in VM sources. -Wno-unused-parameter has to be disabled due to lots of such warnings in sdbusplus. Tested: Compilation generates no warnings Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
2021-05-06Change log level to InfoCzarnowski, Przemyslaw1-3/+2
Due to security reasons "user/username" has to be removed from the information that is logged by application. Sensitive data has been moved to "Debug"" level (lowest one) and default one has moved one level up to "Info". Also some important information allowing to catch basic errors has been upgraded to "Info". Tested: Manually, mounting both Legacy mode remote types (HTTPs and CIFS) and checking if journal for VirtualMedia service does not contain sensitive information. Change-Id: Ie6c3a79c94637e3632af76daf957e986b2dd3b6d Signed-off-by: Czarnowski, Przemyslaw <przemyslaw.hawrylewicz.czarnowski@intel.com>
2020-07-17Fixing multiple problems with state machine in virtual mediaKrzysztof Grobelny1-1041/+50
- Previously machine did not handle AnyEvent correctly, implementation in BaseState was always run - Changing from ActiveState to ReadyState was bugged, previously only one of event SubprocessStopped or UdevNotification caused state change when it is required to wait for both - Introduced longer timer when waiting for ReadyState during Eject and ActiveState during Inject, because ndbkit can timeout during Eject and it is required to complete before next inject can success. - Added event notification when process is terminated - Added resourcess classes to handle deletion and notifications Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com> Signed-off-by: Karol Wachowski <karol.wachowski@intel.com> Change-Id: Ie914e650c2f15bd73cdc87582ea77a94997a3472 Signed-off-by: Karol Wachowski <karol.wachowski@intel.com>
2020-07-01Use timeout value from virtual-media.json fileKarol Wachowski1-1/+1
timeout value was always set to default instead of using configuration file. Tested: verified that timeout value set in /etc/virtual-media.json is actually used by service Signed-off-by: Karol Wachowski <karol.wachowski@intel.com> Change-Id: I6865f25c91d95eb273792798f6159838cfd013c5 Signed-off-by: Karol Wachowski <karol.wachowski@intel.com>
2020-04-03Make 'Legacy mode' (mounting through HTTPS or SMB) configurable at compile time.Adrian Ambrożewicz1-0/+9
This change modifies the default configuration and removes ability to configure endpoints in such mode. Tests performed: Tested on WilsonCity for regression. Proxy mode works. Manual configuration injection (modifying virtual-media.json) didn't enable Legacy endpoints - they are ignored. Change-Id: Idb63f1cf0f391dc428d6ad3d8e3684017d509369 Signed-off-by: Adrian Ambrożewicz <adrian.ambrozewicz@linux.intel.com>
2020-02-28Fix for 'Mounting image using legacy mode with invalid credentialsAgata Olender1-2/+8
restart VM service'. Due to unsuccessful mounting of image, mount point changes state to ReadyState and perform reset on target object. Target is no longer available so fix assumes adding verification against null value before performing other reset on target fields. Tested manually for scenarios with valid and invalid passwords. Change-Id: I6c9d5f680f76af3c2ba609a7889552345451cf28 Signed-off-by: Agata Olender <agata.olender@intel.com>
2020-02-20Add handling of exit code property.Agata Olender1-6/+11
Property returns exit code value from nbd-client process for proxy mode and from nbdkit process for legacy mode. The initial value for this property is -1 and will be returned before starting the process and in the process execution time. Tested manually for proxy and legacy mode: - initial value before process first run - initial value in process execution time - 0 value for successful exit - specific value for forced process termination Change-Id: I4cefa423bade522fc2fac0cab620cbba0b66cce2 Signed-off-by: Agata Olender <agata.olender@intel.com>
2020-02-06Authentication support for Legacy modeAgata Olender1-12/+90
This change introduces new 'Mount' API argument - UNIX_FD for named pipe. This named pipe is utilized to securely send secret data over D-Bus. Currently data consists of null-terminated char buffers with username and password. Data on receiving side is encapsulated into classes whose role is to: - keep secret as short-lived as possible - erase secret from memory when it's not needed - pass secrets (and format them) to another secure container with above capabilities New classes: - Credentials: is a class encapsulating login and password. It zeroes them at destruction. - CredentialProvider: contains Credentials, specifies SecureBuffer, allows to store credentials in SecureBuffer - SecureBuffer: char vector which zeroes itself at destruction, used to provision secret data - VolatileFile: class creating temporary file with 'owner-only' permissions in /tmp; at destruction overwrites it's contents with '*' and removes it New behavior: - when UNIX_FD is provided over D-Bus it's treated as open unix pipe. Data is read from this pipe and stored securely into CredentialsProvider - credentials are stored in applications inside CredentialsProvider object, encapsulated by unique_ptr for as long as it's needed - strings containing secrets are zeroed immediately after use - VolatileFile is used to securely pass credentials to nbdkit curl plugin instead of command line parameters. Tested: Manual and automated tests on WilsonCity platform: - positive and negative tests for authentication on both CIFS and HTTPS resources - error injection (ill-formed data transfered over pipe, pipe broken etc.) Change-Id: I608ae0380b8ad57110bc0939f71eb48604e7dc99 Signed-off-by: Adrian Ambrożewicz <adrian.ambrozewicz@linux.intel.com> Signed-off-by: Agata Olender <agata.olender@intel.com>
2020-02-06Detailed error handlingAgata Olender1-18/+50
Previously implemented error handling for Mount checks only if mounting was successful and returns boolean with the result. Following change introduces optional error to existing ReadyState (a.k.a. "idle state"). If state machine enters ReadyState with error it is stored into ReadyState field with std::errc and std::string message. In the case of mount failure with such error information stored, Mount returns graceful D-Bus error reply with specific error code. Tested: Manual and automated tests on WilsonCity platform: - negative tests for invalid network share, unauthorized share access, error injection (renaming expected unix socket names etc) Change-Id: I22cf9b17e9e6342aad0ae68766853734fac79b8e Signed-off-by: Adrian Ambrożewicz <adrian.ambrozewicz@linux.intel.com> Signed-off-by: Agata Olender <agata.olender@intel.com>
2020-02-06Integration with NBDKit for Legacy modeAgata Olender1-17/+163
This change introduces integration of virtual-media application with NBDKit. NBDKit is used here to connect to externally provided image on web and expose NBD device internally in BMC for NBD subsystem (already implemented in Proxy mode) to use. 'Mount' D-Bus call accepts 's imgUrl' and 'b rw'. Based on 's imgUrl' prefix (https:// or smb://) proper mount type is attempted. 'b rw' determines Read-Only mode for both USB Gadget and NBD stack. When 'Mount' is called, virtual-media parses arguments, determines mounting options and attempts to mount external share. For SMB protocol native CIFS Linux module is used: 1) mount(8) call is used to mound provided CIFS share 2) NBDKit loads file on mounted filesystem and exposes NBD Server on internal unix socket 3) Pre-existing code takes care of mouting gadget automatically (connecting socket to /dev/nbdX and then /dev/nbdX to USB Gadget) For HTTPS protocol provisioning is performed by NBDKit: 1) NBDKit connects to provided resource and exposes NBD Server on internal unix socket 2) Pre-existing code takes care of mouting gadget automatically (connecting socket to /dev/nbdX and then /dev/nbdX to USB Gadget) Tested: Manual and automated tests on WilsonCity platform: - mounting and unmounting images over CIFS and HTTPS (single, multiple at the same time etc) - positive and negative tests for D-Bus calls - ensuring proper information is exposed on D-Bus Change-Id: Ia2b6e8c13603521063f5c94cdfdb06f2e872e9e7 Signed-off-by: Adrian Ambrożewicz <adrian.ambrozewicz@linux.intel.com> Signed-off-by: Agata Olender <agata.olender@intel.com>
2020-01-29Gadget inactivity timeoutAgata Olender1-0/+66
MountPoints being inactive for time defined by InactivityTimeout will be unmounted. Inacitivity is measured based on USB gadget R/W statitics. InactivityTimeout must be set in json configuration and is common for all MountPoints. Remaining time to unmount inactive media is exposed per MountPoint on dbus using RemainingInactivityTimeout property. Change-Id: Ieb80e67dae6c3b4cb0482d801b5b4208884b0809 Signed-off-by: Agata Olender <agata.olender@intel.com>
2020-01-29Manage remote media state transitionsCzarnowski, Przemyslaw1-0/+766
This is a first part of bigger functionality which provides host to use virtual media. First part provides skeleton and definitions of states and events defining state machine, also brings working implementation of proxy mode and some starting point to implement legacy mode. There are at least three additional patchsets implementing legacy mode with https and cifs support and secure passing of secrets. Specifically this change adds StateMachine class used to keep track state of each mount point: - StateMachine is made as std::variant of object derived from BasicState. - Each state has its own possible transitions defined (events). - Transitions defines appropriate behavior. - Specific event triggers transition from one to other specific state (1:1 relation). Tested: Manual tests on WilsonCity platform: - mounting and unmounting using redfish and webui - check state on dbus interfaces Change-Id: I4b13085e1f8884fcedd7d97e76910c21e87ab7f8 Signed-off-by: Rapkiewicz, Pawel <pawel.rapkiewicz@intel.com> Signed-off-by: Czarnowski, Przemyslaw <przemyslaw.hawrylewicz.czarnowski@intel.com>