tweax
This commit is contained in:
40
.gitignore
vendored
Normal file
40
.gitignore
vendored
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Binaries
|
||||||
|
webhook
|
||||||
|
*.exe
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Test binary
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool
|
||||||
|
*.out
|
||||||
|
|
||||||
|
# Go workspace file
|
||||||
|
go.work
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
vendor/
|
||||||
|
|
||||||
|
# IDE specific files
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
|
|
||||||
|
# OS specific files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Certificates and keys
|
||||||
|
*.key
|
||||||
|
*.crt
|
||||||
|
*.csr
|
||||||
|
*.pem
|
||||||
|
.ca-bundle.txt
|
||||||
|
|
||||||
|
# Build artifacts
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
7
Makefile
7
Makefile
@@ -23,7 +23,12 @@ certs:
|
|||||||
|
|
||||||
# Deploy to Kubernetes
|
# Deploy to Kubernetes
|
||||||
deploy:
|
deploy:
|
||||||
kubectl apply -f deploy.yaml
|
@if [ ! -f .ca-bundle.txt ]; then \
|
||||||
|
echo "Error: .ca-bundle.txt not found. Run 'make certs' first."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
@CA_BUNDLE=$$(cat .ca-bundle.txt) && \
|
||||||
|
sed "s|CA_BUNDLE_PLACEHOLDER|$$CA_BUNDLE|g" deploy.yaml | kubectl apply -f -
|
||||||
|
|
||||||
# Undeploy from Kubernetes
|
# Undeploy from Kubernetes
|
||||||
undeploy:
|
undeploy:
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ spec:
|
|||||||
serviceAccountName: irsa-webhook
|
serviceAccountName: irsa-webhook
|
||||||
containers:
|
containers:
|
||||||
- name: webhook
|
- name: webhook
|
||||||
image: ewr.vultrcr.com/chansey/irsa-webhook:latest
|
image: your-registry/irsa-webhook:latest
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8443
|
- containerPort: 8443
|
||||||
@@ -122,7 +122,7 @@ webhooks:
|
|||||||
name: irsa-webhook
|
name: irsa-webhook
|
||||||
namespace: irsa-system
|
namespace: irsa-system
|
||||||
path: /mutate
|
path: /mutate
|
||||||
caBundle: ${CA_BUNDLE} # Replace with base64-encoded CA certificate
|
caBundle: CA_BUNDLE_PLACEHOLDER
|
||||||
rules:
|
rules:
|
||||||
- operations: ["CREATE"]
|
- operations: ["CREATE"]
|
||||||
apiGroups: [""]
|
apiGroups: [""]
|
||||||
@@ -29,7 +29,7 @@ openssl req -x509 -new -nodes -key ${CERT_DIR}/ca.key \
|
|||||||
openssl genrsa -out ${CERT_DIR}/tls.key 2048
|
openssl genrsa -out ${CERT_DIR}/tls.key 2048
|
||||||
|
|
||||||
# Create certificate signing request
|
# Create certificate signing request
|
||||||
cat > ${CERT_DIR}/csr.conf <<EOL
|
cat > ${CERT_DIR}/csr.conf <<EOF
|
||||||
[req]
|
[req]
|
||||||
req_extensions = v3_req
|
req_extensions = v3_req
|
||||||
distinguished_name = req_distinguished_name
|
distinguished_name = req_distinguished_name
|
||||||
@@ -44,7 +44,7 @@ DNS.1 = ${SERVICE_NAME}
|
|||||||
DNS.2 = ${SERVICE_NAME}.${NAMESPACE}
|
DNS.2 = ${SERVICE_NAME}.${NAMESPACE}
|
||||||
DNS.3 = ${SERVICE_NAME}.${NAMESPACE}.svc
|
DNS.3 = ${SERVICE_NAME}.${NAMESPACE}.svc
|
||||||
DNS.4 = ${SERVICE_NAME}.${NAMESPACE}.svc.cluster.local
|
DNS.4 = ${SERVICE_NAME}.${NAMESPACE}.svc.cluster.local
|
||||||
EOL
|
EOF
|
||||||
|
|
||||||
# Generate certificate signing request
|
# Generate certificate signing request
|
||||||
openssl req -new -key ${CERT_DIR}/tls.key \
|
openssl req -new -key ${CERT_DIR}/tls.key \
|
||||||
@@ -65,20 +65,23 @@ openssl x509 -req -in ${CERT_DIR}/tls.csr \
|
|||||||
echo "Certificates generated successfully."
|
echo "Certificates generated successfully."
|
||||||
|
|
||||||
# Create namespace if it doesn't exist
|
# Create namespace if it doesn't exist
|
||||||
kubectl create namespace ${NAMESPACE} --dry-run=client -o yaml | kubectl apply -f -
|
kubectl create namespace ${NAMESPACE} --dry-run=client -o yaml | kubectl apply -f - --validate=false
|
||||||
|
|
||||||
# Create or update secret with certificates
|
# Create or update secret with certificates
|
||||||
kubectl create secret tls ${SECRET_NAME} \
|
kubectl create secret tls ${SECRET_NAME} \
|
||||||
--cert=${CERT_DIR}/tls.crt \
|
--cert=${CERT_DIR}/tls.crt \
|
||||||
--key=${CERT_DIR}/tls.key \
|
--key=${CERT_DIR}/tls.key \
|
||||||
--namespace=${NAMESPACE} \
|
--namespace=${NAMESPACE} \
|
||||||
--dry-run=client -o yaml | kubectl apply -f -
|
--dry-run=client -o yaml | kubectl apply -f - --validate=false
|
||||||
|
|
||||||
echo "Secret ${SECRET_NAME} created/updated in namespace ${NAMESPACE}"
|
echo "Secret ${SECRET_NAME} created/updated in namespace ${NAMESPACE}"
|
||||||
|
|
||||||
# Get CA bundle for webhook configuration
|
# Get CA bundle for webhook configuration
|
||||||
CA_BUNDLE=$(cat ${CERT_DIR}/ca.crt | base64 | tr -d '\n')
|
CA_BUNDLE=$(cat ${CERT_DIR}/ca.crt | base64 | tr -d '\n')
|
||||||
|
|
||||||
|
# Save CA bundle to file for deployment
|
||||||
|
echo "${CA_BUNDLE}" > .ca-bundle.txt
|
||||||
|
|
||||||
# Update MutatingWebhookConfiguration with CA bundle
|
# Update MutatingWebhookConfiguration with CA bundle
|
||||||
if kubectl get mutatingwebhookconfiguration ${WEBHOOK_CONFIG_NAME} &> /dev/null; then
|
if kubectl get mutatingwebhookconfiguration ${WEBHOOK_CONFIG_NAME} &> /dev/null; then
|
||||||
kubectl patch mutatingwebhookconfiguration ${WEBHOOK_CONFIG_NAME} \
|
kubectl patch mutatingwebhookconfiguration ${WEBHOOK_CONFIG_NAME} \
|
||||||
@@ -86,10 +89,8 @@ if kubectl get mutatingwebhookconfiguration ${WEBHOOK_CONFIG_NAME} &> /dev/null;
|
|||||||
-p="[{'op': 'replace', 'path': '/webhooks/0/clientConfig/caBundle', 'value':'${CA_BUNDLE}'}]"
|
-p="[{'op': 'replace', 'path': '/webhooks/0/clientConfig/caBundle', 'value':'${CA_BUNDLE}'}]"
|
||||||
echo "MutatingWebhookConfiguration ${WEBHOOK_CONFIG_NAME} updated with CA bundle"
|
echo "MutatingWebhookConfiguration ${WEBHOOK_CONFIG_NAME} updated with CA bundle"
|
||||||
else
|
else
|
||||||
echo "MutatingWebhookConfiguration ${WEBHOOK_CONFIG_NAME} not found. Please update deploy.yaml with:"
|
echo "MutatingWebhookConfiguration not found yet. CA bundle saved to .ca-bundle.txt"
|
||||||
echo "caBundle: ${CA_BUNDLE}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Setup complete! CA Bundle (for manual configuration):"
|
echo "Setup complete! CA Bundle saved to .ca-bundle.txt"
|
||||||
echo "${CA_BUNDLE}"
|
|
||||||
Reference in New Issue
Block a user