Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment Variable with _FILE suffix throws Exception - Using Directus as a service in GitLab CI/CD #13273

Closed
RANSoftRA opened this issue May 13, 2022 · 0 comments · Fixed by #13274

Comments

@RANSoftRA
Copy link

Describe the Bug

When running a GitLab CI/CD Pipeline, the runner contains a lot of environemt variables: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html.

On of those is: CI_SERVER_TLS_CA_FILE

Directus behavior is to read the file contents if the key ends with _FILE:

In our case this behavior raises a serious problem, because we cannot alter the variable in GitLab (otherwise the job would fail at a different place).

Generally speaking, this behavior is kind of stange, since a enviroment variable that is not managed by directus can contain arbitrary information.

For example: What happens if I set the environment variable TEST_FILE to a huge file.

To Reproduce

In our case - GitLab Configuration:

  • Assuming a working GitLab instance with CI/CD available
  • .gitlab-ci.yml:
image: openjdk:17.0-jdk-bullseye

services:
  - name: postgres:14
    alias: postgres
  - name: directus/directus:9
    alias: directus
variables:
  POSTGRES_DB: db
  POSTGRES_USER: db
  POSTGRES_PASSWORD: db
  KEY: somekey
  SECRET: somesecret
  DB_CLIENT: pg
  DB_HOST: postgres
  DB_PORT: 5432
  DB_DATABASE: db
  DB_USER: db
  DB_PASSWORD: db
  ADMIN_EMAIL: 'directus@test.at'
  ADMIN_PASSWORD: 'db'

Errors Shown

�[0;33m*** WARNING:�[0;m Service runner-75vys7d1-project-96-concurrent-0-ac8237f753d63b8a-directus__directus-1 probably didn't start properly.

Health check error:
start service container: Error response from daemon: Cannot link to a non running container: /runner-75vys7d1-project-96-concurrent-0-ac8237f753d63b8a-directus__directus-1 AS /runner-75vys7d1-project-96-concurrent-0-ac8237f753d63b8a-directus__directus-1-wait-for-service/service (docker.go:1153:1s)

Service container logs:
2022-05-13T09:34:55.886940797Z /directus/node_modules/directus/dist/env.js:190
2022-05-13T09:34:55.886961697Z throw new Error(Failed to read value from file "${value}", defined in environment variable "${key}".);
2022-05-13T09:34:55.886965574Z ^
2022-05-13T09:34:55.886967868Z
2022-05-13T09:34:55.886970022Z Error: Failed to read value from file "-----BEGIN CERTIFICATE-----
2022-05-13T09:34:55.886972327Z ****************************************************************
2022-05-13T09:34:55.886974541Z ****************************************************************
2022-05-13T09:34:55.886976715Z ****************************************************************
2022-05-13T09:34:55.886978879Z ****************************************************************
2022-05-13T09:34:55.886981103Z ****************************************************************
2022-05-13T09:34:55.886983417Z ****************************************************************
2022-05-13T09:34:55.886985582Z ****************************************************************
2022-05-13T09:34:55.886987726Z THE WHOLE CERTIFICATE CHAIN**
2022-05-13T09:34:55.886989910Z ****************************************************************
2022-05-13T09:34:55.886992094Z ****************************************************************
2022-05-13T09:34:55.886994288Z ****************************************************************
2022-05-13T09:34:55.886996442Z ****************************************************************
2022-05-13T09:34:55.886998636Z ****************************************************************
2022-05-13T09:34:55.887000780Z ****************************************************************
2022-05-13T09:34:55.887002944Z ****************************************************************
2022-05-13T09:34:55.887005178Z ****************************************************************
2022-05-13T09:34:55.887175700Z -----END CERTIFICATE-----", defined in environment variable "CI_SERVER_TLS_CA_FILE".
2022-05-13T09:34:55.887178134Z at processValues (/directus/node_modules/directus/dist/env.js:190:23)
2022-05-13T09:34:55.887180389Z at Object. (/directus/node_modules/directus/dist/env.js:96:7)
2022-05-13T09:34:55.887183274Z at Module._compile (node:internal/modules/cjs/loader:1105:14)
2022-05-13T09:34:55.887185789Z at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
2022-05-13T09:34:55.887188083Z at Module.load (node:internal/modules/cjs/loader:981:32)
2022-05-13T09:34:55.887190267Z at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-05-13T09:34:55.887192501Z at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-05-13T09:34:55.887194716Z at require (node:internal/modules/cjs/helpers:102:18)
2022-05-13T09:34:55.887196890Z at Object. (/directus/node_modules/directus/dist/cache.js:9:31)
2022-05-13T09:34:55.887199234Z at Module._compile (node:internal/modules/cjs/loader:1105:14)

What version of Directus are you using?

9.10.0

What version of Node.js are you using?

Use of Docker Image directus/directus:9

What database are you using?

Postgres 14

What browser are you using?

none - ci/cd pipeline

How are you deploying Directus?

Docker

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants