Skip to content

Commit

Permalink
feat: adding _OP_CLOUD_SYS_VENDOR key (#418)
Browse files Browse the repository at this point in the history
should be helpful in debugging IMDS errors
  • Loading branch information
miki725 authored Sep 5, 2024
1 parent da45ae0 commit 7330736
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- `_OP_EXIT_CODE` key which reports external commands
exit code such as for `chalk docker build`.
([#417](https://github.com/crashappsec/chalk/pull/417))
- `_OP_CLOUD_SYS_VENDOR` key for reporting sys vendor
file content used to identity cloud provider.
([#418](https://github.com/crashappsec/chalk/pull/418))

## 0.4.12

Expand Down
12 changes: 12 additions & 0 deletions src/configs/base_keyspecs.c4m
Original file line number Diff line number Diff line change
Expand Up @@ -4477,6 +4477,18 @@ metadata.
"""
}

keyspec _OP_CLOUD_SYS_VENDOR {
kind: RunTimeHost
type: string
standard: true
since: "0.4.13"
shortdoc: "Content of the system DMI vendor file"
doc: """
Content of the system hardware DMI vendor file as configured by
`cloud_provider.cloud_instance_hw_identifiers.sys_vendor_path`.
"""
}

keyspec _OP_ERRORS {
kind: RunTimeHost
type: list[string]
Expand Down
2 changes: 1 addition & 1 deletion src/configs/base_plugins.c4m
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ plugin cloud_metadata {
enabled: true
priority: 1000
post_run_keys: ["_GCP_INSTANCE_METADATA", "_GCP_PROJECT_METADATA",
"_AZURE_INSTANCE_METADATA",
"_AZURE_INSTANCE_METADATA", "_OP_CLOUD_SYS_VENDOR",
"_OP_CLOUD_PROVIDER", "_OP_CLOUD_PROVIDER_SERVICE_TYPE",
"_OP_CLOUD_PROVIDER_ACCOUNT_INFO", "_OP_CLOUD_PROVIDER_REGION",
"_OP_CLOUD_PROVIDER_REGION", "_OP_CLOUD_PROVIDER_IP",
Expand Down
6 changes: 6 additions & 0 deletions src/configs/base_report_templates.c4m
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ report and subtract from it.
key._ENV.use = true
key._TENANT_ID.use = true
key._OPERATION.use = true
key._OP_EXIT_CODE.use = true
key._TIMESTAMP.use = true
key._DATE.use = true
key._TIME.use = true
Expand Down Expand Up @@ -372,6 +373,7 @@ report and subtract from it.
key._OP_ARP_TABLE.use = true
key._OP_CPU_INFO.use = true
key._OP_ALL_PS_INFO.use = true
key._OP_CLOUD_SYS_VENDOR.use = true
key._OP_CLOUD_PROVIDER.use = true
key._OP_CLOUD_PROVIDER_SERVICE_TYPE.use = true
key._OP_CLOUD_PROVIDER_ACCOUNT_INFO.use = true
Expand Down Expand Up @@ -484,6 +486,7 @@ doc: """
key._ENV.use = true
key._TENANT_ID.use = true
key._OPERATION.use = true
key._OP_EXIT_CODE.use = true
key._TIMESTAMP.use = true
key._DATE.use = true
key._TIME.use = true
Expand Down Expand Up @@ -522,6 +525,7 @@ doc: """
key._OP_CPU_INFO.use = true
key._OP_ALL_PS_INFO.use = true
key._CHALK_EXTERNAL_ACTION_AUDIT.use = true
key._OP_CLOUD_SYS_VENDOR.use = true
key._OP_CLOUD_PROVIDER.use = true
key._OP_CLOUD_PROVIDER_SERVICE_TYPE.use = true
key._OP_CLOUD_PROVIDER_ACCOUNT_INFO.use = true
Expand Down Expand Up @@ -996,6 +1000,7 @@ container.
key._OP_CLOUD_METADATA.use = true
key._CHALK_EXTERNAL_ACTION_AUDIT.use = true
key._OP_ERRORS.use = true
key._OP_CLOUD_SYS_VENDOR.use = true
key._OP_CLOUD_PROVIDER.use = true
key._OP_CLOUD_PROVIDER_SERVICE_TYPE.use = true
key._OP_CLOUD_PROVIDER_ACCOUNT_INFO.use = true
Expand Down Expand Up @@ -1456,6 +1461,7 @@ and keep the run-time key.
key._OP_CLOUD_METADATA.use = true
key._CHALK_EXTERNAL_ACTION_AUDIT.use = true
key._OP_ERRORS.use = true
key._OP_CLOUD_SYS_VENDOR.use = true
key._OP_CLOUD_PROVIDER.use = true
key._OP_CLOUD_PROVIDER_SERVICE_TYPE.use = true
key._OP_CLOUD_PROVIDER_ACCOUNT_INFO.use = true
Expand Down
1 change: 1 addition & 0 deletions src/configs/crashoverride.c4m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ This is mostly a copy of insert template however all keys are immutable.
~key._OP_CLOUD_METADATA.use = true
~key._CHALK_EXTERNAL_ACTION_AUDIT.use = true
~key._OP_ERRORS.use = true
~key._OP_CLOUD_SYS_VENDOR.use = true
~key._OP_CLOUD_PROVIDER.use = true
~key._OP_CLOUD_PROVIDER_SERVICE_TYPE.use = true
~key._OP_CLOUD_PROVIDER_ACCOUNT_INFO.use = true
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/cloudMetadata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -486,5 +486,7 @@ proc cloudMetadataGetrunTimeHostInfo*(self: Plugin,
of hkGcp:
getGcpMetadata()

result.setIfNeeded("_OP_CLOUD_SYS_VENDOR", vendor)

proc loadCloudMetadata*() =
newPlugin("cloud_metadata", rtHostCallback = RunTimeHostCb(cloudMetadataGetrunTimeHostInfo))
3 changes: 2 additions & 1 deletion tests/functional/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_aws_no_imds(
):
with make_tmp_file() as vendor, make_tmp_file() as instance:
# make imds plugin think we are running in EC2
vendor.write_text("Amazon")
vendor.write_text("Amazon EC2")
instance.write_text("i-abc123xyz789")
bin_path = copy_files[0]
insert = chalk.insert(
Expand All @@ -164,6 +164,7 @@ def test_aws_no_imds(
)
assert insert.report.contains(
{
"_OP_CLOUD_SYS_VENDOR": "Amazon EC2",
"_OP_CLOUD_PROVIDER": "aws",
"_OP_CLOUD_PROVIDER_SERVICE_TYPE": "aws_ec2",
"_AWS_INSTANCE_ID": "i-abc123xyz789",
Expand Down

0 comments on commit 7330736

Please sign in to comment.