goreleaser / nfpm

nFPM is Not FPM - a simple deb, rpm, apk, ipk, and arch linux packager written in Go
https://nfpm.goreleaser.com/
MIT License
2.13k stars 157 forks source link

Bad rights on created subdirectories #738

Closed kduret closed 7 months ago

kduret commented 9 months ago

What happened?

When I package a RPM, subdirectories has root:root even if I set file_info.owner and file_info.group to apache

When using type: tree, all files and subdirectories are root:root instead of apache:apache

How can we reproduce this?

contents:

nfpm version

# nfpm --version
       _____ ____  __  __
 _ __ |  ___|  _ \|  \/  |
| '_ \| |_  | |_) | |\/| |
| | | |  _| |  __/| |  | |
|_| |_|_|   |_|   |_|  |_|
nfpm: a simple and 0-dependencies deb, rpm, apk and arch linux packager written in Go
https://nfpm.goreleaser.com

GitVersion:    2.33.1
GitCommit:     bb6d0b9839c71ebd5d9d9bc0cf4088b3b933dc09
GitTreeState:  false
BuildDate:     2023-09-22T02:48:09Z
BuiltBy:       goreleaser
GoVersion:     go1.21.1
Compiler:      gc
ModuleSum:     h1:EkdAzZyVhAI9JC1vjmjjbmnNzyH1J6Cu4JCsA7YcQuc=
Platform:      linux/amd64

Search

Code of Conduct

Additional context

caarlos0 commented 9 months ago

I still need to investigate properly, but I think part of the issue is files.addParents which adds the implicit parent dirs with root/root/0o755.

That's not the full story though... as rpms do not add the implicit dirs - and I don't remember why)

cc/ @goreleaser/nfpm if anyone has more ideas

erikgeiser commented 9 months ago

@caarlos0 If an rpm explicitly adds a directory, the package takes ownership of the directory. If /etc/ was added implicitly when adding /etc/program.conf, the package would take ownership of /etc. However, the correct owner of /etc is the filesystem package. This can result in conflicts as seen here: https://github.com/google/rpmpack/issues/62

This is also documented here: https://github.com/goreleaser/nfpm/blob/a8707cd42874f46a192ec2ef9918d3a75631afb6/www/docs/configuration.md?plain=1#L244-L254

Other tools such as fpm use a workaround where some directories such as /etc are blacklisted. I use a custom wrapper around nfpm that does this, too. My list works for my use case but I don't think there is a list that fits all needs.

kduret commented 9 months ago

Thank you for your answers

But if I claim explicitely the directory ownership using following instructions :

contents:
  - dst: "/usr/share/A"
    type: dir
    file_info:
      mode: 0755
      owner: "apache"
      group: "apache"

  - src: "./A"
    dst: "/usr/share/A"
    file_info:
      mode: 0644
      owner: "apache"
      group: "apache"

The subdirectories in /usr/share/A/ remain root:root

ccb1900 commented 8 months ago

I also encountered the same problem.

- dst: /var/lib/test
    type: tree
    file_info:
      mode: 0755
      owner: test
      group: test

subdirectories got "root",expected "test:test"

ccb1900 commented 8 months ago

Thank you for your answers

But if I claim explicitely the directory ownership using following instructions :

contents:
  - dst: "/usr/share/A"
    type: dir
    file_info:
      mode: 0755
      owner: "apache"
      group: "apache"

  - src: "./A"
    dst: "/usr/share/A"
    file_info:
      mode: 0644
      owner: "apache"
      group: "apache"

The subdirectories in /usr/share/A/ remain root:root

because the code

image

ower and group are invalid, as @caarlos0 said

@kduret

caarlos0 commented 8 months ago

754 should fix it I think

kduret commented 8 months ago

Thanks for your work @caarlos0 ❤️ I will test it soon

ccb1900 commented 8 months ago

754 should fix it I think

"/ etc / var" and other system directory permissions?

caarlos0 commented 8 months ago

ah, I forgot about that... will fix

caarlos0 commented 8 months ago

check #760