1

I'm setting authentication functionality by firebase.
It's working fine in my local docker environment.
But its firebaseConfig is located in client side.
I want to hide firebaseConfig information as environment variables.

Here is the stack.

・client: react/axios
・api: golang/gin
・web server: nginx
・db: mysql
・container: docker
・ci-tool: travis
・deploy: aws elastic beanstalk

Here is the repository structure

article
  ├ client
  ├   └ src
  │      └ firebase.ts
  ├ api
  ├ nginx
  └ docker-compose.yml

I set process.env in firebaseConfig.

//firebase.ts
import * as firebase from 'firebase';
import 'firebase/auth';

const firebaseConfig = {
  apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
  authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
  databaseURL: process.env.REACT_APP_FIREBASE_DATABASE_URL,
  projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
  storageBucket: '',
  messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
  appId: process.env.REACT_APP_FIREBASE_APP_ID,
};

firebase.initializeApp(firebaseConfig);

export default firebase;

This works fine in local environment.
But in production environment(elastic beanstalk), I have no idea to set these environment variables because they are in client side.

Entire source code is here:
https://github.com/jpskgc/article
Production URL is here:
http://multidocker-env.vwnrixavuv.ap-northeast-1.elasticbeanstalk.com/

I expect firebase authentication works in production environment(elastic beanstalk).
But the actual does not.

Zr {code: "auth/invalid-api-key", message: "Your API key is invalid, please check you have copied it correctly."}
code: "auth/invalid-api-key"
message: "Your API key is invalid, please check you have copied it correctly."
__proto__: Error

****UPDATE****
I set environemt variables in docker-compose.yml and elastic beanstalk.
but still same error occurs.

//docker-compose.yml
  client:
    build:
      dockerfile: Dockerfile.dev
      context: ./client
    volumes:
      - /app/node_modules
      - ./client:/app
    environment:
      - REACT_APP_FIREBASE_API_KEY=${REACT_APP_FIREBASE_API_KEY}
      - REACT_APP_FIREBASE_AUTH_DOMAIN=${REACT_APP_FIREBASE_AUTH_DOMAIN}
      - REACT_APP_FIREBASE_DATABASE_URL=${REACT_APP_FIREBASE_DATABASE_URL}
      - REACT_APP_FIREBASE_PROJECT_ID=${REACT_APP_FIREBASE_PROJECT_ID}
      - REACT_APP_FIREBASE_MESSAGING_SENDER_ID=${REACT_APP_FIREBASE_MESSAGING_SENDER_ID}
      - REACT_APP_FIREBASE_APP_ID=${REACT_APP_FIREBASE_APP_ID}

here is the elastic beanstalk environment variables setting:
https://i.stack.imgur.com/m8HRx.jpg

jpskgc
  • 657
  • 14
  • 27
  • you can not add the `ENV` in your `docker-compose.yml` ? – LinPy Aug 12 '19 at 06:14
  • I do not want to expose `firebaseConfig` information to public. If they are listed on `docker-compose.yml`, they are exposed on github. – jpskgc Aug 12 '19 at 06:23
  • add just the `ARG` name without a value in your `compose` and then pass the value in the docker up command `REACT_APP_FIREBASE_APP_ID=TEST && docker-ompose up` – LinPy Aug 12 '19 at 06:26
  • it works fine in local environment maybe, but I'm talking about `elastic beanstalk `environment. I tried it now by setting on `docker-compose.yml` and `elastic beanstalk` environment variables. but still same error occured. – jpskgc Aug 12 '19 at 06:58
  • All environment variables defined in the Elastic Beanstalk console are passed to the containers. so that should works see https://docs.amazonaws.cn/en_us/elasticbeanstalk/latest/dg/create_deploy_docker.html – LinPy Aug 12 '19 at 07:02
  • why don't you put the entire config info on another file and add that into `.gitignore` file? – HexaCrop Aug 12 '19 at 07:02
  • I added it on docker-compose.yml and set on elastic beanstalk. but not work.https://github.com/jpskgc/article/blob/master/docker-compose.yml#L47-L52 https://imgur.com/a/XvjL4dh – jpskgc Aug 12 '19 at 07:16
  • i guess, in case you passing ENV like @Linpy suggested, in your compose file instead of keeping `REACT_APP_FIREBASE_API_KEY ` , i do like `REACT_APP_FIREBASE_API_KEY =${REACT_APP_FIREBASE_API_KEY}` – Saikat Chakrabortty Aug 12 '19 at 07:19
  • I changed `docker-compose.yml` as @ saikat chakrabortty suggested, but still same error happens. https://github.com/jpskgc/article/blob/master/docker-compose.yml#L47-L52 – jpskgc Aug 12 '19 at 07:37
  • As this article says, no prolbem to expose firebaseConfig.
    https://stackoverflow.com/questions/37482366/is-it-safe-to-expose-firebase-apikey-to-the-public
    – jpskgc Aug 22 '19 at 06:01

1 Answers1

2

There is no prolbem to expose firebaseConfig.
I take a look at flowing article.
So issue is resolved.

Is it safe to expose Firebase apiKey to the public?

jpskgc
  • 657
  • 14
  • 27