Skip to content

Commit b1f9715

Browse files
committed
Look for the certificate in permanent storage before asking allow_domain
A lookup in permanent storage is cheap for us (because Redis), compared to firing a HTTP request to our backend to validate the domain.
1 parent 9d43c23 commit b1f9715

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

lib/resty/auto-ssl/ssl_certificate.lua

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,6 @@ local function get_cert_der(auto_ssl_instance, domain, ssl_options)
113113
}
114114
end
115115

116-
-- Check to ensure the domain is one we allow for handling SSL.
117-
--
118-
-- Note: We perform this after the memory lookup, so more costly
119-
-- "allow_domain" lookups can be avoided for cached certs. However, we will
120-
-- perform this before the storage lookup, since the storage lookup could
121-
-- also be more costly (or blocking in the case of the file storage adapter).
122-
-- We may want to consider caching the results of allow_domain lookups
123-
-- (including negative caching or disallowed domains).
124-
local allow_domain = auto_ssl_instance:get("allow_domain")
125-
if not allow_domain(domain, auto_ssl_instance, ssl_options, false) then
126-
return nil, "domain not allowed"
127-
end
128-
129116
-- Next, look for the certificate in permanent storage (which can be shared
130117
-- across servers depending on the storage).
131118
local storage = auto_ssl_instance.storage
@@ -140,6 +127,12 @@ local function get_cert_der(auto_ssl_instance, domain, ssl_options)
140127
return cert_der
141128
end
142129

130+
-- Check to ensure the domain is one we allow for handling SSL.
131+
local allow_domain = auto_ssl_instance:get("allow_domain")
132+
if not allow_domain(domain, auto_ssl_instance, ssl_options, false) then
133+
return nil, "domain not allowed"
134+
end
135+
143136
-- Finally, issue a new certificate if one hasn't been found yet.
144137
if not ssl_options or ssl_options["generate_certs"] ~= false then
145138
cert = issue_cert(auto_ssl_instance, storage, domain)

0 commit comments

Comments
 (0)