简体   繁体   English

使用Google Cloud Endpoints进行机器对机器的身份验证

[英]Machine to machine authentication with Google Cloud Endpoints

CONTEXT CONTEXT

Have created an API using Google Cloud Endpoints (Python) with which numerous low power devices will GET/POST data. 已使用Google Cloud Endpoints(Python)创建了一个API,许多低功耗设备将使用该API进行GET / POST数据。

The only communication with the API will be from these custom devices (I own both ends of the communication). 与API的唯一通信将来自这些自定义设备(我拥有通信的两端)。

RESEARCH 研究

Looking at authentication, was hoping it would be as simple as using SSL/TLS client certs: 查看身份验证,希望它像使用SSL / TLS客户端证书一样简单:

  • Each remote device will have a client cert signed by a single project CA anyway. 无论如何,每个远程设备都将具有由单个项目CA签名的客户端证书。
  • The Google cloud endpoints mandate SSL. Google云端点要求SSL。

However, only oauth2 appears to be supported; 但是,似乎仅支持oauth2。 I'm looking for a 'clean' way to implement 'hands off' authentication, ideally utilising the client SSL cert I already have on the client devices. 我正在寻找一种“干净”的方式来实现“越区切换”身份验证,理想情况下是利用客户端设备上已经具有的客户端SSL证书。

I have investigated creating 'service' oauth2 accounts, however as I want to protect against a device spoofing another device (one set of credentials for all is not acceptable), I would need to generate a service account for each client device, which would be bulky and horrible to maintain on the API-end. 我已经研究过创建“服务” oauth2帐户,但是由于要防止某个设备欺骗其他设备(不接受所有一组凭据),我需要为每个客户端设备生成一个服务帐户,在API端维护笨重且可怕。

It seems i'm looming towards needing to add a layer of authentication within my code for each API method, which somewhat defeats the point of utilising the services of Google's cloud endpoints. 似乎我迫在眉睫,需要在我的代码中为每种API方法添加一层身份验证,这在某种程度上使使用Google的云端点服务的观点无法兑现。

QUESTION... Finally 问题...最后

  1. Has anyone had experience in authenticating 'hands off' machine to machine devices at scale against google's cloud endpoint? 有没有人在针对Google的云端点大规模验证“移交”机器对机器设备的经验?

  2. Does anyone know of a way of using a client certificate in the Oauth2 authentication process in a way which would be supported by GCE? 有谁知道在Oauth2身份验证过程中以GCE支持的方式使用客户端证书的方法吗?

  3. Is my only option going to be custom authentication within the API methods based on some crypto data in the POST/GET headers. 我唯一的选择是基于POST / GET标头中的某些加密数据在API方法中进行自定义身份验证。 (or just moving to hosting an API with Apache/NGINX and client-cert auth?) (或者只是转向使用Apache / NGINX和客户端证书身份验证托管API?)

Regards, Matt 问候,马特

I wrote you an essay: 我给你写了一篇文章:

Consider that Cloud Endpoints basically exists in the application layer of the OSI model, since it communicates via HTTPS requests (it sends HTTP requests within a TLS session). 考虑到Cloud Endpoints基本上存在于OSI模型的应用程序层中,因为它通过HTTPS请求进行通信(它在TLS会话中发送HTTP请求)。 Whether or not Endpoints uses HTTP or HTTPS is not a developer-configurable option - it must be HTTPS. 端点是否使用HTTP或HTTPS都不是开发人员可配置的选项-它必须是HTTPS。

It uses HTTPS in that the API server has a TLS cert which is used to authenticate the API server. 它使用HTTPS,因为API服务器具有用于认证API服务器的TLS证书。 Inside the secure connection, the RPC params and responses are also secured from eavesdropping. 在安全连接内部,还防止RPC参数和响应被窃听。 This is the extent to which Endpoints "interacts" with TLS - it uses it to establish the session and send HTTP requests inside this session. 这是端点与TLS“交互”的程度-它使用它来建立会话并在此会话内发送HTTP请求。

So, already I can tell you that you will not be able to have your TLS client certs (not an often-used feature) used to authenticate API clients automatically by endpoints, in the connection setup phase. 因此,已经可以告诉您,在连接建立阶段,您将无法使用TLS客户端证书(不是常用功能)来由端点自动对API客户端进行身份验证。 TLS client certs simply aren't looked at or requested by the Endpoints API server. Endpoints API服务器根本不会查看或请求TLS客户端证书。

Now, while authentication of the API server itself is guaranteed through the API server's TLS cert, authentication of API clients is done via Client IDs or the Users API , which sits in your code and abstracts over the different auth options App Engine offers at present: 现在,虽然可以通过API服务器的TLS证书来保证对API服务器本身的身份验证,但可以通过客户端IDUsers API来完成对API 客户端的身份验证,后者位于您的代码中,并抽象了App Engine当前提供的不同身份验证选项:

  • OAuth (2.0) OAuth(2.0)
  • OpenID OpenID的

So, in order to auth your client devices in one of these two manners and still take advantage of Cloud Endpoints, you will need to find a way for each device to perform an OAuth flow or OpenID flow, your system having provisioned an identity for the respective auth method at the time of that device's initial deployment. 因此,为了以两种方式中的一种对您的客户端设备进行身份验证并仍然利用Cloud Endpoints,您将需要找到一种使每个设备执行OAuth流或OpenID流的方法,而您的系统已经为该设备最初部署时的相应auth方法。

Google (Apps) Accounts option Google(应用程序)帐户选项

This will involve creating a Google account (Google's unified SSO) or a Google Apps account managed by a custom domain for each device, and provisioning these accounts' credentials to each respective device. 这将涉及为每个设备创建一个Google帐户(Google的统一SSO)或一个由自定义域管理的Google Apps帐户,并将这些帐户的凭据提供给每个相应的设备。 You can read more about custom domain authentication and App Engine auth configuration in general here . 您可以在此处大致了解有关自定义域身份验证和App Engine身份验证配置的更多信息。

OpenID option ( general doc on OpenID with GAE ) OpenID选项有关带有GAE的OpenID的常规文档

This will involve setting up your own OpenID provider on a GCE instance using an OpenID connect library like pyoidc , so that you can provision accounts yourself, or it could involve registering accounts with a known OpenID provider for each device. 这将涉及使用像pyoidc这样的OpenID连接库在GCE实例上设置自己的OpenID提供程序,以便您可以自己设置帐户,也可能涉及为每个设备向已知的OpenID提供程序注册帐户。 The first solution is more robust but more time-consuming (OpenID providers can go down temporarily, or deactivate forever, and then your IOT network is out of luck). 第一个解决方案更强大,但更耗时(OpenID提供程序可以暂时关闭或永久停用,然后您的IOT网络就不走运了)。

Third option using Client IDs 使用客户端ID的第三种选择

You can of course generate an "installed application" client ID/secret and distribute these to each device in your network. 您当然可以生成“已安装的应用程序”客户端ID /秘密,并将其分发到网络中的每个设备。 They can use this to authenticate themselves as network devices (as opposed to an attacker's laptop), and then you trust devices to accurately report their own id as a param with each API call. 他们可以使用它来认证自己为网络设备(而不是攻击者的便携式计算机),然后您相信设备可以在每个API调用中将自己的ID准确地报告为参数。 Depending on how hackable your devices are and how widely you intend to distribute them, this scheme doesn't necessarily prevent devices from spoofing each other's id's, although depending on the id generation scheme, you can make it very difficult (each id being a long sufficiently long hash). 根据设备的可破解程度和打算分发它们的范围,此方案不一定会阻止设备欺骗彼此的ID,尽管根据ID生成方案,您可能会感到非常困难(每个id很长)。足够长的哈希值)。

If you go this route and you're really concerned about this, you can provision a client ID for each device, but who knows if you'll hit some kind of undocumented limit on number of client IDs per app, and also this will require you to either do it by hand or write a script that logs into the dev console on a headless browser and does what you need. 如果您选择这条路线并且确实对此感到担心,则可以为每个设备设置一个客户端ID,但是谁知道您是否会对每个应用程序的客户端ID数量达到某种未记录的限制,这也需要您可以手动执行此操作,也可以编写脚本来登录无头浏览器中的开发控制台并执行所需的操作。

Fourth crazy option that actually uses the TLS client certs 实际使用TLS客户端证书的第四个疯狂选项

If you're really set on using both TLS client certs for auth and Cloud Endpoints for your API, you could try to send the client cert in the request , since TLS is encrypting the request data (unless your attacker has found a way to efficiently solve the inverse discrete logarithm problem, in which case they'll probably be too busy attacking more important targets (no offense) and changing the infosec game forever), and then reading and auth'ing the cert in your endpoints method somehow (third party libs uploaded with your app are probably necessary for this). 如果您确实打算同时使用TLS客户端证书进行身份验证 Cloud Endpoints作为API,则可以尝试在请求中发送客户端证书,因为TLS正在加密请求数据(除非您的攻击者找到了一种有效的方法解决离散离散对数问题,在这种情况下,他们可能会太忙于攻击更重要的目标(无进攻)并永远更改信息安全游戏),然后以某种方式在端点方法中读取和认证证书(第三方为此,可能需要使用随应用程序上传的库。

Fourth realistic option if you have your heart set on TLS client certs 如果您对TLS客户端证书有一定的了解,则是第四个现实选择

Switch from App Engine to Compute Engine , where you basically have a VM managed and hosted in the same data-centers. 从App Engine切换到Compute Engine ,基本上可以在同一数据中心内管理和托管VM。 On this box, you can implement any kind of connection protocol on any port you like, so you could have incoming API requests (not Endpoints, notice) TLS-authenticated based on teh connecting device's client certs. 在此框中,您可以在喜欢的任何端口上实现任何类型的连接协议,因此您可以基于连接设备的客户端证书对传入的API请求(而不是端点,通知)进行TLS身份验证。

Good luck! 祝好运!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM