LoginSignup
0

More than 5 years have passed since last update.

awscliでS3のパーミッションを確認する

Posted at

余計なパーミッション付いてるのないよねというのを確認したい。全部なめるしかないのか。つらい。

期待しているACLの状態

Granteeがひとつだけだよねというのを確認したい。

{
    "Owner": {
        "DisplayName": "john",
        "ID": "222222222222"
    },
    "Grants": [
        {
            "Grantee": {
                "Type": "CanonicalUser",
                "DisplayName": "john",
                "ID": "111111111111"
            },
            "Permission": "FULL_CONTROL"
        }
    ]
}

ひとつずつやるなら

Grantsが複数ある場合、キーを出力する。

for key in $(aws s3 ls s3://$BUCKET --recursive | awk '{print $4}'); do if $(aws s3api get-object-acl --bucket $BUCKET --key $key | jq '.Grants | length != 1'); then echo $key >> result.txt; fi; done

xargsで並列でやるなら

xargsに渡されたインプットを条件次第でechoしたかったので関数のかたちにした。

zshfunc_acl
function acl() {
  if $(aws s3api get-object-acl --bucket $1 --key "$2" | jq '.Grants | length != 1');
    then echo $2 | tee result.txt;
  fi
}

xargsで立ち上がるのは別プロセスだから関数定義を読み込まないといけないよね。
xargsでzshの自作シェル関数を使う - Qiita

aws s3 ls s3://$BUCKET --recursive | awk '{print $4}' | xargs -P4 -I{} zsh -c ". ./zshfunc_acl; acl $BUCKET {}"

雑だけどとりあえずこれで確認した。

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