Skip to content

Extensible key types #2

@OEP

Description

@OEP

We need a way that applications can define their own key types so that keys don't have to be tied to users.

The thinking was that we store keys in a model which isn't really associated with anything called Key and clients create their own model types which hold a foreign key to Key. User keys work using this sort of model. A UserKey is just has foreign keys to Key and auth.User.

The API looks something like this:

>>> from django_sshkey.models import UserKey
>>> from django.contrib.auth.models import User
>>> basekey = UserKey.base(key='ssh-rsa AAA...')
>>> basekey.full_clean()
>>> basekey.save()
>>> userkey = UserKey(basekey=basekey, user=User.objects.create(username='fred'))
>>> userkey.full_clean()
>>> userkey.save()

and users can define their own key types like so

>>> from django_sshkey.models import NamedKey
>>> class ServiceKey(NamedKey): pass
>>> basekey = ServiceKey.base(key='ssh-rsa AAA...')
...

where NamedKey is one of a couple of abstract models a user can inherit from to make the API consistent between key types. This type also requires keys to be named.

We expect this change to be mostly backwards compatible, but will probably breaking in Django's generated APIs (i.e. QuerySets). For that, this probably requires a major release. People who just use the views and forms, but don't deal extensively with the UserKey model should not be affected. This is because several attributes on UserKey will be moved into the Key model, so anyone expecting those attributes to exist on that particular model would see breakage.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions