public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
From: Michael Tremer <michael.tremer@ipfire.org>
To: development@lists.ipfire.org
Subject: [PATCH] oci: user-data: Try to decode base64 content
Date: Mon, 21 Feb 2022 17:24:56 +0000	[thread overview]
Message-ID: <20220221172456.1055696-1-michael.tremer@ipfire.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 1332 bytes --]

Terraform only supports sending any shell scripts encoded in base64
which is however not required by Oracle. Therefore we have to test if
the script is encoded or not.

Signed-off-by: Michael Tremer <michael.tremer(a)ipfire.org>
---
 src/initscripts/helper/oci-setup | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/initscripts/helper/oci-setup b/src/initscripts/helper/oci-setup
index 0763a96e7..98b9858d6 100644
--- a/src/initscripts/helper/oci-setup
+++ b/src/initscripts/helper/oci-setup
@@ -15,6 +15,24 @@ get() {
 	wget -qO - "http://169.254.169.254/opc/v1/${file}"
 }
 
+try_base64_decode() {
+	local input="${1}"
+
+	local tmp="$(mktemp)"
+
+	# Try to decode this and return output if successful
+	if base64 -d <<< "${input}" > "${tmp}" 2>/dev/null; then
+		echo "$(<${tmp})"
+
+	# Otherwise just return the input
+	else
+		echo "${input}"
+	fi
+
+	# Cleanup
+	unlink "${tmp}"
+}
+
 to_address() {
 	local n="${1}"
 
@@ -115,6 +133,9 @@ import_oci_configuration() {
 		# Download a startup script
 		local script="$(get instance/metadata/user_data)"
 
+		# Try to decode this
+		script="$(try_base64_decode "${script}")"
+
 		# Execute the script
 		if [ "${script:0:2}" = "#!" ]; then
 			echo "${script}" > /tmp/user-data.script
-- 
2.30.2


             reply	other threads:[~2022-02-21 17:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-21 17:24 Michael Tremer [this message]
2022-02-21 21:32 ` Peter Müller
2022-02-22 10:26   ` Michael Tremer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220221172456.1055696-1-michael.tremer@ipfire.org \
    --to=michael.tremer@ipfire.org \
    --cc=development@lists.ipfire.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox