2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

itamae|ldap認証のCentos7でwebサーバーを構築するレシピ(続き)

Last updated at Posted at 2016-09-08

概要

itamae|ldap認証のCentos7でwebサーバーを構築するレシピで構築サーバーのnginxをldap対応にして、basic認証する。

前準備

itamae|ldap認証のCentos7でwebサーバーを構築するレシピでnginxのインストール前まで構築する

本稿では、以前の構築でepel経由のnginxをインストールしているので、nginxをアンインストールすることから始める。
(nginxをインストールしていないなら、本編まで飛ばす)
itamaeのレシピでアンイントールしても良いが、再利用する必要がないので、アンインストールのみ主導でおこなう

centos−webサーバー側のrootアカウントで行う


# nginxをとめる
systemctl stop nginx.service

# 完全に初期化していので、nginxだけでなく、依存関係で同時に入ったものを全て消す
yum remove nginx GeoIP fontconfig fontpackages-filesystem gd gperftools-libs libX11 libX11-common libXau libXpm libjpeg-turbo libpng libunwind libxcb libxslt nginx-filesystem perl perl-Carp perl-Encode perl-Exporter perl-File-Path perl-File-Temp perl-Filter perl-Getopt-Long  perl-HTTP-Tiny perl-PathTools perl-Pod-Escapes perl-Pod-Perldoc perl-Pod-Simple perl-Pod-Usage perl-Scalar-List-Utils perl-Socket perl-Storable perl-Text-ParseWords perl-Time-HiRes perl-Time-Local perl-constant perl-libs perl-macros perl-parent perl-podlators perl-threads perl-threads-shared

# インストールで追加されたnginxアカウントも削除
userdel nginx -rf

# 追加するパッケージでsystemctl用ファイルが上書きになるので、systemctlデーモンでファイルを再読み込みさせる
systemctl daemon-reload

本編

本稿で使用したレシピはgithubに上げてある

管理サーバーからitamaeレシピファイルを作成する

  • 自作パッケージの公開用リポジトリを追加

    リポジトリ用レシビ格納ディレクトリで作成/実行する

cd ~/itamae_cookbooks/repos
myrepo.rb
template "/etc/yum.repos.d/myrepo.repo" do
    action :create
    owner  "root"
    group  "root"
    mode   "644"
    source "files/myrepo.repo"
end

(管理サーバーでitamaeを実行する)

itamae ssh -u xxx -h 192.168.56.102 -i id_rsa_xxx myrepo.rb
  • nginx_myrpm追加用レシピを作成する
    • nginx_myrpmを追加する
    • ldap確認用virtualhost用ディレクトリ設置
    • ssl設定用 crt/keyファイル、nginxのコンフィグファイルの設置
    • ldap確認用virtualhost用ファイルの設置
    • nginx(nginx_myrpm)の自動起動設定/開始

nginx用レシビ格納ディレクトリで作成/実行する

cd ~/itamae_cookbooks/nginx
nginx_myrpm.rb
package "nginx_myrpm" do
    action :install
end

[
    "/var/www",
    "/var/www/ldap_auth",
].each {| dir |
    directory dir do
       action :create
       owner  "nginx"
       group  "nginx"
       mode   "755"
    end
}

[
    "server.crt",
    "server.key",
    "nginx.conf",
].each {| file |
    template "/etc/nginx/#{file}" do
        action :create
        owner  "nginx"
        group  "nginx"
        mode   "644"
        source "files/#{file}"
    end
}

[
    "index",
    "404",
    "50x",
].each{| com |
    execute "404" do
        command "echo \"#{com}\" > /var/www/ldap_auth/#{com}.html;chmod 666 /var/www/ldap_auth/#{com}.html"
        not_if  "test -e /var/www/ldap_auth/#{com}.html"
    end
}

service "nginx" do
    action [:enable, :start]
end

(管理サーバーでitamaeを実行する)

itamae ssh -u xxx -h 192.168.56.102 -i id_rsa_xxx nginx_myrpm.rb

確認作業

  • webサーバー構築の確認

ブラウザで構築済みのサーバー(http://192.168.56.102) にアクセスし確認する
スクリーンショット 2016-09-08 13.35.15.png

  • webサーバー(ldap対応)の構築確認

ブラウザでldap認証の確認(https://192.168.56.102) にアクセス
スクリーンショット 2016-09-07 13.44.32.png

ダイアログに、ldapサーバーに登録してある、ユーザー/パスワードを正しく入力すると認証をパスできる
スクリーンショット 2016-09-07 13.55.21.png

ldap認証に関して

ldap認証は、所詮ベーシック認証をファイルから、ldapサーバーに置き換えたにすぎない
そのため、httpヘッダーには "ユーザー:パスワード"が base64エンコードしている情報がそのまま流れている、パケットキャプチャーされると、ユーザー:パスワードがそのままもれので、通信自体をsslで暗号化して、安全性を確保する必要がある
そのため、必ずbasic認証とsslはセットで使うこと

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?