API 키는 할당량, 청구, 모니터링 목적으로 Google Cloud 프로젝트를 식별하는 간단한 문자열입니다. 개발자는 Google Cloud 콘솔에서 프로젝트에 API 키를 생성하고 API에 대한 모든 호출에 이 키를 쿼리 매개변수로 또는 요청 헤더에 포함합니다.
API 구성에 API 키 요구사항을 지정하면 API 게이트웨이가 이 API 키를 사용해서 연결된 Google Cloud 프로젝트를 조회합니다. API 키가 Google Cloud 프로젝트에서 또는 API가 사용 설정된 다른 Google Cloud 프로젝트 내에서 생성되지 않았으면 API 게이트웨이가 요청을 거부합니다.
API 키를 만들거나 Google Cloud 프로젝트 내에서 이미 제공된 API 키를 보려면 API 및 서비스 > 사용자 인증 정보 페이지로 이동합니다.
할당량과 같은 API 게이트웨이 기능을 사용하려면 클라이언트 애플리케이션이 연결된 Google Cloud 프로젝트를 API 게이트웨이가 식별할 수 있도록 API 키를 전달할 수 있습니다.
API 게이트웨이의 API 키 인증 정보
인증을 위해 API 키를 사용하는 경우 먼저 서비스에 대해 API 키 지원을 사용 설정해야 합니다.
다음 명령어를 입력합니다.
gcloud services enable MANAGED_SERVICE_NAME
MANAGED_SERVICE_NAME은 API를 배포할 때 만든 관리형 서비스의 이름을 지정합니다. 이 이름은 콘솔의 API 방문 페이지에서 API에 대한 관리형 서비스 열에서 찾을 수 있습니다. 또는 gcloud api-gateway apis describe 명령어를 사용할 때 Managed service 속성에서 이 이름을 찾을 수 있습니다.
API 키는 기본적으로 무제한 상태입니다. 무제한 키는 어디서나 사용할 수 있으므로 안전하지 않습니다. 가능하면 API 제한사항을 추가하는 것이 좋습니다.
API 제한사항은 API 키를 사용해서 호출할 수 있는 API를 지정합니다. 프로덕션 애플리케이션에서 사용하는 모든 API 키에는 API 제한사항이 있어야 합니다.
API 제한사항을 추가하려면 다음 안내를 따르세요.
API 구성에 명시된 API 제목을 찾습니다. 다음 예시에서 API 제목은 My Example Config입니다.
# openapi.yamlswagger:'2.0'info:title:My Example Configdescription:Sample API on API Gatewayversion:1.0.0...
Google Cloud 콘솔에서 API 및 서비스 > 사용자 인증 정보 페이지로 이동합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-12-21(UTC)"],[[["\u003cp\u003eAPI keys are simple strings used to identify a Google Cloud project for quota, billing, and monitoring in API Gateway.\u003c/p\u003e\n"],["\u003cp\u003eAPI Gateway requires API keys generated within your Google Cloud project, or projects where your API is enabled, to authorize requests.\u003c/p\u003e\n"],["\u003cp\u003eWhile useful for features like quotas, API keys are vulnerable to man-in-the-middle attacks and should not be the sole form of authentication for sensitive data.\u003c/p\u003e\n"],["\u003cp\u003eEnabling API key support for a service requires using the \u003ccode\u003egcloud services enable MANAGED_SERVICE_NAME\u003c/code\u003e command, specifying the managed service's name.\u003c/p\u003e\n"],["\u003cp\u003eFor security, API keys should be restricted to specific APIs through the Google Cloud console's \u003cstrong\u003eAPIs & Services > Credentials\u003c/strong\u003e page, ensuring they are not used by unauthorized parties.\u003c/p\u003e\n"]]],[],null,["# Using API Keys\n==============\n\nThis page describes how to utilize API keys in API Gateway.\n\nAn API key is a simple string that identifies a\nGoogle Cloud project for quota, billing, and monitoring purposes. A\ndeveloper generates an API key in a project in the Google Cloud console and\nembeds that key in every call to your API as a query parameter or in a request header.\n\nIf you specify an API key requirement in your API config,\nAPI Gateway uses the API key to look up the associated Google Cloud project. API Gateway rejects requests unless\nthe API key was generated in your Google Cloud project or within other\nGoogle Cloud projects in which your API has been enabled.\n| **Note:** Unlike credentials that use short-lived tokens or signed requests, API keys function as part of the API request. As a result, API keys are vulnerable to [man-in-the-middle attacks](https://wikipedia.org/wiki/Man-in-the-middle_attack) and may not be as secure as other authentication credentials. You can use API keys in addition to one of the other [supported forms of authentication](/api-gateway/docs/authentication-method), but we do not recommend using *only* API keys when API calls contain sensitive data.\n\nTo create an API key, or view API keys already available within your Google Cloud project, go to the **APIs \\& Services** \\\u003e **Credentials** page.\n\n[Go to Credentials](https://console.cloud.google.com/apis/credentials)\n\n\u003cbr /\u003e\n\n### Use case\n\nTo use API Gateway features such as\n[quotas](/api-gateway/docs/quotas-overview), you can pass in an API\nkey so that API Gateway can identify the Google Cloud project\nthat the client application is associated with.\n\n### About API key authentication for API Gateway\n\nIf you are using an API key for authentication, you must first enable API key support\nfor your service.\n\nEnter the following command: \n\n```\ngcloud services enable MANAGED_SERVICE_NAME\n```\n\n\u003cbr /\u003e\n\nThe \u003cvar translate=\"no\"\u003eMANAGED_SERVICE_NAME\u003c/var\u003e specifies the name of the managed service created when you deployed the API. You can find this name in the Managed Service column for your API on the APIs landing page in the console. Alternatively, you can find this name in the `Managed service` property when using the `gcloud api-gateway apis describe` command.\n\nFor example: \n\n```\ngcloud services enable my-api-a12bcd345e67f89g0h.apigateway.my-project.cloud.goog\n```\n\n### Restricting API keys\n\nAPI keys are unrestricted by default. Unrestricted keys are insecure because\nthey can be used by anyone from anywhere. We recommend that you add *API restrictions* where possible.\nAPI restrictions specify which APIs can be called using the API key. All API keys used by production applications should have API restrictions.\n\nTo add API restrictions:\n\n1. Find the title of the API as noted in your API Config. In the following example, the API title is `My Example Config`:\n\n ```yaml\n # openapi.yaml\n swagger: '2.0'\n info:\n title: My Example Config\n description: Sample API on API Gateway\n version: 1.0.0\n ...\n ```\n2. In the Google Cloud console, go to the **APIs \\& Services** \\\u003e **Credentials** page.\n\n [Go to Credentials](https://console.cloud.google.com/apis/credentials)\n\n \u003cbr /\u003e\n\n3. Select the name of the API key you wish to use for your API.\n\n4. In the **API restrictions** section of the API key detail page, click **Restrict key**.\n\n5. Select the API that your API key will be used to access from the dropdown list of available APIs. For example, if\n using the example config above, select `My Example Config`.\n\n6. Click **Save**.\n\nYour restriction should take effect momentarily."]]