Description
With cross db ownership chaining enabled, a chain of objects with the same owner can cross database boundaries and skip a permission check on the referenced object. Cloud SQL no longer allows this flag to be enabled on any SQL Server version.
Potential impact
A user who can change objects in one database may gain access to data in another. Disabling existing chains can break calls that rely on them.
Remediation
Review cross-database calls and object ownership. Provide necessary access through explicit grants or signed stored procedures, then remove the existing flag or set it to off. Test normal workflows and verify that unintended access is denied.
Examples
Both blocks target sqlserver-instance. To change only the flag, keep your current engine version and edition. Supply a supported SQL Server machine type for var.sql_server_tier and fill in the other required settings.
Before
resource "google_sql_database_instance" "db" {
name = "sqlserver-instance"
database_version = "SQLSERVER_2017_EXPRESS"
region = "us-central1"
settings {
database_flags {
name = "cross db ownership chaining"
value = "on"
}
}
}
After
resource "google_sql_database_instance" "db" {
name = "sqlserver-instance"
database_version = "SQLSERVER_2019_STANDARD"
region = "us-central1"
settings {
tier = var.sql_server_tier
database_flags {
name = "cross db ownership chaining"
value = "off"
}
}
}
Explanation:
- Before:
onis a historical setting that may remain on existing instances. - After:
offdisables instance-wide chaining. The example’s move to 2019 Standard is a separate change.