見出し画像

Ubuntu22.04での Shibboleth IdP V5 構築手順


はじめに


こんにちは、株式会社SHIFT ITソリューション部の田平です。

Shibboleth V5が2023年9月にリリースされましたが、2023年12月時点で構築に関する情報が少ないので構築手順をまとめてみました。

今回はShibbolethのインストールまでで、各種設定については別の機会とさせていただきます。

概要


Shibboleth:オープンソースのシングルサインオン(SSO)ソフトウェア。学術認証フェデレーション「学認(GakuNin)」で利用されているため、大学などで利用されることが多い。 また、以下のように利用者数も世界的に多いソフトウェアです。

採用状況
世界の多くの国々で連合が形成され、SAML とシボレスを利用した情報交換のための委任のしくみが構築されている。多くの主要なコンテンツ提供者がシボレスによるアクセスに対応している。連合に参加する学生教職員や部局の数は400万に上る。

引用元:シボレス Wikipedia

Amazon Corretto:Amazonが提供している無料の Open Java Development Kit (OpenJDK) ディストリビューション。

Jetty:100%Javaで開発されたJava Servletコンテナ/Webサーバ。Shibbolethの動作環境として推奨されている。

検証環境


今回は以下の環境で構築を行います。

・Ubuntu 22.04.3 LTS
・Shibboleth IdP V5.0.0
・Amazon Corretto 17 for Linux
・Jetty 11.0.18
・Apache 2.4.52

最新システム要件は公式ページのWikiで確認してください。

環境準備


1. Corretto 17 のインストール

Correttoリポジトリを追加し、Corretto 17をインストールします。

$ wget -O - https://apt.corretto.aws/corretto.key | sudo gpg --dearmor -o /usr/share/keyrings/corretto-keyring.gpg && \
echo "deb [signed-by=/usr/share/keyrings/corretto-keyring.gpg] https://apt.corretto.aws stable main" | sudo tee /etc/apt/sources.list.d/corretto.list
$ sudo apt-get update; sudo apt-get install -y java-17-amazon-corretto-jdk

インストールされたことを確認します。

$ java -version

以下のような表示が行われればOKです。

openjdk version "17.0.9" 2023-10-17 LTS
OpenJDK Runtime Environment Corretto-17.0.9.8.1 (build 17.0.9+8-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.9.8.1 (build 17.0.9+8-LTS, mixed mode, sharing)

2. Jetty 11のインストール

Eclipse Foundationから最新版のパッケージ(.tgz)をダウンロードしてインストールします。

下記コマンドで利用しているURL等はインストール時のバージョンに合わせて修正してください。

$ wget https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/11.0.18/jetty-home-11.0.18.tar.gz
$ sudo tar zxv -C /opt -f jetty-home-11.0.18.tar.gz
$ sudo ln -s /opt/jetty-home-11.0.18 /opt/jetty

Jettyユーザーを作成します。

$ sudo useradd -d /opt/jetty-base -s /sbin/nologin jetty

3. jetty-baseの設定

jetty-baseを配置します。

$ git clone https://git.shibboleth.net/git/java-idp-jetty-base
$ cd java-idp-jetty-base
$ git checkout 11
$ sudo cp -r src/main/resources/jetty-base /opt/
$ sudo chown jetty:jetty /opt/jetty-base/tmp
$ sudo chown jetty:jetty /opt/jetty-base/logs

/opt/jetty-base/start.d/start.ini を以下の内容で新規に作成します。

# Any other required Jetty modules...
# Allows setting Java system properties (-Dname=value)
# and JVM flags (-X, -XX) in this file
# NOTE: spawns child Java process --exec

# Uncomment if IdP is installed somewhere other than /opt/shibboleth-idp
#-Didp.home=/path/to/shibboleth-idp

# Maximum amount of memory that Jetty may use, at least 1.5G is recommended
# for handling larger (> 25M) metadata files but you will need to test on
# your particular metadata configuration. If MDQ metadata on demand is used,
# requirements may be much lower.
-Xmx1500m

# Prevent blocking for entropy.
-Djava.security.egd=file:/dev/urandom

# Set Java tmp location
-Djava.io.tmpdir=tmp

/opt/jetty-base/start.d/idp.ini を以下の内容で修正します。
--module=idpの後ろに以下の2行を追加します。

--module=http
--module=http-forwarded

末尾にあるjetty.http.portのポート番号を変更します。

# Allows use of default IdP command line tools.
jetty.http.host=127.0.0.1
jetty.http.port=8080

修正後のidp.ini

#---------------------------------------
# Module: idp
# Shibboleth IdP
# ---------------------------------------
--module=logging-logback
--module=idp
--module=http
--module=http-forwarded

## Keystore file path (relative to $jetty.base)
jetty.sslContext.keyStorePath=credentials/idp-userfacing.p12
## Truststore file path (relative to $jetty.base)
jetty.sslContext.trustStorePath=credentials/idp-userfacing.p12

## Keystore type
jetty.sslContext.keyStoreType=PKCS12
## Truststore type and provider
jetty.sslContext.trustStoreType=PKCS12

## Keystore password
jetty.sslContext.keyStorePassword=changeit
## Truststore password
jetty.sslContext.trustStorePassword=changeit
## KeyManager password
jetty.sslContext.keyManagerPassword=changeit

## Deny SSL renegotiation
jetty.sslContext.renegotiationAllowed=false

## Connector host/address to bind to
# jetty.ssl.host=0.0.0.0

## Connector port to listen on
jetty.ssl.port=443

## Route request logging through standard logging API
etc/jetty-requestlog.xml

# Allows use of default IdP command line tools.
jetty.http.host=127.0.0.1
jetty.http.port=8080

以下のコマンドを実行し、logging-logbackモジュールを追加します。

$ cd /opt/jetty-base/
$ sudo java -jar /opt/jetty/start.jar --add-module=logging-logback

/opt/jetty-base/modules/idp.modからhttpsとsslをコメントアウトします。

[description]
Shibboleth IdP

[depend]
annotations
deploy
http #https 
jsp
jstl
plus
resources
server
servlets #ssl 

[files]
tmp/

Jetty起動用の設定を行います。

$ sudo ln -s /opt/jetty/bin/jetty.sh /etc/init.d/jetty
$ sudo cp -ip /opt/jetty/bin/jetty.service /etc/systemd/system/

/etc/systemd/system/jetty.serviceのPIDFileを以下のように修正します。

[Unit]
Description=Jetty Web Application Server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/opt/jetty-base/tmp/jetty.pid
ExecStart=/etc/init.d/jetty start
ExecStop=/etc/init.d/jetty stop
ExecReload=/etc/init.d/jetty restart
User=jetty
Group=jetty

[Install]
WantedBy=multi-user.target

/etc/default/jettyを以下の内容で新規に作成します。

JETTY_HOME=/opt/jetty
JETTY_BASE=/opt/jetty-base
JETTY_RUN=/opt/jetty-base/tmp
JETTY_STATE=/opt/jetty-base/tmp/jetty.state

設定を反映させます。

$ sudo systemctl daemon-reload
$ sudo systemctl enable jetty

4. Apache の設定

Apacheをインストールし、必要なモジュールを有効化します。

$ sudo apt install apache2
$ sudo a2enmod proxy_http proxy ssl headers

デフォルトサイトを無効にします。

$ sudo a2dissite 000-default

/etc/apache2/conf-enabled/security.confでServerTokensとServerSignatureを修正します。

※Apacheのセキュリティ対策は他にも設定がありますが必要に応じて設定してください。

ServerTokens Prod
ServerSignature Off

VirutalHostを追加し、IdPにアクセスできるようにします。

環境により色々設定の仕方があると思いますので以下は参考までに。

※localhost:80はstatusコマンド等で利用されますので、設定しておいてください。

<VirtualHost localhost:80>
    ProxyPass /idp/ http://localhost:8080/idp/ connectiontimeout=5 timeout=15
</VirtualHost>

<VirtualHost *:443>
    ServerName idp.example.internal
    ServerAdmin admin@example.internal
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    SSLEngine on
    SSLProxyEngine On
    SSLCertificateFile /etc/apache2/ssl/idp.crt
    SSLCertificateKeyFile /etc/apache2/ssl/idp.key
    ProxyRequests Off
    ProxyPreserveHost On

    RequestHeader set X-Forwarded-Port 443
    RequestHeader set X-Forwarded-Proto https
    RequestHeader unset Forwarded
    RequestHeader unset X-Forwarded-For
    ProxyPass /idp/ http://localhost:8080/idp/ connectiontimeout=5 timeout=15
        
    <Location /idp>
        Order allow,deny
        Allow from all
    </Location>
</VirtualHost>

VirtualHostを有効化し、Apacheを起動します。

$ sudo a2ensite <作成したVirtualhost設定>
$ sudo systemctl enable --now apache2

Shibboleth IdPのインストール


Shibbolethのサイトからダウンロードして、インストールします。

$ cd ~
$ wget https://shibboleth.net/downloads/identity-provider/latest/shibboleth-identity-provider-5.0.0.tar.gz
$ sudo tar xzvf shibboleth-identity-provider-5.0.0.tar.gz
$ cd shibboleth-identity-provider-5.0.0
$ sudo ./bin/install.sh

画面の指示に従い必要事項を入力しながら進めてください。

確認される項目はInstallation Directory、Host Name、SAML EntityID、Attribute Scopeです。 表示内容に問題なければそのままEnterで進め、修正する場合は修正内容を入力してください。

$ sudo ./bin/install.sh
Installation Directory: [/opt/shibboleth-idp] ? 

INFO  - New Install.  Version: 5.0.0
Host Name: [172.21.175.80] ? 
idp.example.internal
INFO  - Creating idp-signing, CN = idp.example.internal URI = https://idp.example.internal/idp/shibboleth, keySize=3072
INFO  - Creating idp-encryption, CN = idp.example.internal URI = https://idp.example.internal/idp/shibboleth, keySize=3072
INFO  - Creating backchannel keystore, CN = idp.example.internal URI = https://idp.example.internal/idp/shibboleth, keySize=3072
INFO  - Creating Sealer KeyStore
INFO  - No existing versioning property, initializing...
SAML EntityID: [https://idp.example.internal/idp/shibboleth] ? 

Attribute Scope: [example.internal] ? 

INFO  - Initializing OpenSAML using the Java Services API
INFO  - Algorithm failed runtime support check, will not be usable: http://www.w3.org/2001/04/xmlenc#ripemd160
INFO  - Algorithm failed runtime support check, will not be usable: http://www.w3.org/2001/04/xmldsig-more#hmac-ripemd160
INFO  - Algorithm failed runtime support check, will not be usable: http://www.w3.org/2001/04/xmldsig-more#rsa-ripemd160
INFO  - Algorithm failed runtime support check, will not be usable: http://www.w3.org/2007/05/xmldsig-more#sha1-rsa-MGF1
INFO  - Algorithm failed runtime support check, will not be usable: http://www.w3.org/2007/05/xmldsig-more#sha224-rsa-MGF1
INFO  - Algorithm failed runtime support check, will not be usable: http://www.w3.org/2007/05/xmldsig-more#sha256-rsa-MGF1
INFO  - Algorithm failed runtime support check, will not be usable: http://www.w3.org/2007/05/xmldsig-more#sha384-rsa-MGF1
INFO  - Algorithm failed runtime support check, will not be usable: http://www.w3.org/2007/05/xmldsig-more#sha3-224-rsa-MGF1
INFO  - Algorithm failed runtime support check, will not be usable: http://www.w3.org/2007/05/xmldsig-more#sha3-256-rsa-MGF1
INFO  - Algorithm failed runtime support check, will not be usable: http://www.w3.org/2007/05/xmldsig-more#sha3-384-rsa-MGF1
INFO  - Algorithm failed runtime support check, will not be usable: http://www.w3.org/2007/05/xmldsig-more#sha3-512-rsa-MGF1
INFO  - Algorithm failed runtime support check, will not be usable: http://www.w3.org/2007/05/xmldsig-more#sha512-rsa-MGF1
INFO  - Creating Metadata to /opt/shibboleth-idp/metadata/idp-metadata.xml
INFO  - Rebuilding /opt/shibboleth-idp/war/idp.war, Version 5.0.0
INFO  - Initial populate from /opt/shibboleth-idp/dist/webapp to /opt/shibboleth-idp/webpapp.tmp
INFO  - Overlay from /opt/shibboleth-idp/edit-webapp to /opt/shibboleth-idp/webpapp.tmp
INFO  - Creating war file /opt/shibboleth-idp/war/idp.war

jettyを起動します。

$ sudo systemctl start jetty

Shibbolethの状態を確認します。

$ /opt/shibboleth-idp/bin/status.sh

正常に起動しましたらShibbolethの各種設定を環境に合わせて実施してください。

参考情報


Shibboleth Wiki

Amazon Corretto 17 Installation Instructions for Debian-Based, RPM-Based and Alpine Linux Distributions

シボレス Wikipedia

Jetty -Wikipedia


執筆者プロフィール:田平 隆馬
インフラSEとして約20年のキャリアを経て、2023年11月にSHIFT入社。
得意領域はActive DirectoryやLDAPなどの認証システム。

お問合せはお気軽に

SHIFTについて(コーポレートサイト)
https://www.shiftinc.jp/

SHIFTのサービスについて(サービスサイト)
https://service.shiftinc.jp/

SHIFTの導入事例
https://service.shiftinc.jp/case/

お役立ち資料はこちら
https://service.shiftinc.jp/resources/

SHIFTの採用情報はこちら

PHOTO:UnsphashMohammad Rahmani


みんなにも読んでほしいですか?

オススメした記事はフォロワーのタイムラインに表示されます!