Skip to content

Commit

Permalink
fix: Resolve SSL certificate directory permission issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfreak30 committed Dec 30, 2024
1 parent 5db2ceb commit e63c9e7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
11 changes: 11 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ socket = ${MYSQL_SOCKET}
EOF
chmod 600 "${CONFIG_DIR}/exporter.cnf"

# Set up SSL and CA trust directories with proper permissions
mkdir -p "${MYSQL_SSL_DIR}" "${MYSQL_SSL_TRUST_DIR}"
chown -R mysql:mysql "${MYSQL_SSL_DIR}" "${MYSQL_SSL_TRUST_DIR}"
chmod 750 "${MYSQL_SSL_DIR}" "${MYSQL_SSL_TRUST_DIR}"

# Ensure state directory structure exists with proper permissions
mkdir -p "${STATE_DIR}/ca-trust"
chown -R mysql:mysql "${STATE_DIR}"
chmod 750 "${STATE_DIR}"
chmod 700 "${STATE_DIR}/ca-trust"

# Set proper permissions
chown -R mysql:mysql $DATA_ROOT $RUN_DIR $LOG_DIR $CONFIG_DIR
chmod 750 $DATA_ROOT $DATA_DIR
Expand Down
29 changes: 17 additions & 12 deletions lib/mysql-startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,30 @@ init_ca_trust() {
return 1
fi

# Create and clean CA trust directory
mkdir -p "${MYSQL_SSL_TRUST_DIR}"
rm -f "${MYSQL_SSL_TRUST_DIR}"/*
# Create CA trust directory if it doesn't exist
if [ ! -d "${MYSQL_SSL_TRUST_DIR}" ]; then
log_error "CA trust directory ${MYSQL_SSL_TRUST_DIR} does not exist"
return 1
fi

# Clean directory with proper error handling
find "${MYSQL_SSL_TRUST_DIR}" -type f -delete 2>/dev/null || {
log_warn "Failed to clean CA trust directory, continuing anyway"
}

# Copy our CA certificate
cp "${MYSQL_SSL_CA}" "${MYSQL_SSL_TRUST_DIR}/" || {
if ! cp "${MYSQL_SSL_CA}" "${MYSQL_SSL_TRUST_DIR}/"; then
log_error "Failed to copy CA certificate to trust directory"
return 1
}
fi

# Create hash symlinks
c_rehash "${MYSQL_SSL_TRUST_DIR}" || {
if ! c_rehash "${MYSQL_SSL_TRUST_DIR}" 2>/dev/null; then
log_error "Failed to create certificate hash links"
return 1
}

# Set proper permissions
chown -R mysql:mysql "${MYSQL_SSL_TRUST_DIR}"
chmod -R 500 "${MYSQL_SSL_TRUST_DIR}"
fi

return 0
}

# Generate SSL certificates if needed
Expand Down Expand Up @@ -507,4 +512,4 @@ start_mysql() {
fi

return 0
}
}

0 comments on commit e63c9e7

Please sign in to comment.