Repository navigation
redis: authenticate local REST connections through swss-common - #194
Draft
ashutosh-agrawal wants to merge 7 commits into
Draft
ashutosh-agrawal wants to merge 7 commits into
ashutosh-agrawal wants to merge 7 commits into
Conversation
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This was referenced Nov 3, 2026
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
qiluo-msft
added a commit
to sonic-net/sonic-swss-common
that referenced
this pull request
Nov 24, 2026
### Description of PR Summary: Expose redisconn.DialUnixContext for cancellable native Unix connections in Go clients. Uses [the core authentication implementation and native command callback from merged #1270](#1270). The public Unix factory introduced in [merged #1274](#1274) delegates to the same interruptible implementation. Fixes # (issue): N/A ### Type of change - [x] Bug fix - [x] New feature - [ ] Refactor / cleanup - [ ] Documentation update - [x] Test improvement ### Approach #### What is the motivation for this PR? Go Redis clients such as [RCM/CVL](sonic-net/sonic-mgmt-common#263), [gNMI](sonic-net/sonic-gnmi#846) and [REST](sonic-net/sonic-restapi#194) retain their Redis APIs and pooling while using the shared native authentication implementation. The Go adapter belongs with the native API so it can be shared by Go clients without adding a management-common dependency. It handles Go cancellation and conversion of the native socket into `net.Conn`; policy checks, credential access and authentication stay in C++. #### How did you do it? Add the following public Go entry point: ```go DialUnixContext(ctx context.Context, path string, timeout time.Duration, authenticate bool) (net.Conn, error) ``` A narrow C bridge calls an interruptible native Unix factory. One timeout covers connect and AUTH; context cancellation interrupts stalled work. Transfer descriptor ownership to net.Conn and join the cancellation watcher before returning. Transport failures retain Go network error identity, while policy and credential failures remain non-retryable. The interruptible helper declaration stays internal to the native implementation. The existing `openRedisUnixSocket` entry point delegates with cancellation disabled, removing the duplicate connection/AUTH implementation and fixing successful AUTH returns after the absolute timeout has expired. Callers install this hook for their Unix branch and retain existing TCP/TLS dialing. Native policy and credential parsing stay in C++. This API does not provide a generic TCP dialer or verified TLS support. The isolated CI fixture runs the package with `go test -count=1`. The development package installs the canonical Go adapter at `/usr/share/swss/go/redisconn/dial.go` alongside the native headers. [Management-common #263](sonic-net/sonic-mgmt-common#263) prepares this source before Go vendoring and delivers it to gNMI/framework through its existing codegen package. These consumers use the adapter from their selected SDK and do not need a separate swss-common Go-module revision or source checkout. #### How did you verify/test it? Local checks exercised the installed SDK adapter with the race detector and verified AUTH EOF, native timeout, policy and credential error classification. A go-redis client retried an injected missing-socket failure; the previous adapter returned it without retrying. An unmatched-policy injection made the cancellation test fail promptly without hanging cleanup. The SDK install check retained the public C header and Go adapter while excluding the internal helper header. The Python pool checks cover missing-socket error conversion and blocking/CLOEXEC descriptors through the shared factory. A fragmented AUTH-reply regression fails against the previous factory by returning late success, then passes with delegation. Test-only delayed reads also cover policy processing, credential processing and an unmatched socket policy against the same deadline, with an unlimited-timeout control. The Go test discovers its executable through PATH and skips when unavailable; both discovery paths were checked. #### Any platform specific information? Linux with cgo and the matching native library. ### Documentation The API comments, help output where applicable, and focused tests show the supported call pattern. --------- Signed-off-by: Ashutosh Agrawal <ashu@cisco.com> Co-authored-by: Qi Luo <qiluo-msft@users.noreply.github.com>
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
|
/azp run |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
RESTAPI's Go clients and SWSS producer connections need an explicit writer login when using local Redis sockets. Policy and credential handling stay in swss-common C++.
Changes and dependencies
Install
redisconn.DialUnixContext(..., true)for local Unix Go connections without TLS. Preserve existing TCP, TLS and custom TCP dialers. Move local SWSS producers from numeric socket constructors to named connections through swss-common's C API, returning native failures to Go before startup exits. The local-test TCP path remains unchanged.Copy the SDK-supplied Go adapter from
/usr/share/swss/go/redisconn/dial.gointo REST's existing localswsscommonmodule before building. The development/runtime packages supply the native API and canonical adapter; no swss-common Go-module pin, sibling source checkout or management-common dependency is needed. Refresh the prepared adapter by content so SDK changes are picked up even with older timestamps. This requires swss-common #1272, #1275, and the package/cache wiring in buildimage #30349.Testing
With the assembled native library, disposable Redis tests passed writer transactions, pooling/reconnect, missing-credential rejection, custom TCP and TLS behavior, and an ordinary process that reads but cannot write. An isolated SDK-only build also exercised the normal Make targets without a swss-common source checkout. The five focused Redis client tests passed with the race detector, including ordinary-reader permissions and configured TLS. Adapter refresh with an older SDK timestamp passed, and removing the SDK input rejected a stale workspace. Complete production package, REST API workloads and installed-image validation remain pending.