Skip to content

Commit c2ccc1f

Browse files
authored
Merge pull request #6347 from acmesh-official/dev
2 parents 676d766 + eb00852 commit c2ccc1f

File tree

4 files changed

+247
-5
lines changed

4 files changed

+247
-5
lines changed

.github/workflows/pr_dns.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,26 @@ jobs:
2020
owner: context.repo.owner,
2121
repo: context.repo.repo,
2222
body: `**Welcome**
23+
READ ME !!!!!
24+
25+
26+
Read me !!!!!!
27+
28+
2329
First thing: don't send PR to the master branch, please send to the dev branch instead.
24-
Please make sure you've read our [DNS API Dev Guide](../wiki/DNS-API-Dev-Guide) and [DNS-API-Test](../wiki/DNS-API-Test).
30+
31+
32+
Please read the [DNS API Dev Guide](../wiki/DNS-API-Dev-Guide) and [DNS-API-Test](../wiki/DNS-API-Test).
33+
34+
2535
Then reply on this message, otherwise, your code will not be reviewed or merged.
36+
37+
2638
Please also make sure to add/update the usage here: https://github.com/acmesh-official/acme.sh/wiki/dnsapi2
27-
We look forward to reviewing your Pull request shortly ✨
39+
40+
2841
注意: 必须通过了 [DNS-API-Test](../wiki/DNS-API-Test) 才会被 review. 无论是修改, 还是新加的 dns api, 都必须确保通过这个测试.
42+
2943
`
3044
})
3145

acme.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env sh
22

3-
VER=3.1.1
3+
VER=3.1.2
44

55
PROJECT_NAME="acme.sh"
66

@@ -5504,6 +5504,13 @@ renew() {
55045504
if [ -z "$Le_Keylength" ]; then
55055505
Le_Keylength=2048
55065506
fi
5507+
if [ "$CA_LETSENCRYPT_V2" = "$Le_API" ]; then
5508+
#letsencrypt doesn't support ocsp anymore
5509+
if [ "$Le_OCSP_Staple" ]; then
5510+
export Le_OCSP_Staple=""
5511+
_cleardomainconf Le_OCSP_Staple
5512+
fi
5513+
fi
55075514
issue "$Le_Webroot" "$Le_Domain" "$Le_Alt" "$Le_Keylength" "$Le_RealCertPath" "$Le_RealKeyPath" "$Le_RealCACertPath" "$Le_ReloadCmd" "$Le_RealFullChainPath" "$Le_PreHook" "$Le_PostHook" "$Le_RenewHook" "$Le_LocalAddress" "$Le_ChallengeAlias" "$Le_Preferred_Chain" "$Le_Valid_From" "$Le_Valid_To"
55085515
res="$?"
55095516
if [ "$res" != "0" ]; then

dnsapi/dns_azure.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,17 @@ _azure_getaccess_token() {
340340

341341
if [ "$managedIdentity" = true ]; then
342342
# https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/how-to-use-vm-token#get-a-token-using-http
343-
export _H1="Metadata: true"
344-
response="$(_get http://169.254.169.254/metadata/identity/oauth2/token\?api-version=2018-02-01\&resource=https://management.azure.com/)"
343+
if [ -n "$IDENTITY_ENDPOINT" ]; then
344+
# Some Azure environments may set IDENTITY_ENDPOINT (formerly MSI_ENDPOINT) to have an alternative metadata endpoint
345+
url="$IDENTITY_ENDPOINT?api-version=2019-08-01&resource=https://management.azure.com/"
346+
headers="X-IDENTITY-HEADER: $IDENTITY_HEADER"
347+
else
348+
url="http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/"
349+
headers="Metadata: true"
350+
fi
351+
352+
export _H1="$headers"
353+
response="$(_get "$url")"
345354
response="$(echo "$response" | _normalizeJson)"
346355
accesstoken=$(echo "$response" | _egrep_o "\"access_token\":\"[^\"]*\"" | _head_n 1 | cut -d : -f 2 | tr -d \")
347356
expires_on=$(echo "$response" | _egrep_o "\"expires_on\":\"[^\"]*\"" | _head_n 1 | cut -d : -f 2 | tr -d \")

dnsapi/dns_spaceship.sh

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
#!/usr/bin/env sh
2+
# shellcheck disable=SC2034
3+
dns_spaceship_info='Spaceship.com
4+
Site: Spaceship.com
5+
Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_spaceship
6+
Options:
7+
SPACESHIP_API_KEY Spaceship API Key
8+
SPACESHIP_API_SECRET Spaceship API Secret
9+
SPACESHIP_ROOT_DOMAIN (Optional) Manually specify the root domain if auto-detection fails
10+
Issues: github.com/acmesh-official/acme.sh/issues/6304
11+
Author: Meow <https://github.com/Meo597>
12+
'
13+
14+
# Spaceship API
15+
# https://docs.spaceship.dev/
16+
17+
######## Public functions #####################
18+
19+
SPACESHIP_API_BASE="https://spaceship.dev/api/v1"
20+
21+
# Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
22+
# Used to add txt record
23+
dns_spaceship_add() {
24+
fulldomain="$1"
25+
txtvalue="$2"
26+
27+
_info "Adding TXT record for $fulldomain with value $txtvalue"
28+
29+
# Initialize API credentials and headers
30+
if ! _spaceship_init; then
31+
return 1
32+
fi
33+
34+
# Detect root zone
35+
if ! _get_root "$fulldomain"; then
36+
return 1
37+
fi
38+
39+
# Extract subdomain part relative to root domain
40+
subdomain=$(echo "$fulldomain" | sed "s/\.$_domain$//")
41+
if [ "$subdomain" = "$fulldomain" ]; then
42+
_err "Failed to extract subdomain from $fulldomain relative to root domain $_domain"
43+
return 1
44+
fi
45+
_debug "Extracted subdomain: $subdomain for root domain: $_domain"
46+
47+
# Escape txtvalue to prevent JSON injection (e.g., quotes in txtvalue)
48+
escaped_txtvalue=$(echo "$txtvalue" | sed 's/"/\\"/g')
49+
50+
# Prepare payload and URL for adding TXT record
51+
# Note: 'name' in payload uses subdomain (e.g., _acme-challenge.sub) as required by Spaceship API
52+
payload="{\"force\": true, \"items\": [{\"type\": \"TXT\", \"name\": \"$subdomain\", \"value\": \"$escaped_txtvalue\", \"ttl\": 600}]}"
53+
url="$SPACESHIP_API_BASE/dns/records/$_domain"
54+
55+
# Send API request
56+
if _spaceship_api_request "PUT" "$url" "$payload"; then
57+
_info "Successfully added TXT record for $fulldomain"
58+
return 0
59+
else
60+
_err "Failed to add TXT record. If the domain $_domain is incorrect, set SPACESHIP_ROOT_DOMAIN to the correct root domain."
61+
return 1
62+
fi
63+
}
64+
65+
# Usage: fulldomain txtvalue
66+
# Used to remove the txt record after validation
67+
dns_spaceship_rm() {
68+
fulldomain="$1"
69+
txtvalue="$2"
70+
71+
_info "Removing TXT record for $fulldomain with value $txtvalue"
72+
73+
# Initialize API credentials and headers
74+
if ! _spaceship_init; then
75+
return 1
76+
fi
77+
78+
# Detect root zone
79+
if ! _get_root "$fulldomain"; then
80+
return 1
81+
fi
82+
83+
# Extract subdomain part relative to root domain
84+
subdomain=$(echo "$fulldomain" | sed "s/\.$_domain$//")
85+
if [ "$subdomain" = "$fulldomain" ]; then
86+
_err "Failed to extract subdomain from $fulldomain relative to root domain $_domain"
87+
return 1
88+
fi
89+
_debug "Extracted subdomain: $subdomain for root domain: $_domain"
90+
91+
# Escape txtvalue to prevent JSON injection
92+
escaped_txtvalue=$(echo "$txtvalue" | sed 's/"/\\"/g')
93+
94+
# Prepare payload and URL for deleting TXT record
95+
# Note: 'name' in payload uses subdomain (e.g., _acme-challenge.sub) as required by Spaceship API
96+
payload="[{\"type\": \"TXT\", \"name\": \"$subdomain\", \"value\": \"$escaped_txtvalue\"}]"
97+
url="$SPACESHIP_API_BASE/dns/records/$_domain"
98+
99+
# Send API request
100+
if _spaceship_api_request "DELETE" "$url" "$payload"; then
101+
_info "Successfully deleted TXT record for $fulldomain"
102+
return 0
103+
else
104+
_err "Failed to delete TXT record. If the domain $_domain is incorrect, set SPACESHIP_ROOT_DOMAIN to the correct root domain."
105+
return 1
106+
fi
107+
}
108+
109+
#################### Private functions below ##################################
110+
111+
_spaceship_init() {
112+
SPACESHIP_API_KEY="${SPACESHIP_API_KEY:-$(_readaccountconf_mutable SPACESHIP_API_KEY)}"
113+
SPACESHIP_API_SECRET="${SPACESHIP_API_SECRET:-$(_readaccountconf_mutable SPACESHIP_API_SECRET)}"
114+
115+
if [ -z "$SPACESHIP_API_KEY" ] || [ -z "$SPACESHIP_API_SECRET" ]; then
116+
_err "Spaceship API credentials are not set. Please set SPACESHIP_API_KEY and SPACESHIP_API_SECRET."
117+
_err "Ensure \"$LE_CONFIG_HOME\" directory has restricted permissions (chmod 700 \"$LE_CONFIG_HOME\") to protect credentials."
118+
return 1
119+
fi
120+
121+
# Save credentials to account config for future renewals
122+
_saveaccountconf_mutable SPACESHIP_API_KEY "$SPACESHIP_API_KEY"
123+
_saveaccountconf_mutable SPACESHIP_API_SECRET "$SPACESHIP_API_SECRET"
124+
125+
# Set common headers for API requests
126+
export _H1="X-API-Key: $SPACESHIP_API_KEY"
127+
export _H2="X-API-Secret: $SPACESHIP_API_SECRET"
128+
export _H3="Content-Type: application/json"
129+
return 0
130+
}
131+
132+
_get_root() {
133+
domain="$1"
134+
135+
# Check manual override
136+
SPACESHIP_ROOT_DOMAIN="${SPACESHIP_ROOT_DOMAIN:-$(_readdomainconf SPACESHIP_ROOT_DOMAIN)}"
137+
if [ -n "$SPACESHIP_ROOT_DOMAIN" ]; then
138+
_domain="$SPACESHIP_ROOT_DOMAIN"
139+
_debug "Using manually specified or saved root domain: $_domain"
140+
_savedomainconf SPACESHIP_ROOT_DOMAIN "$SPACESHIP_ROOT_DOMAIN"
141+
return 0
142+
fi
143+
144+
_debug "Detecting root zone for '$domain'"
145+
146+
i=1
147+
p=1
148+
while true; do
149+
_cutdomain=$(printf "%s" "$domain" | cut -d . -f "$i"-100)
150+
151+
_debug "Attempt i=$i: Checking if '$_cutdomain' is root zone (cut ret=$?)"
152+
153+
if [ -z "$_cutdomain" ]; then
154+
_debug "Cut resulted in empty string, root zone not found."
155+
break
156+
fi
157+
158+
# Call the API to check if this _cutdomain is a manageable zone
159+
if _spaceship_api_request "GET" "$SPACESHIP_API_BASE/dns/records/$_cutdomain?take=1&skip=0"; then
160+
# API call succeeded (HTTP 200 OK for GET /dns/records)
161+
_domain="$_cutdomain"
162+
_debug "Root zone found: '$_domain'"
163+
164+
# Save the detected root domain
165+
_savedomainconf SPACESHIP_ROOT_DOMAIN "$_domain"
166+
_info "Root domain '$_domain' saved to configuration for future use."
167+
168+
return 0
169+
fi
170+
171+
_debug "API check failed for '$_cutdomain'. Continuing search."
172+
173+
p=$i
174+
i=$((i + 1))
175+
done
176+
177+
_err "Could not detect root zone for '$domain'. Please set SPACESHIP_ROOT_DOMAIN manually."
178+
return 1
179+
}
180+
181+
_spaceship_api_request() {
182+
method="$1"
183+
url="$2"
184+
payload="$3"
185+
186+
_debug2 "Sending $method request to $url with payload $payload"
187+
if [ "$method" = "GET" ]; then
188+
response="$(_get "$url")"
189+
else
190+
response="$(_post "$payload" "$url" "" "$method")"
191+
fi
192+
193+
if [ "$?" != "0" ]; then
194+
_err "API request failed. Response: $response"
195+
return 1
196+
fi
197+
198+
_debug2 "API response body: $response"
199+
200+
if [ "$method" = "GET" ]; then
201+
if _contains "$(_head_n 1 <"$HTTP_HEADER")" '200'; then
202+
return 0
203+
fi
204+
else
205+
if _contains "$(_head_n 1 <"$HTTP_HEADER")" '204'; then
206+
return 0
207+
fi
208+
fi
209+
210+
_debug2 "API response header: $HTTP_HEADER"
211+
return 1
212+
}

0 commit comments

Comments
 (0)