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

CLOUD-4745: ensure certificates are up to date #104

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.63
0.1.64
8 changes: 8 additions & 0 deletions bin/ih-setup
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ declare -a IH_SETUP_DOMAINS
# they are for the user to customize.
export IH_CUSTOM_DIR="$IH_DIR/custom"

if [ ! -d "$IH_CUSTOM_DIR" ]; then
mkdir "$IH_CUSTOM_DIR"
fi

# The directory where IH shell default files are to be installed
# These are files that may be overwritten during an upgrade
export IH_DEFAULT_DIR="$IH_DIR/default"

if [ ! -d "$IH_DEFAULT_DIR" ]; then
mkdir "$IH_DEFAULT_DIR"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this to fix this error while testing with ./meta/test-isolated:

cp: /tmp/ih-core-test/.ih/default/11_certificates.sh: No such file or directory

fi

# If a step sets this then the ih-setup script will
# write out a warning to the user that they should
# source their .rcs when the script is done.
Expand Down
2 changes: 1 addition & 1 deletion formula/ih-core.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class IhCore < Formula
VERSION="0.1.63"
VERSION="0.1.64"
desc "Brew formula for installing core tools used at Included Health engineering."
homepage "https://github.com/ConsultingMD/homebrew-ih-public"
license "CC BY-NC-ND 4.0"
Expand Down
29 changes: 20 additions & 9 deletions lib/core/certificates/step.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

# IH_CORE_DIR will be set to the directory containing the bin and lib directories.

CA_DIR="$HOME/.ih/certs"
SOURCE_CA_PATH="$IH_CORE_LIB_DIR/core/certificates/certs/grand_rounds_chained_ca.pem"
INSTALLED_CA_PATH="$CA_DIR/grand_rounds_chained_ca.pem"
SOURCE_CERT_SCRIPT="$IH_CORE_LIB_DIR/core/certificates/default/11_certificates.sh"
INSTALLED_CERT_SCRIPT="$IH_DEFAULT_DIR/11_certificates.sh"
MOZILLA_PATH="$CA_DIR/mozilla.pem"

function ih::setup::core.certificates::help() {
# shellcheck disable=SC2016
echo 'Trust the certificates used by the VPN DLP
Expand All @@ -24,12 +31,20 @@ function ih::setup::core.certificates::help() {
# Check if the step has been installed and return 0 if it has.
# Otherwise return 1.
function ih::setup::core.certificates::test() {
if [ ! -f "$INSTALLED_CERT_SCRIPT" ]; then
return 1
fi

if [ ! -f "$IH_DEFAULT_DIR/11_certificates.sh" ]; then
if [ ! -d "$CA_DIR" ]; then
return 1
fi

if [ ! -d "$HOME/.ih/certs" ]; then
# Compare both the CA cert and the certificates script with their sources
if [ ! -f "$INSTALLED_CA_PATH" ] || ! diff -q "$SOURCE_CA_PATH" "$INSTALLED_CA_PATH" >/dev/null; then
return 1
fi

if ! diff -q "$SOURCE_CERT_SCRIPT" "$INSTALLED_CERT_SCRIPT" >/dev/null; then
return 1
fi

Expand All @@ -42,10 +57,6 @@ function ih::setup::core.certificates::deps() {
}

function ih::setup::core.certificates::install() {

local CA_DIR="$HOME/.ih/certs"
local CA_PATH="$CA_DIR/grand_rounds_chained_ca.pem"
local MOZILLA_PATH="$CA_DIR"/mozilla.pem
mkdir -p "$CA_DIR"
ih::log::info "Copying internal CA certs into $CA_DIR"

Expand Down Expand Up @@ -85,7 +96,7 @@ function ih::setup::core.certificates::install() {
return 1
fi
# Append our DLP certs to the mozilla bundle.
cat "$CA_PATH" >>"$MOZILLA_PATH"
cat "$INSTALLED_CA_PATH" >>"$MOZILLA_PATH"

# Download a CA cert that AWS sometimes uses, which is not
# included in the Mozilla bundle. This affects a few people
Expand All @@ -107,13 +118,13 @@ function ih::setup::core.certificates::install() {
OPENSSL_FOUND=$?
if [[ "$OPENSSL_FOUND" -eq 0 ]]; then
ih::log::info "Copying internal CA cert to brew OpenSSL certs..."
cp "$CA_PATH" "$OPENSSL_PATH"/gr_root_ca.pem
cp "$INSTALLED_CA_PATH" "$OPENSSL_PATH"/gr_root_ca.pem
REHASH_PATH=$(brew info openssl | grep -oE "/usr/local/opt/openssl.*")
$REHASH_PATH
fi

ih::log::info "Rehashing brew OpenSSL certs..."
"$(brew --prefix)"/opt/openssl/bin/c_rehash

cp -f "$IH_CORE_LIB_DIR/core/certificates/default/11_certificates.sh" "$IH_DEFAULT_DIR/11_certificates.sh"
cp -f "$SOURCE_CERT_SCRIPT" "$INSTALLED_CERT_SCRIPT"
}