Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dumpcerts.sh: Fix call to "base64" for Alpine #2344

Merged
merged 4 commits into from
Nov 2, 2017

Conversation

nknapp
Copy link
Contributor

@nknapp nknapp commented Oct 29, 2017

Alpine Linux' "base64" does not support the --decode option. Only -d.
In order to run dumpcerts.sh inside the office "traefik:1.4-alpine" docker-image,
base64 must be called with -d

@@ -149,10 +149,10 @@ for domain in $(jq -r '.DomainsCertificate.Certs[].Certificate.Domain' ${acmefil
echo "Extracting cert bundle for ${domain}"
cert=$(jq -e -r --arg domain "$domain" '.DomainsCertificate.Certs[].Certificate |
select (.Domain == $domain )| .Certificate' ${acmefile}) || bad_acme
echo "${cert}" | base64 --decode > "${cdir}/${domain}.crt"
echo "${cert}" | base64 -d > "${cdir}/${domain}.crt"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is -d supported in non-Alpine contexts as well?

If yes: cool 👍

If no: shouldn't our script be smart enough to handle both option styles?

Copy link
Contributor Author

@nknapp nknapp Oct 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The man page states both options. I have verified the help output of Ubuntu 10.04, Ubuntu 16.04, Centos 7 and Fedora 26 and they all support the short-hand option.

Alpine is a bit special, because the installed binary for base64 is actually the busybox binary. I guess that's the reason. I believe it is safe to use -d without checking for the environment.

Copy link
Contributor

@timoreimann timoreimann Oct 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base64 binary shipped with Mac OS X seems to deviate:

$ base64 --help
Usage:	base64 [-hvD] [-b num] [-i in_file] [-o out_file]
  -h, --help     display this message
  -D, --decode   decodes input
  -b, --break    break encoded string into num character lines
  -i, --input    input file (default: "-" for stdin)
  -o, --output   output file (default: "-" for stdout)

:(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's sad... I'll have to check if the is another base64 binary for alpine.

The alternative would be to check if the base64 binary is actually a symlink to busybox and then revert to the -d option. If that's an acceptable solution, I would change my PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just checking in the script whether we run on Darwin and adjust the parameter accordingly?

alias decode_base64='base64 -d'
;;
*)
# Max OS-X supports --decode and -D, but --decode may be supported by other platforms as well.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to complete the picture: We could also invert the logic and switch-case on Darwin to set --decode, and use -d in all other cases (Linux, FreeBSD, you name it).

No idea what might be better. I'd go with your current approach when in doubt.

@nknapp
Copy link
Contributor Author

nknapp commented Oct 31, 2017

Sorry for the force-push. My last version did not work out (aliases don't work in bash-scripts, it seems). Now I'm using a variable to store the base64-decode command.

@@ -42,6 +42,18 @@ set -o nounset

USAGE="$(basename "$0") <path to acme> <destination cert directory>"

# Platform variations
case `uname` in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use $() instead of backticks, just to follow best practices?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. If you want me to squash my commits, just tell me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would by nicer with quotes around, I guess

Copy link
Contributor

@timoreimann timoreimann Oct 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True -- let's add quotes for complete happiness. :)

No need to squash, our bot does that.

@nknapp nknapp force-pushed the patch-2 branch 2 times, most recently from c4e1d82 to 371d552 Compare October 31, 2017 22:56
Copy link
Contributor

@timoreimann timoreimann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, @nknapp -- the PR looks good to me at this point. 🎉

@ldez ldez added the kind/enhancement a new or improved feature. label Nov 1, 2017
Copy link
Contributor

@nmengin nmengin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

nknapp and others added 4 commits November 2, 2017 14:40
Alpine Linux' "base64" does not support the "--decode" option. Only "-d". 
In order to run dumpcerts.sh inside the office "traefik:1.4-alpine" docker-image,
"base64" must be called with "-d"
Detects if this is a Mac OSX (FreeBSD) or Linux and uses '--decode'
or '-d' depending on the outcome. Mac OSX does not support '-d', but '-D' as shortcut.

fixup: remove redundant colon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants