安全授予用户凭据访问其他内部服务的最佳实践(API 密钥)?

Best practices for securely granting user credential access to other internal services (API key)?

我在 Rails 上有一个 Ruby 应用程序,其数据库存储敏感的用户信息(使用 Devise 进行哈希处理)。我现在需要将其中一些敏感信息传递给另一台服务器上的另一项内部服务,该服务需要它来调用第三方 APIs,因此它需要一种从 RoR 应用程序请求该信息的方法。

解决此类问题的最佳方法是什么?我的第一个直觉是授予一个内部 API 密钥,该密钥将授予对数据库中所有敏感信息的访问权限(通过私有端点),与开发人员密钥授予对 API 端点子集的访问权限的方式相同。只要我对 API 密钥进行哈希处理就足够安全了吗?通过内部服务传递敏感信息的最佳方法是什么?

私人 APIs

My first intuition was to grant an internal API key that would grant access to all sensitive information in the DB (via a private endpoint), the same way developer keys give access to a subset of API endpoints

好吧,私人端点或私人 APIs 不存在,仅通过使用 API 密钥来保护它们。在 Web 应用程序中,您只需查看 html 源代码即可找到 API 键。在移动设备中,您可以在有关移动 API 安全技术的 this series 文章中看到对 API 密钥进行逆向工程是多么容易。虽然这些文章是在移动设备的上下文中,但使用的一些技术在其他类型的 API 中也有效。我希望您现在可以看到有人如何获取 API 密钥并滥用您试图保护的 API。

现在即使您不在移动应用程序或网络应用程序中公开 API 密钥,API 仍然可以被发现,特别是如果端点由相同的 [=42] 提供服务=] 用于其他 public 端点。当您在 robots.txt 中告知机器人不应访问某些端点时,这会变得更加容易,因为这是黑客试图将攻击向量枚举到您的 API 中的第一个地方。

可能的解决方案

私人API解决方案

What's the best approach to something like this? My first intuition was to grant an internal API key that would grant access to all sensitive information in the DB (via a private endpoint)

为了拥有私人 API 托管它的服务器需要受防火墙保护,并锁定到使用证书固定并可能还通过 IP 地址使用它的其他内部服务器。为了能够正确保护和锁定托管假定私有 API 的内部服务器,它不得支持任何 public 请求。

Certificate Pinning:

Pinning effectively removes the "conference of trust". An application which pins a certificate or public key no longer needs to depend on others - such as DNS or CAs - when making security decisions relating to a peer's identity. For those familiar with SSH, you should realize that public key pinning is nearly identical to SSH's StrictHostKeyChecking option. SSH had it right the entire time, and the rest of the world is beginning to realize the virtues of directly identifying a host or service by its public key.

数据库直接访问解决方案

What's the best approach to passing sensitive information around through internal services?

就我个人而言,我更愿意直接从另一台服务器访问数据库,并将数据库软件本身配置为只接受来自特定内部服务器的特定用户的请求,而特定用户的权限可能较低,无法执行他们需要的操作。此外,您将使用防火墙锁定并在内部服务器之间使用证书固定。

结论

无论您选择什么解决方案,都将您的数据库和敏感数据放在只托管该数据库并且很好地锁定到您的内部网络的服务器中。

任何需要访问该敏感数据的人都必须只拥有该特定数据库的读取权限table。