Control: 5.2 Ensure no resources are created in the root compartment
Description
When you create a cloud resource such as an instance, block volume, or cloud network, you must specify to which compartment you want the resource to belong. Placing resources in the root compartment makes it difficult to organize and isolate those resources.
Remediation
From Console
- Login to OCI Console.
- Click in the search bar, top of the screen.
- Type
Advance Resource Query
and hit enter. - Click the
Advanced Resource Query
button in the upper right of the screen. - Enter the following query into the query box:
query VCN, instance, volume, filesystem, bucket, autonomousdatabase, database, dbsystem resources where compartmentId = '<tenancy-id>'
- For each item in the returned results, click the item name.
- Then select
Move Resource
orMore Actions
thenMove Resource
. - Select a
compartment
that is not theroot compartment
inCHOOSE NEW COMPARTMENT
. - Click
Move Resource
.
From Command Line
- Execute the following command:
oci search resource structured-search --query-text "query VCN, instance, volume, filesystem, bucket, autonomousdatabase, database, dbsystem resources where compartmentId = '<tenancy-id>'"
- For each bucket item execute the below command:
oci os bucket update --bucket-name <bucket-name> --compartment-id <not root compartment-id>
- For other resources use the change-compartment command for the resource type:
oci <service-command> <resource-command> change-compartment --<item-id> <item-id> --compartment-id <not root compartment-id>
Example for an Autonomous Database:
oci db autonomous-database change-compartment --autonomous-database-id <autonmous-database-id> --compartment-id <not root compartment-id>
Usage
Run the control in your terminal:
powerpipe control run oci_compliance.control.cis_v110_5_2
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run oci_compliance.control.cis_v110_5_2 --share
SQL
This control uses a named query:
manual_control