Skip to content

[CLI] Require explicit CA for remote C++ REST connections - #167

Merged
qiluo-msft merged 4 commits into
sonic-net:masterfrom
ashutosh-agrawal:fix/cpp-rest-server-verification
Sep 9, 2026
Merged

[CLI] Require explicit CA for remote C++ REST connections#167
qiluo-msft merged 4 commits into
sonic-net:masterfrom
ashutosh-agrawal:fix/cpp-rest-server-verification

Conversation

@ashutosh-agrawal

@ashutosh-agrawal ashutosh-agrawal commented Sep 7, 2026

Copy link
Copy Markdown
Member

Why

The C++ klish REST client may connect to either the default local REST server or a configured remote HTTPS endpoint. Remote connections should use a CA certificate selected specifically for that REST server while preserving the existing local workflow.

What

  • Require REST_API_CA_CERT to identify a readable CA certificate file for every non-loopback HTTPS REST endpoint.
  • Configure libcurl to verify the peer certificate and hostname using the selected CA file without falling back to its compiled-in CA directory.
  • Preserve the current behavior for localhost, IPv4 loopback addresses (127.0.0.0/8), and IPv6 loopback (::1).
  • Report a clear initialization error when the required CA configuration is missing or invalid.
  • Add focused coverage for accepted and rejected endpoint classification and CA path validation.

This is the C++ client counterpart to #166. Operator-facing CLI configuration can be added separately.

How to verify

Run tools/test/rest-tls.sh to verify:

  • localhost, IPv4 127.0.0.0/8, IPv6 ::1, and IPv4-mapped 127.0.0.0/8 endpoints are recognized as loopback.
  • Remote, misleading, and malformed endpoint names are not recognized as loopback.
  • Readable CA files are accepted, while missing paths, empty paths, and directories are rejected.

All tests 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).

@ashutosh-agrawal ashutosh-agrawal changed the title CLI: verify remote REST server certificates [CLI] Require explicit CA for remote C++ REST connections Sep 7, 2026

@qiluo-msft qiluo-msft 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.

(superseded by inline comments above)

Comment thread CLI/klish/patches/klish-2.1.4/plugins/clish/rest_tls.h Outdated
Comment thread CLI/klish/patches/klish-2.1.4/plugins/clish/rest_tls.h
Comment thread CLI/klish/patches/klish-2.1.4/plugins/clish/rest_cl.cpp
Comment thread CLI/klish/patches/klish-2.1.4/plugins/clish/rest_cl.cpp Outdated
Comment thread tools/test/rest-tls.sh Outdated
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).

@mssonicbld

Copy link
Copy Markdown

/azp run

@azure-pipelines

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

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 29b5acc into sonic-net:master Sep 9, 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.

3 participants