open-policy-agent/regal

GitHub: open-policy-agent/regal

Regal 是 Rego 策略的代码检查与语言服务器,帮助开发者提升策略质量与开发效率。

Stars: 372 | Forks: 53

# Regal [![Build Status](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/f38c990f6f211449.svg)](https://github.com/open-policy-agent/regal/actions) ![OPA v1.15.2](https://www.openpolicyagent.org/badge/v1.15.2) [![codecov](https://codecov.io/github/open-policy-agent/regal/graph/badge.svg?token=EQK01YF3X3)](https://codecov.io/github/StyraInc/regal) [![Downloads](https://img.shields.io/github/downloads/open-policy-agent/regal/total.svg)](https://github.com/open-policy-agent/regal/releases) Regal 是一款用于 [Rego](https://www.openpolicyagent.org/docs/policy-language/) 的代码检查器、调试器和语言服务器, 让你的 Rego 变得出色,让你成为规则的掌控者! 凭借其丰富的代码检查规则、文档和编辑器集成,Regal 是策略开发的完美伴侣, 无论你是经验丰富的 Rego 开发者,还是刚刚入门。 illustration of a viking representing the Regal logo \- [Merriam Webster](https://www.merriam-webster.com/dictionary/regal) ## Goals - 通过提供最佳工具来提供卓越的策略开发体验 - 识别 Rego 策略中的常见错误、漏洞和低效问题,并提出更好的解决方案 - 提供关于 [最佳实践](https://www.openpolicyagent.org/docs/style-guide)、编码风格和工具的建议 - 允许用户、团队和组织在其策略代码中强制执行自定义规则 ## What People Say About Regal — Leonardo Taccari, [NetBSD](https://www.netbsd.org/) — Dima Korolev, [Miro](https://miro.com/) — Shawn McGuire, [Atlassian](https://www.atlassian.com/) — Jimmy Ray, [Boeing](https://www.boeing.com/) 请参阅 [adopters](https://www.openpolicyagent.org/projects/regal/adopters) 文件以获取更多 Regal 用户。 ## Getting Started ### Download Regal ``` # macOS brew install regal # linux x86 curl -L -o regal https://github.com/open-policy-agent/regal/releases/latest/download/regal_Linux_x86_64 chmod 755 ./regal # windows Invoke-WebRequest -Uri "https://github.com/open-policy-agent/regal/releases/latest/download/regal_Windows_x86_64.exe" -OutFile "regal.exe" ```
Other Installation Options & Packages 手动安装命令: **MacOS (Apple Silicon)** ``` curl -L -o regal "https://github.com/open-policy-agent/regal/releases/latest/download/regal_Darwin_arm64" ``` **MacOS (x86_64)** ``` curl -L -o regal "https://github.com/open-policy-agent/regal/releases/latest/download/regal_Darwin_x86_64" ``` **Linux (arm64)** ``` curl -L -o regal "https://github.com/open-policy-agent/regal/releases/latest/download/regal_Linux_arm64" chmod 755 ./regal ``` **Docker** ``` docker pull ghcr.io/open-policy-agent/regal:latest ``` 请参见 [Packages](https://www.openpolicyagent.org/projects/regal/adopters#packaging) 以获取分发 Regal 的软件包仓库列表。 查看所有版本和校验文件,请访问 Regal [releases](https://github.com/open-policy-agent/regal/releases/) 页面,以及发布的 Docker 镜像,请访问 [packages](https://github.com/open-policy-agent/regal/pkgs/container/regal) 页面。
### Try it out! 首先,编写一些 Rego! ``` package authz default allow = false allow if { isEmployee "developer" in input.user.roles } isEmployee if regex.match("@acmecorp\\.com$", input.user.email) ``` 接下来,运行 `regal lint` 指向一个或多个文件或目录,以对它们进行代码检查。 ``` regal lint policy/ ``` ``` Rule: non-raw-regex-pattern Description: Use raw strings for regex patterns Category: idiomatic Location: policy/authz.rego:12:27 Text: isEmployee if regex.match("@acmecorp\\.com$", input.user.email) Documentation: https://www.openpolicyagent.org/projects/regal/rules/idiomatic/non-raw-regex-pattern Rule: use-assignment-operator Description: Prefer := over = for assignment Category: style Location: policy/authz.rego:5:1 Text: default allow = false Documentation: https://www.openpolicyagent.org/projects/regal/rules/style/use-assignment-operator Rule: prefer-snake-case Description: Prefer snake_case for names Category: style Location: policy/authz.rego:12:1 Text: isEmployee if regex.match("@acmecorp\\.com$", input.user.email) Documentation: https://www.openpolicyagent.org/projects/regal/rules/style/prefer-snake-case 1 file linted. 3 violations found. ```
### 在编辑器中使用 Regal 从命令行进行代码检查是开始使用 Regal 的好方法,即使对于一些有经验的开发者来说, 这也是使用代码检查器的首选方式。然而,Regal 不仅仅是一个代码检查器,还是一个完整的 Rego 开发伴侣! 将 Regal 集成到您喜爱的编辑器中,意味着您将在编写策略时获得即时的代码检查反馈。 不仅如此,它还将解锁一整套利用 Regal 的 [语言服务器](https://www.openpolicyagent.org/projects/regal/language-server) 的功能, 例如上下文感知的代码补全建议、悬停时显示的信息提示, 或转到定义。 在 VS Code、Neovim、Zed、Helix 等编辑器中使用 Regal 提升您的策略开发体验! 要了解 Regal 语言服务器提供的功能,请参见 [语言服务器](https://www.openpolicyagent.org/projects/regal/language-server) 页面。 ### 在构建流水线中使用 Regal 为了确保您的项目中一致地执行 Regal 的规则, 我们已使其易于在构建中运行 Regal。 请参见有关 [在构建流水线中使用 Regal](https://www.openpolicyagent.org/projects/regal/cicd) 的文档,以了解如何设置 Regal 以对每次提交或拉取请求的策略进行代码检查。 ## Next Steps 现在您已经启动并运行了 Regal,请查看我们的 文档以了解 Regal 的不同功能和特性。 - [Rules](https://www.openpolicyagent.org/projects/regal/rules) - [Bugs](https://www.openpolicyagent.org/projects/regal/rules/bugs):常见错误、潜在漏洞和低效的 Rego 策略。 - [Idiomatic](https://www.openpolicyagent.org/projects/regal/rules/idiomatic):更惯用的构造建议。 - [Imports](https://www.openpolicyagent.org/projects/regal/rules/imports):导入的最佳实践。 - [Performance](https://www.openpolicyagent.org/projects/regal/rules/performance):提升策略性能的规则。 - [Style](https://www.openpolicyagent.org/projects/regal/rules/style):Rego 风格指南规则。 - [Testing](https://www.openpolicyagent.org/projects/regal/rules/testing):测试和开发的规则。 - [Custom](https://www.openpolicyagent.org/projects/regal/rules/custom):可调整强制执行以匹配您偏好的自定义规则。 - [Configuration](https://www.openpolicyagent.org/projects/regal/configuration):深入了解各种配置选项。 - [Editor Support](https://www.openpolicyagent.org/projects/regal/editor-support):将 Regal 集成到您选择的编辑器中。 - [Language Server](https://www.openpolicyagent.org/projects/regal/language-server):了解有关 Regal 的高级编辑器功能的更多信息。 - [DAP](https://www.openpolicyagent.org/projects/regal/debug-adapter):使用 Regal 的 DAP 支持实时调试 Rego 策略。 - [Fixing Issues](https://www.openpolicyagent.org/projects/regal/fixing):查看 Regal 如何自动修复 Rego 策略中的问题。 - [CI/CD](https://www.openpolicyagent.org/projects/regal/cicd):将 Regal 作为自动化检查的一部分运行。 - [Custom Rules](https://www.openpolicyagent.org/projects/regal/custom-rules):学习如何为 Regal 编写自己的规则。 - [Adopters](https://www.openpolicyagent.org/projects/regal/adopters):查看其他使用 Regal 的用户。 ## Learn More ### Documentation 请参见 [Regal 的文档网站](https://www.openpolicyagent.org/projects/regal) 以获取 Regal 的 官方文档。 [Contributing](https://github.com/open-policy-agent/regal/blob/main/docs/CONTRIBUTING.md) 包含有关如何修改 Regal 本身的信息。 ### Talks - [OPA Maintainer Track, featuring Regal](https://www.youtube.com/watch?v=XtA-NKoJDaI),KubeCon London,2025 - [Regal the Rego Linter](https://www.youtube.com/watch?v=Xx8npd2TQJ0&t=2567s),CNCF London meetup,2023 年 6 月 [![Regal the Rego Linter](/docs/assets/regal_cncf_london.png)](https://www.youtube.com/watch?v=Xx8npd2TQJ0&t=2567s) ### Blogs and Articles - [Guarding the Guardrails - Introducing Regal the Rego Linter](https://www.styra.com/blog/guarding-the-guardrails-introducing-regal-the-rego-linter/) by Anders Eknert ([@anderseknert](https://github.com/anderseknert)) - [Scaling Open Source Community by Getting Closer to Users](https://thenewstack.io/scaling-open-source-community-by-getting-closer-to-users/) by Charlie Egan ([@charlieegan3](https://github.com/charlieegan3)) - [Renovating Rego](https://www.styra.com/blog/renovating-rego/) by Anders Eknert ([@anderseknert](https://github.com/anderseknert)) - [Linting Rego with... Rego!](https://www.styra.com/blog/linting-rego-with-rego/) by Anders Eknert ([@anderseknert](https://github.com/anderseknert)) - [Regal: Rego(OPA)用リンタの導入手順](https://zenn.dev/erueru_tech/articles/6cfb886d92858a) by Jun Fujita ([@erueru-techhttps://github.com/erueru-tech)) - [Regal を使って Rego を Lint する](https://tech.dentsusoken.com/entry/2024/12/05/Regal_%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6_Rego_%E3%82%92_Lint_%E3%81%99%E3%82%8B) by Shibata Takao ([@shibata.takao](https://shodo.ink/@shibata.takao/)) ## Status Regal 目前处于测试阶段。终端用户不应期望有重大变更,但任何 API 都可能在不通知的情况下更改。 如果您想将 Regal 嵌入到另一个项目或产品中,请联系我们! ## Roadmap 当前的 Roadmap 事项全部与准备 [Regal 1.0](https://github.com/open-policy-agent/regal/issues/979) 有关: - [ ] [Go API: Refactor the Location object in Violation (#1554)](https://github.com/open-policy-agent/regal/issues/1554) - [ ] [Rego API: Provide a stable and well-documented Rego API (#1555)](https://github.com/open-policy-agent/regal/issues/1555) - [ ] [Go API: Audit and reduce the public Go API surface (#1556)](https://github.com/open-policy-agent/regal/issues/1556) - [ ] [Custom Rules: Tighten up Authoring experience (#1559)](https://github.com/open-policy-agent/regal/issues/1559) - [x] [docs: Improve automated documentation generation (#1557)](https://github.com/open-policy-agent/regal/issues/1557) - [x] [docs: Break down README into smaller units (#1558)](https://github.com/open-policy-agent/regal/issues/1558) - [ ] [lsp: Support a JetBrains LSP client (#1560)](https://github.com/open-policy-agent/regal/issues/1560) 如果您有想要添加到路线图的内容,请通过打开问题或在社区 Slack 中联系我们!
标签:EVTX分析, Groq API, Linter, LNA, OPA, Policy as Code, pptx, Rego, 二进制发布, 云安全监控, 代码规范, 开源工具, 政策合规, 文档结构分析, 日志审计, 最佳实践, 策略优化, 策略即代码, 策略安全, 策略开发, 策略引擎, 策略调试, 结构化提示词, 编辑器集成, 网络安全挑战, 聊天机器人安全, 语言服务, 请求拦截, 静态分析, 靶场