Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/deploy-with-password.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Deploy Quarto Site with Password Protection

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Quarto
uses: quarto-dev/quarto-actions/setup@v2

- name: Render Quarto site
run: quarto render

- name: Inject password into login page
run: |
# Replace {{SITE_PASSWORD}} with actual password from GitHub secret
sed -i "s/{{SITE_PASSWORD}}/${{ secrets.SITE_PASSWORD }}/g" _site/password-protect.html
env:
SITE_PASSWORD: ${{ secrets.SITE_PASSWORD }}

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_site
publish_branch: gh-pages
14 changes: 14 additions & 0 deletions .github/workflows/quarto-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ on:
push:
branches:
- main
- addContent
workflow_dispatch:

permissions: write-all

Expand All @@ -28,6 +30,18 @@ jobs:
- run: pip install -r requirements.txt
- run: quarto render --to html

- name: Inject password into login page
run: |
# Replace {{SITE_PASSWORD}} with actual password from GitHub secret
if [ -f "_site/password-protect.html" ]; then
sed -i "s/{{SITE_PASSWORD}}/${{ secrets.SITE_PASSWORD }}/g" _site/password-protect.html
echo "Password injected successfully"
else
echo "Warning: password-protect.html not found"
fi
env:
SITE_PASSWORD: ${{ secrets.SITE_PASSWORD }}

- name: Publish to GitHub Pages (and render)
uses: quarto-dev/quarto-actions/publish@v2
with:
Expand Down
127 changes: 127 additions & 0 deletions SIMPLE_PASSWORD_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Simple Password Protection Setup

This setup uses a GitHub secret to password-protect your documentation site.

## Setup Steps (5 minutes)

### Step 1: Add Password to GitHub Secrets

1. Go to your GitHub repository: `https://github.com/Disasters-Learning-Portal/disasters-docs`
2. Click **Settings** (top menu)
3. Click **Secrets and variables** → **Actions** (left sidebar)
4. Click **New repository secret**
5. Enter:
- **Name:** `SITE_PASSWORD`
- **Secret:** Your desired password (e.g., `DisastersPortal2024`)
6. Click **Add secret**

### Step 2: Enable GitHub Actions

Make sure GitHub Actions is enabled:
1. Go to **Settings** → **Actions** → **General**
2. Ensure "Allow all actions and reusable workflows" is selected

### Step 3: Commit and Push

```bash
git add .
git commit -m "Add password protection"
git push
```

The GitHub Action will automatically:
- Build your Quarto site
- Inject the password from the secret into the login page
- Deploy to GitHub Pages

### Step 4: Test

1. Wait 2-3 minutes for GitHub Actions to complete
2. Visit: `https://disasters-learning-portal.github.io/disasters-docs/password-protect.html`
3. Enter your password
4. You should be redirected to the documentation

## How It Works

1. **GitHub Secret:** Password stored securely in `SITE_PASSWORD` secret
2. **GitHub Actions:** Workflow injects password during build
3. **Login Page:** `password-protect.html` checks entered password
4. **Session:** Authenticated for 8 hours via localStorage
5. **All Pages:** `auth-check.js` verifies authentication

## Making the Login Page Default

To make users see the login page first, you have two options:

### Option A: Rename in GitHub Pages settings

1. After deployment, go to **Settings** → **Pages**
2. GitHub Pages should show `password-protect.html` as an option
3. Or add a redirect in your main `index.html`

### Option B: Add redirect to index.qmd

Add this to the top of your [index.qmd](index.qmd):

```html
<meta http-equiv="refresh" content="0; url=password-protect.html">
```

Or add JavaScript redirect in [_quarto.yml](_quarto.yml):

```yaml
format:
html:
include-before-body:
- text: |
<script>
if (!localStorage.getItem('disasters_docs_auth')) {
window.location.href = 'password-protect.html';
}
</script>
```

## Changing the Password

1. Go to GitHub **Settings** → **Secrets and variables** → **Actions**
2. Click on `SITE_PASSWORD`
3. Click **Update secret**
4. Enter new password
5. Re-run the GitHub Action or push a new commit

## Files Created

- `password-protect.html` - Login page
- `auth-check.js` - Authentication check on all pages
- `.github/workflows/deploy-with-password.yml` - GitHub Actions workflow
- `_quarto.yml` - Updated to include auth-check.js

## Security Notes

⚠️ **This is client-side protection** - password is visible in browser source after deployment. Good for:
- Internal documentation
- Preventing casual access
- Simple team authentication

❌ **NOT suitable for:**
- Highly sensitive data
- Public-facing secure content
- Compliance requirements

For real security, you'd need server-side authentication (like the CloudFront + Keycloak approach).

## Troubleshooting

**Q: Password doesn't work**
- Check the `SITE_PASSWORD` secret is set correctly in GitHub
- Re-run the GitHub Action to rebuild the site

**Q: Can still access pages without login**
- Clear browser localStorage: `localStorage.clear()`
- Make sure `auth-check.js` is being loaded (check _quarto.yml)
- Hard refresh browser (Ctrl+Shift+R or Cmd+Shift+R)

**Q: GitHub Action fails**
- Check the Actions tab for error details
- Make sure `SITE_PASSWORD` secret exists
- Verify the workflow file is in `.github/workflows/`
98 changes: 11 additions & 87 deletions _quarto.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
project:
type: website
resources:
- password-protect.html
- auth-check.js

website:
page-navigation: true
Expand Down Expand Up @@ -81,95 +84,13 @@ website:
href: Presentations/jupyterhub-data-conversions-tutorial.qmd
- text: "STAC Database and Apache Airflow Tutorial"
href: Presentations/stac-airflow-tutorial.qmd
# - href: datausage.qmd
# text: Data Usage Notebooks
# - href: datatransformation.qmd
# text: Data Transformation Documentation
# - href: processingreport.qmd
# text: Processing and Verification Reports
# - href: workflow.qmd
# text: Data Workflow
# - href: advanceduser.qmd
# text: Advanced User Notebooks
- section: datausage.qmd
text: Data Usage Notebooks
text: Disaster Case Studies
contents:
- section: Disaster Case Studies
contents:
- text: "Texas Flood 2025"
href: user_data_notebooks/Texas_Flood_2025.ipynb
- text: "New Mexico Fire 2025"
href: user_data_notebooks/New_Mexico_Fire_2025.ipynb
- section: Community-Contributed Tutorials
contents:
- section: datatransformationcode.qmd
text: Data Transformation Notebooks
contents:
- cog_transformation/eccodarwin-co2flux-monthgrid-v5.ipynb
- text: Atmospheric Carbon Dioxide and Methane Concentrations from the NOAA Global Monitoring Laboratory
href: cog_transformation/noaa-gggrn-concentrations.ipynb
- cog_transformation/influx-testbed-ghg-concentrations.ipynb
- cog_transformation/lam-testbed-ghg-concentrations.ipynb
- cog_transformation/nec-testbed-ghg-concentrations.ipynb
- cog_transformation/ct-ch4-monthgrid-v2023.ipynb
- cog_transformation/emit-ch4plume-v1.ipynb
- cog_transformation/goes-ch4plume-v1.ipynb
- cog_transformation/gosat-based-ch4budget-yeargrid-v1.ipynb
- cog_transformation/gra2pes-ghg-monthgrid-v1.ipynb
- cog_transformation/oco2geos-co2-daygrid-v10r.ipynb
- cog_transformation/oco2-mip-co2budget-yeargrid-v1.ipynb
- cog_transformation/odiac-ffco2-monthgrid-v2024.ipynb
- text: "SEDAC Gridded World Population Density"
href: cog_transformation/sedac-popdensity-yeargrid5yr-v4.11.ipynb
- cog_transformation/epa-ch4emission-grid-v2express.ipynb
- cog_transformation/vulcan-ffco2-yeargrid-v4.ipynb
- section: processingreport.qmd
text: Processing and Verification Reports
contents:
- processing_and_verification_reports/eccodarwin-co2flux-monthgrid-v5_Processing and Verification Report.qmd
- text: "Atmospheric Carbon Dioxide Concentrations from the NOAA Global Monitoring Laboratory"
href: processing_and_verification_reports/noaa-gggrn-co2-concentrations_Processing and Verification Report.qmd
- processing_and_verification_reports/noaa-gggrn-ch4-concentrations_Processing and Verification Report.qmd
- processing_and_verification_reports/influx-testbed-ghg-concentrations_Processing and Verification Report.qmd
- processing_and_verification_reports/lam-testbed-ghg-concentrations_Processing and Verification Report.qmd
- processing_and_verification_reports/nec-testbed-ghg-concentrations_Processing and Verification Report.qmd
- processing_and_verification_reports/ct-ch4-monthgrid-v2023_Processing and Verification Report.qmd
- processing_and_verification_reports/emit-ch4plume-v1_Processing and Verification Report.qmd
- processing_and_verification_reports/goes-ch4plume-v1_Processing and Verification Report.qmd
- processing_and_verification_reports/gosat-based-ch4budget-yeargrid-v1_Processing and Verification Report.qmd
- processing_and_verification_reports/gra2pes-ghg-monthgrid-v1_Processing and Verification Report.qmd
- processing_and_verification_reports/micasa-carbonflux-daygrid-v1_Processing and Verification Report.qmd
- processing_and_verification_reports/oco2geos-co2-daygrid-v10r_Processing and Verification Report.qmd
- processing_and_verification_reports/oco2-mip-co2budget-yeargrid-v1_Processing and Verification Report.qmd
- processing_and_verification_reports/odiac-ffco2-monthgrid-v2024_Processing and Verification Report.qmd
- processing_and_verification_reports/sedac-popdensity-yeargrid5yr-v4.11_Processing and Verification Report.qmd
- processing_and_verification_reports/epa-ch4emission-grid-v2express_Processing and Verification Report.qmd
- processing_and_verification_reports/vulcan-ffco2-yeargrid-v4_Processing and Verification Report.qmd
- processing_and_verification_reports/lpjeosim-wetlandch4-grid-v1_Processing and Verification Report.qmd
- section: workflow.qmd
text: Data Flow Diagrams
contents:
- data_workflow/eccodarwin-co2flux-monthgrid-v5_Data_Flow.qmd
- data_workflow/noaa-gggrn-co2-concentrations_Data_Flow.qmd
- data_workflow/noaa-gggrn-ch4-concentrations_Data_Flow.qmd
- data_workflow/influx-testbed-ghg-concentrations_Data_Flow.qmd
- data_workflow/lam-testbed-ghg-concentrations_Data_Flow.qmd
- data_workflow/nec-testbed-ghg-concentrations_Data_Flow.qmd
- data_workflow/ct-ch4-monthgrid-v2023_Data_Flow.qmd
- data_workflow/emit-ch4plume-v1_Data_Flow.qmd
- data_workflow/goes-ch4plume-v1_Data_Flow.qmd
- data_workflow/gosat-based-ch4budget-yeargrid-v1_Data_Flow.qmd
- data_workflow/gra2pes-ghg-monthgrid-v1_Data_Flow.qmd
- data_workflow/micasa-carbonflux-daygrid-v1_Data_Flow.qmd
- data_workflow/oco2geos-co2-daygrid-v10r_Data_Flow.qmd
- data_workflow/oco2-mip-co2budget-yeargrid-v1_Data_Flow.qmd
- data_workflow/odiac-ffco2-monthgrid-v2024_Data_Flow.qmd
- text: "SEDAC Gridded World Population Density"
href: data_workflow/sedac-popdensity-yeargrid5yr-v4.11_Data_Flow.qmd
- text: "U.S. Gridded Anthropogenic Methane Emissions Inventory"
href: data_workflow/epa-ch4emission-grid-v2express_Data_Flow.qmd
- data_workflow/vulcan-ffco2-yeargrid-v4_Data_Flow.qmd
- data_workflow/lpjeosim-wetlandch4-grid-v1_Data_Flow.qmd
- text: "Texas Flood 2025"
href: user_data_notebooks/Texas_Flood_2025.ipynb
- text: "New Mexico Fire 2025"
href: user_data_notebooks/New_Mexico_Fire_2025.ipynb

format:
html:
Expand All @@ -184,5 +105,8 @@ format:
code-overflow: wrap
toc: true
toc-depth: 3
include-in-header:
- text: |
<script src="auth-check.js"></script>
filters:
- quarto
65 changes: 65 additions & 0 deletions auth-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Authentication check for all pages
(function() {
const SESSION_KEY = 'disasters_docs_auth';

function checkAuth() {
// Skip authentication on localhost (for development)
if (window.location.hostname === 'localhost' ||
window.location.hostname === '127.0.0.1') {
console.log('Running on localhost - skipping authentication');
return;
}

// Skip check if we're on the login page
if (window.location.pathname.endsWith('password-protect.html') ||
window.location.pathname.endsWith('login.html')) {
return;
}

const auth = localStorage.getItem(SESSION_KEY);

if (!auth) {
// No authentication, redirect to login
window.location.href = '/disasters-docs/password-protect.html';
return;
}

try {
const authData = JSON.parse(auth);
const now = new Date().getTime();

if (authData.expires <= now || !authData.authenticated) {
// Expired or invalid session
localStorage.removeItem(SESSION_KEY);
window.location.href = '/disasters-docs/password-protect.html';
return;
}

// Valid session - allow page to load
} catch (e) {
// Invalid auth data
localStorage.removeItem(SESSION_KEY);
window.location.href = '/disasters-docs/password-protect.html';
}
}

// Run check immediately
checkAuth();

// Add logout functionality
window.addEventListener('DOMContentLoaded', function() {
// Add logout button to page if it doesn't exist
const existingLogout = document.getElementById('logout-btn');
if (!existingLogout) {
const logoutBtn = document.createElement('button');
logoutBtn.id = 'logout-btn';
logoutBtn.textContent = 'Logout';
logoutBtn.style.cssText = 'position: fixed; top: 10px; right: 10px; padding: 8px 16px; background: #e74c3c; color: white; border: none; border-radius: 5px; cursor: pointer; z-index: 9999; font-size: 14px;';
logoutBtn.onclick = function() {
localStorage.removeItem(SESSION_KEY);
window.location.href = '/disasters-docs/password-protect.html';
};
document.body.appendChild(logoutBtn);
}
});
})();
Loading