Skip to content

Skip authentication for UDS connections#617

Merged
hdwhdw merged 2 commits intosonic-net:masterfrom
hdwhdw:allow-gnoi-uds-auth-bypass
Mar 12, 2026
Merged

Skip authentication for UDS connections#617
hdwhdw merged 2 commits intosonic-net:masterfrom
hdwhdw:allow-gnoi-uds-auth-bypass

Conversation

@hdwhdw
Copy link
Contributor

@hdwhdw hdwhdw commented Mar 10, 2026

What I did

When --client_auth cert is configured, connections over Unix Domain Socket (UDS) fail authentication because ClientCertAuthenAndAuthor() requires TLS peer credentials that don't exist on Unix sockets.

This PR skips certificate authentication for all RPCs (gNMI and gNOI) when the connection arrives over a UDS. UDS access is already secured at the filesystem level via socket permissions (srw-rw---- root:root), making TLS auth redundant.

How I did it

Added a check at the top of authenticate() in server.go that detects UDS connections via peer.Addr.(*net.UnixAddr) and returns early, bypassing auth.

How to verify it

Unit tests:

=== RUN   TestAuthenticate
--- PASS: TestAuthenticate (0.00s)
=== RUN   TestAuthenticateUDS
--- PASS: TestAuthenticateUDS (0.00s)

On-device (vlab-01):

$ sudo grpcurl -plaintext unix:///var/run/gnmi/gnmi.sock gnoi.system.System/Time
{
  "time": "1773163799143468772"
}

Without sudo: permission denied at filesystem level (correct behavior — socket is 0660 root:root).

When the server is configured with cert-only auth, UDS connections
fail because ClientCertAuthenAndAuthor requires TLS peer credentials
that don't exist on Unix sockets. Add a check at the top of
authenticate() to bypass auth for gNOI requests on UDS connections,
since UDS security is enforced at the file-system level via socket
permissions (0750/0660).

The bypass is scoped to gNOI only -- gNMI RPCs on UDS continue to
follow existing auth rules.

Signed-off-by: Dawei Huang <[email protected]>
Copilot AI review requested due to automatic review settings March 10, 2026 17:24
@mssonicbld
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an authentication bypass in the authenticate() function of the gNMI server, allowing gNOI RPCs made over Unix Domain Socket (UDS) connections to succeed even when the server is configured with certificate-only auth. The rationale is that UDS connections are already secured at the filesystem level via socket permissions (0750/0660), so requiring TLS peer credentials is redundant and would make UDS connections non-functional for gNOI services.

Changes:

  • gnmi_server/server.go: Inserts a short-circuit at the top of authenticate() that returns immediately (with AuthEnabled = false) when target == "gnoi" and the connection is over a Unix socket.
  • gnmi_server/server_test.go: Adds a CreateUDSCtx() helper and a TestAuthenticateGnoiUDS test covering gNOI read/write success over UDS and gNMI failure over UDS with cert-only auth.

Reviewed changes

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

File Description
gnmi_server/server.go Adds UDS auth bypass for target == "gnoi" in authenticate()
gnmi_server/server_test.go Adds CreateUDSCtx helper and TestAuthenticateGnoiUDS unit test

Remove the gnoi-only restriction so that both gNMI and gNOI RPCs
skip certificate auth when the caller connects via Unix domain socket.
UDS access is already gated by filesystem permissions on the socket.

Signed-off-by: Dawei Huang <[email protected]>
@mssonicbld
Copy link
Contributor

/azp run

@hdwhdw hdwhdw changed the title Allow gNOI access for UDS connections without certificate auth Skip authentication for UDS connections Mar 11, 2026
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@hdwhdw hdwhdw merged commit 4946885 into sonic-net:master Mar 12, 2026
9 checks passed
@hdwhdw hdwhdw deleted the allow-gnoi-uds-auth-bypass branch March 12, 2026 21:59
hdwhdw added a commit to hdwhdw/sonic-buildimage that referenced this pull request Mar 12, 2026
Includes sonic-net/sonic-gnmi#617: skip certificate authentication
for connections over Unix domain sockets.

Signed-off-by: Dawei Huang <[email protected]>
yxieca pushed a commit to sonic-net/sonic-buildimage that referenced this pull request Mar 13, 2026
What is the motivation for this PR
When --client_auth cert is configured on the gNMI server, UDS connections fail auth because TLS peer creds are unavailable, blocking local services (e.g., device-ops-agent) from using gNMI/gNOI over UDS.

How did you do it
Updated sonic-gnmi submodule to include sonic-net/sonic-gnmi#617, adding a UDS detection check in authenticate() to skip cert auth for UDS (secured by socket permissions).

How did you verify/test it
On a device with --client_auth cert configured:
$ sudo grpcurl -plaintext unix:///var/run/gnmi/gnmi.sock gnoi.system.System/Time
{time: 1773163799143468772}

Without sudo: permission denied at filesystem level.

Unique Signed-off-by
Signed-off-by: Dawei Huang <[email protected]>
eddieruan-alibaba pushed a commit to eddieruan-alibaba/sonic-buildimage that referenced this pull request Mar 19, 2026
What is the motivation for this PR
When --client_auth cert is configured on the gNMI server, UDS connections fail auth because TLS peer creds are unavailable, blocking local services (e.g., device-ops-agent) from using gNMI/gNOI over UDS.

How did you do it
Updated sonic-gnmi submodule to include sonic-net/sonic-gnmi#617, adding a UDS detection check in authenticate() to skip cert auth for UDS (secured by socket permissions).

How did you verify/test it
On a device with --client_auth cert configured:
$ sudo grpcurl -plaintext unix:///var/run/gnmi/gnmi.sock gnoi.system.System/Time
{time: 1773163799143468772}

Without sudo: permission denied at filesystem level.

Unique Signed-off-by
Signed-off-by: Dawei Huang <[email protected]>
Signed-off-by: Eddie Ruan <[email protected]>
eddieruan-alibaba added a commit to sonic-net/sonic-buildimage that referenced this pull request Mar 23, 2026
* Add db alias

Signed-off-by: Eddie Ruan <[email protected]>

* Fix a typo

Signed-off-by: Eddie Ruan <[email protected]>

* Remove redis-sysmondb alias

Signed-off-by: Eddie Ruan <[email protected]>

* Take care review comments from Aseem and Selva

Signed-off-by: Eddie Ruan <[email protected]>

* Update sonic-gnmi submodule to include UDS auth bypass (#26155)

What is the motivation for this PR
When --client_auth cert is configured on the gNMI server, UDS connections fail auth because TLS peer creds are unavailable, blocking local services (e.g., device-ops-agent) from using gNMI/gNOI over UDS.

How did you do it
Updated sonic-gnmi submodule to include sonic-net/sonic-gnmi#617, adding a UDS detection check in authenticate() to skip cert auth for UDS (secured by socket permissions).

How did you verify/test it
On a device with --client_auth cert configured:
$ sudo grpcurl -plaintext unix:///var/run/gnmi/gnmi.sock gnoi.system.System/Time
{time: 1773163799143468772}

Without sudo: permission denied at filesystem level.

Unique Signed-off-by
Signed-off-by: Dawei Huang <[email protected]>
Signed-off-by: Eddie Ruan <[email protected]>

* Remove exit based on Aseem's comments

Signed-off-by: Eddie Ruan <[email protected]>

* Add DCO sign-off for previous commit

Signed-off-by: Eddie Ruan <[email protected]>

* Reorg codes based on Ashwin's comments

Signed-off-by: Eddie Ruan <[email protected]>

* Update pythonscript name

Signed-off-by: Eddie Ruan <[email protected]>

---------

Signed-off-by: Eddie Ruan <[email protected]>
Signed-off-by: Dawei Huang <[email protected]>
Co-authored-by: Dawei Huang <[email protected]>
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