Skip to content

Commit 4f9b8b9

Browse files
authored
fix(kas): Do not log index object (#2910)
### Proposed Changes 1.) Have `key_indexers` implement `slog.LogValuer` and `fmt.Stringer` so that object internals are not accidentally logged Example of log after change: ```json time=2025-11-14T13:04:24.587-06:00 level=WARN msg="failure to decrypt dek" namespace=kas error="decrypt: unable to find key by ID 'r3' within index opentdf.io/in-process: not found" request-id=34d60cdd-879e-4840-b133-65c6f080c956 user-agent="connect-go/1.18.1 (go1.25.4)" request-ip=None actor-id=5bc210a6-f501-4e0a-9f0b-34a41673f1f3 ``` ### Checklist - [ ] I have added or updated unit tests - [ ] I have added or updated integration tests (if appropriate) - [ ] I have added or updated documentation ### Testing Instructions
1 parent 89714f2 commit 4f9b8b9

File tree

6 files changed

+49
-0
lines changed

6 files changed

+49
-0
lines changed

service/internal/security/in_process_provider.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ func (a *InProcessProvider) WithLogger(logger *slog.Logger) *InProcessProvider {
134134
return a
135135
}
136136

137+
// Implement fmt.Stringer so Index's default to our String() method
138+
func (a *InProcessProvider) String() string {
139+
return inProcessSystemName
140+
}
141+
142+
// Implement slog.LogValuer for slog logging.
143+
func (a *InProcessProvider) LogValue() slog.Value {
144+
return slog.StringValue(a.String())
145+
}
146+
137147
// FindKeyByAlgorithm finds a key by algorithm using the underlying CryptoProvider.
138148
// This will only return default keys if legacy is false.
139149
// If legacy is true, it will return the first legacy key found that matches the algorithm.

service/kas/access/publicKey_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"crypto/x509"
1010
"encoding/pem"
1111
"errors"
12+
"log/slog"
1213
"math/big"
1314
"os"
1415
"testing"
@@ -98,6 +99,14 @@ func NewMockSecurityProvider() *MockSecurityProvider {
9899
}
99100
}
100101

102+
func (m *MockSecurityProvider) String() string {
103+
return "MockSecurityProvider"
104+
}
105+
106+
func (m *MockSecurityProvider) LogValue() slog.Value {
107+
return slog.StringValue(m.String())
108+
}
109+
101110
func (m *MockSecurityProvider) AddKey(key *MockKeyDetails) {
102111
m.keys[key.id] = key
103112
}

service/kas/access/rewrap_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ type fakeKeyIndex struct {
6767
err error
6868
}
6969

70+
func (f *fakeKeyIndex) String() string {
71+
return "fakeKeyIndex"
72+
}
73+
74+
func (f *fakeKeyIndex) LogValue() slog.Value {
75+
return slog.GroupValue(
76+
slog.String("Indexer", f.String()),
77+
)
78+
}
79+
7080
func (f *fakeKeyIndex) FindKeyByAlgorithm(context.Context, string, bool) (trust.KeyDetails, error) {
7181
return nil, errors.New("not implemented")
7282
}

service/kas/key_indexer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/pem"
1010
"errors"
1111
"fmt"
12+
"log/slog"
1213

1314
"github.com/lestrrat-go/jwx/v2/jwk"
1415
"github.com/opentdf/platform/lib/ocrypto"
@@ -85,6 +86,10 @@ func (p *KeyIndexer) String() string {
8586
return fmt.Sprintf("PlatformKeyIndexer[%s]", p.kasURI)
8687
}
8788

89+
func (p *KeyIndexer) LogValue() slog.Value {
90+
return slog.StringValue(p.String())
91+
}
92+
8893
func (p *KeyIndexer) FindKeyByAlgorithm(ctx context.Context, algorithm string, includeLegacy bool) (trust.KeyDetails, error) {
8994
alg, err := convertAlgToEnum(algorithm)
9095
if err != nil {

service/trust/delegating_key_service_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package trust
33
import (
44
"context"
55
"crypto/elliptic"
6+
"log/slog"
67
"testing"
78

89
"github.com/opentdf/platform/lib/ocrypto"
@@ -54,6 +55,16 @@ type MockKeyIndex struct {
5455
mock.Mock
5556
}
5657

58+
func (m *MockKeyIndex) String() string {
59+
return "mockKeyIndex"
60+
}
61+
62+
func (m *MockKeyIndex) LogValue() slog.Value {
63+
return slog.GroupValue(
64+
slog.String("Indexer", m.String()),
65+
)
66+
}
67+
5768
func (m *MockKeyIndex) FindKeyByAlgorithm(ctx context.Context, algorithm string, includeLegacy bool) (KeyDetails, error) {
5869
args := m.Called(ctx, algorithm, includeLegacy)
5970
if a0, ok := args.Get(0).(KeyDetails); ok {

service/trust/key_index.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package trust
22

33
import (
44
"context"
5+
"fmt"
6+
"log/slog"
57

68
"github.com/opentdf/platform/lib/ocrypto"
79
"github.com/opentdf/platform/protocol/go/policy"
@@ -63,6 +65,8 @@ type KeyDetails interface {
6365

6466
// KeyIndex provides methods to locate keys by various criteria
6567
type KeyIndex interface {
68+
fmt.Stringer
69+
slog.LogValuer
6670
// FindKeyByAlgorithm returns a key for the specified algorithm
6771
// If includeLegacy is true, legacy keys will be included in the search
6872
FindKeyByAlgorithm(ctx context.Context, algorithm string, includeLegacy bool) (KeyDetails, error)

0 commit comments

Comments
 (0)