google-app-engine - App Engine 上的云存储和安全下载策略。 GCS acl 或 blobstore

标签 google-app-engine authentication google-cloud-storage acl blobstorage

我的应用引擎应用创建云存储文件。这些文件将由第三方下载。这些文件包含个人医疗信息

首选的下载方式是什么:

  1. 使用带有用户 READER acl 的直接 GCS 下载链接。
  2. 或者在应用引擎应用程序中使用 blobstore 下载处理程序。

两种方案都需要第三方登录(google登录)。性能不是问题。隐私和安全错误和错误的发生是。

使用加密的 zip 文件下载是一种选择。这意味着我必须将密码存储在项目中。或者通过电子邮件发送一个随 secret 码?

更新我用来创建签名下载 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))

最佳答案

如果少数用户可以访问存储桶中的所有文件,那么解决方案 #1 就足够了,因为管理 ACL 不会太麻烦。

但是,如果您有许多不同的用户,每个用户都需要对存储桶中的不同文件进行不同的访问,那么解决方案 #1 就不切实际。

我也会避免使用解决方案 #2,因为您需要为不必要的传入/传出 GAE 带宽付费。

也许要考虑的第三种解决方案是使用 App Engine 处理身份验证,并编写逻辑来确定哪些用户可以访问哪些文件。然后,当请求下载文件时,您创建 Signed URLs直接从 GCS 下载数据。您可以将过期参数设置为适合您的值,这将使 URL 在设定的时间后失效。

关于google-app-engine - App Engine 上的云存储和安全下载策略。 GCS acl 或 blobstore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29847759/

相关文章:

c# - 根据 JWT 身份验证 token 中的声明验证请求中的 IP

google-cloud-storage - 对象不继承桶权限

python - 当tbody为空时如何隐藏thead?

google-app-engine - 应用引擎 : How to "reset" the datastore?

java - 如何在wicket中进行weblogic表单认证

google-app-engine - "App Engine flexible environment"(以前称为 "Managed VMs")中的 Google App Engine 导入问题 (golang)

python - 如何在 Python 中列出 Google Cloud Bucket 文件夹中的所有对象?

google-app-engine - Appengine API 调用 : Application restrictions: HTTP referrers (websites) or IP addresses (web servers, cron 作业等)

java - 在使用 googleapp 引擎时使用 apache commons 库

iframe - 在 iframe 中显示 Salesforce 登录表单