博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Cloud Design Pattern - Valet Key Pattern
阅读量:2235 次
发布时间:2019-05-09

本文共 2928 字,大约阅读时间需要 9 分钟。

1.前言

前一篇我们讨论了,了解了如何通过设定系统的资源消耗阀值来控制资源使用率及如何快速弹性扩容.这一篇我们了解下如何控制对应用程序依赖但不受应用程序控制的资源的访问.在静态资源托管模式中,我们把应用所依赖的某些静态部分存储在云存储中,通过存储服务进行读取,这时候我们就需要设计一种机制来确保云存储中资源的访问都是经过应用程序授权的.

2.概念

在前言中其实已经道出了Valet key模式的核心思想,那就是通过应用程序的授权机制,确保用户对不通过应用程序进行加载的资源的访问都是经过授权的合法访问.这种问题的解决方案是如何运作的呢?下图很好地展示了这种解决方案!

这种方式的根本目的在于限制用户对资源的访问的时间和范围,即用户只在这一次访问中对特定的某些资源有访问权限.这种模式能够大量简化用户的授权,角色的管理,权限的移除等等.

3.需要考虑的问题

1) 管理认证的状态及key的周期

2) 控制访问资源的key的级别

3) 如何控制用户的行为

4) 校验和数据过滤

5) 对所有操作的审核

6) key的安全传送

7) 保护敏感数据

4.何时使用

关于何时使用这种模式,官方给出了以下几点建议:

1)如果需要最小化静态资源下载,从而提升性能,并且对扩展性也有相应的要求

2)最小化操作的费用

3)数据存储在分布在不同的数据中心

5.Example

Micresoft Azure Storage 支持Shared Access Signatures (SAS)机制,可以对blob,table,queue进行这种控制.SAS token可以配置成对资源的read,write,update,并且可以配置时间限制(某个时间段或者无限制)

public class ValuesController : ApiController{  private readonly CloudStorageAccount account;  private readonly string blobContainer;  ...  ///   /// Return a limited access key that allows the caller to upload a file   /// to this specific destination for a defined period of time.  ///   private StorageEntitySas GetSharedAccessReferenceForUpload(string blobName)  {    var blobClient = this.account.CreateCloudBlobClient();    var container = blobClient.GetContainerReference(this.blobContainer);    var blob = container.GetBlockBlobReference(blobName);    var policy = new SharedAccessBlobPolicy    {      Permissions = SharedAccessBlobPermissions.Write,      // Specify a start time five minutes earlier to allow for client clock skew.      SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-5),      // Specify a validity period of five minutes starting from now.       SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(5)    };    // Create the signature.     var sas = blob.GetSharedAccessSignature(policy);    return new StorageEntitySas    {      BlobUri = blob.Uri,      Credentials = sas,      Name = blobName    };  }  public struct StorageEntitySas  {    public string Credentials;    public Uri BlobUri;    public string Name;  }}
上面的代码演示了这种模式的实现,Azure对这方面的支持都是基于这种模式来实现的.

6.相关阅读

The following patterns and guidance may also be relevant when implementing this pattern:

  • . This pattern can be used in conjunction with the Valet Key pattern to protect applications and services by using a dedicated host instance that acts as a broker between clients and the application or service. The gatekeeper validates and sanitizes requests, and passes requests and data between the client and the application. This pattern can provide an additional layer of security, and reduce the attack surface of the system.
  • . This pattern describes how to deploy static resources to a cloud-based storage service that can deliver these resources directly to the client in order to reduce the requirement for expensive compute instances. Where the resources are not intended to be publicly available, the Valet Key pattern can be used to secure them.
  • The article  on the Azure Storage Team blog.
  •  on MSDN.
  •  on MSDN.

你可能感兴趣的文章
HashMap 和 HashTable 到底哪不同 ?
查看>>
Java实现简单的递归操作
查看>>
Struts2工作原理和执行流程图
查看>>
在线预览Word,Excel~
查看>>
hibernate延迟加载(get和load的区别)
查看>>
关于文件拷贝效率问题
查看>>
MyBatis分页插件PageHelper的使用
查看>>
【MyBatis学习01】宏观上把握MyBatis框架
查看>>
【MyBatis学习02】走进MyBatis的世界
查看>>
【MyBatis学习03】原始dao开发方法及其弊端
查看>>
【MyBatis学习04】mapper代理方法开发dao
查看>>
【MyBatis学习05】SqlMapConfig.xml文件中的配置总结
查看>>
【MyBatis学习06】输入映射和输出映射
查看>>
【MyBatis学习07】动态sql
查看>>
【MyBatis学习08】高级映射之一对一查询
查看>>
【MyBatis学习09】高级映射之一对多查询
查看>>
【MyBatis学习10】高级映射之多对多查询
查看>>
【MyBatis学习11】MyBatis中的延迟加载
查看>>
【MyBatis学习12】MyBatis中的一级缓存
查看>>
【MyBatis学习13】MyBatis中的二级缓存
查看>>