Secrets & Environment Configuration
Overview
GitHub Secrets are used to securely store sensitive configuration like API endpoints and credentials. These are referenced in the pipeline without exposing values.
Required Secrets
FRONTEND_API_BASE_URL
Purpose: Production API endpoint
Example:
https://api.stockease.com/api
Usage: Injected as
VITE_API_BASE_URL during build
Required: Yes
DOCKER_USERNAME
Purpose: Docker registry login
username
Example: myusername
Usage: Docker login for pushing images
Required: If using Docker registry
DOCKER_PASSWORD
Purpose: Docker registry authentication
token
Example: dckr_pat_xxxxx
Usage: Docker login for pushing images
Required: If using Docker registry
DEPLOY_SSH_KEY
Purpose: SSH key for production server
access
Usage: Deploying to self-hosted server
Required: If using SSH deployment
DEPLOY_HOST
Purpose: Production server IP or
domain
Example: prod.stockease.com
Usage: SSH deployment target
Required: If using SSH deployment
Setting Secrets in GitHub
Step 1: Go to Repository Settings
- Navigate to your GitHub repository
- Click Settings (top-right menu)
- In left sidebar, select Secrets and variables β Actions
Step 2: Create New Secret
- Click New repository secret
- Enter secret name (e.g.,
FRONTEND_API_BASE_URL) - Enter secret value
- Click Add secret
Step 3: Repeat for All Secrets
Add each required secret following the same process.
Using Secrets in Pipeline
Reference in Environment
env:
FRONTEND_API_BASE_URL: ${{ secrets.FRONTEND_API_BASE_URL }}Reference in Steps
- name: Build production bundle
run: |
export VITE_API_BASE_URL="${{ secrets.FRONTEND_API_BASE_URL }}"
npm run buildReference in Docker Build
- name: Build Docker image
run: |
docker build \
--build-arg VITE_API_BASE_URL="${{ secrets.FRONTEND_API_BASE_URL }}" \
-t stockease-frontend:latest .Security Best Practices
β Do's
- β Use GitHub Secrets for all sensitive data
- β Rotate secrets regularly
- β Use strong, unique values
- β Limit secret access to necessary workflows
- β Log secret usage for audit trail
- β Never commit secrets to repository
β Don'ts
- β Never hardcode secrets in .yml files
- β Never log or print secret values
- β Never use weak or shared credentials
- β Don't reuse secrets across projects
- β Don't grant all team members secret access
- β Never commit .env files with secrets
Common Secrets by Use Case
Vercel Deployment
| Secret | Purpose |
|---|---|
| VERCEL_TOKEN | Vercel authentication |
| VERCEL_ORG_ID | Vercel organization ID |
| VERCEL_PROJECT_ID | Project ID on Vercel |
Docker Hub Deployment
| Secret | Purpose |
|---|---|
| DOCKER_USERNAME | Docker Hub username |
| DOCKER_PASSWORD | Docker Hub access token |
| DOCKER_REGISTRY | Registry URL (if not Docker Hub) |
Custom Server Deployment
| Secret | Purpose |
|---|---|
| DEPLOY_SSH_KEY | SSH private key |
| DEPLOY_HOST | Server IP/domain |
| DEPLOY_USER | SSH username |
| DEPLOY_PORT | SSH port (default 22) |
API Configuration
| Secret | Purpose |
|---|---|
| FRONTEND_API_BASE_URL | Production API endpoint |
| API_KEY | If API requires key |
| API_SECRET | If API requires secret |
Testing Secrets Access
Verify Secret is Available
- name: Verify secrets
run: |
if [ -z "${{ secrets.FRONTEND_API_BASE_URL }}" ]; then
echo "ERROR: FRONTEND_API_BASE_URL not set!"
exit 1
fi
echo "β Secrets configured correctly"Debugging Secret Issues
Secret not found in workflow
- Verify secret name spelling (case-sensitive)
- Check Settings β Secrets for exact name
- Ensure workflow has permission to access secrets
Secret value incorrect
- Go to Settings β Secrets
- Edit secret and verify value
- Common issue: Extra spaces or quotes
Secret not injecting into code
- Verify syntax:
${{ secrets.SECRET_NAME }} - Check if using in correct context
- Secrets only available in GitHub Actions, not in built app
- Verify syntax:
Managing Secrets
View All Secrets
- Go to Settings β Secrets and variables β Actions
- List shows secret names (values hidden)
- Can only see that secret exists, not its value
Update Secret
- Go to Settings β Secrets and variables β Actions
- Find secret in list
- Click pencil icon to edit
- Enter new value
- Click Update secret
Delete Secret
- Go to Settings β Secrets and variables β Actions
- Find secret in list
- Click trash icon to delete
- Confirm deletion
- Workflow must not reference deleted secret
Environment Variable Best Practices
In .env Files (Development Only)
# .env (local development only)
VITE_API_BASE_URL=http://localhost:3000/apiIn GitHub Secrets (CI/CD Only)
# .github/workflows/deploy.yml
env:
VITE_API_BASE_URL: ${{ secrets.FRONTEND_API_BASE_URL }}Never Commit
# Add to .gitignore
.env
.env.local
.env.*.localRotating Secrets
When to Rotate
- Monthly as security best practice
- Immediately if compromised
- After employee departure
- When upgrading to new service version
How to Rotate
- Generate new secret value
- Update in GitHub Settings β Secrets
- Update in external service (if applicable)
- Verify workflow still works
- Keep old value until rotation verified
Related Documentation
Last Updated: November 2025
Security Level: Production Ready
Recommended Rotation: Monthly