Skip to content

Commit 15ffd45

Browse files
Version 3.0.0 (#255)
* Version 3.0 * Apply suggestions from code review
1 parent 8864e4f commit 15ffd45

File tree

7 files changed

+51
-6
lines changed

7 files changed

+51
-6
lines changed

CHANGELOG.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## Unreleased
7+
## 3.0.0 - 2023-09-30
88

9-
### Fixed
9+
### Changed
10+
11+
- Use faster SHA512-based key hasher instead of password hashers. Reduces server load by making API key validation orders of magnitude faster (10x to 30x according to estimations, network latency aside). Hashed key will be transparently upgraded the first time `.is_valid()` is called. (Pull #244, Pull #251)
12+
13+
### Removed
1014

15+
- Dropped support for Python 3.7, which has reached EOL. (Pull #247)
1116
- Drop redundant `.has_object_permission()` implementation on `BaseHasAPIKey` when using DRF 3.14.0 or above. (Pull #240)
1217

18+
### Added
19+
20+
- Add official support for Python 3.11. (Pull #247)
21+
1322
## 2.3.0 - 2023-01-19
1423

1524
### Removed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ They can also present enough security for authorizing internal services, such as
5252
Install with `pip`:
5353

5454
```bash
55-
pip install "djangorestframework-api-key==2.*"
55+
pip install "djangorestframework-api-key==3.*"
5656
```
5757

5858
_**Note**: It is highly recommended to **pin your dependency** to the latest major version (as depicted above), as breaking changes may and will happen between major releases._

docs/guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Install with `pip`:
88

99
```bash
10-
pip install "djangorestframework-api-key==2.*"
10+
pip install "djangorestframework-api-key==3.*"
1111
```
1212

1313
_**Note**: It is highly recommended to **pin your dependency** to the latest major version (as depicted above), as breaking changes may and will happen between major releases._

docs/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ They can also present enough security for authorizing internal services, such as
5858
Install with `pip`:
5959

6060
```bash
61-
pip install "djangorestframework-api-key==2.*"
61+
pip install "djangorestframework-api-key==3.*"
6262
```
6363

6464
!!! important

docs/upgrade/3.0.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Upgrading to 3.0
2+
3+
## Introduction
4+
5+
This document lists the steps necessary to upgrade from 2.x to 3.0.
6+
7+
The full list of changes can be found in the [Changelog](https://github.com/florimondmanca/djangorestframework-api-key/blob/master/CHANGELOG.md).
8+
9+
## Steps
10+
11+
### 1. Upgrade your Python to 3.8+
12+
13+
The 3.0 release drops support for Python 3.7, which has reached EOL in June 2023.
14+
15+
Before upgrading, make sure you are running on Python 3.8 or above.
16+
17+
### 2. Review usage of `.has_object_permission()` on DRF 3.14+ with custom API key models
18+
19+
An implementation of `.has_object_permission()` on `BaseHasAPIKey` that was redundant with `.has_permission()` has been dropped when using Django REST Framework 3.14.0 and above.
20+
21+
If you are using DRF 3.14+ and have custom API key models, you will want to review any implementation of `.has_object_permission()`. Calls to `super().has_object_permission()` will now return `True` (the DRF default) instead of re-validating the API key. This is the desirable thing to do, but you may need some adjustements if you relied on the previous behavior somehow until now.
22+
23+
### 3. Review upgrade of API key hashes following switch to SHA512
24+
25+
This release brings a notable performance improvement by changing the hashing algorithm for API keys.
26+
27+
Hashing API keys used to be done using Django's `PASSWORD_HASHERS`. These hashers are slow by design as they're meant to deal with low-entropy strings such as user passwords. As a result, they typically added 200ms or more on every single request. On the contrary, API keys are long, randomly generated strings of ASCII characters. This means they have a high entropy, so we can get away with hashing them with a simpler — and faster — algorithm.
28+
29+
Consequently, version 3.0 now uses SHA512 for hashing API keys.
30+
31+
Limited testing has shown API key verification should be at least 10x faster on typical CPUs — although greater improvements could be observed.
32+
33+
The hashes of existing API keys will be transparently updated the next time `.is_valid()` is called (i.e. the next time the API key is used).
34+
35+
There shouldn't be any action required on your side, but you may want to test things in a staging environment out of caution.

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ nav:
1515
- User Guide: guide.md
1616
- Security: security.md
1717
- Upgrade Guides:
18+
- "3.0": upgrade/3.0.md
1819
- "2.0": upgrade/2.0.md
1920
- "1.4": upgrade/1.4.md
2021
- "1.0": upgrade/1.0.md

src/rest_framework_api_key/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
if django.VERSION < (3, 2): # pragma: no cover
77
default_app_config = "rest_framework_api_key.apps.RestFrameworkApiKeyConfig"
88

9-
__version__ = "2.3.0"
9+
__version__ = "3.0.0"
1010

1111
__all__ = ["__version__", "default_app_config"]

0 commit comments

Comments
 (0)