Skip to content

Conversation

@networkException
Copy link
Member

@networkException networkException commented Dec 22, 2024

This pull request adds support for using systemd's LoadCredential= feature to read various secret files used by nextcloud service units.

Previously credentials had to be readable by the nextcloud user, this is now no longer required.

The nextcloud-occ wrapper script has been adjusted to use systemd-run for loading credentials when being called from outside a service.

See the individual commits for more details.

Depends on #365442
Continuation of #152141

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/)
  • 25.05 Release Notes (or backporting 24.11 and 25.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 Dec 22, 2024
@github-actions github-actions 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 Dec 22, 2024
@networkException
Copy link
Member Author

networkException commented Dec 22, 2024

This should be generally well tested already so reviews are encouraged, undrafting when

@Ma27
Copy link
Member

Ma27 commented Dec 22, 2024

Thanks!
Will try to review in the upcoming days.

@networkException networkException force-pushed the nextcloud-loadcredential branch 2 times, most recently from 6c60763 to 6fece8a Compare December 22, 2024 22:12
@networkException networkException marked this pull request as ready for review December 23, 2024 16:27
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why you added a fixme for that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe a note is better, I added this after removing the explicit (somewhat duplicate) variable from the nextcloud-update-db service

Copy link
Member

Choose a reason for hiding this comment

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

I think the comment is good for clarification, but I don't really see this as something super-actionable, so I think I'd prefer NOTE: here.

Copy link
Member Author

Choose a reason for hiding this comment

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

@networkException networkException force-pushed the nextcloud-loadcredential branch 3 times, most recently from 3d64615 to db42190 Compare January 5, 2025 21:11
@networkException
Copy link
Member Author

Rebased onto master and checked that the test still pass

@Ma27
Copy link
Member

Ma27 commented Jan 21, 2025

So the code mostly looks reasonable to me and the tests are passing.
I guess I'll pick it to my personal nixpkgs branch, deploy my private instance and see how it turns out.

Copy link
Member

@Ma27 Ma27 left a comment

Choose a reason for hiding this comment

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

Works as expected, thanks 👍

No approval yet though because

Also cc @britter @dotlambda you may also be interested in taking a look.

@networkException networkException force-pushed the nextcloud-loadcredential branch from db42190 to e08ac4c Compare January 21, 2025 12:12
…-and-secrets

This patch adds a subtest and corresponding configuration to
with-declarative-redis-and-secrets to test for nextcloud notify_push
to be working, just as in with-postgresql-and-redis.

As notify_push needs to connect to the database, including it
in this test checks that it can read the dbpassFile properly.
@networkException networkException force-pushed the nextcloud-loadcredential branch from e08ac4c to 549d8a6 Compare January 21, 2025 19:09
@networkException
Copy link
Member Author

networkException commented Jan 21, 2025

Rebased onto master again, tests still pass

@networkException
Copy link
Member Author

I had to adjust some parts of my config

What did you need to change?

@Ma27
Copy link
Member

Ma27 commented Jan 21, 2025

What did you need to change?

adminpassFile was set to a /run/credentials/... path already and this broke nextcloud-setup in the credentials setup phase.

Also, I had another service for generating previews for new images as a systemd timer and inherited ExecCOndition from nextcloud-setup which broke evaluation.

…ible change in the 25.05 release notes

This patch adds a release note entry to the 25.05 release
about the use of systemd credentials to read in secrets.

It's part of the backward incompatibilities section as
changes to the behavior of `nextcloud-occ` might break
existing scripts.
@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 Jan 22, 2025
`nextcloud-notify_push.service` requires
`nextcloud-notify_push-setup.service`. If the latter fails (e.g. because
of Nextcloud not being there yet), the push service would also fail with
result 'dependency'.

RestartMode=direct doesn't put a unit into failed state IF it's about to
be restarted again. That way, `nextcloud-notify_push` will await several
restart attempts. Only if the unit fails due to a rate-limit (i.e. too
many restarts), the push service will also fail.

If the startup is still too slow, it may make sense for administrators to
configure higher intervals between the start attempts with RestartSec.
Copy link
Member

@Ma27 Ma27 left a comment

Choose a reason for hiding this comment

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

I deploy my Nextcloud with these patches on top for ~2 months now. I'm getting 'eepy now, so I'll merge tomorrow afternoon.

If people still have reservations about this, please speak up.

@Ma27 Ma27 merged commit 6c4f93e into NixOS:master Mar 7, 2025
27 checks passed
@SuperSandro2000
Copy link
Member

I just cherry-picked that into my local nixos-unstable fork and shellcheck fails. I will do a follow up PR that fixes that.

SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Mar 7, 2025
@SuperSandro2000
Copy link
Member

#387913

@Ma27
Copy link
Member

Ma27 commented Mar 7, 2025

I just cherry-picked that into my local nixos-unstable fork and shellcheck fails. I will do a follow up PR that fixes that.

Where is the shellcheck even running? Tests were all building fwiw.

@SuperSandro2000
Copy link
Member

I have systemd.enableStrictShellChecks
https://search.nixos.org/options?channel=unstable&show=systemd.enableStrictShellChecks&from=0&size=50&sort=relevance&type=packages&query=shellcheck enabled globally, so it didn't trigger when you build it.

@Ma27
Copy link
Member

Ma27 commented Mar 8, 2025

Oof... that sounds like an invitation for random build failures whenever one updates their systems.
To be clear: I've seen the missing quotes, but I decided to not start another feedback cycle for that given that (1) it is guaranteed that CREDENTIALS_DIRECTORY exists and (2) the quotes do not improve the error reporting if it it doesn't.

I mean, I'll merge since it doesn't hurt and will fix people's setup with this option, but... I'm not sure if this option is a good idea in the first place.

@SuperSandro2000
Copy link
Member

I have it on since a while and after the initial fixes I barely get any regressions. Maybe every 2 to 4 weeks. It is surprising. 😂

@eyJhb
Copy link
Member

eyJhb commented May 31, 2025

This PR breaks the following use-case here, where I utilize nextcloud-setup to reset the admin users password. I can't even do it by hand anymore, as the OC_PASS is no longer being preserved.

Are there any good ways to mitigate this?

EDIT: I've made a issue here #412675

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

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants