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

閉域網からPrivateLink経由でAWSCLIを打鍵する構成を考える

Posted at

はじめに

Privateなネットワーク環境からAWS CLIを打鍵する際は、必ずPublicに出る必要があります。
今回、他クラウドからのAWS CLI打鍵を、VPN接続されたVPC内部通信を介して、決められたAWSの出口からのみ、AWSCLI用の通信を出せないかという話題が上がり、
他クラウドから打鍵するために、NetworkLoadBalancerのPrivateLink経由で出口を提供できないか検証してみました。

検証構成

シンプルにサブネットを分け、疑似的な閉域網を作りました。

kouseizu2.png

左側のEC2が他クラウドから接続されたクライアントの想定です。

設定

以下設定です。

Proxy

ルートテーブル

ProxyのEC2が存在するサブネットは、インターネットに向いたルートテーブルに所属しています。

ROute1.jpg

OS内部

ユーザーデータ経由でSquidをインストール&設定しています。

ユーザーデータ

#!/bin/bash -xe
yum update -y
yum install -y squid

# Configure Squid as a proxy
cat > /etc/squid/squid.conf << 'EOF'
acl SSL_ports port 443
acl Safe_ports port 80
acl Safe_ports port 443
acl Safe_ports port 1025-65535

http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager

# Allow AWS API endpoints
acl aws_endpoints dstdomain .amazonaws.com
http_access allow aws_endpoints

# Allow local network
acl localnet src 10.0.0.0/8
acl localnet src 172.16.0.0/12
acl localnet src 192.168.0.0/16
http_access allow localnet

http_access allow localhost
http_access deny all

http_port ${ProxyPort}

coredump_dir /var/spool/squid
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
EOF

# Start Squid service
systemctl enable squid
systemctl start squid

PrivateLink

ルートテーブル

PrivateLink 経由でトラフィックを強制的にProxyに流すだけなので、設定はデフォルト状態です。

Route2.jpg

PrivateLink設定

8080を転送するListen設定を入れたNLBがあります。

NLB.jpg

エンドポイントサービスを作り、自VPCにエンドポイントを公開しました。

エンドポイント2.jpg

Client EC2

ルートテーブル

デフォルトルートはNLBのENIを指定しております。

EC2.jpg

OS内部

プロキシをエンドポイントサービスのDNSに設定しています。

EC2-naka.jpg

結果

無事にAWS CLIを打鍵できました。
kekka.jpg

※プロキシ設定を入れない状態だとタイムアウトになります。

その他

PrivateLinkを作らなくても、NLBまたは直EC2プロキシ指定で、閉域網を通じたアクセスは可能ですが、
PrivateLink経由だとスケーラビリティの向上が見込めるようです(未検証)
必要に応じて後日検証できればしようと思います。

決まった内容のAWS CLIを打鍵するのみだと、APIGateway、Lambdaで構成する方がコストメリットはあると思います。複数のAWS CLIを打つ必要がある場合は、この構成(プロキシ経由)がよいかなと思ってます。
ご意見あればコメント頂けると嬉しいです。

ToDo

なお、AWS CLI用のプロキシは、~/.aws/config に設定する形でも可…のはずだがうまく通らない…ので後日検証する

[default]
cli_http_proxy = http://your-proxy:port/
cli_https_proxy = http://your-proxy:port/
0
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
0
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?