項目標題與描述
Authelia是一個開源的認證和授權服務器,專注于為應用程序提供雙因素認證(2FA)和單點登錄(SSO)功能。通過Web門戶,Authelia能夠作為身份和訪問管理(IAM)系統,確保應用程序的安全性。項目支持OpenID Connect 1.0協議,并已通過OpenID認證,具備廣泛的集成能力。
功能特性
- 雙因素認證:支持TOTP、WebAuthn等多種雙因素認證方式,提升賬戶安全性。
- 單點登錄:提供統一的登錄門戶,簡化用戶訪問多個應用的流程。
- OpenID Connect提供者:作為認證提供者,支持與第三方應用集成。
- 靈活的訪問控制:基于規則策略,支持按域名、資源、網絡等條件進行細粒度授權。
- 多后端支持:支持LDAP、文件等多種用戶存儲后端,適應不同環境需求。
- 高度可配置:通過YAML配置文件,可自定義認證策略、密碼策略等。
安裝指南
系統要求
- Linux/FreeBSD系統(macOS目前不支持開發工作流)
- Go 1.18+
- Node.js和pnpm(用于前端構建)
- Docker和Docker Compose(用于容器化部署)
安裝步驟
-
克隆項目倉庫:
git clone https://github.com/authelia/authelia.git cd authelia
-
運行引導腳本以安裝依賴:
./bootstrap.sh
-
構建項目:
authelia-scripts build
-
使用Docker構建鏡像:
authelia-scripts docker build
依賴項
- 后端:Go模塊依賴(詳見
go.mod
) - 前端:Node.js和pnpm(依賴項在
web/package.json
中定義)
使用說明
基本配置
Authelia通過YAML文件進行配置。以下是一個最小配置示例:
server:host: 0.0.0.0port: 9091authentication_backend:file:path: /config/users_database.ymlaccess_control:default_policy: denyrules:- domain: "secure.example.com"policy: two_factor
啟動服務
使用以下命令啟動Authelia服務:
authelia --config /path/to/configuration.yml
API使用
Authelia提供RESTful API用于集成。例如,檢查用戶權限:
curl -X POST https://auth.example.com/api/verify \-H "Content-Type: application/json" \-d '{"username": "user", "password": "pass"}'
核心代碼
主入口點
主函數初始化并執行根命令:
package mainimport ("os""github.com/authelia/authelia/v4/internal/commands"
)func main() {if err := commands.NewRootCmd().Execute(); err != nil {os.Exit(1)}
}
認證提供者接口
定義用戶提供者的核心接口:
package authenticationtype UserProvider interface {CheckUserPassword(username string, password string) (valid bool, err error)GetDetails(username string) (details *UserDetails, err error)UpdatePassword(username string, newPassword string) (err error)Close() (err error)
}
訪問控制規則
實現基于規則的訪問控制邏輯:
package authorizationtype AccessControlRule struct {Domains []AccessControlDomainResources []AccessControlResourcePolicy Level
}func (acr *AccessControlRule) IsMatch(subject Subject, object Object) (match bool) {if !acr.MatchesDomains(subject, object) {return false}// 其他匹配邏輯...return true
}
更多精彩內容 請關注我的個人公眾號 公眾號(辦公AI智能小助手)
公眾號二維碼