5

私の appengine アプリは cloudstorage ファイルを作成します。ファイルは第三者によってダウンロードされます。ファイルには個人の医療情報が含まれています。

ダウンロードの好ましい方法は次のとおりです。

  1. ユーザー READER acl で GCS の直接ダウンロード リンクを使用する。
  2. または、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))
4

1 に答える 1

3

少数のユーザーがバケット内のすべてのファイルにアクセスできる場合は、解決策 1 で十分です。ACL の管理はそれほど面倒ではないからです。

ただし、バケット内の異なるファイルへの異なるアクセスを必要とする多数の異なるユーザーがいる場合、解決策 1 は実用的ではありません。

不必要な着信/発信 GAE 帯域幅に料金を支払うことになるため、解決策 2 も避けます。

おそらく 3 つ目の解決策として、App Engine ハンドル認証を使用し、どのユーザーがどのファイルにアクセスできるかを判断するロジックを記述することです。次に、ファイルのダウンロードがリクエストされたら、署名付き URLを作成して GCS からデータを直接ダウンロードします。有効期限パラメーターを適切な値に設定すると、一定の時間が経過すると URL が無効になります。

于 2015-04-24T13:47:23.810 に答える