How to create username/password combo with permission to gmp.authenticate

I have a system running the latest version of python-gvm and would like to create a new user that is capable of authenticating through gmp.authenticate. notably to be able to have tasks and targets etc that this user created to be only visible to them.

I have used the gmp.create_user function to create new users and this works but they get a 401 unauthorized error when attempting to use their credentials within gmp.authenticate.

Any help is appreciated!

I’m not sure why you get 401 error. Here is code that works for me using GMP to create user and authenticate. Notably, if you do not assign a role_id for the user, you will get a 400 error when trying to authenticate.

from gvm.connections import UnixSocketConnection
from gvm.protocols.gmp import Gmp

# path to unix socket
path = '/run/gvmd/gvmd.sock'
connection = UnixSocketConnection(path=path)

# Get the XML transformer
from gvm.transforms import EtreeCheckCommandTransform
transform = EtreeCheckCommandTransform()

# using the with statement to automatically connect and disconnect to gvmd
with Gmp(connection=connection, transform=transform) as gmp:

    # Authenticate as admin
    gmp.authenticate('admin', 'password')

    # Create user with User role
    gmp.create_user('user1', password='password123', role_ids=['8d453140-b74d-11e2-b0be-406186ea4fc5'])

# Authenticate as user
with Gmp(connection=connection, transform=transform) as gmp:

    # Authenticate as user
    gmp.authenticate('user1', 'password123')

    # Get settings for user
    sets = gmp.get_user_settings()
    for set in sets:
        print(set.tag, set.attrib)