Skip to content

Commit 7de093e

Browse files
authored
Improve utility scripts (cloudflare#169)
* Make the create log script edit the wrangler.jsonc * Add script to create the ccadb_roots kv namespace * Make location optional * Improve script correctness * Update ct_worker/readme to mention scripts * Run shellcheck
1 parent 5b84b42 commit 7de093e

File tree

3 files changed

+103
-31
lines changed

3 files changed

+103
-31
lines changed

crates/ct_worker/README.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,36 +104,48 @@ Follow these instructions to deploy a CT log with the `dev` configuration to Clo
104104
105105
Run the following for each of the `dev2025h1a` and `dev2025h2a` log shards to configure resources (or use `scripts/create-log.sh`):
106106
107-
1. Set log shard name and deployment environment.
107+
1. Set log shard name and deployment environment. The [location hint][location-hint] is optional.
108108
109-
export LOG_NAME=dev2025h1a
110-
export ENV=dev
109+
```bash
110+
export LOG_NAME=dev2025h1a
111+
export CLOUDFLARE_ACCOUNT_ID=some-account-id-here
112+
export ENV=dev
113+
export LOCATION=wnam # optional
114+
```
111115

112-
1. Create R2 bucket for public assets, optionally with a [location hint](https://developers.cloudflare.com/r2/reference/data-location/).
116+
1. Setup the roots kv namespace
113117

114-
npx wrangler r2 bucket create static-ct-public-${LOG_NAME} [--location <location>]
118+
```bash
119+
npx wrangler -e="${ENV}" kv namespace create static-ct-ccadb-roots --binding ccadb_roots
120+
```
115121

116-
1. Create KV namespace for per-log deduplication cache.
122+
**Alternatively run the script [create-root-kv.sh](./scripts/create-root-kv.sh)**
117123

118-
```text
119-
# After running, add generated namespace ID to `wrangler.jsonc`
120-
npx wrangler kv namespace create static-ct-cache-${LOG_NAME}
121-
```
124+
1. Create the the R2 bucket for public assets, the kv namespace for per-log
125+
deduplication cache and generate the [secrets][secrets-docs] for signing and witness keys.
122126

123-
1. Generate [secrets](https://developers.cloudflare.com/workers/configuration/secrets) for the signing and witness keys. NOTE: this will overwrite any existing secrets of the same name.
127+
```bash
128+
npx wrangler r2 bucket create static-ct-public-${LOG_NAME} [--location <location>]
129+
npx wrangler kv namespace create static-ct-cache-${LOG_NAME}
130+
openssl genpkey -algorithm ed25519 | npx wrangler -e=${ENV} secret put WITNESS_KEY_${LOG_NAME}
131+
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 | npx wrangler -e=${ENV} secret put SIGNING_KEY_${LOG_NAME}
132+
```
124133

125-
openssl genpkey -algorithm ed25519 | npx wrangler -e=${ENV} secret put WITNESS_KEY_${LOG_NAME}
126-
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 | npx wrangler -e=${ENV} secret put SIGNING_KEY_${LOG_NAME}
134+
**Alternatively, simply run the script [create-log.sh](./scripts/create-log.sh)**
127135

128-
(Note: For mtc_worker we use ed25519 for the signing key. There is no witness.)
136+
(Note: For mtc_worker we use ed25519 for the signing key. There is no witness.)
129137

130138
1. Deploy the worker. The worker will be available at `https://static-ct-${ENV}.<your-team>.workers.dev/logs/${LOG_NAME}`.
131139

132-
npx wrangler -e=${ENV} deploy
140+
```bash
141+
npx wrangler -e=${ENV} deploy
142+
```
133143

134144
1. Tail the worker:
135145

136-
npx wrangler -e=${ENV} tail
146+
```bash
147+
npx wrangler -e=${ENV} tail
148+
```
137149

138150
1. Send some requests. See [local development](#local-deployment) for examples.
139151

@@ -197,3 +209,7 @@ This project ports code from [sunlight](https://github.com/FiloSottile/sunlight)
197209
## License
198210

199211
The project is licensed under the [BSD-3-Clause License](./LICENSE).
212+
213+
214+
location-hint: https://developers.cloudflare.com/r2/reference/data-location/
215+
secrets-docs: https://developers.cloudflare.com/workers/configuration/secrets
Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,74 @@
11
#!/usr/bin/env bash
22

33
set -e -o pipefail
4+
cd "$(dirname "$0")/.." || exit # this script assumes it's runnnig inside the ct_worker dir
45

56
# Helper script to create resources for a log shard.
67

7-
if [ -z $ENV ] || [ -z $LOG_NAME ] || [ -z $LOCATION ] || [ -z $CLOUDFLARE_ACCOUNT_ID ]; then
8-
echo "ENV, LOG_NAME, LOCATION, and CLOUDFLARE_ACCOUNT_ID must all be set"
8+
if [ -z "${ENV}" ] || [ -z "${LOG_NAME}" ] || [ -z "${CLOUDFLARE_ACCOUNT_ID}" ]; then
9+
echo "ENV, LOG_NAME, and CLOUDFLARE_ACCOUNT_ID must all be set"
910
exit 1
1011
fi
1112

1213
WRANGLER_CONF=${WRANGLER_CONF:-wrangler.jsonc}
1314

1415
while true; do
15-
read -p "Do you want to proceed with ENV=${ENV}, LOG_NAME=${LOG_NAME}, LOCATION=${LOCATION}, CLOUDFLARE_ACCOUNT_ID=${CLOUDFLARE_ACCOUNT_ID}? (y/N) " yn
16+
if [ "${LOCATION}" ]; then
17+
L=", LOCATION=${LOCATION}"
18+
fi
19+
read -rp "Do you want to proceed with ENV=${ENV}, LOG_NAME=${LOG_NAME}${L}, CLOUDFLARE_ACCOUNT_ID=${CLOUDFLARE_ACCOUNT_ID}? (y/N) " yn
1620
case $yn in
1721
[yY] ) echo "Proceeding..."; break;;
1822
[nN] ) echo "Exiting..."; exit;;
1923
* ) echo "Invalid input. Please enter 'y' or 'N'.";;
2024
esac
2125
done
2226

27+
28+
# https://github.com/cloudflare/azul/pull/169#discussion_r2582145507
29+
location=()
30+
if [ "${LOCATION}" ]; then
31+
location=(--location "${LOCATION}")
32+
fi
33+
2334
# Create R2 bucket if it does not already exist
24-
npx wrangler -e="${ENV}" -c "${WRANGLER_CONF}" r2 bucket create static-ct-public-${LOG_NAME} --location ${LOCATION}
35+
npx wrangler \
36+
-e="${ENV}" \
37+
-c "${WRANGLER_CONF}" \
38+
r2 bucket create \
39+
"static-ct-public-${LOG_NAME}" \
40+
--update-config \
41+
--binding "public_${LOG_NAME}" "${location[@]}"
2542

2643
# Create KV namespace if it does not already exist
27-
npx wrangler -e="${ENV}" -c "${WRANGLER_CONF}" kv namespace create static-ct-cache-${LOG_NAME}
44+
npx wrangler \
45+
-e="${ENV}" \
46+
-c "${WRANGLER_CONF}" \
47+
kv namespace create \
48+
"static-ct-cache-${LOG_NAME}" \
49+
--update-config \
50+
--binding "cache_${LOG_NAME}"
2851

2952
# Create witness and log signing keys if they do not already exist
30-
if npx wrangler -e=${ENV} secret list | grep -q WITNESS_KEY_${LOG_NAME}; then
53+
if npx wrangler -e="${ENV}" -c "${WRANGLER_CONF}" secret list | grep -q "WITNESS_KEY_${LOG_NAME}"; then
3154
echo "WITNESS_KEY_${LOG_NAME} already exists"
3255
else
33-
openssl genpkey -algorithm ed25519 | npx wrangler -c "$WRANGLER_CONF" -e=${ENV} secret put WITNESS_KEY_${LOG_NAME}
56+
openssl genpkey -algorithm ed25519 |
57+
npx wrangler -e="${ENV}" -c "${WRANGLER_CONF}" secret put "WITNESS_KEY_${LOG_NAME}"
3458
fi
35-
if npx wrangler -e=${ENV} secret list | grep -q SIGNING_KEY_${LOG_NAME}; then
59+
if npx wrangler -e="${ENV}" -c "${WRANGLER_CONF}" secret list | grep -q "SIGNING_KEY_${LOG_NAME}"; then
3660
echo "SIGNING_KEY_${LOG_NAME} already exists"
3761
else
38-
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 | npx wrangler -c "$WRANGLER_CONF" -e=${ENV} secret put SIGNING_KEY_${LOG_NAME}
62+
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 |
63+
npx wrangler -e="${ENV}" -c "${WRANGLER_CONF}" secret put "SIGNING_KEY_${LOG_NAME}"
3964
fi
4065

4166
echo "DONE"
4267
echo "NOTE: If you intend to run wrangler dev with this log, you must add the appropriate signing keys to .dev.vars"
4368
echo "~~~~~~"
44-
echo "echo -n \"SIGNING_KEY_${LOG_NAME}=\\\\\"\" >> .dev.vars"
45-
echo "openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 | sed 's/$/\\\\\\\\\\\\\\\\n/g' | tr -d \\\\n >> .dev.vars"
46-
echo "echo '\"' >> .dev.vars"
47-
echo "echo -n \"WITNESS_KEY_${LOG_NAME}=\\\\\"\" >> .dev.vars"
48-
echo "openssl genpkey -algorithm ed25519 | sed 's/$/\\\\\\\\\\\\\\\\n/g' | tr -d \\\\n >> .dev.vars"
49-
echo "echo '\"' >> .dev.vars"
69+
printf 'echo -n "SIGNING_KEY_%s=\\"" >> .dev.vars\n' "${LOG_NAME}"
70+
printf 'openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 | sed '\''s/$/\\\\n/g'\'' | tr -d '\''\\n'\'' >> .dev.vars\n'
71+
printf 'echo \\" >> .dev.vars\n'
72+
printf 'echo -n "WITNESS_KEY_%s=\\"" >> .dev.vars\n' "${LOG_NAME}"
73+
printf 'openssl genpkey -algorithm ed25519 | sed '\''s/$/\\\\n/g'\'' | tr -d '\''\\n'\'' >> .dev.vars\n'
74+
printf 'echo \\" >> .dev.vars\n'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -o pipefail
4+
cd "$(dirname "$0")/.." || exit # this script assumes it's runnnig inside the ct_worker dir
5+
6+
# Helper script to create resources for a log shard.
7+
8+
if [ -z "${ENV}" ] || [ -z "${CLOUDFLARE_ACCOUNT_ID}" ]; then
9+
echo "ENV and CLOUDFLARE_ACCOUNT_ID must all be set"
10+
exit 1
11+
fi
12+
13+
WRANGLER_CONF=${WRANGLER_CONF:-wrangler.jsonc}
14+
15+
while true; do
16+
read -rp "Do you want to proceed with ENV=${ENV}, CLOUDFLARE_ACCOUNT_ID=${CLOUDFLARE_ACCOUNT_ID}? (y/N) " yn
17+
case $yn in
18+
[yY] ) echo "Proceeding..."; break;;
19+
[nN] ) echo "Exiting..."; exit;;
20+
* ) echo "Invalid input. Please enter 'y' or 'N'.";;
21+
esac
22+
done
23+
24+
# Create KV namespace if it does not already exist
25+
npx wrangler \
26+
-e="${ENV}" \
27+
-c "${WRANGLER_CONF}" \
28+
kv namespace create \
29+
static-ct-ccadb-roots \
30+
--update-config \
31+
--binding ccadb_roots

0 commit comments

Comments
 (0)