私の appengine アプリは cloudstorage ファイルを作成します。ファイルは第三者によってダウンロードされます。ファイルには個人の医療情報が含まれています。
ダウンロードの好ましい方法は次のとおりです。
- ユーザー READER acl で GCS の直接ダウンロード リンクを使用する。
- または、appengine アプリで blobstore ダウンロード ハンドラーを使用します。
どちらのソリューションでも、サードパーティによるログイン (Google ログイン) が必要です。パフォーマンスは問題ではありません。プライバシーとセキュリティ エラーや間違いの発生です。
暗号化された zip ファイルを使用してダウンロードすることもできます。これは、プロジェクトにパスワードを保存する必要があることを意味します。または、ランダムなパスワードを電子メールで送信しますか?
更新署名付きダウンロード URL の作成に使用した appengine コード
import time
import urllib
from datetime import datetime, timedelta
from google.appengine.api import app_identity
import os
import base64
API_ACCESS_ENDPOINT = 'https://storage.googleapis.com'
# Use the default bucket in the cloud and not the local SDK one from app_identity
default_bucket = '%s.appspot.com' % os.environ['APPLICATION_ID'].split('~', 1)[1]
google_access_id = app_identity.get_service_account_name()
def sign_url(bucket_object, expires_after_seconds=60):
""" cloudstorage signed url to download cloudstorage object without login
Docs : https://cloud.google.com/storage/docs/access-control?hl=bg#Signed-URLs
API : https://cloud.google.com/storage/docs/reference-methods?hl=bg#getobject
"""
method = 'GET'
gcs_filename = '/%s/%s' % (default_bucket, bucket_object)
content_md5, content_type = None, None
expiration = datetime.utcnow() + timedelta(seconds=expires_after_seconds)
expiration = int(time.mktime(expiration.timetuple()))
# Generate the string to sign.
signature_string = '\n'.join([
method,
content_md5 or '',
content_type or '',
str(expiration),
gcs_filename])
_, signature_bytes = app_identity.sign_blob(signature_string)
signature = base64.b64encode(signature_bytes)
# Set the right query parameters.
query_params = {'GoogleAccessId': google_access_id,
'Expires': str(expiration),
'Signature': signature}
# Return the download URL.
return '{endpoint}{resource}?{querystring}'.format(endpoint=API_ACCESS_ENDPOINT,
resource=gcs_filename,
querystring=urllib.urlencode(query_params))