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/pam: Use secure default for sshAgentAuth.authorizedKeysFiles #277626

Merged
merged 1 commit into from
Apr 28, 2024

Conversation

nbraud
Copy link
Contributor

@nbraud nbraud commented Dec 29, 2023

Follow-up on #277620, blocked until it is merged.

Description of changes

Change the default value of security.pam.sshAgentAuth.authorizedKeysFiles to [ "/etc/ssh/authorized_keys.d/%u" ].
This breaks backwards-compatibility to fix a security vulnerability: #31611

Things done


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: documentation This PR adds or changes documentation 8.has: changelog 8.has: module (update) This PR changes an existing module in `nixos/` labels Dec 29, 2023
@nbraud nbraud requested a review from Majiir December 29, 2023 22:28
@nbraud nbraud added 1.severity: security Issues which raise a security issue, or PRs that fix one 2.status: blocked by pr/issue Another PR or issue is preventing this from being completed needs_reviewer (old Marvin label, do not use) labels Dec 29, 2023
Copy link
Contributor

@Majiir Majiir left a comment

Choose a reason for hiding this comment

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

LGTM. Are you planning to merge this for unstable only?

Comment on lines 42 to 63
- The `pam_ssh_agent_auth(8)` module now trusts files listed in `security.pam.sshAgentAuth.authorizedKeysFiles`,
defaulting to `/etc/ssh/authorized_keys.d/%u` only; previously, the set of trusted `authorized_keys` files wasn't
configurable and included `~/.ssh/authorized_keys` **which is insecure**:
see [#31611](https://github.com/NixOS/nixpkgs/issues/31611).

Copy link
Contributor

Choose a reason for hiding this comment

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

On one hand, this note could make it more obvious that upgrading could cause a user to lose access to anything protected by pam_ssh_agent_auth. On the other hand, they could always boot up an earlier configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. I'll try and think of a more-explicit wording, thanks <3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Majiir What do you think of the new wording?

@Kranzes
Copy link
Member

Kranzes commented Dec 29, 2023

Can't we also use config.services.openssh.authorizedKeysFiles?

@nbraud
Copy link
Contributor Author

nbraud commented Dec 30, 2023

Can't we also use config.services.openssh.authorizedKeysFiles?

No. That's the current behaviour (and remains the default after #277620) but it's insecure-by-default:
services.openssh.authorizedKeysFiles contains %h/.ssh/authorized_keys which is user-writeable.

The reason this is a problem is explained (and illustrated with exploitation steps) in #31611

PS: In case that was unclear, this PR includes the commits that are in #277620, but only 24536c0c0884f694d987b4b445403daa492c7357 is new here.

@nbraud
Copy link
Contributor Author

nbraud commented Dec 30, 2023

LGTM. Are you planning to merge this for unstable only?

I guess? That would be a breaking change for users of the 23.11 branch, in principle, and I expect the previous PR's warning to trigger on the vast majority of insecure configurations.

@nbraud nbraud force-pushed the nixos/pam/ssh-agent-auth-31611-fix branch from 907127f to 24536c0 Compare December 30, 2023 22:07
@nbraud
Copy link
Contributor Author

nbraud commented Dec 30, 2023

Rebased on the current version of #277620

@nbraud
Copy link
Contributor Author

nbraud commented Dec 31, 2023

Rebased after #266332

@nbraud nbraud force-pushed the nixos/pam/ssh-agent-auth-31611-fix branch from 24536c0 to e129071 Compare December 31, 2023 10:20
@nbraud
Copy link
Contributor Author

nbraud commented Jan 1, 2024

Rebased after #266332

@nbraud nbraud force-pushed the nixos/pam/ssh-agent-auth-31611-fix branch 2 times, most recently from 5775b42 to c8f25bf Compare January 5, 2024 11:34
@nbraud
Copy link
Contributor Author

nbraud commented Jan 5, 2024

Rebased on current #277620, should be final.

@nbraud nbraud marked this pull request as ready for review January 8, 2024 17:12
@nbraud nbraud added needs_merger (old Marvin label, do not use) 12.approvals: 1 This PR was reviewed and approved by one reputable person labels Jan 8, 2024
@nbraud
Copy link
Contributor Author

nbraud commented Jan 8, 2024

@ofborg eval

@nbraud
Copy link
Contributor Author

nbraud commented Jan 8, 2024

Rebased on the previous PR's merge commit, so GitHub shows the appropriate commit set and diff. Only change in file is from #276499 being merged :

❯ git --no-pager diff c8f25bf f5ed08f -- nixos/modules/security/pam.nix
diff --git a/nixos/modules/security/pam.nix b/nixos/modules/security/pam.nix
index aedcac44cf71..95aceeaccc5c 100644
--- a/nixos/modules/security/pam.nix
+++ b/nixos/modules/security/pam.nix
@@ -1473,6 +1473,13 @@ in
           `security.pam.zfs.enable` requires enabling ZFS (`boot.zfs.enabled` or `boot.zfs.enableUnstable`).
         '';
       }
+      {
+        assertion = config.security.pam.enableSSHAgentAuth -> config.services.openssh.authorizedKeysFiles != [];
+        message = ''
+          `security.pam.enableSSHAgentAuth` requires `services.openssh.authorizedKeysFiles` to be a non-empty list.
+          Did you forget to set `services.openssh.enable` ?
+        '';
+      }
     ];

     warnings = optional

@nbraud nbraud force-pushed the nixos/pam/ssh-agent-auth-31611-fix branch from c8f25bf to f5ed08f Compare January 8, 2024 17:42
@delroth delroth removed the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Jan 8, 2024
@nbraud
Copy link
Contributor Author

nbraud commented Jan 8, 2024

eval failure fixed in master
@ofborg eval

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Jan 8, 2024
@nbraud nbraud requested a review from Majiir January 8, 2024 19:37
@nbraud
Copy link
Contributor Author

nbraud commented Jan 9, 2024

@ofborg test ssh-agent-auth

@nbraud
Copy link
Contributor Author

nbraud commented Jan 12, 2024

Rebased due to merge conflict in release notes. No change.

@nbraud nbraud force-pushed the nixos/pam/ssh-agent-auth-31611-fix branch from f5ed08f to bd6966b Compare January 12, 2024 13:42
@nbraud
Copy link
Contributor Author

nbraud commented Jan 12, 2024

@ofborg test ssh-agent-auth

Copy link
Member

@leona-ya leona-ya left a comment

Choose a reason for hiding this comment

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

Seems to be reasonable and good.

@wegank wegank added the 12.approvals: 3+ This PR was reviewed and approved by three or more reputable people label Mar 8, 2024
Copy link
Member

@LeSuisse LeSuisse left a comment

Choose a reason for hiding this comment

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

Changes make sense. I played a bit with it locally and everything works as expected.

If nobody complains about it, I'm going to merge this by the end of the week.

@montchr
Copy link
Member

montchr commented Apr 26, 2024

When this is released, are there any safeguards (edit: other than a warning explaining the change in abstract) to prevent a system admin from accidentally locking themselves out through misunderstanding the implications? Is there any way to make it crystal clear exactly which authorized keys will be affected on a system?

@LeSuisse
Copy link
Member

[...] prevent a system admin from accidentally locking themselves out through misunderstanding the implications? Is there any way to make it crystal clear exactly which authorized keys will be affected on a system?

Unfortunately given that the root cause comes from a default setting with a wrong value I do not see a lot of options.

The probability of being locked out seems to be quite low:

  • it requires that the system admin was relying on the behavior this PR is fixing
  • the default value was kept
  • pam_ssh_agent_auth is the only available way for local auth
  • the system admin cannot rollback to the previous generation at boot

This is not ideal but keeping this footgun around is also not :/

@LeSuisse LeSuisse merged commit deed6fb into NixOS:master Apr 28, 2024
11 checks passed
@nbraud nbraud deleted the nixos/pam/ssh-agent-auth-31611-fix branch April 29, 2024 17:10
@@ -47,6 +47,20 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m

- `himalaya` was updated to v1.0.0-beta, which introduces breaking changes. Check out the [release note](https://github.com/soywod/himalaya/releases/tag/v1.0.0-beta) for details.

- `security.pam.enableSSHAgentAuth` was replaced by the `sshAgentAuth` attrset, and **only**
Copy link
Member

Choose a reason for hiding this comment

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

This should use the renamed option which I think got dropped below and was at some point later re-added #316884

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.severity: security Issues which raise a security issue, or PRs that fix one 2.status: blocked by pr/issue Another PR or issue is preventing this from being completed 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog 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 12.approvals: 3+ This PR was reviewed and approved by three or more reputable people needs_merger (old Marvin label, do not use) needs_reviewer (old Marvin label, do not use)
Projects
None yet
Development

Successfully merging this pull request may close these issues.