I have a cloud build trigger that attempts to push my application to firebase hosting. To do that I have an encrypted .env.enc file that contains the firebase token needed to deploy. During my build I decrypt this file and attempt to deploy but am met with an unauthorised message.
I tried hard coding the token in my deployment script instead of using the environment variable and it deploys fine.
Here is my cloudbuild.yaml
steps:
- name: gcr.io/cloud-builders/gcloud
args:
- kms
- decrypt
- --ciphertext-file=.env.enc
- --plaintext-file=.env
- --location=global
- --keyring=ssr-vue-docker-app
- --key=cloudbuild-env
# Install
- name: 'gcr.io/cloud-builders/npm'
args: ['install']
# Test
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'test']
# Build
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'build']
# Deploy
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'deploy']
The final deploy step calls an npm script in my package.json with the environment variable used from the decrypted .env file.
"deploy": "firebase deploy --debug --token \"$FIREBASE_TOKEN\"
The initial output I get suggests that the token is not being used but that could also be redacted from the final log.
Step #4: [2019-04-17T21:14:48.087Z] Command: /usr/local/bin/node /workspace/node_modules/.bin/firebase deploy --debug --token= --only=hosting
This is the error I receive when attempting to deploy.
Step #4: Error: HTTP Error: 403, The caller does not have permission
Step #4:
Step #4: [2019-04-17T21:14:48.531Z] <<< HTTP RESPONSE BODY code=403, message=The caller does not have permission, status=PERMISSION_DENIED
Step #4: [2019-04-17T21:14:48.530Z] <<< HTTP RESPONSE 403 vary=X-Origin, Referer, Origin,Accept-Encoding, content-type=application/json; charset=UTF-8, date=Wed, 17 Apr 2019 21:14:48 GMT, server=ESF, cache-control=private, x-xss-protection=1; mode=block, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, accept-ranges=none, transfer-encoding=chunked
Step #4: rewrites=[glob=**, region=us-central1, serviceId=nuxt-server], deployment-tool=cli-firebase
Step #4: [2019-04-17T21:14:48.337Z] >>> HTTP REQUEST POST https://firebasehosting.googleapis.com/v1beta1/sites/ssr-vue-docker-app/versions
Step #4: i deploying hosting
Step #4:
Step #4: === Deploying to 'ssr-vue-docker-app'...
Any suggestions on how I might debug if the environment variable is being used? Or is there something I am missing from my build steps that allow me to use environment variables from a .env file?
I attempted to follow this guide: https://fireship.io/lessons/ci-cd-with-google-cloud-build/. I can't seem to see what I'm missing here so any help is appreciated.