Errori di permessi con \"./launcher rebuild app\" su nuova installazione

Ho fatto:

git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse
chmod 700 containers

poi ho copiato il mio vecchio app.yml in containers e ho provato a ricostruire l’app:


[root@two discourse]# ./launcher rebuild app
x86_64 arch detected.
Ensuring launcher is up to date
Launcher is up-to-date
Stopping old container
+ /usr/bin/docker stop -t 600 app
app
2.0.20250722-0020: Pulling from discourse/base
Digest: sha256:3b975c30ef85e9742e2d7f6093450867e67dae204c93d22cc38d043dcbf530b3
Status: Image is up to date for discourse/base:2.0.20250722-0020
docker.io/discourse/base:2.0.20250722-0020
/usr/local/lib/ruby/gems/3.3.0/gems/pups-1.3.0/lib/pups.rb
/usr/local/bin/pups --stdin
I, [2025-09-12T19:05:09.283821 #1]  INFO -- : Reading from stdin
I, [2025-09-12T19:05:09.296585 #1]  INFO -- : File > /etc/service/postgres/run  chmod: +x  chown: 
I, [2025-09-12T19:05:09.301579 #1]  INFO -- : File > /etc/service/postgres/log/run  chmod: +x  chown: 
I, [2025-09-12T19:05:09.307391 #1]  INFO -- : File > /etc/runit/3.d/99-postgres  chmod: +x  chown: 
I, [2025-09-12T19:05:09.313597 #1]  INFO -- : File > /root/install_postgres  chmod: +x  chown: 
I, [2025-09-12T19:05:09.319914 #1]  INFO -- : File > /root/upgrade_postgres  chmod: +x  chown: 
I, [2025-09-12T19:05:09.320255 #1]  INFO -- : Replacing data_directory = '/var/lib/postgresql/15/main' with data_directory = '/shared/postgres_data' in /etc/postgresql/15/main/postgresql.conf
I, [2025-09-12T19:05:09.323526 #1]  INFO -- : Replacing (?-mix:#?listen_addresses *=.*) with listen_addresses = '*' in /etc/postgresql/15/main/postgresql.conf
I, [2025-09-12T19:05:09.324153 #1]  INFO -- : Replacing (?-mix:#?synchronous_commit *=.*) with synchronous_commit = $db_synchronous_commit in /etc/postgresql/15/main/postgresql.conf
I, [2025-09-12T19:05:09.324577 #1]  INFO -- : Replacing (?-mix:#?shared_buffers *=.*) with shared_buffers = $db_shared_buffers in /etc/postgresql/15/main/postgresql.conf
I, [2025-09-12T19:05:09.324945 #1]  INFO -- : Replacing (?-mix:#?work_mem *=.*) with work_mem = $db_work_mem in /etc/postgresql/15/main/postgresql.conf
I, [2025-09-12T19:05:09.325369 #1]  INFO -- : Replacing (?-mix:#?default_text_search_config *=.*) with default_text_search_config = '$db_default_text_search_config' in /etc/postgresql/15/main/postgresql.conf
I, [2025-09-12T19:05:09.325759 #1]  INFO -- : Replacing (?-mix:#?checkpoint_segments *=.*) with checkpoint_segments = $db_checkpoint_segments in /etc/postgresql/15/main/postgresql.conf
I, [2025-09-12T19:05:09.329467 #1]  INFO -- : Replacing (?-mix:#?logging_collector *=.*) with logging_collector = $db_logging_collector in /etc/postgresql/15/main/postgresql.conf
I, [2025-09-12T19:05:09.330304 #1]  INFO -- : Replacing (?-mix:#?log_min_duration_statement *=.*) with log_min_duration_statement = $db_log_min_duration_statement in /etc/postgresql/15/main/postgresql.conf
I, [2025-09-12T19:05:09.330761 #1]  INFO -- : Replacing (?-mix:^#local +replication +postgres +peer$) with local replication postgres  peer in /etc/postgresql/15/main/pg_hba.conf
I, [2025-09-12T19:05:09.331823 #1]  INFO -- : Replacing (?-mix:^host.*all.*all.*127.*$) with host all all 0.0.0.0/0 md5 in /etc/postgresql/15/main/pg_hba.conf
I, [2025-09-12T19:05:09.332230 #1]  INFO -- : Replacing (?-mix:^host.*all.*all.*::1\/128.*$) with host all all ::/0 md5 in /etc/postgresql/15/main/pg_hba.conf
I, [2025-09-12T19:05:09.332621 #1]  INFO -- : > if [ -f /root/install_postgres ]; then
  /root/install_postgres && rm -f /root/install_postgres
elif [ -e /shared/postgres_run/.s.PGSQL.5432 ]; then
  socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
fi

mkdir: cannot create directory ‘/shared/postgres_run’: Permission denied
chown: cannot access '/shared/postgres_run': No such file or directory
chmod: cannot access '/shared/postgres_run': No such file or directory
mkdir: cannot create directory ‘/shared/postgres_run’: Permission denied
chown: cannot access '/shared/postgres_run/15-main.pg_stat_tmp': No such file or directory
install: cannot change owner and permissions of '/shared/postgres_data': No such file or directory
initdb: error: could not create directory "/shared/postgres_data": Permission denied
find: ‘/shared/postgres_data’: No such file or directory
chown: cannot dereference '/var/run/postgresql': No such file or directory
cat: /shared/postgres_data/PG_VERSION: No such file or directory
du: cannot access '/shared/postgres_data': No such file or directory
/root/upgrade_postgres: line 7: * 2: syntax error: operand expected (error token is "* 2")
I, [2025-09-12T19:05:12.122891 #1]  INFO -- : Generating locales (this might take a while)...
  en_US.UTF-8... done
Generation complete.
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /shared/postgres_data ... Upgrading PostgreSQL from version to 15


FAILED
--------------------
Pups::ExecError: if [ -f /root/install_postgres ]; then
  /root/install_postgres && rm -f /root/install_postgres
elif [ -e /shared/postgres_run/.s.PGSQL.5432 ]; then
  socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
fi
 failed with return #<Process::Status: pid 18 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.3.0/lib/pups/exec_command.rb:131:in `spawn'
exec failed with the params {"tag"=>"db", "cmd"=>"if [ -f /root/install_postgres ]; then\n  /root/install_postgres && rm -f /root/install_postgres\nelif [ -e /shared/postgres_run/.s.PGSQL.5432 ]; then\n  socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1\nfi\n"}
bootstrap failed with exit code 1
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
c9c7badf83b119a15b40255ae48a05182f72663cc870ca85e867c1f9a218bb83

Apparentemente c’è un problema di permessi all’interno del container fin dall’inizio:

mkdir: cannot create directory ‘/shared/postgres_run’: Permission denied

Cosa potrebbe causare questo?

Sembra che io debba eseguire docker con il flag --privileged, poiché questo risolve il problema:

./launcher rebuild app --docker-args '--privileged'

Non mi è chiaro perché sia così. (Questo è su Fedora 42.) Mi piacerebbe capire cosa sta succedendo qui.

Perché in Discourse quei file sono di proprietà di root (o la directory padre lo è?).

Forse è impostato di default in Ubuntu. Non so cosa potrebbe essere diverso in Ubuntu.

Potresti provare a impostare /var/discourse/shared come scrivibile da tutti e vedere se funziona? O forse potresti vedere se funziona senza --privileged ora?

Ubuntu è ciò che è raccomandato e Debian è ciò che è all’interno del container (e potrebbe ora essere ciò che CDCK usa per il loro sistema operativo host?). Fedora ha un sacco di cose bloccate che Ubuntu non ha. Se ti piacerebbe capire, probabilmente sarai in gran parte da solo, anche se penso di ricordare che almeno una persona qui con una certa frequenza apprezza Fedora CentOS (che è più vicina a Fedora di quanto lo sia Ubuntu!). Questo potrebbe contenere indizi: MKJ's Opinionated Discourse Deployment Configuration

Mi chiedo quale sia l’uid effettivo nel punto in cui lo script di bootstrap sta cercando di creare sottodirectory in /var/discourse/shared; pensavo sarebbe stato root, dato che docker viene eseguito come root, ma apparentemente non è così?

Non vedo nulla lì riguardo all’uso di --privileged, purtroppo, anche se condivido il suo desiderio di fare tutto questo con podman invece che con docker.

1 Mi Piace

Sì, non ho provato a eseguire Discourse in produzione su Fedora, ho solo fatto sviluppo di Discourse su Fedora, e non su 42. I miei server Discourse ora sono su AlmaLinux 9 e non ho bisogno di --privileged lì. Non ho Docker installato su nessuno dei miei sistemi Fedora.

1 Mi Piace

Penso che proverò a determinare di chi siano le directory senza --privileged quando avrò tempo.

1 Mi Piace

Guardando --privileged vedo che disabilita le etichette di processo SELinux.

Non sto disabilitando SELinux sul mio server Discourse e, infatti, ho istruzioni nella mia guida su come adattarsi a mantenere SELinux abilitato mentre si utilizza nginx esterno. Puoi anche controllare i tuoi log avc per le negazioni pertinenti e scrivere una policy locale utilizzando audit2allow. Ma questo può essere un processo iterativo lungo. Inizierei da zero (cancellando /var/discourse) per assicurarmi che sia un test valido e vedere se hai ancora bisogno di --permissive con SELinux disabilitato (ad esempio, setenforce 0). Quindi, se funziona, puoi usare audit2allow perché setenforce 0 scrive ancora voci avc, ma non viene più fermato al primo cancello, quindi arriverai a una policy funzionante più velocemente.

Non credo che continuerei a usare --privileged su un sistema di produzione se potessi evitarlo.

1 Mi Piace