Skip to content

Commit 0727108

Browse files
committed
Secure answer key - use GitHub Secrets instead of committing
SECURITY FIX: Students would've seen the answer key! Changes: - Remove answer_key.json from git tracking - Add .github/grading/answer_key.json to .gitignore - Update autograding.yml to read answer key from GitHub Secret - Create README_INSTRUCTOR.md with setup instructions How it works now: 1. Instructor runs analysis, gets answers.json 2. Instructor adds answers.json as ANSWER_KEY_JSON GitHub Secret 3. GitHub Actions reads secret (students can't access it!) 4. Grading happens server-side with secret key 5. Students never see the answers Instructor TODO: - Run ./run-analysis.sh - Run python3 answer_assignment.py - Copy answers.json to GitHub Secret: ANSWER_KEY_JSON - See .github/grading/README_INSTRUCTOR.md for details
1 parent 2fe4e7e commit 0727108

4 files changed

Lines changed: 135 additions & 36 deletions

File tree

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Instructor Setup: Automated Grading
2+
3+
## How to Set Up the Answer Key (CRITICAL!)
4+
5+
The answer key is stored as a **GitHub Secret** so students can't see it.
6+
7+
### Step 1: Generate the Answer Key
8+
9+
Run the analysis yourself to get the correct answers:
10+
11+
```bash
12+
# Run the analysis on the class data
13+
./run-analysis.sh
14+
15+
# Answer the questions interactively
16+
python3 answer_assignment.py
17+
18+
# This creates answers.json with the CORRECT answers
19+
```
20+
21+
### Step 2: Copy the Answer Key JSON
22+
23+
```bash
24+
# Copy the contents of answers.json
25+
cat answers.json
26+
```
27+
28+
**Copy the entire JSON output** (you'll need this in the next step)
29+
30+
### Step 3: Add to GitHub Secrets
31+
32+
**For the Template Repository:**
33+
34+
1. Go to: https://github.com/cosmelab/dna-barcoding-analysis/settings/secrets/actions
35+
2. Click **"New repository secret"**
36+
3. Name: `ANSWER_KEY_JSON`
37+
4. Value: **Paste the entire JSON from answers.json**
38+
5. Click **"Add secret"**
39+
40+
**For GitHub Classroom (ALL student repos):**
41+
42+
You need to add the secret to EACH student repository, OR use GitHub Classroom's secret sync feature:
43+
44+
1. Go to your GitHub Classroom assignment settings
45+
2. Under "Secrets", add the secret there
46+
3. It will sync to all student repositories
47+
48+
**Alternative: Manual per-repo setup**
49+
50+
If you don't use Classroom secrets:
51+
52+
```bash
53+
# Use GitHub CLI to add secret to all student repos
54+
gh secret set ANSWER_KEY_JSON --body "$(cat answers.json)" -R cosmelab/dna-barcoding-analysis-STUDENT1
55+
gh secret set ANSWER_KEY_JSON --body "$(cat answers.json)" -R cosmelab/dna-barcoding-analysis-STUDENT2
56+
# ... repeat for all students
57+
```
58+
59+
Or write a script:
60+
61+
```bash
62+
#!/bin/bash
63+
ANSWER_KEY=$(cat answers.json)
64+
65+
for repo in $(gh repo list cosmelab --json name -q '.[] | select(.name | startswith("dna-barcoding-analysis-")) | .name'); do
66+
echo "Adding secret to $repo..."
67+
gh secret set ANSWER_KEY_JSON --body "$ANSWER_KEY" -R cosmelab/$repo
68+
done
69+
```
70+
71+
### Step 4: Verify It Works
72+
73+
1. Make a test commit to a student repo
74+
2. Check the Actions tab
75+
3. The grading step should run and check answers
76+
77+
## How the Grading Works
78+
79+
1. Student runs `python3 answer_assignment.py` → creates `answers.json`
80+
2. Student commits and pushes `answers.json`
81+
3. GitHub Actions workflow runs:
82+
- Checks tutorial complete
83+
- Checks analysis complete
84+
- **Grades answers.json against secret answer key**
85+
- Returns feedback and score
86+
4. Student sees ✅ or ❌ in Actions tab
87+
88+
## Updating the Answer Key
89+
90+
If you need to update the answer key (e.g., fix a typo):
91+
92+
1. Update your local `answers.json`
93+
2. Copy the new JSON
94+
3. Go to repository secrets
95+
4. Edit `ANSWER_KEY_JSON`
96+
5. Paste the new JSON
97+
6. Save
98+
99+
The next time students push, they'll be graded against the new key.
100+
101+
## Security
102+
103+
- ✅ Answer key stored as GitHub Secret (encrypted)
104+
- ✅ Students cannot access secrets
105+
- ✅ Answer key not in git history
106+
- ✅ Answer key created in /tmp and deleted after grading
107+
- ✅ GitHub Classroom can sync secrets to all student repos
108+
109+
## Troubleshooting
110+
111+
**Error: "ANSWER_KEY_JSON secret not found"**
112+
- Make sure you added the secret to the repository
113+
- Check the secret name is exactly `ANSWER_KEY_JSON`
114+
- For Classroom, make sure secret sync is enabled
115+
116+
**Students getting wrong grades**
117+
- Check your answer key JSON is valid
118+
- Run the analysis yourself to verify correct answers
119+
- Look at the Actions log for grading feedback
120+
121+
**Need to disable auto-grading temporarily?**
122+
- Remove the secret (students will get "answers_graded=false")
123+
- Or comment out the grading step in `.github/workflows/autograding.yml`

.github/grading/answer_key.json

Lines changed: 0 additions & 35 deletions
This file was deleted.

.github/workflows/autograding.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ jobs:
148148

149149
- name: Grade Assignment Answers
150150
id: grading
151+
env:
152+
ANSWER_KEY: ${{ secrets.ANSWER_KEY_JSON }}
151153
run: |
152154
echo "Grading assignment answers..."
153155
@@ -157,10 +159,16 @@ jobs:
157159
exit 0
158160
fi
159161
162+
# Create answer key from secret
163+
echo "$ANSWER_KEY" > /tmp/answer_key.json
164+
160165
# Run grading script
161-
python3 .github/grading/grade_answers.py answers.json .github/grading/answer_key.json
166+
python3 .github/grading/grade_answers.py answers.json /tmp/answer_key.json
162167
GRADE_EXIT_CODE=$?
163168
169+
# Clean up answer key
170+
rm /tmp/answer_key.json
171+
164172
if [ $GRADE_EXIT_CODE -eq 0 ]; then
165173
echo "answers_graded=pass" >> $GITHUB_OUTPUT
166174
else

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ results/
55
# Student answers - generated by answer_assignment.py
66
answers.json
77

8+
# Answer key - instructors only (NOT for students!)
9+
.github/grading/answer_key.json
10+
811
# Instructor-only materials (not for students)
912
.instructor/
1013
architecture.md

0 commit comments

Comments
 (0)