Skip to content

nixos/transmission: improvements#350085

Merged
misuzu merged 4 commits into
NixOS:masterfrom
diniamo:fix-transmission
Dec 4, 2024
Merged

nixos/transmission: improvements#350085
misuzu merged 4 commits into
NixOS:masterfrom
diniamo:fix-transmission

Conversation

@diniamo

@diniamo diniamo commented Oct 20, 2024

Copy link
Copy Markdown
Contributor

As per Transmission's documentation, the umask option should be a string.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions Bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Oct 20, 2024
@ofborg ofborg Bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Oct 20, 2024
Comment thread nixos/modules/services/torrent/transmission.nix Outdated
@github-actions github-actions Bot added 8.has: documentation This PR adds or changes documentation 8.has: changelog This PR adds or changes release notes labels Oct 21, 2024
@diniamo diniamo changed the title nixos/transmission: fix settings.umask to be of type str nixos/transmission: fix permissions Oct 22, 2024
@diniamo

diniamo commented Oct 22, 2024

Copy link
Copy Markdown
Contributor Author

@ju1m could you help with this PR?

@ju1m

ju1m commented Oct 23, 2024

Copy link
Copy Markdown
Contributor

@diniamo thanks for spotting this mistake, type = with types; either str int could be used for backward compatibility, and a warning can be added to issue a deprecation message of int for the next stable version (nixos-25.05) when typeOf cfg.settings.umask == "string".

@diniamo

diniamo commented Oct 23, 2024

Copy link
Copy Markdown
Contributor Author

Does that mean I should remove the release note entry?

@ju1m

ju1m commented Oct 23, 2024

Copy link
Copy Markdown
Contributor

@diniamo , sorry I did not notice you had already done all that work, what you did is better, thanks!

@ju1m ju1m self-requested a review October 23, 2024 17:11

@ju1m ju1m left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ju1m ju1m added needs_merger 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. labels Oct 23, 2024
@diniamo

diniamo commented Oct 23, 2024

Copy link
Copy Markdown
Contributor Author

@ju1m just to make sure: I changed serviceConfig.StateDirectoryMode to cfg.downloadDirPermissions as well. It's needed because other things can't access any subdirectories, if they can't access the parent directory. Alternatively, do you have a better solution?

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one person. label Oct 23, 2024
@ju1m

ju1m commented Oct 23, 2024

Copy link
Copy Markdown
Contributor

@ju1m just to make sure: I changed serviceConfig.StateDirectoryMode to cfg.downloadDirPermissions as well. It's needed because other things can't access any subdirectories, if they can't access the parent directory. Alternatively, do you have a better solution?

Right, no I would not change StateDirectoryMode= because the better way security-wise is to add users to services.transmission.group, or to set cfg.settings.download-dir & co. to some path where intended users have access to them (since they are bind-mounted into the RootDirectory= using BindPaths=, transmission will be able to access them).

Besides, if cfg.downloadDirPermissions is null (the default) then StateDirectoryMode= would default to 755 instead of the current 750 which would open transmission's state folder read-only to every users. Sure ${cfg.home}/${settingsDir}/settings.json is forced to 600, but yet, AFAICS it's not necessary to relax the 750, just use services.transmission.group, which is allowed read-only.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep 750 and let users add themselves to the transmission group.

@diniamo

diniamo commented Oct 24, 2024

Copy link
Copy Markdown
Contributor Author

How do I add a user to multiple groups declaratively though?

Edit: seems like removing the downloadDirPermissions option worked. Although what happens if you set it to null is not documented.

@ju1m

ju1m commented Oct 24, 2024

Copy link
Copy Markdown
Contributor

How do I add a user to multiple groups declaratively though?

users.users."diniamo".extraGroups = [ config.transmission.group ];

Or:

users.groups.${config.transmission.group}.members = [ "diniamo" ];

@diniamo

diniamo commented Oct 24, 2024

Copy link
Copy Markdown
Contributor Author

And do you know why setting downloadDirPermissions to null makes it 755? I'll add a note about that to the description.

@ju1m

ju1m commented Oct 24, 2024

Copy link
Copy Markdown
Contributor

And do you know why setting downloadDirPermissions to null makes it 755? I'll add a note about that to the description.

Yes, I explained it in my previous message. But please do not use StateDirectoryMode = cfg.downloadDirPermissions; there's no need to relax 750 since user groups or bind-mounts are a common and more secure way to give access to directories.

@diniamo

diniamo commented Oct 25, 2024

Copy link
Copy Markdown
Contributor Author

How is this?

@ju1m ju1m Oct 25, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think you've misunderstood what I tried to say previously, when I wrote:

Besides, if cfg.downloadDirPermissions is null (the default) then StateDirectoryMode= would default to 755 instead of the current 750 which would open transmission's state folder read-only to every users.

I was describing what would happen if we were to use StateDirectoryMode = cfg.downloadDirPermissions; but that's no longer the case, so downloadDirPermissions == null remains a no-op.

Indeed, the description only documents the If not null, case, but adding users to config.transmission.group is unrelated to that option being null or not, it's related to StateDirectoryMode == "750".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then that option is very misleading. If I set it to 755, then I expect other users to be able to read the download directories, which is not the case. This is very unintuitive, and the option descriptions don't mention this anywhere. It took a long while before I figured out what was going on.

It would be nice if we could avoid wasting others' time. What do you suggest?

@ju1m ju1m Oct 26, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, downloadDirPermissions is a quirk that should not even exist in the first place, since adding users to services.transmission.group is both more secure and more idiomatic.

Yet this option lingers and we have to deal with it, I would suggest to improve its description by explaining the two main ways to give access to the directories that I explained previously:

  1. the better way security-wise is to add users to services.transmission.group,
  2. or to set cfg.settings.download-dir & co. to some path where intended users have access to them [and use settings.umask = "002" and downloadDirPermissions = "755"]

@diniamo

diniamo commented Oct 26, 2024

Copy link
Copy Markdown
Contributor Author

How is this?

I did some minimal testing in a VM, and it seems to be working fine.

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one person. label Oct 28, 2024
@Aleksanaa

Copy link
Copy Markdown
Member

We have to wait until after NixOS 24.11 as this is a breaking change and not a trivial fix.

@diniamo

diniamo commented Oct 28, 2024

Copy link
Copy Markdown
Contributor Author

I don't get it. Why do we have to wait for 24.11?

@Aleksanaa

Copy link
Copy Markdown
Member

Because breaking changes are blocked in this period to prepare for the next release. See #339153

@Aleksanaa Aleksanaa added the 2.status: wait for branch‐off Waiting for the next Nixpkgs branch‐off label Oct 28, 2024
@wegank wegank removed the 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. label Oct 29, 2024
@diniamo

diniamo commented Oct 29, 2024

Copy link
Copy Markdown
Contributor Author

@ju1m it looks like I didn't do enough research: transmission 3 (which is the default for the module) still uses the old way of configuring umask (decimal number), while transmission 4 uses the new way (octal number as a string). Should I update the default package as well, or?

@ambroisie

ambroisie commented Oct 29, 2024

Copy link
Copy Markdown
Contributor

@diniamo should probably be using type = with lib.types; either str int; (which would make it a non-breaking change) to accommodate both versions.

EDIT: maybe adjusting the default to be 2 or "002" depending of the version of cfg.package would be good too.

@diniamo

diniamo commented Oct 29, 2024

Copy link
Copy Markdown
Contributor Author

I was thinking of something like that as well. Thnaks for that suggestion, I'll implement it.

@ju1m

ju1m commented Oct 29, 2024

Copy link
Copy Markdown
Contributor

@ju1m it looks like I didn't do enough research: transmission 3 (which is the default for the module) still uses the old way of configuring umask (decimal number), while transmission 4 uses the new way (octal number as a string). Should I update the default package as well, or?

@diniamo, chances are that nixos-25.05 (first NixOS stable release on which this PR will land) may indeed switch to transmission_4 as default for services.transmission, which is currently blocked to transmission_3 for nixos-24.11:

- `transmission` package has been aliased with a `trace` warning to `transmission_3`. Since [Transmission 4 has been released last year](https://github.com/transmission/transmission/releases/tag/4.0.0), and Transmission 3 will eventually go away, it was decided perform this warning alias to make people aware of the new version. The `services.transmission.package` defaults to `transmission_3` as well because the upgrade can cause data loss in certain specific usage patterns (examples: [#5153](https://github.com/transmission/transmission/issues/5153), [#6796](https://github.com/transmission/transmission/issues/6796)). Please make sure to back up to your data directory per your usage:
- `transmission-gtk`: `~/.config/transmission`
- `transmission-daemon` using NixOS module: `${config.services.transmission.home}/.config/transmission-daemon` (defaults to `/var/lib/transmission/.config/transmission-daemon`)

But that would have to be discussed with people involved in #258058

diniamo added 3 commits October 29, 2024 15:34
nixos/transmission: improve code

- Remove `with lib;`
- Use `{ name = { ... }; }` instead of `{ name.foo = ...; name.bar =
...; }`
@github-actions github-actions Bot removed 8.has: documentation This PR adds or changes documentation 8.has: changelog This PR adds or changes release notes labels Oct 29, 2024
@diniamo

diniamo commented Oct 29, 2024

Copy link
Copy Markdown
Contributor Author

In that case, I'll leave updating the default to them, and this should be fine.

@diniamo

diniamo commented Oct 29, 2024

Copy link
Copy Markdown
Contributor Author

@Aleksanaa this is no longer a breaking change.

@l0b0 l0b0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread nixos/modules/services/torrent/transmission.nix
@diniamo

diniamo commented Dec 1, 2024

Copy link
Copy Markdown
Contributor Author

@l0b0 is there anything else to do?

@l0b0

l0b0 commented Dec 1, 2024

Copy link
Copy Markdown
Contributor

@l0b0 is there anything else to do?

Not as far as I'm concerned - I already accepted. I don't have merge rights though.

@diniamo

diniamo commented Dec 1, 2024

Copy link
Copy Markdown
Contributor Author

Oh huh, I thought you did.

@misuzu misuzu merged commit dfc9f72 into NixOS:master Dec 4, 2024
@diniamo

diniamo commented Dec 5, 2024

Copy link
Copy Markdown
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: wait for branch‐off Waiting for the next Nixpkgs branch‐off 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants