Salt API

Api installieren

yum install salt-api
apt-get install salt-api

Konfiguration

Folgende Zeilen zu /etc/salt/master.d/api.conf hinzufügen:

external_auth:
  pam:
    salt-api:
      - .*
      - '@wheel'
      - '@runner'

rest_cherrypy:
  port: 8000
  disable_ssl: true
  debug: true
service salt-master restart
service salt-api restart

Einen Benutzer anlegen

useradd -m -d /var/lib/salt-api -r -s /usr/sbin/nologin salt-api
passwd salt-api # 123ab

Zugriffe auf Key-Verwaltung beschräken

external_auth:
  pam:
    salt-api:
      - '@wheel'

Testen

Anmelden und API Token holen

curl -sS http://salt:8000/login \
    -H 'Accept: application/x-yaml' \
    -d username=salt-api \
    -d password=123ab \
    -d eauth=pam|grep token|awk '{print $2}'>/tmp/token

Eine Anfrage stellen, z.B. salt '*' test.ping über die API auslösen.

curl -sSk http://salt:8000 \
    -H 'Accept: application/x-yaml' \
    -H "X-Auth-Token: $(cat /tmp/token)"\
    -d client=local \
    -d tgt='*' \
    -d fun=test.ping

State.apply per API durchführen

curl -sSk http://salt:8000 \
    -H 'Accept: application/x-yaml'\
    -H "X-Auth-Token: $(cat /tmp/token)"\
    -d client=local\
    -d tgt='*' \
    -d fun="state.apply" \
    -d arg="generic.all"

Einen neuen Minion registrieren

Prüfen, ob für einen Minion schon Zertifikate generiert wurden:

curl -sSk http://salt:8000/keys \
    -H 'Accept: application/x-yaml' \
    -H "X-Auth-Token: $(cat /tmp/token)"

Wenn kein Zertifikat vorhanden, ein neues generieren und downloaden. Der Download besteht aus einem Tar-File, in welchem minion-Key und minion-Zerifikat enthalten sind.

curl -sSk http://salt:8000/keys \
        -d mid=$(cat /etc/salt/minion_id) \
        -d username=salt-api \
        -d password=123ab \
        -d eauth=pam \
        | tar -C /etc/salt/pki/minion -xmf -

Beispiel Systeme beim Hochfahren registrieren

/etc/rc.local:

# /etc/rc.local
test -e /etc/salt/ready && exit
service salt-minion stop
rm /etc/salt/pki/minion/*

pwgen -0 -A 12 1 >/etc/salt/minion_id
while true; do
  ping -c 1 salt&&break
  sleep 1
done

curl -sSk http://salt:8000/keys \
        -d mid=$(cat /etc/salt/minion_id) \
        -d username=salt-api \
        -d password=123ab \
        -d eauth=pam \
        | tar -C /etc/salt/pki/minion -xmf -
service salt-minion start && touch /etc/salt/ready

Installieren Sie vorher den Salt-Minion und das Tool pwgen. Löschen Sie die Datei /etc/salt/ready, bevor Sie die VM herunterfahren.

apt-get -y install pwgen

results matching ""

    No results matching ""