-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add sops.make for mozillas sops encryption. cleaned up comments (#24)
* added a new sops.make for mozillas sops. * added sops decrypt to tests * test for sops * get test in for vault.decrypt * change builder base * fix gpg import and base docker * minor readme tweak.
- Loading branch information
Showing
12 changed files
with
121 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
# NEVER CHECK IN | ||
# dotenv is for user environment for testing and development | ||
# below are some options for override | ||
# for a list of what your make build is currently using run `make log-vars` | ||
# Copy and rename this to a .env to override variables for testing and development | ||
# Copy to a secrets.env if data is sensitive | ||
# `make log-vars` shows what is defined in .env and will not show whats in .secrets.env | ||
|
||
# if not storing GITHUB_TOKEN in bash ENV then set it here | ||
# if not storing GITHUB_TOKEN in bash ENV then set it in .secrects.env | ||
# GITHUB_TOKEN=gp123l4j1234lkj | ||
|
||
# Some releasing targets depend on ACTIVE_BRANCH being set, which is normally only set when its a CI | ||
# these can help with simulation or manual deploys | ||
# Set this to a "releasable" branch and some targets such as publish-release or kube.deploy will be active | ||
# ACTIVE_BRANCH=master | ||
# MAVEN_REPO_KEY = xxx | ||
# MAVEN_REPO_USER = yyy | ||
|
||
# to test some of the CIRCLE targets | ||
# CIRCLECI=true | ||
# CIRCLE_BRANCH=master | ||
# this is the org | ||
# CIRCLE_PROJECT_USERNAME=yakworks | ||
# CIRCLE_PROJECT_REPONAME=gorm-tools | ||
|
||
# `make log-vars` should show this | ||
# dummy, should show up in log-vars | ||
FOO=bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# josh 54B2, joanna FC1B, 9cibot C575, Ken EFC9 | ||
creation_rules: | ||
- pgp: >- | ||
54B28047704C36FDCB30E63B472AC57FC3EB83C8, | ||
C5758A15DF91198CF5347A90F8E8B460302AAEFA, | ||
FC1B46ABD5AE6A99E31165E42DCB557950992300, | ||
EFC9CC2C54F7387675F435F4D51CED1BA3F5E95E |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
# tell shipkit where the main build.sh is, not used in test | ||
# build.sh := ./build.sh | ||
|
||
# If setting any vars needed for the $(shell init_vars..) in Shipkit.make then track the MAKE_VARS so those dont get added | ||
# if not git is installed then need to add the PROJECT_FULLNAME, much easier to add a build.sh and do it there | ||
# if not git is installed then need to add the PROJECT_FULLNAME, much easier to add a build.yml and do it there | ||
# export PROJECT_FULLNAME = yakworks/shipkit | ||
# BUILD_VARS = PROJECT_FULLNAME # need this in order for it to build what vars get passed the $(shell) | ||
# core include, creates the makefile.env for the BUILD_VARS that evrything else depends on | ||
include Shipkit.make | ||
include $(SHIPKIT_MAKEFILES)/base-build.make | ||
include $(SHIPKIT_MAKEFILES)/docker.make | ||
include $(SHIPKIT_MAKEFILES)/secrets.make | ||
# include $(SHIPKIT_MAKEFILES)/secrets.make | ||
include $(SHIPKIT_MAKEFILES)/vault.make | ||
include $(SHIPKIT_MAKEFILES)/git-tools.make | ||
include $(SHIPKIT_MAKEFILES)/ship-version.make | ||
include $(SHIPKIT_MAKEFILES)/circle.make | ||
include $(SHIPKIT_MAKEFILES)/bats-testing.make | ||
|
||
# -- Variables --- | ||
export BOT_EMAIL ?= [email protected] | ||
export VAULT_URL = https://github.com/9ci/vault.git | ||
# can be set here but best do it on command line with make | ||
# export LOGIT_DEBUG_ENABLED := true | ||
|
||
# --- Dockers --- | ||
docker_tools := $(SHIPKIT_BIN)/docker_tools | ||
DOCK_SHELL_URL = yakworks/builder:bash-make | ||
DOCK_SHELL_URL = yakworks/builder:base | ||
|
||
## docker shell for testing | ||
docker.shell: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Opinionated process to clone and decrypt a github project use as a "vault | ||
# installs sops if not present on OS, will not be for build dockers, for local dev should already be there | ||
# clones the github repo in VAULT_DIR, we call it the vault | ||
|
||
SOP_VERSION := 3.7.1 | ||
SOP_URL := https://github.com/mozilla/sops/releases/download/v$(SOP_VERSION)/sops-v$(SOP_VERSION).linux | ||
VAULT_DIR ?= $(BUILD_DIR)/vault | ||
VAULT_FILES ?= bot.enc.env | ||
VAULT_BOT_ENV_FILE := $(VAULT_DIR)/bot.env | ||
|
||
# --- look for build/vault/bot.env , run sops.decrypt-vault-files -- | ||
# we import it straight into make since these are secrets, dont want them in BUILD_VARS where they can get logged | ||
|
||
ifneq ($(wildcard $(VAULT_BOT_ENV_FILE)),) | ||
include $(VAULT_BOT_ENV_FILE) | ||
VAULT_ENV_VARS := $(shell sed '/^#.*/d; /^$$/d; s/=.*//g;' $(VAULT_BOT_ENV_FILE)) | ||
# $(info including $(VAULT_ENV_VARS) from $(VAULT_ENV_FILE)) | ||
export $(VAULT_ENV_VARS) | ||
endif | ||
# --- | ||
|
||
SOP_SH := $(shell which sops 2> /dev/null) | ||
|
||
# if doesn't already exists then above will be empty | ||
ifeq ($(SOP_SH),) | ||
|
||
SOP_SH := $(SHIPKIT_INSTALLS)/sops | ||
# $(info sops is NOT installed) | ||
|
||
endif | ||
|
||
# on demand clone and install of git-secret for build dockers | ||
# as a make reminder, if the file ref SOP_SH doesn't exist then this runs, if its there already then this does nothing | ||
$(SOP_SH): | ||
$(logr) "intalling sops $(SOP_URL)" | ||
# make sure installs is created | ||
mkdir -p $(SHIPKIT_INSTALLS) | ||
curl -qsL $(SOP_URL) -o $(SOP_SH) | ||
chmod +x $(SOP_SH) | ||
$(logr.done) | ||
|
||
# easier for testing | ||
sops.install: $(SOP_SH) | ||
|
||
vault.clone: | _verify_VAULT_URL | ||
[ ! -e $(VAULT_DIR) ] && git clone $(VAULT_URL) $(VAULT_DIR) || :; | ||
|
||
vault.decrypt-files: $(SOP_SH) gpg.import-private-key vault.clone | ||
cd $(VAULT_DIR) | ||
for vfile in $(VAULT_FILES); do | ||
outFile="$${vfile/.enc./.}" # remove .enc. | ||
outFile="$${outFile/.encrypted./.}" # remove .encrypted. | ||
$(logr) "$$vfile > $$outFile" | ||
$(SOP_SH) -d $$vfile > $$outFile | ||
done | ||
$(logr.done) | ||
|
||
# to test the gpg stuff set this to the base64 encoded key, DO NOT CHECK IN | ||
# GPG_KEY=ZZZ | ||
# set this to the gpg passphrase if needed, not base64 | ||
# GPG_PASS := xxx | ||
|
||
# imports private key from GPG_PRIVATE_KEY var | ||
gpg.import-private-key: | ||
if [ "$(GPG_KEY)" ]; then | ||
echo "$(GPG_KEY)" | base64 --decode | gpg -v --batch --import --quiet --no-verbose | ||
$(logr) "GPG_KEY imported" | ||
else | ||
$(logr) "GPG_KEY not set, no key to import" | ||
fi | ||
|
||
# encrypts a dummy file so that it doesnt ask again for passphrase when sops is run | ||
# this is only needed if using a private key that has passphrase | ||
gpg.passphrase: | ||
if [ "$(GPG_PASS)" ]; then | ||
touch build/dummy.txt | ||
# a bit remarkable that this is what it takes but it is. | ||
echo $(GPG_PASS) | gpg -q --sign --batch --pinentry-mode loopback --passphrase-fd 0 --output /dev/null --yes build/dummy.txt | ||
fi | ||
|
||
# gpg above --batch doesn't ask for prompt and -v is verbose |