Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

replace sample secret key for plausible with a more obvioulsy safe value (#4283)

Princewill Onyenanu0ed6673a6721
diff --git a/docker/plausible/env.docker b/docker/plausible/env.docker
index 0c22b92ca..5c270f472 100644
--- a/docker/plausible/env.docker
+++ b/docker/plausible/env.docker
@@ -1,4 +1,5 @@
BASE_URL=http://localhost:50288
-SECRET_KEY_BASE=MN00EYOjQegVd5Z2NkMoSk3o1cklN/37YINtjYtM3yxsoXUhRNnvgWu3pgnEibKR126HmlGeHu7KHpPaYj/Awg==
+API_KEY=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+SECRET_KEY_BASE=this_is_a_sample_secret_key_longer_than_64_bytes_this_is_a_sample_secret_key_longer_than_64_bytes
DATABASE_URL=postgres://deploy:deploy@plausible_db:5432/plausible
CLICKHOUSE_DATABASE_URL=http://plausible_ch:8123/plausible_ch
diff --git a/setup_plausible.sh b/setup_plausible.sh
index 383a0c9d1..44780085a 100755
--- a/setup_plausible.sh
+++ b/setup_plausible.sh
@@ -8,18 +8,21 @@ docker compose exec -T "$PLAUSIBLE_SERVICE_NAME" \
/app/bin/plausible rpc \
'Plausible.Auth.User.new(%{name: "Deploy", email: "[email protected]", password: "deploy", password_confirmation: "deploy"}) |> Plausible.Repo.insert'
-# Create an API key with '{sites:provision:*}' scope
-# API key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa (that's 64 times 'a')
-# Key hash: SHA256(`SECRET_KEY_BASE` + API key)
+# load necessary environment variables into shell session
+# Note: API_KEY with '{sites:provision:*}' scope and SECRET_KEY_BASE
+# are both gotten from env file.
+# shellcheck disable=SC1091
+source docker/plausible/env.docker
+
docker compose exec -T "$PLAUSIBLE_DB_SERVICE_NAME" /bin/bash -c "psql -U deploy -d plausible <<-EOF
INSERT INTO api_keys
(id, user_id, name, key_prefix, key_hash, inserted_at, updated_at, scopes, hourly_request_limit)
VALUES
- (1, 1, 'Development', 'aaaaaa', '332015ffc9f0e1f475c0fadb1e1a14d2eb09774249f71961f5a2c477efc0a0fc', now(), now(), '{sites:provision:*}', 1000)
+ (1, 1, 'Development', 'aaaaaa', encode(digest('$SECRET_KEY_BASE$API_KEY', 'sha256'), 'hex'), now(), now(), '{sites:provision:*}', 1000)
ON CONFLICT (id) DO NOTHING
EOF"
-authorization_header="Authorization: Bearer aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+authorization_header="Authorization: Bearer $API_KEY"
local_plausible="http://localhost:50288"
# Create site using API key