Skip to content

Display false warning when run as non-root user with setuid bit set #7758

Closed
@dbjpanda

Description

@dbjpanda

I configured my php executable i.e /usr/local/bin/php with a setuid for user deploy. So that if any user calls that php binary it should be executed as deploy only. As you can see below php binary is chowned by a non-root user deploy.

> ls -al /usr/local/bin/php
 -rwxr-xr-x    1 root     root     /usr/local/bin/php

> chown deploy:deploy /usr/local/bin/php 

> chmod u+s /usr/local/bin/php

> ls -al /usr/local/bin/php
 -rwsr-xr-x    1 deploy   deploy   /usr/local/bin/php

> ls -al composer.phar 
 -rwxr-xr-x    1 deploy   1000     composer.phar

> whoami 
 root

> php composer.phar -V
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Composer version 1.7.2 2018-08-16 16:57:12

Output getting
Do not run Composer as root/super user! .

Expected result:
I shouldn't get that warning as php binary is owned by deploy and setuid bit is set.

However even if executing php composer.phar install as root the vendor dir created is owned by deploy. Infact the composer process ignores the setuid bit but when it creates any file/dir it obey setuid.

I inserted below inside the composer.phar and get the right user i.e deploy but with a warning Don't call as root .

$processUser = posix_getpwuid(posix_geteuid());
print $processUser['name'];

Output of composer diagnose:

# php composer diag
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Checking composer.json: OK
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys: 
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 1.7.2
PHP version: 7.2.11
PHP binary path: /usr/local/bin/php

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions