Skip to content

Commit f743245

Browse files
authored
[spicedb] rolling update when schema changes (#18561)
1 parent 4bf139e commit f743245

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

components/server/src/authorization/spicedb-authorizer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { v1 } from "@authzed/authzed-node";
88
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
9+
import { TrustedValue } from "@gitpod/gitpod-protocol/lib/util/scrubbing";
910

1011
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
1112
import { inject, injectable } from "inversify";
@@ -47,7 +48,9 @@ export class SpiceDBAuthorizer {
4748
return permitted;
4849
} catch (err) {
4950
error = err;
50-
log.error("[spicedb] Failed to perform authorization check.", err, { req });
51+
log.error("[spicedb] Failed to perform authorization check.", err, {
52+
request: new TrustedValue(req),
53+
});
5154
return false;
5255
} finally {
5356
observeSpicedbClientLatency("check", error, timer());
@@ -72,7 +75,7 @@ export class SpiceDBAuthorizer {
7275
return response;
7376
} catch (err) {
7477
error = err;
75-
log.error("[spicedb] Failed to write relationships.", err, { updates });
78+
log.error("[spicedb] Failed to write relationships.", err, { updates: new TrustedValue(updates) });
7679
} finally {
7780
observeSpicedbClientLatency("write", error, timer());
7881
}
@@ -104,7 +107,7 @@ export class SpiceDBAuthorizer {
104107
error = err;
105108
// While in we're running two authorization systems in parallel, we do not hard fail on writes.
106109
//TODO throw new ApplicationError(ErrorCodes.INTERNAL_SERVER_ERROR, "Failed to delete relationships.");
107-
log.error("[spicedb] Failed to delete relationships.", err, { req });
110+
log.error("[spicedb] Failed to delete relationships.", err, { request: new TrustedValue(req) });
108111
return [];
109112
} finally {
110113
observeSpicedbClientLatency("delete", error, timer());

install/installer/pkg/components/spicedb/deployment.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
3434
return nil, errors.New("missing configuration for spicedb.secretRef")
3535
}
3636

37-
bootstrapVolume, bootstrapVolumeMount, bootstrapFiles, err := getBootstrapConfig(ctx)
37+
bootstrapVolume, bootstrapVolumeMount, bootstrapFiles, contentHash, err := getBootstrapConfig(ctx)
3838
if err != nil {
3939
return nil, fmt.Errorf("failed to get bootstrap config: %w", err)
4040
}
@@ -56,10 +56,14 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
5656
Strategy: common.DeploymentStrategy,
5757
Template: corev1.PodTemplateSpec{
5858
ObjectMeta: metav1.ObjectMeta{
59-
Name: Component,
60-
Namespace: ctx.Namespace,
61-
Labels: labels,
62-
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),
59+
Name: Component,
60+
Namespace: ctx.Namespace,
61+
Labels: labels,
62+
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment, func() map[string]string {
63+
return map[string]string{
64+
common.AnnotationConfigChecksum: contentHash,
65+
}
66+
}),
6367
},
6468
Spec: corev1.PodSpec{
6569
Affinity: cluster.WithNodeAffinityHostnameAntiAffinity(Component, cluster.AffinityLabelMeta),

install/installer/pkg/components/spicedb/schema.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package spicedb
66

77
import (
8+
"crypto/sha256"
9+
"encoding/hex"
810
"fmt"
911
"path/filepath"
1012

@@ -42,7 +44,7 @@ func bootstrap(ctx *common.RenderContext) ([]runtime.Object, error) {
4244
}, nil
4345
}
4446

45-
func getBootstrapConfig(ctx *common.RenderContext) (corev1.Volume, corev1.VolumeMount, []string, error) {
47+
func getBootstrapConfig(ctx *common.RenderContext) (corev1.Volume, corev1.VolumeMount, []string, string, error) {
4648
var volume corev1.Volume
4749
var mount corev1.VolumeMount
4850
var paths []string
@@ -68,12 +70,21 @@ func getBootstrapConfig(ctx *common.RenderContext) (corev1.Volume, corev1.Volume
6870

6971
files, err := spicedb_component.GetBootstrapFiles()
7072
if err != nil {
71-
return corev1.Volume{}, corev1.VolumeMount{}, nil, fmt.Errorf("failed to get bootstrap files: %w", err)
73+
return corev1.Volume{}, corev1.VolumeMount{}, nil, "", fmt.Errorf("failed to get bootstrap files: %w", err)
7274
}
7375

7476
for _, f := range files {
7577
paths = append(paths, filepath.Join(mountPath, f.Name))
7678
}
7779

78-
return volume, mount, paths, nil
80+
concatenated := ""
81+
for _, f := range files {
82+
concatenated += f.Data
83+
}
84+
85+
hasher := sha256.New()
86+
hasher.Write([]byte(concatenated))
87+
hash := hex.EncodeToString(hasher.Sum(nil))
88+
89+
return volume, mount, paths, hash, nil
7990
}

0 commit comments

Comments
 (0)