Skip to content

Commit 88375d9

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

File tree

5 files changed

+694
-5
lines changed

5 files changed

+694
-5
lines changed

api/types/sessionrecording.go

Lines changed: 60 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+
// GetEncryptionKeys gets the encryption keys for the session recording config.
51+
GetEncryptionKeys() []*AgeEncryptionKey
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,55 @@ 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+
// GetEncryptionKeys gets the encryption keys for the session recording config.
188+
func (c *SessionRecordingConfigV2) GetEncryptionKeys() []*AgeEncryptionKey {
189+
if c.Status != nil {
190+
return c.Status.EncryptionKeys
191+
}
192+
193+
return nil
194+
}
195+
196+
// SetEncryptionKeys sets the encryption keys that should be used for session recordings.
197+
func (c *SessionRecordingConfigV2) SetEncryptionKeys(keys iter.Seq[*AgeEncryptionKey]) bool {
198+
existingKeys := make(map[string]struct{})
199+
for _, key := range c.GetEncryptionKeys() {
200+
existingKeys[string(key.PublicKey)] = struct{}{}
201+
}
202+
203+
var keysChanged bool
204+
var newKeys []*AgeEncryptionKey
205+
addedKeys := make(map[string]struct{})
206+
for key := range keys {
207+
if _, exists := existingKeys[string(key.PublicKey)]; !exists {
208+
keysChanged = true
209+
}
210+
211+
if _, added := addedKeys[string(key.PublicKey)]; !added {
212+
addedKeys[string(key.PublicKey)] = struct{}{}
213+
newKeys = append(newKeys, key)
214+
}
215+
216+
}
217+
218+
if c.Status == nil {
219+
c.Status = &SessionRecordingConfigStatus{}
220+
}
221+
c.Status.EncryptionKeys = newKeys
222+
223+
return keysChanged || len(existingKeys) != len(addedKeys)
224+
}
225+
166226
// Clone returns a copy of the resource.
167227
func (c *SessionRecordingConfigV2) Clone() SessionRecordingConfig {
168228
return utils.CloneProtoMsg(c)

go.mod

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

261+
require github.com/google/go-github/v70 v70.0.0
262+
263263
require (
264264
cel.dev/expr v0.20.0 // indirect
265265
cloud.google.com/go v0.120.0 // indirect
@@ -269,6 +269,7 @@ require (
269269
cloud.google.com/go/monitoring v1.24.1 // indirect
270270
cloud.google.com/go/pubsub v1.47.0 // indirect
271271
dario.cat/mergo v1.0.1 // indirect
272+
filippo.io/age v1.2.1
272273
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
273274
github.com/99designs/keyring v1.2.2 // indirect
274275
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
@@ -344,7 +345,7 @@ require (
344345
github.com/docker/go-metrics v0.0.1 // indirect
345346
github.com/docker/go-units v0.5.0 // indirect
346347
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
347-
github.com/ebitengine/purego v0.8.3 // indirect
348+
github.com/ebitengine/purego v0.8.2 // indirect
348349
github.com/elastic/elastic-transport-go/v8 v8.7.0 // indirect
349350
github.com/emicklei/go-restful/v3 v3.11.3 // indirect
350351
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
@@ -385,6 +386,7 @@ require (
385386
github.com/goccy/go-json v0.10.5 // indirect
386387
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
387388
github.com/godbus/dbus/v5 v5.1.0 // indirect
389+
github.com/golang-jwt/jwt/v5 v5.2.2
388390
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
389391
github.com/golang-sql/sqlexp v0.1.0 // indirect
390392
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
c2sp.org/CCTV/age v0.0.0-20240306222714-3ec4d716e805 h1:u2qwJeEvnypw+OCPUHmoZE3IqwfuN5kgDfo5MLzpNM0=
2+
c2sp.org/CCTV/age v0.0.0-20240306222714-3ec4d716e805/go.mod h1:FomMrUJ2Lxt5jCLmZkG3FHa72zUprnhd3v/Z18Snm4w=
13
cel.dev/expr v0.20.0 h1:OunBvVCfvpWlt4dN7zg3FM6TDkzOePe1+foGJ9AXeeI=
24
cel.dev/expr v0.20.0/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
35
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
@@ -641,6 +643,8 @@ cuelang.org/go v0.12.1/go.mod h1:B4+kjvGGQnbkz+GuAv1dq/R308gTkp0sO28FdMrJ2Kw=
641643
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
642644
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
643645
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
646+
filippo.io/age v1.2.1 h1:X0TZjehAZylOIj4DubWYU1vWQxv9bJpo+Uu2/LGhi1o=
647+
filippo.io/age v1.2.1/go.mod h1:JL9ew2lTN+Pyft4RiNGguFfOpewKwSHm5ayKD/A4004=
644648
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
645649
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
646650
gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8=
@@ -1182,8 +1186,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
11821186
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
11831187
github.com/dvsekhvalnov/jose2go v1.6.0 h1:Y9gnSnP4qEI0+/uQkHvFXeD2PLPJeXEL+ySMEA2EjTY=
11841188
github.com/dvsekhvalnov/jose2go v1.6.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
1185-
github.com/ebitengine/purego v0.8.3 h1:K+0AjQp63JEZTEMZiwsI9g0+hAMNohwUOtY0RPGexmc=
1186-
github.com/ebitengine/purego v0.8.3/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
1189+
github.com/ebitengine/purego v0.8.2 h1:jPPGWs2sZ1UgOSgD2bClL0MJIqu58nOmIcBuXr62z1I=
1190+
github.com/ebitengine/purego v0.8.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
11871191
github.com/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE=
11881192
github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk=
11891193
github.com/elastic/go-elasticsearch/v8 v8.18.0 h1:ANNq1h7DEiPUaALb8+5w3baQzaS08WfHV0DNzp0VG4M=

0 commit comments

Comments
 (0)