Skip to content

[tacacs]: Add SSH TraceId authorization attribute#27667

Open
Rod-Persky wants to merge 5 commits into
sonic-net:masterfrom
Rod-Persky:dev/rodpersky/sonic-tracability
Open

[tacacs]: Add SSH TraceId authorization attribute#27667
Rod-Persky wants to merge 5 commits into
sonic-net:masterfrom
Rod-Persky:dev/rodpersky/sonic-tracability

Conversation

@Rod-Persky

@Rod-Persky Rod-Persky commented Jun 2, 2026

Copy link
Copy Markdown

Why I did it

Operators correlating SSH activity with TACACS+ audit logs currently have no way to tie a user's interactive shell session to a higher-level request trace. This PR implements the HLD in sonic-net/SONiC#2358 by propagating a client-supplied SSH_CLIENT_TRACEID from the SSH session into per-command TACACS+ authorization requests, so each authorized command carries the originating trace identifier. This PR also depends on sonic-net/sonic-host-services#407 for tacplus_nss configuration support.

Work item tracking
  • Microsoft ADO (number only): 38265947

How I did it

  • build_debian.sh: append AcceptEnv SSH_CLIENT_TRACEID to sshd_config (idempotent guard so re-runs don't duplicate the line) so OpenSSH will accept a SSH_CLIENT_TRACEID env var sent by the client via SendEnv.
  • files/image_config/bash/bash.bashrc: in interactive shells, mark SSH_CLIENT_TRACEID as readonly when present so the user cannot mutate or unset it for the lifetime of the shell.
  • src/tacacs/bash_tacplus/bash_tacplus.c: new get_trace_id() helper reads $SSH_CLIENT_TRACEID, enforces the TACACS+ 255-byte attribute limit, and rejects any value containing characters outside [A-Za-z0-9._:-|]. send_authorization_message() attaches it as a traceid=<value> attribute on each authorization request when valid; behavior is unchanged when SSH_CLIENT_TRACEID is absent, empty, oversized, or contains unsafe characters (silently dropped with a debug log).
  • src/tacacs/bash_tacplus/unittest/: extend mock_helper to capture SSH_CLIENT_TRACEID attribute adds, and add 5 CUnit cases covering valid, missing, empty, invalid-character, and oversized values.

How to verify it

  1. Build sonic-vs from this branch and install on a VS testbed configured with TACACS+ authorization.
  2. From a client with SendEnv SSH_CLIENT_TRACEID (or ssh -o SendEnv=SSH_CLIENT_TRACEID), export a value such as SSH_CLIENT_TRACEID=trace-123:abc.def and SSH to the DUT.
  3. Run any command and confirm the TACACS+ server log shows the request with a traceid=trace-123:abc.def attribute alongside the usual cmd/service/protocol attributes.
  4. Verify negative cases: connect without SSH_CLIENT_TRACEID, with an empty value, with an oversized value (>247 chars), and with disallowed characters (e.g. newline, space, ;) — authorization still succeeds and no traceid attribute is sent.
  5. Inside the shell, SSH_CLIENT_TRACEID=other / unset SSH_CLIENT_TRACEID must fail with "readonly variable".
  6. Run the unit tests cd src/tacacs/bash_tacplus/unittest && make && ./plugin_test and all CUnit cases (including the 5 new TraceId tests) must pass.

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

  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511

Backport requested to 202505 (20250510), 202411 (20241110), and 202305 (20230531) although not required initially as these are major long-lived release trains used in production, and SSH↔TACACS+ traceability is needed for incident correlation on those fleets. The change is small, behind an opt-in env var, and a no-op when TraceId is unset, so the risk profile is acceptable for stable branches.

Tested branch (Please provide the tested image version)

  • master.

Description for the changelog

[tacacs]: Propagate SSH-supplied SSH_CLIENT_TRACEID env var as a TACACS+ authorization attribute for per-command audit correlation.

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

image

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 2, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: Copilot / name: Copilot (2debd38)
  • ✅ login: Rod-Persky / name: Rod Persky (2debd38)

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

This PR has backport request for branch(es): 202305,202411,202505.
Added label(s) for branch(es) 202305,202411,202505.

---Powered by SONiC BuildBot

@Rod-Persky

Copy link
Copy Markdown
Author

Validated on the pipeline build https://dev.azure.com/mssonic/build/_build/results?buildId=1128509

image

…uthorization

Implements the HLD in sonic-net/SONiC#2358. Accepts a client-supplied `TraceId` env var via OpenSSH AcceptEnv, marks it readonly in the user's initial interactive bash, validates the value, and attaches it as a `TraceId=<value>` attribute on per-command TACACS+ authorization requests. Behavior is unchanged when TraceId is absent or invalid.

How to verify it:
- Build sonic-vs and SSH with `SendEnv TraceId` set to a valid value; confirm authorization requests include the TraceId attribute and that invalid/oversized values are silently dropped.
- Run the bash_tacplus unit tests under src/tacacs/bash_tacplus/unittest/.

Signed-off-by: Rod Persky <770327+Rod-Persky@users.noreply.github.com>
@Rod-Persky
Rod-Persky force-pushed the dev/rodpersky/sonic-tracability branch from 2debd38 to f26d2a4 Compare June 3, 2026 07:00
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@Rod-Persky
Rod-Persky marked this pull request as ready for review June 4, 2026 08:31
@Rod-Persky
Rod-Persky requested a review from lguohan as a code owner June 4, 2026 08:31
Copilot AI review requested due to automatic review settings June 4, 2026 08:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for propagating an SSH client-supplied TraceId into TACACS+ authorization attributes, along with unit tests and OS image configuration to pass and protect the environment variable.

Changes:

  • Add TraceId parsing/validation and include it as a TACACS+ attribute in authorization requests.
  • Add unit tests and mock tracking for the TraceId attribute behavior.
  • Configure SSHD to accept TraceId via AcceptEnv and make TraceId readonly in interactive shells.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/tacacs/bash_tacplus/unittest/plugin_test.c Adds TraceId-related unit tests for authorization message behavior
src/tacacs/bash_tacplus/unittest/mock_helper.h Declares mock state and reset helper for TraceId attribute capture
src/tacacs/bash_tacplus/unittest/mock_helper.c Implements mock capture/reset of TraceId attribute in tac_add_attrib
src/tacacs/bash_tacplus/bash_tacplus.c Implements TraceId validation/extraction and adds it to TACACS+ attributes
files/image_config/bash/bash.bashrc Makes TraceId readonly (best-effort) in interactive shells
build_debian.sh Ensures sshd_config includes AcceptEnv TraceId

Comment thread src/tacacs/bash_tacplus/unittest/mock_helper.c
Comment thread src/tacacs/bash_tacplus/unittest/plugin_test.c Outdated
Comment thread src/tacacs/bash_tacplus/bash_tacplus.c Outdated
Signed-off-by: Rod Persky <770327+Rod-Persky@users.noreply.github.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@auspham

auspham commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

/azpw retry

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

No failed(or canceled) jobs found in completed stages. Only failed(or canceled) jobs in completed stages can be retried.

Stages in progress: Test. Please wait for the stages to complete and then retry again.

@Rod-Persky

Copy link
Copy Markdown
Author

@qiluo-msft this is a change into the existing sonic-bash plugin to capture an end to end trace ID. There is also a corresponding HLD sonic-net/SONiC#2358 . Could you please assist in identifying next steps please

@mssonicbld

Copy link
Copy Markdown
Collaborator

The backport request for branch(es) 202305,202411,202505 has been removed from PR description. Removed label(s)....

---Powered by SONiC BuildBot

Copilot AI review requested due to automatic review settings July 7, 2026 08:29
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread src/tacacs/bash_tacplus/unittest/plugin_test.c
Comment thread src/tacacs/bash_tacplus/bash_tacplus.c
Signed-off-by: Rod Persky <770327+Rod-Persky@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 9, 2026 02:00
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Comment thread build_debian.sh
Comment thread files/image_config/bash/bash.bashrc
Comment thread src/tacacs/bash_tacplus/bash_tacplus.c
Comment thread src/tacacs/bash_tacplus/bash_tacplus.c Outdated
Comment thread src/tacacs/bash_tacplus/unittest/plugin_test.c
Comment thread src/tacacs/bash_tacplus/unittest/plugin_test.c
Comment thread src/sonic-yang-models/yang-models/sonic-system-tacacs.yang
Signed-off-by: Rod Persky <770327+Rod-Persky@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 07:33
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread build_debian.sh
Comment thread src/tacacs/bash_tacplus/bash_tacplus.c
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