Skip to content

Commit 9917ad1

Browse files
committed
Add trusted platform module support to TLS
Signed-off-by: Pavol Loffay <[email protected]>
1 parent c43ecad commit 9917ad1

File tree

34 files changed

+617
-6
lines changed

34 files changed

+617
-6
lines changed

.chloggen/tls-tpm.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: tls
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add trusted platform module (TPM) support to TLS authentication.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12801]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
Now the TLS allows the use of TPM for for loading private keys (e.g. TSS2 format).
20+
21+
# Optional: The change log or logs in which this entry should be included.
22+
# e.g. '[user]' or '[user, api]'
23+
# Include 'user' if the change is relevant to end users.
24+
# Include 'api' if there is a change to a library API.
25+
# Default: '[user]'
26+
change_logs: [user]

.github/workflows/build-and-test-windows.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ jobs:
2424
steps:
2525
- name: Checkout Repo
2626
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
27+
- name: Dir OpenSSL
28+
run: dir 'C:/Program Files/OpenSSL'
29+
- name: Dir OpenSSL/lib
30+
run: dir 'C:/Program Files/OpenSSL/lib'
31+
- name: Dir OpenSSL/include
32+
run: dir 'C:/Program Files/OpenSSL/include/openssl'
2733
- name: Setup Go
2834
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
2935
with:

.github/workflows/utils/cspell.json

+1
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@
430430
"testprovider",
431431
"testutil",
432432
"tocstop",
433+
"tpmrm",
433434
"tracecontext",
434435
"traceid",
435436
"tracesonmemory",

cmd/otelcorecol/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ require (
4242
github.com/davecgh/go-spew v1.1.1 // indirect
4343
github.com/ebitengine/purego v0.8.2 // indirect
4444
github.com/felixge/httpsnoop v1.0.4 // indirect
45+
github.com/foxboron/go-tpm-keyfiles v0.0.0-20250323135004-b31fac66206e // indirect
4546
github.com/fsnotify/fsnotify v1.8.0 // indirect
4647
github.com/go-logr/logr v1.4.2 // indirect
4748
github.com/go-logr/stdr v1.2.2 // indirect
4849
github.com/go-ole/go-ole v1.2.6 // indirect
4950
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
5051
github.com/gogo/protobuf v1.3.2 // indirect
5152
github.com/golang/snappy v1.0.0 // indirect
53+
github.com/google/go-tpm v0.9.3 // indirect
5254
github.com/google/uuid v1.6.0 // indirect
5355
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1 // indirect
5456
github.com/hashicorp/go-version v1.7.0 // indirect
@@ -156,6 +158,7 @@ require (
156158
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
157159
go.uber.org/multierr v1.11.0 // indirect
158160
go.uber.org/zap v1.27.0 // indirect
161+
golang.org/x/crypto v0.36.0 // indirect
159162
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
160163
golang.org/x/net v0.38.0 // indirect
161164
golang.org/x/text v0.23.0 // indirect

cmd/otelcorecol/go.sum

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/configgrpc/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ require (
2626

2727
require (
2828
github.com/davecgh/go-spew v1.1.1 // indirect
29+
github.com/foxboron/go-tpm-keyfiles v0.0.0-20250323135004-b31fac66206e // indirect
2930
github.com/fsnotify/fsnotify v1.8.0 // indirect
3031
github.com/go-logr/logr v1.4.2 // indirect
3132
github.com/go-logr/stdr v1.2.2 // indirect
3233
github.com/gogo/protobuf v1.3.2 // indirect
3334
github.com/golang/snappy v0.0.4 // indirect
35+
github.com/google/go-tpm v0.9.3 // indirect
3436
github.com/google/uuid v1.6.0 // indirect
3537
github.com/hashicorp/go-version v1.7.0 // indirect
3638
github.com/json-iterator/go v1.1.12 // indirect
@@ -50,6 +52,7 @@ require (
5052
go.opentelemetry.io/otel/trace v1.35.0 // indirect
5153
go.uber.org/multierr v1.11.0 // indirect
5254
go.uber.org/zap v1.27.0 // indirect
55+
golang.org/x/crypto v0.36.0 // indirect
5356
golang.org/x/net v0.37.0 // indirect
5457
golang.org/x/sys v0.31.0 // indirect
5558
golang.org/x/text v0.23.0 // indirect

config/configgrpc/go.sum

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/confighttp/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ require (
2828
require (
2929
github.com/davecgh/go-spew v1.1.1 // indirect
3030
github.com/felixge/httpsnoop v1.0.4 // indirect
31+
github.com/foxboron/go-tpm-keyfiles v0.0.0-20250323135004-b31fac66206e // indirect
3132
github.com/fsnotify/fsnotify v1.8.0 // indirect
3233
github.com/go-logr/logr v1.4.2 // indirect
3334
github.com/go-logr/stdr v1.2.2 // indirect
3435
github.com/gogo/protobuf v1.3.2 // indirect
36+
github.com/google/go-tpm v0.9.3 // indirect
3537
github.com/google/uuid v1.6.0 // indirect
3638
github.com/hashicorp/go-version v1.7.0 // indirect
3739
github.com/pmezard/go-difflib v1.0.0 // indirect
@@ -46,6 +48,7 @@ require (
4648
go.opentelemetry.io/otel/sdk/metric v1.35.0 // indirect
4749
go.opentelemetry.io/otel/trace v1.35.0 // indirect
4850
go.uber.org/multierr v1.11.0 // indirect
51+
golang.org/x/crypto v0.36.0 // indirect
4952
golang.org/x/sys v0.31.0 // indirect
5053
golang.org/x/text v0.23.0 // indirect
5154
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect

config/confighttp/go.sum

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/confighttp/xconfighttp/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ require (
1414
require (
1515
github.com/davecgh/go-spew v1.1.1 // indirect
1616
github.com/felixge/httpsnoop v1.0.4 // indirect
17+
github.com/foxboron/go-tpm-keyfiles v0.0.0-20250323135004-b31fac66206e // indirect
1718
github.com/fsnotify/fsnotify v1.8.0 // indirect
1819
github.com/go-logr/logr v1.4.2 // indirect
1920
github.com/go-logr/stdr v1.2.2 // indirect
2021
github.com/gogo/protobuf v1.3.2 // indirect
2122
github.com/golang/snappy v1.0.0 // indirect
23+
github.com/google/go-tpm v0.9.3 // indirect
2224
github.com/google/uuid v1.6.0 // indirect
2325
github.com/hashicorp/go-version v1.7.0 // indirect
2426
github.com/klauspost/compress v1.18.0 // indirect
@@ -43,6 +45,7 @@ require (
4345
go.opentelemetry.io/otel/sdk/metric v1.35.0 // indirect
4446
go.uber.org/multierr v1.11.0 // indirect
4547
go.uber.org/zap v1.27.0 // indirect
48+
golang.org/x/crypto v0.36.0 // indirect
4649
golang.org/x/net v0.38.0 // indirect
4750
golang.org/x/sys v0.31.0 // indirect
4851
golang.org/x/text v0.23.0 // indirect

config/confighttp/xconfighttp/go.sum

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/configtls/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ Additionally certificates may be reloaded by setting the below configuration.
8181
How TLS/mTLS is configured depends on whether configuring the client or server.
8282
See below for examples.
8383

84+
- `tpm` (optional): Use the trusted platform module to retrieve the TLS key.
85+
8486
## Client Configuration
8587

8688
[Exporters](https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/README.md)
@@ -155,3 +157,32 @@ receivers:
155157
grpc:
156158
endpoint: mysite.local:55690
157159
```
160+
161+
## Trusted platform module (TPM) configuration
162+
163+
The [trusted platform module](https://trustedcomputinggroup.org/resource/trusted-platform-module-tpm-summary/) (TPM) configuration can be used for loading TLS key from TPM. Currently only TSS2 format is supported.
164+
165+
- `enabled` (default = false): Enables loading `tls.key_file` from TPM.
166+
167+
- `path` (default = ""): The path to the TPM device or Unix domain socket. For instance `/dev/tpm0` or `/dev/tpmrm0`. This option is not supported on Windows.
168+
169+
- `owner_auth` (default = ""): The owner authorization value. This is used to authenticate the TPM device. If not set, the default owner authorization will be used.
170+
171+
- `auth` (default = ""): The authorization value. This is used to authenticate the TPM device. If not set, the default authorization will be used.
172+
173+
Example:
174+
175+
```yaml
176+
exporters:
177+
otlp:
178+
endpoint: myserver.local:55690
179+
tls:
180+
ca_file: ca.crt
181+
cert_file: client.crt
182+
key_file: client-tss2.key
183+
tpm:
184+
enabled: true
185+
path: /dev/tpmrm0
186+
```
187+
188+
The `client-tss2.key` private key with TSS2 format will be loaded from the TPM device `/dev/tpmrm0`.

config/configtls/configtls.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ type Config struct {
7575
// an ECDHE handshake, in preference order
7676
// Defaults to empty list and "crypto/tls" defaults are used, internally.
7777
CurvePreferences []string `mapstructure:"curve_preferences,omitempty"`
78+
79+
// Trusted platform module configuration
80+
TPMConfig TPMConfig `mapstructure:"tpm,omitempty"`
7881
}
7982

8083
// NewDefaultConfig creates a new TLSSetting with any default values set.
@@ -359,11 +362,18 @@ func (c Config) loadCertificate() (tls.Certificate, error) {
359362
keyPem = []byte(c.KeyPem)
360363
}
361364

362-
certificate, err := tls.X509KeyPair(certPem, keyPem)
363-
if err != nil {
364-
return tls.Certificate{}, fmt.Errorf("failed to load TLS cert and key PEMs: %w", err)
365+
if c.TPMConfig.Enabled {
366+
certificate, errTPM := c.TPMConfig.tpmCertificate(keyPem, certPem, openTPM(c.TPMConfig.Path))
367+
if errTPM != nil {
368+
return tls.Certificate{}, fmt.Errorf("failed to load private key from TPM: %w", errTPM)
369+
}
370+
return certificate, nil
365371
}
366372

373+
certificate, errKeyPair := tls.X509KeyPair(certPem, keyPem)
374+
if errKeyPair != nil {
375+
return tls.Certificate{}, fmt.Errorf("failed to load TLS cert and key PEMs: %w", errKeyPair)
376+
}
367377
return certificate, err
368378
}
369379

0 commit comments

Comments
 (0)