Best practices for securing your NiFi CI/CD workflow with NiPyAPI Actions.
The NiFi GitHub Flow Registry Client requires a Personal Access Token (PAT). The automatic GITHUB_TOKEN provided by GitHub Actions does not work because:
GITHUB_TOKENis an app installation token, not a user token- NiFi's client calls GitHub's
/userAPI endpoint for authentication - This endpoint requires user authentication, which
GITHUB_TOKENcannot provide
Error you'll see if using GITHUB_TOKEN:
"Resource not accessible by integration"
For the best security posture, use a fine-grained PAT with minimal permissions:
-
Go to GitHub Settings then Developer settings then Personal access tokens then Fine-grained tokens
-
Click Generate new token
-
Configure:
| Setting | Value |
|---|---|
| Token name | nifi-flow-registry |
| Expiration | Per your security policy |
| Repository access | Only select repositories |
| Selected repositories | Your flow repository only |
- Set permissions:
| Permission | Access Level | Notes |
|---|---|---|
| Contents | Read-only | Sufficient for CI/CD testing |
| Metadata | Read-only | Required |
Note on read-write access: Read-only is sufficient for these GitHub Actions (deploying and testing flows). If you also want to use the same token for versioning flows directly from NiFi's UI (committing flow changes back to GitHub), you'll need Contents: Read and write instead.
- Generate and securely store the token
- Minimal permissions: Read-only access means token cannot modify code (for CI use)
- Scoped access: Limited to specific repositories
- Audit trail: GitHub logs token usage
- Expiration: Tokens can have mandatory expiration dates
- Revocable: Easy to revoke if compromised
If you cannot use fine-grained tokens (e.g., GitHub Enterprise Server older than 3.10):
- Go to Settings then Developer settings then Personal access tokens then Tokens (classic)
- Generate with
reposcope (orpublic_repofor public repositories)
Note: Classic PATs are less secure as they grant broader access.
Repository secrets are available to all workflows in your repository:
- Go to Repository then Settings then Secrets and variables then Actions
- Click New repository secret
- Add your secrets:
| Secret Name | Description |
|---|---|
NIFI_URL |
NiFi API endpoint |
NIFI_USERNAME |
NiFi username |
NIFI_PASSWORD |
NiFi password |
GH_REGISTRY_TOKEN |
GitHub PAT |
Use environment secrets when you need approval workflows for deployments:
- Create an environment (e.g.,
production) - Configure protection rules (required reviewers, wait timer)
- Add secrets to the environment
- Reference in workflow:
jobs:
deploy:
runs-on: ubuntu-latest
environment: production # Requires approval
steps:
- uses: Chaffelson/nipyapi-actions@main
with:
command: deploy-flow
nifi-api-endpoint: ${{ secrets.NIFI_URL }}
# Uses environment-scoped secretsFor secrets shared across multiple repositories:
- Go to Organization then Settings then Secrets and variables then Actions
- Add secrets and configure repository access
- Reference the same way as repository secrets
GitHub automatically protects against secret leakage:
- Fork PRs: Secrets are NOT available to workflows triggered by fork PRs
- Branch PRs: Only PRs from branches within the same repo can access secrets
- Pull request approval: Require approval before running workflows on fork PRs
-
Enable branch protection on
main:- Require pull request reviews
- Require status checks to pass
- Restrict who can push
-
Configure workflow permissions:
permissions: contents: read
-
Use pull_request_target carefully: This event has access to secrets even for fork PRs. Avoid it unless you fully understand the security implications.
-
Limit workflow triggers:
on: pull_request: branches: [main] # Only run on PRs to main
For development and testing, NiFi's single-user mode is simplest:
nifi-username: ${{ secrets.NIFI_USERNAME }}
nifi-password: ${{ secrets.NIFI_PASSWORD }}Development (self-signed):
nifi-verify-ssl: 'false'
nipyapi-suppress-ssl-warnings: 'true'Production:
- Use proper CA-signed certificates
- Keep
nifi-verify-ssl: 'true'(default) - Mount CA bundle if using internal CA
- Generate new PAT before old one expires
- Update repository secret
- Verify workflows succeed
- Revoke old PAT
- Update password in NiFi
- Update repository secret
- Verify workflows succeed
- Review workflow runs for unexpected behavior
- Secrets are automatically masked in logs
- Failed authentication attempts are logged
- NiFi logs all API access
- Review for unexpected:
- Registry client modifications
- Process group deployments
- Controller service changes
- Using fine-grained PAT with minimal permissions
- PAT scoped to specific repository
- Secrets stored in repository/environment secrets
- Branch protection enabled on main
- Workflow permissions restricted
- SSL verification enabled in production
- NiFi service account with minimal permissions
- Regular credential rotation scheduled
- Audit logging reviewed periodically
- Setup Guide - Initial setup instructions
- How It Works - Architecture overview
- GitHub Actions Security Hardening