LoginSignup
6
3

More than 5 years have passed since last update.

IBM Cloud Object Storage (ICOS) の認証方式について調べてみた

Last updated at Posted at 2019-03-26

認証方式は2つある

※ IAM = Identity and Access Management
※ HMAC = Hash-based Message Authentication Code

  • IAM トークン認証方式
    • IAM API key を使って、IAM endpoint で 1 時間有効なトークンを発行し、そのトークンを使ってアクセスする方式です
    • ICOS 用の SDK があり、AWS S3 SDK から IBM Cloud IAM 向けに一部カスタマイズされている

The IAM endpoint (iam.cloud.ibm.com) is used to fetch an access token in exchange for an API key.
This token is used in the Authorization header in all REST API requests sent to an Object Storage service endpoint.
There are IBM COS SDKs available for Python, Java, and Node.js. These are forked versions of the AWS S3 SDKs that have been modified to support IAM token-based authentication, as well as support for Key Protect.

  • HMAC 認証方式
    • access key と secret key からハッシュ関数を使って作成される署名を用いて、認証する方式です
    • 「AWS Signature Version 4」と互換性があるので、S3 互換のツールやライブラリで問題なく動作するはず

In addition to IAM token-based authentication, it is also possible to authenticate using a signature created from a pair of access and secret keys. This is functionally identical to the AWS Signature Version 4, and HMAC keys provided by IBM COS should work with the majority of S3-compatible libraries and tools.

2つの認証方式の間の差異

IAM API key を使った IAM トークン認証方式のほうが、IAM での権限設定を使って、より詳細にアクセス制御を行える。
一方で、HMAC キーは AWS CLI や Cyberduck などの S3 互換ツールを使う際に必要になる。

While IAM API keys allow for much stronger and fine-grained access control, HMAC keys are required for using S3-compatible tools and gateways (such as the AWS CLI or Cyberduck).

IAM トークン認証方式

注意点としては、トークン発行の際に IAM エンドポイント (iam.cloud.ibm.com) を使う必要がある点です。
IAM エンドポイントはパブリックのみで提供しているので、パブリック経由でアクセスできる必要があります。(プライベートのみ環境では使えません)
トークンだけパブリックで取って、その後のアクセスはプライベートという使い方は可能です。

iam.cloud.ibm.com - ibm IP Location
Host: iam.cloud.ibm.com
IP: 104.108.50.236
Hostname: a104-108-50-236.deploy.static.akamaitechnologies.com
ISP: Akamai Technologies
Organization: Akamai Technologies
City:
Region:
Country: Netherlands
Timezone:
Longitude: 4.899500
Latitude: 52.382400

IAM トークン取得方法

curl (REST API) を使って取得

以下のドキュメントにある通りです。
apikey は、ICOS の Service Credential 内にある「apikey」を使います。

Getting an IBM Cloud IAM token by using an API key - IBM Cloud Docs

入力
curl -k -X POST \
  --header "Content-Type: application/x-www-form-urlencoded" \
  --header "Accept: application/json" \
  --data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey" \
  --data-urlencode "apikey=<apikey>" \
  "https://iam.cloud.ibm.com/identity/token"
出力
{
  "access_token": "eyJhbGciOiJIUz......sgrKIi8hdFs",
  "refresh_token": "SPrXw5tBE3......KBQ+luWQVY=",
  "token_type": "Bearer",
  "expires_in": 3600,
  "expiration": 1473188353
}

Kobito.fGGgMg.png

CLI

IBM Cloud CLI を使って、以下のように取得できます

Getting an IAM token - IBM Cloud Docs

入力
ibmcloud login
ibmcloud iam oauth-tokens
出力
IAM token:  Bearer XXXXXXXXXX
UAA token:  bearer YYYYYYYYYY

HMAC 認証方式

HMAC 認証の場合、パブリック経由でもアクセスできますが、
プライベートオンリー環境でもプライベート経由だけでアクセスを完結できます
(トークン取得のためにパブリックを経由することは不要)
各種バックアップソフトウェアなど S3 互換ツールを使う場合には、HMAC 認証の「access key id」「secret access key」を使いましょう。

注意点としては、Service Credential 発行の際に「HMAC認証情報を含める」にチェック入れて発行する必要がある点です。
以下の画面を参考にしてください。

Service Credentials
image.png
image.png
Kobito.N41qAI.png

まとめ

利用形態に合わせて、ぜひ使い分けてみてください。

参考リンク

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