Skip to content

feat(installer): bootstrap discovery datasources - #152

Open
PrashantBtkl wants to merge 1 commit into
mainfrom
feat/forager-install-discovery-bootstrap
Open

feat(installer): bootstrap discovery datasources#152
PrashantBtkl wants to merge 1 commit into
mainfrom
feat/forager-install-discovery-bootstrap

Conversation

@PrashantBtkl

@PrashantBtkl PrashantBtkl commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Description

Add optional Linux Forager datasource bootstrap for discovery and SSH installations. The installer validates inputs, securely copies private keys, downloads and verifies the v2 inventory pack, and preserves existing configuration unless replacement is explicit.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Enhancement (non-breaking change which improves existing functionality)
  • Refactor (non-breaking change which improves code structure)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation
  • CI/CD

How Has This Been Tested?

  • Unit tests (go test ./pkg/config)
  • Manual testing (bash -n deploy/install.sh, git diff --check)

Checklist

  • CLA signed (the CLA bot will prompt on your first PR)
  • make validate passes (fmt + lint + test)
  • Docs updated if the wire shape, config surface, or proxy module behavior changed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for configuring discovery and SSH datasources during installation via the deploy/install.sh script, along with corresponding documentation in README.md. The review feedback highlights several critical and medium-severity issues in the shell script, including a missing datasources: key in the generated YAML configuration, insecure directory permissions for SSH keys, an incorrectly scoped cleanup trap for temporary files, and global scope pollution from undeclared local variables.

Comment thread deploy/install.sh Outdated
DATASOURCES=discovery
fi
local key_path item
DATASOURCE_YAML=""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The generated configuration is missing the datasources: key, which will result in invalid YAML and cause the agent to fail to parse the configuration. Prepend the datasources: key to DATASOURCE_YAML when initializing it.

Suggested change
DATASOURCE_YAML=""
DATASOURCE_YAML="datasources:\n"

Comment thread deploy/install.sh Outdated
[ -n "$source" ] || { err "SSH private key file is required for datasource '$name'"; return 1; }
[ -r "$source" ] || { err "SSH private key file is not readable: $source"; return 1; }
[ -s "$source" ] || { err "SSH private key file is empty: $source"; return 1; }
mkdir -p "${DATA_DIR}/ssh"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using mkdir -p to create the SSH key directory leaves it owned by root:root with default permissions (usually 0755), which is a security risk for private keys and prevents the nudgebee user from managing the directory. Use install -d with secure permissions (0700) and the correct owner/group instead.

Suggested change
mkdir -p "${DATA_DIR}/ssh"
install -d -o nudgebee -g nudgebee -m 0700 "${DATA_DIR}/ssh"

Comment thread deploy/install.sh Outdated
Comment on lines +115 to +120
tmp_pack="$(mktemp)"
trap 'rm -f "$tmp_pack"; trap - RETURN' RETURN
if command -v curl &>/dev/null; then curl -fsSL -o "$tmp_pack" "$url"; elif command -v wget &>/dev/null; then wget -q -O "$tmp_pack" "$url"; else err "Neither curl nor wget found"; return 1; fi
[ -s "$tmp_pack" ] || { rm -f "$tmp_pack"; err "Downloaded inventory pack is empty"; return 1; }
"$INSTALL_DIR/$BINARY_NAME" pack verify "$tmp_pack" --key "$PACK_PUBLIC_KEY" >/dev/null
install -o nudgebee -g nudgebee -m 0644 "$tmp_pack" "${PACK_DIR}/linux-inventory-v2.yaml"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

When defining a trap to clean up a temporary file stored in a local variable within a function, use double quotes (e.g., trap "rm -f \"${tmp_pack}\"" EXIT) instead of single quotes. Single quotes defer variable expansion until the trap runs, at which point the local variable is out of scope if the function has already returned, causing the cleanup to fail. Additionally, use the EXIT trap instead of RETURN to ensure cleanup runs even if the script exits prematurely due to set -e.

Suggested change
tmp_pack="$(mktemp)"
trap 'rm -f "$tmp_pack"; trap - RETURN' RETURN
if command -v curl &>/dev/null; then curl -fsSL -o "$tmp_pack" "$url"; elif command -v wget &>/dev/null; then wget -q -O "$tmp_pack" "$url"; else err "Neither curl nor wget found"; return 1; fi
[ -s "$tmp_pack" ] || { rm -f "$tmp_pack"; err "Downloaded inventory pack is empty"; return 1; }
"$INSTALL_DIR/$BINARY_NAME" pack verify "$tmp_pack" --key "$PACK_PUBLIC_KEY" >/dev/null
install -o nudgebee -g nudgebee -m 0644 "$tmp_pack" "${PACK_DIR}/linux-inventory-v2.yaml"
local tmp_pack
tmp_pack="$(mktemp)"
trap "rm -f \"${tmp_pack}\"" EXIT
References
  1. In bash scripts, when defining a trap to clean up a temporary directory stored in a local variable within a function, use double quotes (e.g., trap "rm -rf "${tmpdir}"" EXIT) instead of single quotes. Single quotes defer variable expansion until the trap runs, at which point the local variable is out of scope if the function has already returned, causing the cleanup to fail on successful execution paths.

Comment thread deploy/install.sh
}

validate_list() {
local value="$1" label="$2" item

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The items array variable is not declared as local, which pollutes the global shell scope. Declare it as a local array.

Suggested change
local value="$1" label="$2" item
local value="$1" label="$2" item
local -a items

Comment thread deploy/install.sh Outdated
}

prompt_discovery() {
local tty=/dev/tty

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The value variable used in prompt_discovery is not declared as local, which pollutes the global shell scope. Declare it as local.

Suggested change
local tty=/dev/tty
local tty=/dev/tty value

Comment thread deploy/install.sh
prompt_discovery
DATASOURCES=discovery
fi
local key_path item

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The items array variable is not declared as local, which pollutes the global shell scope. Declare it as a local array.

Suggested change
local key_path item
local key_path item
local -a items

@PrashantBtkl
PrashantBtkl force-pushed the feat/forager-install-discovery-bootstrap branch 4 times, most recently from 1b66072 to 0d0a21a Compare September 4, 2026 15:32
@PrashantBtkl
PrashantBtkl force-pushed the feat/forager-install-discovery-bootstrap branch from 0d0a21a to 9d2bb19 Compare September 4, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant