Skip to content

Commit 39d49d7

Browse files
feat(securitycenter): Add Resource SCC Management API Org SHA Custom … (#3978)
* feat(securitycenter): Add Resource SCC Management API Org SHA Custom Modules * update test case --------- Co-authored-by: Katie McLaughlin <[email protected]>
1 parent 8f0eaac commit 39d49d7

6 files changed

+375
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use strict';
15+
16+
/**
17+
* Delete the security health analytics custom module
18+
*/
19+
function main(organizationId, customModuleId, locationId = 'global') {
20+
// [START securitycenter_delete_security_health_analytics_custom_module]
21+
// npm install '@google-cloud/securitycentermanagement'
22+
const {
23+
SecurityCenterManagementClient,
24+
} = require('@google-cloud/securitycentermanagement');
25+
26+
const client = new SecurityCenterManagementClient();
27+
28+
/*
29+
* Required. Resource name of security health analytics module.
30+
* Its format is
31+
* `organizations/[organization_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
32+
* `folders/[folder_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
33+
* `projects/[project_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
34+
*/
35+
const name = `organizations/${organizationId}/locations/${locationId}/securityHealthAnalyticsCustomModules/${customModuleId}`;
36+
37+
async function deleteSecurityHealthAnalyticsCustomModule() {
38+
const [response] = await client.deleteSecurityHealthAnalyticsCustomModule({
39+
name: name,
40+
});
41+
console.log(
42+
'Security Health Analytics Custom Module delete succeeded: ',
43+
response
44+
);
45+
}
46+
47+
deleteSecurityHealthAnalyticsCustomModule();
48+
// [END securitycenter_delete_security_health_analytics_custom_module]
49+
}
50+
51+
main(...process.argv.slice(2));
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use strict';
15+
16+
/**
17+
* List all descendant security health analytics custom module under a given parent resource
18+
*/
19+
function main(organizationId, locationId = 'global') {
20+
// [START securitycenter_list_descendant_security_health_analytics_custom_module]
21+
// npm install '@google-cloud/securitycentermanagement'
22+
const {
23+
SecurityCenterManagementClient,
24+
} = require('@google-cloud/securitycentermanagement');
25+
26+
const client = new SecurityCenterManagementClient();
27+
28+
/*
29+
* Required. The name of the parent resource of security health analytics module
30+
* Its format is
31+
* `organizations/[organization_id]/locations/[location_id]`
32+
* `folders/[folder_id]/locations/[location_id]`
33+
* `projects/[project_id]/locations/[location_id]`
34+
*/
35+
const parent = `organizations/${organizationId}/locations/${locationId}`;
36+
37+
async function listDescendantSecurityHealthAnalyticsCustomModule() {
38+
const [response] =
39+
await client.listDescendantSecurityHealthAnalyticsCustomModules({
40+
parent: parent,
41+
});
42+
console.log(
43+
'Security Health Analytics Custom Module list descendant succeeded: ',
44+
response
45+
);
46+
}
47+
48+
listDescendantSecurityHealthAnalyticsCustomModule();
49+
// [END securitycenter_list_descendant_security_health_analytics_custom_module]
50+
}
51+
52+
main(...process.argv.slice(2));
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use strict';
15+
16+
/**
17+
* List all effective security health analytics custom module under a given parent resource
18+
*/
19+
function main(organizationId, locationId = 'global') {
20+
// [START securitycenter_list_effective_security_health_analytics_custom_module]
21+
// npm install '@google-cloud/securitycentermanagement'
22+
const {
23+
SecurityCenterManagementClient,
24+
} = require('@google-cloud/securitycentermanagement');
25+
26+
const client = new SecurityCenterManagementClient();
27+
28+
/*
29+
* Required. The name of the parent resource of security health analytics module
30+
* Its format is
31+
* `organizations/[organization_id]/locations/[location_id]`
32+
* `folders/[folder_id]/locations/[location_id]`
33+
* `projects/[project_id]/locations/[location_id]`
34+
*/
35+
const parent = `organizations/${organizationId}/locations/${locationId}`;
36+
37+
async function listEffectiveSecurityHealthAnalyticsCustomModule() {
38+
const [response] =
39+
await client.listEffectiveSecurityHealthAnalyticsCustomModules({
40+
parent: parent,
41+
});
42+
console.log(
43+
'Security Health Analytics Custom Module list effective succeeded: ',
44+
response
45+
);
46+
}
47+
48+
listEffectiveSecurityHealthAnalyticsCustomModule();
49+
// [END securitycenter_list_effective_security_health_analytics_custom_module]
50+
}
51+
52+
main(...process.argv.slice(2));
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use strict';
15+
16+
/**
17+
* List all security health analytics custom module under a given parent resource
18+
*/
19+
function main(organizationId, locationId = 'global') {
20+
// [START securitycenter_list_security_health_analytics_custom_module]
21+
// npm install '@google-cloud/securitycentermanagement'
22+
const {
23+
SecurityCenterManagementClient,
24+
} = require('@google-cloud/securitycentermanagement');
25+
26+
const client = new SecurityCenterManagementClient();
27+
28+
/*
29+
* Required. The name of the parent resource of security health analytics module
30+
* Its format is
31+
* `organizations/[organization_id]/locations/[location_id]`
32+
* `folders/[folder_id]/locations/[location_id]`
33+
* `projects/[project_id]/locations/[location_id]`
34+
*/
35+
const parent = `organizations/${organizationId}/locations/${locationId}`;
36+
37+
async function listSecurityHealthAnalyticsCustomModule() {
38+
const [response] = await client.listSecurityHealthAnalyticsCustomModules({
39+
parent: parent,
40+
});
41+
console.log(
42+
'Security Health Analytics Custom Module list succeeded: ',
43+
response
44+
);
45+
}
46+
47+
listSecurityHealthAnalyticsCustomModule();
48+
// [END securitycenter_list_security_health_analytics_custom_module]
49+
}
50+
51+
main(...process.argv.slice(2));
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use strict';
15+
16+
/**
17+
* Simulate security health analytics custom module
18+
*/
19+
function main(organizationId, locationId = 'global') {
20+
// [START securitycenter_simulate_security_health_analytics_custom_module]
21+
// npm install '@google-cloud/securitycentermanagement'
22+
const {
23+
SecurityCenterManagementClient,
24+
protos,
25+
} = require('@google-cloud/securitycentermanagement');
26+
27+
const client = new SecurityCenterManagementClient();
28+
29+
const Severity =
30+
protos.google.cloud.securitycentermanagement.v1.CustomConfig.Severity;
31+
32+
/*
33+
* Required. The name of the parent resource of security health analytics module
34+
* Its format is
35+
* `organizations/[organization_id]/locations/[location_id]`
36+
* `folders/[folder_id]/locations/[location_id]`
37+
* `projects/[project_id]/locations/[location_id]`
38+
*/
39+
const parent = `organizations/${organizationId}/locations/${locationId}`;
40+
41+
// define the CEL expression here and this will scans for keys that have not been rotated in
42+
// the last 30 days, change it according to the your requirements
43+
const expr = {
44+
expression: `has(resource.rotationPeriod) && (resource.rotationPeriod > duration('2592000s'))`,
45+
};
46+
47+
// define the resource selector
48+
const resourceSelector = {
49+
resourceTypes: ['cloudkms.googleapis.com/CryptoKey'],
50+
};
51+
52+
// define the custom module configuration, update the severity, description,
53+
// recommendation below
54+
const customConfig = {
55+
predicate: expr,
56+
resourceSelector: resourceSelector,
57+
severity: Severity.MEDIUM,
58+
description: 'add your description here',
59+
recommendation: 'add your recommendation here',
60+
};
61+
62+
// define the simulated resource data
63+
const resourceData = {
64+
fields: {
65+
resourceId: {stringValue: 'test-resource-id'},
66+
name: {stringValue: 'test-resource-name'},
67+
},
68+
};
69+
70+
// define the policy
71+
const policy = {
72+
bindings: [
73+
{
74+
role: 'roles/owner',
75+
members: ['user:[email protected]'],
76+
},
77+
],
78+
};
79+
80+
// replace with the correct resource type
81+
const simulatedResource = {
82+
resourceType: 'cloudkms.googleapis.com/CryptoKey',
83+
resourceData: resourceData,
84+
iamPolicyData: policy,
85+
};
86+
87+
async function simulateSecurityHealthAnalyticsCustomModule() {
88+
const [response] = await client.simulateSecurityHealthAnalyticsCustomModule(
89+
{
90+
parent: parent,
91+
customConfig: customConfig,
92+
resource: simulatedResource,
93+
}
94+
);
95+
console.log(
96+
'Security Health Analytics Custom Module simulate succeeded: ',
97+
response
98+
);
99+
}
100+
101+
simulateSecurityHealthAnalyticsCustomModule();
102+
// [END securitycenter_simulate_security_health_analytics_custom_module]
103+
}
104+
105+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)