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

[auth][api] QgsAuthConfigurationStorage classes and tests #57992

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

elpaso
Copy link
Contributor

@elpaso elpaso commented Jul 5, 2024

Abstract authentication credentials storage

Implementation of qgis/QGIS-Enhancement-Proposals#248

Goal

Provide an abstract API to manage authentication configurations storage.
The new API supports any database supported by QSqlDatabase (https://doc.qt.io/qt-5/qsqldatabase.html) including SQLite.

Additional features:

  • support non-DB sources through Python plugins or new C++ implementations
  • support multiple sources through a new QgsAuthConfigurationStorageRegistry that holds the (ordered) list of authentication storages available to the system
  • granular CRUD capabilities to allow storages to support only a subset of the auth assets that are currently supported by the QGIS auth system
  • support for both encrypted and unencrypted storages (for external third party storages that handle encryption themselves)

@elpaso elpaso added API API improvement only, no visible user interface changes Authentication Related to the QGIS Authentication subsystem or user/password handling NOT FOR MERGE Don't merge! labels Jul 5, 2024
@elpaso elpaso marked this pull request as draft July 5, 2024 07:03
@github-actions github-actions bot added this to the 3.40.0 milestone Jul 5, 2024
src/core/auth/qgsauthconfigurationstorage.h Show resolved Hide resolved
src/core/auth/qgsauthconfigurationstorage.h Show resolved Hide resolved
src/core/auth/qgsauthconfigurationstorage.h Outdated Show resolved Hide resolved
src/core/CMakeLists.txt Outdated Show resolved Hide resolved
* Abstract class that defines the interface for all authentication configuration storage implementations.
* \since QGIS 3.40
*/
class CORE_EXPORT QgsAuthConfigurationStorage: public QObject SIP_ABSTRACT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class CORE_EXPORT QgsAuthConfigurationStorage: public QObject SIP_ABSTRACT
class CORE_EXPORT QgsAbstractAuthConfigurationStorage: public QObject SIP_ABSTRACT

I'd argue that "storage" in this class name is needlessly restrictive. Perhaps QgsAbstractAuthBackend is a better choice?

src/core/auth/storage/qgsauthconfigurationstoragedb.cpp Outdated Show resolved Hide resolved

bool QgsAuthConfigurationStorageDb::authDbOpen() const
{
QMutexLocker locker( &mMutex );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all these implementations 1:1 copies of the current code? Or are there modifications I should look over specifically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are mostly 1:1 copies but I did not just cut & paste. I'd say that you can defer the review of the CRUD methods after finish writing the tests, I will probably intercept most issues while testing.

src/core/auth/qgsauthconfigurationstorage.h Show resolved Hide resolved
src/core/qgis.h Outdated Show resolved Hide resolved
src/core/qgis.h Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Jul 9, 2024

🪟 Windows builds ready!

Windows builds of this PR are available for testing here. Debug symbols for this build are available here.

(Built from commit 0b8eddc)

@elpaso elpaso force-pushed the authmanager-storage-api branch 5 times, most recently from 50b2786 to d93a8c2 Compare July 15, 2024 14:03
@elpaso elpaso force-pushed the authmanager-storage-api branch 2 times, most recently from 04b6f9b to da447d3 Compare July 18, 2024 10:32
@elpaso elpaso marked this pull request as ready for review July 18, 2024 17:29
@elpaso elpaso removed the NOT FOR MERGE Don't merge! label Jul 18, 2024
src/core/auth/qgsauthconfigurationstorage.h Outdated Show resolved Hide resolved
src/core/auth/qgsauthconfigurationstorageregistry.h Outdated Show resolved Hide resolved
src/core/auth/qgsauthconfigurationstorageregistry.h Outdated Show resolved Hide resolved
src/core/qgis.h Outdated Show resolved Hide resolved
src/core/qgis.h Show resolved Hide resolved
}

QSqlQuery query( authDatabaseConnection() );

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a design question than a code question -- but I'm curious how this method will work in a multi-user setup? Eg a number of plugins I've come across (and some I maintain) use this method to securely store API tokens after a user authenticates with a service. So I'm wondering what would happen if there's a central auth db setup (say on postgres), and then a plugin attempts to store something inherently user-specific like a API token? Either the db will be locked down and prevent this, or they'll clobber their work colleagues' token. Both situations are bad, and would ultimately break the plugin. 😱 (Or is the intention here that a centrally managed auth db is siloed into completely separate user "buckets" via db-level handling? )

Unless this situation is gracefully handled I can see this being a blocker for real-world use cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a step back: the original goal was to provide a way to store credentials in a real client-server DB to remove the filesystem sqlite DB which is causing a lot of issues with QGIS server deployments in the cloud.

For the desktop there is an enterprise use case which I think is interesting (and I spotted in the wild when working with big government orgs in the past): centrally managed shared credentials for company's services.

With the new API you can have read/only storages and you can have multiple storages, so you can imagine using a read/write local storage for user overrides.

Also, you can subclass QgsAuthConfigurationStorage (if not SIP_ABSTRACT) or QgsAuthConfigurationStorageDb and create your own accessors to the DB with filters for the user.

I thought about adding a 'user' field or something similar to the tables but I thought it was too much specific and it wouldn't ever cover all use cases.

Coming back to your use case (if I get this right): if a plugin uses the auth system for its own secure storage it would probably be capable of managing its own keys naming convention to avoid clashes with other users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API API improvement only, no visible user interface changes Authentication Related to the QGIS Authentication subsystem or user/password handling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants