Skip to content

Commit 0687dbc

Browse files
authored
Fix Authentication issues introduced in 0.14.3, and other minor fixes (#256)
Revert 0.14.3 changes to Authentication handling which introduced basicAuth support but resulted in some NiFi connections appearing incorrectly as Anonymous Added simpler basicAuth control to force it via a config switch without changing tokenAuth and other Authorization header behavior during normal usage nipyapi.config.global_force_basic_auth is now available for use for this purpose Secured Registry users will now require the authorization policy to retrieve the swagger so we may use it to validate which version of Registry is in use for feature enablement Moved all Security controls in config.py to a common area at the foot of the file Removed auth_type from security.service_login as it is now redundant Added controls to handle certificate checking behavior which has become more strict in recently versions of Python3, ssl_verify and check_hostname are now handled security.set_service_auth_token now has an explicit flag for ssl host checking as well Fix oversight where improved model serialisation logic was not correctly applied to Registry Removed unusused parameter refresh from parameters.update_parameter_context Reduced unecessary complexity in utils.dump with no change in functionality Updated client gen mustache templates to reflect refactored security and api client code Minor linting and docstring and codestyle improvements Set pyUp to ignore Watchdog as it must stay between versions to statisfy py2 and py3 compatibility If Client is not instantiated, optimistically instantiate for version checking
1 parent 9c880be commit 0687dbc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+819
-772
lines changed

nipyapi/config.py

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from __future__ import absolute_import
1010
import logging
1111
import os
12+
import ssl
1213
import urllib3
1314
from nipyapi.nifi import configuration as nifi_config
1415
from nipyapi.registry import configuration as registry_config
@@ -34,32 +35,6 @@
3435
# Set Default Host for NiFi-Registry
3536
registry_config.host = 'http://' + default_host + ':18080/nifi-registry-api'
3637

37-
38-
# Set Default Auth Types
39-
# Set list to the Auth type you want to use
40-
# Currently basicAuth trumps tokenAuth if both are enabled
41-
default_auth = ['tokenAuth']
42-
# NiFi valid options: ['tokenAuth', 'basicAuth']
43-
# Registry valid options: ['tokenAuth', 'basicAuth', 'Authorization']
44-
nifi_config.enabled_auth = default_auth # tokenAuth was default before 0.14.2
45-
46-
47-
# Set SSL Handling
48-
# When operating with self signed certs, your log can fill up with
49-
# unnecessary warnings
50-
# Set to True by default, change to false if necessary
51-
global_ssl_verify = True
52-
53-
nifi_config.verify_ssl = global_ssl_verify
54-
registry_config.verify_ssl = global_ssl_verify
55-
if not global_ssl_verify:
56-
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
57-
58-
if os.getenv('NIFI_CA_CERT') is not None:
59-
nifi_config.ssl_ca_cert = os.getenv('NIFI_CA_CERT')
60-
nifi_config.cert_file = os.getenv('NIFI_CLIENT_CERT')
61-
nifi_config.key_file = os.getenv('NIFI_CLIENT_KEY')
62-
6338
# --- Project Root ------
6439
# Is is helpful to have a reference to the root directory of the project
6540
PROJECT_ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
@@ -140,6 +115,43 @@
140115
# If called for during policy setup, particularly bootstrap_policies
141116
default_proxy_user = 'CN=localhost, OU=nifi'
142117

118+
# Auth handling
119+
# If set, NiPyAPI will always include the Basic Authorization header
120+
global_force_basic_auth = False
121+
nifi_config.username = default_nifi_username
122+
nifi_config.password = default_nifi_password
123+
nifi_config.force_basic_auth = global_force_basic_auth
124+
registry_config.username = default_registry_username
125+
registry_config.password = default_registry_password
126+
registry_config.force_basic_auth = global_force_basic_auth
127+
128+
# Set SSL Handling
129+
# When operating with self signed certs, your log can fill up with
130+
# unnecessary warnings
131+
# Set to True by default, change to false if necessary
132+
global_ssl_verify = True
133+
134+
nifi_config.verify_ssl = global_ssl_verify
135+
registry_config.verify_ssl = global_ssl_verify
136+
if not global_ssl_verify:
137+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
138+
139+
# Enforce no host checking when SSL context is disabled
140+
global_ssl_host_check = False
141+
if not global_ssl_host_check:
142+
nifi_config.ssl_context = ssl.create_default_context()
143+
nifi_config.ssl_context.check_hostname = False
144+
nifi_config.ssl_context.verify_mode = ssl.CERT_NONE
145+
146+
registry_config.ssl_context = ssl.create_default_context()
147+
registry_config.ssl_context.check_hostname = False
148+
registry_config.ssl_context.verify_mode = ssl.CERT_NONE
149+
150+
if os.getenv('NIFI_CA_CERT') is not None:
151+
nifi_config.ssl_ca_cert = os.getenv('NIFI_CA_CERT')
152+
nifi_config.cert_file = os.getenv('NIFI_CLIENT_CERT')
153+
nifi_config.key_file = os.getenv('NIFI_CLIENT_KEY')
143154

155+
# --- URL Encoding
144156
# URL Encoding bypass characters will not be encoded during submission
145157
default_safe_chars = ''

nipyapi/nifi/api_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,8 @@ def update_params_for_auth(self, headers, querys, auth_settings):
523523
raise ValueError(
524524
'Authentication token must be in `query` or `header`'
525525
)
526+
if config.force_basic_auth:
527+
headers['Authorization'] = config.get_basic_auth_token()
526528

527529
def __deserialize_file(self, response):
528530
"""

nipyapi/nifi/apis/access_api.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def create_access_token_with_http_info(self, **kwargs):
130130
select_header_content_type(['application/x-www-form-urlencoded'])
131131

132132
# Authentication setting
133-
auth_settings = ['tokenAuth', 'basicAuth']
133+
auth_settings = ['tokenAuth']
134134

135135
return self.api_client.call_api('/access/token', 'POST',
136136
path_params,
@@ -228,7 +228,7 @@ def create_access_token_from_ticket_with_http_info(self, **kwargs):
228228
select_header_content_type(['text/plain'])
229229

230230
# Authentication setting
231-
auth_settings = ['tokenAuth', 'basicAuth']
231+
auth_settings = ['tokenAuth']
232232

233233
return self.api_client.call_api('/access/kerberos', 'POST',
234234
path_params,
@@ -326,7 +326,7 @@ def create_download_token_with_http_info(self, **kwargs):
326326
select_header_content_type(['application/x-www-form-urlencoded'])
327327

328328
# Authentication setting
329-
auth_settings = ['tokenAuth', 'basicAuth']
329+
auth_settings = ['tokenAuth']
330330

331331
return self.api_client.call_api('/access/download-token', 'POST',
332332
path_params,
@@ -424,7 +424,7 @@ def create_ui_extension_token_with_http_info(self, **kwargs):
424424
select_header_content_type(['application/x-www-form-urlencoded'])
425425

426426
# Authentication setting
427-
auth_settings = ['tokenAuth', 'basicAuth']
427+
auth_settings = ['tokenAuth']
428428

429429
return self.api_client.call_api('/access/ui-extension-token', 'POST',
430430
path_params,
@@ -522,7 +522,7 @@ def get_access_status_with_http_info(self, **kwargs):
522522
select_header_content_type(['*/*'])
523523

524524
# Authentication setting
525-
auth_settings = ['tokenAuth', 'basicAuth']
525+
auth_settings = ['tokenAuth']
526526

527527
return self.api_client.call_api('/access', 'GET',
528528
path_params,
@@ -542,7 +542,7 @@ def get_access_status_with_http_info(self, **kwargs):
542542
def get_login_config(self, **kwargs):
543543
"""
544544
Retrieves the access configuration for this NiFi
545-
545+
546546
This method makes a synchronous HTTP request by default. To make an
547547
asynchronous HTTP request, please define a `callback` function
548548
to be invoked when receiving the response.
@@ -567,7 +567,7 @@ def get_login_config(self, **kwargs):
567567
def get_login_config_with_http_info(self, **kwargs):
568568
"""
569569
Retrieves the access configuration for this NiFi
570-
570+
571571
This method makes a synchronous HTTP request by default. To make an
572572
asynchronous HTTP request, please define a `callback` function
573573
to be invoked when receiving the response.
@@ -620,7 +620,7 @@ def get_login_config_with_http_info(self, **kwargs):
620620
select_header_content_type(['*/*'])
621621

622622
# Authentication setting
623-
auth_settings = ['tokenAuth', 'basicAuth']
623+
auth_settings = ['tokenAuth']
624624

625625
return self.api_client.call_api('/access/config', 'GET',
626626
path_params,
@@ -718,7 +718,7 @@ def knox_callback_with_http_info(self, **kwargs):
718718
select_header_content_type(['*/*'])
719719

720720
# Authentication setting
721-
auth_settings = ['tokenAuth', 'basicAuth']
721+
auth_settings = ['tokenAuth']
722722

723723
return self.api_client.call_api('/access/knox/callback', 'GET',
724724
path_params,
@@ -816,7 +816,7 @@ def knox_logout_with_http_info(self, **kwargs):
816816
select_header_content_type(['*/*'])
817817

818818
# Authentication setting
819-
auth_settings = ['tokenAuth', 'basicAuth']
819+
auth_settings = ['tokenAuth']
820820

821821
return self.api_client.call_api('/access/knox/logout', 'GET',
822822
path_params,
@@ -914,7 +914,7 @@ def knox_request_with_http_info(self, **kwargs):
914914
select_header_content_type(['*/*'])
915915

916916
# Authentication setting
917-
auth_settings = ['tokenAuth', 'basicAuth']
917+
auth_settings = ['tokenAuth']
918918

919919
return self.api_client.call_api('/access/knox/request', 'GET',
920920
path_params,
@@ -1012,7 +1012,7 @@ def log_out_with_http_info(self, **kwargs):
10121012
select_header_content_type(['*/*'])
10131013

10141014
# Authentication setting
1015-
auth_settings = ['tokenAuth', 'basicAuth']
1015+
auth_settings = ['tokenAuth']
10161016

10171017
return self.api_client.call_api('/access/logout', 'DELETE',
10181018
path_params,
@@ -1110,7 +1110,7 @@ def oidc_callback_with_http_info(self, **kwargs):
11101110
select_header_content_type(['*/*'])
11111111

11121112
# Authentication setting
1113-
auth_settings = ['tokenAuth', 'basicAuth']
1113+
auth_settings = ['tokenAuth']
11141114

11151115
return self.api_client.call_api('/access/oidc/callback', 'GET',
11161116
path_params,
@@ -1208,7 +1208,7 @@ def oidc_exchange_with_http_info(self, **kwargs):
12081208
select_header_content_type(['*/*'])
12091209

12101210
# Authentication setting
1211-
auth_settings = ['tokenAuth', 'basicAuth']
1211+
auth_settings = ['tokenAuth']
12121212

12131213
return self.api_client.call_api('/access/oidc/exchange', 'POST',
12141214
path_params,
@@ -1306,7 +1306,7 @@ def oidc_logout_with_http_info(self, **kwargs):
13061306
select_header_content_type(['*/*'])
13071307

13081308
# Authentication setting
1309-
auth_settings = ['tokenAuth', 'basicAuth']
1309+
auth_settings = ['tokenAuth']
13101310

13111311
return self.api_client.call_api('/access/oidc/logout', 'GET',
13121312
path_params,
@@ -1404,7 +1404,7 @@ def oidc_request_with_http_info(self, **kwargs):
14041404
select_header_content_type(['*/*'])
14051405

14061406
# Authentication setting
1407-
auth_settings = ['tokenAuth', 'basicAuth']
1407+
auth_settings = ['tokenAuth']
14081408

14091409
return self.api_client.call_api('/access/oidc/request', 'GET',
14101410
path_params,

nipyapi/nifi/apis/connections_api.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, api_client=None):
4343
def delete_connection(self, id, **kwargs):
4444
"""
4545
Deletes a connection
46-
46+
4747
This method makes a synchronous HTTP request by default. To make an
4848
asynchronous HTTP request, please define a `callback` function
4949
to be invoked when receiving the response.
@@ -72,7 +72,7 @@ def delete_connection(self, id, **kwargs):
7272
def delete_connection_with_http_info(self, id, **kwargs):
7373
"""
7474
Deletes a connection
75-
75+
7676
This method makes a synchronous HTTP request by default. To make an
7777
asynchronous HTTP request, please define a `callback` function
7878
to be invoked when receiving the response.
@@ -141,7 +141,7 @@ def delete_connection_with_http_info(self, id, **kwargs):
141141
select_header_content_type(['*/*'])
142142

143143
# Authentication setting
144-
auth_settings = ['tokenAuth', 'basicAuth']
144+
auth_settings = ['tokenAuth']
145145

146146
return self.api_client.call_api('/connections/{id}', 'DELETE',
147147
path_params,
@@ -161,7 +161,7 @@ def delete_connection_with_http_info(self, id, **kwargs):
161161
def get_connection(self, id, **kwargs):
162162
"""
163163
Gets a connection
164-
164+
165165
This method makes a synchronous HTTP request by default. To make an
166166
asynchronous HTTP request, please define a `callback` function
167167
to be invoked when receiving the response.
@@ -187,7 +187,7 @@ def get_connection(self, id, **kwargs):
187187
def get_connection_with_http_info(self, id, **kwargs):
188188
"""
189189
Gets a connection
190-
190+
191191
This method makes a synchronous HTTP request by default. To make an
192192
asynchronous HTTP request, please define a `callback` function
193193
to be invoked when receiving the response.
@@ -247,7 +247,7 @@ def get_connection_with_http_info(self, id, **kwargs):
247247
select_header_content_type(['*/*'])
248248

249249
# Authentication setting
250-
auth_settings = ['tokenAuth', 'basicAuth']
250+
auth_settings = ['tokenAuth']
251251

252252
return self.api_client.call_api('/connections/{id}', 'GET',
253253
path_params,
@@ -267,7 +267,7 @@ def get_connection_with_http_info(self, id, **kwargs):
267267
def update_connection(self, id, body, **kwargs):
268268
"""
269269
Updates a connection
270-
270+
271271
This method makes a synchronous HTTP request by default. To make an
272272
asynchronous HTTP request, please define a `callback` function
273273
to be invoked when receiving the response.
@@ -294,7 +294,7 @@ def update_connection(self, id, body, **kwargs):
294294
def update_connection_with_http_info(self, id, body, **kwargs):
295295
"""
296296
Updates a connection
297-
297+
298298
This method makes a synchronous HTTP request by default. To make an
299299
asynchronous HTTP request, please define a `callback` function
300300
to be invoked when receiving the response.
@@ -360,7 +360,7 @@ def update_connection_with_http_info(self, id, body, **kwargs):
360360
select_header_content_type(['application/json'])
361361

362362
# Authentication setting
363-
auth_settings = ['tokenAuth', 'basicAuth']
363+
auth_settings = ['tokenAuth']
364364

365365
return self.api_client.call_api('/connections/{id}', 'PUT',
366366
path_params,

0 commit comments

Comments
 (0)