Skip to content

Commit 42843d2

Browse files
balasankarcRobert Marshall
authored andcommitted
Add docs about extra_config_command settings
Document the new gitlab.rb options that allow an external script to provide secrets dynamically rather than rely on local plain text storage. Related https://gitlab.com/groups/gitlab-org/-/epics/12317 Signed-off-by: Balasankar 'Balu' C <[email protected]>
1 parent e982d7a commit 42843d2

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-0
lines changed

doc/settings/configuration.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,155 @@ If using a custom external proxy such as Apache, it may be necessary to add the
731731
gitlab_rails['allowed_hosts'] = ['gitlab.example.com', '127.0.0.1', 'localhost']
732732
```
733733

734+
## Provide sensitive configuration to components without plain text storage
735+
736+
Some components expose an `extra_config_command` option in `gitlab.rb`. This allows an external script to provide secrets
737+
dynamically rather than read them from plain text storage.
738+
739+
The available options are:
740+
741+
| `gitlab.rb` setting | Responsibility |
742+
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
743+
| `gitlab_rails['redis_extra_config_command']` | Provides extra configuration to the Redis configuration files used by GitLab Rails application. (`resque.yml`, `redis.yml`, `redis.<redis_instance>.yml` files) |
744+
| `gitlab_rails['db_extra_config_command']` | Provides extra configuration to the DB configuration file used by GitLab Rails application. (`database.yml`) |
745+
| `gitlab_kas['extra_config_command']` | Provides extra configuration to GitLab agent server for Kubernetes (KAS). |
746+
| `gitlab_workhorse['extra_config_command']` | Provides extra configuration to GitLab Workhorse.|
747+
| `gitlab_exporter['extra_config_command']` | Provides extra configuration to GitLab Exporter.
748+
749+
The value assigned to any of these options should be an absolute path to an executable script
750+
that writes the sensitive configuration in the required format to STDOUT. The
751+
components:
752+
753+
1. Execute the supplied script.
754+
1. Replace values set by user and default configuration files with those emitted
755+
by the script.
756+
757+
### Provide Redis password to client components
758+
759+
As an example, you can use the script and `gitlab.rb` snippet below to
760+
specify the password of a Redis server to the components that need to connect to
761+
Redis.
762+
763+
1. Save the script below as `/opt/generate-redis-conf`
764+
765+
```ruby
766+
#!/opt/gitlab/embedded/bin/ruby
767+
768+
require 'json'
769+
require 'yaml'
770+
771+
class RedisConfig
772+
REDIS_PASSWORD = `echo "toomanysecrets"`.strip # Change the command inside backticks to fetch Redis password
773+
774+
class << self
775+
def rails
776+
puts YAML.dump({
777+
'password' => REDIS_PASSWORD
778+
})
779+
end
780+
781+
def kas
782+
puts YAML.dump({
783+
'redis' => {
784+
'password' => REDIS_PASSWORD
785+
}
786+
})
787+
end
788+
789+
def workhorse
790+
puts JSON.dump({
791+
redis: {
792+
password: REDIS_PASSWORD
793+
}
794+
})
795+
end
796+
797+
def gitlab_exporter
798+
puts YAML.dump({
799+
'probes' => {
800+
'sidekiq' => {
801+
'opts' => {
802+
'redis_password' => REDIS_PASSWORD
803+
}
804+
}
805+
}
806+
})
807+
end
808+
end
809+
end
810+
811+
def print_error_and_exit
812+
$stdout.puts "Usage: redis_credentials <COMPONENT>"
813+
$stderr.puts "Supported components are: rails, kas, workhorse, gitlab_exporter"
814+
815+
exit 1
816+
end
817+
818+
print_error_and_exit if ARGV.length != 1
819+
820+
component = ARGV.shift
821+
begin
822+
RedisConfig.send(component.to_sym)
823+
rescue NoMethodError
824+
print_error_and_exit
825+
end
826+
```
827+
828+
1. Ensure the script created above is executable:
829+
830+
```shell
831+
chmod +x /opt/generate-redis-conf
832+
```
833+
834+
1. Add the snippet below to `/etc/gitlab/gitlab.rb`:
835+
836+
```ruby
837+
gitlab_rails['redis_extra_config_command'] = '/opt/generate-redis-conf rails'
838+
gitlab_workhorse['extra_config_command'] = '/opt/generate-redis-conf workhorse'
839+
gitlab_kas['extra_config_command'] = '/opt/generate-redis-conf kas'
840+
gitlab_exporter['extra_config_command'] = '/opt/generate-redis-conf gitlab_exporter'
841+
```
842+
843+
1. Run `sudo gitlab-ctl reconfigure`.
844+
845+
### Provide the PostgreSQL user password to GitLab Rails
846+
847+
As an example, you can use the script and configuration below to provide the
848+
password that GitLab Rails should use to connect to the PostgreSQL server.
849+
850+
1. Save the script below as `/opt/generate-db-config`:
851+
852+
```ruby
853+
#!/opt/gitlab/embedded/bin/ruby
854+
855+
require 'yaml'
856+
857+
db_password = `echo "toomanysecrets"`.strip # Change the command inside backticks to fetch DB password
858+
859+
puts YAML.dump({
860+
'main' => {
861+
'password' => db_password
862+
},
863+
'ci' => {
864+
'password' => db_password
865+
}
866+
})
867+
```
868+
869+
1. Ensure the script created above is executable:
870+
871+
```shell
872+
chmod +x /opt/generate-db-config
873+
```
874+
875+
1. Add the snippet below to `/etc/gitlab/gitlab.rb`:
876+
877+
```ruby
878+
gitlab_rails['db_extra_config_command'] = '/opt/generate-db-config'
879+
```
880+
881+
1. Run `sudo gitlab-ctl reconfigure`.
882+
734883
## Related topics
735884

736885
- [Disable impersonation](https://docs.gitlab.com/ee/api/index.html#disable-impersonation)

doc/settings/database.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,10 @@ see [Revert packaged PostgreSQL server to the previous version](#revert-packaged
928928
If you are doing a fresh install on an environment that previously had GitLab installed on it and you are using a pinned PostgreSQL version, first make
929929
sure that any folders that relate to PostgreSQL are deleted and that there are no PostgreSQL processes running on the instance.
930930
931+
## Provide sensitive data configuration to GitLab Rails without plain text storage
932+
933+
For more information, see the example in [configuration documentation](../settings/configuration.md#provide-the-postgresql-user-password-to-gitlab-rails).
934+
931935
### Troubleshooting
932936
933937
#### Set `default_transaction_isolation` into `read committed`

doc/settings/redis.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ redis['io_threads'] = 4
231231
redis['io_threads_do_reads'] = true
232232
```
233233

234+
## Provide sensitive configuration to Redis clients without plain text storage
235+
236+
For more information, see the example in [configuration documentation](../settings/configuration.md#provide-redis-password-to-client-components).
237+
234238
## Troubleshooting
235239

236240
### `x509: certificate signed by unknown authority`

0 commit comments

Comments
 (0)