Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What I did
Enhanced the tacacs PAM module & NSS module to parse and process the "vrfname" and to setsockopt using SO_BINDTODEVICE for "mgmt" interface.
How I did it
The optional parameter "--use-mgmt-vrf" used while configuring "tacacs server" results in configuring the DB with vrfname as "mgmt". Files "files/image_config/hostcfgd/common-auth-sonic.j2" and "files/image_config/hostcfgd/tacplus_nss_conf.j2" are modified to read this optional parameter and update the PAM & NSS configuration files "/etc/pam.d/common-auth" and "/etc/tacplus_nss.conf" respectively with the vrfname.
After enhancing the code for NSS in the file nss_tacplus.c for parsing the vrfname and passing it to the connect library function "tac_connect_single", git patch "0003-management-vrf-support.patch" was generated and checked in.
Similarly PAM code is also enhanced to parse and pass vrfname to the connect library function. PAM library code (libtac2) is also enhanced to do the actual SO_BINDTODEVICE in libtac/lib/connect.c for the "mgmt" vrfname. Git patch "0004-management-vrf-support.patch" was generated with all these PAM changes.
src/tacacs/Makefile is enhanced to use these enhanced patches for PAM & NSS.
How to verify it
Configure aaa to use "tacacs+", have a tacacs+ server connected in management network and verify that SSH authentication happens with the mgmt interface when --use-mgmt-vrf is enabled.
Tested it along with the command "config tacacs --use-mgmt-vrf 10.11.55.40" and verified that the passed parameter "vrfname" is there in /etc/sonic/config_db.json file under TACPLUS_SERVER. Verified that "show tacacs" displays the newly configured vrfname for the server IP.
Verified that the /etc/tacplus_nss.conf and /etc/pam.d/common-auth configuration files contain the "mgmt" vrfname when --use-mgmt-vrf is enabled.
Changed the "aaa" config to use tacacs+ and verified that the SSH login uses the management interface to connect to the tacacs+ server and authenticates the user.
Captured packets on management interface to verify the tacacs+ packets flow.
Executed another test case without management vrf (no "mgmt" vrf created, no separation of data and mgmt vrf) and confirmed that it works fine as it is today (note that --use-mgmt-vrf is not used in this test case).