fix(security): remove hardcoded AWX credential from script
The AWX admin password was hardcoded in scripts/awx_create_job_templates.py. Read credentials from environment variables instead (AWX_USER, AWX_PASSWORD, AWX_URL) and fail loudly when AWX_PASSWORD is unset. No credentials are stored in this repository. 🤖 Generated with [Crush](https://github.com/charmassociates/crush) Assisted-by: GLM-5 via Crush <crush@charm.land>
This commit is contained in:
@@ -10,18 +10,32 @@ It will:
|
|||||||
4. Create the inventory source (auto-syncs hosts from inventory/hosts.yml)
|
4. Create the inventory source (auto-syncs hosts from inventory/hosts.yml)
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
export AWX_PASSWORD='...'
|
||||||
python3 awx_create_job_templates.py
|
python3 awx_create_job_templates.py
|
||||||
|
|
||||||
|
Configuration (environment variables):
|
||||||
|
AWX_URL AWX API base URL (default: http://100.91.39.53/api/v2)
|
||||||
|
AWX_USER AWX admin username (default: admin)
|
||||||
|
AWX_PASSWORD AWX admin password (REQUIRED - never committed to the repo)
|
||||||
|
AWX_PROJECT_ID, AWX_INVENTORY_ID, AWX_SCM_CRED_ID,
|
||||||
|
AWX_MACHINE_CRED_ID, AWX_ORG_ID resource IDs (sensible defaults below)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
import urllib.request, urllib.parse, json, base64, time, sys
|
import urllib.request, urllib.parse, json, base64, time, sys
|
||||||
|
|
||||||
API = "http://100.91.39.53/api/v2"
|
API = os.environ.get("AWX_URL", "http://100.91.39.53/api/v2")
|
||||||
AUTH = base64.b64encode(b"***REMOVED***").decode()
|
_AWX_USER = os.environ.get("AWX_USER", "admin")
|
||||||
PROJECT_ID = 10
|
_AWX_PASS = os.environ.get("AWX_PASSWORD")
|
||||||
INVENTORY_ID = 2
|
if not _AWX_PASS:
|
||||||
SCM_CRED_ID = 3
|
sys.exit("ERROR: AWX_PASSWORD environment variable is not set. "
|
||||||
MACHINE_CRED_ID = 4
|
"Refusing to run — no credentials are stored in this repo.")
|
||||||
ORG_ID = 1
|
AUTH = base64.b64encode(f"{_AWX_USER}:{_AWX_PASS}".encode()).decode()
|
||||||
|
PROJECT_ID = int(os.environ.get("AWX_PROJECT_ID", "10"))
|
||||||
|
INVENTORY_ID = int(os.environ.get("AWX_INVENTORY_ID", "2"))
|
||||||
|
SCM_CRED_ID = int(os.environ.get("AWX_SCM_CRED_ID", "3"))
|
||||||
|
MACHINE_CRED_ID = int(os.environ.get("AWX_MACHINE_CRED_ID", "4"))
|
||||||
|
ORG_ID = int(os.environ.get("AWX_ORG_ID", "1"))
|
||||||
|
|
||||||
def awx_req(method, endpoint, data=None):
|
def awx_req(method, endpoint, data=None):
|
||||||
url = f"{API}/{endpoint}"
|
url = f"{API}/{endpoint}"
|
||||||
@@ -144,7 +158,7 @@ print("ALL DONE - AWX is ready!")
|
|||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
print("""
|
print("""
|
||||||
AWX URL: http://tsys-awx.knel.net (or http://100.91.39.53)
|
AWX URL: http://tsys-awx.knel.net (or http://100.91.39.53)
|
||||||
Login: admin
|
Login: $AWX_USER (password supplied via $AWX_PASSWORD env var)
|
||||||
|
|
||||||
Resources created:
|
Resources created:
|
||||||
Credentials:
|
Credentials:
|
||||||
|
|||||||
Reference in New Issue
Block a user