Skip to content

Commit 08f2b5d

Browse files
author
doomedraven
committed
GCS
1 parent 654729d commit 08f2b5d

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

conf/default/reporting.conf.default

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ enabled = no
217217
[browserext]
218218
enabled = no
219219

220-
# Google Cloud Storage - Store all copy of analysis foldr in GCS
220+
# Google Cloud Storage
221221
[gcs]
222222
enabled = no
223223
# The name of your Google Cloud Storage bucket where files will be uploaded.
@@ -231,6 +231,8 @@ exclude_dirs = logs, shots
231231
# Good examples are large report formats you don't need in GCS.
232232
exclude_files =
233233

234-
# The absolute path to your Google Cloud service account JSON key file.
234+
# Can be vm or json
235+
auth_by = vm
236+
# only if auth_by = json. The absolute path to your Google Cloud service account JSON key file.
235237
# This file is required for authentication.
236238
credentials_path = data/gcp-credentials.json

docs/book/src/installation/host/gcs.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Before installing the module, you need to prepare your Google Cloud environment.
1818
* Grant it the **Storage Object Creator** or **Storage Object Admin** role. This permission is necessary to write files to the bucket.
1919

2020
3. **Download JSON Key:**
21+
* This step is optional if you use ``auth_by=vm``
2122
* After creating the service account, go to its **Keys** tab.
2223
* Click **Add Key** > **Create new key**.
2324
* Select ``JSON`` as the key type and click **Create**. A JSON file will be downloaded.
@@ -40,6 +41,7 @@ Module Installation and Configuration
4041
* Edit ``/opt/CAPEv2/conf/reporting.conf``.
4142
* ``[gcs]`` section, enable ``enabled=yes``.
4243
* Set ``bucket_name`` to the name of your GCS bucket.
44+
* Set ``auth_by`` to ``vm`` if using system account or ``json`` if using credential file.
4345
* Set ``credentials_path`` to the **absolute path** where you saved your service account JSON key file.
4446

4547
3. **Restart CAPE-processor:**

modules/reporting/gcs.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,22 @@ def run(self, results):
4545
bucket_name = self.options.get("bucket_name")
4646
if not bucket_name:
4747
raise CuckooReportError("GCS bucket_name is not configured in reporting.conf -> gcs")
48+
auth_by = self.options.get("auth_by")
49+
if auth_by == "vm":
50+
storage_client = storage.Client()
51+
else:
52+
credentials_path_str = self.options.get("credentials_path")
53+
if not credentials_path_str:
54+
raise CuckooReportError("GCS credentials_path is not configured in reporting.conf -> gcs")
55+
56+
credentials_path = os.path.join(CUCKOO_ROOT, credentials_path_str)
57+
if not os.path.isfile(credentials_path):
58+
raise CuckooReportError(
59+
"GCS credentials_path '%s' is invalid or file does not exist in reporting.conf -> gcs", credentials_path
60+
)
4861

49-
credentials_path_str = self.options.get("credentials_path")
50-
if not credentials_path_str:
51-
raise CuckooReportError("GCS credentials_path is not configured in reporting.conf -> gcs")
52-
53-
credentials_path = os.path.join(CUCKOO_ROOT, credentials_path_str)
54-
if not os.path.isfile(credentials_path):
55-
raise CuckooReportError(
56-
"GCS credentials_path '%s' is invalid or file does not exist in reporting.conf -> gcs", credentials_path
57-
)
62+
credentials = service_account.Credentials.from_service_account_file(credentials_path)
63+
storage_client = storage.Client(credentials=credentials)
5864

5965
# Read the exclusion lists, defaulting to empty strings
6066
exclude_dirs_str = self.options.get("exclude_dirs", "")
@@ -73,8 +79,6 @@ def run(self, results):
7379
try:
7480
# --- Authentication ---
7581
log.debug("Authenticating with Google Cloud Storage...")
76-
credentials = service_account.Credentials.from_service_account_file(credentials_path)
77-
storage_client = storage.Client(credentials=credentials)
7882
bucket = storage_client.bucket(bucket_name)
7983

8084
# Check if the bucket exists and is accessible

0 commit comments

Comments
 (0)