Skip to content

Commit 7c97b4f

Browse files
committed
adding Manager for RecordingEncryption resources that handles shared ops more complex than CRUD
1 parent c900a70 commit 7c97b4f

File tree

5 files changed

+778
-7
lines changed

5 files changed

+778
-7
lines changed

api/types/sessionrecording.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package types
1818

1919
import (
20+
"iter"
2021
"slices"
2122
"strings"
2223
"time"
@@ -43,6 +44,16 @@ type SessionRecordingConfig interface {
4344
// SetProxyChecksHostKeys sets if the proxy will check host keys.
4445
SetProxyChecksHostKeys(bool)
4546

47+
// GetEncrypted gets if session recordings should be encrypted or not.
48+
GetEncrypted() bool
49+
50+
// GetStatus gets the status for session recording config
51+
GetStatus() SessionRecordingConfigStatus
52+
53+
// SetEncryptionKeys sets the encryption keys for the session recording config.
54+
// It returns true if there was a change applied and false otherwise.
55+
SetEncryptionKeys(iter.Seq[*AgeEncryptionKey]) bool
56+
4657
// Clone returns a copy of the resource.
4758
Clone() SessionRecordingConfig
4859
}
@@ -163,6 +174,50 @@ func (c *SessionRecordingConfigV2) SetProxyChecksHostKeys(t bool) {
163174
c.Spec.ProxyChecksHostKeys = NewBoolOption(t)
164175
}
165176

177+
// GetEncrypted gets if session recordings should be encrypted or not.
178+
func (c *SessionRecordingConfigV2) GetEncrypted() bool {
179+
encryption := c.Spec.Encryption
180+
if encryption == nil {
181+
return false
182+
}
183+
184+
return encryption.Enabled
185+
}
186+
187+
// GetStatus gets if session recordings should be encrypted or not.
188+
func (c *SessionRecordingConfigV2) GetStatus() SessionRecordingConfigStatus {
189+
return c.Status
190+
}
191+
192+
// SetEncryptionKeys sets the cluster's session recording status.
193+
func (c *SessionRecordingConfigV2) SetEncryptionKeys(keys iter.Seq[*AgeEncryptionKey]) bool {
194+
existingKeys := make(map[string]struct{})
195+
for _, key := range c.GetStatus().EncryptionKeys {
196+
existingKeys[string(key.PublicKey)] = struct{}{}
197+
}
198+
199+
var keysChanged bool
200+
var newKeys []*AgeEncryptionKey
201+
addedKeys := make(map[string]struct{})
202+
for key := range keys {
203+
if _, exists := existingKeys[string(key.PublicKey)]; !exists {
204+
keysChanged = true
205+
}
206+
207+
if _, added := addedKeys[string(key.PublicKey)]; !added {
208+
addedKeys[string(key.PublicKey)] = struct{}{}
209+
newKeys = append(newKeys, key)
210+
}
211+
212+
}
213+
214+
c.Status = SessionRecordingConfigStatus{
215+
EncryptionKeys: newKeys,
216+
}
217+
218+
return keysChanged || len(existingKeys) != len(addedKeys)
219+
}
220+
166221
// Clone returns a copy of the resource.
167222
func (c *SessionRecordingConfigV2) Clone() SessionRecordingConfig {
168223
return utils.CloneProtoMsg(c)

go.mod

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,10 @@ require (
125125
github.com/gofrs/flock v0.12.1
126126
github.com/gogo/protobuf v1.3.2 // replaced
127127
github.com/golang-jwt/jwt/v4 v4.5.2
128-
github.com/golang-jwt/jwt/v5 v5.2.2
129128
github.com/google/btree v1.1.3
130129
github.com/google/go-attestation v0.5.1
131130
github.com/google/go-cmp v0.7.0
132131
github.com/google/go-containerregistry v0.20.3
133-
github.com/google/go-github/v70 v70.0.0
134132
github.com/google/go-querystring v1.1.0
135133
github.com/google/go-tpm v0.9.4
136134
github.com/google/go-tpm-tools v0.4.5
@@ -261,6 +259,8 @@ require (
261259
software.sslmate.com/src/go-pkcs12 v0.5.0
262260
)
263261

262+
require github.com/zeebo/assert v1.3.0
263+
264264
require (
265265
cel.dev/expr v0.20.0 // indirect
266266
cloud.google.com/go v0.120.0 // indirect
@@ -270,6 +270,7 @@ require (
270270
cloud.google.com/go/monitoring v1.24.1 // indirect
271271
cloud.google.com/go/pubsub v1.47.0 // indirect
272272
dario.cat/mergo v1.0.1 // indirect
273+
filippo.io/age v1.2.1 // indirect
273274
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
274275
github.com/99designs/keyring v1.2.2 // indirect
275276
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
@@ -345,7 +346,7 @@ require (
345346
github.com/docker/go-metrics v0.0.1 // indirect
346347
github.com/docker/go-units v0.5.0 // indirect
347348
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
348-
github.com/ebitengine/purego v0.8.3 // indirect
349+
github.com/ebitengine/purego v0.8.2 // indirect
349350
github.com/elastic/elastic-transport-go/v8 v8.7.0 // indirect
350351
github.com/emicklei/go-restful/v3 v3.11.3 // indirect
351352
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
@@ -386,6 +387,7 @@ require (
386387
github.com/goccy/go-json v0.10.5 // indirect
387388
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
388389
github.com/godbus/dbus/v5 v5.1.0 // indirect
390+
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
389391
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
390392
github.com/golang-sql/sqlexp v0.1.0 // indirect
391393
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,8 @@ cuelang.org/go v0.12.1/go.mod h1:B4+kjvGGQnbkz+GuAv1dq/R308gTkp0sO28FdMrJ2Kw=
641641
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
642642
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
643643
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
644+
filippo.io/age v1.2.1 h1:X0TZjehAZylOIj4DubWYU1vWQxv9bJpo+Uu2/LGhi1o=
645+
filippo.io/age v1.2.1/go.mod h1:JL9ew2lTN+Pyft4RiNGguFfOpewKwSHm5ayKD/A4004=
644646
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
645647
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
646648
gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8=
@@ -1189,8 +1191,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
11891191
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
11901192
github.com/dvsekhvalnov/jose2go v1.6.0 h1:Y9gnSnP4qEI0+/uQkHvFXeD2PLPJeXEL+ySMEA2EjTY=
11911193
github.com/dvsekhvalnov/jose2go v1.6.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
1192-
github.com/ebitengine/purego v0.8.3 h1:K+0AjQp63JEZTEMZiwsI9g0+hAMNohwUOtY0RPGexmc=
1193-
github.com/ebitengine/purego v0.8.3/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
1194+
github.com/ebitengine/purego v0.8.2 h1:jPPGWs2sZ1UgOSgD2bClL0MJIqu58nOmIcBuXr62z1I=
1195+
github.com/ebitengine/purego v0.8.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
11941196
github.com/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE=
11951197
github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk=
11961198
github.com/elastic/go-elasticsearch/v8 v8.18.0 h1:ANNq1h7DEiPUaALb8+5w3baQzaS08WfHV0DNzp0VG4M=
@@ -1477,8 +1479,6 @@ github.com/google/go-containerregistry v0.20.3 h1:oNx7IdTI936V8CQRveCjaxOiegWwvM
14771479
github.com/google/go-containerregistry v0.20.3/go.mod h1:w00pIgBRDVUDFM6bq+Qx8lwNWK+cxgCuX1vd3PIBDNI=
14781480
github.com/google/go-github/v55 v55.0.0 h1:4pp/1tNMB9X/LuAhs5i0KQAE40NmiR/y6prLNb9x9cg=
14791481
github.com/google/go-github/v55 v55.0.0/go.mod h1:JLahOTA1DnXzhxEymmFF5PP2tSS9JVNj68mSZNDwskA=
1480-
github.com/google/go-github/v70 v70.0.0 h1:/tqCp5KPrcvqCc7vIvYyFYTiCGrYvaWoYMGHSQbo55o=
1481-
github.com/google/go-github/v70 v70.0.0/go.mod h1:xBUZgo8MI3lUL/hwxl3hlceJW1U8MVnXP3zUyI+rhQY=
14821482
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
14831483
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
14841484
github.com/google/go-sev-guest v0.12.1 h1:H4rFYnPIn8HtqEsNTmh56Zxcf9BI9n48ZSYCnpYLYvc=

0 commit comments

Comments
 (0)