From patchwork Mon Feb 21 17:24:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 5191 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4K2ThS0dlDz3wtR for ; Mon, 21 Feb 2022 17:25:12 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4K2ThG6z6Vz17x; Mon, 21 Feb 2022 17:25:02 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4K2ThG5ZMlz2yW4; Mon, 21 Feb 2022 17:25:02 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4K2ThF0q44z2xKb for ; Mon, 21 Feb 2022 17:25:01 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4K2ThC2KBqz80; Mon, 21 Feb 2022 17:24:59 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1645464299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=G0rNpRD8dMRQ4PRuOUwiru9GKEHUyEAo5Pj7uFwue40=; b=/7n+WReJ+edCuXQpbdiLtL5S9iPKQSzkyJaZLwgHg3TiP8H0Y0jk4SrryV/YoTLXrmhdac Vp1uI0QChtupjcDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1645464299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=G0rNpRD8dMRQ4PRuOUwiru9GKEHUyEAo5Pj7uFwue40=; b=fAnl5U3qHPdNvL0IhM+7B3ZNnUSyYhCwd5PneppMlDA7CfnyL/k0y4oDbhFB3ovRTahpEe I+FLu+obu4AN7TIcsaZpc1zJe/KNiJW4RlV2iezITBL4mJIcSQG2Ue1EwqYqOkpYQ8eIu1 zhkADbqcvD5X0RLRliG1cn//3gDLfieJ0VnVN95O3dg7H017TIOQPLsEgDmjqhKdmTeJcK 1KyPk6Kbl2gPHjj/MXfmI36rWg/IO94XsgV5TvGdSqyKbxrq1yTsyebAQHa/F9hxzrgw2k fEBdMzwL/RfrvGeaiqGJvH7sQBhF6DSJFrwUfle/8p4dT9yVU9JMbqkLE5WJUg== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH] oci: user-data: Try to decode base64 content Date: Mon, 21 Feb 2022 17:24:56 +0000 Message-Id: <20220221172456.1055696-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" 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 Reviewed-by: Peter Müller --- 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