98 lines
4.4 KiB
Bash
Executable File
98 lines
4.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ============================================================================
|
|
# A-Team Security — Infrastructure & Security Agent Engineer
|
|
# One-command setup: login → pull → run
|
|
# ============================================================================
|
|
set -euo pipefail
|
|
|
|
IMAGE="us-ashburn-1.ocir.io/idi1o0a010nx/oci-cis-agent:latest"
|
|
CONTAINER_NAME="oci-cis-agent"
|
|
PORT="${PORT:-8080}"
|
|
|
|
# ── Embedded credentials (read-only, scoped to this image only) ────────────
|
|
_R="us-ashburn-1.ocir.io"
|
|
_U="idi1o0a010nx/oracleidentitycloudservice/gustavo.nogueira@oracle.com"
|
|
_K() { python3 -c "
|
|
import base64 as b,hashlib as h
|
|
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
|
from cryptography.hazmat.primitives import hashes
|
|
from cryptography.fernet import Fernet
|
|
k=PBKDF2HMAC(algorithm=hashes.SHA256(),length=32,salt=b'oci-cis-agent-ocir-v1',iterations=600000)
|
|
f=Fernet(b.urlsafe_b64encode(k.derive(b'$(printf '%s' "YXRlYW0tc2VjdXJpdHktMjAyNg==" | base64 -d)')))
|
|
print(f.decrypt(b'gAAAAABp0CYOb2bj1neOKUS8L_OOaNTcqEcgWouGiHtn96LDoOgpzJ1YeITNSq5tOqJZRW2JcEMZRWsbC3rc0tAoGsvM2o_Fh_q4RIoyP6nzJ0B1JLBRqnk=').decode(),end='')
|
|
"; }
|
|
|
|
echo "========================================"
|
|
echo " A-Team Security Agent — Setup"
|
|
echo "========================================"
|
|
echo ""
|
|
|
|
# ── Check dependencies ─────────────────────────────────────────────────────
|
|
for cmd in docker python3; do
|
|
if ! command -v $cmd &>/dev/null; then
|
|
echo "Error: $cmd is required but not installed."
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
python3 -c "from cryptography.fernet import Fernet" 2>/dev/null || {
|
|
echo "Installing cryptography..."
|
|
pip3 install cryptography --quiet
|
|
}
|
|
|
|
# ── Stop existing container if running ─────────────────────────────────────
|
|
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
|
echo "Stopping existing container..."
|
|
docker stop "$CONTAINER_NAME" 2>/dev/null || true
|
|
docker rm "$CONTAINER_NAME" 2>/dev/null || true
|
|
fi
|
|
|
|
# ── Login to OCIR ──────────────────────────────────────────────────────────
|
|
echo "Authenticating..."
|
|
_K | docker login "$_R" -u "$_U" --password-stdin >/dev/null 2>&1
|
|
echo "Authenticated."
|
|
|
|
# ── Pull latest image ──────────────────────────────────────────────────────
|
|
echo "Pulling image..."
|
|
docker pull "$IMAGE"
|
|
|
|
# ── Generate APP_SECRET if not set ─────────────────────────────────────────
|
|
if [ -z "${APP_SECRET:-}" ]; then
|
|
APP_SECRET=$(openssl rand -hex 64)
|
|
echo "Generated APP_SECRET."
|
|
fi
|
|
|
|
# ── Run container ──────────────────────────────────────────────────────────
|
|
echo "Starting container on port $PORT..."
|
|
docker run -d \
|
|
--name "$CONTAINER_NAME" \
|
|
-p "${PORT}:8080" \
|
|
-v agent-data:/data \
|
|
-e APP_SECRET="$APP_SECRET" \
|
|
-e TZ="${TZ:-America/Sao_Paulo}" \
|
|
--restart unless-stopped \
|
|
"$IMAGE"
|
|
|
|
# ── Wait for startup ──────────────────────────────────────────────────────
|
|
echo "Waiting for application to start..."
|
|
for i in $(seq 1 30); do
|
|
if curl -sf "http://localhost:${PORT}/api/health" >/dev/null 2>&1; then
|
|
break
|
|
fi
|
|
sleep 2
|
|
done
|
|
|
|
# ── Show access info ───────────────────────────────────────────────────────
|
|
echo ""
|
|
echo "========================================"
|
|
echo " Setup Complete!"
|
|
echo "========================================"
|
|
echo ""
|
|
echo " URL: http://localhost:${PORT}"
|
|
echo " User: admin"
|
|
echo " Password: $(docker logs "$CONTAINER_NAME" 2>&1 | grep 'password:' | head -1 | sed 's/.*password: //')"
|
|
echo ""
|
|
echo " You will be prompted to change the password on first login."
|
|
echo ""
|
|
echo "========================================"
|