diff --git a/src/oracle-db-mcp-java-toolkit/README.md b/src/oracle-db-mcp-java-toolkit/README.md index 2f84d6548..735945821 100644 --- a/src/oracle-db-mcp-java-toolkit/README.md +++ b/src/oracle-db-mcp-java-toolkit/README.md @@ -98,6 +98,46 @@ To enable YAML configuration, launch the server with: java -DconfigFile=/path/to/config.yaml -jar .jar ``` +### Runtime configuration in a separate YAML file + +Keep `configFile` for `dataSources`, custom `tools`, and `toolsets`. Put deployment settings that +would otherwise be JVM system properties in a separate runtime file selected with +`-DruntimeConfigFile`: + +```yaml +network: + transport: "http" + http: + allowedOriginalHosts: "mcp.example.com" + https: + port: "45451" + certificatePath: "/run/secrets/server.p12" + certificatePassword: "${CERTIFICATE_PASSWORD}" +database: + url: "jdbc:oracle:thin:@//db.example.com:1521/ORCLPDB1" + user: "${DB_USER}" + password: "${DB_PASSWORD}" +userAuth: + enabled: "true" +``` + +Start with both files when custom tools or datasource definitions are needed: + +```bash +java \ + -DruntimeConfigFile=/path/to/runtime-config.yaml \ + -DconfigFile=/path/to/config.yaml \ + -jar .jar +``` + +`runtimeConfigFile` and `configFile` are bootstrap properties and remain on the command line. A +non-blank `-D` property overrides the matching YAML value. Use the same canonical names in both +places: for example, `database.url` and `network.https.port`. Existing property names such as +`db.url` and `https.port` remain supported as compatibility aliases. When both forms are supplied, +the canonical property wins. Runtime YAML is resolved by the toolkit and is not written into JVM +system properties. See [`runtime-config.example.yaml`](runtime-config.example.yaml) for all +supported runtime settings. + Toolsets can be enabled from `-Dtools` alongside individual tools. For example: - `-Dtools=reporting` enables all tools in the `reporting` toolset - `-Dtools=reporting,explain` enables your `reporting` set plus the built-in `explain` toolset (see below) @@ -469,7 +509,7 @@ _Note: The `mcp-admin` toolset is focused on protected runtime configuration and - Requirements and behavior: - Must be explicitly enabled with `-Dtools=list-credentials` or `-Dtools=mcp-admin`. - When HTTP authentication is enabled, requires OAuth scope `mcp:credentials:read` or `mcp:admin`. - - To allow any authenticated caller to use `list-credentials` without scope enforcement, set `-DlistCredentials.requireScope=false`. + - Set `toolAuthorization.listCredentials.requireScope: false` only when every authenticated caller should be allowed to list credential metadata. - `edit-tools`: Create, update, or remove a YAML-defined tool. Changes are auto-reloaded by the server. - Inputs (subset; see schema in code): @@ -484,7 +524,7 @@ _Note: The `mcp-admin` toolset is focused on protected runtime configuration and - Must be explicitly enabled with `-Dtools=edit-tools` or `-Dtools=mcp-admin`. - Requires `-DconfigFile` to be set to a writable YAML file; otherwise the tool will return an error. - When HTTP authentication is enabled, requires OAuth scope `mcp:tools:write` or `mcp:admin`. - - To allow any authenticated caller to use `edit-tools` without scope enforcement, set `-DeditTools.requireScope=false`. + - Set `toolAuthorization.editTools.requireScope: false` only when every authenticated caller should be allowed to edit tools. - OAuth scope lookup defaults to the `scope` claim in the introspection response. If your authorization server uses a different claim, configure its dot-separated path with `-Doauth.scopeClaimPath=`. - Tool names must be safe and cannot collide with built-in tools or toolsets. - For `edit-tools` changes, `dataSource` is required, must exist under `dataSources:`, and must be in `admin.editTools.allowedDataSources` when that allowlist is configured. @@ -590,7 +630,7 @@ For local development only, an unauthenticated server can be started with `-Dhtt -Dhttp.allowedOriginalHosts=mcp.example.com ``` -Use a reverse proxy or firewall appropriate for your deployment. `allowedHosts` is a separate CORS setting for OAuth discovery metadata; it does not control MCP request admission. +Use a reverse proxy or firewall appropriate for your deployment. `network.cors.allowedOrigin` is a separate CORS setting for OAuth discovery metadata; it does not control MCP request admission. The legacy `allowedHosts` name remains supported. ##### Enabling HTTPS (SSL/TLS) @@ -680,7 +720,7 @@ In order to configure an OAuth2 server, enable `-Dauth.enabled=true` alongside t * `-Dauth.userTokenValidation.jwt.jwksCacheSeconds`: Optional JWKS cache duration in seconds when `auth.userTokenValidation.mode=jwt` (default: `600`). * `-Dauth.userTokenValidation.introspection.clientId`: Client ID used for introspection (e.g. `oracle-db-toolkit`). * `-Dauth.userTokenValidation.introspection.clientSecret`: Client secret used for introspection. -* `-DallowedHosts`: (default: `*`) The value of `Access-Control-Allow-Origin` header when requesting the `/.well-known/oauth-protected-resource` endpoint (and `/.well-known/oauth-authorization-server` if `-Dauth.openIdDiscoveryRedirectEnabled=true`) of the MCP Server. +* `-Dnetwork.cors.allowedOrigin`: (default: `*`) The value of the `Access-Control-Allow-Origin` header for the `/.well-known/oauth-protected-resource` endpoint (and `/.well-known/oauth-authorization-server` when enabled). The legacy `-DallowedHosts` alias remains supported. ##### MCP login scopes vs DeepSec database scopes @@ -707,7 +747,7 @@ java \ -Dauth.userTokenValidation.introspection.endpoint=http://localhost:8080/realms/mcp/protocol/openid-connect/token/introspect \ -Dauth.userTokenValidation.introspection.clientId=oracle-db-toolkit \ -Dauth.userTokenValidation.introspection.clientSecret=Xj9mPqR2vL5kN8tY3hB7wF4uD6cA1eZ0 \ - -DallowedHosts=http://localhost:6274 \ + -Dnetwork.cors.allowedOrigin=http://localhost:6274 \ -jar /oracle-db-mcp-toolkit-1.0.0.jar ``` @@ -756,8 +796,6 @@ Required properties: * `-Ddeepsec.databaseToken.clientId`: Client ID used to obtain the database-scoped DeepSec token. * `-Ddeepsec.databaseToken.clientSecret`: Client secret used to obtain the database-scoped DeepSec token. * `-Ddeepsec.databaseToken.scope`: Database resource scope for the DeepSec/database token, for example `OracleDBDB_ACCESS_SCOPE`. -* `-Doracle.ucp.createConnectionInBorrowThread=true`: Ensures UCP creates a new physical connection in the request thread that is borrowing it, so the current DeepSec context is available during connection creation. - Optional properties: * `-Ddeepsec.databaseToken.staticValue`: Static database-scoped token for local smoke tests. Prefer `deepsec.databaseToken.tokenEndpoint` plus client credentials for normal use. @@ -795,7 +833,6 @@ java \ -Ddb.url='jdbc:oracle:thin:@mydb_high?TNS_ADMIN=/path/to/wallet' \ -Ddb.user=mcp_app_user \ -Ddb.password='your-db-password' \ - -Doracle.ucp.createConnectionInBorrowThread=true \ -Dtransport=http \ -Dhttps.port=8080 \ -DcertificatePath=/path/to/your-certificate.p12 \ @@ -1018,6 +1055,12 @@ Ultimately, the token must be included in the http request header (e.g. `Authori Path to a YAML file defining datasources and tools. Required if you intend to use the edit-tools admin tool to persist changes. /opt/mcp/config.yaml + + runtimeConfigFile + No + Path to a separate YAML file containing nested runtime settings. Individual JVM properties override its values. + /opt/mcp/runtime-config.yaml + auth.enabled No @@ -1056,22 +1099,22 @@ Ultimately, the token must be included in the http request header (e.g. `Authori -Doauth.scopeClaimPath=scope - editTools.requireScope + toolAuthorization.editTools.requireScope No - Whether edit-tools requires OAuth scope mcp:tools:write or mcp:admin when HTTP authentication is enabled. Defaults to true. Set to false only when any authenticated caller should be allowed to use edit-tools. - -DeditTools.requireScope=false + Whether edit-tools requires OAuth scope mcp:tools:write or mcp:admin when HTTP authentication is enabled. Defaults to true. Set to false only when any authenticated caller should be allowed to edit tools. The legacy editTools.requireScope name remains supported. + -DtoolAuthorization.editTools.requireScope=false - listCredentials.requireScope + toolAuthorization.listCredentials.requireScope No - Whether list-credentials requires OAuth scope mcp:credentials:read or mcp:admin when HTTP authentication is enabled. Defaults to true. Set to false only when any authenticated caller should be allowed to list credential metadata. - -DlistCredentials.requireScope=false + Whether list-credentials requires OAuth scope mcp:credentials:read or mcp:admin when HTTP authentication is enabled. Defaults to true. Set to false only when any authenticated caller should be allowed to list credential metadata. The legacy listCredentials.requireScope name remains supported. + -DtoolAuthorization.listCredentials.requireScope=false - allowedHosts + network.cors.allowedOrigin No - The Access-Control-Allow-Origin header value when making a request to the MCP Server's /.well-known/oauth-protected-resource endpoint (default * e.g. all hosts are allowed). - -DallowedHosts=http://localhost:6274 + The Access-Control-Allow-Origin header value for OAuth discovery endpoints (default *). The legacy allowedHosts name remains supported. + -Dnetwork.cors.allowedOrigin=http://localhost:6274 auth.openIdDiscoveryRedirectEnabled diff --git a/src/oracle-db-mcp-java-toolkit/runtime-config.example.yaml b/src/oracle-db-mcp-java-toolkit/runtime-config.example.yaml new file mode 100644 index 000000000..b9cf542f1 --- /dev/null +++ b/src/oracle-db-mcp-java-toolkit/runtime-config.example.yaml @@ -0,0 +1,66 @@ +# Start with: java -DruntimeConfigFile=/path/to/runtime-config.yaml -jar oracle-db-mcp-toolkit.jar +# Any non-blank -D property overrides the matching YAML setting below. +# Keep this deployment-specific file out of source control and provide secrets through environment variables. +network: + transport: "http" + http: + # Set this explicitly for production HTTP deployments. + allowedOriginalHosts: "mcp.example.com" + cors: + allowedOrigin: "*" + https: + port: "45451" + certificatePath: "/path/to/certificate.p12" + certificatePassword: "${CERTIFICATE_PASSWORD}" + +toolSelection: + enabled: "read-query,write-query" +dataIngestion: + rootDirectory: "/data/ingest" + maxFileSizeMb: "100" +database: + url: "jdbc:oracle:thin:@tcps://db.example.com:1521/ORCLPDB1" + user: "${DB_USER}" + password: "${DB_PASSWORD}" + transactions: + idleTimeoutSeconds: "120" + maxLifetimeSeconds: "300" + maxPerUser: "4" + jdbc: + extensionsDirectory: "/opt/oracle/extensions" + +userAuth: + openIdDiscoveryRedirectEnabled: "false" + enabled: "true" + authorizationServer: "https://identity.example.com/tenant-id" + tokenValidation: + mode: "jwt" + introspection: + endpoint: "https://identity.example.com/introspect" + clientId: "${INTROSPECTION_CLIENT_ID}" + clientSecret: "${INTROSPECTION_CLIENT_SECRET}" + jwt: + issuer: "https://identity.example.com/tenant-id/" + jwksUri: "https://identity.example.com/tenant-id/discovery/keys" + audience: "api://mcp-server" + jwksCacheSeconds: "600" + +toolAuthorization: + editTools: + requireScope: "true" + listCredentials: + requireScope: "true" +mcp: + oauth: + scopes: "openid" + resourceUrl: "https://mcp.example.com/mcp" + +deepDataSecurity: + enabled: "false" + # Set staticValue instead of the endpoint/client credentials when a database token is supplied directly. + databaseToken: + staticValue: "${DEEPSEC_DATABASE_TOKEN}" + tokenEndpoint: "https://identity.example.com/tenant-id/oauth2/v2.0/token" + clientId: "${DATABASE_TOKEN_CLIENT_ID}" + clientSecret: "${DATABASE_TOKEN_CLIENT_SECRET}" + scope: "api://database/.default" diff --git a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/LoadedConstants.java b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/LoadedConstants.java index 5384078fc..86d961a77 100644 --- a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/LoadedConstants.java +++ b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/LoadedConstants.java @@ -7,95 +7,166 @@ package com.oracle.database.mcptoolkit; -/** - * Provides a set of constants loaded from system properties and environment variables. - * These constants are used to configure various aspects of the application, including - * network settings, tool configurations, OAuth settings, and more. - * - *

This class is not intended to be instantiated and provides only static constants. - */ +import com.oracle.database.mcptoolkit.config.RuntimeConfigRoot; +import com.oracle.database.mcptoolkit.config.RuntimePropertyNames; +import java.util.LinkedHashMap; +import java.util.Map; + +/** Provides runtime settings loaded from system properties and an optional YAML file. */ public final class LoadedConstants { - private LoadedConstants() {} // Prevent instantiation - - /** Network config */ - public static final String TRANSPORT_KIND = System.getProperty("transport", "stdio") - .trim() - .toLowerCase(); - public static final String HTTPS_PORT = System.getProperty("https.port"); - public static final String KEYSTORE_PATH = System.getProperty("certificatePath"); - public static final String KEYSTORE_PASSWORD = System.getProperty("certificatePassword"); - public static final String HTTP_ALLOWED_ORIGINAL_HOSTS = System.getProperty("http.allowedOriginalHosts"); - public static final boolean HTTP_ALLOW_UNAUTHENTICATED_FOR_DEVELOPMENT = Boolean.parseBoolean( - System.getProperty("http.allowUnauthenticatedForDevelopment", "false")); - - /** Tools config */ - public static final String TOOLS = System.getProperty("tools"); - public static final String INGEST_ROOT_DIR = System.getProperty("ingestRootDir"); - public static final String INGEST_MAX_FILE_SIZE_MB = System.getProperty("ingestMaxFileSizeMb"); - public static final String DB_URL = System.getProperty("db.url"); - public static final String DB_USER = System.getProperty("db.user"); - public static final char[] DB_PASSWORD = System.getProperty("db.password") != null - ? System.getProperty("db.password").toCharArray() - : null; - public static final int DB_TRANSACTION_IDLE_TIMEOUT_SECONDS = - Integer.parseInt(System.getProperty("db.transactionIdleTimeoutSeconds", "120")); - public static final int DB_TRANSACTION_MAX_LIFETIME_SECONDS = - Integer.parseInt(System.getProperty("db.transactionMaxLifetimeSeconds", "300")); - public static final int DB_MAX_TRANSACTIONS_PER_USER = - Integer.parseInt(System.getProperty("db.maxTransactionsPerUser", "4")); - - /** OAuth config */ - public static final String ALLOWED_HOSTS= System.getProperty("allowedHosts","*"); - public static final String AUTH_OPENID_DISCOVERY_REDIRECT_ENABLED = - System.getProperty("auth.openIdDiscoveryRedirectEnabled", "false"); - public static final boolean AUTH_ENABLED = Boolean.parseBoolean(System.getProperty("auth.enabled", "false")); - public static final String ORACLE_DB_TOOLKIT_AUTH_TOKEN = System.getenv("ORACLE_DB_TOOLKIT_AUTH_TOKEN"); - public static final String AUTH_AUTHORIZATION_SERVER = System.getProperty("auth.authorizationServer"); - public static final String USER_TOKEN_INTROSPECTION_ENDPOINT = - System.getProperty("auth.userTokenValidation.introspection.endpoint"); - public static final String USER_TOKEN_INTROSPECTION_CLIENT_ID = - System.getProperty("auth.userTokenValidation.introspection.clientId"); - public static final String USER_TOKEN_INTROSPECTION_CLIENT_SECRET = - System.getProperty("auth.userTokenValidation.introspection.clientSecret"); - public static final String OAUTH_SCOPE_CLAIM_PATH = System.getProperty("oauth.scopeClaimPath", "scope"); - public static final boolean EDIT_TOOLS_REQUIRE_SCOPE = Boolean.parseBoolean( - System.getProperty("editTools.requireScope", "true")); - public static final boolean LIST_CREDENTIALS_REQUIRE_SCOPE = Boolean.parseBoolean( - System.getProperty("listCredentials.requireScope", "true")); - public static final String USER_TOKEN_VALIDATION_MODE = - System.getProperty("auth.userTokenValidation.mode", "introspection") - .trim() - .toLowerCase(); - public static final String USER_TOKEN_JWT_ISSUER = - System.getProperty("auth.userTokenValidation.jwt.issuer"); - public static final String USER_TOKEN_JWT_JWKS_URI = - System.getProperty("auth.userTokenValidation.jwt.jwksUri"); - public static final String USER_TOKEN_JWT_AUDIENCE = - System.getProperty("auth.userTokenValidation.jwt.audience"); - public static final long USER_TOKEN_JWT_JWKS_CACHE_SECONDS = Long.parseLong( - System.getProperty("auth.userTokenValidation.jwt.jwksCacheSeconds", "600")); - - /** MCP OAuth discovery config */ - public static final String MCP_OAUTH_SCOPES = System.getProperty("mcp.oauth.scopes", "openid"); - public static final String MCP_OAUTH_RESOURCE_URL = System.getProperty("mcp.oauth.resourceUrl"); - - /** Deep Data Security config */ - public static final boolean DEEPSEC_ENABLED = Boolean.parseBoolean(System.getProperty("deepsec.enabled", "false")); - public static final String DEEPSEC_DATABASE_TOKEN_STATIC_VALUE = - System.getProperty("deepsec.databaseToken.staticValue"); - public static final String DEEPSEC_DATABASE_TOKEN_ENDPOINT = - System.getProperty("deepsec.databaseToken.tokenEndpoint"); - public static final String DEEPSEC_DATABASE_TOKEN_CLIENT_ID = - System.getProperty("deepsec.databaseToken.clientId"); - public static final String DEEPSEC_DATABASE_TOKEN_CLIENT_SECRET = - System.getProperty("deepsec.databaseToken.clientSecret"); - public static final String DEEPSEC_DATABASE_TOKEN_SCOPE = - System.getProperty("deepsec.databaseToken.scope"); - - /** Yaml config */ + private LoadedConstants() {} + + /** Identifies the existing YAML file for datasources and custom tools. */ public static final String CONFIG_FILE = System.getProperty("configFile"); + /** Identifies the optional YAML file containing runtime settings. */ + public static final String RUNTIME_CONFIG_FILE = System.getProperty("runtimeConfigFile"); + + /** Network config. */ + public static String TRANSPORT_KIND; + public static String HTTPS_PORT; + public static String KEYSTORE_PATH; + public static String KEYSTORE_PASSWORD; + public static String HTTP_ALLOWED_ORIGINAL_HOSTS; + public static boolean HTTP_ALLOW_UNAUTHENTICATED_FOR_DEVELOPMENT; + + /** Tools and database config. */ + public static String TOOLS; + public static String INGEST_ROOT_DIR; + public static String INGEST_MAX_FILE_SIZE_MB; + public static String DB_URL; + public static String DB_USER; + public static char[] DB_PASSWORD; + public static int DB_TRANSACTION_IDLE_TIMEOUT_SECONDS; + public static int DB_TRANSACTION_MAX_LIFETIME_SECONDS; + public static int DB_MAX_TRANSACTIONS_PER_USER; + + /** User authentication and OAuth discovery config. */ + public static String CORS_ALLOWED_ORIGIN; + public static String AUTH_OPENID_DISCOVERY_REDIRECT_ENABLED; + public static boolean AUTH_ENABLED; + public static final String ORACLE_DB_TOOLKIT_AUTH_TOKEN = System.getenv("ORACLE_DB_TOOLKIT_AUTH_TOKEN"); + public static String AUTH_AUTHORIZATION_SERVER; + public static String USER_TOKEN_INTROSPECTION_ENDPOINT; + public static String USER_TOKEN_INTROSPECTION_CLIENT_ID; + public static String USER_TOKEN_INTROSPECTION_CLIENT_SECRET; + public static String OAUTH_SCOPE_CLAIM_PATH; + public static boolean EDIT_TOOLS_REQUIRE_SCOPE; + public static boolean LIST_CREDENTIALS_REQUIRE_SCOPE; + public static String USER_TOKEN_VALIDATION_MODE; + public static String USER_TOKEN_JWT_ISSUER; + public static String USER_TOKEN_JWT_JWKS_URI; + public static String USER_TOKEN_JWT_AUDIENCE; + public static long USER_TOKEN_JWT_JWKS_CACHE_SECONDS; + + /** MCP OAuth discovery config. */ + public static String MCP_OAUTH_SCOPES; + public static String MCP_OAUTH_RESOURCE_URL; + + /** Deep Data Security config. */ + public static boolean DEEPSEC_ENABLED; + public static String DEEPSEC_DATABASE_TOKEN_STATIC_VALUE; + public static String DEEPSEC_DATABASE_TOKEN_ENDPOINT; + public static String DEEPSEC_DATABASE_TOKEN_CLIENT_ID; + public static String DEEPSEC_DATABASE_TOKEN_CLIENT_SECRET; + public static String DEEPSEC_DATABASE_TOKEN_SCOPE; + + /** External extensions. */ + public static String OJDBC_EXT_DIR; + + static { + initialize(null); + } + + /** + * Applies canonical runtime settings. A non-blank JVM system property always takes precedence. + * + * @param configRoot parsed runtime YAML root, or {@code null} when no YAML file was supplied + */ + public static void initialize(RuntimeConfigRoot configRoot) { + Map yamlProperties = configRoot == null ? null : configRoot.properties(); + Map systemProperties = canonicalSystemProperties(); + TRANSPORT_KIND = value("network.transport", yamlProperties, systemProperties, "stdio").trim().toLowerCase(); + HTTPS_PORT = value("network.https.port", yamlProperties, systemProperties, null); + KEYSTORE_PATH = value("network.https.certificatePath", yamlProperties, systemProperties, null); + KEYSTORE_PASSWORD = value("network.https.certificatePassword", yamlProperties, systemProperties, null); + HTTP_ALLOWED_ORIGINAL_HOSTS = value("network.http.allowedOriginalHosts", yamlProperties, systemProperties, null); + HTTP_ALLOW_UNAUTHENTICATED_FOR_DEVELOPMENT = bool( + "network.http.allowUnauthenticatedForDevelopment", yamlProperties, systemProperties, false); + TOOLS = value("toolSelection.enabled", yamlProperties, systemProperties, null); + INGEST_ROOT_DIR = value("dataIngestion.rootDirectory", yamlProperties, systemProperties, null); + INGEST_MAX_FILE_SIZE_MB = value("dataIngestion.maxFileSizeMb", yamlProperties, systemProperties, null); + DB_URL = value("database.url", yamlProperties, systemProperties, null); + DB_USER = value("database.user", yamlProperties, systemProperties, null); + String dbPassword = value("database.password", yamlProperties, systemProperties, null); + DB_PASSWORD = dbPassword == null ? null : dbPassword.toCharArray(); + DB_TRANSACTION_IDLE_TIMEOUT_SECONDS = integer("database.transactions.idleTimeoutSeconds", yamlProperties, systemProperties, 120); + DB_TRANSACTION_MAX_LIFETIME_SECONDS = integer("database.transactions.maxLifetimeSeconds", yamlProperties, systemProperties, 300); + DB_MAX_TRANSACTIONS_PER_USER = integer("database.transactions.maxPerUser", yamlProperties, systemProperties, 4); + CORS_ALLOWED_ORIGIN = value("network.cors.allowedOrigin", yamlProperties, systemProperties, "*"); + AUTH_OPENID_DISCOVERY_REDIRECT_ENABLED = value("userAuth.openIdDiscoveryRedirectEnabled", yamlProperties, systemProperties, "false"); + AUTH_ENABLED = bool("userAuth.enabled", yamlProperties, systemProperties, false); + AUTH_AUTHORIZATION_SERVER = value("userAuth.authorizationServer", yamlProperties, systemProperties, null); + USER_TOKEN_INTROSPECTION_ENDPOINT = value("userAuth.tokenValidation.introspection.endpoint", yamlProperties, systemProperties, null); + USER_TOKEN_INTROSPECTION_CLIENT_ID = value("userAuth.tokenValidation.introspection.clientId", yamlProperties, systemProperties, null); + USER_TOKEN_INTROSPECTION_CLIENT_SECRET = value("userAuth.tokenValidation.introspection.clientSecret", yamlProperties, systemProperties, null); + OAUTH_SCOPE_CLAIM_PATH = value("userAuth.tokenValidation.introspection.scopeClaimPath", yamlProperties, systemProperties, "scope"); + EDIT_TOOLS_REQUIRE_SCOPE = bool("toolAuthorization.editTools.requireScope", yamlProperties, systemProperties, true); + LIST_CREDENTIALS_REQUIRE_SCOPE = bool("toolAuthorization.listCredentials.requireScope", yamlProperties, systemProperties, true); + USER_TOKEN_VALIDATION_MODE = value("userAuth.tokenValidation.mode", yamlProperties, systemProperties, "introspection").trim().toLowerCase(); + USER_TOKEN_JWT_ISSUER = value("userAuth.tokenValidation.jwt.issuer", yamlProperties, systemProperties, null); + USER_TOKEN_JWT_JWKS_URI = value("userAuth.tokenValidation.jwt.jwksUri", yamlProperties, systemProperties, null); + USER_TOKEN_JWT_AUDIENCE = value("userAuth.tokenValidation.jwt.audience", yamlProperties, systemProperties, null); + USER_TOKEN_JWT_JWKS_CACHE_SECONDS = longValue("userAuth.tokenValidation.jwt.jwksCacheSeconds", yamlProperties, systemProperties, 600); + MCP_OAUTH_SCOPES = value("mcp.oauth.scopes", yamlProperties, systemProperties, "openid"); + MCP_OAUTH_RESOURCE_URL = value("mcp.oauth.resourceUrl", yamlProperties, systemProperties, null); + DEEPSEC_ENABLED = bool("deepDataSecurity.enabled", yamlProperties, systemProperties, false); + DEEPSEC_DATABASE_TOKEN_STATIC_VALUE = value("deepDataSecurity.databaseToken.staticValue", yamlProperties, systemProperties, null); + DEEPSEC_DATABASE_TOKEN_ENDPOINT = value("deepDataSecurity.databaseToken.tokenEndpoint", yamlProperties, systemProperties, null); + DEEPSEC_DATABASE_TOKEN_CLIENT_ID = value("deepDataSecurity.databaseToken.clientId", yamlProperties, systemProperties, null); + DEEPSEC_DATABASE_TOKEN_CLIENT_SECRET = value("deepDataSecurity.databaseToken.clientSecret", yamlProperties, systemProperties, null); + DEEPSEC_DATABASE_TOKEN_SCOPE = value("deepDataSecurity.databaseToken.scope", yamlProperties, systemProperties, null); + OJDBC_EXT_DIR = value("database.jdbc.extensionsDirectory", yamlProperties, systemProperties, null); + } + + private static Map canonicalSystemProperties() { + Map canonical = new LinkedHashMap<>(); + Map legacy = new LinkedHashMap<>(); + System.getProperties().forEach((key, value) -> { + String name = key.toString(); + String canonicalName = RuntimePropertyNames.canonicalName(name); + if (canonicalName.equals(name)) { + canonical.put(name, value.toString()); + } else { + legacy.putIfAbsent(canonicalName, value.toString()); + } + }); + legacy.forEach(canonical::putIfAbsent); + return canonical; + } + + private static String value(String name, Map yamlProperties, + Map systemProperties, String defaultValue) { + String systemValue = systemProperties.get(name); + if (systemValue != null && !systemValue.isBlank()) return systemValue; + if (yamlProperties != null) { + String yamlValue = yamlProperties.get(name); + if (yamlValue != null && !yamlValue.isBlank()) return yamlValue; + } + return defaultValue; + } + + private static boolean bool(String name, Map yamlProperties, + Map systemProperties, boolean defaultValue) { + return Boolean.parseBoolean(value(name, yamlProperties, systemProperties, Boolean.toString(defaultValue))); + } - /** External extensions */ - public static final String OJDBC_EXT_DIR = System.getProperty("ojdbc.ext.dir"); + private static int integer(String name, Map yamlProperties, + Map systemProperties, int defaultValue) { + return Integer.parseInt(value(name, yamlProperties, systemProperties, Integer.toString(defaultValue))); + } + private static long longValue(String name, Map yamlProperties, + Map systemProperties, long defaultValue) { + return Long.parseLong(value(name, yamlProperties, systemProperties, Long.toString(defaultValue))); + } } diff --git a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/OracleDatabaseMCPToolkit.java b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/OracleDatabaseMCPToolkit.java index f44f20f90..8285043a8 100644 --- a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/OracleDatabaseMCPToolkit.java +++ b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/OracleDatabaseMCPToolkit.java @@ -53,6 +53,7 @@ public class OracleDatabaseMCPToolkit { static { + LoadedConstants.initialize(Utils.loadRuntimeConfig()); config = Utils.loadConfig(); } diff --git a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/Utils.java b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/Utils.java index c1ce9b47e..1faa10c9f 100644 --- a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/Utils.java +++ b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/Utils.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.oracle.database.mcptoolkit.config.ConfigRoot; import com.oracle.database.mcptoolkit.config.DataSourceConfig; +import com.oracle.database.mcptoolkit.config.RuntimeConfigRoot; import com.oracle.database.mcptoolkit.config.ToolConfig; import com.oracle.database.mcptoolkit.config.ToolParameterConfig; import com.oracle.database.mcptoolkit.oauth.EndUserSecurityContextHolder; @@ -327,6 +328,35 @@ static ServerConfig loadConfig() { return config; } + /** + * Loads runtime settings from the YAML file specified by {@code runtimeConfigFile}. + * The legacy {@code configFile} remains dedicated to datasources and custom tools. + * + * @return parsed runtime configuration, or {@code null} when none was supplied + */ + static RuntimeConfigRoot loadRuntimeConfig() { + return loadRuntimeConfig(LoadedConstants.RUNTIME_CONFIG_FILE); + } + + static RuntimeConfigRoot loadRuntimeConfig(String runtimeConfigFilePath) { + if (runtimeConfigFilePath == null || runtimeConfigFilePath.isBlank()) { + LOG.info("Runtime config file is not specified. Using values from system properties."); + return null; + } + try (Reader reader = Files.newBufferedReader(Paths.get(runtimeConfigFilePath))) { + Object parsedYaml = new Yaml().load(reader); + if (parsedYaml != null && !(parsedYaml instanceof Map)) { + throw new IllegalArgumentException("Runtime config root must be a YAML mapping"); + } + RuntimeConfigRoot runtimeConfig = RuntimeConfigRoot.fromYaml((Map) parsedYaml); + if (runtimeConfig != null) runtimeConfig.substituteEnvVars(); + return runtimeConfig; + } catch (Exception e) { + LOG.log(Level.SEVERE, "Unable to load runtime config file: " + runtimeConfigFilePath, e); + throw new IllegalStateException("Unable to load runtime config file: " + runtimeConfigFilePath, e); + } + } + /** * Acquires a JDBC connection from the active data source. * diff --git a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/config/RuntimeConfigRoot.java b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/config/RuntimeConfigRoot.java new file mode 100644 index 000000000..1d82a7b22 --- /dev/null +++ b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/config/RuntimeConfigRoot.java @@ -0,0 +1,61 @@ +/* + ** Oracle Database MCP Toolkit version 1.0.0 + ** + ** Copyright (c) 2026 Oracle and/or its affiliates. + ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ + */ + +package com.oracle.database.mcptoolkit.config; + +import com.oracle.database.mcptoolkit.EnvSubstitutor; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Represents runtime settings formerly supplied as JVM system properties. + * This intentionally uses a separate YAML file from custom tool and datasource configuration. + */ +public class RuntimeConfigRoot { + private final Map properties = new LinkedHashMap<>(); + + /** Creates a runtime configuration by flattening its nested YAML sections into property names. */ + public static RuntimeConfigRoot fromYaml(Map yaml) { + RuntimeConfigRoot config = new RuntimeConfigRoot(); + if (yaml != null) config.flatten(null, yaml); + return config; + } + + /** Creates a runtime configuration from already-flattened properties. */ + public static RuntimeConfigRoot fromProperties(Map properties) { + RuntimeConfigRoot config = new RuntimeConfigRoot(); + if (properties != null) { + properties.forEach((name, value) -> + config.properties.put(RuntimePropertyNames.canonicalName(name), value)); + } + return config; + } + + public Map properties() { + return properties; + } + + /** Substitutes environment variables in runtime settings. */ + public void substituteEnvVars() { + properties.replaceAll((key, value) -> EnvSubstitutor.substituteEnvVars(value)); + } + + private void flatten(String prefix, Map section) { + for (Map.Entry entry : section.entrySet()) { + if (!(entry.getKey() instanceof String key) || key.isBlank()) { + throw new IllegalArgumentException("Runtime configuration keys must be non-blank strings"); + } + String propertyName = prefix == null ? key : prefix + "." + key; + Object value = entry.getValue(); + if (value instanceof Map nestedSection) { + flatten(propertyName, nestedSection); + } else if (value != null) { + properties.put(RuntimePropertyNames.canonicalName(propertyName), value.toString()); + } + } + } +} diff --git a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/config/RuntimePropertyNames.java b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/config/RuntimePropertyNames.java new file mode 100644 index 000000000..968a8046c --- /dev/null +++ b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/config/RuntimePropertyNames.java @@ -0,0 +1,53 @@ +/* + ** Oracle Database MCP Toolkit version 1.0.0 + ** + ** Copyright (c) 2026 Oracle and/or its affiliates. + ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ + */ + +package com.oracle.database.mcptoolkit.config; + +import java.util.Map; + +/** Resolves legacy runtime property names to the canonical public names. */ +public final class RuntimePropertyNames { + private static final Map CANONICAL_NAMES = Map.ofEntries( + Map.entry("transport", "network.transport"), + Map.entry("http.allowedOriginalHosts", "network.http.allowedOriginalHosts"), + Map.entry("http.allowUnauthenticatedForDevelopment", "network.http.allowUnauthenticatedForDevelopment"), + Map.entry("https.port", "network.https.port"), + Map.entry("certificatePath", "network.https.certificatePath"), + Map.entry("certificatePassword", "network.https.certificatePassword"), + Map.entry("tools", "toolSelection.enabled"), + Map.entry("ingestRootDir", "dataIngestion.rootDirectory"), + Map.entry("ingestMaxFileSizeMb", "dataIngestion.maxFileSizeMb"), + Map.entry("db.url", "database.url"), Map.entry("db.user", "database.user"), + Map.entry("db.password", "database.password"), + Map.entry("db.transactionIdleTimeoutSeconds", "database.transactions.idleTimeoutSeconds"), + Map.entry("db.transactionMaxLifetimeSeconds", "database.transactions.maxLifetimeSeconds"), + Map.entry("db.maxTransactionsPerUser", "database.transactions.maxPerUser"), + Map.entry("ojdbc.ext.dir", "database.jdbc.extensionsDirectory"), + Map.entry("auth.enabled", "userAuth.enabled"), Map.entry("allowedHosts", "network.cors.allowedOrigin"), + Map.entry("auth.authorizationServer", "userAuth.authorizationServer"), + Map.entry("auth.openIdDiscoveryRedirectEnabled", "userAuth.openIdDiscoveryRedirectEnabled"), + Map.entry("oauth.scopeClaimPath", "userAuth.tokenValidation.introspection.scopeClaimPath"), + Map.entry("editTools.requireScope", "toolAuthorization.editTools.requireScope"), + Map.entry("listCredentials.requireScope", "toolAuthorization.listCredentials.requireScope"), + Map.entry("deepsec.enabled", "deepDataSecurity.enabled"), + Map.entry("deepsec.databaseToken.staticValue", "deepDataSecurity.databaseToken.staticValue"), + Map.entry("deepsec.databaseToken.tokenEndpoint", "deepDataSecurity.databaseToken.tokenEndpoint"), + Map.entry("deepsec.databaseToken.clientId", "deepDataSecurity.databaseToken.clientId"), + Map.entry("deepsec.databaseToken.clientSecret", "deepDataSecurity.databaseToken.clientSecret"), + Map.entry("deepsec.databaseToken.scope", "deepDataSecurity.databaseToken.scope")); + + private RuntimePropertyNames() {} + + public static String canonicalName(String name) { + String mapped = CANONICAL_NAMES.get(name); + if (mapped != null) return mapped; + if (name.startsWith("auth.userTokenValidation.")) { + return "userAuth.tokenValidation." + name.substring("auth.userTokenValidation.".length()); + } + return name; + } +} diff --git a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/web/RedirectOAuthToOpenIDServlet.java b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/web/RedirectOAuthToOpenIDServlet.java index 761192ad9..ee656452a 100644 --- a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/web/RedirectOAuthToOpenIDServlet.java +++ b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/web/RedirectOAuthToOpenIDServlet.java @@ -40,7 +40,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t final String redirectLink = OAuth2Configuration.getInstance().getAuthServer() + "/.well-known/openid-configuration"; - response.addHeader("Access-Control-Allow-Origin", WebUtils.getAllowedHosts()); + response.addHeader("Access-Control-Allow-Origin", WebUtils.getAllowedOrigin()); response.sendRedirect(redirectLink); } } diff --git a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/web/WebUtils.java b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/web/WebUtils.java index 771c18ef8..a67487190 100644 --- a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/web/WebUtils.java +++ b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/web/WebUtils.java @@ -58,14 +58,9 @@ static String buildURLFromRequest(final HttpServletRequest request) { return url.toString(); } - /** - * Retrieves the value of the system property {@code allowedHosts}. - * If the property is not set, it defaults to {@code "*"}. - * - * @return the value of the {@code allowedHosts} system property, or {@code "*"} if not set - */ - static String getAllowedHosts() { - return LoadedConstants.ALLOWED_HOSTS; + /** Returns the configured CORS response origin for OAuth discovery endpoints. */ + static String getAllowedOrigin() { + return LoadedConstants.CORS_ALLOWED_ORIGIN; } /** diff --git a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/web/WellKnownServlet.java b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/web/WellKnownServlet.java index 2af846bb9..b794119be 100644 --- a/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/web/WellKnownServlet.java +++ b/src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/web/WellKnownServlet.java @@ -45,7 +45,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t } response.setContentType("application/json"); - response.addHeader("Access-Control-Allow-Origin", WebUtils.getAllowedHosts()); + response.addHeader("Access-Control-Allow-Origin", WebUtils.getAllowedOrigin()); response.setStatus(HttpServletResponse.SC_OK); final String serverURL = WebUtils.buildURLFromRequest(request); diff --git a/src/oracle-db-mcp-java-toolkit/src/test/java/com/oracle/database/mcptoolkit/LoadedConstantsTest.java b/src/oracle-db-mcp-java-toolkit/src/test/java/com/oracle/database/mcptoolkit/LoadedConstantsTest.java new file mode 100644 index 000000000..05bfb87b0 --- /dev/null +++ b/src/oracle-db-mcp-java-toolkit/src/test/java/com/oracle/database/mcptoolkit/LoadedConstantsTest.java @@ -0,0 +1,128 @@ +/* + ** Oracle Database MCP Toolkit version 1.0.0 + ** + ** Copyright (c) 2026 Oracle and/or its affiliates. + ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ + */ + +package com.oracle.database.mcptoolkit; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.oracle.database.mcptoolkit.config.RuntimeConfigRoot; +import java.io.StringReader; +import java.util.Map; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.yaml.snakeyaml.Yaml; + +class LoadedConstantsTest { + @AfterEach + void resetConstants() { + for (String property : new String[] { + "transport", "network.transport", "https.port", "network.https.port", "db.user", "database.user", + "db.password", "database.password", "http.allowedOriginalHosts", "network.http.allowedOriginalHosts", + "http.allowUnauthenticatedForDevelopment", "network.http.allowUnauthenticatedForDevelopment", + "auth.enabled", "userAuth.enabled", "allowedHosts", "network.cors.allowedOrigin", + "editTools.requireScope", "toolAuthorization.editTools.requireScope", + "deepsec.enabled", "deepDataSecurity.enabled", "deepsec.databaseToken.tokenEndpoint", + "deepDataSecurity.databaseToken.tokenEndpoint" + }) { + System.clearProperty(property); + } + LoadedConstants.initialize(null); + } + + @Test + void loadsRuntimeSettingsFromYamlProperties() { + RuntimeConfigRoot root = RuntimeConfigRoot.fromProperties(Map.of( + "network.transport", "HTTP", "database.user", "yaml-user", "database.password", "yaml-password", + "toolAuthorization.editTools.requireScope", "false")); + + LoadedConstants.initialize(root); + + assertEquals("http", LoadedConstants.TRANSPORT_KIND); + assertEquals("yaml-user", LoadedConstants.DB_USER); + assertArrayEquals("yaml-password".toCharArray(), LoadedConstants.DB_PASSWORD); + assertEquals(false, LoadedConstants.EDIT_TOOLS_REQUIRE_SCOPE); + } + + @Test + void systemPropertiesOverrideYamlProperties() { + RuntimeConfigRoot root = RuntimeConfigRoot.fromProperties(Map.of( + "network.transport", "stdio", "database.user", "yaml-user")); + System.setProperty("transport", "http"); + System.setProperty("database.user", "system-user"); + + LoadedConstants.initialize(root); + + assertEquals("http", LoadedConstants.TRANSPORT_KIND); + assertEquals("system-user", LoadedConstants.DB_USER); + } + + @Test + void parsesNestedRuntimeSettingsFromYaml() { + RuntimeConfigRoot root = RuntimeConfigRoot.fromYaml(new Yaml().load(new StringReader(""" + network: + transport: http + http: + allowedOriginalHosts: mcp.example.com + https: + port: \"45451\" + cors: + allowedOrigin: mcp.example.com + database: + user: ${DB_USER} + toolSelection: + enabled: read-query + userAuth: + enabled: true + deepDataSecurity: + enabled: true + """))); + + root.properties().put("database.user", "yaml-user"); + LoadedConstants.initialize(root); + + assertEquals("http", LoadedConstants.TRANSPORT_KIND); + assertEquals("mcp.example.com", LoadedConstants.HTTP_ALLOWED_ORIGINAL_HOSTS); + assertEquals("45451", LoadedConstants.HTTPS_PORT); + assertEquals("yaml-user", LoadedConstants.DB_USER); + assertEquals("read-query", LoadedConstants.TOOLS); + assertEquals(true, LoadedConstants.AUTH_ENABLED); + assertEquals("mcp.example.com", LoadedConstants.CORS_ALLOWED_ORIGIN); + assertEquals(true, LoadedConstants.DEEPSEC_ENABLED); + } + + @Test + void loadsHttpSecurityAndDeepSecSettingsFromYamlProperties() { + RuntimeConfigRoot root = RuntimeConfigRoot.fromProperties(Map.of( + "network.http.allowedOriginalHosts", "mcp.example.com", + "network.http.allowUnauthenticatedForDevelopment", "true", "userAuth.enabled", "true", + "deepDataSecurity.enabled", "true", + "deepDataSecurity.databaseToken.tokenEndpoint", "https://identity.example.com/token")); + + LoadedConstants.initialize(root); + + assertEquals("mcp.example.com", LoadedConstants.HTTP_ALLOWED_ORIGINAL_HOSTS); + assertEquals(true, LoadedConstants.HTTP_ALLOW_UNAUTHENTICATED_FOR_DEVELOPMENT); + assertEquals(true, LoadedConstants.AUTH_ENABLED); + assertEquals(true, LoadedConstants.DEEPSEC_ENABLED); + assertEquals("https://identity.example.com/token", LoadedConstants.DEEPSEC_DATABASE_TOKEN_ENDPOINT); + } + + @Test + void canonicalSystemPropertiesOverrideLegacyAliasesWithoutMutation() { + RuntimeConfigRoot root = RuntimeConfigRoot.fromProperties(Map.of("database.user", "yaml-user")); + System.setProperty("db.user", "legacy-user"); + System.setProperty("database.user", "canonical-user"); + + LoadedConstants.initialize(root); + + assertEquals("canonical-user", LoadedConstants.DB_USER); + assertEquals("canonical-user", System.getProperty("database.user")); + assertEquals("legacy-user", System.getProperty("db.user")); + } + +} diff --git a/src/oracle-db-mcp-java-toolkit/src/test/java/com/oracle/database/mcptoolkit/UtilsTest.java b/src/oracle-db-mcp-java-toolkit/src/test/java/com/oracle/database/mcptoolkit/UtilsTest.java new file mode 100644 index 000000000..d0b345b2e --- /dev/null +++ b/src/oracle-db-mcp-java-toolkit/src/test/java/com/oracle/database/mcptoolkit/UtilsTest.java @@ -0,0 +1,43 @@ +/* + ** Oracle Database MCP Toolkit version 1.0.0 + ** + ** Copyright (c) 2026 Oracle and/or its affiliates. + ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ + */ + +package com.oracle.database.mcptoolkit; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +class UtilsTest { + @TempDir + Path temporaryDirectory; + + @Test + void rejectsMissingRuntimeConfigFile() { + assertThrows(IllegalStateException.class, + () -> Utils.loadRuntimeConfig(temporaryDirectory.resolve("missing.yaml").toString())); + } + + @Test + void rejectsMalformedRuntimeConfigFile() throws IOException { + Path runtimeConfig = temporaryDirectory.resolve("runtime.yaml"); + Files.writeString(runtimeConfig, "network: ["); + + assertThrows(IllegalStateException.class, () -> Utils.loadRuntimeConfig(runtimeConfig.toString())); + } + + @Test + void rejectsRuntimeConfigWithMissingEnvironmentVariable() throws IOException { + Path runtimeConfig = temporaryDirectory.resolve("runtime.yaml"); + Files.writeString(runtimeConfig, "database:\n password: ${MISSING_RUNTIME_CONFIG_TEST_VALUE}\n"); + + assertThrows(IllegalStateException.class, () -> Utils.loadRuntimeConfig(runtimeConfig.toString())); + } +}