Skip to content

Rate limit device creation by application ID instead of device ID#7756

Merged
nicholaspcr merged 1 commit into
v3.35from
fix/device_count_on_device_creation
Nov 19, 2025
Merged

Rate limit device creation by application ID instead of device ID#7756
nicholaspcr merged 1 commit into
v3.35from
fix/device_count_on_device_creation

Conversation

@nicholaspcr
Copy link
Copy Markdown
Contributor

Previously, CreateEndDeviceRequest was rate-limited per device ID, which was ineffective since each new device has a unique ID. This allowed unlimited device creation attempts per application.

Now rate limiting is applied per application ID, properly restricting the rate of device creation requests at the application level.

Summary

This fixes a reported behavior where the rate-limiter does not work as intented

Changes

  • Update the key used in the rate-limit operation associated with end-device creation

Testing

Steps

Unit tests

Regressions

This is a bug fix

Checklist

  • Scope: The referenced issue is addressed, there are no unrelated changes.
  • Compatibility: The changes are backwards compatible with existing API, storage, configuration and CLI, according to the compatibility commitments in README.md for the chosen target branch.
  • Documentation: Relevant documentation is added or updated.
  • Testing: The steps/process to test this feature are clearly explained including testing for regressions.
  • Infrastructure: If infrastructural changes (e.g., new RPC, configuration) are needed, a separate issue is created in the infrastructural repositories.
  • Changelog: Significant features, behavior changes, deprecations and fixes are added to CHANGELOG.md.
  • Commits: Commit messages follow guidelines in CONTRIBUTING.md, there are no fixup commits left.

@nicholaspcr nicholaspcr added this to the v3.35.1 milestone Nov 12, 2025
@nicholaspcr nicholaspcr self-assigned this Nov 12, 2025
@nicholaspcr nicholaspcr requested a review from a team as a code owner November 12, 2025 21:04
@nicholaspcr nicholaspcr added the bug Something isn't working label Nov 12, 2025
Copy link
Copy Markdown
Member

@happyRip happyRip left a comment

Choose a reason for hiding this comment

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

LGTM, but fix linter issues.

@nicholaspcr nicholaspcr force-pushed the fix/device_count_on_device_creation branch from 66dd310 to 15b9b2d Compare November 18, 2025 21:36
@nicholaspcr nicholaspcr requested a review from happyRip November 18, 2025 21:37
@nicholaspcr
Copy link
Copy Markdown
Contributor Author

nicholaspcr commented Nov 18, 2025

@happyRip I ended up looking for other places where this could happen. As far as I know only requests that implement the IDString interface have this problem.

I ended up updating these requests to use the Collaborator as part of the key, so the limit is applied in a per collaborator basis.

I ended up using only the full-method and the auth-token as a key.

key := fmt.Sprintf("grpc:method:%s:%s", fullMethod, grpcEntityFromRequest(ctx, req))
if authTokenID := authTokenID(ctx); authTokenID != unauthenticated {
key = fmt.Sprintf("%s:token:%s", key, authTokenID)
}
return &resource{
key: key,
classes: []string{fmt.Sprintf("grpc:method:%s", fullMethod), "grpc:method"},
}

This means that on creation, grpcEntityFromRequest returns an empty string.

@nicholaspcr nicholaspcr force-pushed the fix/device_count_on_device_creation branch from 15b9b2d to 66173e6 Compare November 18, 2025 22:33
Previously, Create<Entity>Request was rate-limited per the entityID
generated by the IDString interface, which was ineffective since each
new entity has an unique ID. This allowed unlimited device creation
attempts.

Now rate limiting is applied withou the entityID, properly restricting
create requests using full-method and auth-token strings as key.
@nicholaspcr nicholaspcr force-pushed the fix/device_count_on_device_creation branch from 66173e6 to 419720f Compare November 19, 2025 10:03
@nicholaspcr nicholaspcr merged commit be8f5c7 into v3.35 Nov 19, 2025
13 checks passed
@nicholaspcr nicholaspcr deleted the fix/device_count_on_device_creation branch November 19, 2025 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants