Skip to content

[libnss-radius] Handle empty secondary groups for useradd#23571

Open
manoharan-nexthop wants to merge 1 commit intosonic-net:masterfrom
manoharan-nexthop:nss-radius
Open

[libnss-radius] Handle empty secondary groups for useradd#23571
manoharan-nexthop wants to merge 1 commit intosonic-net:masterfrom
manoharan-nexthop:nss-radius

Conversation

@manoharan-nexthop
Copy link

Fixes #23570

How I did it

When a user login is attempted, the user is created locally and then the user is processed for authentication. With the issue, the user creation fails and the successive authentication happens with wrong information. When the user was created locally and then the authentication was attempted, we dont hit the issue.

the user addition fails as the secondary group list is empty and when it is, useradd fails with invalid -G argument. Check for secondary group string validity before using the same.

How to verify it

Verified the user authentication is successful.

Which release branch to backport (provide reason below if selected)

The issue exists only in master.

  • 202205
  • 202211
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505

Description for the changelog

[libnss-radius] Handle empty secondary groups for useradd

@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@dt-nexthop
Copy link
Contributor

@qiluo-msft, would you mind reviewing this when you get a chance?

@qiluo-msft qiluo-msft requested review from Copilot and liuh-80 August 11, 2025 21:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug in the libnss-radius NSS module where user creation fails when the secondary groups list is empty. The issue occurs during user authentication when useradd is called with an invalid -G argument containing an empty string, causing the user creation to fail and subsequent authentication to use incorrect information.

  • Adds validation to check if secondary groups string is non-empty before passing it to useradd
  • Provides separate execl calls for cases with and without secondary groups
  • Fixes the authentication flow by ensuring user creation succeeds before authentication attempts

@qiluo-msft
Copy link
Collaborator

Could you add sonic-mgmt testcase?

@dt-nexthop
Copy link
Contributor

dt-nexthop commented Aug 11, 2025

Yes, there are in this PR - sonic-net/sonic-mgmt#16475 - but since the current master build in sonic has this bug, all the tests will fail on the sonic-mgmt PR. We have run them locally, though, with this patch, and they do pass. @manoharan-nexthop, can you paste in the local results to this PR?

@qiluo-msft qiluo-msft requested a review from Yarden-Z August 11, 2025 21:45
@manoharan-nexthop
Copy link
Author

Yes, there are in this PR - sonic-net/sonic-mgmt#16475 - but since the current master build in sonic has this bug, all the tests will fail on the sonic-mgmt PR. We have run them locally, though, with this patch, and they do pass. @manoharan-nexthop, can you paste in the local results to this PR?

With this change, all the tests passes..

1 test_radius_rw_user PASS
2 test_radius_ro_user PASS
3 test_radius_command_auth PASS
4 test_radius_fallback PASS
5 test_radius_failed_auth PASS
6 test_radius_source_ip PASS

@dt-nexthop
Copy link
Contributor

@qiluo-msft please give another review to this PR when you get a chance

Why I did it
User authentication through radius fails with invalid password information sent to radius server.

How I did it
When a user login is attempted, the user is created locally and then the user is processed for authentication. With the issue, the user creation fails and the successive authentication happens with wrong information. When the user was created locally and then the authentication was attempted, we dont hit the issue.

the user addition fails as the secondary group list is empty and when it is, useradd fails with invalid -G argument. Check for secondary group string validity before using the same.

How to verify it
Verified the user authentication is successful.
@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link

@Yarden-Z Yarden-Z left a comment

Choose a reason for hiding this comment

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

Looks good - do we have a fix for tacacs as well?
Since I think the same item applies there as well

@dt-nexthop
Copy link
Contributor

@Yarden-Z, not sure about TACACS, can we take that up in a different PR?

@manoharan-nexthop
Copy link
Author

Looks good - do we have a fix for tacacs as well? Since I think the same item applies there as well

I dont see similar issue in TACACS.. The issue is happening only with RADIUS.

@dt-nexthop
Copy link
Contributor

@ Yarden-Z I wanted to see if there is anything left we need to do merge this one in. I would like to get this merged in so the RADIUS test in sonic-mgmt will also start passing.

Copy link

@Yarden-Z Yarden-Z left a comment

Choose a reason for hiding this comment

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

If nothing is relevant for Tacacs - this looks ok.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: garbage password sent when authenticating with RADIUS through SSH

7 participants