From patchwork Tue Feb 22 12:51:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 5256 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) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4K2zbJ56VTz3xgm for ; Tue, 22 Feb 2022 12:52:28 +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) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4K2zZq0xx4z5Z7; Tue, 22 Feb 2022 12:52:03 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4K2zZk45wfz32Nr; Tue, 22 Feb 2022 12:51:58 +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) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4K2zZh55KVz315x for ; Tue, 22 Feb 2022 12:51:56 +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 4K2zZh15DCz5SZ; Tue, 22 Feb 2022 12:51:56 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1645534316; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TMyZCCxN1VUQiEwhd2QZqezlDG16Lnh+U/ZmE2NMaI0=; b=MwOgAknnY0AHzt2ACXNjCTC6sTREYOHxUiImC61hEGUU66i9FnPvYjAybGJmnJqiCDbHrG BT6wdcloukW2DoBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1645534316; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TMyZCCxN1VUQiEwhd2QZqezlDG16Lnh+U/ZmE2NMaI0=; b=gfoNaTIiZqA8FRaBUDqlcnAQBC+1ZNIjJ44c3n+fFNFCewOdfBV2CBLRRaLZeNu2QiWo6T 3b4Ufj4nsVbWaSV8wrtuJ31n+SVjKpKx7+ejQQvqEExZZpvyCV22fnelIjsXPB8y5OxxYS 2DchE9LQkfj85/GdFN8QLnJ07wnjByC0H+C9wFyt7R4L9Sv1furQilOz6/Cj7tNVx6JO7t Zo01dhySeZbWFOHDetsiHqbUctZoQ29EMHz685qo7ADQ1f1+xs4ljlT8dCLhBHYbtHYmug OUMJ63gD1q+Jmk8BVsFPTC2WjVi+nGmU2ocZ6nkwmbOlMtgxLePMJsPhEKbmug== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH 33/50] oci: user-data: Try to decode base64 content Date: Tue, 22 Feb 2022 12:51:18 +0000 Message-Id: <20220222125135.1211290-34-michael.tremer@ipfire.org> In-Reply-To: <20220222125135.1211290-1-michael.tremer@ipfire.org> References: <20220222125135.1211290-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 4dbc05ae3..782fde5a2 100644 --- a/src/initscripts/helper/oci-setup +++ b/src/initscripts/helper/oci-setup @@ -34,6 +34,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}" @@ -134,6 +152,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