Lua-resty-auto-ssl: allow_domain 호좜 λΉˆλ„

에 λ§Œλ“  2017λ…„ 10μ›” 06일  Β·  6μ½”λ©˜νŠΈ  Β·  좜처: auto-ssl/lua-resty-auto-ssl

도메인 μœ νš¨μ„± 검사λ₯Ό μˆ˜ν–‰ν•˜κΈ° μœ„ν•΄ μ›Ή μ„œλΉ„μŠ€λ₯Ό κ΅¬ν˜„ν–ˆμŠ΅λ‹ˆλ‹€. μš°λ¦¬κ°€ κΆκΈˆν•œ 것은 allow_domain λ©”μ†Œλ“œμ—μ„œ μ›Ή μš”μ²­μ„ λ°œν–‰ν•  λ•Œμ˜ μ„±λŠ₯ 영ν–₯μž…λ‹ˆλ‹€. λ˜ν•œ 이 λ©”μ†Œλ“œλŠ” μ–Όλ§ˆλ‚˜ 자주 ν˜ΈμΆœλ©λ‹ˆκΉŒ? Let's Encrypt μ‹œν€€μŠ€ μ§μ „μ—λ§Œ ν˜ΈμΆœλ©λ‹ˆκΉŒ?

allow_domain λ₯Ό ν˜ΈμΆœν•  ν•„μš”κ°€ μ—†λŠ” μ €μž₯μ†Œμ— 도메인에 λŒ€ν•œ μΈμ¦μ„œκ°€ μžˆλŠ” κ²ƒμ²˜λŸΌ 보일 κ²ƒμž…λ‹ˆλ‹€.

μ•„λ§ˆλ„ μ΄λŸ¬ν•œ μœ ν˜•μ˜ μ„€λͺ…이 λ¬Έμ„œμ—μ„œ 더 μœ μš©ν•  κ²ƒμž…λ‹ˆλ‹€.

κ°μ‚¬ν•©λ‹ˆλ‹€.

λͺ¨λ“  6 λŒ“κΈ€

μΈμ¦μ„œκ°€ μžˆλŠ”μ§€ μ—¬λΆ€λ₯Ό ν˜ΈμΆœν•©λ‹ˆλ‹€. 개인적으둜 μ €λŠ” λ°±μ—”λ“œμ— μƒˆ μΈμ¦μ„œλ₯Ό 생성해도 λ˜λŠ”μ§€ 묻기 전에 이미 μΈμ¦μ„œκ°€ μžˆλŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€.

-- first check if we have the certificate already, else check with backend if we allow it 
    local certstorage = auto_ssl:get("storage")

    local fullchain_pem, privkey_pem = certstorage:get_cert(domain)
    if fullchain_pem then
      return true
    else ...

μ˜€λ²„ν—€λ“œ/μ„±λŠ₯ 영ν–₯에 λŒ€ν•΄μ„œλ„ μ•½κ°„ μš°λ €ν•˜κ³  μžˆμ§€λ§Œ 아직 κ³„νš 단계에 있으며 μ•„μ§κΉŒμ§€λŠ” λ‹¬μ„±ν•˜μ§€ λͺ»ν–ˆμŠ΅λ‹ˆλ‹€.

@brianlund 곡유 lua_shared_dict λ₯Ό κ΅¬ν˜„ν–ˆμŠ΅λ‹ˆλ‹€.

    auto_ssl:set("allow_domain", function(domain)
      local http = require "resty.http"
      local httpc = http.new()
      local cjson = require "cjson"
      local our_allow_domain_cache = ngx.shared.our_allow_domain_cache

      local found = our_allow_domain_cache:get(domain)

      if found == nil then
        local res, err = httpc:request_uri("[is domain allowed web service]"..domain, {
          method = "GET",
        })

        if not res then
          found = false
        else
          local data = cjson.decode(res.body)
          found = data.found
        end

        -- Cache for 60 seconds, for now...
        our_allow_domain_cache:set(domain, found, 60)
      else
        if found then
          -- Known good domain, keep it in cache for a little longer
          our_allow_domain_cache:set(domain, found, 300)
        end
      end

auto_ssl:get("storage") μ„œλΉ„μŠ€λ₯Ό ν™•μΈν•˜λŠ” λ‹Ήμ‹ μ˜ 아이디어가 정말 λ§ˆμŒμ— λ“­λ‹ˆλ‹€. λ‚˜λŠ” λΉ„μŠ·ν•œ 것을 가지고 갈 수 μžˆμŠ΅λ‹ˆλ‹€. 이것이 λͺ¨λ“  μš”μ²­μ—μ„œ λ°œμƒν•œλ‹€κ³  κ°€μ •ν•  수 μžˆμŠ΅λ‹ˆκΉŒ? μ•„λ‹ˆλ©΄ lua_shared_dict auto_ssl κ°€ μ €μž₯용 캐싱 λ ˆμ΄μ–΄λ‘œ μ‚¬μš©λ˜κ³  μžˆμŠ΅λ‹ˆκΉŒ? λ‹€μŒκ³Ό 같을 수 μžˆμŠ΅λ‹ˆλ‹€. https://github.com/GUI/lua-resty-auto-ssl/blob/master/lib/resty/auto-ssl/ssl_certificate.lua#L20

κ·€ν•˜μ˜ μ˜ˆμ—μ„œ λ‹€μŒμ„ ν™•μΈν•˜λŠ” 것이 더 λ‚˜μ€μ§€ κΆκΈˆν•©λ‹ˆλ‹€.
ngx.shared.auto_ssl:get("domain:fullchain_der:" .. domain) λŒ€ storage 직접 호좜.

ngx.shared.auto_ssl:get("domain:fullchain_der:" .. domain) λŠ” 곡유 λ©”λͺ¨λ¦¬ μΊμ‹œλ§Œ ν™•μΈν•©λ‹ˆλ‹€. μ—¬λŸ¬ λ…Έλ“œλ₯Ό μ‹€ν–‰ν•  κ³„νšμ΄λ―€λ‘œ λ…Έλ“œ 간에 κ³΅μœ ν•  수 μžˆλŠ” ν•­λͺ©(redis μŠ€ν† λ¦¬μ§€)이 ν•„μš”ν•©λ‹ˆλ‹€. ν•˜μ§€λ§Œ μΊμ‹œ μ†”λ£¨μ…˜μ΄ λ§ˆμŒμ— λ“­λ‹ˆλ‹€. μŠ€ν† λ¦¬μ§€ μ„œλΉ„μŠ€μ— λŒ€ν•œ λ§Žμ€ ν˜ΈμΆœμ„ μ ˆμ•½ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 자주 ν˜ΈμΆœν•˜λŠ” 데 λ¬Έμ œκ°€ μžˆλŠ” 경우 이λ₯Ό 염두에 λ‘κ² μŠ΅λ‹ˆλ‹€.

데λͺ¨ μ½”λ“œλ₯Ό μ œκ³΅ν•΄ μ£Όμ‹  μ „ν•˜κ³  μ‹ΆμŠ΅λ‹ˆλ‹€. 이것은 μ €μ—κ²Œ 맀우 μœ μš©ν•œ ꡬ성 μš”μ†Œμ˜€μŠ΅λ‹ˆλ‹€! κ°μ‚¬ν•©λ‹ˆλ‹€!

이것이 λͺ¨λ“  μš”μ²­μ—μ„œ λ°œμƒν•œλ‹€κ³  κ°€μ •ν•  수 μžˆμŠ΅λ‹ˆκΉŒ?

이것은 정말 쒋은 μ§ˆλ¬Έμž…λ‹ˆλ‹€.

λ‚΄ 가정은 이 λ©”μ„œλ“œκ°€ 도메인에 λŒ€ν•œ μΈμ¦μ„œκ°€ 없을 λ•Œ ν˜ΈμΆœλ˜μ§€λ§Œ ν™•μ‹€ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.
@jasonbouffard 확인

@Alir3z4

저도 이게 κΆκΈˆν–ˆμŠ΅λ‹ˆλ‹€.
λ¬Έμ„œλŠ” 이에 λŒ€ν•΄ 투λͺ…ν•˜μ§€ μ•ŠμœΌλ―€λ‘œ μ†ŒμŠ€ μ½”λ“œλ₯Ό 검사해야 ν–ˆμŠ΅λ‹ˆλ‹€.

λ”°λΌμ„œ λͺ¨λ“  μš”μ²­μ—μ„œ auto-ssl은 λ‹€μŒμ„ μˆ˜ν–‰ν•©λ‹ˆλ‹€.

  • 1μ‹œκ°„ λ™μ•ˆ μΊμ‹œλœ ngx.shared.auto_ssl μ‚¬μ „μ—μ„œ μΈμ¦μ„œλ₯Ό κ°€μ Έμ˜€λ €κ³  ν•©λ‹ˆλ‹€.
  • μ‚¬μš©μž μ •μ˜ allow_domain λ©”μ†Œλ“œ 호좜
  • μ €μž₯μ†Œμ—μ„œ μΈμ¦μ„œλ₯Ό κ°€μ Έμ˜€λ €κ³  ν•©λ‹ˆλ‹€.
  • μƒˆ μΈμ¦μ„œλ₯Ό μƒμ„±ν•©λ‹ˆλ‹€

README.mdμ—μ„œ 이것을 μ„€λͺ…ν•˜λŠ” 것이 μ™„λ²½ν•  κ²ƒμž…λ‹ˆλ‹€.
감사 ν•΄μš”!

좜처:

https://github.com/auto-ssl/lua-resty-auto-ssl/blob/86d3c94807ad1585b464fad2d4defb379f9c152a/lib/resty/auto-ssl/ssl_certificate.lua#L104 -L157

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰