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

Save the CA bundle to a kubernetes secret #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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 .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
schedule:
- cron: 0 1 * * *
push:
branches: [ main ]
branches: [ main, kubernetes-secret ]
pull_request:
branches: [ main ]

Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ RUN yum -y install epel-release && yum -y update

RUN yum -y install rsync ca-policy-egi-core fetch-crl

RUN curl -LO https://dl.k8s.io/release/v1.29.0/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin
Comment on lines +11 to +13

Choose a reason for hiding this comment

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

Usually there is only one RUN command (if possible):

Suggested change
RUN curl -LO https://dl.k8s.io/release/v1.29.0/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin
RUN curl -LO https://dl.k8s.io/release/v1.29.0/bin/linux/amd64/kubectl \
&& chmod +x ./kubectl \
&& mv ./kubectl /usr/local/bin

which you can then merge with the following one. curl also allows to download directly in /usr/local/bin/kubectl (-o option).
Said that, have you considered putting these commands directly into update-trust-anchors.sh, inside the if [ -n "${CA_BUNDLE_SECRET_TARGET}" ]; then? in that way, kubectl would be available in the container only if needed; before downloading it, you could check if it's already present, in case the script has already been run.


RUN chmod go+rx /update-trust-anchors.sh && chmod go+w /etc/grid-security/certificates/ && chmod -R go+wx /etc/pki

ENTRYPOINT ["/update-trust-anchors.sh"]
13 changes: 13 additions & 0 deletions update-trust-anchors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ if [ -n "${CA_BUNDLE_TARGET}" ]; then
rsync -avu -O --no-owner --no-group --no-perms --exclude 'CA/private' /etc/pki/ ${CA_BUNDLE_TARGET}
fi

if [ -n "${CA_BUNDLE_SECRET_TARGET}" ]; then
echo "Copying ca bundle to ${CA_BUNDLE_SECRET_TARGET}"

if kubectl get secret "$CA_BUNDLE_SECRET_TARGET" 2>/dev/null; then
kubectl create secret generic "$CA_BUNDLE_SECRET_TARGET" --from-file=ca.crt=$DEST/pem/tls-ca-bundle-all.pem --dry-run=client -o yaml | kubectl replace -f -
echo "Secret '$CA_BUNDLE_SECRET_TARGET' updated."
else
kubectl create secret generic "$CA_BUNDLE_SECRET_TARGET" --from-file=ca.crt=$DEST/pem/tls-ca-bundle-all.pem
echo "Secret '$CA_BUNDLE_SECRET_TARGET' created."
fi

fi

if [ $# -gt 0 ]; then
echo "Certificate copy requested to $1"
rsync -avu -O --no-owner --no-group --no-perms /etc/grid-security/certificates/ $1
Expand Down
Loading