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?

OAC と OAI の違い(CloudFront + S3)

0
Posted at

AWSのCloudFrontからS3へ安全にアクセスさせる方法として、

  • OAI(Origin Access Identity)
  • OAC(Origin Access Control)

があります。

現在は:

OAC が新世代
OAI は旧方式

です。


まず何をしたい仕組みか

通常、S3をWeb公開すると:

https://bucket.s3.amazonaws.com

へ直接アクセスできてしまいます。

しかし本来は:

CloudFront経由だけ許可したい

ことが多いです。

そのため:

CloudFrontだけがS3へアクセス可能

にする仕組みが必要になります。


OAI(旧方式)

正式名:

Origin Access Identity


仕組み

CloudFront専用の仮想ユーザーを作ります。

CloudFront専用IAMユーザーみたいなもの

をS3バケットポリシーで許可。


イメージ

User
 ↓
CloudFront
 ↓(OAI)
S3

S3側

Principal: {
  AWS: "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ..."
}

を許可。


OAC(新方式)

正式名:

Origin Access Control


特徴

CloudFrontが:

SigV4署名付きリクエスト

でS3へアクセスします。

つまり:

「CloudFront本人である証明」

を付けてアクセス。


イメージ

User
 ↓
CloudFront
 ↓(署名付きアクセス)
S3

最大の違い

OAI

IAMユーザー的

OAC

CloudFrontサービスプリンシパル
+ SigV4署名

なぜOACが推奨?

AWS公式でも現在はこちら推奨です。

CloudFront OAC公式ドキュメント


OACのメリット

① セキュリティ強化

SigV4署名。

よりAWS標準。


② SSE-KMS対応が強い

KMS暗号化S3との相性が良い。


③ 全HTTPメソッド対応

PUT
POST
DELETE
など。


④ 将来性

AWSはOAC推奨。

新機能もOAC中心。


OAIの弱点

古い仕組み

レガシー寄り。


機能制限

一部制約あり。


将来的に非推奨方向

完全廃止ではないですが、

「新規ならOAC」

が基本。


CDKでの違い


OAI(旧)

const oai = new cloudfront.OriginAccessIdentity(this, 'OAI');

bucket.grantRead(oai);

new cloudfront.Distribution(this, 'Dist', {
  defaultBehavior: {
    origin: new origins.S3Origin(bucket, {
      originAccessIdentity: oai,
    }),
  },
});

OAC(新)

最近のCDKでは:

new origins.S3BucketOrigin(bucket)

などで自動的にOAC寄りの構成になるケースがあります。

または:

originAccessControl

を利用。


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?