-
Notifications
You must be signed in to change notification settings - Fork 763
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Ability to Store Export Data in AWS S3 Bucket (#45)
* Allow override of image and version for exports * Refactor export storage specification * Add aws export example * Add initial support for exports to AWS * Add documentation for ArgoCDExport resource
- Loading branch information
Showing
23 changed files
with
818 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM argoproj/argocd:v1.5.1 | ||
|
||
COPY util.sh /usr/local/bin/argocd-operator-util |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#!/bin/sh -e | ||
|
||
# Copyright 2020 ArgoCD Operator Developers | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
BACKUP_SCRIPT=$0 | ||
BACKUP_ACTION=$1 | ||
BACKUP_LOCATION=$2 | ||
BACKUP_FILENAME=argocd-backup.yaml | ||
BACKUP_EXPORT_LOCATION=/tmp/${BACKUP_FILENAME} | ||
BACKUP_ENCRYPT_LOCATION=/backups/${BACKUP_FILENAME} | ||
BACKUP_KEY_LOCATION=/secrets/backup.key | ||
|
||
export_argocd () { | ||
echo "exporting argo-cd" | ||
create_backup | ||
encrypt_backup | ||
push_backup | ||
echo "argo-cd export complete" | ||
} | ||
|
||
create_backup () { | ||
echo "creating argo-cd backup" | ||
argocd-util export > ${BACKUP_EXPORT_LOCATION} | ||
} | ||
|
||
encrypt_backup () { | ||
echo "encrypting argo-cd backup" | ||
echo "backup hash: `md5sum ${BACKUP_KEY_LOCATION}`" | ||
echo "export hash: `md5sum ${BACKUP_EXPORT_LOCATION}`" | ||
|
||
openssl enc -aes-256-cbc -pbkdf2 -pass file:${BACKUP_KEY_LOCATION} -in ${BACKUP_EXPORT_LOCATION} -out ${BACKUP_ENCRYPT_LOCATION} | ||
rm ${BACKUP_EXPORT_LOCATION} | ||
|
||
echo "encrypt hash: `md5sum ${BACKUP_ENCRYPT_LOCATION}`" | ||
} | ||
|
||
push_backup () { | ||
case ${BACKUP_LOCATION} in | ||
"aws") | ||
echo "pushing argo-cd backup to aws" | ||
BACKUP_BUCKET_NAME=`cat /secrets/aws.bucket.name` | ||
BACKUP_BUCKET_URI="s3://${BACKUP_BUCKET_NAME}" | ||
aws s3 mb ${BACKUP_BUCKET_URI} | ||
aws s3api put-public-access-block --bucket ${BACKUP_BUCKET_NAME} --public-access-block-configuration "BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true" | ||
aws s3 cp ${BACKUP_ENCRYPT_LOCATION} ${BACKUP_BUCKET_URI}/${BACKUP_FILENAME} | ||
;; | ||
*) | ||
# local and unsupported backends | ||
esac | ||
} | ||
|
||
import_argocd () { | ||
echo "importing argo-cd" | ||
pull_backup | ||
decrypt_backup | ||
load_backup | ||
echo "argo-cd import complete" | ||
} | ||
|
||
pull_backup () { | ||
case ${BACKUP_LOCATION} in | ||
"aws") | ||
echo "pulling argo-cd backup from aws" | ||
BACKUP_BUCKET_NAME=`cat /secrets/aws.bucket.name` | ||
BACKUP_BUCKET_URI="s3://${BACKUP_BUCKET_NAME}" | ||
aws s3 cp ${BACKUP_BUCKET_URI}/${BACKUP_FILENAME} ${BACKUP_ENCRYPT_LOCATION} | ||
;; | ||
*) | ||
# local and unsupported backends | ||
esac | ||
} | ||
|
||
decrypt_backup () { | ||
echo "decrypting argo-cd backup" | ||
echo "backup hash: `md5sum ${BACKUP_KEY_LOCATION}`" | ||
echo "encrypt hash: `md5sum ${BACKUP_ENCRYPT_LOCATION}`" | ||
|
||
openssl enc -aes-256-cbc -d -pbkdf2 -pass file:${BACKUP_KEY_LOCATION} -in ${BACKUP_ENCRYPT_LOCATION} -out ${BACKUP_EXPORT_LOCATION} | ||
|
||
echo "export hash: `md5sum ${BACKUP_EXPORT_LOCATION}`" | ||
} | ||
|
||
load_backup () { | ||
echo "loading argo-cd backup" | ||
argocd-util import - < ${BACKUP_EXPORT_LOCATION} | ||
} | ||
|
||
usage () { | ||
echo "usage: ${BACKUP_SCRIPT} export|import" | ||
} | ||
|
||
case ${BACKUP_ACTION} in | ||
"export") | ||
export_argocd | ||
;; | ||
"import") | ||
import_argocd | ||
;; | ||
# TODO: Implement finalize action to clean up cloud resources! | ||
*) | ||
usage | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.