Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Enforcing Bespoke Policies in Kubernetes

897 views

Published on

Kubernetes enables fully-automated, self-service management of large-scale, heterogenous deployments. These deployments are often managed by distributed engineering teams that have unique requirements for how the platform treats their workloads, but at the same time, they must conform to organization-wide constraints around cost, security, and performance. As Kubernetes matures, extensibility has become a critical feature that organizations can leverage to enforce their organization’s bespoke policies.

In this talk, Torin explains how to use extensibility features in Kubernetes (e.g., External Admission Control) to enforce custom policies over workloads. The talk shows how to build custom admission controllers using Initializers and Webhooks, and shows how the same features lay the groundwork for policy-based control through integration with third party policy engines like the Open Policy Agent project.

Published in: Technology
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Enforcing Bespoke Policies in Kubernetes

  1. 1. Torin Sandall @sometorin openpolicyagent.org Enforcing Bespoke Policies in Kubernetes
  2. 2. openpolicyagent.org@sometorin Overview ● Background: What Is Policy? ● Example Scenario ● Admission Control ● Open Policy Agent
  3. 3. openpolicyagent.org@sometorin What Is Policy?
  4. 4. openpolicyagent.org@sometorin What Is Policy? ● Policies are vital to every organization ○ Policies are required across the stack ○ Policies are organization-specific ○ Policies change frequently over time
  5. 5. openpolicyagent.org@sometorin What Is Policy? ● Policies are vital to every organization ○ Policies are required across the stack ○ Policies are organization-specific ○ Policies change frequently over time ● Policy enforcement methods vary wildly ○ Weak guarantees from tribal knowledge & wikis ○ High cost from hard-coded policy decisions
  6. 6. openpolicyagent.org@sometorin What Is Policy? ● Policies are vital to every organization ○ Policies are required across the stack ○ Policies are organization-specific ○ Policies change frequently over time ● Policy enforcement methods vary wildly ○ Weak guarantees from tribal knowledge & wikis ○ High cost from hard-coded policy decisions ● Existing solutions lack expressiveness ○ Logic and data ○ Decisions ○ Composition
  7. 7. openpolicyagent.org Example Scenario Alice Platform Engineer Bob App Engineer ● Alice and Bob work for AcmeCorp
  8. 8. openpolicyagent.org Example Scenario Alice Platform Engineer Bob App Engineer ● Alice and Bob work for AcmeCorp ● Bob needs shell access to containers running on Kubernetes
  9. 9. openpolicyagent.org Example Scenario Alice Platform Engineer Bob App Engineer ● Alice and Bob work for AcmeCorp ● Bob needs shell access to containers running on Kubernetes ● Bob cannot be trusted with access to privileged containers running in the production namespace
  10. 10. openpolicyagent.org@sometorin Kubernetes Extensibility Dynamic Admission Control Custom Resource Definitions (CRDs) API Aggregation Multi-scheduler Operators (Pattern) Image Webhook Token Authenticator Webhook Authorizer Hook 1.3 1.4 1.5 1.7<1.3 1.9 MutatingWebhook (+beta)
  11. 11. openpolicyagent.org@sometorin Admission Control etcd Kubernetes API Server Authentication Authorization Admission Control
  12. 12. openpolicyagent.org@sometorin Admission Control etcd Kubernetes API Server Admission Control Resource Quota Service Accounts Authentication Authorization Resource Management Security
  13. 13. openpolicyagent.org@sometorin Admission Control etcd Kubernetes API Server Admission Control Resource Quota Service Accounts Authentication Authorization Resource Management Security
  14. 14. openpolicyagent.org@sometorin ● Static compilation & configuration ○ 30+ admission controllers ○ 1-4 added per release ○ Command line arguments ○ Static configuration files admit deny exec limitranger namespace resourcequota securitycontext serviceaccount initialresources alwayspullimages antiaffinity persistentvolume security imagepolicy storageclass gc podnodeselector defaulttolerationseconds podpreset initialization noderestriction podtolerationrestriction schedulingpolicy image/imagelimitrangerplugin image/imagepolicyplugin ingress/ingress project/lifecycle project/podnodeenvironment project/projectrequestlimit quota/quotaclusterresourceoverride quota/clusterquota quota/runonceduration scheduler/podnodeconstraints security/constraint Admission Control: Before 1.7
  15. 15. openpolicyagent.org@sometorin ● Static compilation & configuration ○ 30+ admission controllers ○ 1-4 added per release ○ Command line arguments ○ Static configuration files ● Example Scenario ○ Alice forks Kubernetes into a private repository ○ Alice implements the policy inside the plugin framework ○ Alice now has to build, push, and upgrade Kubernetes itself Admission Control: Before 1.7 admit deny exec limitranger namespace resourcequota securitycontext serviceaccount initialresources alwayspullimages antiaffinity persistentvolume security imagepolicy storageclass gc podnodeselector defaulttolerationseconds podpreset initialization noderestriction podtolerationrestriction schedulingpolicy image/imagelimitrangerplugin image/imagepolicyplugin ingress/ingress project/lifecycle bobprotectionpolicy project/podnodeenvironment project/projectrequestlimit quota/quotaclusterresourceoverride quota/clusterquota quota/runonceduration scheduler/podnodeconstraints security/constraint
  16. 16. openpolicyagent.org@sometorin Admission Control: Webhooks ● Admission controllers can be implemented as webhooks that run on top of Kubernetes ● Webhooks can allow or deny incoming requests ○ Before etcd is updated ○ Before clients are notified ● Webhooks are configured dynamically via Kubernetes APIs Kubernetes API Server Admission Control External Admission Webhooks
  17. 17. openpolicyagent.org@sometorin Admission Control: Webhooks ● The API Server calls webhooks whose configuration rules match the incoming request: match [ {operations: [“create”], kinds: [“pods”]}, {operations: [“delete”], kinds: [“services”]} ] ● Rules can include wildcards: match [ {operations: [“*”], kinds: [“*”]} ] Kubernetes API Server Admission Control External Admission Webhooks
  18. 18. openpolicyagent.org@sometorin Admission Control: Webhooks ● The API Server provides the operation, entire object, and user info in the webhook call kind: AdmissionReview spec: kind: {kind: Pod, version: v1} name: admission-webhook-demo-373699553-8srx8 namespace: default object: Options: Command: [sh] Container: admission-webhook-demo ... ResourcePath: pods/exec operation: CONNECT userInfo: groups: ['system:masters', 'system:authenticated'] username: minikube Kubernetes API Server Admission Control External Admission Webhooks $ kubectl exec
  19. 19. openpolicyagent.org@sometorin Admission Control: Webhooks ● Webhooks respond with an AdmissionReview that indicates whether to allow or deny the request kind: AdmissionReview status: allowed: false reason: message: “nice try bob -alice” ● The API Server rejects the request IF ANY of the webhooks return a denial Kubernetes API Server Admission Control External Admission Webhooks $ kubectl exec error: nice try bob -alice
  20. 20. openpolicyagent.org@sometorin Demo
  21. 21. openpolicyagent.org@sometorin ● Be careful with webhook dependencies! ○ Consider performance and availability ○ Avoid side effects Webhooks: Lessons Learned
  22. 22. openpolicyagent.org@sometorin ● Be careful with webhook dependencies! ○ Consider performance and availability ○ Avoid side effects ● API server sends “internal representation” of Kubernetes objects over the wire Webhooks: Lessons Learned
  23. 23. openpolicyagent.org@sometorin ● Be careful with webhook dependencies! ○ Consider performance and availability ○ Avoid side effects ● API server sends “internal representation” of Kubernetes objects over the wire ● API server “fails open” if webhook fails (configurable in 1.9) Webhooks: Lessons Learned
  24. 24. openpolicyagent.org@sometorin ● Be careful with webhook dependencies! ○ Consider performance and availability ○ Avoid side effects ● API server sends “internal representation” of Kubernetes objects over the wire ● API server “fails open” if webhook fails (configurable in 1.9) ● Must serve POST requests at https://<ip>:<port>/ (paths supported in 1.9) Webhooks: Lessons Learned
  25. 25. openpolicyagent.org@sometorin ● Be careful with webhook dependencies! ○ Consider performance and availability ○ Avoid side effects ● API server sends “internal representation” of Kubernetes objects over the wire ● API server “fails open” if webhook fails (configurable in 1.9) ● Must serve POST requests at https://<ip>:<port>/ (paths supported in 1.9) ● Client-go vendoring has improved significantly Webhooks: Lessons Learned
  26. 26. openpolicyagent.org@sometorin Webhooks...all the way down? ● Webhooks (and initializers) lay the groundwork for extensible policy enforcement
  27. 27. openpolicyagent.org@sometorin Webhooks...all the way down? ● Webhooks (and initializers) lay the groundwork for extensible policy enforcement ● Policy decisions have been decoupled from enforcement
  28. 28. openpolicyagent.org@sometorin Webhooks...all the way down? ● Webhooks (and initializers) lay the groundwork for extensible policy enforcement ● Policy decisions have been decoupled from enforcement ● Is there a better way to author policies that control who can do what?
  29. 29. openpolicyagent.org@sometorin apiVersion: v1 kind: Pod metadata: labels: app: nginx name: nginx-1493591563-bvl8q namespace: production spec: containers: - image: nginx imagePullPolicy: Always name: nginx securityContext: privileged: true dnsPolicy: ClusterFirst nodeName: minikube restartPolicy: Always status: containerStatuses: - name: nginx ready: true restartCount: 0 state: running: startedAt: 2017-08-01T06:34:22Z hostIP: 192.168.99.100 phase: Running podIP: 172.17.0.4 startTime: 2017-08-01T06:34:13Z
  30. 30. openpolicyagent.org@sometorin apiVersion: v1 kind: Pod metadata: labels: app: nginx name: nginx-1493591563-bvl8q namespace: production spec: containers: - image: nginx imagePullPolicy: Always name: nginx securityContext: privileged: true dnsPolicy: ClusterFirst nodeName: minikube restartPolicy: Always status: containerStatuses: - name: nginx ready: true restartCount: 0 state: running: startedAt: 2017-08-01T06:34:22Z hostIP: 192.168.99.100 phase: Running podIP: 172.17.0.4 startTime: 2017-08-01T06:34:13Z # references spec.containers[0].image
  31. 31. openpolicyagent.org@sometorin apiVersion: v1 kind: Pod metadata: labels: app: nginx name: nginx-1493591563-bvl8q namespace: production spec: containers: - image: nginx imagePullPolicy: Always name: nginx securityContext: privileged: true dnsPolicy: ClusterFirst nodeName: minikube restartPolicy: Always status: containerStatuses: - name: nginx ready: true restartCount: 0 state: running: startedAt: 2017-08-01T06:34:22Z hostIP: 192.168.99.100 phase: Running podIP: 172.17.0.4 startTime: 2017-08-01T06:34:13Z # references spec.containers[0].image # variables and iteration container = spec.containers[_]
  32. 32. openpolicyagent.org@sometorin apiVersion: v1 kind: Pod metadata: labels: app: nginx name: nginx-1493591563-bvl8q namespace: production spec: containers: - image: nginx imagePullPolicy: Always name: nginx securityContext: privileged: true dnsPolicy: ClusterFirst nodeName: minikube restartPolicy: Always status: containerStatuses: - name: nginx ready: true restartCount: 0 state: running: startedAt: 2017-08-01T06:34:22Z hostIP: 192.168.99.100 phase: Running podIP: 172.17.0.4 startTime: 2017-08-01T06:34:13Z # references spec.containers[0].image # variables and iteration container = spec.containers[_] # expressions container.securityContext.privileged = true
  33. 33. openpolicyagent.org@sometorin apiVersion: v1 kind: Pod metadata: labels: app: nginx name: nginx-1493591563-bvl8q namespace: production spec: containers: - image: nginx imagePullPolicy: Always name: nginx securityContext: privileged: true dnsPolicy: ClusterFirst nodeName: minikube restartPolicy: Always status: containerStatuses: - name: nginx ready: true restartCount: 0 state: running: startedAt: 2017-08-01T06:34:22Z hostIP: 192.168.99.100 phase: Running podIP: 172.17.0.4 startTime: 2017-08-01T06:34:13Z # references spec.containers[0].image # variables and iteration container = spec.containers[_] # expressions container.securityContext.privileged = true # functions is_privileged(container) { container.securityContext.privileged = true }
  34. 34. openpolicyagent.org@sometorin apiVersion: v1 kind: Pod metadata: labels: app: nginx name: nginx-1493591563-bvl8q namespace: production spec: containers: - image: nginx imagePullPolicy: Always name: nginx securityContext: privileged: true dnsPolicy: ClusterFirst nodeName: minikube restartPolicy: Always status: containerStatuses: - name: nginx ready: true restartCount: 0 state: running: startedAt: 2017-08-01T06:34:22Z hostIP: 192.168.99.100 phase: Running podIP: 172.17.0.4 startTime: 2017-08-01T06:34:13Z # references spec.containers[0].image # variables and iteration container = spec.containers[_] # expressions container.securityContext.privileged = true # functions is_privileged(container) { container.securityContext.privileged = true } # rules deny { review.user = “bob” review.operation = “CONNECT” review.namespace = “production” is_privileged(spec.containers[_]) }
  35. 35. openpolicyagent.org@sometorin OPA is an open source, general-purpose policy engine Policy Query Policy Decision
  36. 36. openpolicyagent.org@sometorin OPA is an open source, general-purpose policy engine Policy Query Policy Decision ● Declarative Language (Rego) ○ Is X allowed to call operation Y on resource Z? ○ What clusters should workload X be deployed to? ○ What annotations must be present on object X?
  37. 37. openpolicyagent.org@sometorin OPA is an open source, general-purpose policy engine Policy Query Policy Decision ● Declarative Language (Rego) ○ Is X allowed to call operation Y on resource Z? ○ What clusters should workload X be deployed to? ○ What annotations must be present on object X? ● Library/Daemon (Go) ○ In-memory, zero runtime dependencies ○ Evaluation engine: parser, compiler, interpreter ○ Tooling: REPL, test runner, tracing
  38. 38. openpolicyagent.org@sometorin OPA is an open source, general-purpose policy engine Policy Query Policy Decision ● Declarative Language (Rego) ○ Is X allowed to call operation Y on resource Z? ○ What clusters should workload X be deployed to? ○ What annotations must be present on object X? ● Library/Daemon (Go) ○ In-memory, zero runtime dependencies ○ Evaluation engine: parser, compiler, interpreter ○ Tooling: REPL, test runner, tracing ● Growing community ○ Sponsored by Styra and Google/Firebase ○ Used by Netflix, Medallia, Huawei, Schuberg Philis, and more ○ Integrations for Istio, Kubernetes, Terraform, PAM, AWS, and more
  39. 39. openpolicyagent.org@sometorin Demo
  40. 40. openpolicyagent.org@sometorin Istio Hashicorp Terraform github.com/open-policy-agent/library Contributions welcome. Standard Library
  41. 41. openpolicyagent.org@sometorin github.com/open-policy-agent/opa tsandall/admission-webhook-demo slack.openpolicyagent.org Thank you!

×