Skip to content

Remote server tls authentication - #1885

Open
asher-pem-arm wants to merge 2 commits into
labgrid-project:masterfrom
ARM-software:remote-server-tls-authentication
Open

Remote server tls authentication#1885
asher-pem-arm wants to merge 2 commits into
labgrid-project:masterfrom
ARM-software:remote-server-tls-authentication

Conversation

@asher-pem-arm

@asher-pem-arm asher-pem-arm commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

This MR adds support for gRPC SSL/TLS server authentication to labgrid-coordinator, labgrid-exporter and labgrid-client.

Enabling a secure channel on all three components is done by adding the --secure argument. Paths to the certificate and key (labgrid-coordinator-only) can be specified with the --cert and --key arguments.

Testing has been added to verify that, given a secure-enabled labgrid-coordinator, both labgrid-client and labgrid-exporter can connect successfully and perform an operation.

Note on use of labgrid-client and labgrid-exporter without an explicit --cert specified

On Linux, this currently reads the Debian/Ubuntu CA bundle at:
/etc/ssl/certs/ca-certificates.crt

On macOS, this reads certificates from the system Keychain using:
security find-certificate -a -p

If the coordinator certificate is not trusted by the host, or the platform's system roots cannot be loaded, pass the coordinator certificate explicitly with --cert.

Closes: #1541

@Emantor
Emantor requested review from Bastian-Krause, Emantor and jluebbe and removed request for Emantor and jluebbe June 3, 2026 18:29
@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.69697% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.1%. Comparing base (7121ff3) to head (9f39d0f).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/remote/common.py 34.2% 25 Missing ⚠️
labgrid/remote/client.py 84.2% 3 Missing ⚠️
labgrid/remote/coordinator.py 94.7% 1 Missing ⚠️
labgrid/remote/exporter.py 85.7% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##           master   #1885   +/-   ##
======================================
  Coverage    61.0%   61.1%           
======================================
  Files         182     182           
  Lines       14906   14996   +90     
======================================
+ Hits         9105    9164   +59     
- Misses       5801    5832   +31     
Flag Coverage Δ
3.10 61.0% <69.6%> (+<0.1%) ⬆️
3.11 61.0% <69.6%> (+<0.1%) ⬆️
3.12 61.0% <69.6%> (+<0.1%) ⬆️
3.13 61.0% <69.6%> (+<0.1%) ⬆️
3.14 61.0% <69.6%> (+<0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Emantor
Emantor previously approved these changes Jun 9, 2026

@Emantor Emantor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Otherwise looks good

Comment thread doc/man/client.rst Outdated

.. code-block:: bash

$ labgrid-client --secure [--cert PATH] places

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Feels very much like bikeshedding to write this, but should we rename --secure to --tls instead? This makes it clear that we are using TLS for gRPC secure channels instead of a generic --secure which does not carry much meaning.

@gastmaier gastmaier 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.

Looks good! Some minor comments

Comment thread doc/getting_started.rst Outdated
Refer to the ``labgrid-coordinator`` man page for details.

When you are connecting with ``labgrid-client`` or ``labgrid-exporter`` to a
``labgrid-coordinator``that has secure gRPC channels enabled you need to pass

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
``labgrid-coordinator``that has secure gRPC channels enabled you need to pass
``labgrid-coordinator`` that has secure gRPC channels enabled you need to pass

Comment thread doc/man/coordinator.rst Outdated
Comment on lines +28 to +33
--secure
enable TLS gRPC channel
--cert
path to TLS certificate (in PEM format)
--key
path to TLS key (in PEM format)

@gastmaier gastmaier Jun 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On the coordinator side, the tls at the reverse proxy is also an option, right?
At servers, I would rather have nginx handling the certificates.

If so, could you add an alternative, such as


Or use a reverse proxy to add TLS, for example with ``nginx``:

.. code-block:: nginx
    server {
        listen 20407 ssl http2;
        server_name labgrid.example.com;
        ssl_certificate     /etc/ssl/labgrid-coordinator.crt;
        ssl_certificate_key /etc/ssl/labgrid-coordinator.key;
        location / {
            grpc_pass grpc://127.0.0.1:20408;
        }
    }

https://blog.nginx.org/blog/nginx-1-13-10-grpc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

included

Comment thread labgrid/remote/common.py
Comment thread doc/getting_started.rst
the ``--secure`` (and ``--cert`` if the certificate is not trusted by the host
machine) option.
Refer to the ``labgrid-client`` and ``labgrid-exporter`` man pages for details.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

explain roots.pem and GRPC_DEFAULT_SSL_ROOTS_FILE_PATH precedence here, please

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated

@asher-pem-arm

Copy link
Copy Markdown
Contributor Author

@Emantor I have added 3 commits for the comments in the PR, if you've happy with these I'll squash all 3 into the first commit to keep the PR tidy

@gastmaier gastmaier 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.

Sounds good!

Users have the option to pass explicitly or read gprc doc for the env alternative GRPC_DEFAULT_SSL_ROOTS_FILE_PATH.

Comment thread labgrid/remote/common.py
@Emantor

Emantor commented Jun 10, 2026

Copy link
Copy Markdown
Member

@Emantor I have added 3 commits for the comments in the PR, if you've happy with these I'll squash all 3 into the first commit to keep the PR tidy

Looks good, please squash.

Comment thread doc/man/coordinator.rst

Instead of enabling TLS in ``labgrid-coordinator`` directly, a reverse proxy can
terminate TLS and forward cleartext gRPC to the coordinator. For example, with
``nginx``:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In which cases would a reverse proxy preferred over having the coordinator do TLS itself?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that depends on the deployment environment. I would expect the default option to be the direct coordinator TLS but some orgs might standardise TLS at the ingress layer, even then they might want to use the TLS enabled coordinator on top of that

Comment thread doc/getting_started.rst Outdated
Comment on lines +449 to +451
the ``--tls`` option. If ``--cert`` is not set, labgrid uses the host CA
certificates to verify the coordinator certificate. Use ``--cert`` to provide
a specific CA certificate instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For the client side, the usual approach is to use --cacert (like curl) to set the trusted CA certificates to check against. This leaves --cert free to allow future extension to client certificates.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated

Comment thread labgrid/resource/remote.py
@asher-pem-arm
asher-pem-arm force-pushed the remote-server-tls-authentication branch 2 times, most recently from d814bd4 to c925307 Compare July 8, 2026 14:41
@asher-pem-arm
asher-pem-arm requested a review from Emantor July 16, 2026 13:10
@asher-pem-arm

Copy link
Copy Markdown
Contributor Author

updated with a new commit for supporting external clients with the client stream, will squash the latest 2 when you're both happy with the content

@Emantor Emantor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMO this looks good, two things:

  1. The first commit should have a proper commit message instead of the commit message for the work done in the second commit.
  2. The second commit should have the commit message of the first.

Also please squash, the kw_only=True commit for compatibility makes sense to me.

@Emantor
Emantor requested a review from jluebbe July 17, 2026 08:07
@asher-pem-arm
asher-pem-arm force-pushed the remote-server-tls-authentication branch from b47b9f4 to 2d97b99 Compare July 17, 2026 08:22
@asher-pem-arm
asher-pem-arm requested a review from Emantor July 17, 2026 08:22
Comment thread labgrid/remote/common.py Outdated
Comment thread labgrid/resource/remote.py Outdated
Comment thread labgrid/remote/client.py

@jluebbe jluebbe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With the changes requested by @Emantor and @Bastian-Krause fid, I'd be fine with this.

asher-pem-arm and others added 2 commits August 13, 2026 16:43
Allow the coordinator to serve gRPC over TLS, and allow clients,
exporters, and RemotePlace connections to authenticate the coordinator.
Add command-line and configuration options along with documentation and
tests for secure channels.

Signed-off-by: Asher Pemberton <asher.pemberton@arm.com>
Reviewed-by: Asher Pemberton <asher.pemberton@arm.com> # gatekeeper
Co-authored-by: Luke Beardsmore <luke.beardsmore2@arm.com>
The Linux root certificate handling is intentionally done in labgrid
instead of relying on grpcio's Python default.

In gRPC's ComputePemRootCerts() precedence, GRPC_DEFAULT_SSL_ROOTS_FILE_PATH
is considered first. The Python grpcio package then installs an
ssl_roots_override_cb from grpc/_cython/cygrpc.pyx which loads the bundled
grpc/_cython/_credentials/roots.pem. Because that callback succeeds before
the later LoadSystemRootCerts() path is used, a normal pip-installed
grpcio package can ignore CA certificates installed in the host trust
store.

Therefore labgrid's TLS certificate precedence is:

  1. explicit certificate argument
  2. system trust store loaded by labgrid
  3. grpcio default roots, including bundled roots.pem, as fallback

Signed-off-by: Asher Pemberton <asher.pemberton@arm.com>
Reviewed-by: Asher Pemberton <asher.pemberton@arm.com> # gatekeeper
Co-authored-by: Luke Beardsmore <luke.beardsmore2@arm.com>
@asher-pem-arm
asher-pem-arm force-pushed the remote-server-tls-authentication branch from 2d97b99 to 9f39d0f Compare August 14, 2026 08:07
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.

5 participants