Skip to content

Add trusted platform module (TPM) support to TLS package #12801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025

Conversation

pavolloffay
Copy link
Member

@pavolloffay pavolloffay commented Apr 4, 2025

Description

Add trusted platform module (TPM) support to TLS package.

Link to tracking issue

Resolves open-telemetry/opentelemetry-collector-contrib#38682
Replaces open-telemetry/opentelemetry-collector-contrib#39059

TPM cannot be implemented as extension open-telemetry/opentelemetry-collector-contrib#38682 because it overrides the entire http.transport and therefore invalidates other extensions/authenticators.

Testing

# make otelcorecol 
# sudo ./bin/otelcorecol_linux_amd64 --config ./examples/local/tpm.yaml
#
# CA
#  openssl genrsa -des3 -out ca.key 2048
# openssl req -new -x509 -days 1826 -key ca.key -out ca.crt -subj "/C=US/ST=CA/L=Santa Clara/O=Edge/OU=Edge/CN=localhost" -addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
#
# client
# sudo tpm2tss-genkey -a rsa -s 2048 edge-cert.key
# sudo openssl req -new -provider tpm2  -key edge-cert.key -out edge-cert.csr -subj "/C=US/ST=CA/L=Santa Clara/O=Edge/OU=Edge/CN=localhost" -addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
# openssl x509 -req -in edge-cert.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out edge-cert.crt -days 1826 -copy_extensions copyall
#
# server
# openssl genrsa -out server.key 2048
# openssl req -new -key server.key -out server.csr  -subj "/C=US/ST=CA/L=Santa Clara/O=Edge/OU=Edge/CN=localhost" -addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
# openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 360 -copy_extensions copyall
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: localhost:4317
      http:
        endpoint: localhost:4318
  otlp/server:
    protocols:
      grpc:
        endpoint: localhost:4319
        tls:
          client_ca_file: ca.crt
          cert_file: server.crt
          key_file: server.key
exporters:
  otlp:
    endpoint: https://localhost:4319
    tls:
      key_file: edge-cert.key
      cert_file: edge-cert.crt
      ca_file: ca.crt
      tpm:
        enabled: true
        path: /dev/tpmrm0
  debug:
    verbosity: normal
service:
  telemetry:
    metrics:
      address: localhost:8889
  pipelines:
    metrics/client:
      receivers: [otlp]
      exporters: [otlp]
    metrics/server:
      receivers: [otlp/server]
      exporters: [debug]

Documentation

@pavolloffay pavolloffay requested a review from a team as a code owner April 4, 2025 10:00
@pavolloffay pavolloffay requested a review from songy23 April 4, 2025 10:00
Copy link

codecov bot commented Apr 4, 2025

Codecov Report

Attention: Patch coverage is 93.75000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 91.69%. Comparing base (9dc5682) to head (ff33b51).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
config/configtls/tpm.go 88.00% 2 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (93.75%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #12801   +/-   ##
=======================================
  Coverage   91.69%   91.69%           
=======================================
  Files         501      503    +2     
  Lines       27506    27550   +44     
=======================================
+ Hits        25221    25262   +41     
- Misses       1806     1808    +2     
- Partials      479      480    +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jmacd
Copy link
Contributor

jmacd commented Apr 7, 2025

I was interested in the statement

TPM cannot be implemented as extension open-telemetry/opentelemetry-collector-contrib#38682 because it overrides the entire http.transport and therefore invalidates other extensions/authenticators.

It looks like the code just needs to modify the certificate used with TLS. In theory, we could define some kind of TLS-extension API, if we wanted the TPM dependency to be an optional one. 🤷 I'm not sure what process this repo uses to manage SBOM.

@pavolloffay pavolloffay force-pushed the tls-tpm branch 3 times, most recently from 70746d5 to 9917ad1 Compare April 8, 2025 14:13
@pavolloffay
Copy link
Member Author

@codeboten thanks for the review. I have fixed the build but I am not able to get 95% code coverage without making the code a bit odd. Could you please re-review?

@pavolloffay
Copy link
Member Author

There are conflicts in go.mod I have already resolved them once. I will wait for reviews and resolve the conflicts then.

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Thanks @pavolloffay, approving, please resolve the conflicts and we can get this merged

@pavolloffay
Copy link
Member Author

PR is rebased

@codeboten codeboten added this pull request to the merge queue Apr 30, 2025
Merged via the queue into open-telemetry:main with commit 045488f Apr 30, 2025
55 of 56 checks passed
@sincejune
Copy link
Contributor

@pavolloffay Changed in this PR are currently failing unit tests on the ARM platform in the main branch. Do you have a plan to address and fix this issue? https://github.com/open-telemetry/opentelemetry-collector/actions/runs/14757290557/job/41428733892

@jackgopack4
Copy link
Contributor

It seems like this PR introduced a CGO dependency from go-tpm-tools

john.peterson@COMP-HHVKJYJXCY configtls % go test -v ./...
# github.com/google/go-tpm-tools/simulator/internal
In file included from ../../../../go/pkg/mod/github.com/google/[email protected]/simulator/internal/internal_cgo.go:45:
In file included from ../../../../go/pkg/mod/github.com/google/[email protected]/simulator/ms-tpm-20-ref/TPMCmd/tpm/include/Tpm.h:47:
In file included from ../../../../go/pkg/mod/github.com/google/[email protected]/simulator/ms-tpm-20-ref/TPMCmd/tpm/include/LibSupport.h:65:
../../../../go/pkg/mod/github.com/google/[email protected]/simulator/ms-tpm-20-ref/TPMCmd/tpm/include/Ossl/TpmToOsslSym.h:47:10: fatal error: 'openssl/aes.h' file not found
   47 | #include <openssl/aes.h>
      |          ^~~~~~~~~~~~~~~
1 error generated.
FAIL    go.opentelemetry.io/collector/config/configtls [build failed]
FAIL

Is this intended? I thought we weren't using CGO in collector-core

@codeboten
Copy link
Contributor

Adding the CGO requirement was definitely not an intention on my part (having reviewed the PR), @pavolloffay, is cgo a requirement for this?

@pavolloffay
Copy link
Member Author

It should not be. I have tested this PR with

make otelcorecol                                                                                                                                                                                                                                                 ploffay@fedora
pushd cmd/otelcorecol && CGO_ENABLED=0 go build -trimpath -o ../../bin/otelcorecol_linux_amd64 \
	-tags  ./cmd/otelcorecol && popd
~/projects/open-telemetry/opentelemetry-collector/cmd/otelcorecol ~/projects/open-telemetry/opentelemetry-collector
~/projects/open-telemetry/opentelemetry-collector

and it worked well

TimoBehrendt pushed a commit to TimoBehrendt/tracebasedlogsampler that referenced this pull request May 20, 2025
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [go.opentelemetry.io/collector/component](https://github.com/open-telemetry/opentelemetry-collector) | require | minor | `v1.31.0` -> `v1.32.0` |
| [go.opentelemetry.io/collector/component/componenttest](https://github.com/open-telemetry/opentelemetry-collector) | require | minor | `v0.125.0` -> `v0.126.0` |
| [go.opentelemetry.io/collector/confmap](https://github.com/open-telemetry/opentelemetry-collector) | require | minor | `v1.31.0` -> `v1.32.0` |
| [go.opentelemetry.io/collector/consumer](https://github.com/open-telemetry/opentelemetry-collector) | require | minor | `v1.31.0` -> `v1.32.0` |
| [go.opentelemetry.io/collector/consumer/consumertest](https://github.com/open-telemetry/opentelemetry-collector) | require | minor | `v0.125.0` -> `v0.126.0` |
| [go.opentelemetry.io/collector/pdata](https://github.com/open-telemetry/opentelemetry-collector) | require | minor | `v1.31.0` -> `v1.32.0` |
| [go.opentelemetry.io/collector/processor](https://github.com/open-telemetry/opentelemetry-collector) | require | minor | `v1.31.0` -> `v1.32.0` |
| [go.opentelemetry.io/collector/processor/processortest](https://github.com/open-telemetry/opentelemetry-collector) | require | minor | `v0.125.0` -> `v0.126.0` |

---

### Release Notes

<details>
<summary>open-telemetry/opentelemetry-collector (go.opentelemetry.io/collector/component)</summary>

### [`v1.32.0`](https://github.com/open-telemetry/opentelemetry-collector/blob/HEAD/CHANGELOG.md#v1320v01260)

##### 🛑 Breaking changes 🛑

-   `configauth`: Removes deprecated `configauth.Authentication` and `extensionauthtest.NewErrorClient` ([#&#8203;12992](open-telemetry/opentelemetry-collector#12992))
    The following have been removed:
    -   `configauth.Authentication` use `configauth.Config` instead
    -   `extensionauthtest.NewErrorClient` use `extensionauthtest.NewErr` instead

##### 💡 Enhancements 💡

-   `service`: Replace `go.opentelemetry.io/collector/semconv` usage with `go.opentelemetry.io/otel/semconv` ([#&#8203;12991](open-telemetry/opentelemetry-collector#12991))
-   `confmap`: Update the behavior of the confmap.enableMergeAppendOption feature gate to merge only component lists. ([#&#8203;12926](open-telemetry/opentelemetry-collector#12926))
-   `service`: Add item count metrics defined in Pipeline Component Telemetry RFC ([#&#8203;12812](open-telemetry/opentelemetry-collector#12812))
    See [Pipeline Component Telemetry RFC](https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/rfcs/component-universal-telemetry.md) for more details:
    -   `otelcol.receiver.produced.items`
    -   `otelcol.processor.consumed.items`
    -   `otelcol.processor.produced.items`
    -   `otelcol.connector.consumed.items`
    -   `otelcol.connector.produced.items`
    -   `otelcol.exporter.consumed.items`
-   `tls`: Add trusted platform module (TPM) support to TLS authentication. ([#&#8203;12801](open-telemetry/opentelemetry-collector#12801))
    Now the TLS allows the use of TPM for loading private keys (e.g. in TSS2 format).

##### 🧰 Bug fixes 🧰

-   `exporterhelper`: Add validation error for batch config if min_size is greater than queue_size. ([#&#8203;12948](open-telemetry/opentelemetry-collector#12948))

-   `telemetry`: Allocate less memory per component when OTLP exporting of logs is disabled ([#&#8203;13014](open-telemetry/opentelemetry-collector#13014))

-   `confmap`: Use reflect.DeepEqual to avoid panic when confmap.enableMergeAppendOption feature gate is enabled. ([#&#8203;12932](open-telemetry/opentelemetry-collector#12932))

-   `internal telemetry`: Add resource attributes from telemetry.resource to the logger ([#&#8203;12582](open-telemetry/opentelemetry-collector#12582))
    Resource attributes from telemetry.resource were not added to the internal
    console logs.

    Now, they are added to the logger as part of the "resource" field.

-   `confighttp and configcompression`: Fix handling of `snappy` content-encoding in a backwards-compatible way ([#&#8203;10584](open-telemetry/opentelemetry-collector#10584), [#&#8203;12825](open-telemetry/opentelemetry-collector#12825))
    The collector used the Snappy compression type of "framed" to handle the HTTP
    content-encoding "snappy".  However, this encoding is typically used to indicate
    the "block" compression variant of "snappy".  This change allows the collector to:
    -   When receiving a request with encoding 'snappy', the server endpoints will peek
        at the first bytes of the payload to determine if it is "framed" or "block" snappy,
        and will decompress accordingly.  This is a backwards-compatible change.
    If the feature-gate "confighttp.framedSnappy" is enabled, you'll see new behavior for both client and server:
    -   Client compression type "snappy" will now compress to the "block" variant of snappy
        instead of "framed". Client compression type "x-snappy-framed" will now compress to the "framed" variant of snappy.
    -   Servers will accept both "snappy" and "x-snappy-framed" as valid content-encodings.

-   `tlsconfig`: Disable TPM tests on MacOS/Darwin ([#&#8203;12964](open-telemetry/opentelemetry-collector#12964))

<!-- previous-version -->

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yNjMuMSIsInVwZGF0ZWRJblZlciI6IjM5LjI2My4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Reviewed-on: https://gitea.t000-n.de/t.behrendt/tracebasedlogsampler/pulls/13
Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[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.

New component: tpmextesion - trusted platform module
5 participants