Firebase ML Android 앱의 클라우드 사용자 인증 정보 보호
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Android 앱에서 Firebase ML의 Cloud API 중 하나를 사용하는 경우 프로덕션 환경에서 앱을 실행하기 전에 승인되지 않은 API 액세스를 방지하기 위한 몇 가지 추가 조치를 취해야 합니다.
프로덕션 앱의 경우 인증된 클라이언트만 클라우드 서비스에 액세스할 수 있는지 확인합니다. 루팅되지 않은 기기에서만 아래에 설명된 방법으로 인증할 수 있습니다.
그런 다음 테스트와 개발 중에 편리하게 사용할 수 있는 디버그 전용 API 키를 만듭니다.
1. Firebase에 프로덕션 앱 등록
먼저 프로덕션 앱을 Firebase에 등록합니다.
앱의 SHA-1 서명이 있어야 합니다. 자세한 방법은 클라이언트 인증을 참조하세요.
Firebase Console에서 settings프로젝트 설정으로 이동한 후 설정 탭을 선택합니다.
내 앱 카드까지 아래로 스크롤한 다음 Android 앱을 선택합니다.
앱의 SHA-1 서명을 앱 정보에 추가합니다.
2. API 키 범위 제한
다음으로 Cloud Vision API에 대한 액세스를 허용하지 않도록 기존 API 키를 구성합니다.
Google Cloud 콘솔의 사용자 인증 정보 페이지를 엽니다. 메시지가 표시되면 프로젝트를 선택합니다.
목록에 있는 기존 API 키마다 편집 화면을 엽니다.
API 제한사항 섹션에서 키 제한을 선택한 다음 API 키로 액세스할 모든 API를 목록에 추가합니다. Cloud Vision API는 포함하지 않아야 합니다.
API 키의 API 제한사항을 구성하면 키로 액세스할 수 있는 API를 명시적으로 선언하게 됩니다. 기본적으로 API 제한사항 섹션에 키 제한 안함이 선택되어 있으면 프로젝트에 사용 설정된 모든 API 액세스에 API 키를 사용할 수 있습니다.
이제 기존 API 키는 클라우드 ML 서비스에 대한 액세스 권한을 부여하지 않지만 API 제한사항 목록에 추가된 API에서는 각 키가 계속 작동합니다.
향후 추가 API를 사용 설정할 경우 관련 API 키의 API 제한사항 목록에 추가해야 합니다.
3. 디버그 전용 API 키 생성 및 사용
마지막으로 개발용으로만 사용할 새 API 키를 만듭니다. Firebase ML은 에뮬레이터에서 실행할 때와 같이 앱 인증이 불가능한 환경에서 API 키를 사용하여 Google Cloud 서비스에 액세스할 수 있습니다.
개발에 사용할 새 API 키를 만듭니다.
Google Cloud 콘솔의 사용자 인증 정보 페이지를 엽니다. 메시지가 표시되면 프로젝트를 선택합니다.
사용자 인증 정보 만들기 > API 키를 클릭하고 새 API 키를 기록합니다. 이 키는 인증되지 않은 앱에서의 API 액세스를 허용하므로 이 키를 기밀로 유지해야 합니다.
출시된 앱에서 새로운 디버그 API 키가 유출되지 않도록 하려면 디버그 빌드에만 사용되는 Android 매니페스트 파일에 디버그 API 키를 지정합니다.
디버그 매니페스트가 아직 없으면 파일 > 새로 만들기 > 기타 > Android 매니페스트 파일을 클릭하고 대상 소스 세트에서 debug
를 선택하여 하나 만듭니다.
디버그 매니페스트에 다음 선언을 추가합니다.
<application>
<meta-data
android:name="com.firebase.ml.cloud.ApiKeyForDebug"
android:value="your-debug-api-key" />
</application>
앱에서 Firebase ML이 인증서의 디지털 지문 일치를 통해 프로덕션 환경에 있는 클라이언트를 인증하고 디버그 빌드에서만 API 키(디버그 키)를 사용하도록 구성합니다.
Kotlin
val optionsBuilder = FirebaseVisionCloudImageLabelerOptions.Builder()
if (!BuildConfig.DEBUG) {
// Requires physical, non-rooted device:
optionsBuilder.enforceCertFingerprintMatch()
}
// Set other options. For example:
optionsBuilder.setConfidenceThreshold(0.8f)
// ...
// And lastly:
val options = optionsBuilder.build()
FirebaseVision.getInstance().getCloudImageLabeler(options).processImage(myImage)
Java
FirebaseVisionCloudImageLabelerOptions.Builder optionsBuilder =
new FirebaseVisionCloudImageLabelerOptions.Builder();
if (!BuildConfig.DEBUG) {
// Requires physical, non-rooted device:
optionsBuilder.enforceCertFingerprintMatch();
}
// Set other options. For example:
optionsBuilder.setConfidenceThreshold(0.8f);
// ...
// And lastly:
FirebaseVisionCloudImageLabelerOptions options = optionsBuilder.build();
FirebaseVision.getInstance().getCloudImageLabeler(options).processImage(myImage);
다음 단계
다른 Firebase 기능 사용 시 출시할 앱 준비에 대한 내용은 출시 체크리스트를 참조하세요.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-22(UTC)
[null,null,["최종 업데이트: 2025-08-22(UTC)"],[],[],null,["\u003cbr /\u003e\n\nIf your Android app uses one of Firebase ML's cloud APIs, before you launch your\napp in production, you should take some additional steps to prevent\nunauthorized API access.\n\nFor your production apps, you will ensure that only authenticated clients can\naccess cloud services. (Note that only non-rooted devices can authenticate using\nthe method described.)\n\nThen, you will create a debug-only API key that you can use for convenience\nduring testing and development.\n\n1. Register your production apps with Firebase\n\nFirst, register your production apps with Firebase.\n\n1. Make sure that you have your app's SHA-1 signatures. Refer to\n [Authenticating your client](//developers.google.com/android/guides/client-auth)\n to learn how.\n\n2. Go to your settings\n *Project settings* in the Firebase console, then select the *Settings*\n tab.\n\n3. Scroll down to the *Your apps* card, then select your Android app.\n\n4. Add your app's SHA-1 signature to your app's information.\n\n2. Restrict the scope of your API keys\n\nNext, configure your existing API keys to disallow access to the Cloud Vision\nAPI:\n\n1. Open the [Credentials](https://console.cloud.google.com/apis/credentials?project=_) page of the\n Google Cloud console. When prompted, select your project.\n\n2. For each existing API key in the list, open the editing view.\n\n3. In the *API restrictions* section, select **Restrict key** , then add to the\n list all of the APIs to which you want the API key to have access. Make sure\n to ***not*** include the Cloud Vision API.\n\n When you configure an API key's *API restrictions* , you are explicitly\n declaring the APIs to which the key has access. **By default, when the *API\n restrictions* section has *Don't restrict key* selected, an API key can be\n used to access any API that is enabled for the project.**\n\nNow, your existing API keys will not grant access to cloud ML services, but each\nkey will continue to work for any APIs that you added to its *API restrictions*\nlist.\n\nNote that if you enable any additional APIs in the future, you must add them to\nthe *API restrictions* list for the applicable API key.\n\n3. Create and use a debug-only API key\n\nFinally, create a new API key to be used only for development. Firebase ML can\nuse this API key to access Google Cloud services in environments where app\nauthentication isn't possible, such as when running on emulators.\n\n1. Create a new API key to be used for development:\n\n 1. Open the [Credentials](https://console.cloud.google.com/apis/credentials?project=_) page of the\n Google Cloud console. When prompted, select your project.\n\n 2. Click **Create credentials \\\u003e API key** and take note of the new API\n key. This key allows API access from unauthenticated apps, so\n **keep this key confidential**.\n\n2. To ensure the new debug API key is not leaked with your released app,\n specify the debug API key in an Android manifest file used only for debug\n builds:\n\n 1. If you don't already have a debug manifest, create one by clicking\n **File \\\u003e New \\\u003e Other \\\u003e Android Manifest File** and selecting `debug`\n from the target source sets.\n\n 2. In the debug manifest, add the following declaration:\n\n ```text\n \u003capplication\u003e\n \u003cmeta-data\n android:name=\"com.firebase.ml.cloud.ApiKeyForDebug\"\n android:value=\"your-debug-api-key\" /\u003e\n \u003c/application\u003e\n ```\n3. In your app, configure Firebase ML to use certificate fingerprint matching to\n authenticate your client in production and to use API keys---the debug\n key---only in debug builds:\n\n Kotlin \n\n ```kotlin\n val optionsBuilder = FirebaseVisionCloudImageLabelerOptions.Builder()\n if (!BuildConfig.DEBUG) {\n // Requires physical, non-rooted device:\n optionsBuilder.enforceCertFingerprintMatch()\n }\n\n // Set other options. For example:\n optionsBuilder.setConfidenceThreshold(0.8f)\n // ...\n\n // And lastly:\n val options = optionsBuilder.build()\n FirebaseVision.getInstance().getCloudImageLabeler(options).processImage(myImage)https://github.com/firebase/snippets-android/blob/391c1646eacf44d2aab3f76bcfa60dfc6c14acf1/mlkit/app/src/main/java/com/google/firebase/example/mlkit/kotlin/MainActivity.kt#L30-L42\n ```\n\n Java \n\n ```java\n FirebaseVisionCloudImageLabelerOptions.Builder optionsBuilder =\n new FirebaseVisionCloudImageLabelerOptions.Builder();\n if (!BuildConfig.DEBUG) {\n // Requires physical, non-rooted device:\n optionsBuilder.enforceCertFingerprintMatch();\n }\n\n // Set other options. For example:\n optionsBuilder.setConfidenceThreshold(0.8f);\n // ...\n\n // And lastly:\n FirebaseVisionCloudImageLabelerOptions options = optionsBuilder.build();\n FirebaseVision.getInstance().getCloudImageLabeler(options).processImage(myImage);https://github.com/firebase/snippets-android/blob/391c1646eacf44d2aab3f76bcfa60dfc6c14acf1/mlkit/app/src/main/java/com/google/firebase/example/mlkit/MainActivity.java#L30-L43\n ```\n\nNext steps\n\nSee the [launch checklist](/support/guides/launch-checklist) for information on\npreparing your app to launch when using other Firebase features."]]