Skip to content

Commit f7cb224

Browse files
authored
docs: add runbook for updating session key (#147)
* docs: add runbook for updating session key * chore: fix lint
1 parent 4e7a0d0 commit f7cb224

3 files changed

Lines changed: 212 additions & 1 deletion

File tree

docs/update-session-key.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Runbook: Update session key for pin.filecoin.cloud
2+
3+
This runbook describes how to create or refresh the session key used by [pin.filecoin.cloud](https://pin.filecoin.cloud), and how to avoid expiry-related outages. See also [Refresh session key (issue #146)](https://github.com/filecoin-project/filecoin-pin-website/issues/146).
4+
5+
## Context
6+
7+
- The site uses **session key** auth (not the main wallet private key) so the app can create datasets and add pieces without exposing the owner key.
8+
- The session key is valid for a fixed period (e.g. 180 days). When it expires, users see: *"Session key expired or expiring soon"*.
9+
- **Owner wallet:** `0x44f08D1beFe61255b3C3A349C392C560FA333759`
10+
- The **private key** for this wallet is stored in the team’s secure secret store. Use it only to run the script below; never commit it or paste it into docs.
11+
12+
## Prerequisites
13+
14+
- [Foundry](https://book.getfoundry.sh/getting-started/installation) installed (`cast` is used by the script).
15+
- Access to the **private key** for `0x44f08D1beFe61255b3C3A349C392C560FA333759` (from the team secret store).
16+
- Access to update environment variables for the project on Vercel (see [Vercel env vars](#update-environment-variables-on-vercel)).
17+
- Optional: access to the **Filoz team calendar** to create reminder events (or someone who can create them).
18+
19+
## 1. Create a new session key
20+
21+
From the **repository root**:
22+
23+
```bash
24+
# Recommended: 180 days validity to reduce how often you need to rotate
25+
PRIVATE_KEY=<private_key_for_0x44f08D1beFe61255b3C3A349C392C560FA333759> ./scripts/create-session-key.sh 180
26+
```
27+
28+
- Replace `<private_key_for_0x44f08D1beFe61255b3C3A349C392C560FA333759>` with the actual key (from your secret store). It must be the key for the owner wallet above.
29+
- The script will:
30+
- Generate a new session key.
31+
- Resolve the current session key registry from Warm Storage (same as the app).
32+
- Authorize the session key on-chain with CreateDataSet and AddPieces permissions.
33+
- Print **VITE_WALLET_ADDRESS** and **VITE_SESSION_KEY** to add to your env.
34+
35+
**Note the expiry date** printed by the script (e.g. *"Validity: 180 days (expires: YYYY-MM-DD HH:MM:SS)"*). You will use this for calendar reminders and the next rotation.
36+
37+
## 2. Create calendar reminder (before expiry)
38+
39+
To avoid the session key expiring unnoticed, create **one recurring event** on the **Filoz team calendar**:
40+
41+
### Option A: Google Calendar link (quick)
42+
43+
Use a pre-filled Google Calendar link, then adjust dates and set repeat:
44+
45+
1. **Open a pre-filled event** using one of these:
46+
- **Example (copy and edit):** [Open in Google Calendar (expires 2026-08-15)](https://calendar.google.com/calendar/render?action=TEMPLATE&text=Filecoin-pin-website+session+key+expiring+soon%3A+expires%3A+2026-08-15+09%3A24%3A22&dates=20260715T092400Z/20260715T095400Z&details=Rotate+using+runbook%3A+https%3A%2F%2Fgithub.com%2Ffilecoin-project%2Ffilecoin-pin-website%2Fblob%2Fmain%2Fdocs%2Fupdate-session-key.md&add=infra%40filoz.org%2Cbiglep%40filoz.org%2Corjan%40filoz.org%2Csgtpooki%40filoz.org) — then change the title (expires date) and the event start/end to **your** expiry and **1 month before** that (same time).
47+
- **Or build your own:** use `https://calendar.google.com/calendar/render?action=TEMPLATE&text=...&dates=START/END&details=...&add=...` with title `Filecoin-pin-website session key expiring soon: expires: YYYY-MM-DD HH:MM:SS`, `dates` in UTC as `YYYYMMDDTHHMMSSZ/YYYYMMDDTHHMMSSZ` (first occurrence = 1 month before expiry), and `add=infra@filoz.org,biglep@filoz.org,orjan@filoz.org,sgtpooki@filoz.org` (URL-encode the whole query).
48+
49+
2. After the event form opens, set **Repeat****Weekly****End after 4 occurrences**, then save. Guests (infra@filoz.org, biglep@filoz.org, orjan@filoz.org, sgtpooki@filoz.org) are pre-filled.
50+
51+
**Date format for `dates=`:** use UTC in the form `YYYYMMDDTHHMMSSZ` for start and end (e.g. `20260715T092400Z` = 2026-07-15 09:24:00 UTC). End can be 30–60 minutes after start.
52+
53+
### Option B: Create the event manually
54+
55+
1. **Title:** `Filecoin-pin-website session key expiring soon: expires: YYYY-MM-DD HH:MM:SS` (use the **expires** value from the script).
56+
2. **When:** First occurrence **1 month before** the expiry date.
57+
3. **Repeat:** Custom repeat **ending after 4 occurrences** (e.g. weekly → 1 month, 3 weeks, 2 weeks, 1 week before expiry).
58+
4. **Invite:** infra@filoz.org, biglep@filoz.org, orjan@filoz.org, sgtpooki@filoz.org.
59+
60+
## 3. Update environment variables on Vercel
61+
62+
After running the script, update the production environment so the site uses the new session key:
63+
64+
1. Open **[Vercel → filecoin-pin-website → Settings → Environment Variables](https://vercel.com/filoz/filecoin-pin-website/settings/environment-variables)**.
65+
2. Update (or add) for **Production** (and Preview if you use session auth there):
66+
- **VITE_WALLET_ADDRESS** = `0x44f08D1beFe61255b3C3A349C392C560FA333759` (owner address; only changes if the owner wallet changes).
67+
- **VITE_SESSION_KEY** = the **new** session key private key printed by the script (starts with `0x...`).
68+
3. Save. Trigger a new deployment if Vercel doesn’t auto-redeploy so the new values are used.
69+
70+
Do **not** commit `VITE_SESSION_KEY` or the owner private key to the repo.
71+
72+
## 4. Verify
73+
74+
- Visit [pin.filecoin.cloud](https://pin.filecoin.cloud) and try an action that uses the session key (e.g. create a dataset or add content). If it works without “Session key expired or expiring soon”, the update was successful.
75+
- Optionally run the app locally with the same `VITE_WALLET_ADDRESS` and `VITE_SESSION_KEY` in `.env` to double-check.
76+
77+
## Summary checklist
78+
79+
- [ ] Retrieved private key for `0x44f08D1beFe61255b3C3A349C392C560FA333759` from the team secret store.
80+
- [ ] Ran `./scripts/create-session-key.sh 180` and noted the expiry date.
81+
- [ ] Created one recurring calendar event (title: "Filecoin-pin-website session key expiring soon: expires: &lt;date from script&gt;", first occurrence 1 month before expiry, custom repeat ending after 4 occurrences), tagging infra@filoz.org, biglep@filoz.org, orjan@filoz.org, sgtpooki@filoz.org.
82+
- [ ] Updated **VITE_SESSION_KEY** on [Vercel environment variables](https://vercel.com/filoz/filecoin-pin-website/settings/environment-variables).
83+
- [ ] Redeployed or confirmed deployment uses the new env vars.
84+
- [ ] Verified the site works without session key expiry errors.
85+
86+
## References
87+
88+
- [Refresh session key (issue #146)](https://github.com/filecoin-project/filecoin-pin-website/issues/146)
89+
- Script: [scripts/create-session-key.sh](../scripts/create-session-key.sh)
90+
- Vercel env vars: [filoz/filecoin-pin-website → Settings → Environment Variables](https://vercel.com/filoz/filecoin-pin-website/settings/environment-variables)

scripts/create-session-key.sh

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
#
3+
# CREATE SESSION KEY
4+
#
5+
# Creates and authorizes a new session key for use with Synapse SDK.
6+
# Session keys allow delegated access without exposing your main private key.
7+
#
8+
# USAGE:
9+
# PRIVATE_KEY=0x... ./create-session.sh [VALIDITY_DAYS]
10+
#
11+
# ARGUMENTS:
12+
# VALIDITY_DAYS Number of days the session key should be valid (default: 10)
13+
#
14+
# ENVIRONMENT VARIABLES:
15+
# PRIVATE_KEY Your main wallet's private key (required)
16+
#
17+
# EXAMPLES:
18+
# # Create a session key valid for 10 days (default)
19+
# PRIVATE_KEY=0xabc123... ./create-session.sh
20+
#
21+
# # Create a session key valid for 30 days
22+
# PRIVATE_KEY=0xabc123... ./create-session.sh 30
23+
#
24+
# OUTPUT:
25+
# The script outputs environment variables to add to your .env file:
26+
# - VITE_WALLET_ADDRESS: Your main wallet address
27+
# - VITE_SESSION_KEY: The generated session key private key
28+
#
29+
# PERMISSIONS GRANTED:
30+
# - CREATE_DATA_SET: Create new datasets
31+
# - ADD_PIECES: Add data pieces to datasets
32+
#
33+
# SECURITY NOTE:
34+
# Keep the session key secure. If compromised, revoke it immediately
35+
# using ./revoke-session.sh
36+
#
37+
# NOTE (registry address):
38+
# The session key registry address is resolved from the Warm Storage contract
39+
# (same as the website/SDK). If contracts are upgraded, re-run this script to
40+
# create a new session key; the script will use the current registry.
41+
#
42+
set -e
43+
44+
# Configuration
45+
# These must match the addresses/typehashes used by @filoz/synapse-sdk (Warm Storage → sessionKeyRegistry, EIP712_TYPE_HASHES)
46+
VALIDITY_DAYS="${1:-10}" # Default to 10 days, override with first argument
47+
RPC_URL="${VITE_FILECOIN_RPC_URL:-https://api.calibration.node.glif.io/rpc/v1}"
48+
# Warm Storage on calibration - SDK uses this to resolve sessionKeyRegistry()
49+
WARM_STORAGE_CALIBRATION="0x02925630df557F957f70E112bA06e50965417CA0"
50+
# sessionKeyRegistry() selector (keccak256 "sessionKeyRegistry()" truncated to 4 bytes)
51+
SESSION_KEY_REGISTRY_SELECTOR="0x9f6aa572"
52+
# EIP-712 type hashes from @filoz/synapse-sdk (CreateDataSet, AddPieces) - used as permission identifiers
53+
CREATE_DATA_SET_TYPEHASH="0x25ebf20299107c91b4624d5bac3a16d32cabf0db23b450ee09ab7732983b1dc9"
54+
ADD_PIECES_TYPEHASH="0x954bdc254591a7eab1b73f03842464d9283a08352772737094d710a4428fd183"
55+
56+
# Check required env var
57+
if [ -z "$PRIVATE_KEY" ]; then
58+
echo "Error: PRIVATE_KEY environment variable is required" >&2
59+
exit 1
60+
fi
61+
62+
echo "Step 1: Generating new session key..."
63+
# Generate new session key
64+
SESSION_KEY_OUTPUT=$(cast wallet new)
65+
SESSION_KEY_ADDRESS=$(echo "$SESSION_KEY_OUTPUT" | grep "Address:" | awk '{print $2}')
66+
SESSION_KEY_PRIVATE=$(echo "$SESSION_KEY_OUTPUT" | grep "Private key:" | awk '{print $3}')
67+
echo " Session key address: $SESSION_KEY_ADDRESS"
68+
echo " Session key private: ${SESSION_KEY_PRIVATE:0:20}..."
69+
70+
echo "Step 2: Calculating expiry timestamp..."
71+
# Calculate expiry timestamp
72+
CURRENT_TIME=$(date +%s)
73+
EXPIRY=$((CURRENT_TIME + VALIDITY_DAYS * 24 * 60 * 60))
74+
echo " Expiry: $(date -r $EXPIRY '+%Y-%m-%d %H:%M:%S')"
75+
76+
echo "Step 3: Getting owner address from private key..."
77+
# Get owner address
78+
OWNER_ADDRESS=$(cast wallet address --private-key "$PRIVATE_KEY")
79+
echo " Owner address: $OWNER_ADDRESS"
80+
81+
echo "Step 4: Resolving session key registry from Warm Storage (must match SDK)..."
82+
# Fetch current registry address from Warm Storage so we always authorize on the same contract the app uses
83+
REGISTRY_RESPONSE=$(curl -s -X POST "$RPC_URL" -H "Content-Type: application/json" --data "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{\"to\":\"$WARM_STORAGE_CALIBRATION\",\"data\":\"$SESSION_KEY_REGISTRY_SELECTOR\"},\"latest\"],\"id\":1}")
84+
REGISTRY_HEX=$(echo "$REGISTRY_RESPONSE" | grep -o '"result":"[^"]*"' | cut -d'"' -f4)
85+
if [ -z "$REGISTRY_HEX" ] || [ "$REGISTRY_HEX" = "0x" ]; then
86+
echo "Error: Failed to get session key registry from Warm Storage. Check RPC_URL and network." >&2
87+
exit 1
88+
fi
89+
# Decode 32-byte left-padded address (last 40 hex chars = 20 bytes)
90+
REGISTRY="0x${REGISTRY_HEX: -40}"
91+
echo " Registry: $REGISTRY"
92+
93+
echo "Step 5: Authorizing session key on-chain (this may take a minute)..."
94+
echo " RPC URL: $RPC_URL"
95+
# login(signer, expiry, permissions, origin) - origin is required by the SessionKeyRegistry contract
96+
ORIGIN="${SESSION_LOGIN_ORIGIN:-filecoin-pin-website}"
97+
cast send $REGISTRY \
98+
"login(address,uint256,bytes32[],string)" \
99+
"$SESSION_KEY_ADDRESS" \
100+
"$EXPIRY" \
101+
"[$CREATE_DATA_SET_TYPEHASH,$ADD_PIECES_TYPEHASH]" \
102+
"$ORIGIN" \
103+
--private-key "$PRIVATE_KEY" \
104+
--rpc-url "$RPC_URL"
105+
106+
# Output results
107+
echo ""
108+
echo "=========================================="
109+
echo "Session key created successfully!"
110+
echo "=========================================="
111+
echo "Validity: $VALIDITY_DAYS days (expires: $(date -r $EXPIRY '+%Y-%m-%d %H:%M:%S'))"
112+
echo ""
113+
echo "Add these to your .env file:"
114+
echo "------------------------------------------"
115+
echo "VITE_WALLET_ADDRESS=$OWNER_ADDRESS"
116+
echo "VITE_SESSION_KEY=$SESSION_KEY_PRIVATE"
117+
echo ""
118+
echo "Session key info (for debugging):"
119+
echo "------------------------------------------"
120+
echo "SESSION_KEY_ADDRESS=$SESSION_KEY_ADDRESS"
121+
echo "OWNER_ADDRESS=$OWNER_ADDRESS"

src/hooks/use-dataset-pieces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { METADATA_KEYS } from '@filoz/synapse-sdk'
2+
import { getDetailedDataSet } from 'filecoin-pin/core/data-set'
23
import { useCallback, useEffect, useState } from 'react'
34
import { useFilecoinPinContext } from './use-filecoin-pin-context.ts'
4-
import { getDetailedDataSet } from 'filecoin-pin/core/data-set'
55

66
export interface DatasetPiece {
77
id: string

0 commit comments

Comments
 (0)