-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(middleware)!: release v3 — migrate to Fiber v3, cut /v3 major #131
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
Merged
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
024a909
feat(middleware)!: migrate to Fiber v3, cut /v3 major
rodrigodh 4597cc1
chore(ci): accept GO-2026-5932 (unmaintained x/crypto/openpgp)
rodrigodh c78123e
docs(middleware): drop go get -u from install example
rodrigodh d8b7285
Merge pull request #121 from LerianStudio/feat/fiber-v3
rodrigodh 564e71c
chore(release): 3.0.0-beta.1
lerian-studio e31ac53
feat: real M2M subject and token type whitelist
qnen e79ef7f
Merge pull request #122 from LerianStudio/feat/item-17-dynamic-m2m-role
qnen e7dfa91
chore(release): 3.0.0-beta.2
lerian-studio 93c44db
feat(middleware): forward product on M2M auth (flag-gated)
qnen 2fda16e
Merge pull request #123 from LerianStudio/feat/item-17-m2m-product-fo…
qnen 4cebe96
chore(release): 3.0.0-beta.3
lerian-studio 2034198
feat(middleware): add M2M authentication gate
qnen 5afd305
feat(middleware): add optional issuer pinning to M2M gate
qnen b29e0e1
Merge pull request #125 from LerianStudio/feat/item-17-m2m-auth-middl…
qnen dc3ca0d
chore(release): 3.0.0-beta.4
lerian-studio c48393a
feat(middleware): expose M2M identity via request context
qnen 25fc4ec
fix(middleware): return zero M2MIdentity when reporting absent
qnen 8c25485
Merge pull request #126 from LerianStudio/feat/m2m-identity-context
qnen 9feddbb
chore(release): 3.0.0-beta.5
lerian-studio f7fff6c
feat(middleware): add fail-closed AUTH_REQUIRED option
fredcamaral c0469e6
feat(middleware): add authz cache, circuit breaker, and bounded retry
fredcamaral 7474d61
Merge pull request #127 from LerianStudio/feat/auth-required-fail-clo…
fredcamaral d0b6350
chore(release): 3.0.0-beta.6
lerian-studio 7cbd20b
Merge pull request #129 from LerianStudio/feat/authz-resilience-108
fredcamaral 64dd89c
chore(release): 3.0.0-beta.7
lerian-studio 48b81a3
feat(middleware): add opt-in local JWT signature verification (#128)
fredcamaral 467caac
chore(release): 3.0.0-beta.8
lerian-studio 29c0d68
chore(deps): point to stable lib-observability v2.0.0 and lib-commons…
rodrigodh 279918e
Merge pull request #130 from LerianStudio/chore/bump-stable-deps
rodrigodh 469b81a
chore(release): 3.0.0-beta.9
lerian-studio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # GO-2026-5932: golang.org/x/crypto/openpgp is unmaintained (no upstream fix). | ||
| # Introduced transitively by gofiber/fiber/v3 -> golang.org/x/crypto/acme/autocert. | ||
| # The openpgp package is not imported by this module. Accepted risk. | ||
| # Revisit 2026-07-30. | ||
| GO-2026-5932 exp:2026-07-30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| package middleware | ||
|
|
||
| import ( | ||
| "hash/fnv" | ||
| "sync" | ||
| "time" | ||
| ) | ||
|
|
||
| // decisionCacheShards is the fixed shard count. Sharding spreads lock contention | ||
| // across the authorization hot path so a single mutex is not serialized on every | ||
| // authorized request. Fixed (not configurable) — 16 is ample for the expected | ||
| // concurrency and keeps the type dependency-free. | ||
| const decisionCacheShards = 16 | ||
|
|
||
| // decisionCacheMaxPerShard bounds memory under a burst of distinct subjects. | ||
| // ponytail: soft cap with sweep-on-write + single eviction, not an LRU; the short | ||
| // TTL makes entries self-expire quickly, so this only guards a pathological | ||
| // cardinality spike. Raise it (or swap for an LRU) only if eviction pressure shows | ||
| // up in practice. | ||
| const decisionCacheMaxPerShard = 1024 | ||
|
|
||
| // cacheKey identifies an authorization decision by the inputs that determine it — | ||
| // the exact fields sent to the authz service. It NEVER contains the raw token: two | ||
| // tokens for the same subject must share a decision, and a token must never become | ||
| // a cache key (it would leak into memory keyed by a secret). | ||
| type cacheKey struct { | ||
| sub string | ||
| resource string | ||
| action string | ||
| product string | ||
| } | ||
|
|
||
| // cacheEntry is a cached authorization decision with its expiry. | ||
| type cacheEntry struct { | ||
| authorized bool | ||
| expiresAt time.Time | ||
| } | ||
|
|
||
| type cacheShard struct { | ||
| mu sync.Mutex | ||
| entries map[cacheKey]cacheEntry | ||
| } | ||
|
|
||
| // decisionCache is a bounded, sharded, TTL authorization-decision cache. Expiry is | ||
| // lazy (checked on read, swept on write) so there is no background goroutine to | ||
| // leak. get never returns an expired entry, which is what keeps the breaker-open | ||
| // fallback fail-closed: a stale grant is never served. | ||
| type decisionCache struct { | ||
| ttl time.Duration | ||
| shards [decisionCacheShards]*cacheShard | ||
| } | ||
|
|
||
| // newDecisionCache builds an enabled cache with the given TTL. ttl must be > 0 | ||
| // (callers gate on that before constructing). | ||
| func newDecisionCache(ttl time.Duration) *decisionCache { | ||
| c := &decisionCache{ttl: ttl} | ||
| for i := range c.shards { | ||
| c.shards[i] = &cacheShard{entries: make(map[cacheKey]cacheEntry)} | ||
| } | ||
|
|
||
| return c | ||
| } | ||
|
|
||
| // shardFor selects the shard for a key by hashing its fields with a separator, so | ||
| // distinct field boundaries cannot collide (e.g. {"a","b"} vs {"ab",""}). | ||
| func (c *decisionCache) shardFor(k cacheKey) *cacheShard { | ||
| h := fnv.New32a() | ||
| _, _ = h.Write([]byte(k.sub + "\x00" + k.resource + "\x00" + k.action + "\x00" + k.product)) | ||
|
|
||
| return c.shards[h.Sum32()%decisionCacheShards] | ||
| } | ||
|
|
||
| // get returns the cached decision for k and whether a FRESH entry exists. An | ||
| // expired entry is treated as absent (and evicted); callers therefore never see a | ||
| // stale decision — critical for the breaker-open path, which must not serve | ||
| // expired grants. | ||
| func (c *decisionCache) get(k cacheKey) (authorized, ok bool) { | ||
| shard := c.shardFor(k) | ||
|
|
||
| shard.mu.Lock() | ||
| defer shard.mu.Unlock() | ||
|
|
||
| entry, found := shard.entries[k] | ||
| if !found { | ||
| return false, false | ||
| } | ||
|
|
||
| if time.Now().After(entry.expiresAt) { | ||
| delete(shard.entries, k) | ||
|
|
||
| return false, false | ||
| } | ||
|
|
||
| return entry.authorized, true | ||
| } | ||
|
|
||
| // set stores a decision for k with the cache TTL. When the shard is at its soft | ||
| // cap it first sweeps expired entries and, if still full, evicts a single entry so | ||
| // the cache stays bounded. | ||
| func (c *decisionCache) set(k cacheKey, authorized bool) { | ||
| shard := c.shardFor(k) | ||
|
|
||
| shard.mu.Lock() | ||
| defer shard.mu.Unlock() | ||
|
|
||
| if len(shard.entries) >= decisionCacheMaxPerShard { | ||
| evictShard(shard) | ||
| } | ||
|
|
||
| shard.entries[k] = cacheEntry{authorized: authorized, expiresAt: time.Now().Add(c.ttl)} | ||
| } | ||
|
|
||
| // evictShard drops expired entries; if none were expired it removes one arbitrary | ||
| // entry so an insert can proceed without unbounded growth. Caller holds shard.mu. | ||
| func evictShard(shard *cacheShard) { | ||
| now := time.Now() | ||
| evicted := false | ||
|
|
||
| for key, entry := range shard.entries { | ||
| if now.After(entry.expiresAt) { | ||
| delete(shard.entries, key) | ||
|
|
||
| evicted = true | ||
| } | ||
| } | ||
|
|
||
| if evicted { | ||
| return | ||
| } | ||
|
|
||
| for key := range shard.entries { | ||
| delete(shard.entries, key) | ||
|
|
||
| return | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.