📝

AppSync の API キーを AWS CLI から削除した場合の挙動について

に公開

AWS CLI の delete-api-key コマンドで API キーを削除した場合、追加の認証モードに API キーの設定が残存する場合がありました。

  • コンソールから追加の認証モードに API キーを設定
  • delete-api-key コマンドで API キーを削除
  • コンソール上では追加の認証モードに何も表示されない
  • get-graphql-api コマンドの結果には API キーの設定が残存している
  • コンソールから API キーを削除した場合には発生しない

再現してみた

以下の状態からスタートします。

  • GraphQL API を作成
  • プライマリ認証モードには IAM 認証
  • 追加の認証モードに API キー

現在の状態を get-graphql-api コマンドで確認した結果は以下の通りです。

$ aws appsync get-graphql-api \
--api-id knao7zw2jrfdthiua2y223tjlm
{
    "graphqlApi": {
        "name": "My AppSync API",
        "apiId": "knao7zw2jrfdthiua2y223tjlm",
        "authenticationType": "AWS_IAM",
        "arn": "arn:aws:appsync:ap-northeast-1:012345678901:apis/knao7zw2jrfdthiua2y223tjlm",
        "uris": {
            "REALTIME": "wss://36rfis4ee5gchbbz45e4dlauf4.appsync-realtime-api.ap-northeast-1.amazonaws.com/graphql",
            "GRAPHQL": "https://36rfis4ee5gchbbz45e4dlauf4.appsync-api.ap-northeast-1.amazonaws.com/graphql"
        },
        "tags": {},
        "additionalAuthenticationProviders": [
            {
                "authenticationType": "API_KEY"
            }
        ],
        "xrayEnabled": false,
        "dns": {
            "REALTIME": "36rfis4ee5gchbbz45e4dlauf4.appsync-realtime-api.ap-northeast-1.amazonaws.com",
            "GRAPHQL": "36rfis4ee5gchbbz45e4dlauf4.appsync-api.ap-northeast-1.amazonaws.com"
        },
        "visibility": "GLOBAL",
        "apiType": "GRAPHQL",
        "owner": "012345678901",
        "introspectionConfig": "ENABLED",
        "queryDepthLimit": 0,
        "resolverCountLimit": 0
    }
}

additionalAuthenticationProviders > authenticationType に API_KEY が設定されていることを確認できます。

この状態で delete-api-key コマンドを実行します。

$ aws appsync delete-api-key \
--api-id knao7zw2jrfdthiua2y223tjlm \
--id da2-ao5pjvqn6faj7jr7uxgj6v4qce

コンソールでは追加の認証モードに何も表示されなくなりました。

一方、get-graphql-api コマンドの結果には additionalAuthenticationProviders > authenticationType に API_KEY が設定されていることを確認できます。

$ aws appsync get-graphql-api \
--api-id knao7zw2jrfdthiua2y223tjlm
{
    "graphqlApi": {
        "name": "My AppSync API",
        "apiId": "knao7zw2jrfdthiua2y223tjlm",
        "authenticationType": "AWS_IAM",
        "arn": "arn:aws:appsync:ap-northeast-1:012345678901:apis/knao7zw2jrfdthiua2y223tjlm",
        "uris": {
            "REALTIME": "wss://36rfis4ee5gchbbz45e4dlauf4.appsync-realtime-api.ap-northeast-1.amazonaws.com/graphql",
            "GRAPHQL": "https://36rfis4ee5gchbbz45e4dlauf4.appsync-api.ap-northeast-1.amazonaws.com/graphql"
        },
        "tags": {},
        "additionalAuthenticationProviders": [
            {
                "authenticationType": "API_KEY"
            }
        ],
        "xrayEnabled": false,
        "dns": {
            "REALTIME": "36rfis4ee5gchbbz45e4dlauf4.appsync-realtime-api.ap-northeast-1.amazonaws.com",
            "GRAPHQL": "36rfis4ee5gchbbz45e4dlauf4.appsync-api.ap-northeast-1.amazonaws.com"
        },
        "visibility": "GLOBAL",
        "apiType": "GRAPHQL",
        "owner": "012345678901",
        "introspectionConfig": "ENABLED",
        "queryDepthLimit": 0,
        "resolverCountLimit": 0
    }
}

影響について

上記挙動の影響の一つとして、Security Hub のコントロールである AppSync.5 への影響があります。
Security Hub controls for AWS AppSync - AWS Security Hub

当該コントロールでは認証に API キーを使用しないことが条件となっています。
上記挙動が発生した場合、コンソール上では追加の認証モードに API キーが使用されていないため、一見すると Security Hub 側で FAILED として検出されている原因がわかりづらい場合があります。

上記挙動になった場合、update-graphql-api コマンドで追加の認証モードの設定を更新することで解決できます。

$ aws appsync update-graphql-api \
--api-id knao7zw2jrfdthiua2y223tjlm \
--name "My AppSync API" \
--authentication-type "AWS_IAM" \
--additional-authentication-providers "[]"

{
    "graphqlApi": {
        "name": "My AppSync API",
        "apiId": "knao7zw2jrfdthiua2y223tjlm",
        "authenticationType": "AWS_IAM",
        "arn": "arn:aws:appsync:ap-northeast-1:012345678901:apis/knao7zw2jrfdthiua2y223tjlm",
        "uris": {
            "REALTIME": "wss://36rfis4ee5gchbbz45e4dlauf4.appsync-realtime-api.ap-northeast-1.amazonaws.com/graphql",
            "GRAPHQL": "https://36rfis4ee5gchbbz45e4dlauf4.appsync-api.ap-northeast-1.amazonaws.com/graphql"
        },
        "tags": {},
        "xrayEnabled": false,
        "visibility": "GLOBAL",
        "apiType": "GRAPHQL",
        "owner": "012345678901",
        "introspectionConfig": "ENABLED",
        "queryDepthLimit": 0,
        "resolverCountLimit": 0
    }
}

まとめ

今回は AppSync の API キーを AWS CLI から削除した場合の挙動について紹介しました。
AWS からのヒアリングにご協力頂きありがとうございます。
ヒアリング結果については AWS にも連携し、継続調査を実施しております。

参考資料

Discussion