Skip to content

feat(securitycenter): Add Resource SCC Mgmt API Org SHA Custom Modules (Create, Get, List, Delete, Update) #13004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 7, 2025

Conversation

vijaykanthm
Copy link
Contributor

@vijaykanthm vijaykanthm commented Dec 17, 2024

Description

Fixes b/347347639, b/347347585, b/347347681, b/347347739, b/347347584
This PR adds SCC Managament API Org SHA Custom Module Samples to Create, Get, List, Delete & Update.

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

@vijaykanthm vijaykanthm requested review from a team as code owners December 17, 2024 20:36
@product-auto-label product-auto-label bot added the api: securitycenter Issues related to the Security Command Center API. label Dec 17, 2024
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vijaykanthm and reviewers,

Gemini is currently reviewing this pull request and will post a full review in a few minutes. In the meantime, here's a quick summary to help everyone get up to speed:

This pull request adds Python sample code for interacting with the Security Health Analytics Custom Modules API. Specifically, it provides examples for creating, getting, listing, deleting, and updating custom modules within an organization. The intent is to improve the documentation and provide developers with readily available code snippets for common tasks related to Security Health Analytics Custom Modules. The changes include the addition of several new Python files (securitycenter/snippets_management_api/noxfile_config.py, securitycenter/snippets_management_api/requirements-test.txt, securitycenter/snippets_management_api/requirements.txt, securitycenter/snippets_management_api/security_health_analytics_custom_module_test.py, securitycenter/snippets_management_api/security_health_analytics_custom_modules.py) containing the sample code and associated test files, along with updates to the requirements.txt and requirements-test.txt files to include necessary dependencies.

The code is well-structured and includes comprehensive unit tests to ensure functionality. The noxfile_config.py file configures the testing environment, and the security_health_analytics_custom_modules.py file contains the core functions for interacting with the API. The tests in security_health_analytics_custom_module_test.py cover all the CRUD operations (Create, Read, Update, Delete).

Here's a little something to brighten your day:

Code flows like a stream,
Tests catch bugs, a helpful gleam,
Clean code, a joyful dream.

Thanks,
Gemini

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Dec 17, 2024
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request introduces new functionality to manage Security Health Analytics custom modules. Overall, the code is well-organized and the tests are comprehensive. A few minor improvements are suggested below.


TEST_CONFIG_OVERRIDE = {
# You can opt out from the test for specific Python versions.
"ignored_versions": ["2.7", "3.7", "3.9", "3.10", "3.11"],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since this sample supports Python 3.8, consider removing 3.8 from the ignored_versions list to enable testing for this version. Per the authoring guide, samples should support Python 3.8 unless the API or service has specific requirements otherwise.

import time
import random

#Replace these variables before running the sample.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

Consider adding a comment explaining the purpose of each environment variable. This will improve readability and make it easier for others to understand how to configure the tests.

Suggested change
#Replace these variables before running the sample.
#Replace these variables before running the sample.
# GCLOUD_ORGANIZATION: The organization ID.
ORGANIZATION_ID = os.environ["GCLOUD_ORGANIZATION"]
LOCATION = "global"
PREFIX = "python_sample_sha_custom_module" # Prefix used for identifying test modules

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

"custom_config": {
"description": "Sample custom module for testing purpose. Please do not delete.",
"predicate": {
"expression": "has(resource.rotationPeriod) && (resource.rotationPeriod > duration('2592000s'))",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The predicate expression is quite generic. Could you clarify what resource.rotationPeriod refers to and why 2592000 seconds (30 days) is used as a threshold? A more specific example or a detailed explanation in the docstring would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

Comment on lines 48 to 51
"title": "GCE Instance High Severity",
"description": "Custom module to detect high severity issues on GCE instances.",
},
"recommendation": "Ensure proper security configurations on GCE instances.",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The title and description in the predicate refer to "GCE Instance High Severity", but the resource selector targets cloudkms.googleapis.com/CryptoKey. This is a mismatch. Change the title and description to accurately reflect that the predicate applies to Cloud KMS CryptoKeys, not GCE instances.

Suggested change
"title": "GCE Instance High Severity",
"description": "Custom module to detect high severity issues on GCE instances.",
},
"recommendation": "Ensure proper security configurations on GCE instances.",
"title": "Cloud KMS CryptoKey Rotation Period",
"description": "Custom module to check if the rotation period of a Cloud KMS CryptoKey exceeds 30 days.",
},
"recommendation": "Review and adjust the rotation period for Cloud KMS CryptoKeys to align with your security policies.",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

Comment on lines 59 to 62
"description": "The name of the instance",
"expression": "resource.name",
"location": "global",
"title": "Instance Name",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The description, expression, and title in value_expression seem generic. Consider providing more context by relating them to the Cloud KMS CryptoKey example. For instance, instead of "The name of the instance", use "The resource name of the CryptoKey".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

Copy link

snippet-bot bot commented Dec 17, 2024

Here is the summary of changes.

You are about to add 5 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@vijaykanthm vijaykanthm added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 22, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 22, 2025
@glasnt
Copy link
Contributor

glasnt commented Feb 5, 2025

This PR conflicts with #13023 in it's current state. Discussing offline

@glasnt glasnt merged commit 2cb8866 into main Feb 7, 2025
14 checks passed
@glasnt glasnt deleted the scc-mgt-org-create-get branch February 7, 2025 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: securitycenter Issues related to the Security Command Center API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants