sameersbn / sameersbn/docker-gitlab

TypeError when generating Rails.application.secrets.jws_private_key

Open
#1,177 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

wontfix
Dominant language
Shell
Stars
8.1k
Forks
2.1k
Avg merge
17h 47m
Merged PRs (30d)
7

Description

This happens when the GITLAB_SECRETS_* environment variables are set to strings consisting strictly of numbers, e.g. 12345678901234567890.

I discovered this during development when I was too lazy to generate some realistic placeholder values. In production scenarios you would probably generate some proper values and never encounter this issue. But I spent some time working out the reason for this one, and a fix could probably save time for someone else who is also lazy. I understand if this issue won't be prioritized :D

Steps to reproduce:

❯ mkdir /tmp/docker-gitlab-bug-report
❯ cd /tmp/docker-gitlab-bug-report

# Fetch `docker-compose.yml` as mentioned in the README.md
❯ wget https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml
--2017-04-14 11:17:07--  https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.88.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.88.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3836 (3.7K) [text/plain]
Saving to: ‘docker-compose.yml’

docker-compose.yml                           100%[============================================================================================>]   3.75K  --.-KB/s    in 0s

2017-04-14 11:17:07 (18.2 MB/s) - ‘docker-compose.yml’ saved [3836/3836]

# Set values of services.gitlab.environment.GITLAB_SECRETS_* to large numbers
❯ sed -i -e 's/long-and-random-alphanumeric-string/123456789012345678901234567890/g' docker-compose.yml

# Try to bring up the services, but fail
❯ docker-compose up
dockergitlabbugreport_postgresql_1 is up-to-date
dockergitlabbugreport_redis_1 is up-to-date
Starting dockergitlabbugreport_gitlab_1
Attaching to dockergitlabbugreport_postgresql_1, dockergitlabbugreport_redis_1, dockergitlabbugreport_gitlab_1
gitlab_1      | Initializing logdir...
gitlab_1      | Initializing datadir...
postgresql_1  | Initializing datadir...
postgresql_1  | Initializing certdir...
postgresql_1  | Initializing logdir...
postgresql_1  | Initializing rundir...
postgresql_1  | Setting resolv.conf ACLs...
postgresql_1  | Creating database user: gitlab
postgresql_1  | Creating database: gitlabhq_production...
postgresql_1  | ‣ Loading pg_trgm extension...
postgresql_1  | ‣ Granting access to gitlab user...
postgresql_1  | Starting PostgreSQL 9.6...
postgresql_1  | LOG:  database system was shut down at 2017-04-14 02:19:50 UTC
postgresql_1  | LOG:  MultiXact member wraparound protections are now enabled
postgresql_1  | LOG:  database system is ready to accept connections
postgresql_1  | LOG:  autovacuum launcher started
redis_1       | Starting redis-server...
redis_1       | [1] 14 Apr 02:19:47.563 # Server started, Redis version 2.8.4
redis_1       | [1] 14 Apr 02:19:47.563 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
gitlab_1      | Installing configuration templates...
gitlab_1      | Configuring gitlab...
gitlab_1      | Configuring gitlab::database
gitlab_1      | Configuring gitlab::redis
gitlab_1      | Configuring gitlab::secrets...
gitlab_1      | Configuring gitlab::sidekiq...
gitlab_1      | Configuring gitlab::gitlab-workhorse...
gitlab_1      | Configuring gitlab::unicorn...
gitlab_1      | Configuring gitlab::timezone...
gitlab_1      | Configuring gitlab::rack_attack...
gitlab_1      | Configuring gitlab::ci...
gitlab_1      | Configuring gitlab::artifacts...
gitlab_1      | Configuring gitlab::lfs...
gitlab_1      | Configuring gitlab::mattermost...
gitlab_1      | Configuring gitlab::project_features...
gitlab_1      | Configuring gitlab::oauth...
gitlab_1      | Configuring gitlab::ldap...
gitlab_1      | Configuring gitlab::backups...
gitlab_1      | Configuring gitlab::backups::schedule...
gitlab_1      | Configuring gitlab::registry...
gitlab_1      | Configuring gitlab::pages...
gitlab_1      | Configuring gitlab-shell...
gitlab_1      | Configuring nginx...
gitlab_1      | Configuring nginx::gitlab...
gitlab_1      | Setting up GitLab for firstrun. Please be patient, this could take a while...
gitlab_1      | Missing Rails.application.secrets.jws_private_key for production environment. The secret will be generated and stored in config/secrets.yml.
gitlab_1      | rake aborted!
gitlab_1      | TypeError: no implicit conversion of Bignum into String
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/key_generator.rb:21:in `pbkdf2_hmac_sha1'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/key_generator.rb:21:in `generate_key'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/key_generator.rb:38:in `generate_key'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.8/lib/rails/application.rb:206:in `message_verifier'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/globalid-0.3.7/lib/global_id/railtie.rb:25:in `block (2 levels) in <class:Railtie>'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/lazy_load_hooks.rb:44:in `each'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.8/lib/rails/application/finisher.rb:62:in `block in <module:Finisher>'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.8/lib/rails/initializable.rb:30:in `instance_exec'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.8/lib/rails/initializable.rb:30:in `run'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.8/lib/rails/initializable.rb:55:in `block in run_initializers'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.8/lib/rails/initializable.rb:54:in `run_initializers'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.8/lib/rails/application.rb:352:in `initialize!'
gitlab_1      | /home/git/gitlab/config/environment.rb:5:in `<top (required)>'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:274:in `require'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:274:in `block in require'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:240:in `load_dependency'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:274:in `require'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.8/lib/rails/application.rb:328:in `require_environment!'
gitlab_1      | /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.8/lib/rails/application.rb:457:in `block in run_tasks_blocks'
gitlab_1      | Tasks: TOP => gitlab:setup => environment
gitlab_1      | (See full trace by running task with --trace)
dockergitlabbugreport_gitlab_1 exited with code 1

The values are strings in the context of docker-compose (courtesy of docker-compose.yml parsing I guess):

❯ docker-compose config | grep GITLAB_SECRETS
      GITLAB_SECRETS_DB_KEY_BASE: '123456789012345678901234567890'
      GITLAB_SECRETS_OTP_KEY_BASE: '123456789012345678901234567890'
      GITLAB_SECRETS_SECRET_KEY_BASE: '123456789012345678901234567890'

However, the values become numbers in config/secrets.yml:

❯ docker-compose exec gitlab cat config/secrets.yml
production:
  # db_key_base is used to encrypt for Variables. Ensure that you don't lose it.
  # If you change or lose this key you will be unable to access variables stored in database.
  # Make sure the secret is at least 30 characters and all random,
  # no regular words or you'll be exposed to dictionary attacks.
  db_key_base: 123456789012345678901234567890
  secret_key_base: 123456789012345678901234567890
  otp_key_base: 123456789012345678901234567890

development:
  db_key_base: development

test:
  db_key_base: test

In case it's needed:

❯ docker info
Containers: 8
 Running: 4
 Paused: 0
 Stopped: 4
Images: 4
Server Version: 17.04.0-ce
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 41
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary:
containerd version: 422e31ce907fd9c3833a38d7b8fdd023e5a76e73
runc version: 9c2d8d184e5da67c95d601382adf14862e4f2228
init version: 949e6fa
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.4.0-72-generic
Operating System: Ubuntu 16.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.503GiB
Name: havet
ID: YWIW:5WW3:N7UX:WGBR:57PT:WFZZ:KMNJ:25UZ:USZ6:FQ6A:5M43:XVOY
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the GITLAB_SECRETS_* handling that generates config/secrets.yml, using the docker-compose.yml reproduction and the shown docker-compose config output. Check how numeric-looking environment values are serialized, then confirm the generated secrets remain strings and Rails initialization completes without the TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, docker-compose, rails, shell
Domain
devops, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.