Kuberentes RBAC 规则允许仅从 CronJob 创建作业
是否可以创建一个 kubernetes RBAC 规则,允许从现有 CronJob 创建作业,但阻止以其他方式创建作业?
我们希望严格锁定我们的集群,以避免不受 CICD 管理的任意部署 - 但我们还需要促进 CronJobs 的手动测试,或者不按计划重新运行失败的作业。我希望开发人员能够运行以下命令:
kubectl create job --from=cronjob/my-job my-job-test-run-1
但不能运行以下命令:
kubectl create job my-evil-job -f evil-job.yaml
这可能吗?
Is it possible to create a kubernetes RBAC rule that allows creating a Job from an existing CronJob, but prevents creating a Job any other way?
We want to keep our clusters tightly locked down to avoid arbitrary deployments not managed by CICD - but we also need to facilitate manual testing of CronJobs, or rerunning failed jobs off schedule. I'd like developers to be able to run a command like:
kubectl create job --from=cronjob/my-job my-job-test-run-1
But not be able to run something like:
kubectl create job my-evil-job -f evil-job.yaml
Is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,为了成功执行此命令:
User/ServiceAccount 应该具有正确的 RBAC 规则(下面提供的输出中至少有两条,创建
Jobs
并获取CronJobs
。在第一个示例中,我授予了创建
Jobs
的访问权限代码>并获取CronJobs
并且我能够创建Job
和Job --from CronJob
但如果我仅授予访问权限来创建
Job< /code> 没有 get
CronJob
,我能够创建Job
但不能创建Job --from CronJob
当我删除创建的访问权限时
乔布斯
,我无法创建Job
以及Job --from CronJob
如您所见,如果 User/ServiceAccount 在这种情况下没有这两种权限,则无法创建(
Job
或Job --from CronJob
),因此不可能仅使用 RABC 规则来创建此类限制。一种可能的解决方案是将此权限拆分为两个不同的 User/ServiceAccount 来执行两个不同的任务(第一个用户可以创建
Jobs
+ 获取CronJobs
,第二个用户没有权限创建>工作
)。另一种可能性是尝试将 k8s 准入控制器与 fe 开放策略代理一起使用
In this scenario in order to successfully execute this command:
User/ServiceAccount should have proper RBAC rules (at least two from the output provided below, create
Jobs
and getCronJobs
.In first example I granted access to create
Jobs
and getCronJobs
and I was able to createJob
andJob --from CronJob
But if I granted access only to create
Job
without getCronJob
, I was be able to createJob
but not to createJob --from CronJob
When I deleted access to create
Jobs
, I couldn't createJob
and alsoJob --from CronJob
As you can see if User/ServiceAccount doesn't have both permission in this scenario it's impossible to create (
Job
orJob --from CronJob
) so it's impossible to create such restrictions using only RABC rules.One possible solution is to split this permission into two different User/ServiceAccount for two different tasks (first user can create
Jobs
+ getCronJobs
, second user without permission to createJobs
).Another possibility is to try to use k8s admission Controller with f.e. Open Policy agent