CAA DNS 憑證授權記錄設定

CAA DNS Certificate Authority Authorization

CAA 記錄概述

CAA(Certificate Authority Authorization)是一種 DNS 記錄類型,用於指定哪些憑證頒發機構(CA)被授權為特定網域發行 SSL/TLS 憑證。透過設定 CAA 記錄,網域擁有者可以有效防止未經授權的 CA 為其網域發行憑證,從而提高網站的安全性。

CAA 記錄於 2013 年在 RFC 6844 中首次定義,並於 2017 年 9 月起成為所有公開信任的 CA 必須遵守的強制性規範。這意味著在發行憑證之前,CA 必須檢查網域的 CAA 記錄,並確認自己被列入授權清單中。

CAA 記錄的優點

  • 防止錯誤發行:限制能夠為網域發行憑證的 CA,降低憑證被錯誤發行的風險
  • 增強安全性:作為額外的安全層,防止攻擊者透過未授權的 CA 取得憑證
  • 事件通報:可設定 iodef 標籤,當有 CA 嘗試違規發行憑證時接收通知
  • 支援萬用字元控制:可分別控制一般憑證和萬用字元憑證的發行權限

CAA 記錄語法

CAA 記錄的基本格式如下:

1
<domain> CAA <flags> <tag> <value>

各欄位說明:

欄位說明
domain要設定的網域名稱
flags標誌值,通常為 0,若設為 128 表示關鍵標籤
tag標籤類型,可為 issue、issuewild 或 iodef
value標籤對應的值,通常是 CA 的網域名稱

Flags 標誌值

  • 0:標準標籤,CA 若不認識此標籤可忽略
  • 128:關鍵標籤(Critical),CA 若不認識此標籤必須拒絕發行憑證

issue 標籤

issue 標籤用於指定被授權發行一般 SSL/TLS 憑證的 CA。

1
2
example.com.  CAA  0  issue  "letsencrypt.org"
example.com.  CAA  0  issue  "digicert.com"

上述設定表示只有 Let’s Encrypt 和 DigiCert 被授權為 example.com 發行憑證。

禁止所有 CA 發行憑證

若要禁止所有 CA 為網域發行憑證,可使用空字串:

1
example.com.  CAA  0  issue  ";"

帶參數的 issue 標籤

部分 CA 支援額外的參數,例如限制特定帳戶:

1
example.com.  CAA  0  issue  "letsencrypt.org; accounturi=https://acme-v02.api.letsencrypt.org/acme/acct/123456"

issuewild 標籤

issuewild 標籤專門用於控制萬用字元憑證(Wildcard Certificate)的發行權限。萬用字元憑證使用 *.example.com 格式,可以涵蓋一個網域下的所有子網域。

1
example.com.  CAA  0  issuewild  "digicert.com"

issue 與 issuewild 的關係

  • 若只設定 issue,則該設定同時適用於一般憑證和萬用字元憑證
  • 若同時設定 issueissuewild,則萬用字元憑證只遵循 issuewild 的設定
  • 若只設定 issuewild,則一般憑證不受限制

禁止發行萬用字元憑證

1
2
example.com.  CAA  0  issue      "letsencrypt.org"
example.com.  CAA  0  issuewild  ";"

上述設定允許 Let’s Encrypt 發行一般憑證,但禁止任何 CA 發行萬用字元憑證。

iodef 標籤

iodef(Incident Object Description Exchange Format)標籤用於設定安全事件通報的聯絡方式。當 CA 收到違反 CAA 政策的憑證申請時,可透過此管道通知網域擁有者。

支援的通知方式:

  • Email:使用 mailto: 格式
  • HTTPS:使用 https: URL 格式
1
2
example.com.  CAA  0  iodef  "mailto:security@example.com"
example.com.  CAA  0  iodef  "https://example.com/caa-report"

請注意,並非所有 CA 都支援 iodef 通報功能,但設定此標籤仍是良好的安全實踐。

常見 CA 的 CAA 值

以下是常見憑證頒發機構的 CAA 設定值:

憑證頒發機構CAA 值
Let’s Encryptletsencrypt.org
DigiCertdigicert.com
Comodo/Sectigocomodoca.comsectigo.com
GlobalSignglobalsign.com
GoDaddygodaddy.com
Amazon (AWS)amazon.comamazontrust.com
Google Trust Servicespki.goog
Cloudflarecloudflare.comdigicert.com
ZeroSSLsectigo.com
Buypassbuypass.com

DNS 設定範例

範例一:只允許 Let’s Encrypt

1
2
3
; 只允許 Let's Encrypt 發行所有類型的憑證
example.com.  IN  CAA  0  issue      "letsencrypt.org"
example.com.  IN  CAA  0  iodef      "mailto:admin@example.com"

範例二:多個 CA 授權

1
2
3
4
5
; 允許多個 CA 發行憑證
example.com.  IN  CAA  0  issue      "letsencrypt.org"
example.com.  IN  CAA  0  issue      "digicert.com"
example.com.  IN  CAA  0  issue      "sectigo.com"
example.com.  IN  CAA  0  iodef      "mailto:security@example.com"

範例三:分開控制一般與萬用字元憑證

1
2
3
4
5
; Let's Encrypt 可發行一般憑證
; DigiCert 可發行萬用字元憑證
example.com.  IN  CAA  0  issue      "letsencrypt.org"
example.com.  IN  CAA  0  issuewild  "digicert.com"
example.com.  IN  CAA  0  iodef      "mailto:ssl-team@example.com"

範例四:禁止所有憑證發行

1
2
; 完全禁止為此網域發行任何憑證
internal.example.com.  IN  CAA  0  issue  ";"

範例五:AWS 與 Let’s Encrypt 混合使用

1
2
3
4
5
6
; 適用於使用 AWS Certificate Manager 和 Let's Encrypt 的環境
example.com.  IN  CAA  0  issue      "amazon.com"
example.com.  IN  CAA  0  issue      "amazontrust.com"
example.com.  IN  CAA  0  issue      "letsencrypt.org"
example.com.  IN  CAA  0  issuewild  "amazon.com"
example.com.  IN  CAA  0  iodef      "mailto:devops@example.com"

範例六:子網域繼承

CAA 記錄具有繼承特性,子網域會繼承父網域的 CAA 設定,除非子網域有自己的 CAA 記錄。

1
2
3
4
5
; 父網域設定
example.com.      IN  CAA  0  issue  "letsencrypt.org"

; 子網域覆蓋父網域設定
api.example.com.  IN  CAA  0  issue  "digicert.com"

驗證 CAA 設定

設定完成後,務必驗證 CAA 記錄是否正確生效。

使用 dig 命令

1
2
3
4
5
6
7
8
# 查詢 CAA 記錄
dig example.com CAA

# 查詢特定 DNS 伺服器
dig @8.8.8.8 example.com CAA

# 簡潔輸出
dig +short example.com CAA

使用 nslookup 命令

1
nslookup -type=CAA example.com

使用 host 命令

1
host -t CAA example.com

線上驗證工具

常見錯誤

1. 忘記加入所有使用中的 CA

錯誤的設定可能導致憑證續期失敗:

1
2
3
; 錯誤:忘記加入正在使用的 CA
example.com.  IN  CAA  0  issue  "digicert.com"
; 若目前使用 Let's Encrypt,上述設定會導致續期失敗

2. 語法錯誤

1
2
3
4
5
; 錯誤:value 值未加引號
example.com.  IN  CAA  0  issue  letsencrypt.org

; 正確:value 值需要引號
example.com.  IN  CAA  0  issue  "letsencrypt.org"

3. 使用錯誤的 CA 識別碼

1
2
3
4
5
; 錯誤:使用完整 URL
example.com.  IN  CAA  0  issue  "https://letsencrypt.org"

; 正確:只使用網域名稱
example.com.  IN  CAA  0  issue  "letsencrypt.org"

4. 忽略萬用字元憑證的設定

1
2
3
4
5
6
; 問題:只設定 issue,會同時允許萬用字元憑證
example.com.  IN  CAA  0  issue  "letsencrypt.org"

; 若要禁止萬用字元,需明確設定
example.com.  IN  CAA  0  issue      "letsencrypt.org"
example.com.  IN  CAA  0  issuewild  ";"

5. DNS 傳播延遲

CAA 記錄變更後需要等待 DNS 傳播,建議:

  • 降低 TTL 值以加快傳播速度
  • 等待至少 24-48 小時後再申請新憑證
  • 使用多個 DNS 查詢工具確認記錄已生效

參考資料

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy