LoginSignup
1
1

More than 1 year has passed since last update.

IBM Cloud: ibmcloud CLIがproxy経由で利用できることを確認してみた

Last updated at Posted at 2022-05-14

1. はじめに

APIを利用すれば東京リージョン・大阪リージョンでもprivate endpointに対応したAPIを呼び出すことができるが、残念ながらibmcloud CLIは本記事執筆時点では東京リージョン・大阪リージョンには対応していない。
ibmcloud CLIを実行するVSIがpublic gatewayやfloating IP経由でインターネットに直接アクセスできると良いのかもしれないが、セキュリティー上の要件でそういうアクセスを許可していないというシステムもまた多いと思われる。

一つの代替案は、(Forward) Proxyサーバーを構築し、

  • Proxyサーバーのみインターネットにアクセスする。それ以外のサーバーはインターネットに直接アクセスできない。
  • ProxyサーバーではFQDNでOutboundアクセスを制御する。
  • インターネットにアクセスする必要があるサーバーは、Proxyサーバー経由でのみインターネットにアクセス可能とする。

という構成であろう。ということで、本当にibmcloud CLIがproxyサーバー経由でアクセスできるかどうかを確認してみた。

2. ibmcloud CLIが導入されているサーバーの環境がPrivate onlyであることを確認

以下のようにインターネットには出れないことを確認。

pingできない
[root@syasuda-metavsi ~]# ping www.yahoo.co.jp
PING edge12.g.yimg.jp (183.79.250.123) 56(84) bytes of data.
^C
--- edge12.g.yimg.jp ping statistics ---
9 packets transmitted, 0 received, 100% packet loss, time 7999ms
port443で繋がらない
[root@syasuda-metavsi ~]# nmap -Pn www.yahoo.co.jp -p 443

Starting Nmap 6.40 ( http://nmap.org ) at 2022-05-13 10:37 UTC
Nmap scan report for www.yahoo.co.jp (182.22.28.252)
Host is up.
PORT    STATE    SERVICE
443/tcp filtered https

Nmap done: 1 IP address (1 host up) scanned in 2.40 seconds
curlでも繋がらない
[root@syasuda-metavsi ~]# curl -I https://www.yahoo.co.jp
(無応答)
当然、ibmcloudコマンドを実行しても繋がらない。
[root@syasuda-metavsi ~]# ibmcloud login -a cloud.ibm.com --apikey @ibmcloud_apikey_1756623 -r jp-tok
API endpoint: https://cloud.ibm.com
Authenticating...
^C
ibmcloudのDebug結果。アクセスできずにTimeoutが発生している。
[root@syasuda-metavsi ~]# IBMCLOUD_TRACE=true ibmcloud login -a cloud.ibm.com --apikey @ibmcloud_apikey_1756623 -r jp-tok
API endpoint: https://cloud.ibm.com
Authenticating...

REQUEST: [2022-05-13T10:26:18Z]
POST /identity/token HTTP/1.1
Host: iam.cloud.ibm.com
Accept: application/json
Accept-Language: en
Accept-Language: en-US
Authorization: [PRIVATE DATA HIDDEN]
Content-Type: application/x-www-form-urlencoded
User-Agent: IBM Cloud CLI 2.6.0 / linux

apikey=[PRIVATE DATA HIDDEN]&grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey&response_type=cloud_iam
Post "https://iam.cloud.ibm.com/identity/token": dial tcp 104.87.66.105:443: i/o timeout

API endpoint:   https://cloud.ibm.com
Region:
Not logged in.

REQUEST: [2022-05-13T10:26:48Z]
GET /ibm-cloud-cli-metadata/info.json HTTP/1.1
Host: download.clis.cloud.ibm.com
Accept: application/json
Accept-Language: en
Accept-Language: en-US
Content-Type: application/json
User-Agent: IBM Cloud CLI 2.6.0 / linux



Warning: unable to check latest CLI version.
TIP: use 'ibmcloud config --check-version=false' to disable update check.

FAILED
Unable to authenticate.

3. Proxyの設定をする

Squidはすでに構成済みで、10.0.0.4:3128で待ち受けているものとする。

[root@syasuda-metavsi ~]# export https_proxy=http://10.0.0.4:3128
curlでの動作確認
[root@syasuda-metavsi ~]# curl -I https://www.yahoo.co.jp
HTTP/1.1 200 Connection established

HTTP/1.1 200 OK
Content-Length: 0
Content-Type: text/html; charset=utf-8
Date: Fri, 13 May 2022 10:39:16 GMT
Etag: W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"
Vary: Accept-Encoding
X-Vcap-Request-Id: c35e52ad-bc11-4feb-5103-175aa9c43ebf
X-Xss-Protection: 1; mode=block
Age: 0
Connection: keep-alive
Server: ATS

4. ibmcloud CLI(Proxyあり)の動作確認

ibmcloudコマンドの実行(アクセス可能)
[root@syasuda-metavsi ~]# ibmcloud login -a cloud.ibm.com --apikey @ibmcloud_apikey_1756623 -r jp-tok
API endpoint: https://cloud.ibm.com
Authenticating...
OK

Targeted account xxx (xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) <-> xxxxxxx

Targeted region jp-tok


API endpoint:      https://cloud.ibm.com
Region:            jp-tok
User:              xxxxxxx@xx.xxx.xxx
Account:           xxx (xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) <-> xxxxxxx
Resource group:    No resource group targeted, use 'ibmcloud target -g RESOURCE_GROUP'
CF API endpoint:
Org:
Space:
CLIの更新確認(成功) 
[root@syasuda-metavsi ~]# ibmcloud update
Checking for updates...
No update required. Your CLI is already up-to-date.
To view available plugin updates, run 'ibmcloud plugin list'.
VPCPluginの新規導入(成功)
[root@syasuda-metavsi ~]# ibmcloud plugin install vpc-infrastructure
Looking up 'vpc-infrastructure' from repository 'IBM Cloud'...
Plug-in 'vpc-infrastructure[infrastructure-service] 4.0.3' found in repository 'IBM Cloud'
Attempting to download the binary file...
 18.99 MiB / 18.99 MiB [======================================================================================================================================================================================] 100.00% 0s
19910656 bytes downloaded
Installing binary...
OK
Plug-in 'vpc-infrastructure 4.0.3' was successfully installed into /root/.bluemix/plugins/vpc-infrastructure. Use 'ibmcloud plugin show vpc-infrastructure' to show its details.
VPCPluginの実行(成功)
[root@syasuda-metavsi ~]# ibmcloud is vpcs
Listing vpcs in all resource groups and region jp-tok under account IBM as user shiyasu@jp.ibm.com...
ID                                          Name               Status      Classic access   Default network ACL                   Default security group               Resource group
(略)
1
1
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
1
1