こちらのページで基本的な使い方を把握した GCP DLP に相当する AWS サービスに Amazon Comprehend が存在します。GCP VPC 内から Public Internet を経由せずに利用する設定の例を記載します。
クラウド | 項目 | 値 |
---|---|---|
AWS | VPC region | ap-northeast-1 |
AWS | VPC CIDR | 10.2.0.0/16 |
AWS | ap-northeast-1b | 10.2.2.0/24 |
AWS | ap-northeast-1c | 10.2.3.0/24 |
AWS | DNS hostnames | Disabled/Enabled (どちらでも可) |
GCP | asia-northeast1 | 10.1.1.0/24 |
GCP | asia-northeast1 | 10.8.0.0/28 (Serverless VPC access を利用する場合) |
GCP | Private Google Access | On |
参考資料: AWS VPC と GCP VPC を VPN 接続するための設定例
Priority | Direction of traffic | Action on match | IP ranges |
---|---|---|---|
65534 | Ingress | Deny | 0.0.0.0/0 |
65534 | Egress | Deny | 0.0.0.0/0 |
1000 | Ingress | Allow | 35.235.240.0/20 |
1000 | Egress | Allow | 199.36.153.4/30 |
1000 | Egress | Allow | 10.2.0.0/16 |
参考資料:
VPC Service Controls に関する雑多な事項の整理
グローバルIP を持たない GCP VM への SSH 接続方法
項目 | 値 |
---|---|
DNS 種別 | Response policy |
DNS type | A |
*.googleapis.com | 199.36.153.4 |
*.googleapis.com | 199.36.153.5 |
*.googleapis.com | 199.36.153.6 |
*.googleapis.com | 199.36.153.7 |
参考資料: VPC Service Controls に関する雑多な事項の整理
クラウド | 項目 | 値 |
---|---|---|
AWS | VPC route propagation | Yes (応答するパケットを返すときにはルートが必要です) |
AWS | EC2 security group Allow Inbound | 10.1.1.0/24 |
AWS | VPCE security group Allow Inbound | 10.1.1.0/24, 10.8.0.0/28, 10.2.0.0/16 |
参考資料: AWS VPC と GCP VPC を VPN 接続するための設定例
項目 | チェック |
---|---|
Programmatic access | O |
AWS Management Console access | X |
AmazonS3FullAccess | O |
iam:PassRole | 下記参照 |
comprehend:* | 下記参照 |
Inline Poliy 等によって付与
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Resource": "*",
"Action": [
"comprehend:DetectEntities",
"comprehend:BatchDetectEntities",
"comprehend:StartEntitiesDetectionJob",
"comprehend:ListEntitiesDetectionJobs",
"comprehend:DescribeEntitiesDetectionJob",
"comprehend:StopEntitiesDetectionJob",
"comprehend:DetectPiiEntities",
"comprehend:ContainsPiiEntities",
"comprehend:StopPiiEntitiesDetectionJob",
"comprehend:ListPiiEntitiesDetectionJobs",
"comprehend:DescribePiiEntitiesDetectionJob",
"comprehend:StartPiiEntitiesDetectionJob",
"comprehend:DetectDominantLanguage"
]
},
{
"Effect": "Allow",
"Resource": "arn:aws:iam::123412341234:role/my-comprehend-role",
"Action": [
"iam:PassRole"
],
"Condition": {
"StringEquals": {
"iam:PassedToService": "comprehend.amazonaws.com"
}
}
}
]
}
Comprehend が S3 にアクセスする際に利用する IAM Role を作成します。
項目 | 値 |
---|---|
ARN | arn:aws:iam::123412341234:role/my-comprehend-role |
Trust Relationship | 下記参照 |
Permissions | 下記参照 |
Trust Relationship
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "comprehend.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Permissions
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::my-comprehend-bucket-20210905",
"arn:aws:s3:::my-comprehend-bucket-20210905/*"
]
},
{
"Effect": "Allow",
"Action": [
"ec2:CreateNetworkInterface",
"ec2:CreateNetworkInterfacePermission",
"ec2:DeleteNetworkInterface",
"ec2:DeleteNetworkInterfacePermission",
"ec2:DescribeNetworkInterfaces",
"ec2:DescribeVpcs",
"ec2:DescribeDhcpOptions",
"ec2:DescribeSubnets",
"ec2:DescribeSecurityGroups"
],
"Resource": "*"
}
]
}
参照資料:
簡単のため、以下の設定で作成します。AWS IAM User の Secret access key を格納します。
項目 | 値 |
---|---|
Replication policy | asia-northeast1, asia-northeast2 |
Encryption | google-managed |
Rotation | None |
Notifications | None |
Expiration | Never |
Permissions |
roles/secretmanager.secretAccessor (GCE および Cloud Functions の Service Account) |
参考資料:
latest
を使わずに特定の version を指すようにします。roles/secretmanager.secretAccessor
を利用します。roles/editor
と roles/viewer
は secret 値を参照できません。クラウド | 項目 | 値 |
---|---|---|
GCP | Region | asia-northeast1 |
GCP | Access scopes | Allow full access to all Cloud APIs (cloud-platform) |
GCP | External IP | None |
AWS | Public IP address | None |
AWS | security group | 10.1.1.0/24 からの通信を許可 |
参考資料:
cloud-platform
を選択することで IAM による制御のみに切り換えます。項目 | 値 |
---|---|
com.amazonaws.ap-northeast-1.comprehend | Interface |
com.amazonaws.ap-northeast-1.s3 | Interface |
ap-northeast-1b | O |
ap-northeast-1c | O |
Enable DNS name | O/X (どちらでも可) |
security group | 10.1.1.0/24, 10.8.0.0/28, 10.2.0.0/16 からの通信を許可 |
Policy | 下記参照 |
参考資料: AWS VPC 内の PrivateLink VPC Endpoint を VPN 接続された GCP VPC および別の AWS VPC から利用するための設定例
{
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": [
"comprehend:*",
"iam:PassRole"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:PrincipalAccount": "123412341234"
}
}
}
]
}
{
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::my-comprehend-bucket-20210905",
"arn:aws:s3:::my-comprehend-bucket-20210905/*"
],
"Condition": {
"StringEquals": {
"aws:PrincipalAccount": "123412341234"
}
}
}
]
}
参考資料:
項目 | 値 |
---|---|
com.amazonaws.ap-northeast-1.s3 | Gateway |
Route Tables | O |
Policy | 下記参照 |
{
"Version": "2008-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::my-comprehend-bucket-20210905",
"arn:aws:s3:::my-comprehend-bucket-20210905/*"
],
"Condition": {
"StringEquals": {
"aws:PrincipalAccount": "123412341234"
}
}
}
]
}
参考資料:
値 | 項目 |
---|---|
バケット名 | my-comprehend-bucket-20210905 |
Policy | 下記参照 |
{
"Statement": [
{
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::my-comprehend-bucket-20210905",
"arn:aws:s3:::my-comprehend-bucket-20210905/*"
],
"Condition": {
"StringNotEquals": {
"aws:sourceVpce": [
"vpce-xxxxxxxxxxxxxxxxx",
"vpce-yyyyyyyyyyyyyyyyy"
],
"aws:PrincipalArn": "arn:aws:iam::123412341234:user/myadmin"
}
}
}
]
}
参照資料:
export AWS_DEFAULT_REGION=ap-northeast-1
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX
export AWS_SECRET_ACCESS_KEY=$(gcloud secrets versions access latest --secret my-aws-iam)
aws --endpoint-url https://vpce-xxxxxxxxxxxxxxxxx-xxxxxxxx.comprehend.ap-northeast-1.vpce.amazonaws.com \
comprehend detect-dominant-language --text "It is raining today in Seattle."
aws --endpoint-url https://vpce-xxxxxxxxxxxxxxxxx-xxxxxxxx.comprehend.ap-northeast-1.vpce.amazonaws.com \
comprehend detect-entities --text "私は田中です。こんにちは" \
--language-code ja
aws --endpoint-url https://vpce-xxxxxxxxxxxxxxxxx-xxxxxxxx.comprehend.ap-northeast-1.vpce.amazonaws.com \
comprehend detect-pii-entities --text "My Phone number is 090-1111-2222" \
--language-code en
aws --endpoint-url https://bucket.vpce-xxxxxxxxxxxxxxxxx-xxxxxxxx.s3.ap-northeast-1.vpce.amazonaws.com \
s3 ls s3://my-comprehend-bucket-20210905/
python3 sample.py
sample.py
import boto3
import json
comprehend = boto3.client(service_name='comprehend', endpoint_url='https://vpce-xxxxxxxxxxxxxxxxx-xxxxxxxx.comprehend.ap-northeast-1.vpce.amazonaws.com')
text = "It is raining today in Seattle"
print('Calling DetectDominantLanguage')
print(json.dumps(comprehend.detect_dominant_language(Text = text), sort_keys=True, indent=4))
print("End of DetectDominantLanguage\n")
参考資料:
--endpoint-url
には PrivateLink 作成時に生成された URL を指定します。項目 | 値 |
---|---|
Project | myproject-20210411 |
Restricted Services | All |
VPC Accessible Services | RESTRICTED-SERVICES |
Access Levels | my-dev-machine-ip |
Ingress policy From Identities | xxxxxxxxxxxx@cloudbuild.gserviceaccount.com |
Ingress policy From Source | All sources allowed |
Ingress policy To Projects | myproject-20210411 |
Ingress policy To Services | All services |
参考資料:
項目 | 値 |
---|---|
Region | asia-northeast1 |
Subnet | 10.8.0.0/28 |
Minimum instances | 2 |
Maximum instances | 10 |
Instance type | e2-micro |
参考資料:
Organization Policy Administrator (roles/orgpolicy.policyAdmin) で設定します。Cloud Functions 動作時の通信を VPC 内に閉じ込めるための設定です。
項目 | 値 |
---|---|
cloudfunctions.allowedIngressSettings | ALLOW_INTERNAL_ONLY |
cloudfunctions.requireVPCConnector | Enforce |
cloudfunctions.allowedVpcConnectorEgressSettings | ALL_TRAFFIC |
参考資料:
項目 | 値 |
---|---|
Region | asia-northeast1 |
AWS_DEFAULT_REGION | ap-northeast-1 |
AWS_ACCESS_KEY_ID | XXXXXXXXXXXXXXXXXXXX |
Ingress settings | Allow internal traffic only |
Egress settings | Route all traffic through the VPC connector |
Reference a Secret | AWS_SECRET_ACCESS_KEY |
Runtime | Python 3.9 |
main.py
import boto3
import json
def hello_world(request):
s3 = boto3.resource('s3', endpoint_url='https://bucket.vpce-xxxxxxxxxxxxxxxxx-xxxxxxxx.s3.ap-northeast-1.vpce.amazonaws.com')
my_bucket = s3.Bucket('my-comprehend-bucket-20210905')
for my_bucket_object in my_bucket.objects.all():
print(my_bucket_object)
comprehend = boto3.client(service_name='comprehend', endpoint_url='https://vpce-xxxxxxxxxxxxxxxxx-xxxxxxxx.comprehend.ap-northeast-1.vpce.amazonaws.com')
text = "It is raining today in Seattle"
return json.dumps(comprehend.detect_dominant_language(Text = text), sort_keys=True, indent=4)
requirements.txt
boto3==1.18.36
出力例
{
"Languages": [
{
"LanguageCode": "en",
"Score": 0.9925304651260376
}
],
"ResponseMetadata": {
"HTTPHeaders": {
"content-length": "64",
"content-type": "application/x-amz-json-1.1",
"date": "Sun, 05 Sep 2021 14:21:50 GMT",
"x-amzn-requestid": "8c1561be-ac8f-4591-b9c9-e3e7f9efe594"
},
"HTTPStatusCode": 200,
"RequestId": "8c1561be-ac8f-4591-b9c9-e3e7f9efe594",
"RetryAttempts": 0
}
}
参考資料:
s3://my-comprehend-bucket-20210905/input/sample.txt
こんにちは。私の名前は田中です。
実行例
aws --endpoint-url https://vpce-xxxxxxxxxxxxxxxxx-xxxxxxxx.comprehend.ap-northeast-1.vpce.amazonaws.com \
comprehend start-entities-detection-job \
--input-data-config S3Uri=s3://my-comprehend-bucket-20210905/input/ \
--output-data-config S3Uri=s3://my-comprehend-bucket-20210905/output/ \
--data-access-role-arn arn:aws:iam::123412341234:role/my-comprehend-role \
--job-name reviews-entities-analysis \
--language-code ja \
--vpc-config SecurityGroupIds=sg-0cd4e94d4c206acdc,Subnets=subnet-07820d34f9d239941,subnet-04b91b3ac40ebe829
aws --endpoint-url https://vpce-xxxxxxxxxxxxxxxxx-xxxxxxxx.comprehend.ap-northeast-1.vpce.amazonaws.com \
comprehend describe-entities-detection-job \
--job-id 2425a650c688f62dfbeffe1a966e736b
出力例
cat output | jq .
{
"Entities": [
{
"BeginOffset": 11,
"EndOffset": 13,
"Score": 0.9976550619896744,
"Text": "田中",
"Type": "PERSON"
}
],
"File": "sample.txt",
"Line": 0
}
参考資料:
--vpc-config
によって ENI を VPC 内に作成するのがポイントです。AWS Organizations を利用した opt-out policy の設定、またはサポートに問い合わせることで、AI サービス品質向上のためのデータ提供に関してオプトアウトの設定が可能です。
参考資料: Easily manage your content policies for AI services with AWS Organizations