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

Better certificate generation #1

Open
wants to merge 1 commit into
base: legacy
Choose a base branch
from

Conversation

chregu
Copy link
Member

@chregu chregu commented Aug 14, 2019

Initial problem: The certificate generation doesn't work on OS X, since openssl behaves differently (it errors out)

Solution: Use a docker image to generate to certificates on all platforms. Also to make the environment consistent.

Problem 2: If you want to have an additional domain name other than the default one for your project (let's say, api.rokka.test instead of rokka-api.pontsun.test), there was no easy way.

Solution 2: Add alternate DNS entries to the cert. The script now reads all the existing and adds new one before recreating it.

More stuff in this MR:

  • Moved certificates from certificates/ to etc/certificates to be able to have more config options in that directory (it's configurable via the PONTSUN_DIR_ETC variable)

  • Automatically installs the generated root certificate to the system trust store on OS X or if smallstep-cli is installed (https://smallstep.com/docs/cli/), if it doesn't exist already (needs password)

The helper image (liip/pontsun-helper:latest) for openssl cert generation isn't on hub.docker.com yet (I need to get the credentials before I can upload it), you have to generate it first locally with build/build.sh

@chregu chregu force-pushed the certificate-generation-improvements branch from 01a2878 to c43800f Compare August 14, 2019 08:08
Copy link
Member

@OdyX OdyX left a comment

Choose a reason for hiding this comment

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

In general, not fan of the idea to need a container for something as trivial as generating a cert, but why not.

I'd make sure no bashisms are in use, and rely on /bin/sh (with set -e) everywhere.

@@ -7,3 +7,6 @@

# Local
.env

Copy link
Member

Choose a reason for hiding this comment

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

No whitespace; add comment please

Copy link
Member Author

Choose a reason for hiding this comment

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

added a comment, left the whitespace

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Copy link
Member

Choose a reason for hiding this comment

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

There's really nothing less ugly?

DIR=$(realpath $(dirname $(dirname $0)))

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

It's even worse (or not really possible at all) in Posix sh

https://stackoverflow.com/questions/29832037/how-to-get-script-directory-in-posix-sh#29834779

@@ -0,0 +1,5 @@
FROM debian:stable-slim
Copy link
Member

Choose a reason for hiding this comment

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

Please specify the Debian release; buster-slim; but thanks for using Debian!

Copy link
Member Author

Choose a reason for hiding this comment

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

changed

scripts/env.sh Outdated
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
Copy link
Member

Choose a reason for hiding this comment

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

Would be best to avoid bashisms and use standard /bin/sh, no?

Copy link
Member

Choose a reason for hiding this comment

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

Also set -e all these please.

Copy link
Member Author

Choose a reason for hiding this comment

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

added set -e

@@ -0,0 +1,59 @@
#!/bin/bash
Copy link
Member

Choose a reason for hiding this comment

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

Not coherent with the /usr/bin/env calls elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

replaced with #!/usr/bin/env bash for now (see chat discussion)

@chregu chregu changed the title Better certificate generation and adding an "global" pontsun script Better certificate generation and adding a "global" pontsun script Aug 14, 2019
README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@Aerzas Aerzas left a comment

Choose a reason for hiding this comment

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

We're missing a documentation or two to make it run smoothly for newcomers and we could maybe improve some structure but it's working well, thank you.

build/helper/Dockerfile Outdated Show resolved Hide resolved
containers/.env.example Show resolved Hide resolved
chmod 600 $PROJECT_NAME.key $PROJECT_NAME.pem
fi
docker run --rm -v $DIR/../:/generate/ -v $PONTSUN_DIR_ETC/certificates/:/certs/ -it liip/pontsun-helper:latest /generate/scripts/helper/docker-generate-certificates.sh $1
if [[ "$OSTYPE" == "darwin"* ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

If we start to support explicitly Mac, shouldn't we support other platforms also ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. Windows support is needed/wanted, too. But I need the help of our windows users here and something that can be added later.

We supported mac before anyway already (the source of this scripts and the docs/ at least ;))

Copy link
Contributor

Choose a reason for hiding this comment

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

smallstep CLI has a command to install certificates into truststores for windows, linux and macOS.
Respective code is at smallstep/truststore:

Copy link
Member Author

Choose a reason for hiding this comment

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

It's now included and used, if installed (didn't check on windows, but that's something to be added later)

Copy link
Member Author

Choose a reason for hiding this comment

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

It = smallstep CLI


# Load env file
set -a
test -f $(dirname $0)/../../containers/.env && source $(dirname $0)/../../containers/.env
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not specified in the README.md that we need to copy the .env file and without it it's not working by default. We should maybe warn the user if we don't find some env variables and stop the script with an explicit message.

Copy link
Member Author

Choose a reason for hiding this comment

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

It does that now. Plus I added some section to the README

cat $PROJECT_NAME.crt $PROJECT_NAME.key > $PROJECT_NAME.pem
chmod 600 $PROJECT_NAME.key $PROJECT_NAME.pem
fi
docker run --rm -v $DIR/../:/generate/ -v $PONTSUN_DIR_ETC/certificates/:/certs/ -it liip/pontsun-helper:latest /generate/scripts/helper/docker-generate-certificates.sh $1
Copy link
Contributor

Choose a reason for hiding this comment

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

By default the liip/pontsun-helper image doesn't exist, we should maybe integrate the build process of the image here or push this image to a repo so users only need to pull it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm still in the process of recovering our "liip" docker hub account, so that we can push it there (and then yes, why not add it into CI/CD)and people don't have to do anything.

scripts/install-cert-macos.sh Outdated Show resolved Hide resolved
scripts/env.sh Outdated Show resolved Hide resolved
scripts/pontsun Outdated
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

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

For a single command that also exists as a script maybe this binary is not needed. Is there other commands that are planned to be added later ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, there will be more up and down for example (see #5 which is WIP for now)

One reason to do this was also, that we have to possibility to maybe move away from a shell script here and do it in go or whatever other language.

@chregu chregu force-pushed the certificate-generation-improvements branch 2 times, most recently from e9fefaa to 02ddea4 Compare August 20, 2019 09:46
@chregu chregu force-pushed the certificate-generation-improvements branch from 02ddea4 to cac4c2b Compare August 20, 2019 09:47
@chregu chregu changed the title Better certificate generation and adding a "global" pontsun script Better certificate generation Aug 20, 2019
@mweibel
Copy link
Contributor

mweibel commented Dec 4, 2019

what's the status here?
currently the documentation still refers to use USER_ID=$(id -u) docker-compose -f docker-compose.certificates.yml up for the certificates but that file doesn't exist.

// Edit: actually it does exist, I just didn't see it (and needs a cd containers). Will amend docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants