Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/nextcloud: fix nginx routing to store and nix apps #277382

Merged
merged 1 commit into from
Dec 29, 2023

Conversation

Ma27
Copy link
Member

@Ma27 Ma27 commented Dec 28, 2023

Description of changes

Closes #277206

The bug mentioned above was a symptom of the issue fixed here: when opening the forms app which is installed via extraApps (or the app store) the site wouldn't work because .mjs files had the wrong Content-Type.

The actual problem got fixed already[1], however this config was not used for stuff from /nix-apps & /store-apps which had their own location section with only a root ; statement.

In fact, this setup isn't strictly supported by Nextcloud upstream[2], so to fix this for good, I decided to follow the upstream suggestion for app directories outside the server root, i.e. linking them back into the store path.

This means that the module generates a new derivation now with

  • services.nextcloud.package linked into it via lndir.
  • under nix-apps is a symlink to the link farm containing all apps from services.nextcloud.extraApps.
  • under store-apps is a symlink to /var/lib/nextcloud/store-apps. Since this is only used in the NixOS module that also configures this location for imperatively installed apps, this seems an OK thing to do.

Successfully tested the change on a productive Nextcloud 28.0.1 with several apps installed via extraApps (forms, cospend, maps, user_saml and a few more).

[1] 292c74c
[2] https://docs.nextcloud.com/server/28/admin_manual/apps_management.html#using-custom-app-directories

cc @Silver-Golden for testing.

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.05 Release Notes (or backporting 23.05 and 23.11 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.

@Silver-Golden
Copy link
Member

I'lltest this out this evening and get back to ye.
Thanks for the prompt response.

@SuperSandro2000
Copy link
Member

I don't think we really want to backport this to 23.05 which supports ends literally in the next days.

Copy link
Member

@SuperSandro2000 SuperSandro2000 left a comment

Choose a reason for hiding this comment

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

I've cherry-picked the commit into my fork and deployed it to my nextcloud which only has store-apps, no apps installed via nix, and I didn't encounter any issues.

nixos/modules/services/web-apps/nextcloud.nix Outdated Show resolved Hide resolved
nixos/modules/services/web-apps/nextcloud.nix Outdated Show resolved Hide resolved
Copy link
Contributor

@beardhatcode beardhatcode left a comment

Choose a reason for hiding this comment

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

I no not have time to test this on my server atm, but it looks good

@Silver-Golden
Copy link
Member

I copied the nextcloud.nix file locally, added disabledModules = [ "services/web-apps/nextcloud.nix" ]; to disable the existing one and then imported that file.

Forms work as expected.

Closes NixOS#277206

The bug mentioned above was a symptom of the issue fixed here: when
opening the `forms` app which is installed via `extraApps` (or the
app store) the site wouldn't work because `.mjs` files had the wrong
Content-Type.

The actual problem got fixed already[1], however this config was not
used for stuff from `/nix-apps` & `/store-apps` which had their own
location section with only a `root ;` statement.

In fact, this setup isn't strictly supported by Nextcloud upstream[2],
so to fix this for good, I decided to follow the upstream suggestion for
app directories outside the server root, i.e. linking them back into the
store path.

This means that the module generates a new derivation now with

* `services.nextcloud.package` linked into it via `lndir`.
* under `nix-apps` is a symlink to the link farm containing all apps
  from `services.nextcloud.extraApps`.
* under `store-apps` is a symlink to `/var/lib/nextcloud/store-apps`.
  Since this is only used in the NixOS module that also configures this
  location for imperatively installed apps, this seems an OK thing to
  do.

Successfully tested the change on a productive Nextcloud 28.0.1 with
several apps installed via `extraApps` (`forms`, `cospend`, `maps`,
`user_saml` and a few more).

[1] 292c74c
[2] https://docs.nextcloud.com/server/28/admin_manual/apps_management.html#using-custom-app-directories
@Ma27 Ma27 merged commit a1f20ed into NixOS:master Dec 29, 2023
19 checks passed
@Ma27 Ma27 deleted the fix-nextcloud-app-routing branch December 29, 2023 22:44
Copy link
Contributor

Backport failed for release-23.05, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin release-23.05
git worktree add -d .worktree/backport-277382-to-release-23.05 origin/release-23.05
cd .worktree/backport-277382-to-release-23.05
git switch --create backport-277382-to-release-23.05
git cherry-pick -x bae5e6516269cc804974ef2d5f494d46f7a012c1

Copy link
Contributor

Successfully created backport PR for release-23.11:

Ma27 added a commit to Ma27/nixpkgs that referenced this pull request Feb 10, 2024
PR NixOS#277382 didn't fix just an issue with .mjs files for the `forms` app,
but an underlying, more problematic issue: for `/nix-apps` &
`/store-apps`, the fcgi config for PHP and the block for assets were
never reached.

That meant that e.g. `/nix-apps/notes/lib/AppInfo/Application.php`
returned the PHP source code as text/plain. Considering that there was
never a fundamental change to how this config's structure, I'm pretty
sure that the issue was pretty much there since the module exists.

After consulting the NixOS security team we agreed that this is most
likely harmless because you'd have to use private apps with secrets in
the raw PHP code of said app. However, this is still problematic because
one important assumption - that PHP code is never sent to the browser -
is broken which is why we decided on not mentioning this impact in the
previous PR from December 2023.

To make sure that we don't regress our nginx config, I decided to add
the reproducer which fails on 8bbbb22
as testcase to our integration tests.
github-actions bot pushed a commit that referenced this pull request Feb 21, 2024
PR #277382 didn't fix just an issue with .mjs files for the `forms` app,
but an underlying, more problematic issue: for `/nix-apps` &
`/store-apps`, the fcgi config for PHP and the block for assets were
never reached.

That meant that e.g. `/nix-apps/notes/lib/AppInfo/Application.php`
returned the PHP source code as text/plain. Considering that there was
never a fundamental change to how this config's structure, I'm pretty
sure that the issue was pretty much there since the module exists.

After consulting the NixOS security team we agreed that this is most
likely harmless because you'd have to use private apps with secrets in
the raw PHP code of said app. However, this is still problematic because
one important assumption - that PHP code is never sent to the browser -
is broken which is why we decided on not mentioning this impact in the
previous PR from December 2023.

To make sure that we don't regress our nginx config, I decided to add
the reproducer which fails on 8bbbb22
as testcase to our integration tests.

(cherry picked from commit 37d6961)
Septias pushed a commit to Septias/nixpkgs that referenced this pull request Feb 21, 2024
PR NixOS#277382 didn't fix just an issue with .mjs files for the `forms` app,
but an underlying, more problematic issue: for `/nix-apps` &
`/store-apps`, the fcgi config for PHP and the block for assets were
never reached.

That meant that e.g. `/nix-apps/notes/lib/AppInfo/Application.php`
returned the PHP source code as text/plain. Considering that there was
never a fundamental change to how this config's structure, I'm pretty
sure that the issue was pretty much there since the module exists.

After consulting the NixOS security team we agreed that this is most
likely harmless because you'd have to use private apps with secrets in
the raw PHP code of said app. However, this is still problematic because
one important assumption - that PHP code is never sent to the browser -
is broken which is why we decided on not mentioning this impact in the
previous PR from December 2023.

To make sure that we don't regress our nginx config, I decided to add
the reproducer which fails on 8bbbb22
as testcase to our integration tests.
superherointj pushed a commit to nixpkgs-friendly/nixpkgs-friendly that referenced this pull request Feb 22, 2024
PR NixOS#277382 didn't fix just an issue with .mjs files for the `forms` app,
but an underlying, more problematic issue: for `/nix-apps` &
`/store-apps`, the fcgi config for PHP and the block for assets were
never reached.

That meant that e.g. `/nix-apps/notes/lib/AppInfo/Application.php`
returned the PHP source code as text/plain. Considering that there was
never a fundamental change to how this config's structure, I'm pretty
sure that the issue was pretty much there since the module exists.

After consulting the NixOS security team we agreed that this is most
likely harmless because you'd have to use private apps with secrets in
the raw PHP code of said app. However, this is still problematic because
one important assumption - that PHP code is never sent to the browser -
is broken which is why we decided on not mentioning this impact in the
previous PR from December 2023.

To make sure that we don't regress our nginx config, I decided to add
the reproducer which fails on 8bbbb22
as testcase to our integration tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nextcloud28: Forms page is blank
5 participants