Compare commits

..

25 Commits

Author SHA1 Message Date
gyurix
513b8ecde5 Refactor start.letsencrypt.sh to improve error handling and logging during certificate issuance
All checks were successful
continuous-integration/drone/push Build is passing
2025-04-14 14:46:24 +02:00
gyurix
5d2a782201 Enhance start.letsencrypt.sh to log successful certificate creation and generate JSON output
All checks were successful
continuous-integration/drone/push Build is passing
2025-03-30 09:54:02 +02:00
gyurix
6d219eaa6c Refactor start.letsencrypt.sh to correct installation check logic and improve domain file handling
All checks were successful
continuous-integration/drone/push Build is passing
2025-03-29 23:22:15 +01:00
gyurix
8fa324553d Refactor start.letsencrypt.sh to update file paths for certificate handling
All checks were successful
continuous-integration/drone/push Build is passing
2025-03-29 22:55:27 +01:00
gyurix
7274cab64f Refactor start.letsencrypt.sh to improve domain handling and installation checks
All checks were successful
continuous-integration/drone/push Build is passing
2025-03-29 22:50:01 +01:00
gyurix
3f2d75c086 Refactor JSON creation in create_json function to enhance domain entry handling
All checks were successful
continuous-integration/drone/push Build is passing
2025-03-15 00:20:41 +01:00
gyurix
0c3dccfa26 Refactor JSON creation in start.letsencrypt.sh to improve domain entry handling
All checks were successful
continuous-integration/drone/push Build is passing
2025-03-14 20:36:51 +01:00
gyurix
d682f43489 Refactor JSON output handling in start.letsencrypt.sh for improved structure
All checks were successful
continuous-integration/drone/push Build is passing
2025-03-14 18:14:40 +01:00
gyurix
2653583702 Refactor letsencrypt script to improve domain handling and JSON output management
All checks were successful
continuous-integration/drone/push Build is passing
2025-03-12 23:07:58 +01:00
14a6e628fc Update start.letsencrypt.sh
All checks were successful
continuous-integration/drone/push Build is passing
2025-03-12 20:07:27 +00:00
gyurix
e558ae96e8 Refactor letsencrypt script for improved readability and consistency
All checks were successful
continuous-integration/drone/push Build is passing
2025-03-08 11:37:41 +01:00
gyurix
815c154a28 Enhance letsencrypt configuration and logging functionality
All checks were successful
continuous-integration/drone/push Build is passing
- Added shared volume for temporary output storage
- Implemented logging of letsencrypt output to a file
- Created JSON log entries for certificate creation status
- Improved handling of domain checks and output file initialization
2025-03-08 11:31:03 +01:00
59cfb9b619 Add .drone.yml
All checks were successful
continuous-integration/drone/push Build is passing
2025-03-05 11:39:34 +00:00
1c25dc156a up to date repo 2025-02-16 08:48:50 +01:00
Gyorgy Berenyi
6e9f7542c4 corrected ssl content directory path 2024-10-14 11:32:45 +00:00
c6c5007ebb Added optional variables settings when exist 2023-03-10 10:00:11 +00:00
e695bff6bd Added letsencrypt server variable to choose which CA server would use for certify your domain 2022-12-16 13:33:19 +00:00
8e6c875d64 diff fullchain 2022-11-09 07:14:25 +00:00
e33c7c2d6a Fixing variable issue 2022-11-04 09:08:17 +00:00
63d9f76cbb Check certificate issuer 2022-11-04 08:53:25 +00:00
6194a9dfe3 Correcting Letsencrypt image name in template json 2022-05-26 07:24:14 +00:00
74aa62abc4 Correting DATE variable and compare processes. Fixing acme.sh issues 2022-03-31 11:24:05 +00:00
e5bfb9299c Inserting date variable to compare created or modified files with previos versions. 2022-03-29 10:53:44 +00:00
33b2570a98 Adding letsencrypt service files 2022-03-28 09:31:28 +00:00
91e715f5cf Checking some file creating path and some cycle end 2022-03-28 09:28:19 +00:00
6 changed files with 341 additions and 44 deletions

47
.drone.yml Normal file
View File

@@ -0,0 +1,47 @@
kind: pipeline
type: kubernetes
name: default
node_selector:
physical-node: dev2
trigger:
branch:
- master
event:
- push
workspace:
path: /drone/src
steps:
- name: build multiarch from dev
image: docker.io/owncloudci/drone-docker-buildx:4
privileged: true
settings:
cache-from: [ "registry.dev.format.hu/letsencrypt" ]
registry: registry.dev.format.hu
repo: registry.dev.format.hu/letsencrypt
tags: latest
dockerfile: Dockerfile
username:
from_secret: dev-hu-registry-username
password:
from_secret: dev-hu-registry-password
platforms:
- linux/amd64
- linux/arm64
- name: pull image to dockerhub
image: docker.io/owncloudci/drone-docker-buildx:4
privileged: true
settings:
cache-from: [ "safebox/letsencrypt" ]
repo: safebox/letsencrypt
tags: latest
username:
from_secret: dockerhub-username
password:
from_secret: dockerhub-password
platforms:
- linux/amd64
- linux/arm64

View File

@@ -1,7 +1,6 @@
FROM neilpang/acme.sh:latest
MAINTAINER gyurix
FROM alpine
RUN apk update && apk add --no-cache jq
RUN apk update && apk add --no-cache jq curl openssl socat
COPY ./start.letsencrypt.sh /start.letsencrypt.sh
ENTRYPOINT ["/start.letsencrypt.sh"]

65
firewall-29eexhrh.json Normal file
View File

@@ -0,0 +1,65 @@
{
"main": {
"SERVICE_NAME": "firewalls",
"DOMAIN": "null"
},
"containers": [
{
"IMAGE": "registry.format.hu/firewall",
"NAME": "null",
"MEMORY": "64M",
"IP": "null",
"NETWORK": "host",
"VOLUMES": [
{
"SOURCE": "/run/",
"DEST": "/run/",
"TYPE": "rw"
},
{
"SOURCE": "/etc/user/config/services",
"DEST": "/services",
"TYPE": "ro"
}
],
"PORTS": [ ],
"READYNESS": [
{"tcp": ""},
{"HTTP": ""},
{"EXEC": "/ready.sh"}
],
"ENVS": [
{
"NAME": "CHAIN",
"VALUE": "DOCKER-USER"
},
{
"NAME": "SOURCE_IP",
"VALUE": "172.18.100.2"
},
{
"NAME": "TARGET_IP",
"VALUE": "172.18.254.254"
},
{
"NAME": "TYPE",
"VALUE": "tcp"
},
{
"NAME": "TARGET_PORT",
"VALUE": "80"
},
{
"NAME": "COMMENT",
"VALUE": "29eexhrh"
}
],
"EXTRA": "--privileged",
"DEPEND": "null",
"START_ON_BOOT": "false",
"CMD": "null",
"PRE_START": "null",
"POST_START": "null"
}
]
}

64
letsencrypt.json Normal file
View File

@@ -0,0 +1,64 @@
{
"main": {
"SERVICE_NAME": "letsencrypt",
"DOMAIN": "null"
},
"networks": [
{
"NAME": "letsencrypt",
"DRIVER": "bridge",
"SUBNET": "172.18.254.0/24",
"RANGE": "172.18.254.0/24",
"GATEWAY": "172.18.254.1"
}
],
"containers": [
{
"IMAGE": "registry.format.hu/letsencrypt",
"NAME": "letsencrypt",
"MEMORY": "64M",
"IP": "172.18.254.254",
"NETWORK": "letsencrypt",
"VOLUMES": [
{
"SOURCE": "/etc/system/data/ssl/keys/",
"DEST": "/acme.sh/",
"TYPE": "rw"
},
{
"SOURCE": "SHARED",
"DEST": "/var/tmp/shared",
"TYPE": "rw"
},
{
"SOURCE": "/etc/user/config/domains",
"DEST": "/domains",
"TYPE": "ro"
}
],
"PORTS": [],
"ENV_FILES": [
"/etc/user/config/user.json"
],
"READYNESS": [
{
"tcp": ""
},
{
"HTTP": ""
},
{
"EXEC": "/ready.sh"
}
],
"EXTRA": "",
"DEPEND": "null",
"START_ON_BOOT": "false",
"CMD": "null",
"PRE_START": "null",
"POST_START": [
"firewall-29eexhrh"
]
}
]
}

View File

@@ -1,49 +1,165 @@
#!/bin/sh
email=$EMAIL
email="-m $EMAIL"
DOMAIN=$DOMAIN
start_letsencrypt() {
LOG_DIR=/var/tmp/shared/output
LOG_FILE=$LOG_DIR/letsencrypt.txt
LETSENCRYPT_OUTPUT=$LOG_DIR/letsencrypt.json
DATE=$(date +"%Y-%m-%d-%H-%M")
mkdir -p /acme.sh/$DOMAIN/ ;
echo "email $EMAIL"
echo "DOMAIN: $DOMAIN"
ACME_PARAMS="--issue --standalone --keylength 4096 -d $DOMAIN --cert-file /acme.sh/$DOMAIN/cert.pem --key-file /acme.sh/$DOMAIN/key.pem --fullchain-file /acme.sh/$DOMAIN/fullchain.pem"
if acme.sh --register-account -m $email $ACME_PARAMS | grep 'Already registered' ; then
acme.sh $ACME_PARAMS ;
fi
#mkdir -p /acme.sh/$DOMAIN/ecc-certs ;
#acme.sh --issue --standalone --keylength ec-384 -d $DOMAIN --cert-file /acme.sh/$DOMAIN/ecc-certs/cert.pem --key-file /acme.sh/$DOMAIN/ecc-certs/key.pem --fullchain-file /acme.sh/$DOMAIN/ecc-certs/fullchain.pem
}
LETSENCRYPT_FILE=$(find /acme.sh/ -type f -name letsencrypt);
if [ -n "$LETSENCRYPT_FILE" ] ; then
DOMAIN=$(jq -r .DOMAIN $LETSENCRYPT_FILE) ;
start_letsencrypt;
rm $LETSENCRYPT_FILE;
else
cd /domains
for i in `ls` ; do
DOMAIN=$(jq -r .DOMAIN $i) ;
if [[ -f /acme.sh/$DOMAIN/key.pem && -f /acme.sh/$DOMAIN/fullchain.pem && -f /acme.sh/$DOMAIN/cert.pem ]] ; then
start_letsencrypt ;
touch /acme.sh/$DOMAIN/renew_certificate;
else
start_letsencrypt;
if [[ -f /acme.sh/$DOMAIN/key.pem && -f /acme.sh/$DOMAIN/fullchain.pem && -f /acme.sh/$DOMAIN/cert.pem ]] ; then
touch /acme.sh/$DOMAIN/new_certificate;
else
while [[ ! -f /acme.sh/$DOMAIN/key.pem || ! -f /acme.sh/$DOMAIN/fullchain.pem || ! -f /acme.sh/$DOMAIN/cert.pem ]] ; do
sleep 10;
start_letsencrypt ;
done
fi
fi
done ;
if [ "$LETSENCRYPT_SERVER" != "" ]; then
L_S="--server $LETSENCRYPT_SERVER"
fi
if [ "$EAB_KID" != "" ]; then
EK="--eab-kid $EAB_KID"
fi
if [ "$EAB_HMAC_KEY" != "" ]; then
EHK="--eab-hmac-key $EAB_HMAC_KEY"
fi
TIMEOUT=$TIMEOUT
if [[ -z "$TIMEOUT" ]]; then
TIMEOUT=10
fi
RESTART=$RESTART
if [[ -z "$RESTART" ]]; then
RESTART=5
fi
sending_error_msg() {
echo "there was unsucessfuly created "$DOMAIN" at date: "$DATE
}
create_json() {
LOG=$(cat $LOG_FILE | base64 -w0)
TMP_FILE=$(mktemp)
jq '
if . == null or . == [] then
{"'$DOMAIN'":{"date": "'$DATE'", "status": "'$STATUS'", "log": "'$LOG'"}}
else
. + {"'$DOMAIN'": {"date": "'$DATE'", "status": "'$STATUS'", "log": "'$LOG'"}}
end
' $LETSENCRYPT_OUTPUT >$TMP_FILE
cat $TMP_FILE >$LETSENCRYPT_OUTPUT
rm $TMP_FILE
}
start_letsencrypt() {
cd /root
if [ "$LETSENCRYPT_INSTALLED" != "true" ]; then
curl https://get.acme.sh | sh -s email=$EMAIL
LETSENCRYPT_INSTALLED=true
fi
sh /root/.acme.sh/acme.sh $L_S $EK $EHK --issue --standalone --keylength 4096 -d $DOMAIN --cert-file /acme.sh/$DOMAIN/cert.pem --key-file /acme.sh/$DOMAIN/key.pem --fullchain-file /acme.sh/$DOMAIN/fullchain.pem >$LOG_FILE 2>&1
RESPONSE=$?
echo "OUTPOUT: $RESPONSE"
if [[ "$(echo $RESPONSE)" == "1" ]]; then
for retries in $(seq 0 $((RESTART + 1))); do
if [[ $retries -le $RESTART ]]; then
# Check certificate issuer
ISSUER=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -text -noout | grep -w CN | grep Issuer | cut -d '=' -f2)
SUBJECT=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -text -noout | grep -w CN | grep Subject | cut -d '=' -f2)
if [ "$ISSUER" == "$SUBJECT" ]; then
echo "Self signed certificate found"
sh /root/.acme.sh/acme.sh $L_S $EK $EHK --issue --standalone --keylength 4096 -d $DOMAIN --cert-file /acme.sh/$DOMAIN/cert.pem --key-file /acme.sh/$DOMAIN/key.pem --fullchain-file /acme.sh/$DOMAIN/fullchain.pem >>$LOG_FILE 2>&1
RESPONSE=$?
if [[ "$(echo $RESPONSE)" == "1" ]]; then
sleep $TIMEOUT
echo "Restarting number is only: "$retries" so try again"
else
echo "Created or renew successfuly the certificate for $DOMAIN"
echo "Creating log json from letsencrypt output"
STATUS=success
create_json $STATUS
break
fi
else
sleep $TIMEOUT
echo "Restarting number is only: "$retries" so try again"
fi
else
echo "Reached retrying limit: "$RESTART" ,giving up"
echo "Creating log json from letsencrypt output"
STATUS=failed
create_json $STATUS
fi
done
else
echo "Created or renew successfuly the certificate for $DOMAIN"
echo "Creating log json from letsencrypt output"
STATUS=success
create_json $STATUS
fi
}
check_new_cert() {
#DATE=$(date +%s)
if [[ -f /acme.sh/$DOMAIN/key.pem && -f /acme.sh/$DOMAIN/fullchain.pem && -f /acme.sh/$DOMAIN/cert.pem ]]; then
#D1=$(date -r /acme.sh/$DOMAIN/fullchain.pem +%s)
#DIFF=$(expr $DATE - $D1);
#if [ $DIFF < 3600 ]; then touch /acme.sh/$DOMAIN/new_certificate; fi
NEW=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -fingerprint -noout)
if [ "$ORIGINAL" != "$NEW" ]; then
touch /acme.sh/$DOMAIN/new_certificate
fi
else
sending_error_msg $DOMAIN $DATE
fi
}
LETSENCRYPT_FILES=$(find /acme.sh/ -type f -name letsencrypt)
if [ "$DOMAIN" != "localhost" ]; then
if [ ! -f $LETSENCRYPT_OUTPUT ]; then
install -m 664 -g 65534 /dev/null $LETSENCRYPT_OUTPUT
echo '{}' >$LETSENCRYPT_OUTPUT
fi
if [ "$DOMAIN" != "" ]; then
echo "DOMAIN: $DOMAIN"
echo "domain exists"
ORIGINAL=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -fingerprint -noout)
if [ "$DOMAIN" != "localhost" ]; then
start_letsencrypt
check_new_cert
fi
elif [ -n "$LETSENCRYPT_FILES" ]; then
echo "letsencrypt files exist"
for LETSENCRYPT_FILE in $(echo $LETSENCRYPT_FILES); do
DOMAIN=$(jq -r .DOMAIN $LETSENCRYPT_FILE)
echo "DOMAIN: $DOMAIN"
for DOMAIN in $(echo $DOMAIN); do
ORIGINAL=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -fingerprint -noout)
start_letsencrypt $DOMAIN
check_new_cert
DOMAIN=""
done
done
else
DOMAIN_FILE=""
echo "no any new created domain exists try renew all"
for DOMAIN_FILE in $(ls /domains); do
cd /domains
echo "DOMAIN_FILE: $(basename $DOMAIN_FILE)"
DOMAIN=$(jq -r .DOMAIN $DOMAIN_FILE)
echo "DOMAIN: $DOMAIN"
if [ "$DOMAIN" != "localhost" ]; then
ORIGINAL=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -fingerprint -noout)
start_letsencrypt $DOMAIN
check_new_cert
fi
done
fi
fi

6
user.json Normal file
View File

@@ -0,0 +1,6 @@
{
"letsencrypt": {
"EMAIL": "postmaster@format.hu",
"DOCKER_REGISTRY_URL": "registry.format.hu"
}
}