Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from k8s-at-home/fix-and-feat
Browse files Browse the repository at this point in the history
Add tests directory try wiring in CI
  • Loading branch information
onedr0p authored Apr 13, 2021
2 parents 4d48118 + 454d9ff commit dde7faa
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Sops
.decrypted~*.yaml
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ repos:
- id: check-merge-conflict
- id: detect-private-key
- id: trailing-whitespace
- repo: https://github.com/Lucas-C/pre-commit-hooks-markup
rev: v1.0.1
hooks:
- id: rst-linter
- repo: https://github.com/adrienverge/yamllint
rev: v1.25.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name: Verify sops files
description: Verify that sops files are encrypted.
language: script
files: ((^|/)*.y[a]{0,1}ml$)
files: ((^|/)*.(ya?ml)$)
entry: find-unencrypted-secrets.sh
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# sops-pre-commit

[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/k8s-at-home/sops-pre-commit/main.svg)](https://results.pre-commit.ci/latest/github/k8s-at-home/sops-pre-commit/main)

Sops [pre-commit](https://pre-commit.com/) hook.

* Check for unencrypted Kubernetes secrets in manifest files.
Expand Down
35 changes: 26 additions & 9 deletions find-unencrypted-secrets.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
#!/bin/sh
## angelnu k8s@home
FILE_WITH_SECRETS=$(grep -lZRPi '^kind:\s+secret' . | xargs -r0 grep -L 'ENC.AES256')
if [ -z "$FILE_WITH_SECRETS" ]; then
exit 0
else
echo "$FILE_WITH_SECRETS has unencrypted secrets! (or at least not encrypted with AES256)"
exit 1
fi
#!/usr/bin/env bash
set -eu

# OSX GUI apps do not pick up environment variables the same way as Terminal apps and there are no easy solutions,
# especially as Apple changes the GUI app behavior every release (see https://stackoverflow.com/q/135688/483528). As a
# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here.
export PATH=$PATH:/usr/local/bin

secret_regex="^kind:\s+secret"
sops_regex="ENC.AES256"

has_error=0
for file in "$@"; do
if (grep -q -i -P "${secret_regex}" "${file}"); then
if ! (grep -q -P "${sops_regex}" "${file}"); then
echo "ERROR: ${file} is not encrypted"
has_error=1
fi
fi
done

if [[ "${has_error}" -eq 1 ]] ; then
echo "To ignore, use --no-verify"
fi

exit $has_error
8 changes: 8 additions & 0 deletions tests/secret-fail.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
data:
password: Y2hhbmdlLW1l
user: YWRtaW4=
kind: Secret
metadata:
creationTimestamp: null
name: basic-auth
8 changes: 8 additions & 0 deletions tests/secret-fail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
data:
password: Y2hhbmdlLW1l
user: YWRtaW4=
kind: Secret
metadata:
creationTimestamp: null
name: basic-auth
8 changes: 8 additions & 0 deletions tests/secret-ignore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
data:
password: Y2hhbmdlLW1l
user: YWRtaW4=
kind: Secret
metadata:
creationTimestamp: null
name: basic-auth
9 changes: 9 additions & 0 deletions tests/secret-ignore.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: v1
kind: Secret
metadata:
name: ca-key-pair
namespace: {{ cert_manager_namespace }}
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURvRENDQW9pZ0F3SUJBZ0lVYXRUWVNIK1lUMVJvbXVGekF2clFRWGtsQ0Vrd0RRWUpLb1pJaHZjTkFRRU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nOWo5NzVTOEl5OUxsR3F5bytjcTl5UUN6K2tLN0pObwozWldCMTJnMmRucGZnNm8zM25LMUpaY0FFVHBVdkwzanZvbFFDQjZCclV1RHozSTlQWE5BNzJEdGROSmVvV254CnJpQWxaU09wQzlSNm1OM3l2UHJTNHdLQmdCQS9WWWRPY0pOUS9kcHFyZjdLNDlZVmNiKzFlekVkWDg2WGVJVFgKaUN6VDNnU1dQZVJReUlCOUNnWVR4NklteUNrTTYyK3V6MHFnSkJRY0dxQzBCTVlvM3duWEtXVTBSTEpPbW9BRgpvYzdLY1prNXlrVDR4VEwzK0lSTnZuUXNYL1lKS045RUlFVHdNUDJycTRkbXYzR1FuaEg2eWlndzM0SEhMTmozCkN4alhBb0dBSjBUNkN0c1c2dEVpYUI5bnc4enI3M2xkMDhraDZSL3B4VHF5c2diNERFTmptd2dndUFoMlJSZkwKYVg3eTNqSUNOTFBjWEFOYlB0QmYrQkRBTTl0UTEzMk5hYzg3N016RHRVSyswem9CWWtwWGM4Rkd4akVuTzc5RQp2MC9vT2wzR2RaWnNJSXhLblcvVlVmYjJydGY1RWgyQytOY1FpWkNXZm5kWkthMXR4WjQ9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
38 changes: 38 additions & 0 deletions tests/secret-pass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# yamllint disable
apiVersion: v1
kind: Secret
metadata:
name: example
stringData:
EXAMPLE: ENC[AES256_GCM,data:Y4nfpPpucxeNpAAMMePkhwia1QicYay1JEOOf2jrSmov0UGXZfndgXJmt7snzmxkqyHFoZX8N+Cpv6pEhu2BzUiKaAt85V2ugq9y4WWmNj4suNAroP4bvS0eC+lB3xc92wDFOjh7ogZyuykYA3sQTlSjOoA+Z1uhQMMoaoQu,iv:xrMWtO7aPHr9q2MX9i1jEUpZMtkcSs0KHLtNvEhyH9k=,tag:rloLPaXG9j5fB7R/Cbzuzg==,type:str]
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
age: []
lastmodified: "2021-04-13T00:49:47Z"
mac: ENC[AES256_GCM,data:c+LD6ZbMjpKLrV2XsG4pz3f88ZwQ0xYNDis+cqvPzCIun517SqaXLQo6FR3FRjj+5H/fhYShTwhBjYxFM0Axfe3ccpamELrCmCOeOSABI1EvOph1VsL5fL6MhxBKUV02I3FHjwCWPSNI3T2GTIuKyEzEzQ/uzHbBisVZ0L+j81k=,iv:Vr4VBIfJrcbEFZjJJc4j8Zk128qMQ23xlafHTyZAp84=,tag:IF93M1sFQcCD8p6u0gqzlQ==,type:str]
pgp:
- created_at: "2021-04-12T17:08:42Z"
enc: |
-----BEGIN PGP MESSAGE-----
hQIMAwfpRihAg/tGARAA0XXtTCCkZjUccud57VF8vqqen1K+YJIKXAkALQ7m+NvQ
sqtnMEzXB5+eeT0ne35YZIEYiP8BCnQycn4YCxg3tl7uqIe+jCxt/gtzvJlt5xMS
skjI3OWDfRuuMMQQqzeRQwbiwT0qUd199opb1TBXV3doSvpvhqwUapJ5+eum+Swy
x0bb+x+dqpZw5AZf1dhVYN/KTACHkrlOgFVlldI4RYIt/0yBLg5gb4oco2oJQLhM
NpqorNXe/qt4L21v3ZdH3relXQbIFnjv0fIIWfsSSbpJYvWFGbr8p8bMZ8fdMiIE
siDP03DfsXi0KhrDV88hBPg9eYjnRvGzZGWyUY1DZVIb6Lx689YEveXgHxoMhaH/
XWgiYm616ZrqhKEfurqKSxdZqqe64CxR0wnrMXEIrYpoi98Pxu9dfuVAWTowtBma
ufIm9bRUWOclJUt7LnZ0eXL6h6/HvPXVdlaCiYhc7WjW3VdCJsf2Te5ADIwSP6UZ
yQEWmXJBxDkPbos74c3oPEmf+UzH4BNx2azq+lwEBFF/LsMez+fz0B2cdE6RL9Ub
418C64rQks3OyXDHanRXAEX+CpyKqOAM1+ag/rR/tcOtInQtcH5RmS4ahSEXSOLx
17u9lZQs3XbAudrv8ZSYSYRmhhcPF4EutR6etg+rl7+eX3UZ4c4rlH8zjekBNzbS
XAEEbNB8h8A2cqi/h3AaEjn5jwMbWXWDwAn9cMpKsX7q1eKDjF1sKOYPjenxWFGC
ufN7XNIW5gxfIV3MAS04L37RAy/G5hYpigwbP2xDGUgJqYSAecfNV0uiDRkj
=r1XG
-----END PGP MESSAGE-----
fp: 673F9E296113BAE74D9954A2A92853A46EA01574
encrypted_regex: ((?i)(pass|secret($|[^N])|key|token|^data$|^stringData))
version: 3.7.1
40 changes: 40 additions & 0 deletions tests/secret-pass.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# yamllint disable
apiVersion: ENC[AES256_GCM,data:EB4=,iv:OmAbqRBqdMhIyBFpaAvxGmEQYaZjLijMPEo5ZYc0ySU=,tag:vDfHvfO/WIFXM+hxHPVZFA==,type:str]
data:
password: ENC[AES256_GCM,data:mTRYYopHASkVUB2E,iv:JacQOg+UMokmgnf8x7UM7sBT6zfqdVPXNYaBmbel094=,tag:nLDJp9DD8u8KJoP+0eV/Cw==,type:str]
user: ENC[AES256_GCM,data:esGa8mFfoso=,iv:AvYQ6esRdHgHoLdFWUWNCjMg29D6BYZnrCRQ8Y5GsjY=,tag:3LUeuLG7pxpgLBZYfn68xg==,type:str]
kind: ENC[AES256_GCM,data:jSSHvCrN,iv:TugXD0VM+DSuj8T8kI0J4KJC7CDSDoJ7x51ZYBs+pCw=,tag:t0SMsdjbJ2+ITayIdFSuJA==,type:str]
metadata:
creationTimestamp: null
name: ENC[AES256_GCM,data:/Axsfljw/5ppcQ==,iv:SSrGABB8b4DP1x+6gNig5epkr5zvFcJbEyMiVDhIPPc=,tag:SZsiRFh73gRo7HoI36DbsA==,type:str]
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
age: []
lastmodified: "2021-04-13T12:33:20Z"
mac: ENC[AES256_GCM,data:AEU+d6nM5PYEu5m+xPrDGWf8JQA47is0o6yAXoL05Hv5FKAhacmuOEvrze+W3yb/v68rj5i4BT3EuLkLm70cWw+WqLsugtjaWcdOvGCTyFEBMyPKfp4cBtGhF/X+iVsB0i9hhfOwZkZ1EtCTwVTjGfGvg+YX1rz+9ZGgg1EGpGA=,iv:T86Jgobt/Ov554hsZQKvGdcEitNUU75oZuzU1ItMWMs=,tag:pA8co3VkKgCGCrKzYRlcyQ==,type:str]
pgp:
- created_at: "2021-04-13T12:33:19Z"
enc: |
-----BEGIN PGP MESSAGE-----
hQIMA//CYHpV/IETAQ/+N1fzCqcfxnChiwfig6gE8bNJZ6RSyYhsl9iDK1ePQIPj
93ulRKK2y7741ylPBB4tRXTD8rEYC97VkNSN291CFC818jhFad8L5qiQfcesmUB/
tl8HnX8MsRb2rjn2PlEugL5XqmXtDCFCMZ1T2RAX1zpN34BUCDTTdD0kzXgwDHZL
KRB6rWwnG3SEmxzMcq5Nev+E3m5Be8BggFOMzy7Mdb/NDyNybV/dyOz8RhgLrfFx
qUG7E7tWWVMksLfs4PB3JkysTRhSJpy2VV2FpaxqIFsTHLVFxM587b64b/yqmpGY
f8pOw4heItbgtHrFOXjLhMwZYHBnSEdimGq/V13dr7XTmvU8w4pytU8cUSJ/UhVZ
IdVUbHQo0Yw+947wjDWVVn2XsixNn5vyn2ffMdvngL5QLrVL5tlqNTKElStDRpWj
0/+yt/bXBP7m8OeEicAwaLLMHCix41oWe950/MM/peEB6giS2ONnh28zv12D05ub
JNgON00+6AJQE5ztlxNORtND9miXGOGqk1P27BQWy7cOd1cQMHgTCB1RmPkfqApD
1lzO2JHfoFDlbRmWJAkoCQnSONut7pwlQMoyh1iEA0LPCkuqaHrNEXkQZh5S3ubT
wcgrU2OV+SUpUkTXTFlRNCLucFufnelsAvSAMNVyiJM8fHQ0hTC9ttMqSsWm2n3S
XgEXnY4f2yXApFS+LYWmht+ENrl44u8WMFHShc+h+URnqcMX1DaxnEzUW1BC+ykV
5Q8jN0acUstjvP4VnGDCihI/+ADQ2f/TKDOcUP80xf3PLTqQiXL3AnvZsisWAAk=
=G3Gh
-----END PGP MESSAGE-----
fp: A54D8FB506C103352E67737587CB975CFF2E7D8F
unencrypted_suffix: _unencrypted
version: 3.7.1

0 comments on commit dde7faa

Please sign in to comment.