AWS开源Cedar语言用于定义访问权限
AWS最近开源了Cedar,这是一种用于通过策略定义访问权限的语言。Cedar已集成到Amazon Verified Permissions和AWS Verified Access中,并且可以通过提供的SDK和语言规范直接集成到应用程序中。
Cedar的主要特点
Cedar允许将策略与应用程序代码分离,这种解耦使得策略可以独立编写、分析和审计。Cedar支持基于角色的访问控制(RBAC)和基于属性的访问控制(ABAC)方法。
Cedar的SDK和授权引擎
Cedar的SDK可用于编写和验证策略,以及授权访问请求。Cedar本身是用Rust编写的,但提供了Rust crate和Java包,以便在Java中使用。
通过调用Cedar授权引擎可以验证请求是否被授权。请求信息被转换为Cedar请求并传递给Cedar授权引擎。以下是一个Rust示例:
pub fn is_authorized(
&self,
principal: impl AsRef<EntityUid>,
action: impl AsRef<EntityUid>,
resource: impl AsRef<EntityUid>,
) -> Result<()> {
let es = self.entities.as_entities();
let q = Request::new(
Some(principal.as_ref().clone().into()),
Some(action.as_ref().clone().into()),
Some(resource.as_ref().clone().into()),
Context::empty(),
);
info!(
"is_authorized request: principal: {}, action: {}, resource: {}",
principal.as_ref(),
action.as_ref(),
resource.as_ref()
);
let response = self.authorizer.is_authorized(&q, &self.policies, &es);
info!("Auth response: {:?}", response);
match response.decision() {
Decision::Allow => Ok(()),
Decision::Deny => Err(Error::AuthDenied(response.diagnostics().clone())),
}
}授权引擎通过调用self.authorizer.is_authorized(&q, &self.policies, &es)来执行,参数包括访问请求、Cedar策略和实体集。根据分析,调用将返回Decision::Allow或Decision::Deny。
通过SDK创建策略
以下Java示例创建了一个策略,允许主体Alice对Vacation资源的任何子资源执行View_Photo操作:
private Set<Policy> buildPolicySlice() {
Set<Policy> ps = new HashSet<>();
String fullPolicy = "permit(principal == User::\"Alice\", action == Action::\"View_Photo\", resource in Album::\"Vacation\");";
ps.add(new Policy(fullPolicy, "p1"));
return ps;
}在Java中,可以使用isAuthorized方法执行查询:
public boolean sampleMethod() throws AuthException {
AuthorizationEngine ae = new WrapperAuthorizationEngine();
AuthorizationQuery q = new AuthorizationQuery("User::\"Alice\"", "Action::\"View_Photo\"", "Photo::\"pic01\"");
return ae.isAuthorized(q, buildSlice()).isAllowed();
}Permit.io的Cedar-Agent
Permit.io在AWS发布Cedar之后,发布了Cedar-Agent,这是一个HTTP服务器,作为Cedar策略的策略存储和数据存储。存储允许创建、检索、更新和删除策略。数据存储允许在内存中存储应用程序的数据,并与Cedar-Agent集成以对存储的数据执行授权检查。授权检查在传入的HTTP请求上执行。
社区反响
在HackerNews上,用户dadadad100评论说Cedar可能填补了应用程序授权领域的空白,认为它介于OPA和Zanzibar之间。其他用户如Oxbadcafebee则对AWS没有支持Open Policy Agent表示失望。
开源与社区
Cedar在Apache License 2.0下开源,可通过GitHub获取。更多详细信息可以在最近的AWS博客中找到,并可以通过加入Cedar Policy Slack工作区参与讨论。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用。你还可以使用@来通知其他用户。