首页 > 解决方案 > 当代码指示要写入的文件时,apache2/mod_wsgi/python3/flask 使用什么凭据?

问题描述

这段简单的代码:

from flask import Flask, render_template, request, redirect, abort
import sys, time
import wh_settings as settings


app = Flask(__name__)

@app.route('/', methods=['POST', 'GET'])
def webhook():

    if request.method == 'POST':
        daily_events_fullpath = '/home/[user]/[target directory]/[filename]'

        try:
            with open(daily_events_fullpath, 'a') as fileobject:
                fileobject.write("Hello World\n")

            retval =  """Hellow yellow kitty"""

        except Exception as ex:
            retval =  str(ex)

    else:
        retval = """Not a 'POST'"""

    return retval, 200

...导致:

[Errno 13] 权限被拒绝:'/home/[user]/[target directory]/[filename]'

(将 '[user]/[target directory]/[filename]' 替换为有效内容)

由于我设置了一个允许“www-data”写入该目录的 ACL(并使用“getfacl”对其进行了仔细检查),因此我认为 apache2/mod_wsgi/python3/flask 必须使用其他一些凭据来写入文件。

谁能告诉我如何找出正在使用的凭据?我查看了 /var/log/auth.log 并且没有“拒绝”条目用于尝试打开文件进行追加。

附加系统信息:

Opsys = Linux 
Kernel ver = 5.3.0-1030-aws
distro = Ubuntu 18.04,4 LTS Server (no GUI)
SELinux is not installed
AppArmor is installed and enabled

标签: flaskpermissionsapache2mod-wsgi

解决方案


推荐阅读