rcloneでAmazonCloudDriveにデータを暗号化して同期する

Linux

2017/6/4
RcloneのAmazonCloudDrive接続がClientIDが無効になったことによりできなくなっています。
https://forum.rclone.org/t/rclone-has-been-banned-from-amazon-drive/2314

rcloneが暗号化に対応したと聞いて試してみた。

やること

rcloneを使用してローカルのファイルをAmazonCloudDriveと同期する。
rcloneの機能でAmazonCloudDrive上にデータをアップロードする際は暗号化し、ダウンロードする際は復号化する。

暗号化の必要性

Amazon Cloud Drive利用規約を読むと、アマゾンがファイルにアクセスすることもありうる内容になっている。
私がアヘ顔ダブルピースしているホームビデオを見られる可能性があると困るため、暗号化してファイルを置くことが必須となる。

確認環境

ローカル側
– Ubuntu 16.04
– rclone v1.35
– Windows10(認証用)

リモート側
– Amazon Cloud Drive(プライム会員の5GB)

手順

手順は以下を参考にした。
https://www.reddit.com/r/DataHoarder/comments/598pb2/tutorial_how_to_make_an_encrypted_acd_backup_on/

Ubuntuへのrcloneインストール

ほぼ公式に書いてある手順と同一。

mkdir -p ~/work/rclone
cd ~/work/rclone

sudo apt install unzip

curl -O http://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
cd rclone-*-linux-amd64

sudo cp rclone /usr/sbin/
sudo chown root:root /usr/sbin/rclone
sudo chmod 755 /usr/sbin/rclone

sudo mkdir -p /usr/local/share/man/man1
sudo cp rclone.1 /usr/local/share/man/man1/
sudo mandb

rcloneにAmazonCloudDriveを設定

実行ユーザ毎に設定が作られる。
途中で入力するトークンは後述の方法で入手した。

$ rclone config
2017/--/-- --:--:-- Config file "/home/test/.rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n <-新規に設定を作成
name> ACD <-設定の名前をつける
Type of storage to configure.
Choose a number from below, or type in your own value
 1 / Amazon Drive
   \ "amazon cloud drive"
 2 / Amazon S3 (also Dreamhost, Ceph, Minio)
   \ "s3"
 3 / Backblaze B2
   \ "b2"
 4 / Dropbox
   \ "dropbox"
 5 / Encrypt/Decrypt a remote
   \ "crypt"
 6 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
 7 / Google Drive
   \ "drive"
 8 / Hubic
   \ "hubic"
 9 / Local Disk
   \ "local"
10 / Microsoft OneDrive
   \ "onedrive"
11 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
12 / Yandex Disk
   \ "yandex"
Storage> 1 <-AmazonCloudDriveを使うので1
Amazon Application Client Id - leave blank normally.
client_id> <-空Enter
Amazon Application Client Secret - leave blank normally.
client_secret> <-空Enter
Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n> n <-確認したのがブラウザが開けない環境だったので、nで進めた
For this to work, you will need rclone available on a machine that has a web browser available.
Execute the following on your machine:
        rclone authorize "amazon cloud drive"
Then paste the result below:
result> *** <-後述の方法で入手したトークンを貼り付け
--------------------
[ACD]
client_id =
client_secret =
token = ****
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y <-設定完了
Current remotes:

Name                 Type
====                 ====
ACD                  amazon cloud drive

e) Edit existing remote
n) New remote
d) Delete remote
s) Set configuration password
q) Quit config
e/n/d/s/q> q <-一旦終了

認証を別端末のWindows10で行う

rcloneのWindows版をダウンロードしてきて、コマンドプロンプトで以下を実施。
途中でブラウザからアマゾンの認証画面が開かれるので、ログインする。

C:\test>rclone authorize "amazon cloud drive"
2017/--/-- --:--:-- Config file "C:\\Users\\test/.rclone.conf" not found - using defaults
If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth
Log in and authorize rclone for access
Waiting for code...
Got code
Paste the following into your remote machine --->
**** <-ここに表示されるのがトークン
<---End paste

rcloneに暗号化するディレクトリを設定

AmazonCloudDrive上で暗号化するため必要な設定をする。

$ rclone config
Current remotes:

Name                 Type
====                 ====
ACD                  amazon cloud drive

e) Edit existing remote
n) New remote
d) Delete remote
s) Set configuration password
q) Quit config
e/n/d/s/q> n <-設定を作成
name> ACD_crypt <-設定に名前をつける
Type of storage to configure.
Choose a number from below, or type in your own value
 1 / Amazon Drive
   \ "amazon cloud drive"
 2 / Amazon S3 (also Dreamhost, Ceph, Minio)
   \ "s3"
 3 / Backblaze B2
   \ "b2"
 4 / Dropbox
   \ "dropbox"
 5 / Encrypt/Decrypt a remote
   \ "crypt"
 6 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
 7 / Google Drive
   \ "drive"
 8 / Hubic
   \ "hubic"
 9 / Local Disk
   \ "local"
10 / Microsoft OneDrive
   \ "onedrive"
11 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
12 / Yandex Disk
   \ "yandex"
Storage> 5 <-暗号化設定なので5
Remote to encrypt/decrypt.
Normally should contain a ':' and a path, eg "myremote:path/to/dir",
"myremote:bucket" or maybe "myremote:" (not recommended).
remote> ACD:/DataBackup/ <- 設定ディレクトリ(書き方は後述)
How to encrypt the filenames.
Choose a number from below, or type in your own value
 1 / Don't encrypt the file names.  Adds a ".bin" extension only.
   \ "off"
 2 / Encrypt the filenames see the docs for the details.
   \ "standard"
filename_encryption> 2 <-ファイル名の暗号化をする場合は2
Password or pass phrase for encryption.
y) Yes type in my own password
g) Generate random password
y/g> g <-暗号化パスワードを自動生成
Password strength in bits.
64 is just about memorable
128 is secure
1024 is the maximum
Bits> 128
Your password is: dw37uhP1Dl56Fhr8DYuZjg
Use this password?
y) Yes
n) No
y/n> y <-暗号化パスワードを承認
Password or pass phrase for salt. Optional but recommended.
Should be different to the previous password.
y) Yes type in my own password
g) Generate random password
n) No leave this optional password blank
y/g/n> g <-暗号化のソルトを自動生成
Password strength in bits.
64 is just about memorable
128 is secure
1024 is the maximum
Bits> 128
Your password is: 8UubLhAxmfQc1Cvs3UbuQw
Use this password?
y) Yes
n) No
y/n> y <-暗号化のソルトを承認
Remote config
--------------------
[ACD_crypt]
remote = ACD:/DataBackup/
filename_encryption = standard
password = *** ENCRYPTED ***
password2 = *** ENCRYPTED ***
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y <-設定に問題なければy
Current remotes:

Name                 Type
====                 ====
ACD                  amazon cloud drive
ACD_crypt            crypt

e) Edit existing remote
n) New remote
d) Delete remote
s) Set configuration password
q) Quit config
e/n/d/s/q> q <-設定ウィザードを終了

設定ディレクトリの書き方

(クラウドストレージの設定名):(ディレクトリ)
なので、上述の設定ではAmazonCloudDrive上のDataBackupディレクトリ内に暗号化したファイルを置く設定となる。

ルートに暗号化したデータを置く場合は以下の例のようにディレクトリを空にするらしい?(未検証)
– ACD:

ファイルを暗号化/復号化して同期

ローカルからAmazonCloudDriveに暗号化して同期

ローカルの/dataディレクトリからAmazonCloudDriveの/DataBackupディレクトリに同期する場合。

rclone sync /data ACD_crypt:/DataBackup/

こんな感じに暗号化されたファイル/ディレクトリができる。

AmazonCloudDriveからローカルに復号化して同期

AmazonCloudDriveの/DataBackupディレクトリからローカルの/dataディレクトリに同期する場合。

rclone sync ACD_crypt:/DataBackup/ /data

その他

  • Linuxのrcloneでアップロードしたファイルを、Windowsのrcloneで暗号化パスワードとソルトを同一にしてダウンロードすることもできた。
  • 以前にEncFSを使用して暗号化する方法も検討していたのですが、暗号化したファイルを一時的にでもローカルに置く必要がある点がネックになってました。rcloneだけでできればシンプルで便利。
  • ACDだとファイルとフォルダの名前は半角で255文字以内である必要があるのですが、ファイル名/フォルダ名の暗号化により文字数が増えて制限を超える可能性もあります。制限を超えると、rclone実行時に「failed to satisfy constraint: Member must have length less than or equal to 280」というエラーが出るかもしれません。

コメント

  1. まーこ より:

    Yasuosaiki 先輩

    おはようございます。もし知ってたら教えてください。

    ここ最近で海外版のamazon.com のCloudDriveが接続が切れましたので再接続しても以下のエラーしか出ないようになったので解決方法などもし知ってたら教えてください。

    14.2TB 使用中です。

    netdrive2 接続で Fastcopy での使用は可能です。

    よろしくお願い致します。

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    amazon.com
    申し訳ありません。
    リクエストの処理中に問題が発生しました。現在問題を調査しておりますので、解決するまでもう少々お待ちください。

    Error Summary
    400 Bad Request
    Unknown client_id
    Request Details
    client_id=amzn1.application-oa2-client.6bf18d2d1f5b485c94c8988bb03ad0e7
    redirect_uri=http%3A%2F%2F127.0.0.1%3A53682%2F
    response_type=code
    scope=clouddrive%3Aread_all+clouddrive%3Awrite
    state=6269c283fb993a8dbc781c3fbe735c8d

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

    • yasuosaiki より:

      client_idの値から、RcloneによるAmazonDriveへのアクセスで発生したエラーと仮定して返答させていただきます。
      原因としては、2017/5/20以降にAmazonがRcloneによる接続を受け付けないことに起因していると考えられ、以下がそれに関するRcloneの主開発者によるフォーラムへのポストです。
      https://forum.rclone.org/t/rclone-has-been-banned-from-amazon-drive/2314

      簡潔に内容をまとめると、RcloneにAmazonが問題と考える部分があるためRcloneによる接続を拒否しています。
      今後RcloneのAmazoneDrive対応がどうなるか、一介の利用者である私では分かりません。
      そのため、最新の情報が必要な場合は上記のフォーラム等で、公式情報を確認することをおすすめします。