Skip to content

Commit 1444b0d

Browse files
authored
Fix OCI cache reconstruction (#1076)
* fix(oci): systematically reconstruct cache whenever required * fix(tests): define replicas as numbers * chore(deps): update Go to latest version * fix(tests): replicas as integers * fix(tests): redefine Pulumi default values in auto config+secrets for non-plaintext-strings config * fix(deps): update Go deps
1 parent 3644b68 commit 1444b0d

File tree

26 files changed

+173
-51
lines changed

26 files changed

+173
-51
lines changed

api/v1/challenge/delete.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/ctfer-io/chall-manager/pkg/fs"
1919
"github.com/ctfer-io/chall-manager/pkg/iac"
2020
"github.com/ctfer-io/chall-manager/pkg/lock"
21+
"github.com/ctfer-io/chall-manager/pkg/scenario"
2122
)
2223

2324
func (store *Store) DeleteChallenge(ctx context.Context, req *DeleteChallengeRequest) (*emptypb.Empty, error) {
@@ -93,6 +94,21 @@ func (store *Store) DeleteChallenge(ctx context.Context, req *DeleteChallengeReq
9394
return nil, err
9495
}
9596

97+
// Reload cache if necessary
98+
if _, err := scenario.DecodeOCI(ctx,
99+
fschall.ID, fschall.Scenario, fschall.Additional,
100+
global.Conf.OCI.Insecure, global.Conf.OCI.Username, global.Conf.OCI.Password,
101+
); err != nil {
102+
logger.Error(ctx, "decoding scenario",
103+
zap.String("reference", fschall.Scenario),
104+
zap.Error(multierr.Combine(
105+
clock.RWUnlock(ctx),
106+
err,
107+
)),
108+
)
109+
return nil, errs.ErrInternalNoSub
110+
}
111+
96112
// 5. Create "relock" and "work" wait groups for all instances, and for each
97113
ists, err := fs.ListInstances(req.Id)
98114
if err != nil {

api/v1/challenge/update.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ func (store *Store) UpdateChallenge(ctx context.Context, req *UpdateChallengeReq
106106
return nil, err
107107
}
108108

109+
// Reload cache if necessary
110+
if _, err := scenario.DecodeOCI(ctx,
111+
fschall.ID, fschall.Scenario, req.Additional,
112+
global.Conf.OCI.Insecure, global.Conf.OCI.Username, global.Conf.OCI.Password,
113+
); err != nil {
114+
logger.Error(ctx, "decoding scenario",
115+
zap.String("reference", fschall.Scenario),
116+
zap.Error(err),
117+
)
118+
return nil, errs.ErrInternalNoSub
119+
}
120+
109121
// 5. Update challenge until/timeout, pooler, or scenario on filesystem
110122
updateScenario := false
111123
updateAdditional := false

api/v1/instance/create.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/ctfer-io/chall-manager/pkg/fs"
1818
"github.com/ctfer-io/chall-manager/pkg/iac"
1919
"github.com/ctfer-io/chall-manager/pkg/identity"
20+
"github.com/ctfer-io/chall-manager/pkg/scenario"
2021
)
2122

2223
func (man *Manager) CreateInstance(ctx context.Context, req *CreateInstanceRequest) (*Instance, error) {
@@ -87,6 +88,17 @@ func (man *Manager) CreateInstance(ctx context.Context, req *CreateInstanceReque
8788
}
8889
return nil, err
8990
}
91+
// Reload cache if necessary
92+
if _, err := scenario.DecodeOCI(ctx,
93+
fschall.ID, fschall.Scenario, req.Additional,
94+
global.Conf.OCI.Insecure, global.Conf.OCI.Username, global.Conf.OCI.Password,
95+
); err != nil {
96+
logger.Error(ctx, "decoding scenario",
97+
zap.String("reference", fschall.Scenario),
98+
zap.Error(err),
99+
)
100+
return nil, errs.ErrInternalNoSub
101+
}
90102
if fschall.Until != nil && time.Now().After(*fschall.Until) {
91103
if err := clock.RUnlock(ctx); err != nil {
92104
logger.Error(ctx, "unlocking R challenge", zap.Error(err))

api/v1/instance/delete.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/ctfer-io/chall-manager/pkg/fs"
1818
"github.com/ctfer-io/chall-manager/pkg/iac"
1919
"github.com/ctfer-io/chall-manager/pkg/lock"
20+
"github.com/ctfer-io/chall-manager/pkg/scenario"
2021
)
2122

2223
func (man *Manager) DeleteInstance(ctx context.Context, req *DeleteInstanceRequest) (*emptypb.Empty, error) {
@@ -176,6 +177,18 @@ func (man *Manager) DeleteInstance(ctx context.Context, req *DeleteInstanceReque
176177
return nil, err
177178
}
178179

180+
// Reload cache if necessary
181+
if _, err := scenario.DecodeOCI(ctx,
182+
fschall.ID, fschall.Scenario, fschall.Additional,
183+
global.Conf.OCI.Insecure, global.Conf.OCI.Username, global.Conf.OCI.Password,
184+
); err != nil {
185+
logger.Error(ctx, "decoding scenario",
186+
zap.String("reference", fschall.Scenario),
187+
zap.Error(err),
188+
)
189+
return nil, errs.ErrInternalNoSub
190+
}
191+
179192
stack, err := iac.LoadStack(ctx, fschall.Directory, id)
180193
if err != nil {
181194
if err, ok := err.(*errs.ErrInternal); ok {

api/v1/instance/spin.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/ctfer-io/chall-manager/pkg/fs"
1111
"github.com/ctfer-io/chall-manager/pkg/iac"
1212
"github.com/ctfer-io/chall-manager/pkg/identity"
13+
"github.com/ctfer-io/chall-manager/pkg/scenario"
1314
"go.opentelemetry.io/otel/attribute"
1415
"go.opentelemetry.io/otel/metric"
1516
"go.opentelemetry.io/otel/trace"
@@ -108,6 +109,18 @@ func SpinUp(ctx context.Context, challengeID string) {
108109
id := identity.New()
109110
ctx = global.WithIdentity(ctx, id)
110111

112+
// Reload cache if necessary
113+
if _, err := scenario.DecodeOCI(ctx,
114+
fschall.ID, fschall.Scenario, fschall.Additional,
115+
global.Conf.OCI.Insecure, global.Conf.OCI.Username, global.Conf.OCI.Password,
116+
); err != nil {
117+
logger.Error(ctx, "decoding scenario",
118+
zap.String("reference", fschall.Scenario),
119+
zap.Error(err),
120+
)
121+
return
122+
}
123+
111124
// 10. Spin up instance
112125
stack, err := iac.NewStack(ctx, id, fschall)
113126
if err != nil {

deploy/go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module github.com/ctfer-io/chall-manager/deploy
22

3-
go 1.24.3
3+
go 1.25.4
44

55
require (
66
github.com/Masterminds/sprig/v3 v3.3.0
77
github.com/ctfer-io/chall-manager v0.6.0
88
github.com/ctfer-io/monitoring v0.1.0
99
github.com/pkg/errors v0.9.1
10-
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.23.0
10+
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.24.0
1111
github.com/pulumi/pulumi-random/sdk/v4 v4.18.4
12-
github.com/pulumi/pulumi/pkg/v3 v3.201.0
13-
github.com/pulumi/pulumi/sdk/v3 v3.203.0
12+
github.com/pulumi/pulumi/pkg/v3 v3.208.0
13+
github.com/pulumi/pulumi/sdk/v3 v3.208.0
1414
github.com/stretchr/testify v1.11.1
1515
go.opentelemetry.io/collector/pdata v1.44.0
1616
go.uber.org/multierr v1.11.0
@@ -96,7 +96,7 @@ require (
9696
github.com/go-openapi/jsonpointer v0.21.0 // indirect
9797
github.com/go-openapi/jsonreference v0.20.2 // indirect
9898
github.com/go-openapi/swag v0.23.0 // indirect
99-
github.com/go-test/deep v1.0.3 // indirect
99+
github.com/go-test/deep v1.1.1 // indirect
100100
github.com/goccy/go-json v0.10.5 // indirect
101101
github.com/gofrs/uuid v4.2.0+incompatible // indirect
102102
github.com/gogo/protobuf v1.3.2 // indirect
@@ -181,13 +181,13 @@ require (
181181
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
182182
github.com/segmentio/asm v1.2.0 // indirect
183183
github.com/segmentio/encoding v0.5.3 // indirect
184-
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
184+
github.com/sergi/go-diff v1.4.0 // indirect
185185
github.com/shopspring/decimal v1.4.0 // indirect
186186
github.com/sirupsen/logrus v1.9.3 // indirect
187187
github.com/skeema/knownhosts v1.3.0 // indirect
188188
github.com/spf13/cast v1.7.0 // indirect
189-
github.com/spf13/cobra v1.9.1 // indirect
190-
github.com/spf13/pflag v1.0.7 // indirect
189+
github.com/spf13/cobra v1.10.1 // indirect
190+
github.com/spf13/pflag v1.0.9 // indirect
191191
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
192192
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
193193
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect

deploy/go.sum

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v
220220
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
221221
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
222222
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
223+
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
223224
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
224225
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
225226
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
@@ -447,14 +448,18 @@ github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 h1:vkHw5I/plNdTr435
447448
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231/go.mod h1:murToZ2N9hNJzewjHBgfFdXhZKjY3z5cYC1VXk+lbFE=
448449
github.com/pulumi/esc v0.17.0 h1:oaVOIyFTENlYDuqc3pW75lQT9jb2cd6ie/4/Twxn66w=
449450
github.com/pulumi/esc v0.17.0/go.mod h1:XnSxlt5NkmuAj304l/gK4pRErFbtqq6XpfX1tYT9Jbc=
450-
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.23.0 h1:TZ/XhzF+3/jRiGsjlJHCWhXcU5E5tbXU8O0DKnPmFic=
451-
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.23.0/go.mod h1:jOdpeNeRvY4iN+W8aDP5+HyqrM7hXsxa9paPsmjQFfY=
451+
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.24.0 h1:dlDJvsugKow8tCaD0yJngc7PXdv8WT2YwPEUmj48tF4=
452+
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.24.0/go.mod h1:8HDO923pZUokTAEMgS7XepoUIDCazm2WAwX6s4HUDtc=
452453
github.com/pulumi/pulumi-random/sdk/v4 v4.18.4 h1:mkZ3nB3xLTFZ8Fbh50bXTxiroGpjSyonTFcKovLxWME=
453454
github.com/pulumi/pulumi-random/sdk/v4 v4.18.4/go.mod h1:BBVUyqFkhCbwvUSnDjubH5b+SeJeoMQH4COGNKaaoUI=
454-
github.com/pulumi/pulumi/pkg/v3 v3.201.0 h1:Vu36u/Hv+kGJr5ryPP40fYABDKuvWcKQKm5hYMw/gU4=
455-
github.com/pulumi/pulumi/pkg/v3 v3.201.0/go.mod h1:dwXMnuziQF0d66p6cfB4//gsS3qRoXdqWIMKKyNNx1I=
456-
github.com/pulumi/pulumi/sdk/v3 v3.203.0 h1:naNpZOkGf1QaIcfB47MAh2UHW7DUh37Tg1zOdDmxx5I=
457-
github.com/pulumi/pulumi/sdk/v3 v3.203.0/go.mod h1:aV0+c5xpSYccWKmOjTZS9liYCqh7+peu3cQgSXu7CJw=
455+
github.com/pulumi/pulumi/pkg/v3 v3.205.0 h1:gSsJr4opU+rfx0CJEvk2f+kf6mNA6qIdACdfrDwd4HE=
456+
github.com/pulumi/pulumi/pkg/v3 v3.205.0/go.mod h1:DwMi4+xkHvw6aazISQd4nWzhDHtMGQxl2w5WJtUl6mA=
457+
github.com/pulumi/pulumi/pkg/v3 v3.208.0 h1:MBnkg2QCXE+nssylAgYRWiOGaTi2ynBbSgjGeaaktAk=
458+
github.com/pulumi/pulumi/pkg/v3 v3.208.0/go.mod h1:7SMtVWWoCTPQHQNBpDjaZrqo8tBFygDv50rTCmGjEds=
459+
github.com/pulumi/pulumi/sdk/v3 v3.205.0 h1:Cuev0D3nBUqnFnFzWsO6M5XtOdGCe7lpgSds80yROyQ=
460+
github.com/pulumi/pulumi/sdk/v3 v3.205.0/go.mod h1:aV0+c5xpSYccWKmOjTZS9liYCqh7+peu3cQgSXu7CJw=
461+
github.com/pulumi/pulumi/sdk/v3 v3.208.0 h1:AUBoh7zw67NZVo1IkapOog1WBMz46DXco/7YsKBNK1s=
462+
github.com/pulumi/pulumi/sdk/v3 v3.208.0/go.mod h1:UsBMdaUQ+WoKoQtF2PYbQIbo8ZRJuAo1axkyit9IQVE=
458463
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
459464
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
460465
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
@@ -474,8 +479,8 @@ github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
474479
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
475480
github.com/segmentio/encoding v0.5.3 h1:OjMgICtcSFuNvQCdwqMCv9Tg7lEOXGwm1J5RPQccx6w=
476481
github.com/segmentio/encoding v0.5.3/go.mod h1:HS1ZKa3kSN32ZHVZ7ZLPLXWvOVIiZtyJnO1gPH1sKt0=
477-
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
478-
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
482+
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
483+
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
479484
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
480485
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
481486
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
@@ -485,11 +490,10 @@ github.com/skeema/knownhosts v1.3.0 h1:AM+y0rI04VksttfwjkSTNQorvGqmwATnvnAHpSgc0
485490
github.com/skeema/knownhosts v1.3.0/go.mod h1:sPINvnADmT/qYH1kfv+ePMmOBTH6Tbl7b5LvTDjFK7M=
486491
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
487492
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
488-
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
489-
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
490-
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
491-
github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M=
492-
github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
493+
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
494+
github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0=
495+
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
496+
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
493497
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
494498
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
495499
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=

deploy/integration/cluster_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ func Test_I_Cluster(t *testing.T) {
3636
"replicas": "1", // no need to replicate, we test proper deployments
3737
"etcd-replicas": "1", // no need to replicate, we test proper deployment
3838
"expose": "true", // make API externally reachable
39+
// Following config values are defined, seems like due to a bug in Pulumi loading config
40+
"etcd.replicas": "1",
41+
"oci.insecure": "true",
42+
"otel.insecure": "true",
43+
},
44+
Secrets: map[string]string{
45+
"kubeconfig": "",
3946
},
4047
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
4148
cli := grpcClient(t, stack.Outputs)

deploy/integration/examples_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ func Test_I_Examples(t *testing.T) {
5454
"oci-insecure": "true", // don't mind HTTPS on the CI registry
5555
"pvc-access-mode": "ReadWriteOnce", // don't need to scale (+ not possible with kind in CI)
5656
"expose": "true", // make API externally reachable
57+
// Following config values are defined, seems like due to a bug in Pulumi loading config
58+
"etcd.replicas": "1",
59+
"oci.insecure": "true",
60+
"otel.insecure": "true",
61+
},
62+
Secrets: map[string]string{
63+
"kubeconfig": "",
5764
},
5865
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
5966
cli := grpcClient(t, stack.Outputs)

deploy/integration/monitoring_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ func Test_I_Monitoring(t *testing.T) {
6060
"registry": os.Getenv("REGISTRY"),
6161
"tag": os.Getenv("TAG"),
6262
"romeo-claim-name": os.Getenv("ROMEO_CLAIM_NAME"),
63+
// Following config values are defined, seems like due to a bug in Pulumi loading config
64+
"etcd.replicas": "0",
65+
"oci.insecure": "true",
66+
"otel.insecure": "true",
67+
},
68+
Secrets: map[string]string{
69+
"kubeconfig": "",
6370
},
6471
Env: []string{
6572
"CHALL_MANAGER_TEST_INTEGRATION_MONITORING=pouet",

0 commit comments

Comments
 (0)