How to Promote Custom Apache NiFi Flows from Dev to Production on Snowflake Openflow Gen 2 Runtimes
What It Takes to Promote NiFi Flows Across Dev, QA and Production
Once a flow works on your dev canvas, the next step is running it in QA and production. That's the same dev-to-prod journey as any other code, and a NiFi flow brings its own environment details along: hostnames, credentials, certificates and driver JARs, most of which differ in each environment.
A repeatable promotion process answers a few questions:
- How do you get that same flow into QA, then production, without someone rebuilding it by hand?
- How do you change environment-specific values like hostnames, warehouses and databases without editing JSON?
- How do you handle passwords and keystore secrets without putting them in a config file or a Git repo?
- How do you upload the JDBC drivers and certificates the flow depends on?
- And what happens when a deploy fails halfway?
Snowflake Openflow runtimes are Apache NiFi underneath, and a runtime exposes the NiFi REST API. This post covers Openflow gen 2 runtimes, the generation used by all new deployments. The tool uses that API to upload flows, set parameters and secrets, upload assets, and start, stop and delete flows, so flow promotion can be scripted, repeated and reviewed like any other code.
This post walks through a small open-source Python tool, openflow_nipyapi, that does exactly that. It uses nipyapi, the community Python client for NiFi.
Scope: This post demonstrates a reference-code workflow for promoting custom NiFi flows (process groups you build on the canvas) between Openflow gen 2 runtimes. It is not a general deployment guide for every Openflow generation. It doesn't apply to gen 1 runtimes: the script finds runtimes with SHOW OPENFLOW RUNTIMES, which lists gen 2 runtimes only. It also doesn't manage gen 2 connectors, which use their own versioned configuration. To check a runtime's generation, see Openflow gen 1 and gen 2.
Disclaimer: The repository is reference code that shows one way to automate Openflow flow deployments. It isn't an officially supported Snowflake product, so review and adapt it before using it in your environment. The script reads your Snowflake programmatic access token (PAT) from a local
.envfile. Treat that file as a secret: keep it out of version control (the repo's.gitignoreexcludes it), restrict who can read it, and in CI/CD store the PAT in your pipeline's secret store instead of a file.
NiFi Concepts You Need to Know for Flow Promotion
A few NiFi terms come up throughout this post. Here's what each one means in practice:
| Term | What it means |
|---|---|
| Flow definition | The JSON export of a flow: its processors, connections and settings. This is what you move between environments. |
| Process group | A container on the canvas that holds a flow. Deploying a flow creates one process group. |
| Parameter context | A named set of key/value settings that a process group uses, referenced as #{Kafka Bootstrap Servers}. Contexts can inherit from other contexts. |
| Controller service | A shared component that processors use, such as a database connection pool or an SSL context. Its sensitive properties, like passwords, can't be read back through the API. |
| Asset | A file attached to a parameter context, such as a JDBC driver or a .jks keystore. |
| Runtime | One Openflow NiFi instance you deploy to, such as DEV_RUNTIME or QA_RUNTIME. |
Separating NiFi Flow Definitions from Environment Configuration

Figure 1: Promoting a flow from a gen 2 dev runtime to gen 2 QA/PROD runtimes with per-environment config
There are two artifacts per flow:
my-flow.json: the flow definition, exported from the dev canvas. It's the same in every environment.my-flow.config.yaml: the environment-specific parameters and assets. In this example, it holds references to Snowflake SECRET objects instead of secret values.
The script does everything else.
Walkthrough: Promoting a Kafka-to-Snowflake Flow from Dev to QA
For the rest of this post we'll follow a single flow, avro-kafka-connector. It reads Avro messages from Kafka and lands them in Snowflake, and it already works on the DEV canvas. The goal is to get it running on QA_RUNTIME with one command:
python deploy_flow_secure.py deploy kafka avro-kafka-connector --runtime QA_RUNTIME
Each step below answers one question the script has to settle before that command can succeed.
Authenticating to the Openflow NiFi REST API with a Programmatic Access Token
The first step is connecting to the QA runtime. Before the script can deploy anything, it has to answer two questions: who am I? and where is QA?
The script authenticates with a single Snowflake Programmatic Access Token (PAT) and uses it in two places:
| Job | How |
|---|---|
Run SQL (SHOW OPENFLOW RUNTIMES, LIST @stage, GET @stage) | Snowflake Python connector with authenticator="programmatic_access_token" |
| Call the runtime's NiFi REST API | Authorization: Bearer <PAT> on https://.../nifi-api/... |
ALTER USER deploy_user ADD PROGRAMMATIC ACCESS TOKEN OPENFLOW_DEPLOY_PAT ROLE_RESTRICTION = OPENFLOW_ADMIN DAYS_TO_EXPIRY = 90 COMMENT = 'CI/CD deploys to Openflow runtimes';
Heads-up: Whether a PAT needs a network policy depends on the authentication policy that applies to the user. Its
NETWORK_POLICY_EVALUATIONsetting controls this (see PAT prerequisites). If no authentication policy changes this setting, the user must be subject to a network policy to authenticate with a PAT. If the PAT is rejected even though it looks correct, check the user's authentication and network policies first.
Finding Your Openflow Runtime URL with SHOW OPENFLOW RUNTIMES
You give the script a runtime name, never a URL. URLs hardcoded in pipelines break when runtimes are recreated or moved, so the script looks the runtime up each time. It lists the gen 2 runtimes your role can see with SHOW OPENFLOW RUNTIMES, then reads the runtime's URL from the server_url property returned by DESCRIBE OPENFLOW RUNTIME:
SHOW OPENFLOW RUNTIMES IN ACCOUNT; DESCRIBE OPENFLOW RUNTIME OPENFLOW.OPENFLOW.QA_RUNTIME; -- server_url: https://<host>:443/qaruntime-100/nifi/
server_url is the URL of the runtime's Openflow canvas. The script calls the NiFi REST API on the same host and runtime path, with /nifi-api in place of /nifi/. You can also see the runtime URL in Snowsight.
DESCRIBE OPENFLOW RUNTIME requires the MONITOR privilege on the runtime, so the role in your .env needs it:
GRANT MONITOR ON OPENFLOW RUNTIME OPENFLOW.OPENFLOW.QA_RUNTIME TO ROLE <deploy_role>;
list-runtimes shows what the script can see:
NAME DATABASE SCHEMA STATUS URL ------------------------------------------------------------------------------------------ DEV_RUNTIME OPENFLOW OPENFLOW ACTIVE https://<host>:443/devruntime-100/nifi/ QA_RUNTIME OPENFLOW OPENFLOW ACTIVE https://<host>:443/qaruntime-100/nifi/ OLD_RUNTIME OPENFLOW OPENFLOW SUSPENDED -
A
-means no URL was returned: the runtime is suspended, or the role lacks MONITOR on it.
Prove the Connection Before You Deploy
With the token and the URL in hand, one curl call confirms both:
curl -s -o /dev/null -w "%{http_code}\n" \ -H "Authorization: Bearer $SNOWFLAKE_PAT" \ https://of1--myorg-myaccount.snowflakecomputing.app/qaruntime-100/nifi-api/flow/process-groups/root
| Response | Meaning |
|---|---|
| 200 | The endpoint is reachable and authentication works. |
| 401 | There's a problem with the token, the role, or the endpoint URL. |
| 403 | Authentication worked, but the role can't access this runtime. |
Why the Openflow NiFi API Returns 401 "Token introspection returned no principal"
This error looks like a bad token, but it isn't always one:
401 Unauthorized Bearer error="invalid_token", error_description="Token introspection returned no principal"
First, confirm the request is going to the runtime's own endpoint. The script prints both URLs on every command, so you can compare them with the runtime's server_url:
Runtime URL: https://<host>:443/qaruntime-100/nifi/ NiFi API endpoint: https://<host>/qaruntime-100/nifi-api
If the URL matches, check the PAT itself: that it hasn't expired, that its role restriction is a role with access to the runtime, and if a network policy applies to the user, that it allows your IP.
The script can now reach QA and is allowed in. Next, it needs to know what's different about QA.
Managing Environment-Specific NiFi Parameters with YAML
With the connection in place, the next step is telling the script what's different about QA.
Export the flow JSON from your dev canvas once and commit it. Everything that changes between environments goes in the YAML file next to it:
flows/ └── kafka/ ├── avro-kafka-connector.json # same in every environment └── avro-kafka-connector.config.yaml # values for this environment
parameters: Kafka Bootstrap Servers: "broker-qa-1:9093,broker-qa-2:9093" Destination Database: "QA_RAW" Snowflake Warehouse: "QA_INGEST_WH" # Secrets: references to Snowflake SECRET objects, not values Truststore Password: "$SF_SECRET{QA_DB.SECURITY.KAFKA_TRUSTSTORE_PASSWORD}" Keystore Password: "$SF_SECRET{QA_DB.SECURITY.KAFKA_KEYSTORE_PASSWORD}" assets: - name: "kafka-truststore.jks" stage: "QA_DB.SECURITY.CERTS_STAGE" parameter: "Truststore Filename" - name: "mssql-jdbc-12.8.1.jre11.jar" # Example driver URL; confirm the version and source your organization approves url: "https://repo1.maven.org/maven2/com/microsoft/sqlserver/mssql-jdbc/12.8.1.jre11/mssql-jdbc-12.8.1.jre11.jar" parameter: "SQLServer JDBC Driver"
Promoting to production then means keeping a production version of the YAML, through a branch, a directory, or a pipeline variable. The flow JSON doesn't change.
The script looks for the flow and its config on local disk first and only falls back to GitHub if a file is missing. GitHub settings are optional, so a pipeline that checks out the repo never needs a GitHub token.
Keeping NiFi Passwords Out of Git with Snowflake Secrets
This is the core of the design. Passwords for Kafka keystores, databases and APIs live as Snowflake SECRET objects:
CREATE SECRET QA_DB.SECURITY.KAFKA_KEYSTORE_PASSWORD TYPE = GENERIC_STRING SECRET_STRING = '********'; GRANT READ ON SECRET QA_DB.SECURITY.KAFKA_KEYSTORE_PASSWORD TO ROLE <runtime_execute_as_role>; GRANT USAGE ON DATABASE QA_DB TO ROLE <runtime_execute_as_role>; GRANT USAGE ON SCHEMA QA_DB.SECURITY TO ROLE <runtime_execute_as_role>;
When the script sees $SF_SECRET{DB.SCHEMA.NAME}, it:
- Fetches parameter groups from the provider. Each
DB.SCHEMAbecomes a group. - Validates that every referenced schema and secret is actually visible to the runtime. If anything is missing, it stops here, before the flow is uploaded.
- Applies the group, marking only the secrets referenced in the YAML for inclusion, which creates a NiFi parameter context (for example
QA_DB.SECURITY). - Wires inheritance, so the flow's own parameter context inherits from the provider context.
- Rewires controller-service properties to reference
#{KAFKA_KEYSTORE_PASSWORD}directly.
The last step is needed because NiFi parameter references don't nest: a parameter whose value is #{OTHER} stores that literal text. So instead of passing the secret through a parameter value, the script points the sensitive property straight at the provider-backed parameter.
As a result, no secret value appears in .env, in YAML, in Git, or in the script's output. If a secret is missing, the error says exactly what to fix:
Snowflake secret(s) not found via Parameter Provider: - secret QA_DB.SECURITY.KAFKA_KEY_PASSWORD not found Check that the SECRET exists and the runtime's execute-as role has READ on it and USAGE on its database/schema.
Uploading JDBC Drivers and Keystores to NiFi Parameter Contexts
Most real flows need files: JDBC drivers, .jks keystores, truststores. The script takes each asset from one of two sources:
- A URL (Maven Central, an internal artifact repository).
- A Snowflake internal stage, via
GET @stage/file. This is ideal for certificates you don't want on the public internet.
Assets are validated before deployment: stage files are checked with LIST, and incomplete entries are rejected. They're then uploaded to the right parameter context and bound to their parameter. If an asset already exists on the runtime, it isn't uploaded again, so re-running a deploy is safe.
Deploying the Flow, and Cleaning Up When a Step Fails
With the connection, configuration, secrets and assets covered, here's everything the single deploy command does, in order:
1. Discover runtime by name SHOW OPENFLOW RUNTIMES IN ACCOUNT 2. Resolve runtime URL DESCRIBE OPENFLOW RUNTIME → server_url 3. Load flow JSON local first, GitHub fallback 4. Load config YAML local first, GitHub fallback (optional) 5. Validate assets LIST @stage ... ← fail before upload 6. Resolve $SF_SECRET{...} Parameter Provider fetch ← fail before upload 7. Upload flow POST process-groups/upload 8. Inherit provider contexts 9. Apply parameters 10. Rewire secret properties 11. Upload + bind assets 12. (optional) Start enable controller services, start processors
Failing Safely
Steps 1–5 are read-only checks, and step 6 validates every referenced secret before applying the provider's parameter group. Anything that can be validated up front is checked before the flow is uploaded.
If a step from 8 to 12 raises an error, the script attempts to delete the process group it just created, along with any parameter contexts only that flow used. For example:
Deploy failed: Parameter 'Truststore Filename' for asset 'kafka-truststore.jks' not found ... Rolling back process group 59d3cf4c-... Deleted process group 59d3cf4c-... Kept parameter context 'QA_DB.SECURITY' (managed by Parameter Provider) Deleted parameter context 'avro-kafka-connector Parameters'
Cleanup is a best-effort attempt, not a guarantee. After any failed deploy, check the runtime canvas, because some things may remain:
- The provider-managed context (for example
QA_DB.SECURITY) is intentionally kept, since other flows may use it. - A failure during the upload itself (step 7), or an interrupted run (for example a cancelled CI job), isn't rolled back.
- If cleanup itself fails, the script prints
ROLLBACK FAILED … delete process group <id> manually. Runpython deploy_flow_secure.py delete "<flow-name>" --runtime <RUNTIME> --yes, or remove the group in the canvas. - A parameter context still inherited by something outside the flow is left in place with a WARNING.
Deleting a NiFi Process Group and Its Parameter Contexts
Deleting a flow in NiFi involves several steps: stop components, disable controller services, empty queues, delete the group, then deal with the parameter contexts it leaves behind. The delete command does all of it:
python deploy_flow_secure.py delete "avro-kafka-connector" --runtime QA_RUNTIME --yes
Deleting 36658700-01a1-1000-ffff-ffff934bb1ee... Deleted process group 36658700-01a1-1000-ffff-ffff934bb1ee Kept parameter context 'QA_DB.SECURITY' (managed by Parameter Provider) Deleted parameter context 'Kafka Source Parameters' Deleted parameter context 'Snowflake Destination Parameters'
It's careful about what it removes. Contexts managed by the Parameter Provider, and any context another flow still uses, are kept. Only contexts that belonged to this flow alone are removed.
Running Openflow Flow Deployments from GitHub Actions (Illustrative Example)
Note: The workflow below is an untested, illustrative sketch rather than a validated pipeline. Adapt and test it for your own account before you rely on it.
In particular, check:
- Authentication: whether your authentication policy allows PATs for the deploy user, and whether a network policy is required.
- Runner egress: whether your runner's outbound IPs can reach Snowflake and the Openflow runtime.
- Runtime and privileges: the runtime name, and that the deploy role has the needed privileges (including MONITOR on the runtime).
- Configuration: the flow and config file paths in your repository.
Because everything runs from the command line and is configured through .env, it fits into any pipeline. An illustrative GitHub Actions example:
name: Promote Openflow flow to QA on: push: branches: [ release/qa ] paths: [ "flows/**" ] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: { python-version: "3.11" } - run: pip install -r requirements.txt - name: Deploy env: SNOWFLAKE_ACCOUNT: ${{ vars.SNOWFLAKE_ACCOUNT }} SNOWFLAKE_USER: ${{ vars.SNOWFLAKE_USER }} SNOWFLAKE_ROLE: ${{ vars.SNOWFLAKE_ROLE }} SNOWFLAKE_PAT: ${{ secrets.SNOWFLAKE_PAT }} run: | python deploy_flow_secure.py deploy kafka avro-kafka-connector \ --runtime QA_RUNTIME --start
If your account enforces network policies for PAT authentication, the network policy must allow the CI runner's egress IPs. In that case, use a self-hosted runner or a hosted runner with static IPs, and add those IPs to the policy. Check the authentication policy that applies to the deploy user before you configure runner egress.
Promotion to production follows the same pattern: a separate branch or environment, the production config YAML, the production runtime name, and an approval gate if you want one.
Lessons Learned Debugging NiFi REST API Deployments
Most of these came out of debugging real deploys:
- A 401 isn't always the token.
Token introspection returned no principalcan also mean the request went to the wrong endpoint. Read the URL fromserver_urlinstead of building it yourself, and compare it with what your script calls before you regenerate credentials. - "Curl works" doesn't prove auth works. An unauthenticated curl also returns a status code. Test with the same token and the exact URL the script uses.
- Pin your client library. NiFi client APIs change between nipyapi releases. An unpinned nipyapi produced
'FlowApi' object has no attribute 'get_flow'on one machine and worked fine on another.requirements.txtnow pinsnipyapi==1.5.0. - Validate before you mutate. Checking secrets and stage files up front turned confusing half-deploys into clear, early error messages.
- Always plan for rollback. A failed deploy that leaves a broken process group behind costs more cleanup time than the deploy itself.
- Keep secrets in Snowflake. Referencing Snowflake secrets with
$SF_SECRET{}instead of putting values in config keeps flow passwords out of Git in this setup, and rotating a password happens in Snowflake. Still review CI logging, and store the PAT in your pipeline's secret store.
Conclusion And Resources
Try It Yourself
git clone -b develop https://github.com/sfc-gh-sgope/openflow_nipyapi.git cd openflow_nipyapi pip install -r requirements.txt cp .env.example .env # set SNOWFLAKE_ACCOUNT, SNOWFLAKE_USER, SNOWFLAKE_PAT, SNOWFLAKE_ROLE python deploy_flow_secure.py list-runtimes
The full set of commands:
python deploy_flow_secure.py list-runtimes # runtimes visible to your role python deploy_flow_secure.py list-flows --runtime QA_RUNTIME # flows deployed on a runtime python deploy_flow_secure.py deploy kafka avro-kafka-connector --runtime QA_RUNTIME [--start] python deploy_flow_secure.py start "avro-kafka-connector" --runtime QA_RUNTIME # enable services + start python deploy_flow_secure.py stop "avro-kafka-connector" --runtime QA_RUNTIME # stop + disable services python deploy_flow_secure.py delete "avro-kafka-connector" --runtime QA_RUNTIME --yes
Then export a flow from your gen 2 dev runtime's canvas into flows/<bucket>/, add a .config.yaml, and deploy it to your next gen 2 runtime with a single command.
Openflow gives you NiFi's flexibility on Snowflake's platform. With a small amount of tooling around the NiFi REST API, your custom flows on gen 2 runtimes can be versioned, reviewed, promoted and rolled back like the rest of your code.
Related Resources
This content is provided as is, and is not maintained on an ongoing basis. It may be out of date with current Snowflake instances