Comprehensive security patterns for managing authentication in GitHub Agentic Workflows including GitHub token types, credential storage, token rotation, least privilege access control, MCP server authentication, and API key management best practices.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
npx skills add https://github.com/Hack23/riksdagsmonitor --skill development
The command stays on one line. Scroll horizontally to inspect it before copying.
Prefer a local copy? Download the files currently available to SkillsMP.
Authentication and Credentials for Agentic Workflows
description
Comprehensive security patterns for managing authentication in GitHub Agentic Workflows including GitHub token types, credential storage, token rotation, least privilege access control, MCP server authentication, and API key management best practices.
🔐 Authentication and Credentials for Agentic Workflows
🔴 AI FIRST Quality Principle
Apply the AI FIRST principle: never accept first-pass quality. Minimum 2 iterations. Read all output, improve every section. No shortcuts.
📋 Overview
This skill provides comprehensive security patterns for managing authentication and credentials in GitHub Agentic Workflows. It covers GitHub token types, secure credential storage, token rotation strategies, least privilege access control, MCP server authentication, and API key management best practices for production-ready autonomous agent systems.
🎯 Core Concepts
Authentication Architecture
graph TB
subgraph "Credential Sources"
A[GitHub Secrets] --> B[Environment Variables]
C[Vault] --> B
D[AWS Secrets Manager] --> B
end
subgraph "Agent Runtime"
B --> E[Credential Manager]
E --> F{Token Type}
F -->|GITHUB_TOKEN| G[GitHub API]
F -->|PAT| H[Extended Permissions]
F -->|GitHub App| I[Installation Token]
F -->|API Keys| J[External Services]
end
subgraph "MCP Servers"
E --> K[MCP Authentication]
K --> L[GitHub MCP]
K --> M[Custom MCP]
K --> N[Third-Party MCP]
end
subgraph "Security Controls"
E --> O[Least Privilege]
E --> P[Token Rotation]
E --> Q[Audit Logging]
end
style E fill:#00d9ff
style O fill:#ff006e
style P fill:#ffbe0b
Security Principles
Least Privilege: Minimal permissions required for task
Defense in Depth: Multiple layers of security
Token Rotation: Regular credential updates
Audit Trail: Complete authentication logging
Secure Storage: Encrypted credential management
Time-Limited Access: Short-lived tokens when possible
🔑 GitHub Token Types
1. GITHUB_TOKEN (Automatic)
Characteristics
# Automatic token provided by GitHub Actions# - Automatically created per workflow run# - Expires when workflow completes# - Scoped to the repository# - Configurable permissionspermissions:contents:read# Read repository contentspull-requests:write# Create/update PRsissues:write# Create/update issuesstatuses:read# Read commit statuses
# GITHUB_TOKEN limitations:# ❌ Cannot trigger other workflow runs# ❌ Cannot access other repositories# ❌ Cannot push to protected branches (unless configured)# ❌ Expires at end of workflow run# ❌ Limited to repository permissions# Use PAT for these scenarios:# ✅ Triggering workflows# ✅ Cross-repository operations# ✅ Protected branch pushes# ✅ Long-running agent processes
2. Personal Access Token (PAT)
Classic PAT Configuration
# GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)# # Recommended Scopes for Agentic Workflows:# ✅ repo (Full control of private repositories)# - repo:status (Access commit status)# - repo_deployment (Access deployment status)# - public_repo (Access public repositories)# - repo:invite (Access repository invitations)# ✅ workflow (Update GitHub Action workflows)# ✅ write:packages (Upload packages to GitHub Package Registry)# ✅ read:packages (Download packages from GitHub Package Registry)# ✅ admin:org (Full control of organizations)# - read:org (Read organization data)# ✅ admin:repo_hook (Full control of repository hooks)# Expiration: 90 days (recommended for security)
Fine-Grained PAT (Recommended)
# GitHub Settings → Developer settings → Personal access tokens → Fine-grained tokens## Permissions for Agentic Workflows:# # Repository permissions:# - Actions: Read and write# - Contents: Read and write# - Issues: Read and write# - Metadata: Read-only (mandatory)# - Pull requests: Read and write# - Workflows: Read and write## Organization permissions (if needed):# - Members: Read-only## Account permissions:# - None (unless required)## Repository access:# - Only select repositories (principle of least privilege)## Expiration: 90 days
Usage in Workflows
# Store PAT as repository secret:# Repository Settings → Secrets and variables → Actions → New repository secret# Name: COPILOT_MCP_GITHUB_PERSONAL_ACCESS_TOKENjobs:agent-task:runs-on:ubuntu-lateststeps:-name:CheckoutwithPATuses:actions/checkout@v4with:token:${{secrets.COPILOT_MCP_GITHUB_PERSONAL_ACCESS_TOKEN}}fetch-depth:0-name:RunAgentwithPATenv:GITHUB_TOKEN:${{secrets.COPILOT_MCP_GITHUB_PERSONAL_ACCESS_TOKEN}}run:|
# Agent can now:
# - Push to protected branches
# - Trigger other workflows
# - Access multiple repositories
node scripts/agents/cross-repo-agent.js
-name:CreatePR(TriggersWorkflows)uses:peter-evans/create-pull-request@v6with:token:${{secrets.COPILOT_MCP_GITHUB_PERSONAL_ACCESS_TOKEN}}title:'Agent Update'body:'Automated changes by agent'branch:'agent/update'
# Add secret via GitHub UI:# Repository → Settings → Secrets and variables → Actions → New repository secret# Or via GitHub CLI:
gh secret set ANTHROPIC_API_KEY --body "sk-ant-..."
gh secret set OPENAI_API_KEY --body "sk-..."
gh secret set MCP_DATABASE_URL --body "postgresql://..."# List secrets:
gh secret list
# Delete secret:
gh secret delete ANTHROPIC_API_KEY
Environment Secrets
# Use GitHub Environments for stage-specific secrets# Repository → Settings → Environments → New environment# Development environmentname:developmentsecrets:-API_KEY:dev-key-123-DATABASE_URL:postgresql://dev-db# Production environmentname:productionsecrets:-API_KEY:prod-key-456-DATABASE_URL:postgresql://prod-dbprotection_rules:-required_reviewers:2-wait_timer:5# minutes
# Use environment secrets in workflowjobs:deploy-dev:runs-on:ubuntu-latestenvironment:developmentsteps:-name:DeployAgentenv:API_KEY:${{secrets.API_KEY}}DATABASE_URL:${{secrets.DATABASE_URL}}run:./deploy.shdeploy-prod:runs-on:ubuntu-latestenvironment:productionneeds:deploy-devsteps:-name:DeployAgentenv:API_KEY:${{secrets.API_KEY}}DATABASE_URL:${{secrets.DATABASE_URL}}run:./deploy.sh
Organization Secrets
# For multi-repository access# Organization → Settings → Secrets and variables → Actions# Add organization secret:
gh secret set SHARED_API_KEY \
--org your-org \
--repos "repo1,repo2,repo3" \
--body "shared-key-789"
2. External Secret Managers
AWS Secrets Manager
# .github/workflows/agent-aws-secrets.ymlname:AgentwithAWSSecretsjobs:agent-task:runs-on:ubuntu-latestpermissions:id-token:write# For OIDC authenticationcontents:readsteps:-name:ConfigureAWSCredentialsuses:aws-actions/configure-aws-credentials@v4with:role-to-assume:arn:aws:iam::123456789012:role/GitHubActionsRoleaws-region:us-east-1-name:RetrieveSecretsid:secretsrun:|
# Get secret from AWS Secrets Manager
SECRET_JSON=$(aws secretsmanager get-secret-value \
--secret-id agentic-workflow/production \
--query SecretString \
--output text)
# Parse and export secretsecho"::add-mask::$(echo $SECRET_JSON | jq -r '.api_key')"echo"API_KEY=$(echo $SECRET_JSON | jq -r '.api_key')">>$GITHUB_ENV-name:RunAgentwithSecretenv:API_KEY:${{env.API_KEY}}run:nodescripts/agents/secure-agent.js
🔗 Integration with Riksdagsmonitor agentic workflows
This gh-aw skill is applied by the 11 agentic news workflows in .github/workflows/news-*.md. Their domain contract (analysis-artifact product, gate, article contract) lives in: