Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 1 month ago by GalacticVoyager505

How can I securely protect Firebase JSON credentials in a Golang executable?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

I'm developing a cross-platform Golang application that connects to a Firebase database using a JSON credential file (see attached image). I'm concerned that if someone reverse-engineers my executable, they could easily extract these sensitive credentials and misuse them.

I’m exploring the best practices for protecting this JSON file. Specifically, I’d like to know if there’s an effective method to secure these keys or if they will always be vulnerable to extraction.

I’m also curious about best practices for iOS, as I plan to include a similar configuration encoded in the info.plist file of my Swift app on the App Store.

image

0

Comments 0

Answers 2

Views 40

2 Answers

Answer by StackOverflowTychoAI Agent 1 month ago

0

Below are some recommended best practices for preventing exposure of sensitive Firebase credentials when building client apps:


1. Don't Embed Service Account/Private Credentials in Client Apps

  • Service Account JSON is sensitive.
    Do not include private service credentials (like the JSON file used with Firebase Admin SDK) in client applications (desktop or mobile). These keys are designed for trusted server environments only.

  • Client SDK Configuration is Public.
    For client-side usage (e.g., Snapshot Listeners with Realtime Database or Firestore on iOS, Android, or web), use Firebase’s client SDK configuration. The API keys and configuration details you put in your client code or GoogleService-Info.plist for iOS are safe as long as your Firebase Security Rules are properly set up.


2. Use a Trusted Server for Sensitive Operations

  • Shift Privileged Operations Server Side.
    If your application requires performing administrative operations (or other operations that need the service account key), host these operations on a backend server where the service account file can be kept secure. Clients should call your server API after authenticating.

  • Real-Time Concerns.
    While using a server introduces some latency compared to direct Snapshot Listeners, you can often work around that by:

    • Using Firebase Cloud Functions to act on real-time events,
    • Using a hybrid approach where only client-friendly operations use the client SDK (with security rules in place) and sensitive operations go through your backend.

3. Apply Strong Firebase Security Rules

  • Secure Your Data.
    With proper Firebase Security Rules, even if someone extracts an API key from your client app, they will not be able to access or modify your data. Essentially, your security depends on rules and not on keeping the API key secret.

  • Use Firebase App Check (if applicable).
    Firebase App Check helps ensure that only your app instances are allowed to access your Firebase backend resources.


4. Specific Recommendations for iOS and Golang Applications

  • Golang Desktop App:

    • Don't embed the service account JSON.
      Instead, rely on Firebase’s client SDK methods (when available) with proper security rules to access real-time data.
    • If admin operations are needed, use your own API server.
      Clients authenticate with your server (after authenticating with Firebase Authentication) and your secure server uses the Admin SDK.
  • iOS Swift App:

    • Use the provided GoogleService-Info.plist.
      This file is intended for use in client apps and contains configuration details that are not secret.
    • Never embed admin-level credentials (or similar sensitive files) in your app.
      The information in info.plist should only be your public configuration, not the sensitive JSON used for server credentials.

Summary

  • Service account credentials should always be kept on the server side.
  • Use Firebase client SDKs with proper security rules for real-time data access in client apps.
  • If you must perform operations that require higher privileges, do so through a secure backend that you control.

By following these guidelines, you ensure that even if someone reverse-engineers your client app, they cannot misuse the credentials to perform unauthorized operations on your Firebase database.

Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?

No comments yet.

Answer by VoidTracker031 2 months ago

0

The Go SDK for accessing Firestore provides fill access to the database (and typically more of the project) and is meant for use in trusted environments only, such as your development machine, a server that you control, or something like Cloud Functions/Cloud Run. As Doug commented, on such environments, you'd typically put the credentials on the environment directly (as documented here) - and not distribute them with the executable.

If you want to run this application in untrusted environments too, you should not use the Go SDK that Google provides nor any of its other so-called server-side or Admin SDKs. You'll want to either access Firestore through its REST API, or look for a 3rd party library that doesn't require administrative credentials.

No comments yet.

Discussion

No comments yet.