SQL File Access

Any SQL statement that names a server-side file path can only open that path when the sys account runs the statement with the moadmin role active in the session. Table privileges such as SELECT or INSERT never grant access to files on the MatrixOne host server, and no permissive fallback mode exists.

Which file paths are restricted

A restricted path is any path that the MatrixOne service opens on the server host or in server-side storage, including:

  • A local file path with no service name, which resolves against the MatrixOne host filesystem.

  • A stage reference created by CREATE STAGE.

  • A path resolved against a named object-storage service or an object-storage-backed dynamic provider.

The following statements read or write such paths and are covered by the admission check:

  • LOAD DATA ... INFILE on a server-side path.

  • SELECT ... INTO OUTFILE and other server-side export paths.

  • load_file() and save_file().

  • File-oriented table functions such as parse_jsonl_file().

  • External reads, including external tables, Hive-format readers, and other readers backed by server-side files or object storage.

  • Table dump/load operations.

  • CREATE SNAPSHOT and other backup SQL that names server-side locations.

  • Datalink consumers that resolve a server-side path indirectly.

The following paths are not restricted, because the file is read or written on the client side and never opens a server resource:

  • LOAD DATA LOCAL INFILE, whose file is read by the client and pushed to the server.

  • INLINE data and inline table functions, such as parse_jsonl_data(), where the data is inlined in the statement text.

Admission requirement

The check runs per statement on the statement’s session identity:

  • The session must be authenticated as the sys account, and the moadmin role must be active in the session when the statement runs.

  • The identity is re-evaluated on every statement and is not cached. After set role public, a previously prepared or previously successful statement is denied; after set role moadmin, the same statement is admitted again.

  • Object privileges on a table, such as SELECT or INSERT, never substitute for this check. A user granted full table privileges still cannot read or write server files.

  • There is no permissive fallback mode: if the active identity does not satisfy the check, the statement fails with only the sys account moadmin role can access SQL file paths.

Syntax

set role moadmin;
set role public;

Arguments

  • The check evaluates the session’s account and the role active for the current statement only; neither the login account nor the active role is cached across statements.

  • Object privileges granted on the target table cannot substitute for the account and role requirement.

  • The check does not rely on secure_file_priv, which is not enforced for this boundary.

Examples

The example below shows the shape of the check on a session whose active role is not moadmin. The session prepares a small table, switches to the public role, and the SELECT ... INTO OUTFILE statement is denied with only the sys account moadmin role can access SQL file paths. The example uses a short-lived scratch database and a local export path; in a real deployment you would replace the path with the server-side path or stage that you intend to write.

DROP DATABASE IF EXISTS sql_file_access_demo_db;
CREATE DATABASE sql_file_access_demo_db;
USE sql_file_access_demo_db;
CREATE TABLE demo_src(id INT PRIMARY KEY, note VARCHAR(100));
INSERT INTO demo_src VALUES(1,'first'),(2,'second');
SET ROLE public;
-- Expected-Success: false
SELECT id, note FROM demo_src INTO OUTFILE '/tmp/demo_src.csv';
SET ROLE moadmin;
DROP DATABASE sql_file_access_demo_db;

The SELECT ... INTO OUTFILE is denied by the identity check while the public role is active. Running the same statement again after SET ROLE moadmin is admitted, because the identity is re-evaluated on every statement rather than cached. Note that changing the active role with set role moadmin or set role public changes the outcome of the very next statement, including for statements prepared before the switch.

Dynamic providers and credentials

For dynamic object-storage providers used by SQL statements, the provider description is validated in addition to the identity check:

  • A dynamic provider must not rely on server-local auxiliary files: cert-files, kerberos-keytab-path, and similar certificate and keytab parameters are rejected with SQL dynamic providers cannot use server-local auxiliary files.

  • Server credential discovery mechanisms such as shared-config-profile are rejected with SQL dynamic providers cannot use server credential discovery.

  • Explicit credentials are required: a provider without usable credentials is rejected with SQL dynamic object storage requires explicit credentials.

  • The MO_NO_DEFAULT_CREDENTIALS environment variable and the NoDefaultCredentialsForETL setting do not select SQL credential behavior; credentials for dynamic providers must be stated explicitly in the provider description.

  • HDFS with simple authentication, Aliyun OSS with BearerToken, and MinIO with explicit anonymous credentials remain usable when stated explicitly in the provider description.

Deployment precautions

  • The boundary is enforced only after every SQL-serving CN in the cluster has been upgraded. A CN still running an older version can admit a statement that the upgraded version denies, so complete the upgrade before relying on the restriction.

  • Asynchronous indexed Datalink sources backed by local files become remote-only under this boundary. To migrate, repoint an existing local-file source to a remote service and rebuild the index, or materialize the local content into a TEXT column using a foreground load_text load before the upgrade.

  • Existing archives written before v4.2.7 do not carry the table-ID history objects introduced for physical restore, so the improved table-ID history check cannot be retrofitted to them; see Backup and Recovery Overview for the restore behavior that uses this history.