Repository navigation
Conversation
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.
Summary of ChangesHello, 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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
| 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) |
|
/gemini review |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
| 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
- 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.
Summary
#6462 widened
<cluster>_event_table.cluster_nodesfromTEXTtoMEDIUMTEXT, 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-ALTERagainst CloudSQL.Changes
scripts/setup.pywiden_event_cluster_nodes()now also runs whencloudsql_secretis set. It connects with the credentials from<cluster>-slurm-secret-cloudsql, the secretslurmdbd.confis built from.mediumtext not null. MySQL 8.0 rejects a default on a text column (ERROR 1101). Local database: unchanged, stillmediumtext not null default ''.0600and removed afterwards. The password is never on a command line.slurmctldstartup, 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):
TEXT(current behaviour on CloudSQL)slurmdbd.logmediumtext not null default ''(statement from #6462)ERROR 1101 (42000): BLOB, TEXT, GEOMETRY or JSON column 'cluster_nodes' can't have a default valuemediumtext not nullThis PR's code, booted on a small cluster with CloudSQL MySQL 8.0.46 and Slurm 26.05.4:
setup.log:Widening sqlchk_event_table.cluster_nodes to mediumtext; column read back asmediumtext,NOT NULLsqlchk_event_table.cluster_nodes is 'mediumtext', not wideningTEXT, run againmediumtextagain/tmp; password not found in the Slurm log filesslurmdbd.logerrors after the changeTesting
scripts/tests/test_setup.pyfor the CloudSQL path: option file contents, mode and removal (also on failure), the statement sent, and unusable secrets.pre-commitpasses on the changed files.