Skip to content

Commit 06206eb

Browse files
committed
adding Manager for RecordingEncryption resources that handles shared ops more complex than CRUD
1 parent 6fa728b commit 06206eb

File tree

5 files changed

+694
-0
lines changed

5 files changed

+694
-0
lines changed

api/types/sessionrecording.go

Lines changed: 61 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,56 @@ 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 for the session recording config.
197+
// It returns true if there was a change applied and false otherwise.
198+
func (c *SessionRecordingConfigV2) SetEncryptionKeys(keys iter.Seq[*AgeEncryptionKey]) bool {
199+
existingKeys := make(map[string]struct{})
200+
for _, key := range c.GetEncryptionKeys() {
201+
existingKeys[string(key.PublicKey)] = struct{}{}
202+
}
203+
204+
var keysChanged bool
205+
var newKeys []*AgeEncryptionKey
206+
addedKeys := make(map[string]struct{})
207+
for key := range keys {
208+
if _, exists := existingKeys[string(key.PublicKey)]; !exists {
209+
keysChanged = true
210+
}
211+
212+
if _, added := addedKeys[string(key.PublicKey)]; !added {
213+
addedKeys[string(key.PublicKey)] = struct{}{}
214+
newKeys = append(newKeys, key)
215+
}
216+
217+
}
218+
219+
if c.Status == nil {
220+
c.Status = &SessionRecordingConfigStatus{}
221+
}
222+
c.Status.EncryptionKeys = newKeys
223+
224+
return keysChanged || len(existingKeys) != len(addedKeys)
225+
}
226+
166227
// Clone returns a copy of the resource.
167228
func (c *SessionRecordingConfigV2) Clone() SessionRecordingConfig {
168229
return utils.CloneProtoMsg(c)

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

go.sum

Lines changed: 4 additions & 0 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=

0 commit comments

Comments
 (0)