Skip to content

Commit 39e2fd5

Browse files
committed
docs: add bearer token authentication to profiles documentation
- Add nifi_bearer_token to configuration structure and keys - Document bearer as highest priority NiFi auth method - Add bearer-token profile example in profiles.yml - Add NIFI_BEARER_TOKEN environment variable mapping
1 parent 5cb732a commit 39e2fd5

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

docs/profiles.rst

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Quick Start
3737
- ``secure-ldap`` - LDAP authentication over TLS
3838
- ``secure-mtls`` - Mutual TLS certificate authentication
3939
- ``secure-oidc`` - OpenID Connect (OAuth2) authentication
40+
- ``bearer-token`` - Pre-obtained JWT bearer token
4041
- ``env`` - Pure environment variable configuration (no profiles file required)
4142

4243
Why Use Profiles?
@@ -88,6 +89,7 @@ Default profiles are defined in ``examples/profiles.yml`` (JSON is also supporte
8889
# Authentication credentials
8990
nifi_user: "einstein"
9091
nifi_pass: "password1234"
92+
nifi_bearer_token: null
9193
registry_user: "einstein"
9294
registry_pass: "password1234"
9395
@@ -133,6 +135,7 @@ Core connection settings:
133135

134136
Authentication credentials:
135137
- ``nifi_user`` / ``nifi_pass`` - NiFi Basic authentication credentials
138+
- ``nifi_bearer_token`` - Pre-obtained JWT bearer token for NiFi
136139
- ``registry_user`` / ``registry_pass`` - Registry Basic authentication credentials
137140

138141
Shared SSL/TLS certificates (simple PKI - convenience options where both NiFi and Registry share configuration):
@@ -155,7 +158,7 @@ Advanced settings:
155158
- ``nifi_proxy_identity`` - Identity for NiFi → Registry proxied requests
156159

157160
Authentication method control:
158-
- ``nifi_auth_method`` - Explicit authentication method for NiFi (overrides auto-detection). Valid values: ``oidc``, ``mtls``, ``basic``
161+
- ``nifi_auth_method`` - Explicit authentication method for NiFi (overrides auto-detection). Valid values: ``bearer``, ``oidc``, ``mtls``, ``basic``
159162
- ``registry_auth_method`` - Explicit authentication method for Registry (overrides auto-detection). Valid values: ``mtls``, ``basic``, ``unauthenticated``
160163

161164
OIDC authentication:
@@ -170,7 +173,7 @@ Profile Switching Behavior
170173
1. **Explicit method specification** (highest priority): If ``nifi_auth_method`` or ``registry_auth_method`` are set, that method is used regardless of other available credentials.
171174
2. **Auto-detection** (fallback): When no explicit method is specified, the system auto-detects based on available credentials. Detection order varies by service:
172175

173-
- **NiFi**: **1) OIDC** (``oidc_token_endpoint``), **2) mTLS** (``client_cert`` + ``client_key``), **3) Basic Auth** (``nifi_user`` + ``nifi_pass``)
176+
- **NiFi**: **1) Bearer Token** (``nifi_bearer_token``), **2) OIDC** (``oidc_token_endpoint``), **3) mTLS** (``client_cert`` + ``client_key``), **4) Basic Auth** (``nifi_user`` + ``nifi_pass``)
174177
- **Registry**: **1) mTLS** (``client_cert`` + ``client_key``), **2) Basic Auth** (``registry_user`` + ``registry_pass``), **3) Unauthenticated** (no credentials required)
175178

176179
For predictable behavior, either use explicit method specification or design profiles with only one authentication method per environment.
@@ -318,6 +321,37 @@ OpenID Connect (OAuth2) authentication:
318321

319322
**Use case**: Modern OAuth2 integration, external identity providers
320323

324+
bearer-token (Simplest Configuration)
325+
--------------------------------------
326+
327+
Pre-obtained JWT bearer token authentication - the simplest possible configuration:
328+
329+
.. code-block:: python
330+
331+
nipyapi.profiles.switch('bearer-token')
332+
333+
**Authentication method**: Bearer Token (detected by presence of ``nifi_bearer_token``)
334+
335+
**Required properties**:
336+
- ``nifi_bearer_token: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..."`` (your JWT token)
337+
338+
**Additional properties used**:
339+
- ``nifi_url: https://nifi.example.com/nifi-api``
340+
- ``nifi_verify_ssl: true`` (or false for self-signed certificates)
341+
342+
**Use case**: CI/CD pipelines, GitHub Actions, Kubernetes jobs, or any scenario where you have a pre-obtained JWT token from your identity provider. This is the simplest authentication method - just a URL and a token.
343+
344+
**Example using environment variables only**:
345+
346+
.. code-block:: shell
347+
348+
# Set environment variables
349+
export NIFI_API_ENDPOINT=https://nifi.production.example.com/nifi-api
350+
export NIFI_BEARER_TOKEN=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
351+
352+
# Use the 'env' profile to load from environment
353+
python -c "import nipyapi; nipyapi.profiles.switch('env')"
354+
321355
cli-properties
322356
--------------
323357

@@ -410,6 +444,7 @@ URLs and credentials:
410444
- ``REGISTRY_API_ENDPOINT`` → ``registry_url``
411445
- ``NIFI_USERNAME`` → ``nifi_user``
412446
- ``NIFI_PASSWORD`` → ``nifi_pass``
447+
- ``NIFI_BEARER_TOKEN`` → ``nifi_bearer_token``
413448
- ``REGISTRY_USERNAME`` → ``registry_user``
414449
- ``REGISTRY_PASSWORD`` → ``registry_pass``
415450

examples/profiles.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ secure-oidc:
8585
oidc_client_id: "nipyapi-client"
8686
oidc_client_secret: "nipyapi-secret"
8787

88+
# Bearer token profile - simplest possible configuration
89+
# Use when you have a pre-obtained JWT token (e.g., from CI/CD, identity provider)
90+
# This is ideal for GitHub Actions, Kubernetes jobs, or any environment with injected tokens
91+
bearer-token:
92+
nifi_url: https://nifi.example.com/nifi-api
93+
nifi_bearer_token: null # Set via NIFI_BEARER_TOKEN environment variable
94+
nifi_verify_ssl: true
95+
8896
# GitHub CI/CD profile - NiFi only, for testing Git-based registry workflows
8997
# Uses GitHub Registry Client instead of NiFi Registry
9098
# GitHub registry configuration is handled by nipyapi-actions, not nipyapi profiles

nipyapi/profiles.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"registry_internal_url": None,
1717
"nifi_user": None,
1818
"nifi_pass": None,
19+
"nifi_bearer_token": None,
1920
"registry_user": None,
2021
"registry_pass": None,
2122
"ca_path": None,
@@ -51,6 +52,7 @@
5152
("registry_url", "REGISTRY_API_ENDPOINT"),
5253
("nifi_user", "NIFI_USERNAME"),
5354
("nifi_pass", "NIFI_PASSWORD"),
55+
("nifi_bearer_token", "NIFI_BEARER_TOKEN"),
5456
("registry_user", "REGISTRY_USERNAME"),
5557
("registry_pass", "REGISTRY_PASSWORD"),
5658
# Basic certificate paths and security config
@@ -109,6 +111,11 @@
109111

110112
# Authentication method definitions - data-driven approach for extensibility
111113
NIFI_AUTH_METHODS = {
114+
"bearer": {
115+
"detection_keys": ["nifi_bearer_token"],
116+
"required_keys": ["nifi_bearer_token"],
117+
"optional_keys": [],
118+
},
112119
"oidc": {
113120
"detection_keys": ["oidc_token_endpoint"],
114121
"required_keys": [
@@ -554,6 +561,16 @@ def switch(profile_name, profiles_file=None, login=True):
554561
log.debug("OIDC authentication completed")
555562
else:
556563
log.debug("OIDC configuration completed (no login attempted)")
564+
elif nifi_auth_method == "bearer":
565+
log.debug("Configuring bearer token authentication for NiFi...")
566+
if login:
567+
security.set_service_auth_token(
568+
token=nifi_auth_params["nifi_bearer_token"],
569+
service="nifi",
570+
)
571+
log.debug("Bearer token authentication completed")
572+
else:
573+
log.debug("Bearer token configuration completed (no login attempted)")
557574
elif nifi_auth_method == "mtls":
558575
log.debug("Configuring mTLS authentication for NiFi...")
559576
# Apply client certificates for mTLS

0 commit comments

Comments
 (0)