一组实用程序和类,用于使用基于开放策略代理的工具,包括Gatekeeper和Conftest

policykit的Python项目详细描述


保险箱

CircleCI

一组用于使用基于Open Policy Agent的工具的实用程序和类,包括Gatekeeper和{a4}。在

安装

可以使用pip或类似工具从PyPI安装策略包:

pip install policykit

命令行接口

该模块提供了一个名为pk的CLI工具,用于使用某些功能。在

^{pr2}$

您也可以通过Docker使用该工具:

docker run --rm -it -v $(pwd):/app  garethr/policykit build

Python

此模块当前包含几个类,第一个类用于在Gatekeeper中使用ConstraintTemplates。在

frompolicykitimportConstraintTemplatewithopen(path_to_rego_source_file,"r")asrego:ct=ConstraintTemplate(name,rego.read())print(ct.yaml())

{{cd4}使得与Python类的交互变得容易。 请注意,这要求路径上有conftest可执行文件。在

>>>frompolicykitimportConftest>>>cli=Conftest("policy")>>>result=cli.test("deployment.yaml")>>>resultConftestRun(code=1,results=[ConftestResult(filename='/Users/garethr/Documents/conftest/examples/kubernetes/deployment.yaml',Warnings=[],Failures=['hello-kubernetes must include Kubernetes recommended labels: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/#labels ','Containers must not run as root in Deployment hello-kubernetes','Deployment hello-kubernetes must provide app/release labels for pod selectors'],Successes=[])]>>>result.successFalse

传递给json_input的字典被解析为JSON,然后作为stdin发送到confest可执行文件。在

frompolicykitimportConftestresult=Conftest("policy").test(json_input={"foo":"bar"})print(result)

行动

在GitHub操作中也可以很容易地使用policykit,使用以下操作。这个例子也展示了 将生成的文件提交回Git存储库。根据需要更新<>中的值。在

on:pushname:Gatekeeperjobs:build:runs-on:ubuntu-lateststeps:-uses:actions/checkout@master-name:Generate ConstraintTemplates for Gatekeeperuses:garethr/policykit/action@masterwith:args:<directory-of-rego-source-files>-name:Commit to repositoryenv:GITHUB_TOKEN:${{ secrets.github_token }}COMMIT_MSG:|Generated new ConstraintTemplates from Rego sourceskip-checks: truerun:|# Hard-code user configgit config user.email "<your-email-address>"git config user.name "<your-username>"git config --get-regexp "user\.(name|email)"# Update origin with tokengit remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git# Checkout the branch so we can push back to itgit checkout mastergit add .# Only commit and push if we have changesgit diff --quiet && git diff --staged --quiet || (git commit -m "${COMMIT_MSG}"; git push origin master

注释

对于任何尝试使用此模块的人来说,有一些注意事项。在

  • Loading libraries with ^{}目前只在Gatekeeper HEAD中受支持,但在下一个版本中应该支持。在
  • 此模块不支持参数化ConstraintTemplates

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
我需要编写一个java程序,不断提示用户输入一个句子。然后,只有在输入stop时才退出反向字符串   c和java之间的AES rijndael加密   安卓中实现本地数据实时搜索的java方法   数组如何修复Java中的“.class预期”   Java拆分函数:这是预期的行为吗?   Gradle依赖关系树中星号和箭头符号的java含义   带参数的java并发JUnit测试   java解析postgres对象文本   java如何将blossom模板发布到magnolia公共模块   java抛出,捕捉异常错误   C和Java中数据类型的大小?   java XMPP:BOSH客户端会话在连接到openfire时被随机关闭   java BlockingQueue:put()和isEmpty()不一起工作?   java无法获取OkHttp的响应。身体toString()返回字符串   java将光标放在圆上时改变圆的位置   java如何在安卓中实现twitter深度链接?   删除某些列后,extendedDataTable中的java表状态未保存   JUnit测试中带有远程配置的java Start Spring启动上下文   未执行java Android视图画布onDraw   Java Hibernate HQL SQL内部联接查询无法运行Oracle