Skip to content

Commit 1af08db

Browse files
Correlation ID for Unified Request Tracking (#1443)
* Add correlation ID system for unified request tracking Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * replace undefined bearer_scheme with security Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * lint & test fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fixes for lint Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * pylint fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * test fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * Bandit fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fix for test Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * addiitonal changes for UI & middleware Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fix bug Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * dropdown mismatch fix Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fixes for UI Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * UI fixes for adding user details Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * admin ui fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * flake8 fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * test fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * lint fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fix for doctest Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * auth issue fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * update for failing tests Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * flake8 fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * flake8 issue Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * prevent SQLite rollback error on validation failures Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * false positive issues Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fix lint issue Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * update alembic file Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * updated alembic revision Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * changes in table schema Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * gateway service fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * updated tests Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fix doctest coverage Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fix: resolve rebase conflicts and fix test issues for correlation ID PR - Fix Alembic migration to chain after main branch head (356a2d4eed6f) - Fix is_active/enabled attribute access in services (server, prompt, resource, export) - Update export_service to use getattr with fallback for backwards compatibility - Add db.refresh before return in tool_service.register_tool to handle session expiry after audit/logging commits - Add SessionLocal patches in conftest.py for audit_trail_service and log_aggregator - Update test assertions for expected db.refresh call count - Apply isort import ordering fixes across service files Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * Linting Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix: ensure cross-database compatibility for migrations and update tag fuzz test - Use sa.false() instead of string literals for Boolean server_defaults in migration (SQLite uses 0/1, not "false"/"true") - Use sa.text("'{}'") for JSON server_defaults to ensure proper quoting - Update fuzz test to expect dict tags format {id, label} instead of strings Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Shoumi <shoumimukherjee@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
1 parent 89be0e9 commit 1af08db

File tree

65 files changed

+8955
-422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+8955
-422
lines changed

.env.example

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ SECURITY_HEADERS_ENABLED=true
537537
# null or none: Completely removes iframe restrictions (no headers sent)
538538
# ALLOW-FROM uri: Allows specific domain (deprecated, use CSP instead)
539539
# ALLOW-ALL uri: Allows all (*, http, https)
540-
#
540+
#
541541
# Both X-Frame-Options header and CSP frame-ancestors directive are automatically synced.
542542
# Modern browsers prioritize CSP frame-ancestors over X-Frame-Options.
543543
X_FRAME_OPTIONS=DENY
@@ -659,6 +659,17 @@ LOG_MAX_SIZE_MB=1
659659
LOG_BACKUP_COUNT=5
660660
LOG_BUFFER_SIZE_MB=1.0
661661

662+
# Correlation ID / Request Tracking
663+
# Enable automatic correlation ID tracking for unified request tracing
664+
# Options: true (default), false
665+
CORRELATION_ID_ENABLED=true
666+
# HTTP header name for correlation ID (default: X-Correlation-ID)
667+
CORRELATION_ID_HEADER=X-Correlation-ID
668+
# Preserve incoming correlation IDs from clients (default: true)
669+
CORRELATION_ID_PRESERVE=true
670+
# Include correlation ID in HTTP response headers (default: true)
671+
CORRELATION_ID_RESPONSE_HEADER=true
672+
662673
# Transport Protocol Configuration
663674
# Options: all (default), sse, streamablehttp, http
664675
# - all: Enable all transport protocols
@@ -1193,6 +1204,16 @@ PAGINATION_INCLUDE_LINKS=true
11931204
# Enable TLS for gRPC connections by default
11941205
# MCPGATEWAY_GRPC_TLS_ENABLED=false
11951206

1207+
#####################################
1208+
# Security Event Logging
1209+
#####################################
1210+
1211+
# Enable security event logging (authentication attempts, authorization failures, etc.)
1212+
# Options: true (default), false
1213+
# When enabled, the AuthContextMiddleware will log all authentication attempts to the database
1214+
# This is INDEPENDENT of observability settings - security logging is critical for audit trails
1215+
# SECURITY_LOGGING_ENABLED=true
1216+
11961217
#####################################
11971218
# Observability Settings
11981219
#####################################

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ ContextForge implements **OAuth 2.0 Dynamic Client Registration (RFC 7591)** and
16191619
>
16201620
> **iframe Embedding**: The gateway controls iframe embedding through both `X-Frame-Options` header and CSP `frame-ancestors` directive (both are automatically synced). Options:
16211621
> - `X_FRAME_OPTIONS=DENY` (default): Blocks all iframe embedding
1622-
> - `X_FRAME_OPTIONS=SAMEORIGIN`: Allows embedding from same domain only
1622+
> - `X_FRAME_OPTIONS=SAMEORIGIN`: Allows embedding from same domain only
16231623
> - `X_FRAME_OPTIONS="ALLOW-ALL"`: Allows embedding from all sources (sets `frame-ancestors * file: http: https:`)
16241624
> - `X_FRAME_OPTIONS=null` or `none`: Completely removes iframe restrictions (no headers sent)
16251625
>

docs/docs/deployment/container.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ docker logs mcpgateway
3131
You can now access the UI at [http://localhost:4444/admin](http://localhost:4444/admin)
3232

3333
### Multi-architecture containers
34-
Note: the container build process creates container images for 'amd64', 'arm64' and 's390x' architectures. The version `ghcr.io/ibm/mcp-context-forge:VERSION`
34+
Note: the container build process creates container images for 'amd64', 'arm64' and 's390x' architectures. The version `ghcr.io/ibm/mcp-context-forge:VERSION`
3535
not points to a manifest so that if all commands will pull the correct image for the architecture being used (whether that be locally or on Kubernetes or OpenShift).
3636

3737
If the specific image is needed for one architecture on a different architecture use the appropriate arguments for your given container execution tool:
3838

39-
With docker run:
39+
With docker run:
4040
```
4141
docker run [... all your options...] --platform linux/arm64 ghcr.io/ibm/mcp-context-forge:VERSION
4242
```

gunicorn.config.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,37 +65,37 @@
6565

6666
def on_starting(server):
6767
"""Called just before the master process is initialized.
68-
68+
6969
This is where we handle passphrase-protected SSL keys by decrypting
7070
them to a temporary file before Gunicorn workers start.
7171
"""
7272
global _prepared_key_file
73-
73+
7474
# Check if SSL is enabled via environment variable (set by run-gunicorn.sh)
7575
# and a passphrase is provided
7676
ssl_enabled = os.environ.get("SSL", "false").lower() == "true"
7777
ssl_key_password = os.environ.get("SSL_KEY_PASSWORD")
78-
78+
7979
if ssl_enabled and ssl_key_password:
8080
try:
8181
from mcpgateway.utils.ssl_key_manager import prepare_ssl_key
82-
82+
8383
# Get the key file path from environment (set by run-gunicorn.sh)
8484
key_file = os.environ.get("KEY_FILE", "certs/key.pem")
85-
85+
8686
server.log.info(f"Preparing passphrase-protected SSL key: {key_file}")
87-
87+
8888
# Decrypt the key and get the temporary file path
8989
_prepared_key_file = prepare_ssl_key(key_file, ssl_key_password)
90-
90+
9191
server.log.info(f"SSL key prepared successfully: {_prepared_key_file}")
92-
92+
9393
# Update the keyfile setting to use the decrypted temporary file
9494
# This is a bit of a hack, but Gunicorn doesn't provide a better way
9595
# to modify the keyfile after it's been set via command line
9696
if hasattr(server, 'cfg'):
9797
server.cfg.set('keyfile', _prepared_key_file)
98-
98+
9999
except Exception as e:
100100
server.log.error(f"Failed to prepare SSL key: {e}")
101101
raise
@@ -127,4 +127,3 @@ def worker_exit(server, worker):
127127

128128
def child_exit(server, worker):
129129
server.log.info("Worker child exit (pid: %s)", worker.pid)
130-

0 commit comments

Comments
 (0)