-
Notifications
You must be signed in to change notification settings - Fork 2
Add in-memory IAM introspection and JWKS cache #532
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
Merged
Changes from all commits
Commits
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
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,10 @@ | ||
| { | ||
| "public_listen_address": "127.0.0.1:11110", | ||
| "internal_listen_address": "127.0.0.1:11111", | ||
| "core_url": "http://127.0.0.1:11010", | ||
| "request_timeout": "5s", | ||
| "introspection_cache_ttl": "15s", | ||
| "introspection_cache_max_entries": 100000, | ||
| "jwks_cache_ttl": "1m", | ||
| "jwks_cache_max_entries": 1000 | ||
| } |
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,13 @@ | ||
| [Unit] | ||
| Description=Exordos IAM Cache Service | ||
| After=network-online.target ec-user-api.service | ||
|
|
||
| [Service] | ||
| TimeoutStopSec=10 | ||
| Restart=always | ||
| RestartSec=5s | ||
| KillSignal=SIGINT | ||
| ExecStart=/usr/bin/exordos-iam-cache -config /etc/exordos_core/iam_cache.json | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target |
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
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,53 @@ | ||
| # Exordos IAM Cache | ||
|
|
||
| `exordos-iam-cache` is an in-memory caching proxy for the Exordos Core IAM | ||
| introspection and JWKS endpoints. | ||
|
|
||
| The public listener preserves the existing Core routes: | ||
|
|
||
| - `GET /v1/iam/clients/{client_uuid}/actions/introspect` | ||
| - `GET /v1/iam/clients/{client_uuid}/actions/jwks` | ||
|
|
||
| All other IAM client requests are forwarded unchanged to Core and are never | ||
| cached. Any request carrying `X-OTP`, including a token request, also bypasses | ||
| the cache. Successful introspection responses without `X-OTP` are cached by | ||
| access token. The token UUID is read from the validated access token's `jti` | ||
| claim and is used by the reverse index. | ||
|
|
||
| The internal listener exposes an idempotent invalidation endpoint: | ||
|
|
||
| ```text | ||
| DELETE /internal/v1/cache/introspection/{token_uuid} | ||
| ``` | ||
|
|
||
| Core does not call this endpoint in the first implementation. Until that | ||
| integration is added, introspection entries expire only by their configured | ||
| TTL, the access token expiration, or capacity eviction. | ||
|
|
||
| JWKS responses use a separate cache keyed by IAM client UUID and a separate | ||
| TTL. | ||
|
|
||
| ## Configuration | ||
|
|
||
| The deployment example is | ||
| [`../../etc/exordos_core/iam_cache.json.example`](../../etc/exordos_core/iam_cache.json.example). | ||
| Cache lifetimes and the upstream request timeout use Go duration syntax such | ||
| as `15s`, `5m`, or `1h`. The deployed defaults are 15 seconds for | ||
| introspection and one minute for JWKS. | ||
|
|
||
| The internal listener defaults to loopback. If it is exposed outside the host, | ||
| protect it with the deployment's service-to-service authentication layer. | ||
|
|
||
| ## Run | ||
|
|
||
| ```bash | ||
| go run ./cmd/exordos-iam-cache \ | ||
| -config ../../etc/exordos_core/iam_cache.json.example | ||
| ``` | ||
|
|
||
| ## Test | ||
|
|
||
| ```bash | ||
| go test -race ./... | ||
| go vet ./... | ||
| ``` |
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,115 @@ | ||
| // Copyright 2026 Genesis Corporation | ||
| // | ||
| // All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
| // not use this file except in compliance with the License. You may obtain | ||
| // a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| // License for the specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "flag" | ||
| "fmt" | ||
| "log" | ||
| "net/http" | ||
| "os" | ||
| "os/signal" | ||
| "syscall" | ||
| "time" | ||
|
|
||
| "github.com/exordos/exordos_core/services/iam-cache/internal/app" | ||
| ) | ||
|
|
||
| func main() { | ||
| if err := run(); err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| } | ||
|
|
||
| func run() error { | ||
| configPath := flag.String( | ||
| "config", | ||
| "/etc/exordos_core/iam_cache.json", | ||
| "path to the JSON configuration file", | ||
| ) | ||
| flag.Parse() | ||
|
|
||
| config, err := app.LoadConfig(*configPath) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| proxy := app.NewProxy(config) | ||
|
|
||
| publicServer := newHTTPServer( | ||
| config.PublicListenAddress, | ||
| proxy.PublicHandler(), | ||
| ) | ||
| internalServer := newHTTPServer( | ||
| config.InternalListenAddress, | ||
| proxy.InternalHandler(), | ||
| ) | ||
|
|
||
| runContext, stop := signal.NotifyContext( | ||
| context.Background(), | ||
| syscall.SIGINT, | ||
| syscall.SIGTERM, | ||
| ) | ||
| defer stop() | ||
|
|
||
| serverErrors := make(chan error, 2) | ||
| startServer("public", publicServer, serverErrors) | ||
| startServer("internal", internalServer, serverErrors) | ||
|
|
||
| var runErr error | ||
| select { | ||
| case <-runContext.Done(): | ||
| case runErr = <-serverErrors: | ||
| stop() | ||
| } | ||
|
|
||
| shutdownContext, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
| defer cancel() | ||
|
|
||
| publicErr := publicServer.Shutdown(shutdownContext) | ||
| internalErr := internalServer.Shutdown(shutdownContext) | ||
| return errors.Join(runErr, publicErr, internalErr) | ||
| } | ||
|
|
||
| func newHTTPServer(address string, handler http.Handler) *http.Server { | ||
| return &http.Server{ | ||
| Addr: address, | ||
| Handler: handler, | ||
| ReadHeaderTimeout: 5 * time.Second, | ||
| IdleTimeout: 60 * time.Second, | ||
| } | ||
| } | ||
|
|
||
| func startServer( | ||
| name string, | ||
| server *http.Server, | ||
| errorsChannel chan<- error, | ||
| ) { | ||
| go func() { | ||
| log.Printf("%s listener started on %s", name, server.Addr) | ||
| err := server.ListenAndServe() | ||
| if err != nil && !errors.Is(err, http.ErrServerClosed) { | ||
| errorsChannel <- fmt.Errorf("%s listener: %w", name, err) | ||
| } | ||
| }() | ||
| } | ||
|
|
||
| func init() { | ||
| log.SetOutput(os.Stderr) | ||
| log.SetFlags(log.Ldate | log.Ltime | log.LUTC) | ||
| } |
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,3 @@ | ||
| module github.com/exordos/exordos_core/services/iam-cache | ||
|
|
||
| go 1.23.0 |
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.