TMAegis
Thêm quy tắc cho tdsql

TMA-TDSQL-4.14

Ensure Primary Keys Are Enforced and MyISAM Engine Is Prohibited

Trung bìnhCấp 1Tự độngtdsql

Mô tả

TXSQL enforces "mandatory primary keys" and an "engine allowlist" through two kernel parameters plus Gateway-layer supplementation: sql_require_primary_key (MySQL 8.0 upstream) - a primary key is required when creating/altering tables reject_table_no_pk (TXSQL enhancement) - reject DML on tables without a primary key reject_create_table_myisam (TXSQL enhancement) - reject creation of MyISAM tables ... Runs the mysql client against the TDSQL data node selected by TDSQL_MYSQL_OPTS (e.g. "-h10.0.0.5 -P4001 -utdsql_audit"); keep the password in ~/.my.cnf or a login path rather than MYSQL_PWD or the command line (see 1.4 and 1.5). Passes when sql_require_primary_key, reject_table_no_pk and reject_create_table_myisam all exist and are ON; also run the benchmark query to find existing tables without a primary key or using MyISAM.

Cách kiểm tra

Phương pháp kiểm tra: Truy vấn SQL

sql_query
out=$(mysql ${TDSQL_MYSQL_OPTS:-} -NBe "SHOW GLOBAL VARIABLES WHERE Variable_name IN ('sql_require_primary_key', 'reject_table_no_pk', 'reject_create_table_myisam')" 2>/dev/null) || exit 1; printf '%s\n' "$out" | awk -F'\t' 'NF >= 2 {n++; v = toupper($2); if (v == "ON" || v == "1") ok++} END {print (n == 3 && ok == 3) ? "compliant" : "noncompliant"}'
Đầu ra mong đợi
compliant

Cách khắc phục

Phương pháp khắc phục: Hướng dẫn hoặc bản vá hạ tầng

SET GLOBAL sql_require_primary_key = ON; SET GLOBAL reject_table_no_pk = ON; SET GLOBAL reject_create_table_myisam = ON; persist them in the parameter template and add primary keys / convert MyISAM tables to InnoDB.

Thuộc tính

Hệ điều hành
Bất kỳ
Thẻ
tdsqlhardening
Tham chiếu
CIS Tencent TDSQL 10.3.22 Benchmark v1.0.0 - 4.14 Ensure Primary Keys Are Enforced and MyISAM Engine Is Prohibited

Kiểm tra máy này

Chạy lệnh này trên máy bạn được phép kiểm tra. Lần quét chỉ ở chế độ đọc.

shell
tmaegis scan --target tdsql