<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Automation on make me: APe</title><link>https://apealive.net/tags/automation/</link><description>Recent content in Automation on make me: APe</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 29 Jun 2022 11:59:46 +0000</lastBuildDate><atom:link href="https://apealive.net/tags/automation/index.xml" rel="self" type="application/rss+xml"/><item><title>SOPS Secrets Management Integration inside Makefiles</title><link>https://apealive.net/snippets/sops-makefile-seal-unseal/</link><pubDate>Wed, 29 Jun 2022 11:59:46 +0000</pubDate><guid>https://apealive.net/snippets/sops-makefile-seal-unseal/</guid><description>&lt;p&gt;This article covers &lt;strong&gt;SOPS Secrets Management Integration inside Makefiles&lt;/strong&gt;, originally published as a secure &lt;a href="https://gist.github.com/epcim/2738c2d95f62eea9e73772eda574cf50" target="_blank" rel="noopener noreferrer"&gt;GitHub Gist&lt;/a&gt;
 snippet.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;seal-sops: ## SOPS Encrypt all secrets path matching [_sec|secret|config|*.secret*]
	@find $(PTH) -path &amp;#34;*/_sec/*&amp;#34; -type f -o -path &amp;#34;*/secret/*&amp;#34; -type f -o -path &amp;#34;*/config/*&amp;#34; -name &amp;#34;*.secret*&amp;#34; -type f |\
		egrep -v &amp;#39;(\.enc|\.asc|\.sealed|\.matrix)&amp;#39; |\
		while read file; do \
		 ./scripts/seal-sops $$file;\
		done;


unseal-sops: ## SOPS Decrypt all secrets (suffix: .enc and .enc.yaml)
	@find $(PTH) -name &amp;#34;*.enc&amp;#34; -type f -o -name &amp;#34;*.enc.*&amp;#34; -type f |\
		while read file; do \
		 ./scripts/unseal-sops $$file;\
		done;
#!/bin/bash -e


# sops-seal, encrypt file if modified (adds .enc before(as) its suffix)
sops-seal() {


 file=$1
 fullname=&amp;#34;${file##*/}&amp;#34;
 dirname=&amp;#34;${file%/*}&amp;#34;
 basename=&amp;#34;${fullname%.*}&amp;#34;
 extension=&amp;#34;.${fullname##*.}&amp;#34;


 # If the file is in the same directory with the script,
 # path likely will not include any directory seperator.
 [[ &amp;#34;$dirname&amp;#34; == &amp;#34;$path&amp;#34; ]] &amp;amp;&amp;amp; dirname=&amp;#34;.&amp;#34;


 # If the file has no extension, correct the variable accordingly.
 [[ &amp;#34;$extension&amp;#34; == &amp;#34;.$basename&amp;#34; ]] &amp;amp;&amp;amp; extension=&amp;#34;&amp;#34;


 # Destination file
 dest=&amp;#34;${dirname}/${basename}.enc${extension}&amp;#34;;


 [[ ! -e &amp;#34;$dest&amp;#34; ]] &amp;amp;&amp;amp; {
 sops -e --output &amp;#34;$dest&amp;#34; &amp;#34;$file&amp;#34;;
 } || {
 # if changed
 diff $file &amp;lt;(sops --config ${SOPS_CONFIG:-.sops.yaml} -d &amp;#34;$dest&amp;#34;) &amp;gt; /dev/null ||\
 { rm &amp;#34;$dest&amp;#34;; echo &amp;#34; ${dest}&amp;#34;; sops -e --config ${SOPS_CONFIG:-.sops.yaml} --output &amp;#34;$dest&amp;#34; &amp;#34;$file&amp;#34;;};
 }
 git add -f ${dest} 
}


sops-seal $@
#!/bin/bash


# sops-unseal, decrypt files (while removing `.enc.` file.enc.suffix)
sops-unseal() {
 for file in $(ls $@); do
 ex=&amp;#34;.${file##*.}&amp;#34;;
 fp=&amp;#34;${file%.enc*}&amp;#34;;
 #[[ &amp;#34;$ex&amp;#34; == &amp;#34;.$fp&amp;#34; ]] &amp;amp;&amp;amp; ex=&amp;#34;&amp;#34; # fix, no filename suffix
 dest=&amp;#34;$fp${ex#.enc}&amp;#34;;


 echo &amp;#34; ${dest}&amp;#34;;
	sops -d --config ${SOPS_CONFIG:-.sops.yaml} --output &amp;#34;$dest&amp;#34; &amp;#34;$file&amp;#34;; \
 done
}


sops-unseal $@
&lt;/code&gt;&lt;/pre&gt;</description></item></channel></rss>