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

feat(authorization): Add bcrypt password support to v1 authorizations #19840

Merged
merged 1 commit into from
Oct 28, 2020

Conversation

stuartcarnie
Copy link
Contributor

@stuartcarnie stuartcarnie commented Oct 28, 2020

Closes #19837

This commit extends the v1/authorization package to support passwords associated with a token using bcrypt hashing. This feature is added to support upgrading InfluxDB 1.x users and using their existing passwords. A subsequent PR will utilize these APIs to authorize requests to the /query and /write HTTP endpoints by verifying (comparing) a provided password for a given authorization. These passwords will either be supplied via an Authorization header using the BASIC authentication scheme or via the u (user) and p (password) query parameters.

The influxd upgrade command will be extended to copy the users from meta.db and store the bcrypted version of the user's password so existing clients will not require changes.

The summary of changes include:

  • authorization.Service implements influxdb.PasswordsService
  • As an implementation of influxdb.PasswordsService:
    • passwords may now be assigned to authorizations
    • verifying (comparing) passwords for a given authorization, to be used by v1 handlers in the future (/query, /write)
  • A separate influxdb.PasswordsService that implements a cache when comparing passwords. These are salted and stored in-memory using a SHA256 hash.
    NOTE: This implementation is essentially copied from InfluxDB 1.x.
  • Extended HTTP service to set a password using /private/legacy/authorizations/{id}/password

As this is a private API, the CHANGELOG is not updated.

This commit extends the `v1/authorization` package to support
passwords associated with a token.

The summary of changes include:

* authorization.Service implements influxdb.PasswordsService
* Setting passwords for authorizations
* Verifying (comparing) passwords for a given authorization
* A service to cache comparing passwords, using a weaker hash
  that will live in memory only. This implementation is copied
  from InfluxDB 1.x
* Extended HTTP service to set a password using
  /private/legacy/authorizations/{id}/password

Closes #
@stuartcarnie stuartcarnie added the area/2.x OSS 2.0 related issues and PRs label Oct 28, 2020
@stuartcarnie stuartcarnie self-assigned this Oct 28, 2020
@stuartcarnie stuartcarnie requested review from a team and yquansah and removed request for a team October 28, 2020 02:00
inner influxdb.PasswordsService

mu sync.RWMutex // protects concurrent access to authCache
authCache map[influxdb.ID]authUser
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the bounds on this in memory cache.. or do we not need to worry about it growing unbounded?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question – this is only for unique user name tokens, so we'd expect this to be probably dozens at most

@stuartcarnie stuartcarnie merged commit 6bc4158 into master Oct 28, 2020
@stuartcarnie stuartcarnie deleted the sgc/issues/19837 branch October 28, 2020 20:03
stuartcarnie added a commit that referenced this pull request Oct 28, 2020
Remove remnants of previous token implementation

* As of #19840, V1 API tokens will be authorized using bcrypt passwords
stuartcarnie added a commit that referenced this pull request Oct 29, 2020
Remove remnants of previous token implementation

* As of #19840, V1 API tokens will be authorized using bcrypt passwords
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/2.x OSS 2.0 related issues and PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v1/authorization service should use bcrypt for verification
2 participants