ArduPilot / companion

Companion computer startup scripts and examples
GNU General Public License v3.0
104 stars 164 forks source link

Initial log upload support #21

Open peterbarker opened 7 years ago

peterbarker commented 7 years ago

We need some preliminary, rudimentary log upload support. This will be superseded by something more intelligent later.

Currently the DataFlash logs are written to ~apsync/dflogger/dataflash.

We need to get those logs off the companion computer and onto a server somewhere (heretoforth known as "the cloud")

Proposal:

Doing the files individually has the advantage that we will avoid pushing the same file up multiple times into differently-timestamped directories should the rsync transfer be interrupted by e.g. the CC machine being rebooted. The lack of --partial on the receiver end should mean that we don't end up with partial logs on the server, at the expense of transferring the same data multiple times.

Note that simply running rsync directly on the $HOME/dflogger/dataflash directory will seldom succeed as a file is constantly being written in that directory.

SamuelDudley commented 7 years ago

Outdated Proposal - See my next proposal below

@peterbarker My current work adding this feature can be found here. I’m attempting to follow your proposal but have hit a bit of an issue with the cloudsync_dir. Basically the log is rsync’d from the dflogger directory and I can't find a good way to rsync it to a non-existent target directory without first making the directory on the server. For the time being I’m dumping the logs into the cloudsync_user’s home directory on the server.

I’m using pre shared keys for authentication with the server. It’s quite simple for someone to replicate the server setup if they wanted to manage their own logs, but i'm assuming that the end goal is to have one server used by many users & vehicles.

One idea is as follows (edit - added some details):

One time registration with datalog server

One time setup on the companion computer

This can all be automated from a webform being served by the companion computer

Normal operation

The companion computer wants to rsync a log

Accessing the logs on the datalog server

When a user wants to retrieve logs they have sent to the datalog server

Making this somewhat secure would be a bit of a challenge, but we could chroot jail a user to the assigned folder for that particular one time upload? https://linuxconfig.org/how-to-automatically-chroot-jail-selected-ssh-user-logins https://serverfault.com/questions/287578/trying-to-setup-chrootd-rsync

Just ideas, but let me know your thoughts.

SamuelDudley commented 7 years ago

Current Proposal

@davidbuzz mentioned some really good ideas with regards to making the process easier for users. I'll try and capture those ideas here, but in general:

One time registration with datalog server + setup of the companion computer

Significantly reduces the user setup effort

user steps:
  1. Enter the address of the datalog server or leave the default on the companion computer web UI
  2. Enter your email and optionally a vehicle ID on the companion computer web UI
  3. On the companion computer web UI a button is pushed to 'register'
  4. In the received email a confirmation link is clicked
    all steps:
    • On the companion computer web UI the user enters the address of the datalog server e.g. www.apsync.cloud, their email and an optional unique vehicle ID
    • On the companion computer a button is pushed to 'register' with the server
    • A ssh key pair is generated automatically (thanks @davidbuzz :+1: )
    • A REST endpoint or websocket on the server is pushed / connected to via a TLS/SSL
    • The user email, unique vehicle ID (optional) and public key are sent to the server
    • An email is sent to the user from the server asking them to confirm via clicking on a link in the email
    • Once the link is confirmed, if a vehicle ID was not provided to the server, one is generated and the server associates that public key with the email + vehicle ID combo.
    • The companion computer detects the user has confirmed the email via push or challenge REST request and receives a generic username, unique vehicle id, and port number for the server
    • The configuration file on the companion computer is automatically updated and saved for future use

Normal operation

The companion computer wants to rsync a log

user steps:

N/A

all steps:

Accessing the logs on the datalog server

When a user wants to retrieve logs that have been rsync'd with the datalog server

user steps via 'normal' access :
  1. Navigate to website
  2. Login
    user steps via companion computer access :
  3. Open the correct screen in the companion computer web UI
    all steps:
    • Users navigate to datalog server web front end and login using the email address and ssh public key string (a bit painful?)
    • Perhaps there is an option to login with a linked google / github / ardupilot.org account to simplify things?
    • User is provided with a list of registered vehicles and can browse the associated logs
    • There could be further functions to download / perform analysis on the logs
    • The web UI on the companion computer is also capable of connecting via a REST backend to display a list of sync'd logs for the associated email address (all vehicles) and ssh public key combo