Skip to content

fix(slurm): widen slurmdbd cluster_nodes column on CloudSQL as well - #6817

Draft
AdarshK15 wants to merge 1 commit into
GoogleCloudPlatform:developfrom
AdarshK15:slurm-cloudsql-cluster-nodes
Draft

AdarshK15 wants to merge 1 commit into
GoogleCloudPlatform:developfrom
AdarshK15:slurm-cloudsql-cluster-nodes

Conversation

@AdarshK15

@AdarshK15 AdarshK15 commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Summary

#6462 widened <cluster>_event_table.cluster_nodes from TEXT to MEDIUMTEXT, but only when accounting uses the controller's local database. Clusters on CloudSQL keep the 65,535-byte column, so a longer cluster node list is stored truncated. This PR runs the same check-and-ALTER against CloudSQL.

Changes

Area Change
CloudSQL path
scripts/setup.py
widen_event_cluster_nodes() now also runs when cloudsql_secret is set. It connects with the credentials from <cluster>-slurm-secret-cloudsql, the secret slurmdbd.conf is built from.
Statement CloudSQL: mediumtext not null. MySQL 8.0 rejects a default on a text column (ERROR 1101). Local database: unchanged, still mediumtext not null default ''.
Credentials Passed through a temporary option file created with mode 0600 and removed afterwards. The password is never on a command line.
Failure handling A missing or malformed secret is logged and skipped. As before, a failure never blocks slurmctld startup, and the step runs on the primary controller only.

Evidence

The problem, measured on CloudSQL MySQL 8.0.46 with Slurm 26.05.4 and 5,001 nodesets (using an earlier version of this function, run by hand):

Column definition Result
TEXT (current behaviour on CloudSQL) The 105,027-byte node list was stored cut at 65,535 bytes, with nothing in slurmdbd.log
mediumtext not null default '' (statement from #6462) ERROR 1101 (42000): BLOB, TEXT, GEOMETRY or JSON column 'cluster_nodes' can't have a default value
mediumtext not null Full 105,027 bytes stored

This PR's code, booted on a small cluster with CloudSQL MySQL 8.0.46 and Slurm 26.05.4:

Check Result
First boot setup.log: Widening sqlchk_event_table.cluster_nodes to mediumtext; column read back as mediumtext, NOT NULL
Run again sqlchk_event_table.cluster_nodes is 'mediumtext', not widening
Column put back to TEXT, run again Widened to mediumtext again
Credentials No option file left in /tmp; password not found in the Slurm log files
Accounting afterwards A node-down event was recorded; no slurmdbd.log errors after the change

Testing

  • New unit tests in scripts/tests/test_setup.py for the CloudSQL path: option file contents, mode and removal (also on failure), the statement sent, and unusable secrets.
  • The existing local-database test now asserts the exact statement.
  • pre-commit passes on the changed files.

GoogleCloudPlatform#6462 widened <cluster>_event_table.cluster_nodes from TEXT to MEDIUMTEXT
only when accounting uses the controller's local database. Clusters on
CloudSQL kept the 65,535-byte column, so a longer cluster node list was
stored truncated.

Run the same check-and-ALTER against CloudSQL, using the credentials from
the <cluster>-slurm-secret-cloudsql secret through a root-only temporary
option file. On CloudSQL the column is altered without a default, because
MySQL 8.0 rejects a default on a text column (ERROR 1101). The statement
for the local database is unchanged.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a limitation where the cluster_nodes column in the Slurm accounting database was being truncated on CloudSQL deployments due to the TEXT column size limit. By extending the existing widening logic to support CloudSQL, the change ensures that large node lists are fully stored. The implementation includes secure credential management via temporary configuration files and maintains the existing robustness by ensuring that database schema updates do not interfere with the controller's boot process.

Highlights

  • CloudSQL Database Support: Extended the widen_event_cluster_nodes function to support CloudSQL, ensuring that the cluster_nodes column is correctly widened to MEDIUMTEXT to prevent truncation of large node lists.
  • Secure Credential Handling: Implemented a secure mechanism for CloudSQL authentication using temporary, restricted-permission (0600) MySQL option files, ensuring database passwords are never exposed in command-line arguments.
  • Robust Error Handling: Added comprehensive validation for CloudSQL secrets and ensured that failures in the widening process do not block the controller startup.
  • Enhanced Testing: Added new unit tests to verify the CloudSQL widening logic, secret parsing, secure option file creation, and proper cleanup on failure.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@AdarshK15 AdarshK15 added the release-bugfix Added to release notes under the "Bug fixes" heading. label Dec 4, 2026
@AdarshK15 AdarshK15 self-assigned this Dec 4, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Slurm controller setup script to support widening the cluster_nodes column in the event table when using a CloudSQL accounting database. It introduces helper functions to securely fetch database credentials from a GCP secret, write them to a temporary, root-only MySQL option file, and perform the ALTER TABLE query. Corresponding unit tests have been added to verify this behavior, including credential formatting, file permission enforcement, and cleanup. A review comment suggests an improvement to prevent temporary file leaks by ensuring the file is unlinked if an exception occurs during the write operation in _cloudsql_client_cnf.

Comment on lines +463 to +472
fd, path = tempfile.mkstemp(prefix="slurm-cloudsql-", suffix=".cnf") # created with mode 0600
with os.fdopen(fd, "w") as f:
f.write(
"[client]\n"
f"host={_mysql_cnf_value(host)}\n"
f"port={port}\n"
f"user={_mysql_cnf_value(payload.get('user') or 'slurm')}\n"
f"password={_mysql_cnf_value(payload.get('password') or '')}\n"
)
return db_name, Path(path)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If an exception occurs during the file write operation (e.g., due to a full disk or write error), the temporary file created by tempfile.mkstemp will be leaked on the file system because cnf is not yet returned and assigned in widen_event_cluster_nodes to be cleaned up in its finally block.

Consider wrapping the file writing logic in a try...except block within _cloudsql_client_cnf to ensure the temporary file is unlinked if writing fails.

Suggested change
fd, path = tempfile.mkstemp(prefix="slurm-cloudsql-", suffix=".cnf") # created with mode 0600
with os.fdopen(fd, "w") as f:
f.write(
"[client]\n"
f"host={_mysql_cnf_value(host)}\n"
f"port={port}\n"
f"user={_mysql_cnf_value(payload.get('user') or 'slurm')}\n"
f"password={_mysql_cnf_value(payload.get('password') or '')}\n"
)
return db_name, Path(path)
fd, path = tempfile.mkstemp(prefix="slurm-cloudsql-", suffix=".cnf") # created with mode 0600
try:
with os.fdopen(fd, "w") as f:
f.write(
"[client]\n"
f"host={_mysql_cnf_value(host)}\n"
f"port={port}\n"
f"user={_mysql_cnf_value(payload.get('user') or 'slurm')}\n"
f"password={_mysql_cnf_value(payload.get('password') or '')}\n"
)
except Exception:
Path(path).unlink(missing_ok=True)
raise
return db_name, Path(path)

@AdarshK15

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for CloudSQL databases in the widen_event_cluster_nodes function of the Slurm controller setup script, enabling secure credential retrieval from Secret Manager via a temporary MySQL option file. It also adds comprehensive unit tests for this new functionality. The review feedback recommends enhancing security and robustness by wrapping the temporary file creation in a try...except block to prevent credential leaks on disk if writing fails, and gracefully handling potential JSON parsing errors when reading the secret payload.

Comment on lines +463 to +472
fd, path = tempfile.mkstemp(prefix="slurm-cloudsql-", suffix=".cnf") # created with mode 0600
with os.fdopen(fd, "w") as f:
f.write(
"[client]\n"
f"host={_mysql_cnf_value(host)}\n"
f"port={port}\n"
f"user={_mysql_cnf_value(payload.get('user') or 'slurm')}\n"
f"password={_mysql_cnf_value(payload.get('password') or '')}\n"
)
return db_name, Path(path)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

If an exception occurs during the execution of _cloudsql_client_cnf after tempfile.mkstemp has been called (for example, if _mysql_cnf_value raises an exception due to an unexpected type in the payload, or if writing to the file fails), the temporary file containing the database credentials will be left on disk in /tmp.

Since cnf is only assigned in the caller (widen_event_cluster_nodes) after _cloudsql_client_cnf successfully returns, the finally block in the caller will not be able to clean up this file.

To prevent leaking sensitive credentials on disk, wrap the file writing in a try...except block and delete the temporary file if any exception is raised.

Suggested change
fd, path = tempfile.mkstemp(prefix="slurm-cloudsql-", suffix=".cnf") # created with mode 0600
with os.fdopen(fd, "w") as f:
f.write(
"[client]\n"
f"host={_mysql_cnf_value(host)}\n"
f"port={port}\n"
f"user={_mysql_cnf_value(payload.get('user') or 'slurm')}\n"
f"password={_mysql_cnf_value(payload.get('password') or '')}\n"
)
return db_name, Path(path)
fd, path = tempfile.mkstemp(prefix="slurm-cloudsql-", suffix=".cnf") # created with mode 0600
try:
with os.fdopen(fd, "w") as f:
f.write(
"[client]\n"
f"host={_mysql_cnf_value(str(host))}\n"
f"port={port}\n"
f"user={_mysql_cnf_value(str(payload.get('user') or 'slurm'))}\n"
f"password={_mysql_cnf_value(str(payload.get('password') or ''))}\n"
)
except Exception:
os.unlink(path)
raise
return db_name, Path(path)

log.warning(f"CloudSQL secret {secret_name} not found")
return None
# Same fields and fallbacks as conf.install_dbd_conf, so this reaches the database slurmdbd uses.
payload = json.loads(raw)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the secret payload is not valid JSON, json.loads(raw) will raise a json.JSONDecodeError. Similarly, if the payload is not a dictionary (e.g., a list or a string), calling .get() on it will raise an AttributeError.

These exceptions will propagate to widen_event_cluster_nodes and log a full traceback. Since a malformed secret is a common user configuration issue, it is better to handle these exceptions gracefully and log a clear warning.

Suggested change
payload = json.loads(raw)
try:
payload = json.loads(raw)
if not isinstance(payload, dict):
log.warning(f"CloudSQL secret {secret_name} is not a JSON object")
return None
except (json.JSONDecodeError, TypeError):
log.warning(f"CloudSQL secret {secret_name} is not valid JSON")
return None
References
  1. When a user provides an incompatible or unsupported configuration in boot-time setup scripts, log a warning instead of raising a hard error/exception to avoid completely blocking the instance startup.

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

Labels

release-bugfix Added to release notes under the "Bug fixes" heading.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant