简体   繁体   English

如何管理要在 AWS Lambda 中使用的相互 TLS 的客户端证书

[英]How to manage client certificates for mutual TLS to be used within AWS Lambda

Our team is using AWS Lambda functions and API Gateway to facilitate connections to open banking API's within Europe.我们的团队正在使用 AWS Lambda 函数和 API 网关来促进连接到欧洲境内的开放银行 API。 ( PSD2 ). PSD2 )。

Our Lambda's are written in NodeJS.我们的 Lambda 是用 NodeJS 编写的。

PSD2 requires Mutual TLS, which is fine and we have everything correctly implemented and working in a sandbox environment. PSD2 需要 Mutual TLS,这很好,我们已经正确实施了一切并在沙盒环境中工作。

An example request would look something like this:示例请求如下所示:

{
  hostname: '[bank hostname]',
  path: '[bank api endpoint]',
  method: 'GET',
  headers: {
    accept: 'application/json',
    signature: 'XXX',
    date: 'XXX',
    digest: 'XXX',
    'x-request-id': 'XXX',
    'tpp-signature-certificate': '[PATH_TO_CERTIFICATE]',
    authorization: 'Bearer [accessToken]',
  },
  cert: fs.readFileSync('/var/task/certs/cert.crt'), // Buffer
  key: fs.readFileSync('/var/task/certs/private.key'), // Buffer
} 

The problem we currently have is that we are unsure where to securely store our certificates.我们目前遇到的问题是我们不确定在哪里安全地存储我们的证书。 For the time-being, we are just storing them in an assets folder in our codebase, this is not ideal and we would like to move them out of our codebase for obvious reasons.目前,我们只是将它们存储在代码库中的资产文件夹中,这并不理想,出于显而易见的原因,我们希望将它们从代码库中移出。

We have been looking at AWS ACM .我们一直在研究 AWS ACM However it is not clear how we would retrieve a path to certificates (after uploading them) in order to use it in the request above.但是,尚不清楚我们将如何检索证书的路径(在上传它们之后)以便在上面的请求中使用它。

So my question is how would we use AWS to securely store our certificates in such a way that we can use them in a HTTPS request?所以我的问题是我们如何使用 AWS 安全地存储我们的证书,以便我们可以在 HTTPS 请求中使用它们?

You cannot retrieve certificates from ACM, in fact these are attached to AWS resources only such as CloudFront, ELBs and API Gateway.您无法从 ACM 检索证书,实际上这些证书仅附加到 AWS 资源,例如 CloudFront、ELB 和 API 网关。

To retrieve the contents there is a couple of solutions.要检索内容,有几个解决方案。

The first is to store this in a credential/secrets store, AWS provide this functionality in the secrets manager service.第一种是将其存储在凭证/机密存储中,AWS 在机密管理器服务中提供此功能。 Additionally you can store a SecureString in the systems manager parameter store .此外,您可以将SecureString存储在系统管理器参数存储中。

Alternatively you could use a third party solution such as HashiCorp Vault .或者,您可以使用第三方解决方案,例如HashiCorp Vault

With this approach if you need the file to exist on disk you will need to store the output in the tmp file storage.使用这种方法,如果您需要文件存在于磁盘上,则需要将 output 存储在 tmp 文件存储中。

If these approaches do not work for you, you could make use of AWS EFS .如果这些方法对您不起作用,您可以使用AWS EFS A recent addition has added support to allow Lambdas to have a NFS mount attached to share storage. 最近添加了一项支持,以允许 Lambda 将 NFS 挂载附加到共享存储。

I think ultimately you are looking for a solution like AWS KMS or CloudHSM , which would allow you to securely store your private keys and perform cryptographic functions rather than reveal the keys for "external usage".我认为最终您正在寻找像AWS KMSCloudHSM这样的解决方案,它可以让您安全地存储您的私钥并执行加密功能,而不是为了“外部使用”而泄露密钥。 This is the most secure way as even you won't be able to see the keys (although CloudHSM actually allows to upload/download keys).这是最安全的方式,因为即使您也看不到密钥(尽管 CloudHSM 实际上允许上传/下载密钥)。

As Node.js TLS module is based on OpenSSL and CloudHSM comes with ready-made openssl engine that you'll be able to use for Mutual TLS.由于Node.js TLS 模块基于 OpenSSL 和 CloudHSM 带有现成的 openssl 引擎,您可以将其用于相互 TLS。 Options privateKeyEngine , privateKeyIdentifier , publicKeyEngine and publicKeyIdentifier of tls.createSecureContext are to be used for that. tls.createSecureContext的选项privateKeyEngineprivateKeyIdentifierpublicKeyEnginepublicKeyIdentifier将用于此目的。

For AWS KMS (which is a way more cost-efficient solution) there is open source openssl engine written in Rust .对于 AWS KMS(这是一种更具成本效益的解决方案),有用 Rust 编写的开源 openssl 引擎

That being said, I'm not sure if you are able to use custom openssl engines in Lambda or if CloudHSM engine is included into Lambda's Node.js environment (which would be very logical).话虽如此,我不确定您是否能够在 Lambda 中使用自定义 openssl 引擎,或者 CloudHSM 引擎是否包含在 Lambda 的 Node.js 环境中(这将是非常合乎逻辑的)。 So you may also choose to "offload" mutual TLS connectivity to a "micro service" running outside Lambda.因此,您还可以选择将相互 TLS 连接“卸载”到在 Lambda 之外运行的“微服务”。 We went this way and implemented a very simple broker "proxying" mTLS calls using securely stored private keys.我们采用这种方式并使用安全存储的私钥实现了一个非常简单的代理“代理”mTLS 调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为启用了双向 TLS 的 Node.js Hyperledger 客户端设置所有必要的证书? - How to setup all the necessary certificates for Node.js Hyperledger client with mutual TLS enabled? 如何在 ReactJS 请求中包含客户端证书到需要双向 TLS 的外部 REST API - How to include client certificate in ReactJS requests to an external REST API which requires mutual TLS 具有相互 TLS 的 Axios:如何提供凭据 - Axios with Mutual TLS: how to provide credentials 如何在并发 AWS lambda 函数中管理 Postgres 连接? - How to manage Postgres connection in concurrent AWS lambda function? 如何在 AWS Lambda 中设置环境变量或使用即时客户端库 - How to set env variable or use instant client library in AWS Lambda 如何使用 AWS Lambda 中的 websocket 将响应发送回客户端 - How to send a response back to client using websockets in AWS Lambda 如何在AWS Lambda函数中检查文件类型 - How to check for a file type within an AWS Lambda function 如何在 AWS Lambda 函数中进行外部 api 调用 - How to make an external api call within an AWS Lambda function lambda 函数中的 AWS NodeJS lambda 调用 - AWS NodeJS lambda call within a lambda function 如何优化AWS Lambda? - How to optimize AWS Lambda?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM