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

packaging: Require account validation with pam_unix.so if PAM enabled #15163

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

ton31337
Copy link
Member

With a current pam_rootok.so, it works only with root account. If the user is under frrvty, frr group, it gets the error:

% groups | grep -o -E "frrvty|frr"
frrvty
frr

% vtysh -c 'end'
vtysh_pam: Failed in account validation: Permission denied(6)

Checking the logs:

vtysh[23930]: pam_rootok(frr:account): root check failed

Let's require a valid user, instead of the root user only.

@donaldsharp
Copy link
Member

Possible to get @eqvinox to look at this?

@ton31337 ton31337 added this to the 10.0 milestone Jan 19, 2024
@Jafaral Jafaral self-requested a review January 23, 2024 16:39
Copy link
Contributor

@eqvinox eqvinox left a comment

Choose a reason for hiding this comment

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

Hard NAK.

PAM is incomplete in FRR and should in fact be disabled. It would only work correctly if vtysh is setuid root. pam_unix.so requires root privileges, which you don't have when executing vtysh.

A possible reason to ship FRR with PAM enabled is so that users can enable it without rebuilding FRR, by first setting vtysh setuid root and then making a PAM config. However, we do not test this and it very likely does not work correctly and creates security holes.

OTOH the reason why we're not disabling PAM is probably that users and distro packagers would get confused ("why are you removing security?".) It's a bit of a stupid situation.

@eqvinox
Copy link
Contributor

eqvinox commented Jan 27, 2024

Actually the correct fix here is to replace pam_rootok with pam_permit.

Except then people will complain that we created a security hole on their system by opening something up.

sigh

@ton31337
Copy link
Member Author

More context: #14745

@eqvinox
Copy link
Contributor

eqvinox commented Jan 27, 2024

More context: #14745

Actually it looks like we ignore the PAM result anyway. Which means maybe we can fix this properly because that means we can't be breaking someone's security (because it was already broken, lol.)

@eqvinox
Copy link
Contributor

eqvinox commented Jan 27, 2024

Ok. Yeah. So. This is what we're currently doing: https://github.com/FRRouting/frr/blob/master/vtysh/vtysh_user.c#L51-L74

  • we run the auth check. If it fails, we refuse. Which is pointless for 2 reasons: (a) we already have a logged-in user, we're not trying to become a user, and (b) it defaults to pam_permit anyway. The only reason to do this is that we have to establish who we are for the acct check next (⇒ pam_permit is the correct thing! We're already logged in.)

  • we run the acct check. If it fails, we print a message and continue anyway. (Note second_ret is overwritten with the result from pam_end.) In theory, this would be the place where some admin could put extra security settings. But it does not work for FRR.

  • ultimately we connect() to the daemon VTY sockets. Whether we can do this depends solely on whether we are in the frrvty group or not. If we already are in the frrvty group before the entire PAM circus, we can always do it, and the user can also just use some other tool to directly open the daemon VTY sockets, e.g. socat. If we are not in the frrvty group before the PAM circus, PAM can't add it (because we're not root) and we wil fail anyway regardless of PAM.

⇒ the entirety of PAM in FRRouting is non-functional

Generally speaking, all pam_* functions must be executed with root privilege to work correctly. This is rather poorly documented, but inherent by how PAM operates — the PAM modules need to access files accessible only by root (e.g. /etc/shadow).

@ton31337
Copy link
Member Author

Okay, so just to "hide" the warnings, we can use pam_permit.so? I can change that if this is the only change.

@eqvinox
Copy link
Contributor

eqvinox commented Jan 27, 2024

Okay, so just to "hide" the warnings, we can use pam_permit.so? I can change that if this is the only change.

Yes. In lieu of either disabling it completely, or completely reworking it to do something useful (which would involve making vtysh suid and/or sgid), using pam_permit is a good band-aid.

I would also add a comment to the /etc/pam.d/frr file saying that PAM in FRR is non-functional.

NB: /etc/pam.d/frr is likely not overwritten by package updates, i.e. we may need to make a note somewhere for people seeing this issue after FRR or system upgrades.

@github-actions github-actions bot added the rebase PR needs rebase label Jan 27, 2024
debian/frr.pam Outdated Show resolved Hide resolved
With a current pam_rootok.so, it works only with `root` account. If the user
is under `frrvty`, `frr` group, it gets the error:

```
% groups | grep -o -E "frrvty|frr"
frrvty
frr

% vtysh -c 'end'
vtysh_pam: Failed in account validation: Permission denied(6)
```

Checking the logs:

```
vtysh[23930]: pam_rootok(frr:account): root check failed
```

Signed-off-by: Donatas Abraitis <[email protected]>
@ton31337 ton31337 removed the rebase PR needs rebase label Jan 28, 2024
@Jafaral Jafaral merged commit 471e4b7 into FRRouting:master Jan 30, 2024
11 checks passed
@ton31337 ton31337 deleted the fix/pam_account branch January 30, 2024 17:49
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.

4 participants