3
0

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.

Googleの二要素認証をコマンド一発で済ませてくれるドットコンテナを作りました。

Last updated at Posted at 2018-12-08

【楽したい】

クラウド環境上にあるサーバーに入って何か作業をする際、マネジメントコンソールや踏み台サーバへのログインするために、わざわざスマホを出して手で打ち込むんでいる人居ませんか?
セキュリティは大事ですけど、面倒ですよね~。

そんなGoogleの二要素認証を、コマンド一発で楽にしてくれるコンテナを作成しました。
下記記載のDockerfileからビルド起動したあと、ホスト側でコマンドエイリアスを設定することで、認証用コマンドを生成できちゃいます。

Dockerfile
FROM ubuntu:trusty
MAINTAINER Kato Haruki
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -y update 
RUN apt-get -y upgrade
ENV TZ Asia/Tokyo
RUN apt-get -y install sudo vim tar less oathtool
一応Gitにも挙げておきました。
https://github.com/katoharuki/container_for_google_auth

以下設定の流れ

下記URLのDockerfileからビルド後、ホスト側にてちょろと設定したらおしまいです。
https://github.com/katoharuki/container_for_google_auth

[root@localhost ~]# cat ~/.bashrc
alias google_key='docker exec -t コンテナ名 oathtool --totp -d 6 --time-step-size=30s --base32 "トークン"'
alias aws-01='echo PIN`google_key`'
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# source ~/.bashrc
[root@localhost ~]# 
[root@localhost ~]# 二要素認証のワンタイムパスが出力される。
[root@localhost ~]# google_key
777777
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# PIN付きもいける。
[root@localhost ~]# aws-01
PIN777777

備考

UbuntuのDockerfileを作るとき、以下のようなエラーメッセージも出ました。

■エラーメッセージ
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin:

(TERM is not set, so the dialog frontend is not usable.)
なにやら、フロントエンドからなんかしてあげないといけない模様。 -y つけてもダメな時ってあるんですね〜。
こういう時には、Docsに頼る。

第5章 インストールシステムの起動
https://www.debian.org/releases/sarge/s390/ch05s02.html.ja

なにやら、インストーラで使うユーザインタフェースを制御する環境変数を入れると解決できる模様です。
下記環境変数を与えてあげることで、インタラクティブを回避できるようになり、一発でビルドが通るようになりました〜。
DEBIAN_FRONTEND=noninteractive

<参考>

Ubuntu Weekly Recipe:第508回 Ubuntuでコマンドラインからワンタイムパスワードを扱う #gihyojp
https://gihyo.jp/admin/serial/01/ubuntu-recipe/0508

3
0
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?