Skip to content

[Bug]: StageManager drops enable=False on CREATE; URLs/credentials/comment interpolated unescaped #31389

Description

@Ariznawlll

DRAFT 11 (SDK, 2026-10-27) — to be filed

Title: [Bug]: StageManager drops enable=False on CREATE and interpolates URLs/credentials/comments unescaped

Description

Two defects in BaseStageManager SQL builders (stage.py:256-336):

1. enable parameter is silently ignored on CREATE

def _build_create_stage_sql(self, stage_name, url, credentials=None, enable=True, comment=None, if_not_exists=False):
    sql_parts = ["CREATE STAGE"]
    ...
    # Note: enable is not included in SQL - MatrixOne stages are enabled by default
    return " ".join(sql_parts)

The public API accepts enable (documented as whether the stage is enabled), but the builder never emits it. create_stage(..., enable=False) creates an enabled stage with no warning. Meanwhile the same file's _build_alter_stage_sql supports ENABLE=TRUE/FALSE (line ~314) — so the grammar exists; CREATE just doesn't use it, and the two paths disagree about the feature. (Create-side disabled stages are a real use case: pre-provisioning stages without activating them — RESTRICTED/audit workflows.)

2. Raw interpolation of URL / credentials / comment / WHERE value

sql_parts.append(stage_name)                         # "No escaping to match existing behavior" (code comment admits it)
sql_parts.append(f"URL='{url}'")
cred_parts = [f"'{k}'='{v}'" for k, v in credentials.items()]   # S3 keys/secrets!
sql_parts.append(f"COMMENT='{comment}'")
... f"WHERE stage_name = '{stage_name}'"
  • A value containing ' breaks the statement or rewrites it — and the credentials param carries AWS secrets: a secret with a quote (common in templated secret strings) corrupts the CREATE STAGE statement and the raw secret can leak into error logs (server 1064 messages echo the SQL).
  • stage_name unquoted-identifier + unescaped WHERE literal round out the family. Comments say "matching existing behavior" as if that were compliance rather than the bug.

Reproduction

client.stage.create_stage(
    "my_stage",
    url="s3://bucket/path",
    credentials={"aws_key_id": "AKIA...'", "aws_secret_key": "secret'with'quotes"},
    enable=False,
)
# emitted: CREATE STAGE my_stage URL='s3://bucket/path' CREDENTIALS={'aws_key_id'='AKIA...'', ...}
# 1) server error echoes the malformed SQL (secret leaked into logs); 2) stage is created ENABLED despite enable=False

client.stage.get_stage("x' OR stage_name = 'y")
# emitted: ... WHERE stage_name = 'x' OR stage_name = 'y'   (returns another tenant-visible stage row if name-collision)

Impact

  • enable=False being a no-op silently breaks pre-provisioning flows; the user has no way to know besides inspecting SHOW STAGES output later (stage_status reads enabled). Worse, the docstring and signature promise the behavior.
  • Credentials-corruption leaks secrets via error echoes — the single most sensitive data the SDK handles.
  • The code comments ("No escaping to match existing behavior") actively normalize the defect; any future escaping fix needs to remove those and use the (currently no-op — [Bug]: SDK _escape_string/_escape_identifier are no-ops that only wrap quotes #31375) escape helpers once fixed, or bind-parameters.

Expected behavior

  1. CREATE STAGE must honor enable — emit ENABLE = TRUE/FALSE (parity with ALTER's own grammar in the same file) or drop the parameter with a clear NotImplementedError rather than silently ignoring.
  2. Escape every literal: URL/comment/credential values via '-doubling (fixed helper once [Bug]: SDK _escape_string/_escape_identifier are no-ops that only wrap quotes #31375 lands), stage_name via backticks (doubling), and get_stage via bindparams (WHERE stage_name = :name) since the SDK already depends on SQLAlchemy connection execution.
  3. Regression: stage names/values containing ', {, spaces; enable=False asserting SHOW STAGES reads disabled; credentials round-trip asserting the stored URL/status (not secrets).

Activity

  1. added
    kind/bug
    on Oct 27, 2026
  2. added this to the MO-202610 milestone on Oct 27, 2026
  3. added theissue type on Oct 27, 2026
  4. XuPeng-SH commented on Oct 28, 2026

    @XuPeng-SH
    Contributor

    QA on merged SDK f97056d1107a89854bfac2c06202698e3aafd41e (#31522): the offline stage/moctl files passed 67 tests, including sync/async disabled-stage SQL and default SQL. Additional release-boundary and metadata offline tests passed 31 cases, including a quoted stage comment/identifier and rejection of backslash/NUL in stage string tokens. These establish SDK SQL generation and safe input handling for those cases; they do not establish the server's stored status.

    The original acceptance explicitly asks for SHOW STAGES to read disabled, and stored URL/status with synthetic quoted credential inputs. Those server readbacks have not been run here. The older 83c1 server may be suitable for the SDK contract with mixed-version provenance, but the present resource headroom under the existing guard is insufficient to safely start it. Handing off to QA for those specific checks.

  5. Ariznawlll commented on Oct 28, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。创建禁用 stage 的状态读回正常,但原 issue 要求覆盖的带单引号 comment 仍无法通过真实 SDK 创建,离线 SQL 生成通过不代表服务端接受该输入。

    关键证据

    • 版本:官方 main@9eb05ce0f5ac5ddce36024aaa21c4c79d3e4334c,包含 SDK 修复 PR #31522;本地隔离 1 Log + 1 TN + 2 CN,连接一个 CN,Python SDK 与服务端版本一致。
    • 真实调用 client.stage.create(name, url='file:///tmp/', enable=False, comment="qa 'quoted' comment"),3 个不同 stage 名称均返回 QueryError / 服务端 1105 语法错误(3/3);SDK 实际生成的 SQL 为 CREATE STAGE <name> URL='file:///tmp/' ENABLE=FALSE COMMENT='qa ''quoted'' comment'。失败后检查及清理测试 stage。
    • 直接 SQL 对照:普通 COMMENT='plain comment' 创建后读回 stage_status=disabled;SQL 单引号加倍和反斜杠两种引号写法均返回 1105,重复各 3/3。说明问题至少涉及服务端 stage 语法/执行路径,尚不能断言仅由 SDK 造成。
    • 正常控制:不含引号的 comment、enable=False 读回 disabled,再改为 enable=True 读回 enabled,同步创建与异步读取 3/3;非法反斜杠及 NUL URL 被 SDK 拒绝。均为本地合成输入,未使用实际凭据。

    待解决点

    • 请研发确定 stage COMMENT/URL/credential 字符串对引号的服务端合法表示与 SDK 安全编码方式,使带引号输入可正确存储且不破坏 SQL 边界;需补充合成凭据和 URL 的真实服务端读回、同步/异步测试及回归。
    • 本轮未运行完整 SDK suite 或托管 CI,未对真实外部对象存储操作。
  6. added a commit that references this issue on Oct 30, 2026
    bbfe556
  7. XuPeng-SH commented on Oct 30, 2026

    @XuPeng-SH
    Contributor

    QA handoff for merged #31774 (main bbfe55669a1440424914d45a283a1d0e36f722fa): please verify Stage creation/alter with quoted values, status and native readback. This isolated QA run inspected the issue and merged source but did not run tests or a live MatrixOne service at this SHA because resource headroom under the existing guard was insufficient. Earlier QA counterexamples and PR author-reported validation remain scoped to their recorded versions and are not results of this QA run.

  8. Ariznawlll commented on Oct 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。Stage 创建能保留禁用状态及带引号的 URL、comment 和合成凭据;之前真实服务上的引号失败已复验通过。

    关键证据

    • 官方 main@d39d8a40343ccd40bf665036388df7a40ee867f8;修复 PR fix(python): unify SDK query and analytics lifecycle contracts #31774 的合并提交 bbfe55669a1440424914d45a283a1d0e36f722fa 在祖先链;运行二进制和 SDK 同完整 SHA。本地隔离 1 CN / 1 TN / 1 LogService,唯一 CN 已使用该版本,Python 3.12。
    • 三个独立 stage:同步创建带单引号的 file URL 和 comment,enable=False 后同步及异步读回均为 disabled 且值一致;异步修改为 enabled 并更新带引号 comment 后,同步读取值正确。
    • 使用无效域名及合成凭据创建另一禁用 stage,目录中读回的合成值保留单引号;没有访问真实对象存储。含 NUL URL 被拒绝,已有 stage 状态和 comment 未改变。每轮清理专用 stage。
    • 回归已加入 MOTR #295,定向 3/3 通过、0 skipped。

    待解决点

    • 未验证真实对象存储或多 CN 混合版本升级;PR 明确要求所有 CN 升级后使用新的 Stage 名称/URI 契约。未运行完整 MOTR suite,Add build constraint to assembly source files #295 尚未合入;SDK 用例需显式启用并指定匹配源码,默认 SKIP 不计通过。
  9. Ariznawlll commented on Oct 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    回归位置更正:#295 已关闭并汇总至 MOTR #298;本 issue 的定向用例已补入 #298,之前所述测试结果及未覆盖项不变。#298 尚未合入,完整 MOTR suite 未运行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions