GeekFactory

int128.hatenablog.com

GitLabのSAML SSO認証失敗とシステム時刻

とあるところで運用しているGitLab/Keycloakで発生した障害のメモ。

事象

GitLabにSAML SSOでログインしようとすると500エラーが表示される。GitLabとKeycloakの構成は以下で紹介した通りとなっている。

int128.hatenablog.com

原因

GitLab Omnibusのコンテナで以下のログが出力されていた。

root@gitlab-5fbbf4957d-r5vrc:/# tail -f /var/log/gitlab/unicorn/unicorn_stdout.log

E, [2019-08-13T02:07:13.128716 #11554] ERROR -- omniauth: (saml) Authentication failure! invalid_ticket: OneLogin::RubySaml::ValidationError, Current time is earlier than NotBefore condition (2019-08-13 02:07:13 UTC < 2019-08-13 02:07:14 UTC)

GitLabとKeycloakのシステム時刻がずれているため、SAML認証が失敗している。厳密には、KeycloakがGitLabに返したSAMLレスポンスに含まれる日時(NotBefore)が未来になっていることが原因である。

GitLab Issuesを調べたところ、本件と同じ事象である OmniAuth/SAML Logins Fail with notbefore related error (#59466) · Issues · GitLab.org / GitLab Community Edition · GitLab が見つかった。

暫定対処

GitLabとKeycloakが同一のシステム時刻になるように構成を変更した。

恒久対処

https://docs.gitlab.com/ce/integration/saml.html#allowed_clock_drift のオプションが使えるはずだが未確認。

args: {
        allowed_clock_drift: 60
}