久久国产乱子伦精品免费M,亚洲一区二区三区91,欧美国产在线视频,国产精品视频久久

通過堡壘機代理SSH運行Ansible(譯)

有一種常見的網絡安全模式是阻止私有網絡外部對應用服務器的所有連接(指除了業務數據外其它的連接,如后臺管理系統和內部業務系統。譯者注),然后使用 DMZ 區域中的 堡壘機 來選擇性的將到服務器的流量加入白名單。

我們有這樣的一個服務器池,只允許來自特定 IP 地址的 SSH 流量。這些服務器還由 Ansible 通過 SSH 方式程序化的來管理。

堡壘機方式導致 Ansible 不能直接與應用服務器通訊,因此需要找到通過堡壘機代理 SSH 連接的方法。

我喜歡用 Ansible 創建簡單任務來運行,比如清空 memcache 以消除緩存。運行這個例子,以下是 Ansible 結構:

devops/
    ansible/
        roles/
            memcache/
                tasks/
                    main.yml
                    restart.yml
        tasks/
            restart-memcache.yml
        vars/
            production-memcache.yml
    bin/
        restart-production-memcache.sh
    hosts.ini
    ssh.config
    ansible.cfg

腳本 tasks/restart-production-memcache.sh 如下:

#!/bin/sh
ssh-add ${DEPLOY_KEYS_DIR}/memcache-servers.pem

ansible-playbook -i ansible/hosts.ini -u ansible ansible/tasks/restart-memcache.yml -v

從 devops 根目錄執行,首先將服務器的 SSH key 添加到 SSH 客戶端代理,然后執行 restart-memcache.ymlplaybook ,這包含了 memcache 角色的 restart.yml playbook (以及執行其它任務)。

ssh.config 文件中有以下 SSH 配置:

Host bastion
    User                   ec2-user
    HostName               ###.###.###.###
    ProxyCommand           none
    IdentityFile           /path/to/ssh/key.pem
    BatchMode              yes
    PasswordAuthentication no

Host *
    ServerAliveInterval    60
    TCPKeepAlive           yes
    ProxyCommand           ssh -q -A ec2-user@###.###.###.### nc %h %p
    ControlMaster          auto
    ControlPath            ~/.ssh/mux-%r@%h:%p
    ControlPersist         8h
    User                   ansible
    IdentityFile           /path/to/ssh/key.pem

首先聲明用于連接到堡壘機的配置。緊接著是一個包含所有主機的總配置,在 ProxyCommand 中指明首先連接到堡壘機,然后使用 netcat (`nc) 來傳遞 Ansible 命令到應用服務器。

在 devops 文件夾中運行 ssh bastion -F ssh.config 即可連接到堡壘機。

接下來 Ansible 在連接應用服務器時,需要被告知使用這個自定義的 SSH 配置。

ansible.cfg 文件中有如下配置:

[ssh_connection]
ssh_args = -o ControlPersist=15m -F ssh.config -q
scp_if_ssh = True
control_path = ~/.ssh/mux-%%r@%%h:%%p

當 Ansible 在 devops 中執行時,能自動選擇 ansible.cfg 并在運行 playbooks 時使用定義的配置項。

這種設置方法的一個問題是它運行時的 Ansible 的輸出非常冗長,因為通過堡壘機連接到應用服務器時,包含了 SSH 調試連接信息;暫未找到好的辦法來跳過這些信息。


譯者:Liu Lantao : http://blog.liulantao.com

來源: Using Ansible with a bastion SSH host by Alex Bilbie

相關新聞

歷經多年發展,已成為國內好評如潮的Linux云計算運維、SRE、Devops、網絡安全、云原生、Go、Python開發專業人才培訓機構!

    1. 主站蜘蛛池模板: 平远县| 即墨市| 金沙县| 抚州市| 卢湾区| 黄冈市| 天峻县| 边坝县| 马鞍山市| 当阳市| 确山县| 西平县| 嵊泗县| 台北县| 莆田市| 泾川县| 邹城市| 遂溪县| 乌鲁木齐县| 磴口县| 乳山市| 邹平县| 河间市| 商河县| 正安县| 乡宁县| 太保市| 布尔津县| 墨玉县| 东莞市| 桂阳县| 秦皇岛市| 伊吾县| 芜湖县| 镇雄县| 屏边| 北辰区| 锦州市| 柘荣县| 东宁县| 新蔡县|