Odoo security rules
Skill findscripter/everything-skills/09-verticals/odoo-security-rules
当为 Odoo 自定义模块配置权限或排查"拒绝访问"时使用;编写 ir.model.access.csv 模型级权限、ir.rule 记录规则与多公司可见性规则并定位错误;不适用于字段级权限、PostgreSQL 行级安全或 sudo() 绕过场景;触发词:ir.model.access、ir.rule、记录规则、Access Denied、多公司From its SKILL.md
npx -y skills add findscripter/everything-skills --skill odoo-security-rulesAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its file declares
Copied from the file, not written here
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
5.9 KB, ~1.6k tokens by cl100k_base, as published. Nobody here has run it
何时使用
Odoo 安全分两层:模型级访问(谁能读写哪个模型,由 ir.model.access.csv 控制)与记录级规则(用户能看到哪些记录,由 ir.rule 控制)。在以下情况使用本技能:
- 为新建的自定义模块配置访问权限。
- 限制记录可见范围,让用户只能看到自己或本公司的数据。
- 排查 "Access Denied" / "You are not allowed to access" 报错。
- 实现多公司(multi-company)记录可见性。
不该用的边界:
- 字段级权限(
ir.model.fields的读写限制)不在范围内,需自行用 OWL 或 Python override 实现。 - 门户/公开用户(
base.group_portal)规则有额外细节,本技能不完整覆盖,需单独验证。 - PostgreSQL 行级安全(RLS) 不涉及——Odoo 在 ORM 层统一管控安全。
- 任何
sudo()/ 超级用户上下文会完全绕过ir.rule,本技能无法约束这类代码。
步骤
- 明确场景:判断需求属于模型级(能否读写该模型)还是记录级(能看到哪些行),或两者都要。
- 写 CSV:在
security/ir.model.access.csv中按列填权限位perm_read,perm_write,perm_create,perm_unlink(0/1)。 - 写记录规则:在 XML 中创建
ir.rule,用domain_force定义可见域,并务必绑定groups。 - 建专用安全组:用
res.groups为模块单独建组,不要复用 Odoo 核心组。 - 验证:以非 admin 用户在 debug 模式下测试;注意
sudo()会跳过所有记录规则。
指令
- 模型级权限只能给到组级别;CSV 的
group_id:id留空意味着授予公开(未认证)访问,谨慎使用。 - 管理员角色用
base.group_erp_manager,切勿用base.group_system(保留给 Odoo 技术超级用户,会授予服务器配置等完整技术权限)。 ir.rule若省略<field name="groups">,规则即变为全局(global),对包括管理员在内的所有用户生效。除非确有此意图,否则总要绑定组。- 多公司规则用复数
company_ids(包含用户所属的全部公司),而非单数company_id。 - 遵循最小权限原则:从最严格开始,按需放开。
示例
示例 1:ir.model.access.csv(模型级权限)
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_hospital_patient_user,hospital.patient.user,model_hospital_patient,base.group_user,1,0,0,0
access_hospital_patient_manager,hospital.patient.manager,model_hospital_patient,base.group_erp_manager,1,1,1,1
为模块管理员角色单独建组(而非复用核心组):
<record id="group_hospital_manager" model="res.groups">
<field name="name">Hospital Manager</field>
<field name="category_id" ref="base.module_category_hidden"/>
</record>
示例 2:记录规则——用户只能看到自己的记录
<record id="rule_hospital_patient_own" model="ir.rule">
<field name="name">Hospital Patient: Own Records Only</field>
<field name="model_id" ref="model_hospital_patient"/>
<field name="domain_force">[('create_uid', '=', user.id)]</field>
<field name="groups" eval="[(4, ref('base.group_user'))]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_unlink" eval="False"/>
</record>
注意:省略
groups会让规则变全局,对所有用户(含 admin)生效。
示例 3:多公司记录规则
<record id="rule_hospital_patient_company" model="ir.rule">
<field name="name">Hospital Patient: Multi-Company</field>
<field name="model_id" ref="model_hospital_patient"/>
<field name="domain_force">
['|', ('company_id', '=', False),
('company_id', 'in', company_ids)]
</field>
<field name="groups" eval="[(4, ref('base.group_user'))]"/>
</record>
注意事项
- 从最严格的权限起步,再按需放开。
- 多公司规则用
company_ids(复数),它包含用户所属的所有公司。 - 用非 admin 用户在 debug 模式下测试规则——
sudo()会完全绕过所有记录规则。 - 每个模块建专用安全组,而非复用 Odoo 核心组。
- 不要给普通用户
perm_unlink = 1,除非业务流程明确需要删除。 - 不要在
ir.model.access.csv中留空group_id,除非有意授予公开(未认证)访问。 - 不要用
base.group_system作为模块管理员组——它会授予包括服务器配置在内的完整技术权限。
互见
- Odoo 自定义模块开发与目录结构(
security/目录、__manifest__.py中声明 CSV/XML)。 - Odoo ORM 域(domain)语法与
eval多对多写法(如(4, ref(...))命令元组)。
采编自 sickn33/antigravity-awesome-skills(MIT 许可)。
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.
Gives 0 of the 12 instructions most security skills give in ~1.6k tokens
Counted across 648 of the 828 authors here whose files we hold, read 2026-08-07
- Parameterize all database queriesin 68 of 648, across 51 files
- Hash passwords using bcrypt, scrypt, or argon2in 49 of 648, across 36 files
- Apply rate limiting to authentication endpointsin 48 of 648, across 24 files
- Configure security headersin 35 of 648, across 19 files
- Validate all inputsin 32 of 648, across 24 files
- Validate all external input at the system boundaryin 29 of 648, across 19 files
- Run containers as a non-root userin 28 of 648, across 15 files
- Use httponly secure samesite cookies for sessionsin 26 of 648, across 15 files
- Run dependency audits before every releasein 21 of 648, across 10 files
- Encode output to prevent cross-site scriptingin 21 of 648, across 11 files
- Copy dependencies before source codein 20 of 648, across 9 files
- Store secrets in environment variablesin 20 of 648, across 18 files
Said here and by no other author read
- Determine if the requirement is model-level or record-level
- Define model-level permissions in ir.model.access.csv
- Create record rules in XML using domain_force
- Bind groups when creating record rules
- Create dedicated security groups for custom modules
- Use plural company_ids for multi-company rules
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.