forked from basecamp/kamal-proxy
-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(san-cert): SAN batch resilience — eviction grace, shrink guard, renewal preflight, batch quarantine #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7060212
feat(san-cert): keep evicted certificates until their own expiry
mhenrixon 9505676
feat(san-cert): hold suspicious mass-removals from a domain source
mhenrixon a07e4c7
feat(san-cert): probe dynamic members before every renewal order
mhenrixon 4993c8b
feat(san-cert): probe for culprits when an ACME failure names no domain
mhenrixon 4955983
feat(san-cert): guard the handshake batch with preflight and quarantine
mhenrixon c42a426
docs(san-cert): document the shrink guard and eviction grace period
mhenrixon 260ec16
fix(san-cert): address PR #97 review findings
mhenrixon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "strings" | ||
| "sync" | ||
| ) | ||
|
|
||
| // Attribution of failed ACME orders to the domains that caused them, shared by | ||
| // the dynamic issuer and the background renewer. | ||
|
|
||
| // maxConcurrentProbes bounds parallel pre-flight probes. Each probe can take | ||
| // up to preflightTimeout, so a serial sweep over a large batch would block an | ||
| // issuance slot (or a waiting handshake) for minutes; concurrency keeps the | ||
| // worst case to a few probe timeouts. | ||
| const maxConcurrentProbes = 16 | ||
|
|
||
| // identifyFailedDomains names the domains responsible for a failed order: | ||
| // lego's per-domain error lines when present, a pre-flight probe of each | ||
| // member otherwise, and the whole set when neither can tell — an | ||
| // unattributable failure holds the entire batch on the quarantine ladder so | ||
| // retries back off instead of looping against ACME rate limits. | ||
| func identifyFailedDomains(err error, domains []string, preflight func(string) error) []string { | ||
| if failed := failedDomainsFromError(err, domains); len(failed) > 0 { | ||
| return failed | ||
| } | ||
|
|
||
| if failed, _ := probeDomains(domains, preflight); len(failed) > 0 { | ||
| return failed | ||
| } | ||
|
|
||
| return domains | ||
| } | ||
|
|
||
| // probeDomains runs the pre-flight probe over a set of domains with bounded | ||
| // concurrency and returns the ones that failed, in input order, with each | ||
| // failure's error. Wildcards are skipped — there is no name to answer on one. | ||
| // A nil probe reports nothing. | ||
| func probeDomains(domains []string, preflight func(string) error) ([]string, map[string]error) { | ||
| if preflight == nil { | ||
| return nil, nil | ||
| } | ||
|
|
||
| errs := make([]error, len(domains)) | ||
| sem := make(chan struct{}, maxConcurrentProbes) | ||
| var wg sync.WaitGroup | ||
| for idx, domain := range domains { | ||
| if strings.HasPrefix(domain, "*.") { | ||
| continue | ||
| } | ||
| wg.Add(1) | ||
| sem <- struct{}{} | ||
| go func(idx int, domain string) { | ||
| defer wg.Done() | ||
| defer func() { <-sem }() | ||
| errs[idx] = preflight(domain) | ||
| }(idx, domain) | ||
| } | ||
| wg.Wait() | ||
|
|
||
| failed := []string{} | ||
| failures := map[string]error{} | ||
| for idx, domain := range domains { | ||
| if errs[idx] != nil { | ||
| failed = append(failed, domain) | ||
| failures[domain] = errs[idx] | ||
| } | ||
| } | ||
| return failed, failures | ||
| } | ||
|
|
||
| // failedDomainsFromError matches lego's per-domain error lines | ||
| // ("<domain>: <cause>") against the attempted domains. | ||
| func failedDomainsFromError(err error, domains []string) []string { | ||
| lines := strings.Split(err.Error(), "\n") | ||
|
|
||
| failed := []string{} | ||
| for _, domain := range domains { | ||
| prefix := domain + ": " | ||
| for _, line := range lines { | ||
| if strings.HasPrefix(strings.TrimSpace(line), prefix) { | ||
| failed = append(failed, domain) | ||
| break | ||
| } | ||
| } | ||
| } | ||
| return failed | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestIdentifyFailedDomains(t *testing.T) { | ||
| domains := []string{"a.example.com", "b.example.com"} | ||
| failB := func(domain string) error { | ||
| if domain == "b.example.com" { | ||
| return errors.New("does not route here") | ||
| } | ||
| return nil | ||
| } | ||
| failAll := func(domain string) error { return errors.New("does not route here") } | ||
| passAll := func(domain string) error { return nil } | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| err error | ||
| domains []string | ||
| preflight func(string) error | ||
| expected []string | ||
| }{ | ||
| { | ||
| name: "per-domain error lines take precedence over probing", | ||
| err: fmt.Errorf("error: one or more domains had a problem:\na.example.com: acme: dns problem"), | ||
| domains: domains, | ||
| preflight: failB, | ||
| expected: []string{"a.example.com"}, | ||
| }, | ||
| { | ||
| name: "probe names the culprit when the error does not", | ||
| err: errors.New("acme: internal error"), | ||
| domains: domains, | ||
| preflight: failB, | ||
| expected: []string{"b.example.com"}, | ||
| }, | ||
| { | ||
| name: "everything passes probing: the whole batch is held", | ||
| err: errors.New("acme: internal error"), | ||
| domains: domains, | ||
| preflight: passAll, | ||
| expected: domains, | ||
| }, | ||
| { | ||
| name: "no probe available: the whole batch is held", | ||
| err: errors.New("acme: internal error"), | ||
| domains: domains, | ||
| expected: domains, | ||
| }, | ||
| { | ||
| name: "wildcard members are never probed", | ||
| err: errors.New("acme: internal error"), | ||
| domains: []string{"*.example.com", "a.example.com"}, | ||
| preflight: failAll, | ||
| expected: []string{"a.example.com"}, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| assert.Equal(t, tt.expected, identifyFailedDomains(tt.err, tt.domains, tt.preflight)) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.