gpt4 book ai didi

laravel - docker Apache : 'chmod: changing permissions of "file"Operation not permitted'

转载 作者:行者123 更新时间:2023-12-02 04:08:55 30 4
gpt4 key购买 nike

我有一个使用 docker 部署在 Azure Kubernetes 上的 Laravel 应用程序。每当我尝试上传文件时,我的应用程序在上传文件时遇到问题,我从 Laravel 收到此错误(仅显示堆栈跟踪的一部分):

chmod(): Operation not permitted {"userId":1,"exception":"[object](ErrorException(code: 0): chmod(): Operation not permitted at/var/www/my-app/vendor/league/flysystem/src/Adapter/Local.php:367)[stacktrace]

#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2,'chmod(): Operat...', '/var/www/my-app...', 367, Array)

#1 /var/www/my-app/vendor/league/flysystem/src/Adapter/Local.php(367):chmod('/var/www/my-app...', 420)

但是在我的 Dockerfile 中,我“chowned”了存储文件夹:

RUN chown -R www-data:www-data \
/var/www/my-app/storage \
/var/www/my-app/bootstrap/cache

我应该提到的是,文件已上传,但由于 chmod 而无法继续执行其余代码。异常。

为了调试问题,我运行了 kubectl exec要让 shell 进入 pod,默认情况下它会以 root 身份登录。我cd到上传的文件并尝试通过运行 chmod 420 nameOfFile.ext 更改 root 权限这有效,所以我将其改回权限 777。但是,由于 Laravel 使用 apache 用户“www-data”,所以我运行 su www-data -s /bin/bash然后尝试通过运行 chmod 420 nameOfFile.ext 更改同一文件的权限我收到此错误:

chmod: changing permissions of "nameOfFile.ext" Operation not permitted

所以这让我想知道 chown 中的“-R”是否有效仅适用于直接作为子文件或文件夹的文件和文件夹。因此,我切换回 root 用户“chowned”文件直接所在的文件夹,然后切换回 www-data 用户并尝试运行 chmod但仍然出现相同的错误。

[编辑]我还应该提到该应用程序正在使用 Azure 文件服务作为持久卷。将其更改为 blob 服务会有帮助吗?

[编辑]这是我完整的 Dockerfile 的样子:https://pastebin.com/zLSyfqK8

我已经解决这个问题有一段时间了,非常感谢您的帮助。如果您需要任何其他必要信息,请告诉我。

最佳答案

I also should mention the application is using Azure file service as the persistent volume.

这就是问题所在。 Azure 文件提供 CIFS 共享,在 Linux 下以 cifs 挂载方式挂载。 CIFS共享不提供UNIX类型文件权限和UNIX类型uid/gid存储。

挂载 CIFS 共享时,Linux 计算机使用用户名/密码在 CIFS 服务器上进行身份验证。通过此挂载的每次访问实际上都会在 CIFS 服务器上使用此用户名,无论哪个 UNIX 用户正在启动文件系统操作。根据this GitHub issue ,Azure 文件不支持 UNIX 扩展,这意味着 Linux 客户端必须模拟 UNIX uid/gid 和权限。服务器不存储或提供这些参数。因此在挂载时,您必须添加 uidgidfile_modedir_mode 参数来设置这些数据。

如果您使用操作系统级别 CIFS 挂载(通过 /etc/fstab)或手动 CLI 挂载命令,则必须将这些选项添加到挂载命令中(请参阅 man mount.cifs )。

例如:mount -t cifs -o file_mode=0644,dir_mode=0755,uid=80,gid=80 ...

如果您使用 Kubernetes 卷,则必须将这些选项添加到卷参数中(请参阅 Azure Files share in Kubernetes )。

例如:

apiVersion: v1
kind: PersistentVolume
metadata:
name: azurefile
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
storageClassName: azurefile
azureFile:
secretName: azure-secret
shareName: aksshare
readOnly: false
mountOptions:
- dir_mode=0755
- file_mode=0644
- uid=80
- gid=80
- mfsymlinks

关于laravel - docker Apache : 'chmod: changing permissions of "file"Operation not permitted',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60620423/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com