Skip to content

Commit 2d297cf

Browse files
dholtclaude
andcommitted
fix: address Copilot review feedback on MAAS deploy and inventory
- Quote ssh_bastion value in proxy command to handle spaces/special chars - Use os.environ instead of shell interpolation for network_filter in get_ip() to prevent potential code injection - Deduplicate hosts in inventory when machine has both old and aliased tags (e.g., both kube-master and kube_control_plane) - Validate MAAS_API_KEY format (exactly 3 colon-separated parts) in maas_auth_header() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Douglas Holt <dholt@nvidia.com>
1 parent 97051de commit 2d297cf

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

scripts/maas_deploy.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ load_config() {
6969
api_url) [[ -z "${MAAS_API_URL:-}" ]] && MAAS_API_URL="$value" ;;
7070
api_key) [[ -z "${MAAS_API_KEY:-}" ]] && MAAS_API_KEY="$value" ;;
7171
ssh_user) [[ -z "${MAAS_SSH_USER:-}" ]] && MAAS_SSH_USER="$value" ;;
72-
ssh_bastion) [[ -z "${MAAS_SSH_PROXY:-}" ]] && MAAS_SSH_PROXY="ssh -W %h:%p -q ${value}" ;;
72+
ssh_bastion) [[ -z "${MAAS_SSH_PROXY:-}" ]] && MAAS_SSH_PROXY="ssh -W %h:%p -q \"${value}\"" ;;
7373
network) [[ -z "${MAAS_NETWORK:-}" ]] && MAAS_NETWORK="$value" ;;
7474
machines) [[ -z "${MAAS_MACHINES:-}" ]] && MAAS_MACHINES="$value" ;;
7575
esac
@@ -149,8 +149,12 @@ parse_args() {
149149
# --- MAAS API Helpers ---------------------------------------------------------
150150

151151
maas_auth_header() {
152-
local consumer_key token_key token_secret
153-
IFS=':' read -r consumer_key token_key token_secret <<< "$MAAS_API_KEY"
152+
local consumer_key token_key token_secret extra
153+
IFS=':' read -r consumer_key token_key token_secret extra <<< "$MAAS_API_KEY"
154+
if [[ -n "${extra:-}" || -z "${consumer_key}" || -z "${token_key}" || -z "${token_secret}" ]]; then
155+
echo "ERROR: MAAS_API_KEY must be in format consumer_key:token_key:token_secret" >&2
156+
exit 1
157+
fi
154158
local nonce timestamp
155159
nonce=$(python3 -c "import uuid; print(uuid.uuid4().hex)")
156160
timestamp=$(date +%s)
@@ -191,11 +195,10 @@ print(m['status'])
191195

192196
get_ip() {
193197
local system_id="$1"
194-
local network_filter="${MAAS_NETWORK:-}"
195-
maas_get "/machines/${system_id}/" | python3 -c "
196-
import json, sys
198+
maas_get "/machines/${system_id}/" | MAAS_NETWORK="${MAAS_NETWORK:-}" python3 -c "
199+
import json, os, sys
197200
m = json.load(sys.stdin)
198-
network = '${network_filter}'
201+
network = os.environ.get('MAAS_NETWORK', '')
199202
for iface in m.get('interface_set', []):
200203
for link in iface.get('links', []):
201204
ip = link.get('ip_address', '')

scripts/maas_inventory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ def build_inventory(config):
242242
inventory[group] = {"hosts": [], "vars": {}}
243243
elif "hosts" not in inventory[group]:
244244
inventory[group]["hosts"] = []
245-
inventory[group]["hosts"].append(hostname)
245+
if hostname not in inventory[group]["hosts"]:
246+
inventory[group]["hosts"].append(hostname)
246247

247248
return inventory
248249

0 commit comments

Comments
 (0)