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 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 ~]$
$myVar
? – Arkadiusz Drabczyk Apr 14 '22 at 22:04"very.long.base64.encoded.string.representing.the.original.yaml"
, which doesn't look base64-encoded. In fact it looks like a test string where the encoding wasn't done for some reason. Note also that you haven't mentioned that string is a placeholder even in the text. Inaccurate data like that leads the reader in quite a wrong direction, and there's already enough bad questions on SE sites. If you can't show the real data, come up with something you can show, e.g. a throwaway secret or something like that. – ilkkachu Apr 15 '22 at 09:01"very.long.base64.encoded.string.representing.the.original.yaml=="
is even worse. Base64-encoding adds=
signs for padding, but here, they're inside the quotes. Does that mean the output has the literal quotes there, or that they're part of the placeholder text? The reader can't know. Anyone coming to this question later to see if it helps with their issue can't know. – ilkkachu Apr 15 '22 at 09:24c2VjcmV0cwo=
, run it throughtr a-zA-Z0-9+/ A
, givingAAAAAAAAAAA=
. Or something like that. And then say you did exactly that. Hiding the facts when trying to discuss a technical issue doesn't help. – ilkkachu Apr 15 '22 at 09:29