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

Put ./keys/generate into the docker image #60

Open
Grimeton opened this issue May 4, 2020 · 0 comments
Open

Put ./keys/generate into the docker image #60

Grimeton opened this issue May 4, 2020 · 0 comments

Comments

@Grimeton
Copy link

Grimeton commented May 4, 2020

Hi,

put the file into the docker image so that one can do a one-stop-shop key generation. I don't want to pull down a git repo to generate keys that are needed inside a docker image.

Cu

A script like this, from the top of my head:

#!/usr/bin/env bash
set -o nounset
declare __BASEDIRECTORY="/keys"
declare -a __SUBDIRECTORIES=("web" "worker")
declare -a __RSA_KEYS=( "/keys/web/session_signing_key" )
declare -a __SSH_KEYS=( "/keys/web/tsa_host_key" "/keys/worker/worker_key" )

for __SUBDIRECTORY in "${__SUBDIRECTORIES[@]}"; do

    if [[ ! -d "${__BASEDIRECTORY}/${__SUBDIRECTORY}" ]]; then
        mkdir -p "${__BASEDIRECTORY}/${__SUBDIRECTORY}"
    fi

done

for __KEY in "${__RSA_KEYS[@]}"; do

    if [[ ! -f "${__KEY}" ]]; then
        generate-key -t rsa -f "${__KEY}"
    fi

done

for __KEY in "${__SSH_KEYS[@]}"; do
    if [[ ! -f "${__KEY}" ]]; then
        generate-key -t ssh -f "${__KEY}"
    fi
done

This is what I put together to auto generate the keys on the outside...

#!/usr/bin/env bash
set -o nounset
declare __BASEDIRECTORY="/srv/containers/tools/concourse/config/keys"
declare -a __SUBDIRECTORIES=("web" "worker")
declare -a __RSA_KEYS=( "/web/session_signing_key" )
declare -a __SSH_KEYS=( "/web/tsa_host_key" "/worker/worker_key" )

for __SUBDIRECTORY in "${__SUBDIRECTORIES[@]}"; do

    if [[ ! -d "${__BASEDIRECTORY}/${__SUBDIRECTORY}" ]]; then
        mkdir -p "${__BASEDIRECTORY}/${__SUBDIRECTORY}"
    fi

done

for __KEY in "${__RSA_KEYS[@]}"; do

    if [[ ! -f "${__BASEDIRECTORY}/${__KEY}" ]]; then
        docker run --rm -v "${__BASEDIRECTORY}:/keys" concourse/concourse generate-key -t rsa -f "/keys/${__KEY}"
    fi

done

for __KEY in "${__SSH_KEYS[@]}"; do
    if [[ ! -f "${__BASEDIRECTORY}/${__KEY}" ]]; then
        docker run --rm -v "${__BASEDIRECTORY}:/keys" concourse/concourse generate-key -t ssh -f "/keys/${__KEY}"
    fi
done

cp "${__BASEDIRECTORY}/worker/worker_key.pub" "${__BASEDIRECTORY}/web/authorized_worker_keys"
cp "${__BASEDIRECTORY}/web/tsa_host_key.pub" "${__BASEDIRECTORY}/worker/tsa_host_key.pub"

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

No branches or pull requests

1 participant