GitHub Authentication Guide
Overview
Nirmata AI Agents support multiple GitHub authentication methods to integrate with your GitHub repositories. This guide helps you choose the right authentication method and configure it properly.
Recommended Method: Use Nirmata’s GitHub App for the simplest, most secure integration. Install it once from Nirmata Control Hub, and it works across all GitOps operations.
Authentication Methods
1. Nirmata GitHub App (Recommended)
Best for: Production environments and all GitOps operations
The Nirmata GitHub App method provides the simplest and most secure authentication. Simply install Nirmata’s GitHub App from the Control Hub UI - no need to create your own GitHub App or manage secrets.
Benefits
- ✅ Zero Secret Management: No need to manage GitHub secrets in Kubernetes
- ✅ Centralized Configuration: All credentials managed in Nirmata Control Hub
- ✅ Best Security: Short-lived tokens with fine-grained permissions
- ✅ Automatic Rotation: Token refresh handled automatically
- ✅ Enterprise Ready: Built for organizational use
Prerequisites
- Install GitHub App in Nirmata Control Hub: Follow the GitHub App Integration guide to install Nirmata’s GitHub App
- Navigate to Settings → Integrations in Nirmata Control Hub
- Click Connect on the GitHub card
- Authorize Nirmata to access your GitHub repositories
- Nirmata Control Hub Service Account Token: Your Nirmata Control Hub Service Account token (
SERVICE_ACCOUNT_TOKEN) or API token (API_TOKEN) must be configured in your cluster
Quick Setup
apiVersion: serviceagents.nirmata.io/v1alpha1
kind: ToolConfig
metadata:
name: nirmata-github-tool
namespace: nirmata
spec:
type: github
credentials:
method: nirmata-app # That's all you need!
defaults:
git:
pullRequests:
branchPrefix: "remediation-"
titleTemplate: "remediator: Fix policy violations in %s"
commitMessageTemplate: "Auto-fix: Remediate policy violations in %s"
systemLabels:
- "clusterName"
- "namespace"
customLabels:
- "security"
- "compliance"
```text
#### How It Works
1. You install Nirmata's GitHub App once from the Control Hub UI
2. The agent retrieves GitHub App credentials from Nirmata Control Hub using your Nirmata API token
3. No additional secrets or configuration required in your Kubernetes cluster
4. Works for all GitOps operations including AI agents, policy management, and repository sync
---
### 2. Personal Access Token (PAT)
**Best for**: Development, testing, and proof-of-concept scenarios
Use PAT for quick testing or when GitHub App setup is not feasible.
#### Considerations
- ⚠️ **Long-lived Tokens**: Less secure than GitHub Apps
- ⚠️ **User-bound**: Tied to individual user accounts
- ⚠️ **Broader Permissions**: Less granular permission control
- ✅ **Simple Setup**: Quick to configure for testing
#### Quick Setup
**Step 1: Create PAT Secret**
```bash
kubectl create secret generic github-pat-token \
--from-literal=token=YOUR_GITHUB_PAT \
--namespace nirmata
```text
**Step 2: Create ToolConfig**
```yaml
apiVersion: serviceagents.nirmata.io/v1alpha1
kind: ToolConfig
metadata:
name: github-pat-tool
namespace: nirmata
spec:
type: github
credentials:
method: pat
pat:
tokenSecretRef:
name: github-pat-token
namespace: nirmata
key: token
defaults:
git:
pullRequests:
branchPrefix: "remediation-"
titleTemplate: "[Auto-Remediation] Fix policy violations"
commitMessageTemplate: "Auto-fix: Remediate policy violations"
```text
---
### 3. Custom GitHub App
**Best for**: Organizations that must own the GitHub App themselves, or that run the agent without Nirmata Control Hub credentials
Use your own GitHub App when GitHub App security is required but installing Nirmata's App is not an option — for example a policy that all Apps be owned by your own organization, or an agent installed with `nirmata.auth=none`. You keep GitHub App benefits (short-lived tokens, fine-grained repository permissions) but manage the private key yourself.
github.com only
All three authentication methods target github.com. The agent has no setting for a GitHub Enterprise Server API endpoint, so a custom GitHub App must be installed on github.com — it cannot authenticate against a self-hosted GHES instance.
#### Considerations
- ✅ **Short-lived Tokens**: Installation access tokens, same as the Nirmata App
- ✅ **Fine-grained Permissions**: Scoped per repository, not per user
- ✅ **No Control Hub Dependency**: Works with `nirmata.auth=none`
- ⚠️ **You Manage the Private Key**: Stored as a Kubernetes Secret and rotated by you
- ⚠️ **Requires `github.com` Reachability**: The agent mints tokens against the GitHub API
#### Prerequisites
1. Create a GitHub App in your organization and generate a private key (`.pem`).
2. Grant it repository permissions covering what the agent does: read and write **Contents** (commit the fix) and **Pull requests** (open and comment on PRs), read **Metadata**, and write **Checks** so the agent can report its [CI checks](../configuration/#ci-checks). Add write **Issues** only if you configure the `CreateIssue` action.
3. Install the App on the repositories the agent should remediate.
4. Note the **App ID** from the App's settings page.
#### Quick Setup
**Step 1: Create the private key Secret**
```bash
kubectl create secret generic github-app-private-key \
--from-file=private-key.pem=/path/to/your-app.private-key.pem \
--namespace nirmata
Step 2: Create ToolConfig
apiVersion: serviceagents.nirmata.io/v1alpha1
kind: ToolConfig
metadata:
name: github-app-tool
namespace: nirmata
spec:
type: github
credentials:
method: app
app:
appId: 123456
# installationId: 78901234 # optional — auto-discovered when omitted
privateKeySecretRef:
name: github-app-private-key
key: private-key.pem
defaults:
git:
pullRequests:
branchPrefix: "remediation-"
systemLabels:
- "clusterName"
- "namespace"
appId is an integer, not a string. Omit installationId and the agent discovers it per repository at run time — it reads the installation for the target repo and caches the result; set it explicitly to pin one installation and skip that lookup. The private key may be PKCS#1 or PKCS#8 PEM; it must be RSA.
Secret namespace
The private key Secret is read from the namespace of the ToolConfig, so it must live alongside it —nirmata in these examples. The same applies to PAT secrets. A Secret in another namespace produces a “failed to get private key Secret” error even if privateKeySecretRef.namespace names it.Via Helm values
tool:
credentials:
method: app
app:
appId: 123456
privateKeySecret:
name: github-app-private-key
key: private-key.pem
Comparison Matrix
| Feature | Nirmata GitHub App | Custom GitHub App | Personal Access Token |
|---|---|---|---|
| Security | ✅ Excellent | ✅ Excellent | ⚠️ Moderate |
| Token Lifetime | 1 hour (auto-refresh) | 1 hour (auto-refresh) | Long-lived (requires manual rotation) |
| Setup Complexity | ✅ Simplest (one-click install) | ⚠️ Highest (create App, manage key) | ✅ Simple |
| Secret Management | ✅ Zero (managed by Nirmata Control Hub) | ⚠️ Manual (private key in a K8s secret) | ⚠️ Manual (K8s secrets) |
| Permission Control | ✅ Fine-grained | ✅ Fine-grained | ⚠️ Broad (user-level) |
| Multi-Org Support | ✅ Yes (install per org) | ✅ Yes (install per org) | ⚠️ User-bound |
| Audit Trail | ✅ Excellent (GitHub + Nirmata Control Hub) | ✅ Good (GitHub) | ⚠️ User-level only |
| Enterprise Ready | ✅ Yes | ✅ Yes | ⚠️ Limited |
| Credential Rotation | ✅ Automatic | ⚠️ Manual (private key) | ⚠️ Manual |
| Needs Control Hub credentials | ✅ Yes | ❌ No | ❌ No |
| Works for All GitOps | ✅ Yes | ⚠️ Agent only | ⚠️ Requires separate PATs |
| Best Use Case | Production & all environments | You must own the App, or run without Control Hub | Quick testing/POC only |
Decision Guide
Choose Nirmata GitHub App When:
- ✅ You’re using Nirmata Control Hub (highly recommended)
- ✅ You want the simplest, most secure configuration
- ✅ You need enterprise-grade security without overhead
- ✅ You want zero secret management in Kubernetes
- ✅ You’re deploying to production
- ✅ You want one integration for all GitOps operations
- ✅ You need automated credential rotation
Recommendation: Use Nirmata GitHub App for all environments (production, staging, development). It’s designed specifically for GitOps workflows and requires minimal configuration.
Choose a Custom GitHub App When:
- ✅ Your organization requires that all GitHub Apps be owned by your org
- ✅ You run the agent with
nirmata.auth=noneand still want App-grade security - ✅ You want fine-grained, per-repository permissions without Control Hub
- ⚠️ You accept responsibility for storing and rotating the App private key
- ⚠️ Your repositories are on
github.com, not a self-hosted GHES instance
Recommendation: Prefer the Nirmata GitHub App unless one of the above applies — it removes private key management entirely.
Choose Personal Access Token When:
- ⚠️ You’re doing quick testing or proof-of-concept
- ⚠️ You have simple, single-repository scenarios
- ⚠️ You need to get started immediately without Nirmata Control Hub setup
- ⚠️ Your organization explicitly allows PAT usage for automation
Note: PATs are not recommended for production use due to security limitations and manual credential management requirements.
Complete Configuration Example
Step 1: Install GitHub App (One-Time Setup)
- Navigate to Nirmata Control Hub → Settings → Integrations
- Click Connect on the GitHub card
- Authorize Nirmata to access your repositories
- Done! The GitHub App is now available for all GitOps operations
Step 2: Create ToolConfig for AI Agents
apiVersion: serviceagents.nirmata.io/v1alpha1
kind: ToolConfig
metadata:
name: nirmata-github-tool
namespace: nirmata
spec:
type: github
credentials:
method: nirmata-app # Uses GitHub App from Nirmata Control Hub
defaults:
git:
pullRequests:
branchPrefix: "remediation-"
titleTemplate: "[Auto-Fix] {{.PolicyName}}"
commitMessageTemplate: "Remediate: {{.PolicyName}} violations"
systemLabels:
- "clusterName"
- "namespace"
customLabels:
- "automated"
- "security"
```text
### Step 3: Use with Remediator Agent
```yaml
apiVersion: serviceagents.nirmata.io/v1alpha1
kind: Remediator
metadata:
name: remediator-prod
namespace: nirmata
spec:
environment:
type: argoHub
target:
argoHub:
appSelector:
allApps: true
remediation:
llmConfigRef:
name: nirmata-agent-llm
namespace: nirmata
gitCredentials:
name: nirmata-github-tool # References Nirmata GitHub App
namespace: nirmata
triggers:
- schedule:
crontab: "0 */6 * * *"
eventPolling:
enabled: true
intervalMinutes: 5
actions:
- type: CreatePR
toolRef:
name: nirmata-github-tool
namespace: nirmata
```text
### Complete Workflow
1. ✅ **Install GitHub App** in Nirmata Control Hub (one-time, works for all GitOps operations)
2. ✅ **Create ToolConfig** with `method: nirmata-app`
3. ✅ **Reference in Remediator** - agent automatically uses GitHub App credentials
4. ✅ **Zero secret management** - no GitHub secrets in Kubernetes
5. ✅ **Automatic token rotation** - handled by Nirmata Control Hub
6. ✅ **Audit trail** - tracked in both GitHub and Nirmata Control Hub
---
## Pull Request Configuration
### Understanding Labels
ToolConfig supports two types of PR labels:
#### System Labels (Dynamic)
Computed at runtime based on remediation context:
- `branch`: Git branch being remediated
- `clusterName`: Cluster where violations were found
- `appName`: ArgoCD application name (if applicable)
- `namespace`: Kubernetes namespace with violations
**Note**: System labels are only applied when data is available in the remediation context.
#### Custom Labels (Static)
Always added to every PR:
- `auto-remediation`
- `security`
- `compliance`
- Any custom labels you define
### Example with All Label Types
```yaml
defaults:
git:
pullRequests:
branchPrefix: "fix/"
titleTemplate: "[Auto-Fix] {{.PolicyName}}"
commitMessageTemplate: "Remediate: {{.PolicyName}} violations"
systemLabels:
- "clusterName"
- "namespace"
- "appName"
customLabels:
- "automated"
- "kyverno-policy"
- "needs-review"
```text
---
## Best Practices
### Security
1. **Use Nirmata GitHub App** for production environments with Nirmata Control Hub
2. **Rotate credentials regularly** regardless of method
3. **Limit repository access** to only what's needed
4. **Use separate credentials** for different environments
5. **Monitor audit logs** for unexpected activity
### Configuration
1. **Use descriptive names** for ToolConfig resources
2. **Namespace isolation** - keep configs in appropriate namespaces
3. **Document your setup** - add comments explaining configuration choices
4. **Test in development** before deploying to production
### Maintenance
1. **Review permissions quarterly** - ensure they're still appropriate
2. **Update private keys** on a schedule (every 90 days recommended)
3. **Monitor token usage** through GitHub audit logs
4. **Keep documentation updated** when changing configurations
---
## Troubleshooting
### GitHub App Not Connected
**Symptom**: ToolConfig fails with "GitHub App not configured"
**Solutions**:
1. Verify GitHub App is installed in Nirmata Control Hub:
- Go to Settings → Integrations
- Check if GitHub shows "Connected" status
2. If not connected, click **Connect** and complete the authorization
3. Ensure you selected the repositories where you want Nirmata to work
### Authentication Failures
**Symptom**: Agent cannot authenticate with GitHub
**Common Causes & Solutions**:
**For Nirmata GitHub App**:
1. Verify GitHub App is connected in Nirmata Control Hub (Settings → Integrations)
2. Check your Nirmata Control Hub Service Account token (`SERVICE_ACCOUNT_TOKEN`) or API token (`API_TOKEN`) is valid:
```bash
kubectl get secret nirmata-service-account-token -n nirmata -o yaml
- Ensure the secret contains a valid, non-expired Nirmata Control Hub Service Account token
- Verify network connectivity from cluster to Nirmata Control Hub
- Check that the GitHub App has access to the target repository
For PAT:
- Check token hasn’t expired
- Verify token has required scopes (
repo,write:discussion) - Ensure token secret exists in correct namespace:
kubectl get secret github-pat-token -n nirmata
Cannot Create Pull Requests
Symptom: Authentication succeeds but PRs aren’t created
Solutions:
- Verify Nirmata GitHub App is installed on the target repository:
- Go to GitHub → Settings → Applications → Installed GitHub Apps
- Find “Nirmata” and check repository access
- Ensure the repository is not archived or read-only
- Check branch protection rules don’t block the app
- Review agent logs for detailed error messages:
kubectl logs -n nirmata -l app.kubernetes.io/name=nirmata-agent --tail=100
Missing Repository Access
Symptom: Nirmata cannot access a specific repository
Solutions:
- In GitHub, go to Settings → Applications → Installed GitHub Apps
- Click Configure next to Nirmata
- Add the repository or select “All repositories”
- Click Save
- Wait a few minutes for permissions to propagate
ToolConfig Method Not Working
Symptom: Error like “unsupported method: nirmata-app”
Solutions:
- Verify you’re using the latest Remediator Agent version
- Check that your Helm chart is up to date
- Ensure the agent has network access to Nirmata Control Hub
- Review pod logs for version/compatibility information
Related Documentation
- GitHub App Integration in Nirmata Control Hub
- Remediator Agent Overview
- ToolConfig Configuration
- GitHub Apps Documentation
Support
For additional help:
- Nirmata Support: support@nirmata.com
- Documentation: https://docs.nirmata.io
- GitHub Apps: https://docs.github.com/en/developers/apps