wxccs/tacacs

GitHub: wxccs/tacacs

一个生产级的纯 Go 语言 TACACS+ 协议套件库,完整实现了 AAA 机制及相关 IETF RFC 标准,附带互操作测试命令行工具。

Stars: 0 | Forks: 0

# tacacs [![Go Reference](https://pkg.go.dev/badge/github.com/wxccs/tacacs.svg)](https://pkg.go.dev/github.com/wxccs/tacacs) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE) 一个企业级的 TACACS+ 协议套件的 Go 实现。 `tacacs` 是一个纯 Go 库,实现了 IETF 发布的全套 TACACS 规范,并附带了一个用于互操作性测试的 `tacacs-cli` 命令行 工具: | RFC | 标题 | 角色 | |-----|-------|------| | [RFC 1492](https://www.rfc-editor.org/rfc/rfc1492) | An Access Control Protocol, Sometimes Called TACACS | 原始 TACACS (遗留) | | [RFC 8907](https://www.rfc-editor.org/rfc/rfc8907) | The TACACS+ Protocol | 基础协议 | | [RFC 9887](https://www.rfc-editor.org/rfc/rfc9887) | TACACS+ over TLS 1.3 | 安全传输 | | [RFC 9950](https://www.rfc-editor.org/rfc/rfc9950) | A YANG Data Model for TACACS+ | 配置模型 | ## 功能 - 根据 RFC 8907 实现的身份验证(ASCII、PAP、CHAP、MS-CHAP、MS-CHAPv2)、授权和 计费(start / stop / watchdog)。 - 基于 MD5 的 body 混淆(RFC 8907 §4.5)和 TLS 1.3 传输(RFC 9887), 后者使得在 TLS 上的混淆变得多余。 - 与 YANG 对齐的配置模型(RFC 9950),可通过 YAML 和 JSON 加载。 - 原始 TACACS 协议(RFC 1492),支持其 TCP (ASCII) 和 UDP (simple / extended) 编码。 - 零依赖的核心库,支持注入 logger;`tacacs-cli` 使用了 [cobra](https://github.com/spf13/cobra) 和 [viper](https://github.com/spf13/viper)。 ## 安装说明 ``` go get github.com/wxccs/tacacs ``` 需要 Go 1.26 或更高版本。 ## 快速开始 ### 客户端 ``` import ( "context" "github.com/wxccs/tacacs/client" "github.com/wxccs/tacacs/transport" "github.com/wxccs/tacacs/types" ) func authenticate() error { conn, err := transport.Dial(context.Background(), "tcp", "tacacs.example.com:49", []byte("sharedsecret")) if err != nil { return err } defer conn.Close() c, err := client.New(conn) if err != nil { return err } reply, err := c.Authenticate(context.Background(), client.AuthenRequest{ Action: types.AuthenLogin, Type: types.AuthenTypePAP, Service: types.AuthenServiceLogin, User: "alice", Data: []byte("password"), }, nil) if err != nil { return err } // reply.Status == types.AuthenStatusPass on success. return nil } ``` 对于 TLS 1.3 (RFC 9887),请使用带有 `transport.TLSConfig` 的 `transport.DialTLS` 来代替 `transport.Dial`。 ### 服务端 实现 `server.Handler` 接口并处理连接: ``` import ( "context" "github.com/wxccs/tacacs/server" "github.com/wxccs/tacacs/transport" "github.com/wxccs/tacacs/types" ) type myHandler struct{} func (myHandler) Authenticate(ctx context.Context, ac server.AuthenContext, cont *server.AuthenContinue) (server.AuthenDecision, error) { // ...verify credentials... return server.AuthenDecision{Status: types.AuthenStatusPass}, nil } func (myHandler) Authorize(ctx context.Context, ac server.AuthorContext) (server.AuthorDecision, error) { return server.AuthenDecision{Status: types.AuthorStatusPassAdd}, nil } func (myHandler) Account(ctx context.Context, ac server.AcctContext) (server.AcctDecision, error) { return server.AcctDecision{Status: types.AcctStatusSuccess}, nil } // ln is a net.Listener (use transport.ListenTLS for TLS 1.3). srv := server.New(server.Config{Handler: myHandler{}, Secret: []byte("sharedsecret"), Mode: transport.ModeLegacy}) for { c, _ := ln.Accept() conn := transport.Accept(c, transport.ModeLegacy, []byte("sharedsecret")) go srv.ServeConn(context.Background(), conn) } ``` ### 配置 (RFC 9950) 从 YAML 或 JSON 加载服务器列表: ``` import "github.com/wxccs/tacacs/yang" cfg, err := yang.Load("tacacs.yaml") // cfg.Servers is the unified, ordered server list. ``` 请参阅 [`docs/examples/`](./docs/examples) 获取与 RFC 9950 附录中相匹配的 shared-secret 和 TLS 示例 配置。 ### 命令行工具 ``` # 运行测试服务器 tacacs-cli server --listen 127.0.0.1 --port 49 --secret testkey # 认证 (client) tacacs-cli auth --server 127.0.0.1 --port 49 --secret testkey \ --username admin --password admin123 --type pap --output json # 授权命令 tacacs-cli authz --server 127.0.0.1 --port 49 --secret testkey \ --username admin --service shell --cmd "show version" # Accounting tacacs-cli acct --server 127.0.0.1 --port 49 --secret testkey \ --username admin --action start ``` 对于底层数据包的构造和检查,可以直接使用 `packet`、`crypto`、 `types` 和 `errors` 包。 ## 项目结构 ``` . ├── errors/ typed sentinel errors ├── types/ protocol constants, Logger interface, argument codec ├── packet/ header and body marshalling (RFC 8907) ├── crypto/ MD5 pseudo-pad obfuscation (RFC 8907 §4.5) ├── protocol/ authentication/authorization/accounting state machines ├── transport/ TCP and TLS 1.3 transports (RFC 9887) ├── yang/ RFC 9950 configuration model ├── client/ high-level client API ├── server/ server-side handlers ├── legacy/ RFC 1492 original TACACS ├── cmd/tacacs-cli/ command-line tool └── docs/rfc/ source RFC texts ``` ## 开发 ``` make tidy # go mod tidy make fmt # gofmt make vet # go vet make test # unit + integration tests make cover # coverage report (target >= 90%) ``` 请参阅 [CONTRIBUTING.md](./CONTRIBUTING.md) 了解代码和日志记录规范。 ## 许可证 Copyright (c) 2026 Daniel Wu 本库基于 MIT 许可证授权。请参阅 [LICENSE](./LICENSE) 获取 完整文本。 第三方依赖及其许可条款记录在 [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md) 中。
标签:Docker 部署, EVTX分析, Go, Homebrew安装, Ruby工具, TACACS+, 内核驱动, 日志审计, 网络协议, 网络运维