<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Authentication on OHTLY Blog</title>
    <link>https://blog.ohtly.com/tags/authentication/</link>
    <description>Recent content in Authentication on OHTLY Blog</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Thu, 25 Jun 2026 12:10:34 +0800</lastBuildDate>
    <atom:link href="https://blog.ohtly.com/tags/authentication/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>CouchDB 没有 API Key 以及解决办法</title>
      <link>https://blog.ohtly.com/posts/2026-06-25-couchdb-no-apikey/</link>
      <pubDate>Thu, 25 Jun 2026 12:10:34 +0800</pubDate>
      <guid>https://blog.ohtly.com/posts/2026-06-25-couchdb-no-apikey/</guid>
      <description>&lt;h2 id=&#34;问题&#34;&gt;&#xA;  问题&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#%e9%97%ae%e9%a2%98&#34;&gt;&#xA;    &lt;i class=&#34;fa-solid fa-link&#34; aria-hidden=&#34;true&#34; title=&#34;链接到标题&#34;&gt;&lt;/i&gt;&#xA;    &lt;span class=&#34;sr-only&#34;&gt;链接到标题&lt;/span&gt;&#xA;  &lt;/a&gt;&#xA;&lt;/h2&gt;&#xA;&lt;p&gt;需要给 CouchDB 创建一个凭证，让其他节点能拉取数据库做数据同步。最初想的是&amp;quot;API Key&amp;quot;——一个静态字符串，像大多数现代服务那样，拿来就能用在 &lt;code&gt;curl&lt;/code&gt; 或代码中。&lt;/p&gt;&#xA;&lt;h2 id=&#34;迷惑couchdb-有没有-api-key&#34;&gt;&#xA;  迷惑：CouchDB 有没有 API Key？&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#%e8%bf%b7%e6%83%91couchdb-%e6%9c%89%e6%b2%a1%e6%9c%89-api-key&#34;&gt;&#xA;    &lt;i class=&#34;fa-solid fa-link&#34; aria-hidden=&#34;true&#34; title=&#34;链接到标题&#34;&gt;&lt;/i&gt;&#xA;    &lt;span class=&#34;sr-only&#34;&gt;链接到标题&lt;/span&gt;&#xA;  &lt;/a&gt;&#xA;&lt;/h2&gt;&#xA;&lt;p&gt;很多人提到的 CouchDB &amp;ldquo;API Key&amp;rdquo; 其实来自 IBM Cloudant（托管的 CouchDB 兼容服务），它提供了 &lt;code&gt;POST /_api_keys&lt;/code&gt; 端点，返回一个 key 和 password。&lt;/p&gt;&#xA;&lt;p&gt;但原生 Apache CouchDB &lt;strong&gt;没有这个端点&lt;/strong&gt;。一个常见的误解是把通过 &lt;code&gt;_config/admins/&amp;lt;username&amp;gt;&lt;/code&gt; 创建的 server-level admin 当成了&amp;quot;API Key&amp;quot;——它有用户名和密码，需要 Basic Auth，本质上就是一个管理员账号。&lt;/p&gt;&#xA;&lt;h2 id=&#34;方案探索&#34;&gt;&#xA;  方案探索&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#%e6%96%b9%e6%a1%88%e6%8e%a2%e7%b4%a2&#34;&gt;&#xA;    &lt;i class=&#34;fa-solid fa-link&#34; aria-hidden=&#34;true&#34; title=&#34;链接到标题&#34;&gt;&lt;/i&gt;&#xA;    &lt;span class=&#34;sr-only&#34;&gt;链接到标题&lt;/span&gt;&#xA;  &lt;/a&gt;&#xA;&lt;/h2&gt;&#xA;&lt;h3 id=&#34;1-server-level-admin&#34;&gt;&#xA;  1. Server-level Admin&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#1-server-level-admin&#34;&gt;&#xA;    &lt;i class=&#34;fa-solid fa-link&#34; aria-hidden=&#34;true&#34; title=&#34;链接到标题&#34;&gt;&lt;/i&gt;&#xA;    &lt;span class=&#34;sr-only&#34;&gt;链接到标题&lt;/span&gt;&#xA;  &lt;/a&gt;&#xA;&lt;/h3&gt;&#xA;&lt;p&gt;通过 PUT &lt;code&gt;/_node/_local/_config/admins/sync_obsidian&lt;/code&gt; 在 &lt;code&gt;_config&lt;/code&gt; 中注册一个同步用账号。&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;优点：简单，CouchDB &lt;code&gt;_config&lt;/code&gt; API 一行命令搞定&lt;/li&gt;&#xA;&lt;li&gt;缺点：&lt;strong&gt;全局管理员权限&lt;/strong&gt;，对服务器上所有数据库有完全控制权，权限过宽。只能做数据同步，不应该有删库的权限&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;2-jwt-认证&#34;&gt;&#xA;  2. JWT 认证&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#2-jwt-%e8%ae%a4%e8%af%81&#34;&gt;&#xA;    &lt;i class=&#34;fa-solid fa-link&#34; aria-hidden=&#34;true&#34; title=&#34;链接到标题&#34;&gt;&lt;/i&gt;&#xA;    &lt;span class=&#34;sr-only&#34;&gt;链接到标题&lt;/span&gt;&#xA;  &lt;/a&gt;&#xA;&lt;/h3&gt;&#xA;&lt;p&gt;CouchDB 从 3.x 开始支持 JWT 认证，通过配置 &lt;code&gt;jwt_keys&lt;/code&gt; 和 &lt;code&gt;jwt_authentication_handler&lt;/code&gt; 启用。&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
