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

st2client error when installing pack with a restricted user #5303

Open
minsis opened this issue Jul 14, 2021 · 20 comments
Open

st2client error when installing pack with a restricted user #5303

minsis opened this issue Jul 14, 2021 · 20 comments
Labels

Comments

@minsis
Copy link
Contributor

minsis commented Jul 14, 2021

SUMMARY

I have a restricted user that should only have permissions to install packs. The pack install works fine but the client returns a python error

Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/shell.py", line 408, in run
    func(args)
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/commands/resource.py", line 48, in decorate
    return func(*args, **kwargs)
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/commands/pack.py", line 274, in run_and_print
    packs = instance.result['output']['packs_list']
AttributeError: 'Execution' object has no attribute 'result'

If I do the install with an admin level user everything is fine. The other issue here is that the pack gets installed just fine. The API logs has no errors and produces a 200 response (I do not have it in debug mode).

image

STACKSTORM VERSION

Paste the output of st2 --version: st2 3.4.1, on Python 3.6.8

OS, environment, install method

Post what OS you are running this on, along with any other relevant information/

  • OL7
  • HA install with a controller node running web, redis, rabbitmq, and mongo and 2 cluster nodes running everything else.

Steps to reproduce the problem

Create a user with the following role and install a pack:

name: pack_management
description: Allows a user to install, register, and modify packs only
permission_grants:
  -
    permission_types:
       - "pack_list"
       - "pack_install"
       - "pack_uninstall"
       - "pack_create"
       - "pack_register"
       - "pack_config"
       - "pack_search"
       - "runner_type_list"
  -
    resource_uid: "action:packs:install"
    permission_types:
       - "action_execute"
       - "action_view"
  -
    resource_uid: "action:packs:uninstall"
    permission_types:
       - "action_execute"
       - "action_view"
  -
    resource_uid: "action:packs:delete"
    permission_types:
       - "action_execute"
       - "action_view"
  -
    resource_uid: "action:packs:setup_virtualenv"
    permission_types:
       - "action_execute"
       - "action_view"
  -
    resource_uid: "action:packs:get"
    permission_types:
       - "action_execute"
       - "action_view"
  -
    resource_uid: "action:packs:get_config"
    permission_types:
       - "action_execute"
       - "action_view"
  -
    resource_uid: "action:packs:get_pack_dependencies"
    permission_types:
       - "action_execute"
       - "action_view"
  -
    resource_uid: "action:packs:get_pack_warnings"
    permission_types:
       - "action_execute"
       - "action_view"
  -
    resource_uid: "action:packs:download"
    permission_types:
       - "action_execute"
       - "action_view"
  -
    resource_uid: "action:packs:show"
    permission_types:
       - "action_execute"
       - "action_view"
  -
    resource_uid: "action:packs:unload"
    permission_types:
       - "action_execute"
       - "action_view"
  -
    resource_uid: "action:packs:update_virtualenv"
    permission_types:
       - "action_execute"
       - "action_view"
  -
    resource_uid: "action:packs:virtualenv_prerun"
    permission_types:
       - "action_execute"
       - "action_view"

Expected Results

While the package does in fact get installed, the output should reflect it:

<redacted-admin-user>@<redacted> ~ $ st2 pack install bitbucket

For the "bitbucket" pack, the following content will be registered:

actions   |  16
rules     |  1
sensors   |  1
aliases   |  0
triggers  |  0

Installation may take a while for packs with many items.

        [ succeeded ] init_task
        [ succeeded ] download_pack
        [ succeeded ] make_a_prerun
        [ succeeded ] get_pack_dependencies
        [ succeeded ] check_dependency_and_conflict_list
        [ succeeded ] install_pack_requirements
        [ succeeded ] get_pack_warnings
        [ succeeded ] register_pack

+-------------+-----------------------------------------------+
| Property    | Value                                         |
+-------------+-----------------------------------------------+
| ref         | bitbucket                                     |
| name        | bitbucket                                     |
| description | Pack which allows integration with Bitbucket. |
| version     | 1.0.1                                         |
| author      | Aamir                                         |
+-------------+-----------------------------------------------+

Actual Results

While the package does in fact get installed there's a python error for a missing attribute on an object.

Here is the full output of st2client in debug:

<redacted>@<redacted> ~ $ st2 --debug pack install bitbucket
/opt/stackstorm/st2/lib/python3.6/site-packages/urllib3/connectionpool.py:988: InsecureRequestWarning: Unverified HTTPS request is being made to host '<redacted>'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
# -------- begin 139988789087704 request ----------
curl -X POST -H  'User-Agent: python-requests/2.23.0' -H  'Accept-Encoding: gzip, deflate' -H  'Accept: */*' -H  'Connection: keep-alive' -H  'St2-Api-Key: <redacted>' -H  'content-type: application/json' -H  'Content-Length: 21' --data-binary '{"pack": "bitbucket"}' https://<redacted>/api/v1/packs/index/search
# -------- begin 139988789087704 response ----------
{
    "author": "Aamir",
    "content": {
        "actions": {
            "count": 16,
            "resources": [
                "archive_repo",
                "associate_ssh_key",
                "create_issue",
                "create_repo",
                "create_service",
                "delete_issues",
                "delete_repo",
                "delete_services",
                "delete_ssh_key",
                "list_branches",
                "list_issues",
                "list_repos",
                "list_services",
                "list_ssh_keys",
                "update_issue",
                "update_service"
            ]
        },
        "rules": {
            "count": 1,
            "resources": [
                "post_receive_webhook"
            ]
        },
        "sensors": {
            "count": 1,
            "resources": [
                "RepositorySensor"
            ]
        },
        "tests": {
            "count": 1,
            "resources": [
                "test_repository_sensor.py"
            ]
        }
    },
    "contributors": [
        "Edward Medvedev <edward.medvedev@gmail.com>",
        "Hiroyasu OHYAMA <user.localhost2000@gmail.com>"
    ],
    "description": "Pack which allows integration with Bitbucket.",
    "email": "raza.aamir01@gmail.com",
    "keywords": [
        "bitbucket",
        "vcs",
        "mercurial",
        "git",
        "source control"
    ],
    "name": "bitbucket",
    "python_versions": [
        "3"
    ],
    "ref": "bitbucket",
    "repo_url": "https://github.com/StackStorm-Exchange/stackstorm-bitbucket",
    "stackstorm_version": ">=2.1.0",
    "version": "1.0.1",
    "versions": [
        "1.0.1",
        "1.0.0",
        "0.6.0",
        "0.5.5",
        "0.5.4",
        "0.5.3",
        "0.5.2",
        "0.5.1",
        "0.5.0",
        "0.4.0",
        "0.3.0",
        "0.1.1",
        "0.1.0"
    ]
}
# -------- end 139988789087704 response ------------


For the "bitbucket" pack, the following content will be registered:

actions   |  16
rules     |  1
sensors   |  1
aliases   |  0
triggers  |  0

Installation may take a while for packs with many items.
/opt/stackstorm/st2/lib/python3.6/site-packages/urllib3/connectionpool.py:988: InsecureRequestWarning: Unverified HTTPS request is being made to host '<redacted>'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
# -------- begin 139988789087704 request ----------
curl -X POST -H  'User-Agent: python-requests/2.23.0' -H  'Accept-Encoding: gzip, deflate' -H  'Accept: */*' -H  'Connection: keep-alive' -H  'St2-Api-Key: <redacted>' -H  'content-type: application/json' -H  'Content-Length: 68' --data-binary '{"packs": ["bitbucket"], "force": false, "skip_dependencies": false}' https://<redacted>/api/v1/packs/install
# -------- begin 139988789087704 response ----------
{
    "execution_id": "60ef415ea91f4aa725e83776"
}
# -------- end 139988789087704 response ------------

/opt/stackstorm/st2/lib/python3.6/site-packages/urllib3/connectionpool.py:988: InsecureRequestWarning: Unverified HTTPS request is being made to host '<redacted>'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
# -------- begin 139988789087480 request ----------
curl -X GET -H  'User-Agent: python-requests/2.23.0' -H  'Accept-Encoding: gzip, deflate' -H  'Accept: */*' -H  'Connection: keep-alive' -H  'St2-Api-Key: <redacted>' https://<redacted>/api/v1/executions/60ef415ea91f4aa725e83776
# -------- begin 139988789087480 response ----------
{
    "action": {
        "tags": [],
        "uid": "action:packs:install",
        "metadata_file": "actions/install.meta.yaml",
        "name": "install",
        "ref": "packs.install",
        "description": "Installs or upgrades a pack into local content repository, either by git URL or a short name matching an index entry. Will download pack, load the actions, sensors and rules from the pack. Note that install requires reboot of some st2 services.",
        "enabled": true,
        "entry_point": "workflows/install.yaml",
        "pack": "packs",
        "runner_type": "orquesta",
        "parameters": {
            "packs": {
                "type": "array",
                "items": {
                    "type": "string"
                },
                "required": true,
                "description": "Name of the pack in Exchange or a git repo URL."
            },
            "register": {
                "type": "string",
                "default": "all",
                "description": "Possible options are all, sensors, actions, rules, aliases, runners, triggers, rule_types, policiy_types, policies, configs."
            },
            "env": {
                "type": "object",
                "description": "Optional environment variables.",
                "required": false
            },
            "force": {
                "type": "boolean",
                "description": "Set to True to force install the pack and skip StackStorm version compatibility check and also delete and ignore lock file if one exists.",
                "required": false,
                "default": false
            },
            "skip_dependencies": {
                "type": "boolean",
                "description": "Set to True to skip pack dependency installations.",
                "required": false,
                "default": false
            },
            "timeout": {
                "default": 600,
                "required": false,
                "description": "Action timeout in seconds. Action will get killed if it doesn't finish in timeout",
                "type": "integer"
            }
        },
        "output_schema": {},
        "notify": {},
        "id": "60d1fe29f25c6f0e9fae68bb"
    },
    "runner": {
        "name": "orquesta",
        "description": "A runner for executing orquesta workflow.",
        "uid": "runner_type:orquesta",
        "enabled": true,
        "runner_package": "orquesta_runner",
        "runner_module": "orquesta_runner",
        "runner_parameters": {
            "notify": {
                "type": "array",
                "description": "List of tasks to trigger notifications for.",
                "uniqueItems": true,
                "items": {
                    "type": "string",
                    "minLength": 1,
                    "pattern": "^\\w+$"
                },
                "default": []
            }
        },
        "output_key": "output",
        "output_schema": {
            "errors": {
                "anyOf": [
                    {
                        "type": "object"
                    },
                    {
                        "type": "array"
                    }
                ]
            },
            "output": {
                "anyOf": [
                    {
                        "type": "object"
                    },
                    {
                        "type": "string"
                    },
                    {
                        "type": "integer"
                    },
                    {
                        "type": "number"
                    },
                    {
                        "type": "boolean"
                    },
                    {
                        "type": "array"
                    },
                    {
                        "type": "null"
                    }
                ]
            }
        },
        "id": "60cbaf90fdedc9dd45b59894"
    },
    "liveaction": {
        "action": "packs.install",
        "action_is_workflow": true,
        "parameters": {
            "packs": [
                "bitbucket"
            ]
        },
        "callback": {},
        "runner_info": {},
        "id": "60ef415ea91f4aa725e83775"
    },
    "status": "requested",
    "start_timestamp": "2021-07-14T19:56:14.808247Z",
    "parameters": {
        "packs": [
            "bitbucket"
        ]
    },
    "context": {
        "user": "<redacted-limted-user>",
        "pack": "packs",
        "rbac": {
            "user": "<redacted-limted-user>",
            "roles": [
                "pack_management"
            ]
        }
    },
    "log": [
        {
            "timestamp": "2021-07-14T19:56:14.000000Z",
            "status": "requested"
        }
    ],
    "web_url": "https://<redacted>/#/history/60ef415ea91f4aa725e83776/general",
    "id": "60ef415ea91f4aa725e83776"
}
# -------- end 139988789087480 response ------------

ERROR: 'Execution' object has no attribute 'result'

CLI settings:
----------------
Config file path: /home/st2/.st2/config
Client settings:
----------------
ST2_BASE_URL: https://<redacted>
ST2_AUTH_URL: https://<redacted>/auth/v1
ST2_API_URL: https://<redacted>/api/v1
ST2_STREAM_URL: https://<redacted>/stream/v1
ST2_AUTH_TOKEN: None

Proxy settings:
---------------
HTTP_PROXY:
HTTPS_PROXY:

Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/shell.py", line 408, in run
    func(args)
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/commands/resource.py", line 48, in decorate
    return func(*args, **kwargs)
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/commands/pack.py", line 274, in run_and_print
    packs = instance.result['output']['packs_list']
AttributeError: 'Execution' object has no attribute 'result'

Thanks!

@minsis minsis changed the title st2client error when installing pack for restricted user st2client error when installing pack with a restricted user Jul 14, 2021
@amanda11
Copy link
Contributor

I tried with a 3.5dev install, and when I do the pack install with that role I get an error indicating that the user doesn't have pack view permission on the pack they tried to install.
I don't think we changed anything between 3.4.1 and 3.5 to do with rbac.

@minsis Could you see what happens if you add permissions for pack_view on the pack you are trying to install - to determine if that resolves the error, e.g.

  -
    resource_uid: "pack:bitbucket"
    permission_types:
       - "pack_view"

@minsis
Copy link
Contributor Author

minsis commented Aug 2, 2021

@amanda11 I did what you asked but I still get the same error. Unless my user is an admin I can't properly install packs using my limited roles.

I am able to execute st2 pack get bitbucket and view the pack after its been installed.

Overall the RBAC system seems unnecessarily complicated and the lack of documentation for it makes it really difficult to navigate and configure. Probably a discussion in a different forum.

@blag
Copy link
Contributor

blag commented Aug 2, 2021

Overall the RBAC system seems unnecessarily complicated and the lack of documentation for it makes it really difficult to navigate and configure. Probably a discussion in a different forum.

As another user of the RBAC backend, I agree wholeheartedly.

Not trying to shut you down here, I'm just trying to point you to the right place to discuss RBAC - it's the RBAC backend repo.

The RBAC backend desperately needs some love/updating/improvements/features, but I honestly think that RBAC isn't really the best fit for an authorization backend for ST2. I think something like an ACL system might be better.

Unfortunately, anything I've designed in my head ends up looking suspiciously like Unix file permissions and extended attributes, but there isn't a great way to simply wrap and utilize those, so we may be reinventing the wheel here. There might be a generic Python authorization library we can use like Oso (on GitHub).

@minsis
Copy link
Contributor Author

minsis commented Aug 3, 2021

@blag I have an similar feature opened which I guess goes along this lines of changing the RBAC system.

Also, the RBAC repo seems to go unnoticed by core devs as issues dont seem to get responses or tagged or anything.

So I guess my issue here is some obscure RBAC issue. I'm going to upgrade to 3.5.0 today if I can as I'm having some other issues in another ticket with pack installs dependency conflicts. Hopefully the upgrade can fix this issue as well.

@minsis
Copy link
Contributor Author

minsis commented Aug 3, 2021

@amanda11 I upgraded to 3.5 and am still having this issue. So I'm not sure where the issue is at this point. Is it with RBAC or is it something with st2client, something missing on my end?

I'm guessing its RBAC related since admin role works, but I have no clue what permissions are missing here to make this work.

st2@<redacted> ~ $ /opt/stackstorm/st2/bin/python
Python 3.6.8 (default, Mar  9 2021, 15:08:44)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44.0.3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import st2client
>>> st2client.__version__
'3.5.0'

@amanda11
Copy link
Contributor

amanda11 commented Aug 3, 2021

When you login as that user and try to do a pack install, do you get any errors? When I did it on 3.5 I got a clear error about what permission was reported.

Can you:

  • Check that the user has the pack view permission on the pack they are trying to install, and re-apply the rbac permissions
  • Login as user on command line, and just do a st2 client install as that user - and post the results. I got the error on screen, didn't need to run --debug.
  • In UI or command line, get the output/error of which ever execution failed.
  • In my case, the pack in question wasn't already installed, so I'm just wondering if different permissions needed if pack already installed - so if possible uninstall pack first.

@minsis
Copy link
Contributor Author

minsis commented Aug 3, 2021

So here I dont login I use an API key for this user - not sure if that makes a difference or not. doing st2 install bitbucket gives the traceback output as in my OP `AttributeError: 'Execution' object has no attribute 'result''

  • Check that the user has the pack view permission on the pack they are trying to install, and re-apply the rbac permissions
    This has been done many times. See below example.

With permissions

st2user@<redacted> ~ $ st2 pack get bitbucket
/opt/stackstorm/st2/lib/python3.6/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '<url>'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
+-------------+-----------------------------------------------+
| Property    | Value                                         |
+-------------+-----------------------------------------------+
| name        | bitbucket                                     |
| version     | 1.0.1                                         |
| author      | Aamir                                         |
| email       | raza.aamir01@gmail.com                        |
| keywords    | [                                             |
|             |     "bitbucket",                              |
|             |     "vcs",                                    |
|             |     "mercurial",                              |
|             |     "git",                                    |
|             |     "source control"                          |
|             | ]                                             |
| description | Pack which allows integration with Bitbucket. |
+-------------+-----------------------------------------------+

Without permissions

st2user@<redacted> ~ $ st2 pack get bitbucket
/opt/stackstorm/st2/lib/python3.6/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '<url>'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/commands/resource.py", line 199, in get_resource_by_pk
    instance = self.manager.get_by_id(pk, **kwargs)
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/models/core.py", line 42, in decorate
    return func(*args, **kwargs)
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/models/core.py", line 238, in get_by_id
    self.handle_error(response)
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/st2client/models/core.py", line 195, in handle_error
    response.raise_for_status()
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden
MESSAGE: User "svc-st2" doesn't have required permission "pack_view" on resource "pack:bitbucket" for url: https://<urL>/api/v1/packs/bitbucket
Pack "bitbucket" is not found.

ERROR: Resource bitbucket not found.
  • Login as user on command line, and just do a st2 client install as that user - and post the results. I got the error on screen, didn't need to run --debug.

The error is the same one outlined in the OP. The st2client fails as a python attribute error. Even with this failure the pack still installs just fine.

st2user@<redacted> ~ $ st2 pack install bitbucket
/opt/stackstorm/st2/lib/python3.6/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '<url>'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,

For the "bitbucket" pack, the following content will be registered:

actions   |  16
rules     |  1
sensors   |  1
aliases   |  0
triggers  |  0

Installation may take a while for packs with many items.
/opt/stackstorm/st2/lib/python3.6/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '<url>'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
/opt/stackstorm/st2/lib/python3.6/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '<url>'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
ERROR: 'Execution' object has no attribute 'result'
  • In UI or command line, get the output/error of which ever execution failed.

None of the executions fail. The pack will still install regardless of the st2user getting a traceback on st2client

st2user@<redacted>  ~ $ st2 execution get 6109728a42f81337b39bdf0b
/opt/stackstorm/st2/lib/python3.6/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '<url>'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
/opt/stackstorm/st2/lib/python3.6/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '<url>'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
id: 6109728a42f81337b39bdf0b
action.ref: packs.install
parameters:
  packs:
  - bitbucket
status: succeeded (36s elapsed)
start_timestamp: Tue, 03 Aug 2021 16:44:58 UTC
end_timestamp: Tue, 03 Aug 2021 16:45:34 UTC
log:
  - status: requested
    timestamp: '2021-08-03T16:44:58.110000Z'
  - status: scheduled
    timestamp: '2021-08-03T16:44:58.222000Z'
  - status: running
    timestamp: '2021-08-03T16:44:58.271000Z'
  - status: succeeded
    timestamp: '2021-08-03T16:45:34.560000Z'
result:
  output:
    conflict_list: []
    message: Successfully installed packs
    packs_list:
    - bitbucket
    warning_list: []
+--------------------------+-------------------------+-----------------------------------+-----------------------------+-------------------------------+
| id                       | status                  | task                              | action                      | start_timestamp               |
+--------------------------+-------------------------+-----------------------------------+-----------------------------+-------------------------------+
| 6109728a1e53fd99aedc70f2 | succeeded (0s elapsed)  | init_task                         | core.noop                   | Tue, 03 Aug 2021 16:44:58 UTC |
| 6109728b5f5ba424862603d4 | succeeded (3s elapsed)  | download_pack                     | packs.download              | Tue, 03 Aug 2021 16:44:59 UTC |
| 6109728e5f5ba424862603e3 | succeeded (0s elapsed)  | make_a_prerun                     | packs.virtualenv_prerun     | Tue, 03 Aug 2021 16:45:02 UTC |
| 6109728e5f5ba424862603f2 | succeeded (1s elapsed)  | get_pack_dependencies             | packs.get_pack_dependencies | Tue, 03 Aug 2021 16:45:02 UTC |
| 6109728f5f5ba42486260401 | succeeded (1s elapsed)  | check_dependency_and_conflict_lis | core.noop                   | Tue, 03 Aug 2021 16:45:03 UTC |
|                          |                         | t                                 |                             |                               |
| 610972905f5ba42486260410 | succeeded (27s elapsed) | install_pack_requirements         | packs.setup_virtualenv      | Tue, 03 Aug 2021 16:45:04 UTC |
| 610972ab5f5ba4248626041f | succeeded (1s elapsed)  | get_pack_warnings                 | packs.get_pack_warnings     | Tue, 03 Aug 2021 16:45:31 UTC |
| 610972ac5f5ba4248626042e | succeeded (2s elapsed)  | register_pack                     | packs.load                  | Tue, 03 Aug 2021 16:45:32 UTC |
+--------------------------+-------------------------+-----------------------------------+-----------------------------+-------------------------------+
  • In my case, the pack in question wasn't already installed, so I'm just wondering if different permissions needed if pack already installed - so if possible uninstall pack first.

I've uninstalled/installed the bitbucket pack a lot of times. Doesn't matter if its already installed or not I get the same issue.

PS

I've noticed that I get an https insecure warning on the same user, but when logged in as an admin user I dont see this error. I find this as odd behavior.

st2user

st2user@<redacted> ~ $ st2 execution get 6109728a42f81337b39bdf0b
/opt/stackstorm/st2/lib/python3.6/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '<url>'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
/opt/stackstorm/st2/lib/python3.6/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '<url>'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
id: 6109728a42f81337b39bdf0b

admin user (my account)

me@<redacted> ~ $ st2 execution get 6109728a42f81337b39bdf0b
id: 6109728a42f81337b39bdf0b

@amanda11
Copy link
Contributor

amanda11 commented Aug 3, 2021

I will try and give it a go with the APIKEY to see if I can reproduce the error, as that's the only difference I can see....
Is it possible to do a "st2 login" as a user with that same role and see if the problem exists then as well?

The error indicates that the output doesn't include a result, but from your st2 execution get then it does...

result:
  output:
    conflict_list: []
    message: Successfully installed packs
    packs_list:
    - bitbucket
    warning_list: []

If it's not because it's an API key, then the only thing I can think of is whether there's some timing problem or buffering, but then that doesn't explain why only with the non admin user (unless the apikey is the thing...).

The only other thing is to add in extra debug into the /opt/stackstorm/st2/lib/python3.6/site-packages/st2client/commands/pack.py to see what you have in that result object at the time st2client is trying to retrieve it.

I'm interested at what we have at this bit in the PackInstallCommand class:

    def run_and_print(self, args, **kwargs):
        instance = super(PackInstallCommand, self).run_and_print(args, **kwargs)
        # Hack to get a list of resolved references of installed packs
        packs = instance.result['output']['packs_list']

@amanda11
Copy link
Contributor

amanda11 commented Aug 3, 2021

I've managed to reproduce it...

$ st2 pack install aws_boto3

For the "aws_boto3" pack, the following content will be registered:

actions   |  6
rules     |  0
sensors   |  0
aliases   |  0
triggers  |  0

Installation may take a while for packs with many items.
ERROR: 'Execution' object has no attribute 'result'

@amanda11
Copy link
Contributor

amanda11 commented Aug 3, 2021

I don't think its related to the apikey login versus the username login, as I managed to reproduce today with both methods.

Added in debug, and it looks like its not waiting for the pack to be installed, as its trying to get the result when the execution result is in Requested state.
'''
Installation may take a while for packs with many items.
<Execution status=requested,action={'tags': [], 'uid': 'action:packs:install', 'metadata_file': 'actions/install.meta.yaml', 'name': 'install', 'ref': 'packs.install', 'description': 'Installs or upgrades a pack into local content repository, either by git URL or a short name matching an index entry. Will download pack, load the actions, sensors and rules from the pack. Note that install requires reboot of some st2 services.', 'enabled': True, 'entry_point': 'workflows/install.yaml', 'pack': 'packs', 'runner_type': 'orquesta', 'parameters': {'packs': {'type': 'array', 'items': {'type': 'string'}, 'required': True, 'description': 'Name of the pack in Exchange or a git repo URL.'}, 'register': {'type': 'string', 'default': 'all', 'description': 'Possible options are all, sensors, actions, rules, aliases, runners, triggers, rule_types, policiy_types, policies, configs.'}, 'env': {'type': 'object', 'description': 'Optional environment variables.', 'required': False}, 'force': {'type': 'boolean', 'description': 'Set to True to force install the pack and skip StackStorm version compatibility check and also delete and ignore lock file if one exists.', 'required': False, 'default': False}, 'skip_dependencies': {'type': 'boolean', 'description': 'Set to True to skip pack dependency installations.', 'required': False, 'default': False}, 'timeout': {'default': 600, 'required': False, 'description': "Action timeout in seconds. Action will get killed if it doesn't finish in timeout", 'type': 'integer'}}, 'output_schema': {}, 'notify': {}, 'id': '60bf5d3a17f055a1c56cc1ac'},start_timestamp=2021-08-03T18:55:07.825386Z,end_timestamp=None,parameters={'packs': ['aws_boto3']},delay=None>
ERROR: 'Execution' object has no attribute 'result'
'''

That would explain why it can't find the execution result.

So it looks like ST2 is trying to output the result at the point we've requested it to do a pack install, rather than waiting for the result in this case. Not sure if that's a timing issue, as I didn't see this the other day.

@amanda11 amanda11 added bug and removed bug labels Aug 3, 2021
@amanda11
Copy link
Contributor

amanda11 commented Aug 3, 2021

@minsis Found something in the st2stream logs:

2021-08-03 19:02:29,809 139735081647144 DEBUG error_handling [-] API call failed: User "packuser" doesn't have required permission "stream_view" (exception_class='ResourceTypeAccessDeniedError',exception_message='User "packuser" doesn\'t have required permission "stream_view"',exception_data={'permission_type': 'stream_view', 'user_db': <UserDB: UserDB(id=60f6a1e06a82029b060389a6, is_service=False, name="packuser", nicknames={})>})

So can you try adding stream_view permission, and see if that resolves the issue. It appears to have for me...

@minsis
Copy link
Contributor Author

minsis commented Aug 3, 2021

@amanda11 Looks like this was it. I guess that explains why I didn't see any errors in the API log since it was in the st2stream. I didn't think about it switching to st2stream for this. Thanks and appreciate your help in this!

The global stream_view permission isn't documented.

I would imagine this should still be a bug though as st2stream doesn't report a permissions error back to st2client so it just fails out.

@minsis
Copy link
Contributor Author

minsis commented Aug 3, 2021

Oh, also to note this will still fail if the user doesn't have the pack_view permissions for the pack itself. This makes it counterintuitive as this user is free to install packs but obviously not allowed to edit its own role. This makes my automation process of keeping our clusters in sync across our datacenters more tricky to deal with.

@amanda11
Copy link
Contributor

amanda11 commented Aug 3, 2021

Glad we found the problem, so sounds like this has shown a few things:

  1. we can rephrase or raise a new bug to state that we don't see the error from st2stream in this case
  2. we should document stream_view
  3. the usability in terms of it not stopping you installing but still returning an error - not sure if that should go into the general rbac discussion or we rephrase this for that.

Anything else I missed?

I think now we know root cause it might be worth separating the points out - so we can try and close off some of the simple ones quickly, so that at least if someone else gets the problem they don't have to repeat all our troubleshooting.
Yet we still don't want to forget the bigger problem.

@minsis
Copy link
Contributor Author

minsis commented Aug 3, 2021

  1. I raised a new bug report so that thread can go in the right direction: st2stream doesn't return errors to st2client #5317
  2. I raised a bug report in st2doc for this: Global RBAC permissions needs to be documented st2docs#1083 Overall, global permission types aren't documented.
  3. Not sure here either. I feel the RBAC repo gets overlooked in general since everything lives in st2. Also, while the core of RBAC lives in the rbac repo everything about RBAC is actually defined in st2common for the most part. The RABC repo only seems to host the resolvers for determining the effective user permission.

Let me know how you want to handle point 3 and I'll close out this ticket, unless you feel like its covered with the other two raised issues.

@minsis
Copy link
Contributor Author

minsis commented Aug 3, 2021

Actually re-reading what I wrote for point 3, I guess the answer would be RBAC since that's where it the effective permission would be resolved.

I guess another discussion would spawn out of this as to whether or its even supposed to do that. It seems like stream view shouldn't be a blocker for running actions. If you have those permissions defined in your role then it wouldn't make sense to error out your entire workflow because you can't view it over stream.

Overall I think stream_veiw doesn't make a whole lot of sense to me. It was added in 2.4.0 which is 4 years ago this month, so its hard to say what the intention was.

@amanda11
Copy link
Contributor

amanda11 commented Aug 5, 2021

Point 3 is an odd one. I originally was thinking it was about rbac, but its not its about st2 client doing an async call but then not having the permissions to check the stream. So in hindsight perhaps 1) would cover this, as if we got the error back it would be clear.

But the fact that for pack install you have to have the :pack_view permission to be able to install, is probably another point to add to StackStorm/st2-rbac-backend#53.

I don't have strong opinion, so happy for you to disagree.

@minsis
Copy link
Contributor Author

minsis commented Aug 6, 2021

While RBAC in the end blocks the stream_view on the backend, it doesn't prevent any other actions in the workflow from breaking as long as you have the permissions. Looking at my debug output you can see the failed call is made to https://<redacted>/api/v1/executions/60ef415ea91f4aa725e83776 so st2client tries pull from the api over stream at first. Looking at a working version of this in debug I see the same call and none to /stream, so if I had to take a guess st2client pulls stream data through the api. So I think I would say that point 3 is covered by point 1.

In the end there's just a list of issues with point 3 that contributes to what is happening here. But the root cause of the initial error wouldn't be RBAC it would be something between st2stream and st2client.

@sankojus
Copy link

Same issue for me
[root@xxxxx ~]#st2 pack install linux
ERROR: 'Execution' object has no attribute 'result'

Not able to install basic packs like linux email observing above error.

@stale
Copy link

stale bot commented Apr 16, 2022

Thanks for contributing to this issue. As it has been 90 days since the last activity, we are automatically marking is as stale. If this issue is not relevant or applicable anymore (problem has been fixed in a new version or similar), please close the issue or let us know so we can close it. On the contrary, if the issue is still relevant, there is nothing you need to do, but if you have any additional details or context which would help us when working on this issue, please include it as a comment to this issue.

@stale stale bot added the stale label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants