diff --git a/website/404.html b/website/404.html index 00c1c35d6..92f6c3c7d 100644 --- a/website/404.html +++ b/website/404.html @@ -10,7 +10,7 @@ - +
diff --git a/website/assets/js/bd7f9487.802eb5aa.js b/website/assets/js/bd7f9487.802eb5aa.js deleted file mode 100644 index 5f4f6b8d0..000000000 --- a/website/assets/js/bd7f9487.802eb5aa.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[2044],{9971:(e,n,i)=>{i.r(n),i.d(n,{assets:()=>l,contentTitle:()=>s,default:()=>d,frontMatter:()=>r,metadata:()=>o,toc:()=>p});var a=i(5893),t=i(1151);const r={id:"privileged-containers",title:"Privileged Container"},s="Privileged Container",o={id:"validation/privileged-containers",title:"Privileged Container",description:"Description",source:"@site/docs/validation/privileged-containers.md",sourceDirName:"validation",slug:"/validation/privileged-containers",permalink:"/gatekeeper-library/website/validation/privileged-containers",draft:!1,unlisted:!1,editUrl:"https://github.com/open-policy-agent/gatekeeper-library/edit/master/website/docs/validation/privileged-containers.md",tags:[],version:"current",frontMatter:{id:"privileged-containers",title:"Privileged Container"},sidebar:"docs",previous:{title:"Host Networking Ports",permalink:"/gatekeeper-library/website/validation/host-network-ports"},next:{title:"Proc Mount",permalink:"/gatekeeper-library/website/validation/proc-mount"}},l={},p=[{value:"Description",id:"description",level:2},{value:"Template",id:"template",level:2},{value:"Usage",id:"usage",level:3},{value:"Examples",id:"examples",level:2}];function c(e){const n={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,t.a)(),...e.components},{Details:i}=n;return i||function(e,n){throw new Error("Expected "+(n?"component":"object")+" `"+e+"` to be defined: you likely forgot to import, pass, or provide it.")}("Details",!0),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.h1,{id:"privileged-container",children:"Privileged Container"}),"\n",(0,a.jsx)(n.h2,{id:"description",children:"Description"}),"\n",(0,a.jsxs)(n.p,{children:["Controls the ability of any container to enable privileged mode. Corresponds to the ",(0,a.jsx)(n.code,{children:"privileged"})," field in a PodSecurityPolicy. For more information, see ",(0,a.jsx)(n.a,{href:"https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged",children:"https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged"})]}),"\n",(0,a.jsx)(n.h2,{id:"template",children:"Template"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-yaml",children:'apiVersion: templates.gatekeeper.sh/v1\nkind: ConstraintTemplate\nmetadata:\n name: k8spspprivilegedcontainer\n annotations:\n metadata.gatekeeper.sh/title: "Privileged Container"\n metadata.gatekeeper.sh/version: 1.1.0\n description: >-\n Controls the ability of any container to enable privileged mode.\n Corresponds to the `privileged` field in a PodSecurityPolicy. For more\n information, see\n https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged\nspec:\n crd:\n spec:\n names:\n kind: K8sPSPPrivilegedContainer\n validation:\n openAPIV3Schema:\n type: object\n description: >-\n Controls the ability of any container to enable privileged mode.\n Corresponds to the `privileged` field in a PodSecurityPolicy. For more\n information, see\n https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged\n properties:\n exemptImages:\n description: >-\n Any container that uses an image that matches an entry in this list will be excluded\n from enforcement. Prefix-matching can be signified with `*`. For example: `my-image-*`.\n\n It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name)\n in order to avoid unexpectedly exempting images from an untrusted repository.\n type: array\n items:\n type: string\n targets:\n - target: admission.k8s.gatekeeper.sh\n code:\n - engine: K8sNativeValidation\n source:\n variables:\n - name: containers\n expression: \'has(variables.anyObject.spec.containers) ? variables.anyObject.spec.containers : []\'\n - name: initContainers\n expression: \'has(variables.anyObject.spec.initContainers) ? variables.anyObject.spec.initContainers : []\'\n - name: ephemeralContainers\n expression: \'has(variables.anyObject.spec.ephemeralContainers) ? variables.anyObject.spec.ephemeralContainers : []\'\n - name: exemptImagePrefixes\n expression: |\n !has(variables.params.exemptImages) ? [] :\n variables.params.exemptImages.filter(image, image.endsWith("*")).map(image, string(image).replace("*", ""))\n - name: exemptImageExplicit\n expression: |\n !has(variables.params.exemptImages) ? [] : \n variables.params.exemptImages.filter(image, !image.endsWith("*"))\n - name: exemptImages\n expression: |\n (variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,\n container.image in variables.exemptImageExplicit ||\n variables.exemptImagePrefixes.exists(exemption, string(container.image).startsWith(exemption)))\n - name: badContainers\n expression: |\n (variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,\n !(container.image in variables.exemptImages) &&\n (has(container.securityContext) && has(container.securityContext.privileged) && container.securityContext.privileged == true)\n ).map(container, "Privileged container is not allowed: " + container.name +", securityContext: " + container.securityContext)\n validations:\n - expression: \'(has(request.operation) && request.operation == "UPDATE") || size(variables.badContainers) == 0\'\n messageExpression: \'variables.badContainers.join("\\n")\' \n - engine: Rego\n source:\n rego: |\n package k8spspprivileged\n\n import data.lib.exclude_update.is_update\n import data.lib.exempt_container.is_exempt\n\n violation[{"msg": msg, "details": {}}] {\n # spec.containers.privileged field is immutable.\n not is_update(input.review)\n\n c := input_containers[_]\n not is_exempt(c)\n c.securityContext.privileged\n msg := sprintf("Privileged container is not allowed: %v, securityContext: %v", [c.name, c.securityContext])\n }\n\n input_containers[c] {\n c := input.review.object.spec.containers[_]\n }\n\n input_containers[c] {\n c := input.review.object.spec.initContainers[_]\n }\n\n input_containers[c] {\n c := input.review.object.spec.ephemeralContainers[_]\n }\n libs:\n - |\n package lib.exclude_update\n\n is_update(review) {\n review.operation == "UPDATE"\n }\n - |\n package lib.exempt_container\n\n is_exempt(container) {\n exempt_images := object.get(object.get(input, "parameters", {}), "exemptImages", [])\n img := container.image\n exemption := exempt_images[_]\n _matches_exemption(img, exemption)\n }\n\n _matches_exemption(img, exemption) {\n not endswith(exemption, "*")\n exemption == img\n }\n\n _matches_exemption(img, exemption) {\n endswith(exemption, "*")\n prefix := trim_suffix(exemption, "*")\n startswith(img, prefix)\n }\n\n'})}),"\n",(0,a.jsx)(n.h3,{id:"usage",children:"Usage"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-shell",children:"kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/template.yaml\n"})}),"\n",(0,a.jsx)(n.h2,{id:"examples",children:"Examples"}),"\n",(0,a.jsxs)(i,{children:[(0,a.jsx)("summary",{children:"privileged-containers-disallowed"}),(0,a.jsxs)(i,{children:[(0,a.jsx)("summary",{children:"constraint"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-yaml",children:'apiVersion: constraints.gatekeeper.sh/v1beta1\nkind: K8sPSPPrivilegedContainer\nmetadata:\n name: psp-privileged-container\nspec:\n match:\n kinds:\n - apiGroups: [""]\n kinds: ["Pod"]\n excludedNamespaces: ["kube-system"]\n\n'})}),(0,a.jsx)(n.p,{children:"Usage"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-shell",children:"kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/constraint.yaml\n"})})]}),(0,a.jsxs)(i,{children:[(0,a.jsx)("summary",{children:"example-disallowed"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-yaml",children:"apiVersion: v1\nkind: Pod\nmetadata:\n name: nginx-privileged-disallowed\n labels:\n app: nginx-privileged\nspec:\n containers:\n - name: nginx\n image: nginx\n securityContext:\n privileged: true\n\n"})}),(0,a.jsx)(n.p,{children:"Usage"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-shell",children:"kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/example_disallowed.yaml\n"})})]}),(0,a.jsxs)(i,{children:[(0,a.jsx)("summary",{children:"example-allowed"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-yaml",children:"apiVersion: v1\nkind: Pod\nmetadata:\n name: nginx-privileged-allowed\n labels:\n app: nginx-privileged\nspec:\n containers:\n - name: nginx\n image: nginx\n securityContext:\n privileged: false\n\n"})}),(0,a.jsx)(n.p,{children:"Usage"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-shell",children:"kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/example_allowed.yaml\n"})})]}),(0,a.jsxs)(i,{children:[(0,a.jsx)("summary",{children:"disallowed-ephemeral"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-yaml",children:"apiVersion: v1\nkind: Pod\nmetadata:\n name: nginx-privileged-disallowed\n labels:\n app: nginx-privileged\nspec:\n ephemeralContainers:\n - name: nginx\n image: nginx\n securityContext:\n privileged: true\n\n"})}),(0,a.jsx)(n.p,{children:"Usage"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-shell",children:"kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/disallowed_ephemeral.yaml\n"})})]})]})]})}function d(e={}){const{wrapper:n}={...(0,t.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(c,{...e})}):c(e)}},1151:(e,n,i)=>{i.d(n,{Z:()=>o,a:()=>s});var a=i(7294);const t={},r=a.createContext(t);function s(e){const n=a.useContext(r);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:s(e.components),a.createElement(r.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/website/assets/js/bd7f9487.b994833e.js b/website/assets/js/bd7f9487.b994833e.js new file mode 100644 index 000000000..0b6d9be47 --- /dev/null +++ b/website/assets/js/bd7f9487.b994833e.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[2044],{9971:(e,n,i)=>{i.r(n),i.d(n,{assets:()=>l,contentTitle:()=>s,default:()=>d,frontMatter:()=>r,metadata:()=>o,toc:()=>p});var a=i(5893),t=i(1151);const r={id:"privileged-containers",title:"Privileged Container"},s="Privileged Container",o={id:"validation/privileged-containers",title:"Privileged Container",description:"Description",source:"@site/docs/validation/privileged-containers.md",sourceDirName:"validation",slug:"/validation/privileged-containers",permalink:"/gatekeeper-library/website/validation/privileged-containers",draft:!1,unlisted:!1,editUrl:"https://github.com/open-policy-agent/gatekeeper-library/edit/master/website/docs/validation/privileged-containers.md",tags:[],version:"current",frontMatter:{id:"privileged-containers",title:"Privileged Container"},sidebar:"docs",previous:{title:"Host Networking Ports",permalink:"/gatekeeper-library/website/validation/host-network-ports"},next:{title:"Proc Mount",permalink:"/gatekeeper-library/website/validation/proc-mount"}},l={},p=[{value:"Description",id:"description",level:2},{value:"Template",id:"template",level:2},{value:"Usage",id:"usage",level:3},{value:"Examples",id:"examples",level:2}];function c(e){const n={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,t.a)(),...e.components},{Details:i}=n;return i||function(e,n){throw new Error("Expected "+(n?"component":"object")+" `"+e+"` to be defined: you likely forgot to import, pass, or provide it.")}("Details",!0),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.h1,{id:"privileged-container",children:"Privileged Container"}),"\n",(0,a.jsx)(n.h2,{id:"description",children:"Description"}),"\n",(0,a.jsxs)(n.p,{children:["Controls the ability of any container to enable privileged mode. Corresponds to the ",(0,a.jsx)(n.code,{children:"privileged"})," field in a PodSecurityPolicy. For more information, see ",(0,a.jsx)(n.a,{href:"https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged",children:"https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged"})]}),"\n",(0,a.jsx)(n.h2,{id:"template",children:"Template"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-yaml",children:'apiVersion: templates.gatekeeper.sh/v1\nkind: ConstraintTemplate\nmetadata:\n name: k8spspprivilegedcontainer\n annotations:\n metadata.gatekeeper.sh/title: "Privileged Container"\n metadata.gatekeeper.sh/version: 1.1.1\n description: >-\n Controls the ability of any container to enable privileged mode.\n Corresponds to the `privileged` field in a PodSecurityPolicy. For more\n information, see\n https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged\nspec:\n crd:\n spec:\n names:\n kind: K8sPSPPrivilegedContainer\n validation:\n openAPIV3Schema:\n type: object\n description: >-\n Controls the ability of any container to enable privileged mode.\n Corresponds to the `privileged` field in a PodSecurityPolicy. For more\n information, see\n https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged\n properties:\n exemptImages:\n description: >-\n Any container that uses an image that matches an entry in this list will be excluded\n from enforcement. Prefix-matching can be signified with `*`. For example: `my-image-*`.\n\n It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name)\n in order to avoid unexpectedly exempting images from an untrusted repository.\n type: array\n items:\n type: string\n targets:\n - target: admission.k8s.gatekeeper.sh\n code:\n - engine: K8sNativeValidation\n source:\n variables:\n - name: containers\n expression: \'has(variables.anyObject.spec.containers) ? variables.anyObject.spec.containers : []\'\n - name: initContainers\n expression: \'has(variables.anyObject.spec.initContainers) ? variables.anyObject.spec.initContainers : []\'\n - name: ephemeralContainers\n expression: \'has(variables.anyObject.spec.ephemeralContainers) ? variables.anyObject.spec.ephemeralContainers : []\'\n - name: exemptImagePrefixes\n expression: |\n !has(variables.params.exemptImages) ? [] :\n variables.params.exemptImages.filter(image, image.endsWith("*")).map(image, string(image).replace("*", ""))\n - name: exemptImageExplicit\n expression: |\n !has(variables.params.exemptImages) ? [] : \n variables.params.exemptImages.filter(image, !image.endsWith("*"))\n - name: exemptImages\n expression: |\n (variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,\n container.image in variables.exemptImageExplicit ||\n variables.exemptImagePrefixes.exists(exemption, string(container.image).startsWith(exemption))\n ).map(container, container.image)\n - name: badContainers\n expression: |\n (variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,\n !(container.image in variables.exemptImages) &&\n (has(container.securityContext) && has(container.securityContext.privileged) && container.securityContext.privileged == true)\n ).map(container, "Privileged container is not allowed: " + container.name +", securityContext: " + container.securityContext)\n - name: isUpdate\n expression: has(request.operation) && request.operation == "UPDATE"\n validations:\n - expression: variables.isUpdate || size(variables.badContainers) == 0\n messageExpression: \'variables.badContainers.join("\\n")\' \n - engine: Rego\n source:\n rego: |\n package k8spspprivileged\n\n import data.lib.exclude_update.is_update\n import data.lib.exempt_container.is_exempt\n\n violation[{"msg": msg, "details": {}}] {\n # spec.containers.privileged field is immutable.\n not is_update(input.review)\n\n c := input_containers[_]\n not is_exempt(c)\n c.securityContext.privileged\n msg := sprintf("Privileged container is not allowed: %v, securityContext: %v", [c.name, c.securityContext])\n }\n\n input_containers[c] {\n c := input.review.object.spec.containers[_]\n }\n\n input_containers[c] {\n c := input.review.object.spec.initContainers[_]\n }\n\n input_containers[c] {\n c := input.review.object.spec.ephemeralContainers[_]\n }\n libs:\n - |\n package lib.exclude_update\n\n is_update(review) {\n review.operation == "UPDATE"\n }\n - |\n package lib.exempt_container\n\n is_exempt(container) {\n exempt_images := object.get(object.get(input, "parameters", {}), "exemptImages", [])\n img := container.image\n exemption := exempt_images[_]\n _matches_exemption(img, exemption)\n }\n\n _matches_exemption(img, exemption) {\n not endswith(exemption, "*")\n exemption == img\n }\n\n _matches_exemption(img, exemption) {\n endswith(exemption, "*")\n prefix := trim_suffix(exemption, "*")\n startswith(img, prefix)\n }\n\n'})}),"\n",(0,a.jsx)(n.h3,{id:"usage",children:"Usage"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-shell",children:"kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/template.yaml\n"})}),"\n",(0,a.jsx)(n.h2,{id:"examples",children:"Examples"}),"\n",(0,a.jsxs)(i,{children:[(0,a.jsx)("summary",{children:"privileged-containers-disallowed"}),(0,a.jsxs)(i,{children:[(0,a.jsx)("summary",{children:"constraint"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-yaml",children:'apiVersion: constraints.gatekeeper.sh/v1beta1\nkind: K8sPSPPrivilegedContainer\nmetadata:\n name: psp-privileged-container\nspec:\n match:\n kinds:\n - apiGroups: [""]\n kinds: ["Pod"]\n excludedNamespaces: ["kube-system"]\n parameters:\n exemptImages:\n - "safeimages.com/*"\n\n'})}),(0,a.jsx)(n.p,{children:"Usage"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-shell",children:"kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/constraint.yaml\n"})})]}),(0,a.jsxs)(i,{children:[(0,a.jsx)("summary",{children:"example-disallowed"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-yaml",children:"apiVersion: v1\nkind: Pod\nmetadata:\n name: nginx-privileged-disallowed\n labels:\n app: nginx-privileged\nspec:\n containers:\n - name: nginx\n image: nginx\n securityContext:\n privileged: true\n\n"})}),(0,a.jsx)(n.p,{children:"Usage"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-shell",children:"kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/example_disallowed.yaml\n"})})]}),(0,a.jsxs)(i,{children:[(0,a.jsx)("summary",{children:"example-allowed"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-yaml",children:"apiVersion: v1\nkind: Pod\nmetadata:\n name: nginx-privileged-allowed\n labels:\n app: nginx-privileged\nspec:\n containers:\n - name: nginx\n image: nginx\n securityContext:\n privileged: false\n\n"})}),(0,a.jsx)(n.p,{children:"Usage"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-shell",children:"kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/example_allowed.yaml\n"})})]}),(0,a.jsxs)(i,{children:[(0,a.jsx)("summary",{children:"disallowed-ephemeral"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-yaml",children:"apiVersion: v1\nkind: Pod\nmetadata:\n name: nginx-privileged-disallowed\n labels:\n app: nginx-privileged\nspec:\n ephemeralContainers:\n - name: nginx\n image: nginx\n securityContext:\n privileged: true\n\n"})}),(0,a.jsx)(n.p,{children:"Usage"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-shell",children:"kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/disallowed_ephemeral.yaml\n"})})]}),(0,a.jsxs)(i,{children:[(0,a.jsx)("summary",{children:"exempted-image"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-yaml",children:"apiVersion: v1\nkind: Pod\nmetadata:\n name: nginx-privileged-allowed-exempt\n labels:\n app: nginx-privileged\nspec:\n containers:\n - name: nginx\n image: safeimages.com/nginx\n securityContext:\n privileged: true\n\n"})}),(0,a.jsx)(n.p,{children:"Usage"}),(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-shell",children:"kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/example_allowed_exempt.yaml\n"})})]})]})]})}function d(e={}){const{wrapper:n}={...(0,t.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(c,{...e})}):c(e)}},1151:(e,n,i)=>{i.d(n,{Z:()=>o,a:()=>s});var a=i(7294);const t={},r=a.createContext(t);function s(e){const n=a.useContext(r);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:s(e.components),a.createElement(r.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/website/assets/js/runtime~main.e24eaac4.js b/website/assets/js/runtime~main.b6b5d29d.js similarity index 98% rename from website/assets/js/runtime~main.e24eaac4.js rename to website/assets/js/runtime~main.b6b5d29d.js index abadb00fa..f56ffc60d 100644 --- a/website/assets/js/runtime~main.e24eaac4.js +++ b/website/assets/js/runtime~main.b6b5d29d.js @@ -1 +1 @@ -(()=>{"use strict";var e,a,c,d,t,f={},r={};function b(e){var a=r[e];if(void 0!==a)return a.exports;var c=r[e]={id:e,loaded:!1,exports:{}};return f[e].call(c.exports,c,c.exports,b),c.loaded=!0,c.exports}b.m=f,b.c=r,e=[],b.O=(a,c,d,t)=>{if(!c){var f=1/0;for(i=0;iControls the ability of any container to enable privileged mode. Corresponds to the privileged
field in a PodSecurityPolicy. For more information, see https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged
apiVersion: templates.gatekeeper.sh/v1
kind: ConstraintTemplate
metadata:
name: k8spspprivilegedcontainer
annotations:
metadata.gatekeeper.sh/title: "Privileged Container"
metadata.gatekeeper.sh/version: 1.1.0
description: >-
Controls the ability of any container to enable privileged mode.
Corresponds to the `privileged` field in a PodSecurityPolicy. For more
information, see
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged
spec:
crd:
spec:
names:
kind: K8sPSPPrivilegedContainer
validation:
openAPIV3Schema:
type: object
description: >-
Controls the ability of any container to enable privileged mode.
Corresponds to the `privileged` field in a PodSecurityPolicy. For more
information, see
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged
properties:
exemptImages:
description: >-
Any container that uses an image that matches an entry in this list will be excluded
from enforcement. Prefix-matching can be signified with `*`. For example: `my-image-*`.
It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name)
in order to avoid unexpectedly exempting images from an untrusted repository.
type: array
items:
type: string
targets:
- target: admission.k8s.gatekeeper.sh
code:
- engine: K8sNativeValidation
source:
variables:
- name: containers
expression: 'has(variables.anyObject.spec.containers) ? variables.anyObject.spec.containers : []'
- name: initContainers
expression: 'has(variables.anyObject.spec.initContainers) ? variables.anyObject.spec.initContainers : []'
- name: ephemeralContainers
expression: 'has(variables.anyObject.spec.ephemeralContainers) ? variables.anyObject.spec.ephemeralContainers : []'
- name: exemptImagePrefixes
expression: |
!has(variables.params.exemptImages) ? [] :
variables.params.exemptImages.filter(image, image.endsWith("*")).map(image, string(image).replace("*", ""))
- name: exemptImageExplicit
expression: |
!has(variables.params.exemptImages) ? [] :
variables.params.exemptImages.filter(image, !image.endsWith("*"))
- name: exemptImages
expression: |
(variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
container.image in variables.exemptImageExplicit ||
variables.exemptImagePrefixes.exists(exemption, string(container.image).startsWith(exemption)))
- name: badContainers
expression: |
(variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
!(container.image in variables.exemptImages) &&
(has(container.securityContext) && has(container.securityContext.privileged) && container.securityContext.privileged == true)
).map(container, "Privileged container is not allowed: " + container.name +", securityContext: " + container.securityContext)
validations:
- expression: '(has(request.operation) && request.operation == "UPDATE") || size(variables.badContainers) == 0'
messageExpression: 'variables.badContainers.join("\n")'
- engine: Rego
source:
rego: |
package k8spspprivileged
import data.lib.exclude_update.is_update
import data.lib.exempt_container.is_exempt
violation[{"msg": msg, "details": {}}] {
# spec.containers.privileged field is immutable.
not is_update(input.review)
c := input_containers[_]
not is_exempt(c)
c.securityContext.privileged
msg := sprintf("Privileged container is not allowed: %v, securityContext: %v", [c.name, c.securityContext])
}
input_containers[c] {
c := input.review.object.spec.containers[_]
}
input_containers[c] {
c := input.review.object.spec.initContainers[_]
}
input_containers[c] {
c := input.review.object.spec.ephemeralContainers[_]
}
libs:
- |
package lib.exclude_update
is_update(review) {
review.operation == "UPDATE"
}
- |
package lib.exempt_container
is_exempt(container) {
exempt_images := object.get(object.get(input, "parameters", {}), "exemptImages", [])
img := container.image
exemption := exempt_images[_]
_matches_exemption(img, exemption)
}
_matches_exemption(img, exemption) {
not endswith(exemption, "*")
exemption == img
}
_matches_exemption(img, exemption) {
endswith(exemption, "*")
prefix := trim_suffix(exemption, "*")
startswith(img, prefix)
}
apiVersion: templates.gatekeeper.sh/v1
kind: ConstraintTemplate
metadata:
name: k8spspprivilegedcontainer
annotations:
metadata.gatekeeper.sh/title: "Privileged Container"
metadata.gatekeeper.sh/version: 1.1.1
description: >-
Controls the ability of any container to enable privileged mode.
Corresponds to the `privileged` field in a PodSecurityPolicy. For more
information, see
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged
spec:
crd:
spec:
names:
kind: K8sPSPPrivilegedContainer
validation:
openAPIV3Schema:
type: object
description: >-
Controls the ability of any container to enable privileged mode.
Corresponds to the `privileged` field in a PodSecurityPolicy. For more
information, see
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged
properties:
exemptImages:
description: >-
Any container that uses an image that matches an entry in this list will be excluded
from enforcement. Prefix-matching can be signified with `*`. For example: `my-image-*`.
It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name)
in order to avoid unexpectedly exempting images from an untrusted repository.
type: array
items:
type: string
targets:
- target: admission.k8s.gatekeeper.sh
code:
- engine: K8sNativeValidation
source:
variables:
- name: containers
expression: 'has(variables.anyObject.spec.containers) ? variables.anyObject.spec.containers : []'
- name: initContainers
expression: 'has(variables.anyObject.spec.initContainers) ? variables.anyObject.spec.initContainers : []'
- name: ephemeralContainers
expression: 'has(variables.anyObject.spec.ephemeralContainers) ? variables.anyObject.spec.ephemeralContainers : []'
- name: exemptImagePrefixes
expression: |
!has(variables.params.exemptImages) ? [] :
variables.params.exemptImages.filter(image, image.endsWith("*")).map(image, string(image).replace("*", ""))
- name: exemptImageExplicit
expression: |
!has(variables.params.exemptImages) ? [] :
variables.params.exemptImages.filter(image, !image.endsWith("*"))
- name: exemptImages
expression: |
(variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
container.image in variables.exemptImageExplicit ||
variables.exemptImagePrefixes.exists(exemption, string(container.image).startsWith(exemption))
).map(container, container.image)
- name: badContainers
expression: |
(variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
!(container.image in variables.exemptImages) &&
(has(container.securityContext) && has(container.securityContext.privileged) && container.securityContext.privileged == true)
).map(container, "Privileged container is not allowed: " + container.name +", securityContext: " + container.securityContext)
- name: isUpdate
expression: has(request.operation) && request.operation == "UPDATE"
validations:
- expression: variables.isUpdate || size(variables.badContainers) == 0
messageExpression: 'variables.badContainers.join("\n")'
- engine: Rego
source:
rego: |
package k8spspprivileged
import data.lib.exclude_update.is_update
import data.lib.exempt_container.is_exempt
violation[{"msg": msg, "details": {}}] {
# spec.containers.privileged field is immutable.
not is_update(input.review)
c := input_containers[_]
not is_exempt(c)
c.securityContext.privileged
msg := sprintf("Privileged container is not allowed: %v, securityContext: %v", [c.name, c.securityContext])
}
input_containers[c] {
c := input.review.object.spec.containers[_]
}
input_containers[c] {
c := input.review.object.spec.initContainers[_]
}
input_containers[c] {
c := input.review.object.spec.ephemeralContainers[_]
}
libs:
- |
package lib.exclude_update
is_update(review) {
review.operation == "UPDATE"
}
- |
package lib.exempt_container
is_exempt(container) {
exempt_images := object.get(object.get(input, "parameters", {}), "exemptImages", [])
img := container.image
exemption := exempt_images[_]
_matches_exemption(img, exemption)
}
_matches_exemption(img, exemption) {
not endswith(exemption, "*")
exemption == img
}
_matches_exemption(img, exemption) {
endswith(exemption, "*")
prefix := trim_suffix(exemption, "*")
startswith(img, prefix)
}
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/template.yaml
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sPSPPrivilegedContainer
metadata:
name: psp-privileged-container
spec:
match:
kinds:
- apiGroups: [""]
kinds: ["Pod"]
excludedNamespaces: ["kube-system"]
Usage
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/constraint.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-privileged-disallowed
labels:
app: nginx-privileged
spec:
containers:
- name: nginx
image: nginx
securityContext:
privileged: true
Usage
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/example_disallowed.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-privileged-allowed
labels:
app: nginx-privileged
spec:
containers:
- name: nginx
image: nginx
securityContext:
privileged: false
Usage
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/example_allowed.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-privileged-disallowed
labels:
app: nginx-privileged
spec:
ephemeralContainers:
- name: nginx
image: nginx
securityContext:
privileged: true
Usage
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/disallowed_ephemeral.yaml
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sPSPPrivilegedContainer
metadata:
name: psp-privileged-container
spec:
match:
kinds:
- apiGroups: [""]
kinds: ["Pod"]
excludedNamespaces: ["kube-system"]
parameters:
exemptImages:
- "safeimages.com/*"
Usage
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/constraint.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-privileged-disallowed
labels:
app: nginx-privileged
spec:
containers:
- name: nginx
image: nginx
securityContext:
privileged: true
Usage
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/example_disallowed.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-privileged-allowed
labels:
app: nginx-privileged
spec:
containers:
- name: nginx
image: nginx
securityContext:
privileged: false
Usage
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/example_allowed.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-privileged-disallowed
labels:
app: nginx-privileged
spec:
ephemeralContainers:
- name: nginx
image: nginx
securityContext:
privileged: true
Usage
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/disallowed_ephemeral.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-privileged-allowed-exempt
labels:
app: nginx-privileged
spec:
containers:
- name: nginx
image: safeimages.com/nginx
securityContext:
privileged: true
Usage
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/pod-security-policy/privileged-containers/samples/psp-privileged-container/example_allowed_exempt.yaml