Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Flow Version Failing With Anonymous Identity #258

Open
crhicko opened this issue Jan 28, 2021 · 7 comments
Open

Import Flow Version Failing With Anonymous Identity #258

crhicko opened this issue Jan 28, 2021 · 7 comments
Milestone

Comments

@crhicko
Copy link

crhicko commented Jan 28, 2021

  • Nipyapi version: 0.16.1
  • NiFi version: 1.11.4
  • NiFi-Registry version: 0.8.0
  • Python version: 3.7.4
  • Operating System: Windows

Description

The import_flow_version command is returning 401 errors despite security.service_login returning true. Of note I also have the global_ssl_verify = false set in config.py since the certs arent available for us on local. Other commands such as get_registry_bucket() work fine

What I Did

import nipyapi
nipyapi.config.registry_config.host = <my_env>
nipyapi.security.service_login(service='registry', username=user, password=pass, bool_response=True, auth_type='token')
True
nipyapi.versioning.import_flow_version("5d7bc617-b702-4ba2-8168-f7bf78d3c391", encoded_flow=None, file_path='./tmp/flow.json', flow_name="name", flow_id=None)

Traceback (most recent call last):
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\utils.py", line 604, in rest_exceptions
yield
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\versioning.py", line 470, in create_flow
version_count=0
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\registry\apis\bucket_flows_api.py", line 67, in create_flow
(data) = self.create_flow_with_http_info(bucket_id, body, **kwargs)
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\registry\apis\bucket_flows_api.py", line 154, in create_flow_with_http_info
collection_formats=collection_formats)
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\registry\api_client.py", line 326, in call_api
_return_http_data_only, collection_formats, _preload_content, _request_timeout)
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\registry\api_client.py", line 153, in __call_api
_request_timeout=_request_timeout)
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\registry\api_client.py", line 371, in request
body=body)
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\registry\rest.py", line 268, in POST
body=body)
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\registry\rest.py", line 224, in request
raise ApiException(http_resp=r)
nipyapi.registry.rest.ApiException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Date': 'Thu, 28 Jan 2021 19:30:27 GMT', 'Content-Type': 'text/plain', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Strict-Transport-Security': 'max-age=31540000 ; includeSubDomains', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Security-Policy': "frame-ancestors 'self'", 'Content-Length': '73', 'Server': 'Jetty(9.4.19.v20190610)'})
HTTP response body: Unknown user with identity 'anonymous'. Contact the system administrator.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "", line 1, in
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\versioning.py", line 670, in import_flow_version
flow_name=flow_name
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\versioning.py", line 470, in create_flow
version_count=0
File "C:\Program Files\Python37\lib\contextlib.py", line 130, in exit
self.gen.throw(type, value, traceback)
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\utils.py", line 607, in rest_exceptions
raise(ValueError(e.body), e)
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\future\utils_init
.py", line 403, in raise_from
exec(execstr, myglobals, mylocals)
File "", line 1, in
ValueError: Unknown user with identity 'anonymous'. Contact the system administrator.

Urgency

Blocking work on our nifi flow migration

@Chaffelson
Copy link
Owner

Chaffelson commented Jan 28, 2021 via email

@crhicko
Copy link
Author

crhicko commented Jan 28, 2021

Looks like that resolves the anonymous user issue but now I get this:

nipyapi.versioning.import_flow_version("5d7bc617-b702-4ba2-8168-f7bf78d3c391", encoded_flow=None, file_path='./process-groups/tmp/flow.json', flow_name=None, flow_id="c935dd5f-a012-4bbd-b7db-05a64354f84d")

Traceback (most recent call last):
File "", line 1, in
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\versioning.py", line 685, in import_flow_version
nipyapi.utils.validate_parameters_versioning_support()
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\utils.py", line 525, in validate_parameters_versioning_support
'0.6', service='registry', bool_response=True)
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\utils.py", line 544, in enforce_min_ver
if check_version(min_version, service=service) == 1:
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\utils.py", line 496, in check_version
auth_settings=['tokenAuth', 'Authorization']
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\registry\api_client.py", line 332, in call_api
_return_http_data_only, collection_formats, _preload_content, _request_timeout)
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\registry\api_client.py", line 153, in __call_api
_request_timeout=_request_timeout)
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\registry\api_client.py", line 355, in request
headers=headers)
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\registry\rest.py", line 233, in GET
query_params=query_params)
File "C:\Users\wzrbxs\AppData\Roaming\Python\Python37\site-packages\nipyapi\registry\rest.py", line 224, in request
raise ApiException(http_resp=r)
nipyapi.registry.rest.ApiException: (403)
Reason: Forbidden
HTTP response headers: HTTPHeaderDict({'Date': 'Thu, 28 Jan 2021 22:09:09 GMT', 'Content-Type': 'text/plain;charset=iso-8859-1', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Strict-Transport-Security': 'max-age=31540000 ; includeSubDomains', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Security-Policy': "frame-ancestors 'self'", 'Transfer-Encoding': 'chunked', 'Server': 'Jetty(9.4.19.v20190610)'})
HTTP response body: b'Access is denied due to: Unable to view swagger. Contact the system administrator.\n'

@crhicko
Copy link
Author

crhicko commented Jan 29, 2021

Update: turns out our Registry is version 0.6.0 not 0.8.0. Also it appears there is no registry-0.6.0.json in the api_defs folder of nipy, could this be causing this issue?

@Chaffelson
Copy link
Owner

So the problem is most likely that you do not have permission to download the swagger.json from the Registry, which is a new requirement. The way I've coded it at the moment it'll throw an error in that case.
Perhaps it would be more pythonic to attempt the call and handle the failure if your version of registry is too old to support that feature.
Otherwise you can grant your user the swagger read authorization on Registry and it should work

@iMajna
Copy link

iMajna commented Feb 3, 2021

@crhicko as @Chaffelson mentioned you are most likely missing "/swagger" read policy in Registry for user with which you are trying to make a call

Now, you cannot create that policy through UI. I happened to have the same issue you are meeting with and don't know whether you still have the same issue. So, I'll just post solution so someone else might find his way if he/she is lost.

Best approach would be creating that policy through rest API if you can but if you cannot manual steps would be:

  1. Find user ID (user to which you want to give access to swagger) in authorizations.xml file or group ID (would be even better to respect role base access if you follow one)
  2. Stop NiFi-Registry
  3. Find a swagger policy line in authorizations.xml
  4. Add extra <user identifier="<your-userid"/> or <group identifier="<your-groupid"/> line for that already created policy
  5. Save and restart Registry

You can even try it to do through nipyapi if you want so. Here is the example which is giving user "nobel" read access on bucket:

all_buckets_access_policies = [

you can copy/paste part of code needed for creating policy and have:

  all_buckets_access_policies = [
       ("read", "/swagger")
   ]

instead of what's written in file above, haven't tried it but it should work.

Hope it helps..

@Chaffelson
Copy link
Owner

Chaffelson commented Feb 14, 2021 via email

@wm99
Copy link

wm99 commented Apr 4, 2023

I've the same issue how to fix? also I've this issue.
in wait_to_complete
raise ValueError("Timed Out waiting for {0} to complete".format(
ValueError: Timed Out waiting for is_endpoint_up to complete

@Chaffelson Chaffelson added this to the 0.20 milestone Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants