Skip to content

Commit fb22a26

Browse files
committed
caddytls: Allow missing ECH meta file
1 parent 1bfa111 commit fb22a26

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

modules/caddytls/ech.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (t *TLS) publishECHConfigs() error {
278278
// if all the (inner) domains have had this ECH config list published
279279
// by this publisher, then try the next publication config
280280
if len(serverNamesSet) == 0 {
281-
logger.Debug("ECH config list already published by publisher for associated domains",
281+
logger.Debug("ECH config list already published by publisher for associated domains (or no domains to publish for)",
282282
zap.Uint8s("config_ids", configIDs),
283283
zap.String("publisher", publisherKey))
284284
continue
@@ -299,7 +299,7 @@ func (t *TLS) publishECHConfigs() error {
299299
err := publisher.PublishECHConfigList(t.ctx, dnsNamesToPublish, echCfgListBin)
300300
if err == nil {
301301
t.logger.Info("published ECH configuration list",
302-
zap.Strings("domains", publication.Domains),
302+
zap.Strings("domains", dnsNamesToPublish),
303303
zap.Uint8s("config_ids", configIDs),
304304
zap.Error(err))
305305
// update publication history, so that we don't unnecessarily republish every time
@@ -389,27 +389,33 @@ func loadECHConfig(ctx caddy.Context, configID string) (echConfig, error) {
389389
return echConfig{}, nil
390390
}
391391
metaBytes, err := storage.Load(ctx, metaKey)
392-
if err != nil {
392+
if errors.Is(err, fs.ErrNotExist) {
393+
logger.Warn("ECH config metadata file missing; will recreate at next publication",
394+
zap.String("config_id", configID),
395+
zap.Error(err))
396+
} else if err != nil {
393397
delErr := storage.Delete(ctx, cfgIDKey)
394398
if delErr != nil {
395-
return echConfig{}, fmt.Errorf("error loading ECH metadata (%v) and cleaning up parent storage key %s: %v", err, cfgIDKey, delErr)
399+
return echConfig{}, fmt.Errorf("error loading ECH config metadata (%v) and cleaning up parent storage key %s: %v", err, cfgIDKey, delErr)
396400
}
397-
logger.Warn("could not load ECH metadata; deleted its config folder",
401+
logger.Warn("could not load ECH config metadata; deleted its folder",
398402
zap.String("config_id", configID),
399403
zap.Error(err))
400404
return echConfig{}, nil
401405
}
402406
var meta echConfigMeta
403-
if err := json.Unmarshal(metaBytes, &meta); err != nil {
404-
// even though it's just metadata, reset the whole config since we can't reliably maintain it
405-
delErr := storage.Delete(ctx, cfgIDKey)
406-
if delErr != nil {
407-
return echConfig{}, fmt.Errorf("error decoding ECH metadata (%v) and cleaning up parent storage key %s: %v", err, cfgIDKey, delErr)
407+
if len(metaBytes) > 0 {
408+
if err := json.Unmarshal(metaBytes, &meta); err != nil {
409+
// even though it's just metadata, reset the whole config since we can't reliably maintain it
410+
delErr := storage.Delete(ctx, cfgIDKey)
411+
if delErr != nil {
412+
return echConfig{}, fmt.Errorf("error decoding ECH metadata (%v) and cleaning up parent storage key %s: %v", err, cfgIDKey, delErr)
413+
}
414+
logger.Warn("could not JSON-decode ECH metadata; deleted its config folder",
415+
zap.String("config_id", configID),
416+
zap.Error(err))
417+
return echConfig{}, nil
408418
}
409-
logger.Warn("could not JSON-decode ECH metadata; deleted its config folder",
410-
zap.String("config_id", configID),
411-
zap.Error(err))
412-
return echConfig{}, nil
413419
}
414420

415421
cfg.privKeyBin = privKeyBytes
@@ -700,7 +706,7 @@ nextName:
700706
// HTTPS and SVCB RRs: RFC 9460 (https://www.rfc-editor.org/rfc/rfc9460)
701707
Scheme: "https",
702708
Name: relName,
703-
TTL: 1 * time.Minute, // TODO: for testing only
709+
TTL: 5 * time.Minute, // TODO: low hard-coded value only temporary; change to a higher value once more field-tested and key rotation is implemented
704710
Priority: 2, // allows a manual override with priority 1
705711
Target: ".",
706712
Params: params,

0 commit comments

Comments
 (0)