├── .github └── workflows │ ├── release.yml │ └── test.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── action.yml ├── src ├── entrypoint.sh ├── install.sh └── run.sh └── test ├── kustomize ├── deployment.yaml ├── hpa.yaml └── kustomization.yaml └── policy ├── deny.rego └── kubernetes.rego /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | on: 3 | push: 4 | tags: 5 | - 'v*' 6 | workflow_dispatch: 7 | inputs: 8 | tag: 9 | description: 'image tag prefix' 10 | default: 'rc' 11 | required: true 12 | 13 | jobs: 14 | push-container: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Prepare 19 | id: prep 20 | run: | 21 | VERSION="${{ github.event.inputs.tag }}-${GITHUB_SHA::8}" 22 | if [[ $GITHUB_REF == refs/tags/* ]]; then 23 | VERSION=${GITHUB_REF/refs\/tags\//} 24 | fi 25 | echo ::set-output name=BUILD_DATE::$(date -u +'%Y-%m-%dT%H:%M:%SZ') 26 | echo ::set-output name=VERSION::${VERSION} 27 | - name: Login to Docker Hub 28 | uses: docker/login-action@v1 29 | with: 30 | username: stefanprodan 31 | password: ${{ secrets.DOCKER_PASSWORD }} 32 | - name: Login to GitHub Container Registry 33 | uses: docker/login-action@v1 34 | with: 35 | registry: ghcr.io 36 | username: stefanprodan 37 | password: ${{ secrets.GHCR_TOKEN }} 38 | - name: Push image 39 | uses: docker/build-push-action@v2 40 | with: 41 | push: true 42 | tags: | 43 | ghcr.io/stefanprodan/kube-tools:${{ steps.prep.outputs.VERSION }} 44 | ghcr.io/stefanprodan/kube-tools:latest 45 | docker.io/stefanprodan/kube-tools:${{ steps.prep.outputs.VERSION }} 46 | docker.io/stefanprodan/kube-tools:latest 47 | labels: | 48 | org.opencontainers.image.title=${{ github.event.repository.name }} 49 | org.opencontainers.image.source=${{ github.event.repository.html_url }} 50 | org.opencontainers.image.revision=${{ github.sha }} 51 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | validate: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - name: conftest 11 | uses: ./ 12 | with: 13 | command: | 14 | kustomize build test/kustomize | conftest test -p test/policy - 15 | - name: kubeval 16 | uses: ./ 17 | with: 18 | command: | 19 | kustomize build test/kustomize | kubeval --strict --ignore-missing-schemas 20 | - name: tools 21 | uses: ./ 22 | with: 23 | command: | 24 | kubectl version --client 25 | kustomize version 26 | helm version --client 27 | helmv3 version 28 | kubeval --version 29 | conftest --version 30 | kubeseal --version 31 | yq --version 32 | jq --version 33 | go version 34 | kubeaudit --help 35 | kubeconform --help 36 | kyverno version 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.17 2 | 3 | COPY LICENSE README.md / 4 | COPY src/ / 5 | RUN /install.sh 6 | 7 | ENTRYPOINT ["/entrypoint.sh"] 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TAG?=v1 2 | 3 | build: 4 | docker build -t stefanprodan/kube-tools:$(TAG) . -f Dockerfile 5 | 6 | push: 7 | docker push stefanprodan/kube-tools:$(TAG) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kube-tools 2 | 3 | The kube-tools GitHub Action has been deprecated in favor of 4 | [Arkade](https://github.com/alexellis/arkade) which offers overs 100 CLI tools. 5 | 6 | To migrate your workflows from kube-tools to Arkade, 7 | you can use the [arkade-get](https://github.com/alexellis/arkade-get) 8 | GitHub Action as a drop-in replacement. 9 | 10 | Example: 11 | 12 | ```yaml 13 | - uses: alexellis/setup-arkade@v1 14 | - uses: alexellis/arkade-get@master 15 | with: 16 | kubectl: latest 17 | kustomize: latest 18 | kubeconform: latest 19 | helm: latest 20 | jq: latest 21 | yq: latest 22 | ``` 23 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Kubernetes toolset' 2 | description: 'Github Action with Kubernetes tools: kubectl, kustomize, helm, kubeval, kubeaudit, conftest, jq, yq, go' 3 | author: 'Stefan Prodan' 4 | branding: 5 | icon: 'command' 6 | color: 'blue' 7 | inputs: 8 | command: 9 | description: 'command to run' 10 | required: true 11 | kubectl: 12 | description: 'kubectl version' 13 | kustomize: 14 | description: 'kustomize version' 15 | helm: 16 | description: 'helm version' 17 | helmv3: 18 | description: 'helm version' 19 | kubeseal: 20 | description: 'kubeseal version' 21 | kubeaudit: 22 | description: 'kubeaudit version' 23 | kubeval: 24 | description: 'kubeval version' 25 | conftest: 26 | description: 'conftest version' 27 | kubeconform: 28 | description: 'kubeconform version' 29 | yq: 30 | description: 'yq version' 31 | kyverno: 32 | description: 'kyverno version' 33 | runs: 34 | using: 'docker' 35 | image: 'Dockerfile' 36 | args: 37 | - ${{ inputs.command }} 38 | - ${{ inputs.kubectl }} 39 | - ${{ inputs.kustomize }} 40 | - ${{ inputs.helm }} 41 | - ${{ inputs.helmv3 }} 42 | - ${{ inputs.kubeseal }} 43 | - ${{ inputs.kubeval }} 44 | - ${{ inputs.conftest }} 45 | - ${{ inputs.kubeconform }} 46 | - ${{ inputs.yq }} 47 | - ${{ inputs.kyverno }} 48 | -------------------------------------------------------------------------------- /src/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | set -o pipefail 5 | 6 | KUBECTL_VER=${2} 7 | if [[ "${KUBECTL_VER}" != "" ]]; then 8 | curl -sL https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VER}/bin/linux/amd64/kubectl \ 9 | -o /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl 10 | fi 11 | 12 | KUSTOMIZE_VER=${3} 13 | if [[ "${KUSTOMIZE_VER}" != "" ]]; then 14 | curl -sL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${KUSTOMIZE_VER}/kustomize_v${KUSTOMIZE_VER}_linux_amd64.tar.gz | \ 15 | tar xz && mv kustomize /usr/local/bin/kustomize 16 | fi 17 | 18 | HELM_VER=${4} 19 | if [[ "${HELM_VER}" != "" ]]; then 20 | curl -sL https://get.helm.sh/helm-v${HELM_VER}-linux-amd64.tar.gz | \ 21 | tar xz && mv linux-amd64/helm /usr/local/bin/helm && rm -rf linux-amd64 22 | fi 23 | 24 | HELM3_VER=${5} 25 | if [[ "${HELM3_VER}" != "" ]]; then 26 | curl -sL https://get.helm.sh/helm-v${HELM3_VER}-linux-amd64.tar.gz | \ 27 | tar xz && mv linux-amd64/helm /usr/local/bin/helmv3 && rm -rf linux-amd64 28 | fi 29 | 30 | KUBESEAL_VER=${6} 31 | if [[ "${KUBESEAL_VER}" != "" ]]; then 32 | curl -sL https://github.com/bitnami-labs/sealed-secrets/releases/download/v${KUBESEAL_VER}/kubeseal-linux-amd64 \ 33 | -o /usr/local/bin/kubeseal && chmod +x /usr/local/bin/kubeseal 34 | fi 35 | 36 | KUBEVAL_VER=${7} 37 | if [[ "${KUBEVAL_VER}" != "" ]]; then 38 | curl -sL https://github.com/instrumenta/kubeval/releases/download/${KUBEVAL_VER}/kubeval-linux-amd64.tar.gz | \ 39 | tar xz && mv kubeval /usr/local/bin/kubeval 40 | fi 41 | 42 | CONFTEST_VER=${8} 43 | if [[ "${CONFTEST_VER}" != "" ]]; then 44 | wget -O conftest https://github.com/open-policy-agent/conftest/releases/download/v${CONFTEST_VER}/conftest_${CONFTEST_VER}_Linux_x86_64.tar.gz -q 45 | tar xzf conftest && mv conftest /usr/local/bin 46 | fi 47 | 48 | KUBECONFORM_VER=${9} 49 | if [[ "${KUBECONFORM_VER}" != "" ]]; then 50 | curl -sSL https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM_VER}/kubeconform-linux-amd64.tar.gz | \ 51 | tar xz && mv kubeconform /usr/local/bin/kubeconform 52 | fi 53 | 54 | YQ_VER=${10} 55 | if [[ "${YQ_VER}" != "" ]]; then 56 | curl -sL https://github.com/mikefarah/yq/releases/download/v${YQ_VER}/yq_linux_amd64 \ 57 | -o /usr/local/bin/yq && chmod +x /usr/local/bin/yq 58 | fi 59 | 60 | KYVERNO_VER=${11} 61 | if [[ "${KYVERNO_VER}" != "" ]]; then 62 | curl -sSL https://github.com/kyverno/kyverno/releases/download/v${KYVERNO_VER}/kyverno-cli_v${KYVERNO_VER}_linux_x86_64.tar.gz | \ 63 | tar xz && mv kyverno /usr/local/bin/kyverno 64 | fi 65 | 66 | echo ">>> Executing command <<<" 67 | echo "" 68 | echo "" 69 | 70 | bash -c "set -e; set -o pipefail; $1" 71 | -------------------------------------------------------------------------------- /src/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | 5 | KUBECTL=1.23.0 6 | echo "downloading kubectl ${KUBECTL}" 7 | curl -sL https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL}/bin/linux/amd64/kubectl \ 8 | -o /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl 9 | kubectl version --client 10 | 11 | KUSTOMIZE=4.4.1 12 | echo "downloading kustomize ${KUSTOMIZE}" 13 | curl -sL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${KUSTOMIZE}/kustomize_v${KUSTOMIZE}_linux_amd64.tar.gz | \ 14 | tar xz && mv kustomize /usr/local/bin/kustomize 15 | kustomize version 16 | 17 | HELM_V2=2.17.0 18 | echo "downloading helm ${HELM_V2}" 19 | curl -sSL https://get.helm.sh/helm-v${HELM_V2}-linux-amd64.tar.gz | \ 20 | tar xz && mv linux-amd64/helm /usr/local/bin/helm && rm -rf linux-amd64 21 | helm version --client 22 | 23 | HELM_V3=3.7.2 24 | echo "downloading helm ${HELM_V3}" 25 | curl -sSL https://get.helm.sh/helm-v${HELM_V3}-linux-amd64.tar.gz | \ 26 | tar xz && mv linux-amd64/helm /usr/local/bin/helmv3 && rm -rf linux-amd64 27 | helmv3 version 28 | 29 | KUBEVAL=0.16.1 30 | echo "downloading kubeval ${KUBEVAL}" 31 | curl -sL https://github.com/instrumenta/kubeval/releases/download/v${KUBEVAL}/kubeval-linux-amd64.tar.gz | \ 32 | tar xz && mv kubeval /usr/local/bin/kubeval 33 | kubeval --version 34 | 35 | KUBEAUDIT=0.16.0 36 | echo "downloading kubeaudit ${KUBEAUDIT}" 37 | curl -sSL https://github.com/Shopify/kubeaudit/releases/download/${KUBEAUDIT}/kubeaudit_${KUBEAUDIT}_linux_amd64.tar.gz | \ 38 | tar xz && mv kubeaudit /usr/local/bin/kubeaudit 39 | kubeaudit --help 40 | 41 | CONFTEST=0.28.3 42 | echo "downloading conftest ${CONFTEST}" 43 | curl -sL https://github.com/open-policy-agent/conftest/releases/download/v${CONFTEST}/conftest_${CONFTEST}_Linux_x86_64.tar.gz | \ 44 | tar xz && mv conftest /usr/local/bin/conftest 45 | conftest --version 46 | 47 | KUBESEAL=0.16.0 48 | echo "downloading kubeseal ${KUBESEAL}" 49 | curl -sL https://github.com/bitnami-labs/sealed-secrets/releases/download/v${KUBESEAL}/kubeseal-linux-amd64 \ 50 | -o /usr/local/bin/kubeseal && chmod +x /usr/local/bin/kubeseal 51 | kubeseal --version 52 | 53 | KUBECONFORM=0.4.12 54 | echo "downloading kubeconform ${KUBECONFORM}" 55 | curl -sSL https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM}/kubeconform-linux-amd64.tar.gz | \ 56 | tar xz && mv kubeconform /usr/local/bin/kubeconform 57 | kubeconform --help 58 | 59 | YQ=4.16.1 60 | echo "downloading yq" 61 | curl -sL https://github.com/mikefarah/yq/releases/download/v${YQ}/yq_linux_amd64 \ 62 | -o /usr/local/bin/yq && chmod +x /usr/local/bin/yq 63 | yq --version 64 | 65 | echo "downloading jq" 66 | curl -sL https://github.com/stedolan/jq/releases/latest/download/jq-linux64 \ 67 | -o /usr/local/bin/jq && chmod +x /usr/local/bin/jq 68 | jq --version 69 | 70 | KYVERNO=1.5.7 71 | echo "downloading kyverno ${KYVERNO}" 72 | curl -sSL https://github.com/kyverno/kyverno/releases/download/v${KYVERNO}/kyverno-cli_v${KYVERNO}_linux_x86_64.tar.gz | \ 73 | tar xz && mv kyverno /usr/local/bin/kyverno 74 | kyverno version 75 | -------------------------------------------------------------------------------- /src/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | 5 | bash -c "${command}" 6 | -------------------------------------------------------------------------------- /test/kustomize/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: podinfo 5 | labels: 6 | app: podinfo 7 | spec: 8 | minReadySeconds: 5 9 | revisionHistoryLimit: 5 10 | progressDeadlineSeconds: 60 11 | strategy: 12 | rollingUpdate: 13 | maxUnavailable: 1 14 | type: RollingUpdate 15 | selector: 16 | matchLabels: 17 | app: podinfo 18 | template: 19 | metadata: 20 | annotations: 21 | prometheus.io/scrape: "true" 22 | prometheus.io/port: "9797" 23 | labels: 24 | app: podinfo 25 | spec: 26 | containers: 27 | - name: podinfod 28 | image: stefanprodan/podinfo:3.1.0 29 | imagePullPolicy: IfNotPresent 30 | ports: 31 | - name: http 32 | containerPort: 9898 33 | protocol: TCP 34 | - name: http-metrics 35 | containerPort: 9797 36 | protocol: TCP 37 | - name: grpc 38 | containerPort: 9999 39 | protocol: TCP 40 | command: 41 | - ./podinfo 42 | - --port=9898 43 | - --port-metrics=9797 44 | - --grpc-port=9999 45 | - --grpc-service-name=podinfo 46 | - --level=info 47 | - --random-delay=false 48 | - --random-error=false 49 | livenessProbe: 50 | exec: 51 | command: 52 | - podcli 53 | - check 54 | - http 55 | - localhost:9898/healthz 56 | initialDelaySeconds: 5 57 | timeoutSeconds: 5 58 | readinessProbe: 59 | exec: 60 | command: 61 | - podcli 62 | - check 63 | - http 64 | - localhost:9898/readyz 65 | initialDelaySeconds: 5 66 | timeoutSeconds: 5 67 | resources: 68 | limits: 69 | cpu: 2000m 70 | memory: 512Mi 71 | requests: 72 | cpu: 100m 73 | memory: 64Mi 74 | -------------------------------------------------------------------------------- /test/kustomize/hpa.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: autoscaling/v2beta1 2 | kind: HorizontalPodAutoscaler 3 | metadata: 4 | name: podinfo 5 | spec: 6 | scaleTargetRef: 7 | apiVersion: apps/v1 8 | kind: Deployment 9 | name: podinfo 10 | minReplicas: 2 11 | maxReplicas: 4 12 | metrics: 13 | - type: Resource 14 | resource: 15 | name: cpu 16 | # scale up if usage is above 17 | # 99% of the requested CPU (100m) 18 | targetAverageUtilization: 99 19 | -------------------------------------------------------------------------------- /test/kustomize/kustomization.yaml: -------------------------------------------------------------------------------- 1 | resources: 2 | - hpa.yaml 3 | - deployment.yaml 4 | 5 | -------------------------------------------------------------------------------- /test/policy/deny.rego: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import data.kubernetes 4 | 5 | name = input.metadata.name 6 | 7 | annotations { 8 | input.spec.selector.template.metadata.annotations["prometheus.io/scrape"] 9 | } 10 | 11 | deny[msg] { 12 | kubernetes.containers[container] 13 | [image_name, "latest"] = kubernetes.split_image(container.image) 14 | msg = sprintf("%s in the %s %s has an image, %s, using the latest tag", [container.name, kubernetes.kind, image_name, kubernetes.name]) 15 | } 16 | 17 | warn[msg] { 18 | kubernetes.is_deployment 19 | not annotations 20 | msg = sprintf("Deployment %s should set prometheus.io/scrape pod annotation", [name]) 21 | } 22 | -------------------------------------------------------------------------------- /test/policy/kubernetes.rego: -------------------------------------------------------------------------------- 1 | package kubernetes 2 | 3 | # Variables 4 | 5 | name = input.metadata.name 6 | 7 | kind = input.kind 8 | 9 | is_service { 10 | input.kind = "Service" 11 | } 12 | 13 | is_deployment { 14 | input.kind = "Deployment" 15 | } 16 | 17 | is_pod { 18 | input.kind = "Pod" 19 | } 20 | 21 | split_image(image) = [image, "latest"] { 22 | not contains(image, ":") 23 | } 24 | 25 | split_image(image) = [name, tag] { 26 | [name, tag] = split(image, ":") 27 | } 28 | 29 | pod_containers(pod) = all_containers { 30 | keys = {"containers", "initContainers"} 31 | all_containers = [c | keys[k]; c = pod.spec[k][_]] 32 | } 33 | 34 | containers[container] { 35 | pods[pod] 36 | all_containers = pod_containers(pod) 37 | container = all_containers[_] 38 | } 39 | 40 | containers[container] { 41 | all_containers = pod_containers(input) 42 | container = all_containers[_] 43 | } 44 | 45 | pods[pod] { 46 | is_deployment 47 | pod = input.spec.template 48 | } 49 | 50 | pods[pod] { 51 | is_pod 52 | pod = input 53 | } 54 | --------------------------------------------------------------------------------