Skip to content

hostcfgd: Validate RADIUS server fields before creating PAM files - #430

Merged
qiluo-msft merged 3 commits into
sonic-net:masterfrom
ashutosh-agrawal:validate-radius-server-entry
Sep 25, 2026
Merged

qiluo-msft merged 3 commits into
sonic-net:masterfrom
ashutosh-agrawal:validate-radius-server-entry

Conversation

@ashutosh-agrawal

Copy link
Copy Markdown
Member

What I did

Added validation for the RADIUS server address and authentication port before using the entry to generate RADIUS configuration.

hostcfgd uses these fields in the filename for each server’s PAM configuration. It previously assumed that both values were valid. A bad address or port could result in an unexpected filename or an invalid RADIUS configuration.

How I did it

  • Validate the server address with ipaddress.ip_address().
  • Require the authentication port to be between 1 and 65535.
  • Skip invalid server entries and log the address and port without logging the configured passkey.
  • Leave valid IPv4 and IPv6 server entries unchanged.

How I verified it

Added coverage for valid IPv4 and IPv6 addresses, malformed addresses, non-numeric ports, and ports outside the valid range.

python3 -m pytest tests/hostcfgd/hostcfgd_radius_test.py -q

Result: 8 passed.

Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@mssonicbld

Copy link
Copy Markdown

/azp run

@azure-pipelines

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

Comment thread scripts/hostcfgd Outdated
Comment thread scripts/hostcfgd
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
@mssonicbld

Copy link
Copy Markdown

/azp run

@azure-pipelines

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

@qiluo-msft
qiluo-msft requested a balanced review from Copilot September 23, 2026 22:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Numeric legacy IPv4 forms can bypass validation through the hostname fallback.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Adds RADIUS server address and authentication-port validation before generating PAM configuration.

Changes:

  • Validates host and port values, skipping invalid entries.
  • Normalizes valid ports and logs rejected entries.
  • Adds unit and integration coverage for valid and invalid inputs.
File Description
scripts/​hostcfgd Adds RADIUS validation and filtering.
tests/​hostcfgd/​hostcfgd_radius_test.py Tests validation and rendering.
tests/​hostcfgd/​test_radius_vectors.py Adds invalid server fixtures.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread scripts/hostcfgd
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
@mssonicbld

Copy link
Copy Markdown

/azp run

@azure-pipelines

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

@qiluo-msft
qiluo-msft merged commit 268ca64 into sonic-net:master Sep 25, 2026
6 checks passed
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.

4 participants