Compare commits

...

22 Commits

Author SHA1 Message Date
Greg Karékinian
1e60722ec4 Create an initial encfs cookbook
Usage: Add the kosmos_encfs::default recipe to the run list of a node.
Creating the encrypted directory will keep it mounted. After a reboot,
start the encfs service and enter the password:

```
$ systemctl start encfs
encfs password:
```

For now postgresql@12-main is a hardcoded dependency of the encfs
Systemd unit that is automatically started once the user inputs the
correct password. This list of dependency will need to be different for
every server, based on the services it is running
2020-06-04 19:50:20 +02:00
Greg Karékinian
eded62a3ec Merge branch 'master' into feature/pg_encfs 2020-06-04 15:13:53 +02:00
Greg Karékinian
27845525da Use the same JWT_SECRET as on our previous Gitea
A different one breaks 2FA
2020-06-02 12:12:59 +02:00
Greg Karékinian
c8e50fd226 Install git, it is a required dependency for Gitea
I didn't catch it because git is installed by default in the Vagrant box
I used to write the cookbook
2020-06-02 11:41:19 +02:00
Greg Karékinian
2d6c514257 Add the gitea role 2020-06-02 11:22:10 +02:00
8342298c89 Merge branch 'feature/147-gitea_cookbook' of kosmos/chef into master 2020-06-02 09:16:37 +00:00
Greg Karékinian
94330f2052 Comment out the COOKIE_SECURE config for now
We will enable it again after we have a valid TLS cert generated with
Let's Encrypt. It prevents logins using http, and we will need that as
an admin account
2020-05-28 18:43:31 +02:00
Greg Karékinian
baaae695af Merge branch 'master' into feature/147-gitea_cookbook 2020-05-28 15:44:44 +02:00
5b2d4f269d Merge branch 'bugfix/171-letsencrypt_resource' of kosmos/chef into master 2020-05-26 15:25:27 +00:00
Greg Karékinian
baa0739936 Add the backup recipe
Also move the Gitea data dir to an attribute
2020-05-26 15:21:26 +02:00
Greg Karékinian
3332a1b2e8 Write initial README 2020-05-26 15:21:07 +02:00
Greg Karékinian
210c76c479 Fix the name of the Let's Encrypt cert execute resource
The resource in the notification was invalid, missing the type of
resource (execute)

Fixes #171
2020-05-26 14:10:47 +02:00
6469d2286e Merge branch 'feature/zoom_options' of kosmos/chef into master 2020-05-25 15:52:41 +00:00
9dec1cfce8 Merge branch 'chore/mastodon_system_deps' of kosmos/chef into master 2020-05-25 15:50:58 +00:00
5fcb047505
Update Mastodon system dependencies
Needs new Ruby, and why not upgrade Yarn in the process. Running in
production.
2020-05-25 17:49:22 +02:00
f92b43e0f4
Configure Zoom meeting whitelist
So we only log contributions for actual Kosmos calls
2020-05-25 16:57:09 +02:00
Greg Karékinian
1f0e2ccbdd Move the binary URL to an attribute 2020-05-21 11:51:06 +02:00
Greg Karékinian
51d4d88568 Initial kosmos_gitea cookbook
The default recipe deploys the gitea binary, generates a config file and
our custom Kosmos label set. The service runs as a Systemd unit.

The pg_db recipe needs to run on the primary PostgreSQL (currently
andromeda).

The backup recipe is empty for now

Refs #147
2020-05-18 19:39:43 +02:00
Greg Karékinian
20cbc678bc Add a method that returns the PostgreSQL service 2020-05-18 19:38:37 +02:00
82f1e9863b Merge branch 'bugfix/160-cookbook_fixes' of kosmos/chef into master 2020-05-16 08:53:24 +00:00
Greg Karékinian
d79cdf087b Move the PGPASS environment variable to the execute resource
That way it does not appear in the list of running processes while the
command is running
2020-05-15 18:45:12 +02:00
Greg Karékinian
31dc14e88c Fix the firewall rules for PostgreSQL
I got the source and destination mixed up.
2020-05-15 18:44:42 +02:00
36 changed files with 939 additions and 66 deletions

View File

@ -0,0 +1,10 @@
{
"id": "encfs",
"password": {
"encrypted_data": "+1Q3ojHS0lJgE7lFv3zEv653UHgRiuuuxBQQpfa+XrKaeQms2Kiw\n",
"iv": "sMb1a/NmjcAW62Uf\n",
"auth_tag": "n6jpD1fGoqidgMHRuL3K+A==\n",
"version": 3,
"cipher": "aes-256-gcm"
}
}

View File

@ -0,0 +1,31 @@
{
"id": "gitea",
"jwt_secret": {
"encrypted_data": "jTNhXpJ1mhUXjfRZ3OAR8lrGgxyyob44kN0TyNec5zO2Wb46hJgYMWwtKlZ9\nohNexOKV+wXCjZNeVw0kNgI=\n",
"iv": "NYkJTeTzLilMLptE\n",
"auth_tag": "a/PuBmOmhyCx0ooepz7n1w==\n",
"version": 3,
"cipher": "aes-256-gcm"
},
"internal_token": {
"encrypted_data": "HbyEfyrupc06vGHhSqKUUT8NAIrlvbK4LbMdqxmJMgeltvDItqGgFa0ZdD51\n0djRqQMrRZ4MEdqVTFSBL+8QVdriKeUcLcummp52Sp9tYZKSQKympJFx3fsS\n49rBJhDKRlc3+jUpejJu4jHY4xR2MMNvWWqkkufTvZHhzg==\n",
"iv": "DUSCP7Q3dgjyYXwl\n",
"auth_tag": "HkPLLvY8uVNK871OsMshcg==\n",
"version": 3,
"cipher": "aes-256-gcm"
},
"secret_key": {
"encrypted_data": "bvxdPokzagjZkdGG37hbWBi6ywu+1UuOrlJJ4p5zOG03b4PN4N40ztO4fWr5\ncMHfO7FER779fRc+tA2H7L1SKqSvlJThgk7X8R7AGGQmrQy7Jvc=\n",
"iv": "0uTGeUjnbvnW2WGp\n",
"auth_tag": "Dzfb3Jiim5eYWfwpN3HO5Q==\n",
"version": 3,
"cipher": "aes-256-gcm"
},
"postgresql_password": {
"encrypted_data": "yv2gQYUxMTa7eeC0GJqE+fujOvM9GIwj/OL/L1wvn7uNTjJE97Xt1gYXRw==\n",
"iv": "F6yrDSav9EShCf2N\n",
"auth_tag": "08b4vT71g41qu6A6jZ6opw==\n",
"version": 3,
"cipher": "aes-256-gcm"
}
}

View File

@ -108,7 +108,8 @@
"kosmos-base::letsencrypt",
"git::default",
"git::package",
"build-essential::default"
"build-essential::default",
"poise-git::default"
],
"platform": "ubuntu",
"platform_version": "18.04",

6
roles/gitea.rb Normal file
View File

@ -0,0 +1,6 @@
name "gitea"
run_list %w(
kosmos_gitea::default
kosmos_gitea::backup
)

View File

@ -157,7 +157,7 @@ done
end
nginx_certbot_site new_resource.hostname do
notifies :run, "letsencrypt cert for #{domain}", :delayed
notifies :run, "execute[letsencrypt cert for #{domain}]", :delayed
end
# Generate a Let's Encrypt cert (only if the nginx vhost exists and no cert

View File

@ -120,7 +120,8 @@ application app_path do
"KREDITS_SESSION_SECRET" => data_bag['kredits_session_secret'],
"KREDITS_GITHUB_KEY" => data_bag['kredits_github_key'],
"KREDITS_GITHUB_SECRET" => data_bag['kredits_github_secret'],
"KREDITS_ZOOM_JWT" => data_bag['kredits_zoom_jwt']
"KREDITS_ZOOM_JWT" => data_bag['kredits_zoom_jwt'],
"KREDITS_ZOOM_MEETING_WHITELIST" => "414901303"
}
)
notifies :run, "execute[systemctl daemon-reload]", :delayed

View File

@ -79,10 +79,10 @@ package %w(imagemagick ffmpeg libxml2-dev libxslt1-dev file git curl pkg-config
libprotobuf-dev protobuf-compiler libidn11 libidn11-dev libjemalloc1)
npm_package "yarn" do
version "1.17.3"
version "1.22.4"
end
ruby_version = "2.6.5"
ruby_version = "2.6.6"
execute "systemctl daemon-reload" do
command "systemctl daemon-reload"

View File

@ -1,10 +0,0 @@
[Unit]
Description=EncFS for PostgreSQL data dir
Before=postgresql@12-main.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/mount_pg_encfs
ExecStop=/bin/umount /var/lib/postgresql
[Install]
WantedBy=multi-user.target

View File

@ -29,5 +29,11 @@ class Chef
server_node['ipaddress']
end
end
def postgresql_service_name
postgresql_version = "12"
"postgresql@#{postgresql_version}-main"
end
end
end

View File

@ -62,11 +62,11 @@ postgresql_replicas.each do |replica|
unless node.chef_environment == "development"
include_recipe "firewall"
firewall_rule "postgresql" do
firewall_rule "postgresql replica #{replica[:hostname]}" do
port 5432
protocol :tcp
command :allow
destination replica[:ipaddress]
source replica[:ipaddress]
end
end
end

View File

@ -29,7 +29,6 @@ postgresql_service = "postgresql@#{postgresql_version}-main"
postgresql_custom_server postgresql_version do
role "replica"
encfs true
end
service postgresql_service do
@ -49,10 +48,11 @@ unless primary.nil?
command <<-EOF
systemctl stop #{postgresql_service}
mv #{postgresql_data_dir} #{postgresql_data_dir}.old
PGPASSWORD=#{postgresql_data_bag_item['replication_password']} pg_basebackup -h #{primary[:ipaddress]} -U replication -D #{postgresql_data_dir} -R
pg_basebackup -h #{primary[:ipaddress]} -U replication -D #{postgresql_data_dir} -R
chown -R postgres:postgres #{postgresql_data_dir}
systemctl start #{postgresql_service}
EOF
environment 'PGPASSWORD' => postgresql_data_bag_item['replication_password']
sensitive true
not_if { ::File.exist? "#{postgresql_data_dir}/standby.signal" }
end
@ -73,11 +73,11 @@ systemctl start #{postgresql_service}
unless node.chef_environment == "development"
include_recipe "firewall"
firewall_rule "postgresql" do
firewall_rule "postgresql primary #{primary[:hostname]}" do
port 5432
protocol :tcp
command :allow
destination primary[:ipaddress]
source primary[:ipaddress]
end
end
end

View File

@ -2,16 +2,23 @@ resource_name :postgresql_custom_server
property :postgresql_version, String, required: true, name_property: true
property :role, String, required: true # Can be primary or replica
property :encfs, [TrueClass, FalseClass], default: false
action :create do
postgresql_version = new_resource.postgresql_version
postgresql_data_dir = data_dir(postgresql_version)
postgresql_data_dir = "/mnt/data/postgresql/#{postgresql_version}/main"
postgresql_service = "postgresql@#{postgresql_version}-main"
node.override['build-essential']['compile_time'] = true
include_recipe 'build-essential::default'
directory postgresql_data_dir do
owner "postgres"
group "postgres"
mode "0750"
recursive true
action :create
end
package("libpq-dev") { action :nothing }.run_action(:install)
chef_gem 'pg' do
@ -38,46 +45,6 @@ action :create do
action :install
end
postgresql_user "replication" do
action :create
replication true
password postgresql_data_bag_item['replication_password']
end
if new_resource.encfs
# FIXME: encfs always runs a configuration assistant when creating a new
# volume, so this needs to be done manually:
# systemctl stop postgresql@12-main
# mv /var/lib/postgresql /var/lib/postgresql.old
# encfs /var/lib/postgresql_encrypted /var/lib/postgresql --public
# Pick p (paranoia mode) and enter the password from the data bag twice
# mv /var/lib/postgresql/* /var/lib/postgresql/
# systemctl start postgresql@12-main
package "encfs"
template "/usr/local/bin/mount_pg_encfs" do
source "mount_pg_encfs.erb"
mode "0700"
variables password: postgresql_data_bag_item["encfs_password"]
end
execute "systemctl daemon-reload" do
command "systemctl daemon-reload"
action :nothing
end
# The service will automatically mount the encrypted volume on startup
cookbook_file "/lib/systemd/system/encfs_postgresql.service" do
source "encfs.service"
notifies :run, "execute[systemctl daemon-reload]", :delayed
end
service "encfs_postgresql" do
action [:enable]
end
end
shared_buffers = if node['memory']['total'].to_i / 1024 < 1024 # > 1GB RAM
"128MB"
else # >= 1GB RAM, use 25% of total RAM
@ -91,6 +58,7 @@ action :create do
dynamic_shared_memory_type: "posix",
timezone: "UTC", # default is GMT
listen_addresses: "0.0.0.0",
data_directory: postgresql_data_dir
}
if new_resource.role == "replica"
@ -129,6 +97,13 @@ action :create do
additional_config additional_config
notifies :reload, "service[#{postgresql_service}]"
end
postgresql_user "replication" do
action :create
replication true
password postgresql_data_bag_item['replication_password']
end
end
action_class do

View File

@ -1,3 +0,0 @@
#!/bin/sh
/bin/echo "<%= @password %>" | encfs /var/lib/postgresql_encrypted /var/lib/postgresql --public -S

22
site-cookbooks/kosmos_encfs/.gitignore vendored Normal file
View File

@ -0,0 +1,22 @@
.vagrant
*~
*#
.#*
\#*#
.*.sw[a-z]
*.un~
# Bundler
Gemfile.lock
gems.locked
bin/*
.bundle/*
# test kitchen
.kitchen/
kitchen.local.yml
# Chef
Berksfile.lock
.zero-knife.rb
Policyfile.lock.json

View File

@ -0,0 +1,7 @@
# kosmos_encfs CHANGELOG
This file is used to list changes made in each version of the kosmos_encfs cookbook.
# 0.1.0
Initial release.

View File

@ -0,0 +1,20 @@
Copyright (c) 2020 Kosmos Developers
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,3 @@
# kosmos_encfs
Install encfs and set up encryption for a data directory

View File

@ -0,0 +1,110 @@
# Put files/directories that should be ignored in this file when uploading
# to a Chef Infra Server or Supermarket.
# Lines that start with '# ' are comments.
# OS generated files #
######################
.DS_Store
ehthumbs.db
Icon?
nohup.out
Thumbs.db
# SASS #
########
.sass-cache
# EDITORS #
###########
.#*
.project
.settings
*_flymake
*_flymake.*
*.bak
*.sw[a-z]
*.tmproj
*~
\#*
mkmf.log
REVISION
TAGS*
tmtags
## COMPILED ##
##############
*.class
*.com
*.dll
*.exe
*.o
*.pyc
*.so
*/rdoc/
a.out
# Testing #
###########
.circleci/*
.codeclimate.yml
.foodcritic
.kitchen*
.rspec
.rubocop.yml
.travis.yml
.watchr
azure-pipelines.yml
examples/*
features/*
Guardfile
kitchen.yml*
Procfile
Rakefile
spec/*
spec/*
spec/fixtures/*
test/*
# SCM #
#######
.git
.gitattributes
.gitconfig
.github/*
.gitignore
.gitmodules
.svn
*/.bzr/*
*/.git
*/.hg/*
*/.svn/*
# Berkshelf #
#############
Berksfile
Berksfile.lock
cookbooks/*
tmp
# Bundler #
###########
vendor/*
Gemfile
Gemfile.lock
# Policyfile #
##############
Policyfile.rb
Policyfile.lock.json
# Cookbooks #
#############
CHANGELOG*
CONTRIBUTING*
TESTING*
CODE_OF_CONDUCT*
# Vagrant #
###########
.vagrant
Vagrantfile

View File

@ -0,0 +1,11 @@
[Unit]
Description=EncFS for data dir
Before=postgresql@12-main.service
BindsTo=postgresql@12-main.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/mount_encfs
ExecStop=/bin/umount /mnt/data
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,20 @@
name 'kosmos_encfs'
maintainer 'The Authors'
maintainer_email 'you@example.com'
license 'All Rights Reserved'
description 'Installs/Configures kosmos_encfs'
long_description 'Installs/Configures kosmos_encfs'
version '0.1.0'
chef_version '>= 14.0'
# The `issues_url` points to the location where issues for this cookbook are
# tracked. A `View Issues` link will be displayed on this cookbook's page when
# uploaded to a Supermarket.
#
# issues_url 'https://github.com/<insert_org_here>/kosmos_encfs/issues'
# The `source_url` points to the development repository for this cookbook. A
# `View Source` link will be displayed on this cookbook's page when uploaded to
# a Supermarket.
#
# source_url 'https://github.com/<insert_org_here>/kosmos_encfs'

View File

@ -0,0 +1,70 @@
#
# Cookbook:: kosmos_encfs
# Recipe:: default
#
# The MIT License (MIT)
#
# Copyright:: 2020, Kosmos Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
encfs_data_bag_item = data_bag_item("credentials", "encfs")
encfs_password = encfs_data_bag_item["password"]
package "encfs"
encrypted_directory = "/usr/local/lib/encrypted_data"
mount_directory = "/mnt/data"
template "/usr/local/bin/mount_encfs" do
source "mount_encfs.erb"
mode "0700"
variables encrypted_directory: encrypted_directory,
mount_directory: mount_directory
end
execute "systemctl daemon-reload" do
command "systemctl daemon-reload"
action :nothing
end
directory mount_directory do
action :create
mode "0775"
end
execute "create encrypted file system" do
command <<-EOF
echo "y\\\n
y\\\n
p\\\n
#{encfs_password}\\\n
#{encfs_password}\\\n
" | encfs #{encrypted_directory} #{mount_directory} --public --stdinpass
EOF
sensitive true
not_if { ::File.exist?(encrypted_directory) }
end
# The service will automatically
cookbook_file "/lib/systemd/system/encfs.service" do
source "encfs.service"
notifies :run, "execute[systemctl daemon-reload]", :delayed
end

View File

@ -0,0 +1,3 @@
#!/bin/sh
systemd-ask-password --echo "encfs password:" | encfs <%= @encrypted_directory %> <%= @mount_directory %> --public -S

22
site-cookbooks/kosmos_gitea/.gitignore vendored Normal file
View File

@ -0,0 +1,22 @@
.vagrant
*~
*#
.#*
\#*#
.*.sw[a-z]
*.un~
# Bundler
Gemfile.lock
gems.locked
bin/*
.bundle/*
# test kitchen
.kitchen/
kitchen.local.yml
# Chef
Berksfile.lock
.zero-knife.rb
Policyfile.lock.json

View File

@ -0,0 +1,7 @@
# kosmos_gitea CHANGELOG
This file is used to list changes made in each version of the kosmos_gitea cookbook.
# 0.1.0
Initial release.

View File

@ -0,0 +1,20 @@
Copyright (c) 2020 Kosmos Developers
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,18 @@
# kosmos_gitea
## Recipes
### default
Deploys the gitea binary, generates a config file and our custom Kosmos label
set. The service runs as a Systemd unit.
### backup
Back up the `/var/lib/gitea` directory using the
[backup](https://backup.github.io/backup/) tool and our backup cookbook
### pg_db
Should be executed on the primary PostgreSQL server (`postgresql_primary` role)
to create the user, database and access rules

View File

@ -0,0 +1,6 @@
gitea_version = "1.11.5"
node.default["kosmos_gitea"]["version"] = gitea_version
node.default["kosmos_gitea"]["binary_url"] = "https://dl.gitea.io/gitea/#{gitea_version}/gitea-#{gitea_version}-linux-amd64"
node.default["kosmos_gitea"]["binary_checksum"] = "d8d43c13e71596c79b541e85e29defe065b4f70ac5155e6d0212bcfc669e1b9c"
node.default["kosmos_gitea"]["nginx"]["domain"] = "gitea.kosmos.org"
node.default["kosmos_gitea"]["working_directory"] = "/var/lib/gitea"

View File

@ -0,0 +1,110 @@
# Put files/directories that should be ignored in this file when uploading
# to a Chef Infra Server or Supermarket.
# Lines that start with '# ' are comments.
# OS generated files #
######################
.DS_Store
ehthumbs.db
Icon?
nohup.out
Thumbs.db
# SASS #
########
.sass-cache
# EDITORS #
###########
.#*
.project
.settings
*_flymake
*_flymake.*
*.bak
*.sw[a-z]
*.tmproj
*~
\#*
mkmf.log
REVISION
TAGS*
tmtags
## COMPILED ##
##############
*.class
*.com
*.dll
*.exe
*.o
*.pyc
*.so
*/rdoc/
a.out
# Testing #
###########
.circleci/*
.codeclimate.yml
.foodcritic
.kitchen*
.rspec
.rubocop.yml
.travis.yml
.watchr
azure-pipelines.yml
examples/*
features/*
Guardfile
kitchen.yml*
Procfile
Rakefile
spec/*
spec/*
spec/fixtures/*
test/*
# SCM #
#######
.git
.gitattributes
.gitconfig
.github/*
.gitignore
.gitmodules
.svn
*/.bzr/*
*/.git
*/.hg/*
*/.svn/*
# Berkshelf #
#############
Berksfile
Berksfile.lock
cookbooks/*
tmp
# Bundler #
###########
vendor/*
Gemfile
Gemfile.lock
# Policyfile #
##############
Policyfile.rb
Policyfile.lock.json
# Cookbooks #
#############
CHANGELOG*
CONTRIBUTING*
TESTING*
CODE_OF_CONDUCT*
# Vagrant #
###########
.vagrant
Vagrantfile

View File

@ -0,0 +1,15 @@
#db231d bug ; Something is not working
#ead746 docs ; Documentation
#76db1d enhancement ; Improving existing functionality
#1d76db feature ; New functionality
#db1d76 idea ; Something to consider
#db1d76 question ; Looking for an answer
#fbca04 security ; All your base are belong to us
#1dd5db ui/ux ; User interface, process design, etc.
#333333 dev environment ; Config, builds, CI, deployment, etc.
#008080 kredits-1 ; Small contribution
#008080 kredits-2 ; Medium contribution
#008080 kredits-3 ; Large contribution
#cccccc duplicate ; This issue or pull request already exists
#cccccc invalid ; Not a bug
#cccccc wontfix ; This won't be fixed

View File

@ -0,0 +1,24 @@
name 'kosmos_gitea'
maintainer 'Kosmos Developers'
maintainer_email 'ops@kosmos.org'
license 'MIT'
description 'Installs/Configures kosmos_gitea'
long_description 'Installs/Configures kosmos_gitea'
version '0.1.0'
chef_version '>= 14.0'
# The `issues_url` points to the location where issues for this cookbook are
# tracked. A `View Issues` link will be displayed on this cookbook's page when
# uploaded to a Supermarket.
#
# issues_url 'https://github.com/<insert_org_here>/kosmos_gitea/issues'
# The `source_url` points to the development repository for this cookbook. A
# `View Source` link will be displayed on this cookbook's page when uploaded to
# a Supermarket.
#
# source_url 'https://github.com/<insert_org_here>/kosmos_gitea'
depends "kosmos-nginx"
depends "kosmos-postgresql"
depends "backup"

View File

@ -0,0 +1,31 @@
#
# Cookbook:: kosmos_gitea
# Recipe:: backup
#
# The MIT License (MIT)
#
# Copyright:: 2020, Kosmos Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
unless node.chef_environment == "development"
# backup the data dir and the config files
node.override["backup"]["archives"]["gitea"] = [node["kosmos_gitea"]["working_directory"]]
include_recipe "backup"
end

View File

@ -0,0 +1,155 @@
#
# Cookbook:: kosmos_gitea
# Recipe:: default
#
# The MIT License (MIT)
#
# Copyright:: 2020, Kosmos Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
include_recipe "kosmos-nginx"
domain = node["kosmos_gitea"]["nginx"]["domain"]
working_directory = node["kosmos_gitea"]["working_directory"]
git_home_directory = "/home/git"
config_directory = "/etc/gitea"
gitea_binary_path = "/usr/local/bin/gitea"
gitea_data_bag_item = data_bag_item("credentials", "gitea")
smtp_credentials = data_bag_item("credentials", "smtp")
jwt_secret = gitea_data_bag_item["jwt_secret"]
internal_token = gitea_data_bag_item["internal_token"]
secret_key = gitea_data_bag_item["secret_key"]
postgresql_primary_node = postgresql_primary
postgresql_server = postgresql_primary_node[:ipaddress]
# PostgreSQL is on the same server, connect through localhost
postgresql_server = "localhost" if postgresql_primary_node[:hostname] == node[:hostname]
# Dependency
package "git"
user "git" do
manage_home true
home "/home/git"
end
directory working_directory do
owner "git"
group "git"
mode "0750"
end
%w(custom custom/options custom/options/label).each do |path|
directory "#{working_directory}/#{path}" do
owner "git"
group "git"
mode "0750"
end
end
# Kosmos label set
cookbook_file "#{working_directory}/custom/options/label/Kosmos" do
source "custom/options/label/Kosmos"
owner "git"
group "git"
mode "0640"
end
directory config_directory do
owner "git"
group "git"
mode "0750"
end
# Copy the self-signed root certificate to the system certificate store. Gitea
# will find it there automatically
postgresql_data_bag_item = data_bag_item('credentials', 'postgresql')
root_cert_path = "/etc/ssl/certs/root.kosmos.org.crt"
file root_cert_path do
content postgresql_data_bag_item['ssl_root_cert']
mode "0644"
end
template "#{config_directory}/app.ini" do
source "app.ini.erb"
owner "git"
group "git"
mode "0640"
sensitive true
variables working_directory: working_directory,
git_home_directory: git_home_directory,
config_directory: config_directory,
gitea_binary_path: gitea_binary_path,
jwt_secret: jwt_secret,
internal_token: internal_token,
secret_key: secret_key,
postgresql_host: "#{postgresql_server}:5432",
postgresql_password: gitea_data_bag_item["postgresql_password"],
smtp_host: smtp_credentials["relayhost"],
smtp_user: smtp_credentials["user_name"],
smtp_password: smtp_credentials["password"]
notifies :restart, "service[gitea]", :delayed
end
remote_file gitea_binary_path do
source node['kosmos_gitea']['binary_url']
checksum node['kosmos_gitea']['binary_checksum']
mode "0755"
end
execute "systemctl daemon-reload" do
action :nothing
end
template "/etc/systemd/system/gitea.service" do
source "gitea.service.erb"
variables working_directory: working_directory,
git_home_directory: git_home_directory,
config_directory: config_directory,
gitea_binary_path: gitea_binary_path
notifies :run, "execute[systemctl daemon-reload]", :delayed
end
service "gitea" do
action [:enable, :start]
end
template "#{node['nginx']['dir']}/sites-available/#{domain}" do
source "nginx_conf.erb"
owner 'www-data'
mode 0640
variables server_name: domain,
ssl_cert: "/etc/letsencrypt/live/#{domain}/fullchain.pem",
ssl_key: "/etc/letsencrypt/live/#{domain}/privkey.pem",
upstream_port: 3000
notifies :reload, 'service[nginx]', :delayed
end
nginx_site domain do
action :enable
end
# Enable when we switch the IP of gitea.kosmos.org
# nginx_certbot_site domain
unless node.chef_environment == "development"
include_recipe "firewall"
end

View File

@ -0,0 +1,37 @@
#
# Cookbook:: kosmos_gitea
# Recipe:: pg_db
#
# Copyright:: 2020, Kosmos Developers, All Rights Reserved.
gitea_data_bag_item = data_bag_item("credentials", "gitea")
postgresql_service = "service[#{postgresql_service_name}]"
service postgresql_service do
supports restart: true, status: true, reload: true
end
postgresql_user "gitea" do
action :create
password gitea_data_bag_item["postgresql_password"]
end
postgresql_database "gitea" do
owner "gitea"
action :create
end
search(:node, "role:gitea AND chef_environment:#{node.chef_environment}").each do |gitea_server|
ip = ip_for(gitea_server)
hostname = gitea_server[:hostname]
postgresql_access "gitea #{hostname}" do
access_type "host"
access_db "gitea"
access_user "gitea"
access_addr "#{ip}/32"
access_method "md5"
notifies :reload, postgresql_service, :delayed
end
end

View File

@ -0,0 +1,82 @@
APP_NAME = Gitea
RUN_MODE = prod
[server]
SSH_DOMAIN = gitea.kosmos.org
HTTP_PORT = 3000
DISABLE_SSH = false
SSH_PORT = 22
PROTOCOL = http
DOMAIN = gitea.kosmos.org
ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s
# REDIRECT_OTHER_PORT = true
# PORT_TO_REDIRECT = 3001
# ENABLE_LETSENCRYPT = true
# LETSENCRYPT_ACCEPTTOS = true
# LETSENCRYPT_DIRECTORY = /data/gitea/https
# LETSENCRYPT_EMAIL = ops@5apps.com
[database]
DB_TYPE = postgres
HOST = <%= @postgresql_host %>
NAME = gitea
USER = gitea
PASSWD = <%= @postgresql_password %>
SSL_MODE = verify-ca
# [indexer]
# ISSUE_INDEXER_PATH = /data/gitea/indexers/issues.bleve
[session]
PROVIDER = file
PROVIDER_CONFIG = sessions
# Enable when TLS is enabled
# COOKIE_SECURE = true
[mailer]
ENABLED = true
HOST = <%= @smtp_host %>
FROM = gitea@kosmos.org
USER = <%= @smtp_user %>
PASSWD = <%= @smtp_password %>
[oauth2]
JWT_SECRET = <%= @jwt_secret %>
[security]
INTERNAL_TOKEN = <%= @internal_token %>
INSTALL_LOCK = true
SECRET_KEY = <%= @secret_key %>
[service]
REGISTER_EMAIL_CONFIRM = false
ENABLE_NOTIFY_MAIL = true
DISABLE_REGISTRATION = true
ALLOW_ONLY_EXTERNAL_REGISTRATION = false
ENABLE_CAPTCHA = false
REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = true
DEFAULT_ALLOW_CREATE_ORGANIZATION = false
DEFAULT_ENABLE_TIMETRACKING = false
NO_REPLY_ADDRESS = noreply.kosmos.org
[picture]
DISABLE_GRAVATAR = false
ENABLE_FEDERATED_AVATAR = true
[openid]
ENABLE_OPENID_SIGNIN = false
ENABLE_OPENID_SIGNUP = false
[log]
MODE = console
LEVEL = Debug
[attachment]
ENABLED = true
PATH = data/attachments
ALLOWED_TYPES = image/gif|image/jpeg|image/png|application/zip|application/gzip
; ; Max size of each file. Defaults to 4MB
MAX_SIZE = 10
; ; Max number of files per upload. Defaults to 5
MAX_FILES = 5

View File

@ -0,0 +1,35 @@
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
# Requires=postgresql.service
# Requires=redis.service
[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
LimitMEMLOCK=infinity
LimitNOFILE=65535
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=<%= @working_directory %>
# If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock file
# (manually creating /run/gitea doesn't work, because it would not persist across reboots)
#RuntimeDirectory=gitea
ExecStart=<%= @gitea_binary_path %> web --config <%= @config_directory %>/app.ini
Restart=always
Environment=USER=git HOME=<%= @git_home_directory %> GITEA_WORK_DIR=<%= @working_directory %>
# If you want to bind Gitea to a port below 1024, uncomment
# the two values below, or use socket activation to pass Gitea its ports as above
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
###
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,28 @@
# Generated by Chef
upstream _gitea {
server localhost:<%= @upstream_port %>;
}
server {
<% if File.exist?(@ssl_cert) && !File.exist?(@ssl_key) -%>
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name <%= @server_name %>;
ssl_certificate <%= @ssl_cert %>;
ssl_certificate_key <%= @ssl_key %>;
add_header Strict-Transport-Security "max-age=31536000";
<% else -%>
listen 80;
server_name <%= @server_name %>;
<% end -%>
location / {
# Increase number of buffers. Default is 8
proxy_buffers 1024 8k;
proxy_pass http://_gitea;
proxy_http_version 1.1;
}
}