Using Object Storage as a backup target
This guide sets up a bucket for off-site backups that survive the worst case: ransomware on your network, a compromised backup server, or an admin's mistake. It brings together versioning, Object Lock, a restricted backup user, client-side encryption and lifecycle rules.
What this setup protects against
| Threat | Protection |
|---|---|
| Ransomware encrypts or deletes your backups through the backup server | The backup server's key can only write. Locked versions can't be deleted or overwritten until their retention ends. |
| Someone steals the backup key and uses it elsewhere | The key only works from your IP range |
| Someone gets hold of the bucket owner's key | Compliance-mode Object Lock still prevents deletion until retention ends |
| Data is read in storage or on the way | Data is encrypted on your side before upload, and travels over HTTPS |
| Accidental overwrite or delete | Versioning keeps earlier versions |
You'll need aws-cli set up with the bucket owner's key, as described in Using the S3 API. The examples use DX1 and a 30-day retention. Adjust both to suit you.
1. Create the bucket with Object Lock
Object Lock has to be turned on when the bucket is created. This also turns on versioning.
cd ~
aws s3api create-bucket --bucket <bucket> --object-lock-enabled-for-bucket --profile bamboozle
2. Set a default retention
Every new version is then locked automatically, whatever tool writes it:
cd ~
aws s3api put-object-lock-configuration --bucket <bucket> --profile bamboozle \
--object-lock-configuration '{"ObjectLockEnabled":"Enabled","Rule":{"DefaultRetention":{"Mode":"COMPLIANCE","Days":30}}}'
Choose a period at least as long as you need to go back after discovering a problem. Test with "Days":1 first: Compliance locks can't be shortened, and locked data is billed until the lock ends. See Object Lock.
3. Limit what the backup user can do
Don't give your backup server the bucket owner's key. Instead:
- Contact support to create a separate S3 user for backups. You'll receive its access keys and its user ID.
- As the bucket owner, attach a bucket policy that limits that user.
Which policy you need depends on your tool.
Tools that only upload, such as a script that runs aws s3 cp, or rclone with --no-check-dest: allow s3:PutObject only. Use the upload-only policy.
restic and rclone sync also need to list the bucket and read their own metadata. restic also deletes its own lock files. Allow those actions, and nothing else:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BackupUserList",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::<domain_id>:<user_id>" },
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::<bucket>",
"Condition": { "IpAddress": { "aws:SourceIp": "203.0.113.0/24" } }
},
{
"Sid": "BackupUserReadWrite",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::<domain_id>:<user_id>" },
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::<bucket>/*",
"Condition": { "IpAddress": { "aws:SourceIp": "203.0.113.0/24" } }
},
{
"Sid": "BackupUserRemoveLocks",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::<domain_id>:<user_id>" },
"Action": "s3:DeleteObject",
"Resource": "arn:aws:s3:::<bucket>/*/locks/*",
"Condition": { "IpAddress": { "aws:SourceIp": "203.0.113.0/24" } }
}
]
}
The policy doesn't allow s3:DeleteObjectVersion, so the backup user can never remove data permanently. Even the delete it is allowed only adds a delete marker on a versioned bucket. Object Lock protects the data either way.
4. Encrypt on your side
Object Storage encrypts data at rest, but with keys held by the storage platform. If you want data that only you can read, encrypt it before upload:
- restic encrypts every backup with your repository password. Nothing extra to do, but keep the password safe. Without it, the backups can't be restored.
- rclone encrypts with a crypt remote layered over your Bamboozle remote. Create it with
rclone config, choosing typecryptand a remote such asbamboozle:<bucket>/server01.
5. Add lifecycle rules
Without cleanup, every old version is kept and billed forever. Add a rule that deletes old versions some time after their lock has expired, and clears out unfinished uploads. The backup bucket rule set is a good starting point. Set NoncurrentDays longer than your retention period.
6. Run your backups
restic
cd ~
export AWS_ACCESS_KEY_ID=<backup-user-access-key>
export AWS_SECRET_ACCESS_KEY=<backup-user-secret-key>
export RESTIC_REPOSITORY=s3:https://dxb.bbzs3.com/<bucket>/server01
export RESTIC_PASSWORD_FILE=/root/.restic-password
restic -o s3.bucket-lookup=path init
restic -o s3.bucket-lookup=path backup /etc /srv /var/backups
Run restic forget --prune (to apply your own retention, such as keeping 7 daily and 4 weekly snapshots) from a trusted admin machine with the owner's key, not from the backup server.
rclone, upload only, through a crypt remote:
cd ~
rclone copy /var/backups bamboozle-crypt: --s3-no-check-bucket --no-check-dest --progress
Backup software with an S3 target, such as Veeam or Acronis, can use the same bucket: enter the endpoint, the backup user's keys and the bucket name. If the software manages Object Lock itself, let it do so instead of setting a default retention in step 2. We haven't certified specific backup products.
7. Test a restore
A backup only counts once you've restored from it. After the first run, and regularly after that:
cd ~
restic -o s3.bucket-lookup=path check
restic -o s3.bucket-lookup=path restore latest --target /tmp/restore-test
Also check that the protection works: try to delete a backup version with the backup user's key, and confirm it's refused.
Related
- Security and data location
- Limits and compatibility
- Replication, if you need the backups in a second region as well