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

Deleting Assets on IO produces Error 500/503 #855

Open
nikothome opened this issue Dec 4, 2024 · 2 comments
Open

Deleting Assets on IO produces Error 500/503 #855

nikothome opened this issue Dec 4, 2024 · 2 comments
Labels
breaking-change Tenable.io Tenable.io Package upstream-api The issue is related to the calling API or API Docs

Comments

@nikothome
Copy link

Describe the bug

I tried to delete a couple of assets. However, the call to tio.assets.delete(<asset_id>) errors out. Tenable support suggested to use the bulk delete endpoint, since the workbench delete asset call which is currently used is deprecated.

To Reproduce

#!/usr/bin/python3

from tenable.io import TenableIO
import logging

# prepare logging
logging.basicConfig(
    format='%(asctime)s %(levelname)-8s %(message)s',
    level=logging.INFO,
    datefmt='%Y-%m-%dT%H:%M:%S%z')

config["api_access_dev"] = "123456abef..."
config["api_secret_dev"] = "987654effe..."

tio_prod = TenableIO(config["api_access_dev"], config["api_secret_dev"])

assets_to_delete = {"9949a840-aaaa-4e71-8b93-e1158f9cb1d3", "20572c41-aaaa-48ea-be53-8eb4169b3d7c"}

for asset in assets_to_delete:
    try:
        tio_prod.assets.delete(asset)
        logging.info(f"Asset {asset} was deleted.")
    except Exception as e:
        logging.error(f"Error deleting asset {asset}.")
        logging.error(e, exc_info=True)
        continue

Log output:

2024-12-04T15:26:20+0100 ERROR    [503: DELETE] https://cloud.tenable.com/workbenches/assets/9949a840-aaaa-4e71-8b93-e1158f9cb1d3 body=b'{"statusCode":503,"error":"Service Unavailable","message":"Please wait a moment and try your request again."}'
2024-12-04T15:26:24+0100 ERROR    [500: DELETE] https://cloud.tenable.com/workbenches/assets/9949a840-aaaa-4e71-8b93-e1158f9cb1d3 body=b'{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred. Please wait a moment and try your request again."}'
2024-12-04T15:26:24+0100 ERROR    Error deleting asset 9949a840-aaaa-4e71-8b93-e1158f9cb1d3.
2024-12-04T15:26:24+0100 ERROR    [500: DELETE] https://cloud.tenable.com/workbenches/assets/9949a840-aaaa-4e71-8b93-e1158f9cb1d3 body=b'{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred. Please wait a moment and try your request again."}'
Traceback (most recent call last):
  File "C:\PycharmProjects\tio_python\tio_deleteAssets.py", line 31, in <module>
  File "C:\PycharmProjects\tio_python\venv\Lib\site-packages\tenable\io\assets.py", line 54, in delete
    self._api.delete('workbenches/assets/{}'.format(
  File "C:\PycharmProjects\tio_python\venv\Lib\site-packages\restfly\session.py", line 715, in delete
    return self._req('DELETE', path, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\PycharmProjects\tio_python\venv\Lib\site-packages\restfly\session.py", line 559, in _req
    raise error_resp
restfly.errors.ServerError: [500: DELETE] https://cloud.tenable.com/workbenches/assets/9949a840-aaaa-4e71-8b93-e1158f9cb1d3 body=b'{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred. Please wait a moment and try your request again."}'

Expected behavior
assets are marked as deleted and are ultimately deleted.

Screenshots

System Information (please complete the following information):

  • OS: Windows 11
  • Architecture [e.g. 64bit, 32bit]: 64Bits
  • Version: pytenable 1.6.0 with Python 3.11.7

Additional context
the call to the deprecated workbench with curl fails in the same way.

@SteveMcGrath
Copy link
Contributor

https://pytenable.readthedocs.io/en/stable/api/io/assets.html#tenable.io.assets.AssetsAPI.bulk_delete

The bulk_delete is already there for you to use. It IS filter-based, and not simply ID-based however, so you would construct that call like so:

from tenable.io import TenableIO
# If you use the environment variables TIO_ACCESS_KEY & TIO_SECRET_KEY, 
# you don't need to pass them


def delete_assets(*assets: list[str]):
    filters = []

    # construct the filter for every asset passed in
    for id in asset_ids:
            filters.append(('host.id', 'eq', str(id)))

    # initiate the call with the computed filters.
    with TenableIO() as tvm:
        tvm.assets.bulk_delete(*filters, filter_type='or')

@nikothome
Copy link
Author

Hi @SteveMcGrath,
first of - thanks for maintaining this project. Helped us a great deal so far.
back to the issue:
yeah - I saw that. I just thought that you either want to deprecate the assets.delete function or make it an alias for the delete_assets(*assets: list[str]) function you mentioned above. Having a non-working function call just wastes time of people debugging.

regards,

Niko

@SteveMcGrath SteveMcGrath added Tenable.io Tenable.io Package upstream-api The issue is related to the calling API or API Docs breaking-change labels Dec 6, 2024
@SteveMcGrath SteveMcGrath reopened this Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Tenable.io Tenable.io Package upstream-api The issue is related to the calling API or API Docs
Projects
None yet
Development

No branches or pull requests

2 participants