base64: invalid input error when trying to decode contents of yaml file
-1
votes
1
answer
14245
views
>**What specific syntax must be changed in the bash below to successfully decode the base64 encoded value which is throwing the error below?**
**THE ERROR:**
The following 3 simple commands are typed into the terminal of a RHEL 8 vm running in Azure:
[user@myVM ~]$ myVar=$(az keyvault secret show --name "secretName" --vault-name "vaultName" --query "value")
[user@myVM ~]$ echo $myVar
"very.long.base64.encoded.string.representing.the.original.yaml"
[user@myVM ~]$ echo $myVar | base64 --decode
base64: invalid input
The second command prints what looks like valid base64 encoding of a long string, perhaps a few hundred characters or more encoded.
The error
base64: invalid input
seems to indicate that the base64
program is not able to accept the encoded input into its decode command.
**THE SOURCE DATA:**
The contents of the base64 encoded data above originated in a yaml file with perhaps 20 lines, which was passed through [terraform's fileBase64()
command](https://www.terraform.io/language/functions/filebase64) as follows before the VM was created:
resource "azurerm_key_vault_secret" "secretName" {
name = "secretName"
value = filebase64(var.keySourceFile)
key_vault_id = azurerm_key_vault.vaultName.id
}
**RESULTS OF TRYING USER SUGGESTIONS:**
Per @roaima suggestion, we tried the following:
[user@myVM ~]$ az keyvault secret show --name "secretName" --vault-name "vaultName" --query "value"
"very.long.base64.encoded.string.representing.the.original.yaml=="
[user@myVM ~]$ myVar=$(az keyvault secret show --name "secretName" --vault-name "vaultName" --query "value")
[user@myVM ~]$ echo "$myVar" | base64 --decode >/dev/null
base64: invalid input
As you can see, we validated that a long encoded string is presented by the raw command before we put it into myVar
. Note that it ends with ==
and is surrounded by double-quotes.
The raw data in the original source file that was sent into terraform looks something like:
secret1: value1
secret2: value2
...
secretN: valueN
Then we tried the following but you can see nothing was returned:
[user@myVM ~]$ printf '%s\n' "$myVar" | base64 --decode --ignore-garbage >/dev/null
[user@myVM ~]$
Asked by CodeMed
(5357 rep)
Apr 14, 2022, 09:52 PM
Last activity: Apr 15, 2022, 07:34 AM
Last activity: Apr 15, 2022, 07:34 AM