Skip to content

Symfony4 recipe: setfacl: Operation not permitted #2044

@fishbone1

Description

@fishbone1

Describe the bug
I'm using the symfony4 recipe. On second deployment (after using the application), the following error occurs:

  The command "cd /opt/myapp/releases/2 && (setfacl -L -R -m u:"www-data":rwX -m u:`whoami`:rwX var)" failed.

  Exit Code: 1 (General error)

  Host Name: myhost

  ================
  setfacl: var/sessions/prod/sess_pneuui5pv24bk12cig5vsoglm0: Operation not permitted

The reason is that this file was created by the web server user "www-data", so the ACL cannot be changed by the deployment user.

I see that this is exactly what you are trying to prevent already:

// When running without sudo, exception may be thrown

I assume this doesn't work due to the fact that shared dirs are inside the writable directory:

set('shared_dirs', ['var/log', 'var/sessions']);
set('shared_files', ['.env.local.php', '.env.local']);
set('writable_dirs', ['var']);

... but shared directories are processed before writables. This breaks the hasfacl check here:

$hasfacl = run("getfacl -p $dir | grep \"^user:$httpUser:.*w\" | wc -l");

My suggestion is to place deploy:writable before deploy:shared in the deployment task of the symfony4 recipe.

Environment

  • Deployer version: 6.7.3
  • PHP version: 7-2
  • Deployment target(s) OS: Ubuntu 18

Content of deploy.php

<?php
namespace Deployer;

//require 'recipe/rsync.php';
require 'vendor/deployer/recipes/recipe/rsync.php';
require 'recipe/symfony4.php';

// Project name
set('application', 'myapp');

set('rsync', [
    'exclude' => ['.git', 'meta', 'var', 'app/config/parameters.yml'],
    'flags' => 'rzcE',
    'timeout' => '300',
]);
set('rsync_src', 'src');

// #WORKAROUND --no-dev does't work, because those dependencies are expected on cache:warmup
set('composer_options', '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --optimize-autoloader --no-suggest');

add('shared_files', ['app/config/parameters.yml', 'var/.htpasswd']);
add('shared_dirs', ['var/logs', 'var/sessions', 'var/uploads']);

inventory('hosts.yml');
host('myapp');

task('deploy', [
    'deploy:info',
    'deploy:prepare',
    'deploy:lock',
    'deploy:release',
    //'deploy:update_code',
   'rsync',
    'deploy:shared',
    'deploy:vendors',
    'deploy:writable',
    'deploy:cache:clear',
    'deploy:cache:warmup',
    'deploy:symlink',
    'deploy:unlock',
    'cleanup',
]);

after('deploy:failed', 'deploy:unlock');

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions