我正在尝试让Google云平台数据丢失预防(DLP)客户端库在SSL代理之后工作: https://cloud.google.com/dlp/docs/libraries#client-libraries-usage-python
我正在使用文档中的代码片段:
# Import the client library
import google.cloud.dlp
import os
import subprocess
import json
import requests
import getpass
import urllib.parse
import logging
logging.basicConfig(level=logging.DEBUG)
# Instantiate a client.
dlp_client = google.cloud.dlp.DlpServiceClient()
# The string to inspect
content = 'Robert Frost'
# Construct the item to inspect.
item = {'value': content}
# The info types to search for in the content. Required.
info_types = [{'name': 'FIRST_NAME'}, {'name': 'LAST_NAME'}]
# The minimum likelihood to constitute a match. Optional.
min_likelihood = 'LIKELIHOOD_UNSPECIFIED'
# The maximum number of findings to report (0 = server maximum). Optional.
max_findings = 0
# Whether to include the matching string in the results. Optional.
include_quote = True
# Construct the configuration dictionary. Keys which are None may
# optionally be omitted entirely.
inspect_config = {
'info_types': info_types,
'min_likelihood': min_likelihood,
'include_quote': include_quote,
'limits': {'max_findings_per_request': max_findings},
}
# Convert the project id into a full resource id.
parent = dlp_client.project_path('my-project-id')
# Call the API.
response = dlp_client.inspect_content(parent, inspect_config, item)
# Print out the results.
if response.result.findings:
for finding in response.result.findings:
try:
print('Quote: {}'.format(finding.quote))
except AttributeError:
pass
print('Info type: {}'.format(finding.info_type.name))
# Convert likelihood value to string respresentation.
likelihood = (google.cloud.dlp.types.Finding.DESCRIPTOR
.fields_by_name['likelihood']
.enum_type.values_by_number[finding.likelihood]
.name)
print('Likelihood: {}'.format(likelihood))
else:
print('No findings.')
我还设置了以下ENV变量:
^{pr2}$当你不在SSL代理后面时,它可以正常运行。当我在代理后面工作时,我正在设置3个ENV变量:
REQUESTS_CA_BUNDLE
HTTP_PROXY
HTTPS_PROXY
通过这种设置,其他GCP客户机python库可以在SSL代理之后正常工作,例如存储或bigquery)。在
对于DLP客户机python库,我得到:
E0920 12:21:49.931000000 24852 src/core/tsi/ssl_transport_security.cc:1229] Handshake failed with fatal error SSL_ERROR_SSL: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed.
DEBUG:google.api_core.retry:Retrying due to 503 Connect Failed, sleeping 0.0s ...
E0920 12:21:50.927000000 24852 src/core/tsi/ssl_transport_security.cc:1229] Handshake failed with fatal error SSL_ERROR_SSL: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed.
DEBUG:google.api_core.retry:Retrying due to 503 Connect Failed, sleeping 0.0s ...
我没有在文档中找到解释lib是否与proxy一起工作作为一个GCP客户机lib以及如何配置它以与SSL proxy一起工作的文档。lib是beta版,所以可能还没有实现。在
它似乎与CA证书和握手有关。对于BigQuery和存储客户机python lib,相同的CA没有问题。有什么想法吗?在
您的代理正在执行
TLS Interception
。这会导致Google库不信任代理在访问googleapi端点时呈现的SSL证书。这是一个中间人的问题。在Google的解决方案是绕过api。在应用程序运行的VPC子网中,启用私有Google访问。这要求默认的专有网络路由规则仍然存在(或重新创建)。在
Private Google Access
[在下面的评论后编辑]
我添加此评论是为了吓唬管理层。
TLS拦截非常危险,如果他们读到以下内容,任何合理的公司都不会实施。在
本例中的场景。我是负责公司代理的IT人员。公司已经实施了TLS拦截,我控制了代理。我无法访问我公司的谷歌云资源。我非常聪明,我非常了解谷歌云IAM和OAuth。我要砍掉我的公司,因为也许我没有得到加薪(你自己编个理由)。在
我等待一个拥有组织或项目所有者/编辑级别权限的经理向googlecloud进行身份验证。我的代理记录了指向
https://www.googleapis.com/oauth2/v4/token
的所有内容的HTTPS头、正文和响应以及一些其他url。在可能代理将日志存储在Google云存储桶或SAN卷上,而没有实现可靠的授权。也许我只是一个软件工程师,发现代理日志文件到处都是或者很容易被访问。在
公司管理员登录他的谷歌帐户。我捕获返回的OAuth访问令牌。我现在可以在接下来的3600秒内模拟org管理员。另外,我捕获OAuth刷新令牌。现在,我可以随时根据自己的意愿重新创建OAuth访问令牌,直到撤销刷新令牌为止,对于大多数公司来说,他们从来没有这样做过。在
对于怀疑者,请研究我的Golang项目,该项目展示了如何保存OAuth访问令牌并将令牌刷新到用于认证的任何Google帐户的文件中。我可以把这个文件带回家,在没有任何身份验证的情况下被授权。此代码将在访问令牌过期时重新创建它,使我几乎永远都可以访问这些凭据授权的任何帐户。你的内部IT资源永远不会知道我是在你的公司网络之外这么做的。在
注意:Stackdriver审计日志可以捕获IP地址,但是,身份将是我窃取的凭据。为了隐藏我的IP地址,我会去星巴克或公共图书馆,在离家/工作几小时车程的地方做我的事。现在找出这个黑客在哪里和谁。这会让法医专家感到心痛。在
https://github.com/jhanley-com/google-cloud-shell-cli-go
注意:这个问题不是googleoauth或googlecloud的问题。这是公司部署的安全问题(TLS拦截)的一个例子。这种方式的技术几乎适用于我所知道的不使用MFA的所有认证系统。在
[结束编辑]
小结:
数据丢失预防客户端库python使用gRCP。 google cloud dlp使用gRPC,而google cloud bigquery和 google云存储依赖于请求库 HTTPS上的JSON。因为它是gRPC其他环境变量需要 设置:
更多详细信息和链接可在此处找到link
相关问题 更多 >
编程相关推荐