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/forgejo: Small cleanups and service capability changes #306457

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

pyrox0
Copy link
Member

@pyrox0 pyrox0 commented Apr 24, 2024

Also resolves #306205 and adds myself as a maintainer to the module.

Note: This won't eval cleanly until #306349, which fixes my maintainer attribute name, is merged. However, I've checked and it does work properly with that merged into the tree.

Description of changes

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.

nixos/modules/services/misc/forgejo.nix Show resolved Hide resolved
nixos/modules/services/misc/forgejo.nix Show resolved Hide resolved
nixos/modules/services/misc/forgejo.nix Show resolved Hide resolved
nixos/modules/services/misc/forgejo.nix Outdated Show resolved Hide resolved
@emilylange
Copy link
Member

Regarding #306457 (comment):

See result of nix-build -A nixosTests.forgejo.sqlite3 (or CI)
@ofborg build nixosTests.forgejo.sqlite3

nixos/modules/services/misc/forgejo.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/forgejo.nix Show resolved Hide resolved
nixos/modules/services/misc/forgejo.nix Show resolved Hide resolved
@pyrox0 pyrox0 force-pushed the forgejo-module-ssh branch 2 times, most recently from 440b34c to 357b7df Compare May 7, 2024 20:06
@pyrox0
Copy link
Member Author

pyrox0 commented May 7, 2024

Had to rebase, CI should be green now.

bendlas
bendlas previously requested changes May 8, 2024
Copy link
Contributor

@bendlas bendlas left a comment

Choose a reason for hiding this comment

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

Has the capabilities change been mixed in accidentally?

Feels like this should be a separate PR, because it's security-relevant and hasn't been mentioned in this PR before.

nixos/modules/services/misc/forgejo.nix Outdated Show resolved Hide resolved
@pyrox0 pyrox0 force-pushed the forgejo-module-ssh branch 2 times, most recently from 9b86a77 to 5998e34 Compare May 8, 2024 19:22
Copy link
Contributor

@bendlas bendlas left a comment

Choose a reason for hiding this comment

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

Retracting my change request, since I'm realizing that this is mainly about using the built-in ssh server. That's a use case that I simply don't have, but happen to know that @emilylange does. So I'll trust her expertise on this.

I'd still like to leave one self-quote from the resolved thread for posterity, because I feel like it meaningfully adds to the conversation.

Even when running a server without a reverse proxy, I prefer binding to high ports and then just redirecting the appropriate low ports via firewall.

@bendlas bendlas self-requested a review May 12, 2024 21:43
bendlas

This comment was marked as spam.

@pyrox0 pyrox0 changed the title nixos/forgejo: Cleanup environment settings nixos/forgejo: Small cleanups and service capability changes May 13, 2024
@mweinelt
Copy link
Member

I'm slightly worried about unconditionally handing out capabilities, that are not strictly required. My deployment currently only binds to a UNIX socket, and I honestly don't want it to be able bind to privileged ports by default.

# ss -lpn | grep forgejo
u_str LISTEN 0      128                     /run/forgejo/forgejo.sock 22892                  * 0    users:((".gitea-wrapped",pid=1603,fd=11))    

@emilylange
Copy link
Member

It's a bit unfortunate the CAP discussion/suggestion has been marked as resolved in the meantime.

From what I can tell the majority of Forgejo maintainers leaned towards something like allowBindPrivilegedPort (defaulting to false) in the end.

I get that it was my suggestion to make it unconditional in the first place.
But I changed my mind in #306457 (comment), voicing my support for such option (suggesting the inferior name allowPortBindBelow1024).

We could even backport that variant to 24.05 whenever this PR is ready and merged, long after the branch-off tomorrow, since it wouldn't be a breaking change.

Or, slightly more controversial, we could continue to not provide an option for this at all.

While we do not have concrete guidelines for this in nixpkgs, most folks I speak with expect users of unusual, edge-case-y and advanced configurations to be comfortable doing such override in question themselves via systemd.services.<name>.

{ lib, ... }: {
  systemd.services.forgejo.serviceConfig = {
    AmbientCapabilities = lib.mkForce [ "CAP_NET_BIND_SERVICE" ];
    CapabilityBoundingSet = lib.mkForce [ "CAP_NET_BIND_SERVICE" ];
    PrivateUsers = lib.mkForce false;
  };
}

What if we, as suggested somewhere in one of the many collapsed comments, split the CAP thingy from this PR as it currently stands.

That way, this whole CAP discussion does not hinder the uncontroversial changes from getting merged.

Specifically, the services.openssh conditional bug fix (#306205):

-    services.openssh.settings.AcceptEnv = mkIf (!cfg.settings.START_SSH_SERVER or false) "GIT_PROTOCOL";
+    services.openssh.settings.AcceptEnv = mkIf (!cfg.settings.server.START_SSH_SERVER or false) "GIT_PROTOCOL";

@pyrox0 getting added as maintainer and the GITEA_ -> FORGEJO_ thingy (noop).

PS: I genuinely haven't thought about port forwarding on the machine itself (what @bendlas suggested). I genuinely like that approach. Might copy that for my stuff.

@emilylange emilylange marked this pull request as draft May 24, 2024 23:41
@emilylange
Copy link
Member

Are you still interested in working on this, @pyrox0? :)

@pyrox0
Copy link
Member Author

pyrox0 commented Jun 15, 2024

I am still interested in working on this. I'll rebase and remove the CAP override so that the rest of this can get merged.

Since https://codeberg.org/forgejo/forgejo/issues/497 has been resolved,
these can now be `FORGEJO_` prefixed instead of `GITEA_`.
Adds the necessary capabilities to bind to the port if SSH_PORT is lower
than 1024, and also resolves issue NixOS#306205 by fixing the mentioned check
as well as documenting the mentioned option.
@pyrox0 pyrox0 marked this pull request as ready for review June 21, 2024 03:25
@pyrox0
Copy link
Member Author

pyrox0 commented Jun 24, 2024

This should be ready to merge.

@emilylange
Copy link
Member

@ofborg test forgejo

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.

Forgejo module changes openssh settings even when using built in ssh server
6 participants