-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create backup action #171
Create backup action #171
Conversation
…pse-create-backup-action-workload
src/backup.py
Outdated
|
||
# A smaller value will minimise memory requirements. A bigger value can make the transfer faster. | ||
S3_MAX_CONCURRENT_REQUESTS = 1 | ||
PASSPHRASE_FILE = "/root/.gpg_passphrase" # nosec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is the right place. Any idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the key location? This would imply running synapse as root user, which contravenes the least privilege principle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That file is to store the passphrase key to use when encrypting (using the gpg
command).
I put it in a file so I do not have it in a shell command (not run something like tar | gpg -password plainpassword | aws s3 ...
.
But it is an interesting point, running the backup as another user, not the root, that is the default when running container.exec (I am going to check if it works). where do you think would be a good place to put the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps under the application directory (/srv/synapse/...
I guess) or under $HOME
(wherever that is)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the location of the passphrase file to Synapse config dir. I haven't changed to run it as the Synapse user as it is managed by the startup script and it is not fully configured (has no home dir for example).
WDYT?
BackupError: If there was a problem calculating the size. | ||
""" | ||
command = "set -euxo pipefail; du -bsc " + paths_to_args(paths) + " | tail -n1 | cut -f 1" | ||
exec_process = container.exec([BASH_COMMAND, "-c", command]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try catch
Test coverage for 9060821
Static code analysis report
|
closed as it will be done in another branch |
Applicable spec: ISD095
Overview
This PR creates the action
create-backup
to back up Synapse, using the s3 integration to getS3 credentials and the
backup_passphrase
config variable to use as the encryptionkey.
To create a backup, a tar file is created with all the files that are required for the
backup, then it is encrypted and sent to a S3 compatible object storage. All these
operations are done in the Synapse container using container.exec with a shell
command using pipes, like
tar -c <paths> | gpg --symmetric <options> | aws s3 cp <options>
. Forthat command to work, the gpg
passphrase
to use was previously copied to thecontainer filesystem as a file and the aws client configured with the necessary options and
environment variables.
Besides, the aws s3 command has an option to give the expected size of the object to upload (
--expected-size
). This is required so the aws s3 cp can calculate the correct size for the multipart uploads. This is done in this PR using a baredu
command with all the paths to back up.Rationale
Synapse data and config directories should be backed up for disaster and recovery purposes.
Juju Events Changes
Added
create-backup
action.Module Changes
The entry point for the logic is the
backup_observer
, which register a handler for thecreate-backup
action.All the rest of the logic is inside the
backup
module, that performs several actions in the workload tostream the backup, as explained in the overview section.
Library Changes
Checklist
src-docs
urgent
,trivial
,complex
)