Skip to content

Remote server tls authentication#1885

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

Remote server tls authentication#1885
asher-pem-arm wants to merge 5 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

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.

asher-pem-arm and others added 2 commits June 3, 2026 17:45
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>
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>
@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 52.68817% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.8%. Comparing base (915b591) to head (c6d1da1).
⚠️ Report is 10 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/remote/common.py 35.8% 25 Missing ⚠️
labgrid/remote/coordinator.py 57.8% 8 Missing ⚠️
labgrid/remote/exporter.py 0.0% 7 Missing ⚠️
labgrid/remote/client.py 50.0% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1885     +/-   ##
========================================
+ Coverage    46.0%   46.8%   +0.8%     
========================================
  Files         180     180             
  Lines       14464   14555     +91     
========================================
+ Hits         6654    6819    +165     
+ Misses       7810    7736     -74     
Flag Coverage Δ
3.10 46.8% <52.6%> (+0.8%) ⬆️
3.11 46.8% <52.6%> (+0.8%) ⬆️
3.12 ?
3.13 46.8% <52.6%> (+0.8%) ⬆️
3.14 46.8% <52.6%> (+0.8%) ⬆️

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
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
return None


def _fetch_root_certificates_linux():

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 why this is needed.

the certificate precedence is (src/core/credentials/transport/tls/ssl_utils.cc @ ComputePemRootCerts)

GRPC_DEFAULT_SSL_ROOTS_FILE_PATH
UseSystemRootsOverLanguageCallback()
ssl_roots_override_cb <= never reached
LoadSystemRootCerts()
installed_roots_path fallback

the cb is set at src/python/grpcio/grpc/_cython/cygrpc.pyx
added at github.com/grpc/grpc/commit/fa6cad701c7993aa6e5746824931efbfca84ca24

The only options are indeed GRPC_DEFAULT_SSL_ROOTS_FILE_PATH or as the argument value.

the grpc defaults for linux are (https://github.com/grpc/grpc/blob/master/src/core/credentials/transport/tls/load_system_roots_supported.cc#L48-L62)

    "/etc/ssl/certs/ca-certificates.crt", "/etc/pki/tls/certs/ca-bundle.crt",
    "/etc/ssl/ca-bundle.pem", "/etc/pki/tls/cacert.pem",
    "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"

I wouldn't have one of the default here, but just document that it will default to the bundled roots.pem if not explicitly set through the env or as the argument value.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi @gastmaier I think the important Python bit here is that grpcio installs a roots override callback which loads its bundled roots.pem, so on Python the normal default is not the Linux system trust store. That means if we do not pass root_certificates, --tls may ignore CAs installed on the host.

So I think the correct ordering for Labgrid should be:

  • explicit --cert
  • system trust store loaded by Labgrid
  • gRPC/Python default only as fallback if we cannot load system roots

I'll update the getting_started docs to represent this

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

--tls may ignore CAs installed on the host.
Due to how the gprc source code is structured, it will ignore CAs installed on the host (never read) if roots.pem is present.
and roots.pem is always present with the pip package install:

find . -name 'roots.pem'
./lib/python3.14/site-packages/grpc/_cython/_credentials/roots.pem

Hacking rm ./lib/python3.14/site-packages/grpc/_cython/_credentials/roots.pem as a post-install step for grpcio is not an option.

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
Author

Choose a reason for hiding this comment

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

updated

Signed-off-by: Asher Pemberton <asher.pemberton@arm.com>
Reviewed-by: Asher Pemberton <asher.pemberton@arm.com> # gatekeeper
Signed-off-by: Asher Pemberton <asher.pemberton@arm.com>
Reviewed-by: Asher Pemberton <asher.pemberton@arm.com> # gatekeeper
Signed-off-by: Asher Pemberton <asher.pemberton@arm.com>
Reviewed-by: Asher Pemberton <asher.pemberton@arm.com> # gatekeeper
@asher-pem-arm

Copy link
Copy Markdown
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
return None


def _fetch_root_certificates_linux():

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

--tls may ignore CAs installed on the host.
Due to how the gprc source code is structured, it will ignore CAs installed on the host (never read) if roots.pem is present.
and roots.pem is always present with the pip package install:

find . -name 'roots.pem'
./lib/python3.14/site-packages/grpc/_cython/_credentials/roots.pem

Hacking rm ./lib/python3.14/site-packages/grpc/_cython/_credentials/roots.pem as a post-install step for grpcio is not an option.

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

@Emantor Emantor requested a review from jluebbe June 10, 2026 12:25
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