Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/artifactories/default/0.1/registry_secret.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resource "kubernetes_secret_v1" "registry_secret" {
metadata {
name = each.value.name
namespace = local.namespace
labels = lookup(local.metadata, "labels", {})
labels = merge(lookup(local.metadata, "labels", {}), {"secret-copier" = "yes"})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Find explicit null label assignments that would break merge()
rg -n -C2 '\blabels\s*=\s*null\b|"labels"\s*:\s*null'

# 2) Inspect metadata/labels shapes in Terraform/YAML/JSON inputs
rg -n -C2 '\bmetadata\b|\blabels\b' -g '*.tf' -g '*.tfvars' -g '*.yaml' -g '*.yml' -g '*.json'

# 3) Locate this module's variable definitions to confirm expected type of metadata.labels
fd 'variables.tf$|locals.tf$|README.md$' modules | xargs -r rg -n -C2 '\bvariable\b|\bmetadata\b|\blabels\b'

Repository: Facets-cloud/facets-modules

Length of output: 53


🏁 Script executed:

# View the file in question
cat -n modules/artifactories/default/0.1/registry_secret.tf

Repository: Facets-cloud/facets-modules

Length of output: 565


🏁 Script executed:

# View locals.tf to understand local.metadata
cat -n modules/artifactories/default/0.1/locals.tf

Repository: Facets-cloud/facets-modules

Length of output: 3799


🏁 Script executed:

# View variables.tf for metadata variable definition
cat -n modules/artifactories/default/0.1/variables.tf

Repository: Facets-cloud/facets-modules

Length of output: 1241


🏁 Script executed:

# Check for example inputs or README
fd 'README|example|test' modules/artifactories/default/0.1 -type f

Repository: Facets-cloud/facets-modules

Length of output: 241


🏁 Script executed:

# Check if there's a root level README with usage info
fd 'README' modules/artifactories -type f

Repository: Facets-cloud/facets-modules

Length of output: 241


🏁 Script executed:

find modules/artifactories/default/0.1 -name "*.md" -o -name "*.tf" -o -name "*.json" | head -20

Repository: Facets-cloud/facets-modules

Length of output: 360


🏁 Script executed:

# Check for test directory or examples
fd 'test\|example' modules/artifactories --maxdepth 3

Repository: Facets-cloud/facets-modules

Length of output: 53


🏁 Script executed:

# Look for any validation or conditional handling around metadata.labels
rg -n 'metadata\.labels|type.*labels' modules/artifactories/default/0.1/

Repository: Facets-cloud/facets-modules

Length of output: 53


🏁 Script executed:

# Check if there's a schema or docs describing expected input structure
cat modules/artifactories/default/0.1/README.md 2>/dev/null || echo "No README found"

Repository: Facets-cloud/facets-modules

Length of output: 2347


Harden merge() and loop inputs to prevent failures on null labels.

Line 6 breaks if metadata.labels is present but null, because merge() only accepts maps/objects. In Terraform, lookup(key, default) returns the actual value if the key exists—even if that value is null—so it does not fall back to the default {}. The same vulnerability exists at locals.tf line 62 in the for-loop.

Suggested fix for registry_secret.tf line 6
-    labels    = merge(lookup(local.metadata, "labels", {}), {"secret-copier" = "yes"})
+    labels    = merge(try(lookup(local.metadata, "labels", {})), {}), {"secret-copier" = "yes"})

Also apply a similar defensive pattern to locals.tf line 62:

labels = join(",", [for k, v in lookup(local.metadata, "labels", {}) : "${k}=${v}"])
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
labels = merge(lookup(local.metadata, "labels", {}), {"secret-copier" = "yes"})
labels = merge(try(lookup(local.metadata, "labels", {}), {}), {"secret-copier" = "yes"})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@modules/artifactories/default/0.1/registry_secret.tf` at line 6, The merge
call for the labels in registry_secret.tf can fail when local.metadata.labels
exists but is null; wrap the lookup(local.metadata, "labels", {}) with a
null-coalescing guard (e.g., coalesce(..., {})) so merge always receives a map,
and apply the same pattern to the labels for-loop in locals.tf (the
comprehension that builds the joined labels string) by coalescing the lookup
result to an empty map before iterating.

}
data = {
".dockerconfigjson" : each.value.dockerconfigjson
Expand Down
Loading