AppEngine Dev Server上的Google KMS - 记录混乱

时间:2017-07-03 14:49:17

标签: google-app-engine google-app-engine-python google-cloud-kms

  

这是一个众所周知的问题:https://issuetracker.google.com/issues/63253097

my question about getting Google KMS working with App Engine之后,我打开一个关于相关但有问题的副作用的新问题。

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

  

INFO 03 Jul 2017 14:44:51 Sandbox阻止访问文件" /用户"

     

INFO 03 Jul 2017 14:44:51如果是静态文件,请检查app.yaml中是否设置了application_readable: true

     

INFO 03 Jul 2017 14:44:52 Sandbox阻止访问文件" / usr / lib / Acrobat9 / Resource / CMap"

     

INFO 03 Jul 2017 14:44:52如果是静态文件,请检查app.yaml中是否设置了application_readable: true

     

INFO 03 Jul 2017 14:44:52 Sandbox阻止访问文件" / usr / lib / Acrobat8 / Resource / CMap"

     

INFO 03 Jul 2017 14:44:52如果是静态文件,请检查app.yaml中是否设置了application_readable: true

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

编辑* traceback.print_stack()中将log_access_check_fail添加到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()

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

3 个答案:

答案 0 :(得分: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。

答案 1 :(得分:3)

这非常烦人,而且有bug report

与此同时,我们可以过滤掉这些消息,但我们需要弄清楚他们正在使用哪些logger。有关如何处理日志记录的详细信息,请参阅the docs。看一下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())

答案 2 :(得分:0)

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

  1. 在我的第一个案例中,stubs.py正在寻找那些不存在的文件。因此,您可能需要检查“/ usr / lib / Acrobat8 / Resource / CMap”是否确实存在。然后,从stubs.py开始,尝试找出what file is trying to load it

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

      skip_files:
      - ^(.*/)?\.pyc$
      
  2. 有关Python GAE运行时和沙箱的更多信息,请点击此处。 https://cloud.google.com/appengine/docs/standard/python/runtime