Skip to content

Bug: ansible_name column has no uniqueness constraint or input validation #2011

@mrveiss

Description

@mrveiss

Problem

The ansible_name column added in PR #1932 (#1814) has no uniqueness constraint in the database model and no min_length validation in the Pydantic schema.

Uniqueness

Two nodes could have the same ansible_name, causing Ansible --limit to target the wrong node (or both). Since ansible_name is used for --limit targeting and Ansible inventory host keys, duplicates would cause silent misrouting of playbook executions.

Validation

NodeUpdate.ansible_name accepts any string including empty string "". While "" is falsy in Python's or operator (so the ansible_target property falls back to IP), an explicit Field(min_length=1) would prevent confusion.

Discovered During

Implementation of #1986 (ansible_name auto-populate from heartbeat)

Fix

  1. Add UniqueConstraint or unique index on ansible_name (nullable unique — NULL is allowed, duplicates are not)
  2. Add Field(min_length=1) to NodeUpdate.ansible_name and NodeCreate.ansible_name
  3. Add migration for the unique constraint

Impact

Severity: medium — Silent misrouting of Ansible commands if duplicates exist.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions