3

这是一个已知问题:https ://issuetracker.google.com/issues/63253097

关于让 Google KMS与 App Engine 一起工作的问题,我提出了一个关于相关但有问题的副作用的新问题。

也就是说,Google Cloud API 发现似乎想要在 AppEngine 沙箱之外走多条路径。这本身不是问题,但它使测试和调试非常有问题,因为每次尝试都会被记录下来,产生数百行如下所示:

信息 2017 年 7 月 3 日 14:44:51 沙盒阻止访问文件“/用户”

INFO 2017 年 7 月 3 日 14:44:51 如果它是静态文件,请检查application_readable: true您的 app.yaml 中是否设置了该文件

信息 2017 年 7 月 3 日 14:44:52 沙盒阻止访问文件“/usr/lib/Acrobat9/Resource/CMap”

INFO 2017 年 7 月 3 日 14:44:52 如果它是静态文件,请检查application_readable: true在您的 app.yaml 中设置

信息 2017 年 7 月 3 日 14:44:52 沙盒阻止访问文件“/usr/lib/Acrobat8/Resource/CMap”

INFO 2017 年 7 月 3 日 14:44:52 如果它是静态文件,请检查application_readable: true在您的 app.yaml 中设置

有没有办法禁用或静音这些请求或日志?

编辑*traceback.print_stack()通过添加到log_access_check_failin打印的众多结果之一stub.py(抱歉,这里不是很清晰):

测试 #1:Sentry.io 的 Raven 导入pkg_resources

  File "/Users/bmh/testapp/application.py", line 3, in <module>
    from nassau.application import app, sentry
  File "/Users/bmh/testapp/nassau/application.py", line 28, in <module>
    from raven.contrib.flask import Sentry
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/site-packages/raven/__init__.py", line 16, in <module>
    VERSION = __import__('pkg_resources') \
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3037, in <module>
    @_call_aside
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3021, in _call_aside
    f(*args, **kwargs)
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3050, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 646, in _build_master
    ws = cls()
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 639, in __init__
    self.add_entry(entry)
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 695, in add_entry
    for dist in find_distributions(entry, True):
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2006, in find_on_path
    path_item = _normalize_cached(path_item)
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2217, in _normalize_cached
    _cache[filename] = result = normalize_path(filename)
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2210, in normalize_path
    return os.path.normcase(os.path.realpath(filename))
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/posixpath.py", line 375, in realpath
    path, ok = _joinrealpath('', filename, {})
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/posixpath.py", line 400, in _joinrealpath
    if not islink(newpath):
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/posixpath.py", line 135, in islink
    st = os.lstat(path)
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/stubs.py", line 286, in __call__
    log_access_check_fail(path)
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/stubs.py", line 51, in log_access_check_fail
    traceback.print_stack()

我删除了对 Sentry / Raven 的依赖,但堆栈跟踪继续,通过:

测试 #2:Flask 导入pkgutil

  File "/Users/bmh/testapp/application.py", line 3, in <module>
    from nassau.application import app
  File "/Users/bmh/testapp/nassau/application.py", line 72, in <module>
    app = Flask('nassau')
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/site-packages/flask/app.py", line 331, in __init__
    instance_path = self.auto_find_instance_path()
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/site-packages/flask/app.py", line 622, in auto_find_instance_path
    prefix, package_path = find_package(self.import_name)
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/site-packages/flask/helpers.py", line 661, in find_package
    loader = pkgutil.get_loader(root_mod_name)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pkgutil.py", line 464, in get_loader
    return find_loader(fullname)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pkgutil.py", line 475, in find_loader
    loader = importer.find_module(fullname)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pkgutil.py", line 184, in find_module
    path = [os.path.realpath(self.path)]
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/posixpath.py", line 375, in realpath
    path, ok = _joinrealpath('', filename, {})
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/posixpath.py", line 400, in _joinrealpath
    if not islink(newpath):
  File "/Users/bmh/testapp/python-virtualenv/lib/python2.7/posixpath.py", line 135, in islink
    st = os.lstat(path)
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/stubs.py", line 286, in __call__
    log_access_check_fail(path)
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/stubs.py", line 51, in log_access_check_fail
    traceback.print_stack()

必须有更好的方法来表示堆栈溢出时的堆栈跟踪:)

4

3 回答 3

6

我是一名在 dev_appserver 上工作的全职工程师。此日志消息是从 /google/appengine/tools/devappserver2/python/stubs.py 报告的,方法中log_access_check_fail

我们添加此日志消息以提醒用户 dev_appserver 阻止文件访问的行为。

推荐的解决方法:dev_appserver.py --log_level 警告

--log_level 设置本地 python 运行时进程中的日志级别。log_access_check_fail() 设置为 INFO 并且不会被记录。注意,这个标志也会阻止你的应用程序中的其他 INFO 级别的日志记录。

同时,我们正在修复这个 log_access_check_fail 方法。它可能会将 log_access_check_fail() 日志记录级别降低到 DEBUG。

于 2017-07-07T19:49:53.390 回答
3

这很烦人,并且有一个错误报告

与此同时,我们可以过滤掉这些消息,但我们需要弄清楚logger它们正在使用哪些消息。有关如何处理日志记录的更多信息,请参阅文档。看看stubs.py我发现的来源:

logging.info('Sandbox prevented access to file "%s"', filename)
logging.info('If it is a static file, check that '
           '`application_readable: true` is set in your app.yaml')

所以他们使用的是根记录器(通常是不好的做法)。要在您的根记录器上过滤掉这些消息,请将以下内容添加到您的appengine_config.py

import logging

class StubsFilter(logging.Filter):

    def filter(self, record):
        return 'stubs.py' != record.filename

logging.root.addFilter(StubsFilter())
于 2017-07-11T21:19:04.100 回答
0

对我来说,这些消息似乎来自一个名为 stubs.py 的 GAE (.local) 文件。

  1. 在我的第一个案例中,stubs.py 正在寻找不存在的文件。因此,您可能想检查“/usr/lib/Acrobat8/Resource/CMap”是否确实存在。然后,从 stubs.py 开始,尝试找出正在尝试加载它的文件

    1. 我的项目正在使用 web.py,突然间我又开始收到 (stubs.py) 消息,这次是关于 .pyc 文件。我在 app.yaml 文件的底部放了一个skip_files:,它确实抑制了消息,但我还没有测试我的应用程序是否仍然可以完全编译。

      skip_files:
      - ^(.*/)?\.pyc$
      

更多关于 Python GAE 运行时和沙箱的信息。 https://cloud.google.com/appengine/docs/standard/python/runtime

于 2017-07-05T16:28:29.780 回答