From cc4c8fb90338b70ac87508097813467c2cc568ed Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 16 Apr 2020 17:52:28 +0200 Subject: [PATCH 001/327] Add hubot-kredits Zoom config --- data_bags/credentials/hal8000_xmpp.json | 49 +++++++++++-------- .../kosmos-hubot/recipes/hal8000_xmpp.rb | 3 +- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/data_bags/credentials/hal8000_xmpp.json b/data_bags/credentials/hal8000_xmpp.json index d0c30fc..3e4320e 100644 --- a/data_bags/credentials/hal8000_xmpp.json +++ b/data_bags/credentials/hal8000_xmpp.json @@ -1,51 +1,58 @@ { "id": "hal8000_xmpp", "xmpp_password": { - "encrypted_data": "A1veV6RnPqIqy+DidWeJ7ACwBRmt94AoS2m81iBHtJk=\n", - "iv": "JWHnQjv0br6fOb0u\n", - "auth_tag": "TcFfG8HX+QkwPIQ0lHzswg==\n", + "encrypted_data": "iSQ/GCJvEj+uJ16Ndp8AfponI0Tg/Z7oYvA80mqAvVA=\n", + "iv": "CUp8NKx/5cu3bqCI\n", + "auth_tag": "BGomAzBuViX38bUKoYYxiw==\n", "version": 3, "cipher": "aes-256-gcm" }, "webhook_token": { - "encrypted_data": "GVnCrv7Dgg3YGwJO7unDv2aHkHBpbfoAs+7lljTBx5HdOqKX\n", - "iv": "/PzTocEqCTwq8lBD\n", - "auth_tag": "HLqh9CPZYVaJxI0jWbtLpg==\n", + "encrypted_data": "g6qSxL7JAQlBy2O5g1GCC6DmXm7vGJaV9P47g4Wyj8buYExD\n", + "iv": "lLAxwl9h5L3j7Gq7\n", + "auth_tag": "zx0Uy/crHGAELYRKaBNXAg==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_webhook_token": { - "encrypted_data": "xxEyjeTa8AOZnqr2LUZtogbEPnN3ycviJpjlqruK+pPPlJs=\n", - "iv": "yeqxtkW8P7o4qI7T\n", - "auth_tag": "Ok0P86MLLw11c9slr43mvA==\n", + "encrypted_data": "Ver2bAA7rLBCtmy/VBYtirlercbt3cVUotY3Pv6SdbHG0Ak=\n", + "iv": "cf84lg3B+SQWoRQL\n", + "auth_tag": "UQTb5/NtEbm4I9xINs2yeQ==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_wallet_password": { - "encrypted_data": "dgU5YpNgP0FcceWOnFm9NC5DU+3XZuP9Tq3LeKZwBMulfA==\n", - "iv": "428A3tDCpZrX6tE7\n", - "auth_tag": "ler/y0GNHXHpox4xRMdDmg==\n", + "encrypted_data": "dreUxCjqv0IM2vjI7oe9/l9Ia6DkQljYwPb4ZJwC6m0H4g==\n", + "iv": "Fand4DZjlEbvkcKa\n", + "auth_tag": "prqZA8GlIie+1fidHaYtMw==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_session_secret": { - "encrypted_data": "D7nhOxG0mBQBdiLCAjEiVJgGphjow3NnOe3IBD7BZWky8rj8d/sEUzz1a322\nrLJEwCOeHdtf\n", - "iv": "ObIHcJ6nylGkvtuU\n", - "auth_tag": "+RMiUPzvg7Didu2gRtJxhA==\n", + "encrypted_data": "s4mhAFFLen7vEHwotcdlccp6LzUuQcW7MegamsyA6sL+ndb7brcghkmTxkFf\nPy74iIYqu+qM\n", + "iv": "3vTP43/hXV8oLeaj\n", + "auth_tag": "hwjX7HV8rUMWq46LMva/SA==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_github_key": { - "encrypted_data": "UF3FUnMMGXXMWWJQ7mrywFWKzJL7VP6iWBkZ8K5Z6VN2bpjxaZrQ\n", - "iv": "heAtzJMhnssXKoXo\n", - "auth_tag": "88k/WwYKqq8ii29MmMq0hA==\n", + "encrypted_data": "89zHSvHE/x58i2ghMsHeUrx6VbeW7dygNnQr0kz4SbMa3yJ+gw9E\n", + "iv": "C5i/SXqmi5UsJ1Xo\n", + "auth_tag": "QufI517NeIyoFRQJ0VNx7g==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_github_secret": { - "encrypted_data": "QSyFIBpRP2+98Bfvr0uDdWsmuOun3Kqqbq6M0a4ZSm3pbfowiDnIOFc/4Yvn\nxmRh089MwaGjW02QgOU=\n", - "iv": "3eyJzACgqtLCilKq\n", - "auth_tag": "HsD08zQpCtTRwR2IhkSWIw==\n", + "encrypted_data": "Lj5PAFC/71Exg6pFph8/5w9MCYodDPZjz2/00Dirfvh+LhCl6wuwFXJwD21W\ndDV6/k+mNIufmLEAL+U=\n", + "iv": "OrG+cRZASFa1iFrI\n", + "auth_tag": "o+E8v6mMfCC0x9wzVCFoZg==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "kredits_zoom_jwt": { + "encrypted_data": "piQLeodQKf8P7OY9Wp7En16IXryDPbIWNbl1nDcpBLVGkLbDLmrYw6sNgmlt\nyIjU7PwZGmtl56jaREYT/Kkd9QRcBf31v+pC19uiDzKaQUlEtTUvBQFgrRm8\nWuppievcwa3wUrtKZSAz9wi1jFLPezb92mDTZ0xP4IQi70SUluvq8gztT+40\nhL0FhcAeA6KFXhD98pVNRPXB8TjUg9pQx5z9MkUH798FoPL9kFQfLFEMp1mK\nFhohwA0bEPWYx+NQl6D+LNBHMFCbnzQ=\n", + "iv": "7Y8HdmQDjV+WJgLH\n", + "auth_tag": "n36iqqN51yjNCg4Vw/gTfg==\n", "version": 3, "cipher": "aes-256-gcm" } diff --git a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb index f69055d..98da72d 100644 --- a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb +++ b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb @@ -119,7 +119,8 @@ application app_path do "KREDITS_GRANT_PROTOCOL" => "https", "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_GITHUB_SECRET" => data_bag['kredits_github_secret'], + "KREDITS_ZOOM_JWT" => data_bag['kredits_zoom_jwt'] } ) notifies :run, "execute[systemctl daemon-reload]", :delayed From 73e87f8f45c82f40c473f821cec17822d4fb7ba5 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 19 Apr 2020 13:01:39 +0200 Subject: [PATCH 002/327] Improve LDAP example command We should not log passwords in bash history files. This change will prompt the user for the password instead. --- doc/ldap.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/ldap.md b/doc/ldap.md index 1e3c80c..7ebe26f 100644 --- a/doc/ldap.md +++ b/doc/ldap.md @@ -1,6 +1,6 @@ -# LDAP (389 Directory Server). +# LDAP (389 Directory Server) -## Credentials +## Credentials The admin account is `cn=Directory Manager` with the password stored in the encrypted data bag `admin_password` item @@ -9,8 +9,8 @@ encrypted data bag `admin_password` item $ knife data bag show credentials dirsrv --secret-file .chef/encrypted_data_bag_secret ``` -## Example search: +## Example search (will prompt for password): ``` -$ ldapsearch -x -w $password -D 'cn=Directory Manager' -b "ou=users,dc=kosmos,dc=org" -H "ldaps://ldap.kosmos.org" -v +$ ldapsearch -x -W -D 'cn=Directory Manager' -b "ou=users,dc=kosmos,dc=org" -H "ldaps://ldap.kosmos.org" -v ``` From f5dd2c7de966459ad5a2ee1fd67d51a3332ad80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 20 Apr 2020 14:52:11 +0200 Subject: [PATCH 003/327] Fix the command importing the schema on db creation It had an extra }, but this only fails when creating the databases --- site-cookbooks/kosmos-ejabberd/recipes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index c11aaaa..7128867 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -122,7 +122,7 @@ hosts.each do |host| execute "create db schema #{host[:sql_database]}" do user "ejabberd" - command "psql #{host[:sql_database]}} < #{Chef::Config[:file_cache_path]}/pg.sql" + command "psql #{host[:sql_database]} < #{Chef::Config[:file_cache_path]}/pg.sql" action :nothing end From db8bb44c8bd3694fb8937a18889e2f1db301bac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 20 Apr 2020 14:53:08 +0200 Subject: [PATCH 004/327] Update ejabberd to 20.03 The download URL has changed, they removed a prefix Closes #153 --- site-cookbooks/kosmos-ejabberd/attributes/default.rb | 4 ++-- site-cookbooks/kosmos-ejabberd/recipes/default.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/site-cookbooks/kosmos-ejabberd/attributes/default.rb b/site-cookbooks/kosmos-ejabberd/attributes/default.rb index c71d3b5..22d1e9d 100644 --- a/site-cookbooks/kosmos-ejabberd/attributes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/attributes/default.rb @@ -1,5 +1,5 @@ -node.default["kosmos-ejabberd"]["version"] = "20.02" -node.default["kosmos-ejabberd"]["checksum"] = "2ecbf7025195afaa41996cb6f1c2b5fac661f2880238506a459779051129bc93" +node.default["kosmos-ejabberd"]["version"] = "20.03" +node.default["kosmos-ejabberd"]["checksum"] = "f0ccf1c47c3a30303140f08c887998ee34e731f34ea240d56748a68aa2a2e303" node.override["tor"]["HiddenServices"]["ejabberd"] = { "HiddenServicePorts" => [ diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index 7128867..2de0b63 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -38,7 +38,7 @@ package_checksum = node["kosmos-ejabberd"]["checksum"] package_path = "#{Chef::Config['file_cache_path']}/ejabberd_#{ejabberd_version}-0_amd64.deb" remote_file package_path do - source "https://www.process-one.net/downloads/downloads-action.php?file=/ejabberd/#{ejabberd_version}/ejabberd_#{ejabberd_version}-0_amd64.deb" + source "https://www.process-one.net/downloads/downloads-action.php?file=/#{ejabberd_version}/ejabberd_#{ejabberd_version}-0_amd64.deb" checksum package_checksum notifies :install, "dpkg_package[ejabberd]", :immediately end From 3ca8ab45da5649b334c8add5a0e99b285f25f640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 20 Apr 2020 18:58:30 +0200 Subject: [PATCH 005/327] Fix the invalid ACIs on initial creation This is only executed on initial creation of the instance, the production one is using these fixed ACIs, this was only an issue with the setup The issue was the ACI was set at the wrong level --- site-cookbooks/kosmos-dirsrv/files/users.ldif | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-dirsrv/files/users.ldif b/site-cookbooks/kosmos-dirsrv/files/users.ldif index 136fd00..3ae1306 100644 --- a/site-cookbooks/kosmos-dirsrv/files/users.ldif +++ b/site-cookbooks/kosmos-dirsrv/files/users.ldif @@ -1,6 +1,12 @@ +# kosmos.org +dn: dc=kosmos,dc=org +objectClass: top +objectClass: domain +dc: kosmos +aci: (target="ldap:///dc=kosmos,dc=org") (version 3.0; acl "user-deny-all"; deny (all) userdn="ldap:///dc=kosmos,dc=org";) +aci: (target="ldap:///dc=kosmos,dc=org")(targetattr="userPassword") (version 3.0; acl "user-write-own-password"; allow (write) userdn="ldap:///self";) + dn: ou=users,dc=kosmos,dc=org objectClass: top objectClass: organizationalUnit ou: users -aci: (target="ldap:///dc=kosmos,dc=org") (version 3.0; acl "user-deny-all"; deny (all) userdn="ldap:///dc=kosmos,dc=org";) -aci: (target="ldap:///dc=kosmos,dc=org")(targetattr="userPassword") (version 3.0; acl "user-write-own-password"; allow (write) userdn="ldap:///self";) From d01c9a4d0a0a4aa936842bde378bc8b19d6dc0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 20 Apr 2020 19:09:43 +0200 Subject: [PATCH 006/327] Fix the name of the deploy certbot hook --- site-cookbooks/kosmos-dirsrv/resources/instance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-dirsrv/resources/instance.rb b/site-cookbooks/kosmos-dirsrv/resources/instance.rb index c27e472..97cd492 100644 --- a/site-cookbooks/kosmos-dirsrv/resources/instance.rb +++ b/site-cookbooks/kosmos-dirsrv/resources/instance.rb @@ -118,7 +118,7 @@ nsslapd-allow-anonymous-access: off done EOF - file "/etc/letsencrypt/renewal-hooks/deploy/dirsrrv" do + file "/etc/letsencrypt/renewal-hooks/deploy/dirsrv" do content dirsrv_hook mode 0755 owner "root" From 5e3c8066f9672afaf6b4490803a7565a26888f8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 20 Apr 2020 19:10:15 +0200 Subject: [PATCH 007/327] Add the missing certbot command to generate the LDAP TLS cert This had been done manually on barnard. This will not be executed on barnard again since the cert exists --- site-cookbooks/kosmos-dirsrv/resources/instance.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/site-cookbooks/kosmos-dirsrv/resources/instance.rb b/site-cookbooks/kosmos-dirsrv/resources/instance.rb index 97cd492..0ef689b 100644 --- a/site-cookbooks/kosmos-dirsrv/resources/instance.rb +++ b/site-cookbooks/kosmos-dirsrv/resources/instance.rb @@ -129,9 +129,21 @@ nsslapd-allow-anonymous-access: off source 'nginx_conf_empty.erb' owner node["nginx"]["user"] mode 0640 + notifies :reload, 'service[nginx]', :delayed end nginx_certbot_site new_resource.hostname do + notifies :run, "letsencrypt cert for #{domain}", :delayed + end + + # Generate a Let's Encrypt cert (only if the nginx vhost exists and no cert + # has been generated before. The renew cron will take care of renewing + execute "letsencrypt cert for #{domain}" do + command "/usr/bin/certbot certonly --webroot --agree-tos --email ops@kosmos.org --webroot-path #{root_directory} --deploy-hook /etc/letsencrypt/renewal-hooks/deploy/dirsrv -d #{domain} -n" + only_if do + ::File.exist?("#{node['nginx']['dir']}/sites-enabled/#{domain}_certbot") && + !::File.exist?("/etc/letsencrypt/live/#{domain}/fullchain.pem") + end notifies :run, "execute[add tls config]", :immediately end From 1c920a8cb2731f7a0fd335f0ae276ba3179fa50b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 20 Apr 2020 19:11:34 +0200 Subject: [PATCH 008/327] Remove the encryption keys after TLS cert renewal This is done with awk, this was the best way I found to perform the multi-line deletion. It deletes both the AES AND 3DES sections The keys will be recreated on service restart https://access.redhat.com/documentation/en-us/red_hat_directory_server/9.0/html/administration_guide/ssl-and-attr-encryption Closes #152 --- .../kosmos-dirsrv/resources/instance.rb | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/site-cookbooks/kosmos-dirsrv/resources/instance.rb b/site-cookbooks/kosmos-dirsrv/resources/instance.rb index 0ef689b..de6b6fd 100644 --- a/site-cookbooks/kosmos-dirsrv/resources/instance.rb +++ b/site-cookbooks/kosmos-dirsrv/resources/instance.rb @@ -101,21 +101,25 @@ nsslapd-allow-anonymous-access: off include_recipe "kosmos-base::letsencrypt" dirsrv_hook = <<-EOF - #!/usr/bin/env bash +#!/usr/bin/env bash - set -e +set -e - # Copy the dirsrv certificate and restart the server if it has been renewed - # This is necessary because dirsrv uses a different format for the certificates - for domain in $RENEWED_DOMAINS; do - case $domain in - #{new_resource.hostname}) - openssl pkcs12 -export -in "${RENEWED_LINEAGE}/fullchain.pem" -inkey "${RENEWED_LINEAGE}/privkey.pem" -out #{Chef::Config[:file_cache_path]}/#{new_resource.hostname}.p12 -name 'Server-Cert' -passout pass: - pk12util -i #{Chef::Config[:file_cache_path]}/#{new_resource.hostname}.p12 -d #{inst_dir} -W '' - systemctl restart #{service_name} - ;; - esac - done +# Copy the dirsrv certificate and restart the server if it has been renewed +# This is necessary because dirsrv uses a different format for the certificates +for domain in $RENEWED_DOMAINS; do + case $domain in + #{new_resource.hostname}) + openssl pkcs12 -export -in "${RENEWED_LINEAGE}/fullchain.pem" -inkey "${RENEWED_LINEAGE}/privkey.pem" -out #{Chef::Config[:file_cache_path]}/#{new_resource.hostname}.p12 -name 'Server-Cert' -passout pass: + pk12util -i #{Chef::Config[:file_cache_path]}/#{new_resource.hostname}.p12 -d #{inst_dir} -W '' + # Remove the encryption key entries from the current database. + # They will be recreated on restart for the new certificate + awk '! /^dn: cn=3D|AES,cn=encrypted attribute keys,cn=userRoot/ {print; printf "\n" ; }' RS="" #{inst_dir}/dse.ldif > #{inst_dir}/dse_new.ldif + mv #{inst_dir}/dse_new.ldif #{inst_dir}/dse.ldif + systemctl restart #{service_name} + ;; + esac +done EOF file "/etc/letsencrypt/renewal-hooks/deploy/dirsrv" do From 35a56aa221c6f2a9cbeba351124297cf76319fd5 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 1 May 2020 14:55:13 +0200 Subject: [PATCH 009/327] Update version to 20.04 --- site-cookbooks/kosmos-ejabberd/attributes/default.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-ejabberd/attributes/default.rb b/site-cookbooks/kosmos-ejabberd/attributes/default.rb index 22d1e9d..f383af4 100644 --- a/site-cookbooks/kosmos-ejabberd/attributes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/attributes/default.rb @@ -1,5 +1,5 @@ -node.default["kosmos-ejabberd"]["version"] = "20.03" -node.default["kosmos-ejabberd"]["checksum"] = "f0ccf1c47c3a30303140f08c887998ee34e731f34ea240d56748a68aa2a2e303" +node.default["kosmos-ejabberd"]["version"] = "20.04" +node.default["kosmos-ejabberd"]["checksum"] = "5377ff18960a399e661fa23f4a1d9f57c78d4579ed108c52b8f68e7cd9268868" node.override["tor"]["HiddenServices"]["ejabberd"] = { "HiddenServicePorts" => [ From ef2fa2da722d93d57a9d69f87a67f8e63a8dea78 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 1 May 2020 16:25:38 +0200 Subject: [PATCH 010/327] Configure STUN/TURN Configures built-in STUN/TURN support, and adds the new service discovery module for it. --- site-cookbooks/kosmos-ejabberd/recipes/default.rb | 6 ++++++ site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index 2de0b63..1899493 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -200,6 +200,12 @@ unless node.chef_environment == "development" protocol :tcp command :allow end + + firewall_rule 'ejabberd_stun_turn' do + port 3478 + protocol :udp + command :allow + end end # diff --git a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb index d657aec..9e4c14e 100644 --- a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb +++ b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb @@ -74,6 +74,13 @@ listen: ## "/pub/archive": mod_http_fileserver ## register: true captcha: false + - + port: 3478 + transport: udp + module: ejabberd_stun + use_turn: true + ## The server's public IPv4 address: + # turn_ip: 203.0.113.3 s2s_use_starttls: optional @@ -214,6 +221,7 @@ modules: versioning: true store_current_id: true mod_shared_roster: {} + mod_stun_disco: {} mod_vcard: search: false mod_vcard_xupdate: {} From 0bcb2597e8b02ff5eaf451d42cc90c88af8712d2 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 2 May 2020 12:41:30 +0200 Subject: [PATCH 011/327] Update node info --- nodes/andromeda.kosmos.org.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodes/andromeda.kosmos.org.json b/nodes/andromeda.kosmos.org.json index f233f14..fc8ce4d 100644 --- a/nodes/andromeda.kosmos.org.json +++ b/nodes/andromeda.kosmos.org.json @@ -19,7 +19,7 @@ "automatic": { "fqdn": "andromeda.kosmos.org", "os": "linux", - "os_version": "4.15.0-74-generic", + "os_version": "4.15.0-96-generic", "hostname": "andromeda", "ipaddress": "46.4.18.160", "roles": [ From 4448ec21733bfbae718f6ee46034109f23338601 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 2 May 2020 14:07:14 +0200 Subject: [PATCH 012/327] Configure TURN properly Was missing a couple of necessary properties, and is now using an explicit port range for TURN, and opening those ports in UFW. --- site-cookbooks/kosmos-ejabberd/attributes/default.rb | 2 ++ site-cookbooks/kosmos-ejabberd/recipes/default.rb | 12 +++++++++++- .../kosmos-ejabberd/templates/ejabberd.yml.erb | 6 ++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/site-cookbooks/kosmos-ejabberd/attributes/default.rb b/site-cookbooks/kosmos-ejabberd/attributes/default.rb index f383af4..f724394 100644 --- a/site-cookbooks/kosmos-ejabberd/attributes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/attributes/default.rb @@ -1,5 +1,7 @@ node.default["kosmos-ejabberd"]["version"] = "20.04" node.default["kosmos-ejabberd"]["checksum"] = "5377ff18960a399e661fa23f4a1d9f57c78d4579ed108c52b8f68e7cd9268868" +node.default["kosmos-ejabberd"]["turn_min_port"] = 49152 +node.default["kosmos-ejabberd"]["turn_max_port"] = 59152 node.override["tor"]["HiddenServices"]["ejabberd"] = { "HiddenServicePorts" => [ diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index 1899493..1572727 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -154,7 +154,11 @@ template "/opt/ejabberd/conf/ejabberd.yml" do sensitive true variables pgsql_password: postgresql_data_bag_item['ejabberd_user_password'], hosts: hosts, - admin_users: admin_users + admin_users: admin_users, + stun_auth_realm: "kosmos.org", + turn_ip_address: node['ipaddress'], + turn_min_port: node["kosmos-ejabberd"]["turn_min_port"], + turn_max_port: node["kosmos-ejabberd"]["turn_max_port"] notifies :run, "execute[ejabberdctl reload_config]", :delayed end @@ -206,6 +210,12 @@ unless node.chef_environment == "development" protocol :udp command :allow end + + firewall_rule 'ejabberd_turn' do + port node["kosmos-ejabberd"]["turn_min_port"]..node["kosmos-ejabberd"]["turn_max_port"] + protocol :udp + command :allow + end end # diff --git a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb index 9e4c14e..5ed892b 100644 --- a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb +++ b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb @@ -78,9 +78,11 @@ listen: port: 3478 transport: udp module: ejabberd_stun + auth_realm: <%= @stun_auth_realm %> use_turn: true - ## The server's public IPv4 address: - # turn_ip: 203.0.113.3 + turn_ip: <%= @turn_ip_address %> + turn_min_port: <%= @turn_min_port %> + turn_max_port: <%= @turn_max_port %> s2s_use_starttls: optional From 21119fff08b89b233dc914289af5eab29562a097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 11 May 2020 18:18:21 +0200 Subject: [PATCH 013/327] Add a custom resource to set up PostgreSQL 12 Supports both primary and replica. The access rules and firewall have to be set up outside of the custom resource, so they are part of the recipes instead Refs #160 --- site-cookbooks/kosmos-postgresql/README.md | 39 +++++- .../kosmos-postgresql/attributes/default.rb | 3 + .../kosmos-postgresql/libraries/helpers.rb | 33 +++++ site-cookbooks/kosmos-postgresql/metadata.rb | 2 + .../kosmos-postgresql/recipes/default.rb | 40 +++--- .../kosmos-postgresql/recipes/firewall.rb | 40 ++++++ .../kosmos-postgresql/recipes/replica.rb | 76 +++++++++++ .../kosmos-postgresql/resources/server.rb | 126 ++++++++++++++++++ .../templates/nginx_conf_empty.erb | 0 9 files changed, 339 insertions(+), 20 deletions(-) create mode 100644 site-cookbooks/kosmos-postgresql/attributes/default.rb create mode 100644 site-cookbooks/kosmos-postgresql/libraries/helpers.rb create mode 100644 site-cookbooks/kosmos-postgresql/recipes/firewall.rb create mode 100644 site-cookbooks/kosmos-postgresql/recipes/replica.rb create mode 100644 site-cookbooks/kosmos-postgresql/resources/server.rb create mode 100644 site-cookbooks/kosmos-postgresql/templates/nginx_conf_empty.erb diff --git a/site-cookbooks/kosmos-postgresql/README.md b/site-cookbooks/kosmos-postgresql/README.md index 9521928..f00dccb 100644 --- a/site-cookbooks/kosmos-postgresql/README.md +++ b/site-cookbooks/kosmos-postgresql/README.md @@ -1,4 +1,41 @@ # kosmos-postgresql -TODO: Enter the cookbook description here. +## Custom resources +### `postgresql_custom_server` + +Usage: + +When the `tls` attribute is set to true, a TLS certificate for the FQDN +(`node['fqdn']`, for example `andromeda.kosmos.org`) is generated using Let's +Encrypt and copied to the PostgreSQL data directory and added to the +`postgresql.conf` file + +#### On the primary: + +```ruby +postgresql_custom_server "12" do + role "primary" + tls true +end +``` + +#### On a replica: + +```ruby +postgresql_custom_server "12" do + role "primary" + tls true +end +``` + +After the initial Chef run on the replica, run Chef on the primary to add the +firewall rules and PostgreSQL access rules, then run Chef again on the replica +to set up replication. + +#### Caveat + +[`firewall_rules`](https://github.com/chef-cookbooks/firewall/issues/134) and +[`postgresql_access`](https://github.com/sous-chefs/postgresql/issues/648) need +to be declared in recipes, not resources because of the way custom resources +work currently in Chef diff --git a/site-cookbooks/kosmos-postgresql/attributes/default.rb b/site-cookbooks/kosmos-postgresql/attributes/default.rb new file mode 100644 index 0000000..dec530f --- /dev/null +++ b/site-cookbooks/kosmos-postgresql/attributes/default.rb @@ -0,0 +1,3 @@ +# This is set to false by default, and set to true in the server resource +# for replicas. +node.default['kosmos-postgresql']['ready_to_set_up_replica'] = false diff --git a/site-cookbooks/kosmos-postgresql/libraries/helpers.rb b/site-cookbooks/kosmos-postgresql/libraries/helpers.rb new file mode 100644 index 0000000..a3331b6 --- /dev/null +++ b/site-cookbooks/kosmos-postgresql/libraries/helpers.rb @@ -0,0 +1,33 @@ +class Chef + class Recipe + def postgresql_primary + postgresql_primary = search(:node, "role:postgresql_primary AND chef_environment:#{node.chef_environment}").first + + unless postgresql_primary.nil? + primary_ip = ip_for(postgresql_primary) + + { hostname: postgresql_primary[:hostname], ipaddress: primary_ip } + end + end + + def postgresql_replicas + postgresql_replicas = [] + + search(:node, "role:postgresql_replica AND chef_environment:#{node.chef_environment}").each do |replica| + replica_ip = ip_for(replica) + + postgresql_replicas << { hostname: replica[:hostname], ipaddress: replica_ip } + end + + postgresql_replicas + end + + def ip_for(server_node) + if node.chef_environment == "development" + server_node['network']['interfaces']['eth1']['routes'].first['src'] + else + server_node['ipaddress'] + end + end + end +end diff --git a/site-cookbooks/kosmos-postgresql/metadata.rb b/site-cookbooks/kosmos-postgresql/metadata.rb index c153631..938ee3f 100644 --- a/site-cookbooks/kosmos-postgresql/metadata.rb +++ b/site-cookbooks/kosmos-postgresql/metadata.rb @@ -21,3 +21,5 @@ chef_version '>= 12.14' if respond_to?(:chef_version) depends "postgresql", ">= 7.0.0" depends "build-essential" +depends "kosmos-base" +depends "kosmos-nginx" diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb index 8e48c3a..be288d6 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/default.rb @@ -24,28 +24,30 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -return if platform?('ubuntu') && node[:platform_version].to_f < 18.04 +postgresql_version = "12" +postgresql_service = "postgresql@#{postgresql_version}-main" -node.override['build-essential']['compile_time'] = true -include_recipe 'build-essential::default' - -package("libpq-dev") { action :nothing }.run_action(:install) - -chef_gem 'pg' do - compile_time true +postgresql_custom_server postgresql_version do + role "primary" + tls true unless node.chef_environment == "development" end -postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') - -postgresql_server_install "main" do - version "10" - setup_repo false - password postgresql_data_bag_item['server_password'] - action :install +service postgresql_service do + supports restart: true, status: true, reload: true + action [:enable] end -postgresql_client_install "main" do - version "10" - setup_repo false - action :install +postgresql_replicas.each do |replica| + postgresql_access "#{replica[:hostname]} replication" do + access_type "host" + access_db "replication" + access_user "replication" + access_addr "#{replica[:ipaddress]}/32" + access_method "md5" + # notification does not work, as postgresql_access always says the + # resource was already up to date + notifies :reload, "service[#{postgresql_service}]", :immediately + end end + +include_recipe "kosmos-postgresql::firewall" diff --git a/site-cookbooks/kosmos-postgresql/recipes/firewall.rb b/site-cookbooks/kosmos-postgresql/recipes/firewall.rb new file mode 100644 index 0000000..e2471cc --- /dev/null +++ b/site-cookbooks/kosmos-postgresql/recipes/firewall.rb @@ -0,0 +1,40 @@ +# +# Cookbook:: kosmos-postgresql +# Recipe:: firewall +# +# The MIT License (MIT) +# +# Copyright:: 2019, 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. + +# FIXME: The firewall recipe do not work in the custom resource, so the code +# lives here for now. The issue is described here, but I think messing with the +# run context is confusing: +# +# https://github.com/chef-cookbooks/firewall/issues/134 +unless node.chef_environment == "development" + include_recipe "firewall" + + firewall_rule "postgresql" do + port 5432 + protocol :tcp + command :allow + end +end diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb new file mode 100644 index 0000000..9cc1740 --- /dev/null +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -0,0 +1,76 @@ +# +# Cookbook:: kosmos-postgresql +# Recipe:: replica +# +# The MIT License (MIT) +# +# Copyright:: 2019, 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. + +postgresql_version = "12" +postgresql_service = "postgresql@#{postgresql_version}-main" + +postgresql_custom_server postgresql_version do + role "replica" + tls true unless node.chef_environment == "development" +end + +service postgresql_service do + supports restart: true, status: true, reload: true + action [:enable] +end + +postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') + +primary = postgresql_primary + +unless primary.nil? + postgresql_data_dir = "/var/lib/postgresql/#{postgresql_version}/main" + + if node['kosmos-postgresql']['ready_to_set_up_replica'] + execute "set up replication" do + 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 +chown -R postgres:postgres #{postgresql_data_dir} +systemctl start #{postgresql_service} + EOF + sensitive true + not_if { ::File.exist? "#{postgresql_data_dir}/standby.signal" } + end + end + + postgresql_access "replication" do + access_type "host" + access_db "replication" + access_user "replication" + access_addr "#{primary[:ipaddress]}/32" + access_method "md5" + # notification does not work, as postgresql_access always says the + # resource was already up to date + notifies :reload, "service[#{postgresql_service}]", :immediately + end + + # On the next Chef run the replica will be set up + node.normal['kosmos-postgresql']['ready_to_set_up_replica'] = true +end + +include_recipe "kosmos-postgresql::firewall" diff --git a/site-cookbooks/kosmos-postgresql/resources/server.rb b/site-cookbooks/kosmos-postgresql/resources/server.rb new file mode 100644 index 0000000..14a7fc2 --- /dev/null +++ b/site-cookbooks/kosmos-postgresql/resources/server.rb @@ -0,0 +1,126 @@ +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 :tls, [TrueClass, FalseClass], default: false + +action :create do + postgresql_version = new_resource.postgresql_version + postgresql_data_dir = data_dir(postgresql_version) + postgresql_service = "postgresql@#{postgresql_version}-main" + + node.override['build-essential']['compile_time'] = true + include_recipe 'build-essential::default' + + package("libpq-dev") { action :nothing }.run_action(:install) + + chef_gem 'pg' do + compile_time true + end + + postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') + + postgresql_server_install "main" do + version postgresql_version + setup_repo true + password postgresql_data_bag_item['server_password'] + action :install + end + + service postgresql_service do + supports restart: true, status: true, reload: true + # action [:enable, :start] + end + + postgresql_client_install "main" do + version postgresql_version + setup_repo true + action :install + end + + postgresql_user "replication" do + action :create + replication true + password postgresql_data_bag_item['replication_password'] + end + + shared_buffers = if node['memory']['total'].to_i / 1024 < 1024 # > 1GB RAM + "128MB" + else # >= 1GB RAM, use 25% of total RAM + "#{node['memory']['total'].to_i / 1024 / 4}MB" + end + + additional_config = { + max_connections: 100, # default + shared_buffers: shared_buffers, + unix_socket_directories: "/var/run/postgresql", + dynamic_shared_memory_type: "posix", + timezone: "UTC", # default is GMT + listen_addresses: "0.0.0.0", + } + + if new_resource.role == "replica" + additional_config[:promote_trigger_file] = "#{postgresql_data_dir}/failover.trigger" + end + + if new_resource.tls + include_recipe "kosmos-nginx" + include_recipe "kosmos-base::letsencrypt" + + domain = node[:fqdn] + + postgresql_post_hook = <<-EOF +#!/usr/bin/env bash + +set -e + +# Copy the postgresql certificate and restart the server if it has been renewed +# This is necessary because the postgresql user doesn't have access to the +# letsencrypt live folder +for domain in $RENEWED_DOMAINS; do + case $domain in + #{domain}) + cp "${RENEWED_LINEAGE}/privkey.pem" #{postgresql_data_dir}/#{domain}.key + cp "${RENEWED_LINEAGE}/fullchain.pem" #{postgresql_data_dir}/#{domain}.crt + chown postgres:postgres #{postgresql_data_dir}/#{domain}.* + chmod 600 #{postgresql_data_dir}/#{domain}.* + systemctl reload #{postgresql_service} + ;; + esac +done + EOF + + # This hook will be executed by certbot after every successful certificate + # creation or renewal + file "/etc/letsencrypt/renewal-hooks/post/postgresql" do + content postgresql_post_hook + mode 0755 + owner "root" + group "root" + end + + template "#{node['nginx']['dir']}/sites-available/#{domain}" do + source 'nginx_conf_empty.erb' + owner node["nginx"]["user"] + mode 0640 + notifies :reload, 'service[nginx]', :delayed + end + + nginx_certbot_site domain + + additional_config[:ssl] = "on" + additional_config[:ssl_cert_file] = "#{postgresql_data_dir}/#{domain}.crt" + additional_config[:ssl_key_file] = "#{postgresql_data_dir}/#{domain}.key" + end + + postgresql_server_conf "main" do + version postgresql_version + additional_config additional_config + notifies :reload, "service[#{postgresql_service}]" + end +end + +action_class do + # to use the data_dir helper + include PostgresqlCookbook::Helpers +end diff --git a/site-cookbooks/kosmos-postgresql/templates/nginx_conf_empty.erb b/site-cookbooks/kosmos-postgresql/templates/nginx_conf_empty.erb new file mode 100644 index 0000000..e69de29 From b22a7e3c0f30f2956eb564277d3073eea5130aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 11 May 2020 18:26:35 +0200 Subject: [PATCH 014/327] Update the postgresql upstream cookbook --- Berksfile | 2 +- Berksfile.lock | 4 +- cookbooks/postgresql/CHANGELOG.md | 34 ++++++++--- cookbooks/postgresql/README.md | 60 +++++++++---------- cookbooks/postgresql/libraries/helpers.rb | 15 +++-- cookbooks/postgresql/metadata.json | 2 +- cookbooks/postgresql/metadata.rb | 3 +- cookbooks/postgresql/resources/access.rb | 12 ++-- cookbooks/postgresql/resources/database.rb | 2 +- cookbooks/postgresql/resources/extension.rb | 2 + cookbooks/postgresql/resources/ident.rb | 4 +- .../postgresql/resources/server_install.rb | 19 +++++- cookbooks/postgresql/resources/user.rb | 4 ++ .../templates/createcluster.conf.erb | 41 +++++++++++++ 14 files changed, 145 insertions(+), 59 deletions(-) create mode 100644 cookbooks/postgresql/templates/createcluster.conf.erb diff --git a/Berksfile b/Berksfile index 2ff3ac2..04f18ed 100644 --- a/Berksfile +++ b/Berksfile @@ -30,7 +30,7 @@ cookbook 'nginx', '= 9.0.0' # part of Chef 14 (https://docs.chef.io/resource_build_essential.html) cookbook 'build-essential', '~> 8.2.1' cookbook 'mysql', '~> 8.5.1' -cookbook 'postgresql', '= 7.1.4' +cookbook 'postgresql', '= 7.1.8' cookbook 'apt', '~> 7.0.0' cookbook 'git', '= 6.0.0' cookbook 'hostsfile', '= 2.4.5' diff --git a/Berksfile.lock b/Berksfile.lock index 0c074ae..271a16b 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -44,7 +44,7 @@ DEPENDENCIES poise-ruby-build (~> 1.1.0) poise-service (~> 1.5.2) postfix (= 5.0.2) - postgresql (= 7.1.4) + postgresql (= 7.1.8) redis git: https://github.com/phlipper/chef-redis.git revision: 7476279fc9c8727f082b8d77b5e1922dc2ef437b @@ -154,7 +154,7 @@ GRAPH poise-service (1.5.2) poise (~> 2.0) postfix (5.0.2) - postgresql (7.1.4) + postgresql (7.1.8) redis (0.5.6) apt (>= 0.0.0) seven_zip (3.1.1) diff --git a/cookbooks/postgresql/CHANGELOG.md b/cookbooks/postgresql/CHANGELOG.md index 95af871..ce810eb 100644 --- a/cookbooks/postgresql/CHANGELOG.md +++ b/cookbooks/postgresql/CHANGELOG.md @@ -2,34 +2,52 @@ This file is used to list changes made in the last 3 major versions of the postgresql cookbook. -## Unreleased +## v7.1.8 (2020-02-22) -## v7.1.4 (28-03-2019) +- Fix incorrect ubuntu platform family value in `postgresql_server_install` +- Re-add unit tests that were skipped + +## v7.1.7 (2020-02-21) + +- Correctly configure postgres-common on Ubuntu hosts (fixes #596) + +## v7.1.6 (2020-02-20) + +- Remove unnecessary nil default in resource properties +- Migrate to GitHub Actions for testing + +## v7.1.5 (2019-11-18) + +- Allow to install extensions with hyphens, ex: `postgresql_extension '"uuid-ossp"'` +- Update Circle CI config to match sous-chefs defaults #617 +- Remove Fedora testing from CI, not an official supported OS by sous-chefs, PR welcome #617 + +## v7.1.4 (2019-03-28) - Fix installation of extensions. -## v7.1.3 (15-01-2019) +## v7.1.3 (2019-01-15) - Added support for dash in database role name. -## v7.1.2 (06-01-2019) +## v7.1.2 (2019-06-01) - Cleanup and update the user resource documentation and code. Removed extraneous 'sensitive' property which is a common property in all Chef resources. - Change default permissions on the postgres.conf to be world readable so that psql can work. -## v7.1.1 (26-09-2018) +## v7.1.1 (2018-09-26) - Rename slave to follower - Use CircleCI for testing - Simplyfy extension resource -## v7.1.0 (22-06-2018) +## v7.1.0 (2018-06-22) - Update the `initdb` script to use initdb rather than a service. #542 - Refactor database commands to use the common connect method. #535 - Increase the unit test coverage. -## v7.0.0 (25-05-2018) +## v7.0.0 (2018-05-25) _Breaking Change_ Please see UPGRADING.md and the README.md for information how to use. @@ -57,7 +75,7 @@ _Breaking Change_ Please see UPGRADING.md and the README.md for information how ## v6.1.2 (2018-04-16) -**this will be the last release of the 6.0 series before all recipes are removed from the cookbook** +this will be the last release of the 6.0 series before all recipes are removed from the cookbook - Deprecate all recipes diff --git a/cookbooks/postgresql/README.md b/cookbooks/postgresql/README.md index d25d75e..d8ebb76 100644 --- a/cookbooks/postgresql/README.md +++ b/cookbooks/postgresql/README.md @@ -2,10 +2,16 @@ [![Cookbook Version](https://img.shields.io/cookbook/v/postgresql.svg)](https://supermarket.chef.io/cookbooks/postgresql) [![Build Status](https://img.shields.io/circleci/project/github/sous-chefs/postgresql/master.svg)](https://circleci.com/gh/sous-chefs/postgresql) -[![pullreminders](https://pullreminders.com/badge.svg)](https://pullreminders.com?ref=badge) +[![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) +[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) +[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) Installs and configures PostgreSQL as a client or a server. +## Maintainers + +This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF). + ## Upgrading If you are wondering where all the recipes went in v7.0+, or how on earth I use this new cookbook please see upgrading.md for a full description. @@ -18,7 +24,6 @@ If you are wondering where all the recipes went in v7.0+, or how on earth I use - Debian 7+ - Ubuntu 14.04+ - Red Hat/CentOS/Scientific 6+ -- Fedora ### PostgreSQL version @@ -51,7 +56,7 @@ Name | Types | Description `hba_file` | String | | `#{conf_dir}/main/pg_hba.conf` | no `ident_file` | String | | `#{conf_dir}/main/pg_ident.conf` | no `external_pid_file` | String | | `/var/run/postgresql/#{version}-main.pid` | no -`password` | String, nil | Pass in a password, or have the cookbook generate one for you | | no +`password` | String, nil | Pass in a password, or have the cookbook generate one for you | random string | no #### Examples @@ -211,14 +216,14 @@ end This generates the following line in the `pg_hba.conf`: -``` +```config # Local postgres superuser access local all postgres ident ``` **Note**: The template by default generates a local access for Unix domain sockets only to support running the SQL execute resources. In Postgres version 9.1 and higher, the method is 'peer' instead of 'ident' which is identical. It looks like this: -``` +```config # "local" is for Unix domain socket connections only local all all peer ``` @@ -257,7 +262,7 @@ end This generates the following line in the `pg_ident.conf`: -``` +```config # MAPNAME SYSTEM-USERNAME PG-USERNAME # John Mapping @@ -279,7 +284,7 @@ end This generates the following line in the `pg_hba.conf`: -``` +```config # Local postgres superuser access host all foo 127.0.0.1/32 ident ``` @@ -400,34 +405,27 @@ postgresql_server_conf 'PostgreSQL Config' do end ``` -## Contributing +## Contributors -Please refer to each project's style guidelines and guidelines for submitting patches and additions. In general, we follow the "fork-and-pull" Git workflow. +This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) -1. **Fork** the repo on GitHub -2. **Clone** the project to your own machine -3. **Commit** changes to your own branch -4. **Push** your work back up to your fork -5. Submit a **Pull request** so that we can review your changes +### Backers -NOTE: Be sure to merge the latest from "upstream" before making a pull request! +Thank you to all our backers! -[Contribution informations for this project](CONTRIBUTING.md) +![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) -## License +### Sponsors -Copyright 2010-2017, Chef Software, Inc. +Support this project by becoming a sponsor. Your logo will show up here with a link to your website. -```text -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -``` +![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) diff --git a/cookbooks/postgresql/libraries/helpers.rb b/cookbooks/postgresql/libraries/helpers.rb index 431d5dd..b8d2a2b 100644 --- a/cookbooks/postgresql/libraries/helpers.rb +++ b/cookbooks/postgresql/libraries/helpers.rb @@ -22,7 +22,7 @@ module PostgresqlCookbook require 'securerandom' def psql_command_string(new_resource, query, grep_for: nil, value_only: false) - cmd = "/usr/bin/psql -c \"#{query}\"" + cmd = %(/usr/bin/psql -c "#{query}") cmd << " -d #{new_resource.database}" if new_resource.database cmd << " -U #{new_resource.user}" if new_resource.user cmd << " --host #{new_resource.host}" if new_resource.host @@ -35,12 +35,12 @@ module PostgresqlCookbook def execute_sql(new_resource, query) # If we don't pass in a user to the resource # default to the postgres user - user = new_resource.user ? new_resource.user : 'postgres' + user = new_resource.user || 'postgres' # Query could be a String or an Array of Strings statement = query.is_a?(String) ? query : query.join("\n") - cmd = shell_out(statement, user: user) + cmd = shell_out(statement, user: user, environment: psql_environment) # Pass back cmd so we can decide what to do with it in the calling method. cmd @@ -81,7 +81,7 @@ module PostgresqlCookbook end def create_extension_sql(new_resource) - sql = "CREATE EXTENSION IF NOT EXISTS #{new_resource.extension}" + sql = %(CREATE EXTENSION IF NOT EXISTS #{new_resource.extension}) sql << " FROM \"#{new_resource.old_version}\"" if new_resource.old_version psql_command_string(new_resource, sql) @@ -213,6 +213,7 @@ module PostgresqlCookbook "/usr/pgsql-#{new_resource.version}/bin/initdb" end cmd << " --locale '#{new_resource.initdb_locale}'" if new_resource.initdb_locale + cmd << " -E '#{new_resource.initdb_encoding}'" if new_resource.initdb_encoding cmd << " -D '#{data_dir(new_resource.version)}'" end @@ -239,6 +240,12 @@ module PostgresqlCookbook platform?('amazon') ? '6' : '$releasever' end + # Fedora doesn't seem to know the right symbols for psql + def psql_environment + return {} unless platform?('fedora') + { LD_LIBRARY_PATH: '/usr/lib64' } + end + # Generate a password if the value is set to generate. def postgres_password(new_resource) new_resource.password == 'generate' ? secure_random : new_resource.password diff --git a/cookbooks/postgresql/metadata.json b/cookbooks/postgresql/metadata.json index 52a549a..74f89dd 100644 --- a/cookbooks/postgresql/metadata.json +++ b/cookbooks/postgresql/metadata.json @@ -1 +1 @@ -{"name":"postgresql","version":"7.1.4","description":"Installs and configures postgresql for clients or servers","long_description":"# PostgreSQL cookbook\n\n[![Cookbook Version](https://img.shields.io/cookbook/v/postgresql.svg)](https://supermarket.chef.io/cookbooks/postgresql)\n[![Build Status](https://img.shields.io/circleci/project/github/sous-chefs/postgresql/master.svg)](https://circleci.com/gh/sous-chefs/postgresql)\n[![pullreminders](https://pullreminders.com/badge.svg)](https://pullreminders.com?ref=badge)\n\nInstalls and configures PostgreSQL as a client or a server.\n\n## Upgrading\n\nIf you are wondering where all the recipes went in v7.0+, or how on earth I use this new cookbook please see upgrading.md for a full description.\n\n## Requirements\n\n### Platforms\n\n- Amazon Linux\n- Debian 7+\n- Ubuntu 14.04+\n- Red Hat/CentOS/Scientific 6+\n- Fedora\n\n### PostgreSQL version\n\nWe follow the currently supported versions listed on \n\n### Chef\n\n- Chef 13.8+\n\n### Cookbook Dependencies\n\nNone.\n\n## Resources\n\n### postgresql_client_install\n\nThis resource installs PostgreSQL client packages.\n\n#### Actions\n\n- `install` - (default) Install client packages\n\n#### Properties\n\nName | Types | Description | Default | Required?\n------------------- | ----------------- | ------------------------------------------------------------- | ----------------------------------------- | ---------\n`version` | String | Version of PostgreSQL to install | '9.6' | no\n`setup_repo` | Boolean | Define if you want to add the PostgreSQL repo | true | no\n`hba_file` | String | | `#{conf_dir}/main/pg_hba.conf` | no\n`ident_file` | String | | `#{conf_dir}/main/pg_ident.conf` | no\n`external_pid_file` | String | | `/var/run/postgresql/#{version}-main.pid` | no\n`password` | String, nil | Pass in a password, or have the cookbook generate one for you | | no\n\n#### Examples\n\nTo install version 9.5:\n\n```ruby\npostgresql_client_install 'My PostgreSQL Client install' do\n version '9.5'\nend\n```\n\n### postgresql_server_install\n\nThis resource installs PostgreSQL client and server packages.\n\n#### Actions\n\n- `install` - (default) Install client and server packages\n- `create` - Initialize the database\n\n#### Properties\n\nName | Types | Description | Default | Required?\n------------------- | --------------- | --------------------------------------------- | -------------------------------------------------- | ---------\n`version` | String | Version of PostgreSQL to install | '9.6' | no\n`setup_repo` | Boolean | Define if you want to add the PostgreSQL repo | true | no\n`hba_file` | String | Path of pg_hba.conf file | `/pg_hba.conf'` | no\n`ident_file` | String | Path of pg_ident.conf file | `/pg_ident.conf` | no\n`external_pid_file` | String | Path of PID file | `/var/run/postgresql/-main.pid` | no\n`password` | String, nil | Set PostgreSQL user password | 'generate' | no\n`port` | Integer | Set listen port of PostgreSQL service | 5432 | no\n`initdb_locale` | String | Locale to initialise the database with | 'C' | no\n\n#### Examples\n\nTo install PostgreSQL server, set your own postgres password using non-default service port.\n\n```ruby\npostgresql_server_install 'My PostgreSQL Server install' do\n action :install\nend\n\npostgresql_server_install 'Setup my PostgreSQL 9.6 server' do\n password 'MyP4ssw0rd'\n port 5433\n action :create\nend\n```\n\n#### Known issues\n\nOn some platforms (e.g. Ubuntu 18.04), your `initdb_locale` should be set to the\nsame as the template database [GH-555](https://github.com/sous-chefs/postgresql/issues/555).\n\n### postgresql_server_conf\n\nThis resource manages postgresql.conf configuration file.\n\n#### Actions\n\n- `modify` - (default) Manager PostgreSQL configuration file (postgresql.conf)\n\n#### Properties\n\nName | Types | Description | Default | Required?\n---------------------- | ------- | --------------------------------------- | --------------------------------------------------- | ---------\n`version` | String | Version of PostgreSQL to install | '9.6' | no\n`data_directory` | String | Path of PostgreSQL data directory | `` | no\n`hba_file` | String | Path of pg_hba.conf file | `/pg_hba.conf` | no\n`ident_file` | String | Path of pg_ident.conf file | `/pg_ident.conf` | no\n`external_pid_file` | String | Path of PID file | `/var/run/postgresql/-main.pid` | no\n`stats_temp_directory` | String | Path of stats file | `/var/run/postgresql/version>-main.pg_stat_tmp` | no\n`port` | Integer | Set listen port of PostgreSQL service | 5432 | no\n`additional_config` | Hash | Extra configuration for the config file | {} | no\n\n#### Examples\n\nTo setup your PostgreSQL configuration with a specific data directory. If you have installed a specific version of PostgreSQL (different from 9.6), you must specify version in this resource too.\n\n```ruby\npostgresql_server_conf 'My PostgreSQL Config' do\n version '9.5'\n data_directory '/data/postgresql/9.5/main'\n notifies :reload, 'service[postgresql]'\nend\n```\n\n### postgresql_extension\n\nThis resource manages PostgreSQL extensions for a given database.\n\n#### Actions\n\n- `create` - (default) Creates an extension in a given database\n- `drop` - Drops an extension from the database\n\n#### Properties\n\nName | Types | Description | Default | Required?\n------------- | ------ | -------------------------------------------------------------------------------- | ---------------- | ---------\n`database` | String | Name of the database to install the extension into | | yes\n`extension` | String | Name of the extension to install the database | Name of resource | yes\n`version` | String | Version of the extension to install | | no\n`old_version` | String | Older module name for new extension replacement. Appends FROM to extension query | | no\n\n#### Examples\n\nTo install the `adminpack` extension:\n\n```ruby\n# Add the contrib package in Ubuntu/Debian\npackage 'postgresql-contrib-9.6'\n\n# Install adminpack extension\npostgresql_extension 'postgres adminpack' do\n database 'postgres'\n extension 'adminpack'\nend\n```\n\n### postgresql_access\n\nThis resource uses the accumulator pattern to build up the `pg_hba.conf` file via chef resources instead of piling on a mountain of chef attributes to make this cookbook more reusable. It directly mirrors the configuration options of the postgres hba file in the resource and by default notifies the server with a reload to avoid a full restart, causing a potential outage of service. To revoke access, simply remove the resource and the access change won't be computed into the final `pg_hba.conf`\n\n#### Actions\n\n- `grant` - (default) Creates an access line inside of `pg_hba.conf`\n\n#### Properties\n\nName | Types | Description | Default | Required?\n--------------- | ------ | ----------------------------------------------------------------------------------------- | ----------------- | ---------\n`name` | String | Name of the access resource, this is left as a comment inside the `pg_hba` config | Resource name | yes\n`source` | String | The cookbook template filename if you want to use your own custom template | 'pg_hba.conf.erb' | yes\n`cookbook` | String | The cookbook to look in for the template source | 'postgresql' | yes\n`comment` | String | A comment to leave above the entry in `pg_hba` | nil | no\n`access_type` | String | The type of access, e.g. local or host | 'local' | yes\n`access_db` | String | The database to access. Can use 'all' for all databases | 'all' | yes\n`access_user` | String | The user accessing the database. Can use 'all' for any user | 'all' | yes\n`access_addr` | String | The address(es) allowed access. Can be nil if method ident is used since it is local then | nil | no\n`access_method` | String | Authentication method to use | 'ident' | yes\n\n#### Examples\n\nTo grant access to the PostgreSQL user with ident authentication:\n\n```ruby\npostgresql_access 'local_postgres_superuser' do\n comment 'Local postgres superuser access'\n access_type 'local'\n access_db 'all'\n access_user 'postgres'\n access_addr nil\n access_method 'ident'\nend\n```\n\nThis generates the following line in the `pg_hba.conf`:\n\n```\n# Local postgres superuser access\nlocal all postgres ident\n```\n\n**Note**: The template by default generates a local access for Unix domain sockets only to support running the SQL execute resources. In Postgres version 9.1 and higher, the method is 'peer' instead of 'ident' which is identical. It looks like this:\n\n```\n# \"local\" is for Unix domain socket connections only\nlocal all all peer\n```\n\n### postgresql_ident\n\nThis resource generate `pg_ident.conf` configuration file to manage user mapping between system and PostgreSQL users.\n\n#### Actions\n\n- `create` - (default) Creates an mapping line inside of `pg_ident.conf`\n\n#### Properties\n\nName | Types | Description | Default | Required?\n-------------- | ----------- | -------------------------------------------------------------------------- | ------------------- | ---------\n`mapname` | String | Name of the user mapping | Resource name | yes\n`source` | String | The cookbook template filename if you want to use your own custom template | 'pg_ident.conf.erb' | no\n`cookbook` | String | The cookbook to look in for the template source | 'postgresql' | no\n`comment` | String, nil | A comment to leave above the entry in `pg_ident` | nil | no\n`system_user` | String | System user or regexp used for the mapping | None | yes\n`pg_user` | String | Pg user or regexp used for the mapping | None | yes\n\n#### Examples\n\nCreates a `mymapping` mapping that map `john` system user to `user1` PostgreSQL user:\n\n```ruby\npostgresql_ident 'Map john to user1' do\n comment 'John Mapping'\n mapname 'mymapping'\n system_user 'john'\n pg_user 'user1'\nend\n```\n\nThis generates the following line in the `pg_ident.conf`:\n\n```\n# MAPNAME SYSTEM-USERNAME PG-USERNAME\n\n# John Mapping\nmymapping john user1\n```\n\nTo grant access to the foo user with password authentication:\n\n```ruby\npostgresql_access 'local_foo_user' do\n comment 'Foo user access'\n access_type 'host'\n access_db 'all'\n access_user 'foo'\n access_addr '127.0.0.1/32'\n access_method 'md5'\nend\n```\n\nThis generates the following line in the `pg_hba.conf`:\n\n```\n# Local postgres superuser access\nhost all foo 127.0.0.1/32 ident\n```\n\n### postgresql_database\n\nThis resource manages PostgreSQL databases.\n\n#### Actions\n\n- `create` - (default) Creates the given database.\n- `drop` - Drops the given database.\n\n#### Properties\n\nName | Types | Description | Default | Required?\n---------- | ------- | ------------------------------------------------------------------- | ------------------- | ---------\n`database` | String | Name of the database to create | Resource name | yes\n`user` | String | User which run psql command | 'postgres' | no\n`template` | String | Template used to create the new database | 'template1' | no\n`host` | String | Define the host server where the database creation will be executed | Not set (localhost) | no\n`port` | Integer | Define the port of PostgreSQL server | 5432 | no\n`encoding` | String | Define database encoding | 'UTF-8' | no\n`locale` | String | Define database locale | 'en_US.UTF-8' | no\n`owner` | String | Define the owner of the database | Not set | no\n\n#### Examples\n\nTo create database named 'my_app' with owner 'user1':\n\n```ruby\npostgresql_database 'my_app' do\n owner 'user1'\nend\n```\n\n#### Known issues\n\nOn some platforms (e.g. Ubuntu 18.04), your `initdb_locale` should be set to the\nsame as the template database [GH-555](https://github.com/sous-chefs/postgresql/issues/555).\n\n### postgresql_user\n\nThis resource manage PostgreSQL users.\n\n#### Actions\n\n- `create` - (default) Creates the given user with default or given privileges.\n- `update` - Update user privilieges.\n- `drop` - Deletes the given user.\n\n#### Properties\n\nName | Types | Description | Default | Required?\n-------------------- | ------- | ----------------------------------------------- | -------- | ---------\n`create_user` | String | User to create (defaults to the resource name) | | Yes\n`superuser` | Boolean | Define if user needs superuser role | false | no\n`createdb` | Boolean | Define if user needs createdb role | false | no\n`createrole` | Boolean | Define if user needs createrole role | false | no\n`inherit` | Boolean | Define if user inherits the privileges of roles | true | no\n`replication` | Boolean | Define if user needs replication role | false | no\n`login` | Boolean | Define if user can login | true | no\n`password` | String | Set user's password | | no\n`encrypted_password` | String | Set user's password with an hashed password | | no\n`valid_until` | String | Define an account expiration date | | no\n`attributes` | Hash | Additional attributes for :update action | {} | no\n`user` | String | User for command | postgres | no\n`database` | String | Database for command | | no\n`host` | String | Hostname for command | | no\n`port` | Integer | Port number to connect to postgres | 5432 | no\n\n#### Examples\n\nCreate a user `user1` with a password, with `createdb` role and set an expiration date to 2018, Dec 21.\n\n```ruby\npostgresql_user 'user1' do\n password 'UserP4ssword'\n createdb true\n valid_until '2018-12-31'\nend\n```\n\nCreate a user `user1` with a password, with `createdb` role and set an expiration date to 2018, Dec 21.\n\n```ruby\npostgresql_user 'user1' do\n password 'UserP4ssword'\n createdb true\n valid_until '2018-12-31'\nend\n```\n\n## Usage\n\nTo install and configure your PostgreSQL instance you need to create your own cookbook and call needed resources with your own parameters.\n\nMore examples can be found in `test/cookbooks/test/recipes`\n\n## Example Usage\n\n```ruby\n# cookbooks/my_postgresql/recipes/default.rb\n\npostgresql_client_install 'PostgreSQL Client' do\n setup_repo false\n version '10.6'\nend\n\npostgresql_server_install 'PostgreSQL Server' do\n version '10.6'\n setup_repo false\n password 'P0stgresP4ssword'\nend\n\npostgresql_server_conf 'PostgreSQL Config' do\n notifies :reload, 'service[postgresql]'\nend\n```\n\n## Contributing\n\nPlease refer to each project's style guidelines and guidelines for submitting patches and additions. In general, we follow the \"fork-and-pull\" Git workflow.\n\n1. **Fork** the repo on GitHub\n2. **Clone** the project to your own machine\n3. **Commit** changes to your own branch\n4. **Push** your work back up to your fork\n5. Submit a **Pull request** so that we can review your changes\n\nNOTE: Be sure to merge the latest from \"upstream\" before making a pull request!\n\n[Contribution informations for this project](CONTRIBUTING.md)\n\n## License\n\nCopyright 2010-2017, Chef Software, Inc.\n\n```text\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Sous Chefs","maintainer_email":"help@sous-chefs.org","license":"Apache-2.0","platforms":{"ubuntu":">= 0.0.0","debian":">= 0.0.0","fedora":">= 0.0.0","amazon":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","scientific":">= 0.0.0","oracle":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/sous-chefs/postgresql","issues_url":"https://github.com/sous-chefs/postgresql/issues","chef_version":[[">= 13.8"]],"ohai_version":[]} \ No newline at end of file +{"name":"postgresql","version":"7.1.8","description":"Installs and configures postgresql for clients or servers","long_description":"","maintainer":"Sous Chefs","maintainer_email":"help@sous-chefs.org","license":"Apache-2.0","platforms":{"ubuntu":">= 0.0.0","debian":">= 0.0.0","fedora":">= 0.0.0","amazon":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","scientific":">= 0.0.0","oracle":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/sous-chefs/postgresql","issues_url":"https://github.com/sous-chefs/postgresql/issues","chef_version":[[">= 13.8"]],"ohai_version":[]} \ No newline at end of file diff --git a/cookbooks/postgresql/metadata.rb b/cookbooks/postgresql/metadata.rb index 9fb54ac..b4b193b 100644 --- a/cookbooks/postgresql/metadata.rb +++ b/cookbooks/postgresql/metadata.rb @@ -4,8 +4,7 @@ maintainer 'Sous Chefs' maintainer_email 'help@sous-chefs.org' license 'Apache-2.0' description 'Installs and configures postgresql for clients or servers' -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '7.1.4' +version '7.1.8' source_url 'https://github.com/sous-chefs/postgresql' issues_url 'https://github.com/sous-chefs/postgresql/issues' chef_version '>= 13.8' diff --git a/cookbooks/postgresql/resources/access.rb b/cookbooks/postgresql/resources/access.rb index 56d69cc..8c5ba63 100644 --- a/cookbooks/postgresql/resources/access.rb +++ b/cookbooks/postgresql/resources/access.rb @@ -16,12 +16,12 @@ # limitations under the License. # -property :access_type, String, required: true, default: 'local' -property :access_db, String, required: true, default: 'all' -property :access_user, String, required: true, default: 'postgres' -property :access_method, String, required: true, default: 'ident' -property :cookbook, String, default: 'postgresql' -property :source, String, default: 'pg_hba.conf.erb' +property :access_type, String, default: 'local' +property :access_db, String, default: 'all' +property :access_user, String, default: 'postgres' +property :access_method, String, default: 'ident' +property :cookbook, String, default: 'postgresql' +property :source, String, default: 'pg_hba.conf.erb' property :access_addr, String property :comment, String diff --git a/cookbooks/postgresql/resources/database.rb b/cookbooks/postgresql/resources/database.rb index be2a813..f4f0377 100644 --- a/cookbooks/postgresql/resources/database.rb +++ b/cookbooks/postgresql/resources/database.rb @@ -23,7 +23,7 @@ property :owner, String # Connection prefernces property :user, String, default: 'postgres' property :database, String, name_property: true -property :host, [String, nil], default: nil +property :host, String property :port, Integer, default: 5432 action :create do diff --git a/cookbooks/postgresql/resources/extension.rb b/cookbooks/postgresql/resources/extension.rb index fb104dd..f8987b6 100644 --- a/cookbooks/postgresql/resources/extension.rb +++ b/cookbooks/postgresql/resources/extension.rb @@ -30,6 +30,7 @@ action :create do code create_extension_sql(new_resource) user 'postgres' action :run + environment(psql_environment) not_if { follower? || extension_installed?(new_resource) } end end @@ -39,6 +40,7 @@ action :drop do code psql_command_string(new_resource, "DROP EXTENSION IF EXISTS \"#{new_resource.extension}\"") user 'postgres' action :run + environment(psql_environment) not_if { follower? } only_if { extension_installed?(new_resource) } end diff --git a/cookbooks/postgresql/resources/ident.rb b/cookbooks/postgresql/resources/ident.rb index ba677f0..52fdec3 100644 --- a/cookbooks/postgresql/resources/ident.rb +++ b/cookbooks/postgresql/resources/ident.rb @@ -21,11 +21,11 @@ property :source, String, default: 'pg_ident.conf.erb' property :cookbook, String, default: 'postgresql' property :system_user, String, required: true property :pg_user, String, required: true -property :comment, [String, nil], default: nil +property :comment, String action :create do ident_resource = new_resource - with_run_context :root do # ~FC037 + with_run_context :root do edit_resource(:template, "#{conf_dir}/pg_ident.conf") do |new_resource| source new_resource.source cookbook new_resource.cookbook diff --git a/cookbooks/postgresql/resources/server_install.rb b/cookbooks/postgresql/resources/server_install.rb index 3c66c67..290713b 100644 --- a/cookbooks/postgresql/resources/server_install.rb +++ b/cookbooks/postgresql/resources/server_install.rb @@ -1,4 +1,3 @@ -# frozen_string_literal: true # # Cookbook:: postgresql # Resource:: server_install @@ -26,6 +25,7 @@ property :external_pid_file, String, default: lazy { "/var/run/postgresql/#{vers property :password, [String, nil], default: 'generate' # Set to nil if we do not want to set a password property :port, Integer, default: 5432 property :initdb_locale, String +property :initdb_encoding, String # Connection preferences property :user, String, default: 'postgres' @@ -41,6 +41,23 @@ action :install do setup_repo new_resource.setup_repo end + # First install the postgresql-common package + if platform_family?('debian') + package 'postgresql-common' + + initdb_options = '' + initdb_options << "--locale #{new_resource.initdb_locale}" if new_resource.initdb_locale + initdb_options << " -E #{new_resource.initdb_encoding}" if new_resource.initdb_encoding + + template '/etc/postgresql-common/createcluster.conf' do + source 'createcluster.conf.erb' + cookbook 'postgresql' + variables( + initdb_options: initdb_options + ) + end + end + package server_pkg_name end diff --git a/cookbooks/postgresql/resources/user.rb b/cookbooks/postgresql/resources/user.rb index 05da73b..17b8b18 100644 --- a/cookbooks/postgresql/resources/user.rb +++ b/cookbooks/postgresql/resources/user.rb @@ -40,6 +40,7 @@ action :create do user 'postgres' command create_user_sql(new_resource) sensitive new_resource.sensitive + environment(psql_environment) not_if { follower? || user_exists?(new_resource) } end end @@ -49,6 +50,7 @@ action :update do execute "update postgresql user #{new_resource.create_user}" do user 'postgres' command update_user_sql(new_resource) + environment(psql_environment) sensitive true not_if { follower? } only_if { user_exists?(new_resource) } @@ -64,6 +66,7 @@ action :update do execute "Update postgresql user #{new_resource.create_user} to set #{attr}" do user 'postgres' command update_user_with_attributes_sql(new_resource, v) + environment(psql_environment) sensitive true not_if { follower? } only_if { user_exists?(new_resource) } @@ -76,6 +79,7 @@ action :drop do execute "drop postgresql user #{new_resource.create_user}" do user 'postgres' command drop_user_sql(new_resource) + environment(psql_environment) sensitive true not_if { follower? } only_if { user_exists?(new_resource) } diff --git a/cookbooks/postgresql/templates/createcluster.conf.erb b/cookbooks/postgresql/templates/createcluster.conf.erb new file mode 100644 index 0000000..b85e2b5 --- /dev/null +++ b/cookbooks/postgresql/templates/createcluster.conf.erb @@ -0,0 +1,41 @@ +# Default values for pg_createcluster(8) +# Occurrences of '%v' are replaced by the major version number, +# and '%c' by the cluster name. Use '%%' for a literal '%'. + +# Create a "main" cluster when a new postgresql-x.y server package is installed +#create_main_cluster = true + +# Default start.conf value, must be one of "auto", "manual", and "disabled". +# See pg_createcluster(8) for more documentation. +#start_conf = 'auto' + +# Default data directory. +#data_directory = '/var/lib/postgresql/%v/%c' + +# Default directory for transaction logs +# Unset by default, i.e. transaction logs remain in the data directory. +#waldir = '/var/lib/postgresql/wal/%v/%c/pg_wal' + +# Options to pass to initdb. +initdb_options = '<%= @initdb_options %>' + +# The following options are copied into the new cluster's postgresql.conf: + +# Enable SSL by default (using the "snakeoil" certificates installed by the +# ssl-cert package, unless configured otherwise here) +ssl = on + +# Show cluster name in process title +cluster_name = '%v/%c' + +# Put stats_temp_directory on tmpfs +stats_temp_directory = '/var/run/postgresql/%v-%c.pg_stat_tmp' + +# Add prefix to log lines +log_line_prefix = '%%m [%%p] %%q%%u@%%d ' + +# Add "include_dir" in postgresql.conf +add_include_dir = 'conf.d' + +# Directory for additional createcluster config +include_dir '/etc/postgresql-common/createcluster.d' From 80c7263a72d6fd88eb5931e9ee56a05cae0e9da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 11 May 2020 18:26:57 +0200 Subject: [PATCH 015/327] Upgrade PostgreSQL from 10 to 12 Refs #160 --- site-cookbooks/kosmos-postgresql/recipes/default.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb index be288d6..2b8e09b 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/default.rb @@ -37,6 +37,19 @@ service postgresql_service do action [:enable] end +# This will only be run once, if the /var/lib/postgresql/10/main directory +# exists. The old data directory is then moved. +execute "upgrade postgresql to 12" do + command <<-EOF +systemctl stop postgresql@12-main +systemctl stop postgresql@10-main +su - postgres -c "/usr/lib/postgresql/12/bin/pg_upgrade --old-bindir=/usr/lib/postgresql/10/bin/ --new-bindir=/usr/lib/postgresql/12/bin/ --old-datadir=/etc/postgresql/10/main/ --new-datadir=/etc/postgresql/12/main/" +mv /var/lib/postgresql/10/main /var/lib/postgresql/10/main.old +systemctl start postgresql@12-main + EOF + only_if { ::File.exist? "/var/lib/postgresql/10/main" } +end + postgresql_replicas.each do |replica| postgresql_access "#{replica[:hostname]} replication" do access_type "host" From 254f9020ae12b4c9ebd4ec3118174c17fd7b6f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 12 May 2020 12:10:10 +0200 Subject: [PATCH 016/327] Enable firewall rules to allow primary/replica to connect --- .../kosmos-postgresql/recipes/default.rb | 14 ++++++- .../kosmos-postgresql/recipes/firewall.rb | 40 ------------------- .../kosmos-postgresql/recipes/replica.rb | 14 ++++++- 3 files changed, 26 insertions(+), 42 deletions(-) delete mode 100644 site-cookbooks/kosmos-postgresql/recipes/firewall.rb diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb index 2b8e09b..eb63826 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/default.rb @@ -61,6 +61,18 @@ postgresql_replicas.each do |replica| # resource was already up to date notifies :reload, "service[#{postgresql_service}]", :immediately end + + unless node.chef_environment == "development" + include_recipe "firewall" + + firewall_rule "postgresql" do + port 5432 + protocol :tcp + command :allow + destination replica[:ipaddress] + end + end end -include_recipe "kosmos-postgresql::firewall" +# TODO: We need to set up firewall rules and access rules for clients too +# (Mastodon, ejabberd, etc) diff --git a/site-cookbooks/kosmos-postgresql/recipes/firewall.rb b/site-cookbooks/kosmos-postgresql/recipes/firewall.rb deleted file mode 100644 index e2471cc..0000000 --- a/site-cookbooks/kosmos-postgresql/recipes/firewall.rb +++ /dev/null @@ -1,40 +0,0 @@ -# -# Cookbook:: kosmos-postgresql -# Recipe:: firewall -# -# The MIT License (MIT) -# -# Copyright:: 2019, 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. - -# FIXME: The firewall recipe do not work in the custom resource, so the code -# lives here for now. The issue is described here, but I think messing with the -# run context is confusing: -# -# https://github.com/chef-cookbooks/firewall/issues/134 -unless node.chef_environment == "development" - include_recipe "firewall" - - firewall_rule "postgresql" do - port 5432 - protocol :tcp - command :allow - end -end diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index 9cc1740..82eb4bf 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -71,6 +71,18 @@ systemctl start #{postgresql_service} # On the next Chef run the replica will be set up node.normal['kosmos-postgresql']['ready_to_set_up_replica'] = true + + unless node.chef_environment == "development" + include_recipe "firewall" + + firewall_rule "postgresql" do + port 5432 + protocol :tcp + command :allow + destination primary[:ipaddress] + end + end end -include_recipe "kosmos-postgresql::firewall" +# TODO: We need to set up firewall rules and access rules for clients too +# (Mastodon, ejabberd, etc) From 0180da1aa6061f11f9a103d345e7ff5d2ebac4ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 12 May 2020 15:59:55 +0200 Subject: [PATCH 017/327] Fix a typo in the README --- site-cookbooks/kosmos-postgresql/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-postgresql/README.md b/site-cookbooks/kosmos-postgresql/README.md index f00dccb..76a2418 100644 --- a/site-cookbooks/kosmos-postgresql/README.md +++ b/site-cookbooks/kosmos-postgresql/README.md @@ -24,7 +24,7 @@ end ```ruby postgresql_custom_server "12" do - role "primary" + role "replica" tls true end ``` From eb98aa1bacdd9c9e46526139be482c386a838268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 12 May 2020 16:04:58 +0200 Subject: [PATCH 018/327] Clarify the firewall and client authentication rules --- site-cookbooks/kosmos-postgresql/README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/site-cookbooks/kosmos-postgresql/README.md b/site-cookbooks/kosmos-postgresql/README.md index 76a2418..9d8bda5 100644 --- a/site-cookbooks/kosmos-postgresql/README.md +++ b/site-cookbooks/kosmos-postgresql/README.md @@ -36,6 +36,14 @@ to set up replication. #### Caveat [`firewall_rules`](https://github.com/chef-cookbooks/firewall/issues/134) and -[`postgresql_access`](https://github.com/sous-chefs/postgresql/issues/648) need -to be declared in recipes, not resources because of the way custom resources -work currently in Chef +[`postgresql_access`](https://github.com/sous-chefs/postgresql/issues/648) are +declared in recipes, not resources because of the way custom resources +work currently in Chef. See the `default.rb` and `replica.rb` recipes. + +The primary gives access to the `replication` db to the `replication` user +connecting from a replica, and replicas to the primary. For more information +about PostgreSQL client authentication, see the +[official docs](https://www.postgresql.org/docs/12/auth-pg-hba-conf.html) + +The primary opens up the PostgreSQL port (5432 TCP) to replicas, and replicas +to the primary. From 51b23c2f47fc06b0d1339ee3c78ac17b59e742b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 13 May 2020 15:35:15 +0200 Subject: [PATCH 019/327] Add postgresql roles --- roles/postgresql_primary.rb | 5 +++++ roles/postgresql_replica.rb | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 roles/postgresql_primary.rb create mode 100644 roles/postgresql_replica.rb diff --git a/roles/postgresql_primary.rb b/roles/postgresql_primary.rb new file mode 100644 index 0000000..0cb0ccd --- /dev/null +++ b/roles/postgresql_primary.rb @@ -0,0 +1,5 @@ +name "postgresql_primary" + +run_list %w( + kosmos-postgresql::default +) diff --git a/roles/postgresql_replica.rb b/roles/postgresql_replica.rb new file mode 100644 index 0000000..8ee5100 --- /dev/null +++ b/roles/postgresql_replica.rb @@ -0,0 +1,5 @@ +name "postgresql_replica" + +run_list %w( + kosmos-postgresql::replica +) From f3f8e47cceb9fd5a0f60db6cdc416630e7f9ab41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 13 May 2020 15:35:34 +0200 Subject: [PATCH 020/327] Add replication_password to the postgresql credentials --- data_bags/credentials/postgresql.json | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/data_bags/credentials/postgresql.json b/data_bags/credentials/postgresql.json index 886b65a..e1af8ab 100644 --- a/data_bags/credentials/postgresql.json +++ b/data_bags/credentials/postgresql.json @@ -1,23 +1,30 @@ { "id": "postgresql", "ejabberd_user_password": { - "encrypted_data": "s31aNIv9ZTlU8cVXMDUB79Iv+EozZS1NSZVU5ey9xpBf2WYohpSqni/5Wg==\n", - "iv": "a3LWKNYmUZfSMc1Y\n", - "auth_tag": "3P+WFcDw/R1d983g7YoFUw==\n", + "encrypted_data": "egFuX4xov+JZUq/GUbCBEQUnxDKczzxdJiYeRDisNEIVPYLNO/piG701sw==\n", + "iv": "G0JpgKtcPnTQ5d6v\n", + "auth_tag": "NoNoLmZZT+2qgIuDBEdGKQ==\n", "version": 3, "cipher": "aes-256-gcm" }, "server_password": { - "encrypted_data": "w7zghEF+DjUhS59cze+qviqDcy8mQpIgW6olHabas1IH4t0z+IQ7\n", - "iv": "ppqOzJGczWtwGRnX\n", - "auth_tag": "2Lhqw7Rhm35HcltsDtaJIw==\n", + "encrypted_data": "vJ3cK8vzUKI97YJVLE11I9Ti/Z3Rits+UQjIDZMZDx4cvTiGN0QX\n", + "iv": "ENFE12MnoSta++6j\n", + "auth_tag": "JbeVb+zdrkHvj9g9end/2Q==\n", "version": 3, "cipher": "aes-256-gcm" }, "mastodon_user_password": { - "encrypted_data": "84UPPmtNh/5MH6u4svMPhRHBGK1GFnP4G2tk/a+wQLNxSB8FlDsTuqSC2A==\n", - "iv": "UBl2ILWCc2WKcN6d\n", - "auth_tag": "NF/xcK0tmvbBo1dDFhOf7w==\n", + "encrypted_data": "PTCEBIB+qYe+lBoFjgLxendhx2ccJJ4UbUEwnPf8MT39fsF9MFQwFiytvg==\n", + "iv": "j59Ndhijtj/YQNp5\n", + "auth_tag": "bbdA+OmJvTfjwNHzrF19tg==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "replication_password": { + "encrypted_data": "OFLn4FHP8BbCgBJzlqG+Zo3wjzXtklyKgk3OBKdkcUzzgno=\n", + "iv": "xHiYpKX90SF7Blqi\n", + "auth_tag": "VO/xnf+N+zX6F3DQ8EdSBQ==\n", "version": 3, "cipher": "aes-256-gcm" } From 84cb3de4a035ce88d5fba009fb80834d795c4585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 13 May 2020 19:04:12 +0200 Subject: [PATCH 021/327] Remove outdated comment This was the case when the code lived inside of the custom resource --- site-cookbooks/kosmos-postgresql/recipes/default.rb | 2 -- site-cookbooks/kosmos-postgresql/recipes/replica.rb | 2 -- 2 files changed, 4 deletions(-) diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb index eb63826..af092b5 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/default.rb @@ -57,8 +57,6 @@ postgresql_replicas.each do |replica| access_user "replication" access_addr "#{replica[:ipaddress]}/32" access_method "md5" - # notification does not work, as postgresql_access always says the - # resource was already up to date notifies :reload, "service[#{postgresql_service}]", :immediately end diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index 82eb4bf..1d12d51 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -64,8 +64,6 @@ systemctl start #{postgresql_service} access_user "replication" access_addr "#{primary[:ipaddress]}/32" access_method "md5" - # notification does not work, as postgresql_access always says the - # resource was already up to date notifies :reload, "service[#{postgresql_service}]", :immediately end From 8d2ab785fc1b55a3a6c90bfb501006311a05bf5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 13 May 2020 19:10:14 +0200 Subject: [PATCH 022/327] Use a self-signed TLS certificate for PostgreSQL --- data_bags/credentials/postgresql.json | 45 ++++++++---- site-cookbooks/kosmos-postgresql/README.md | 47 +++++++++++- .../kosmos-postgresql/resources/server.rb | 72 +++++++------------ .../templates/nginx_conf_empty.erb | 0 4 files changed, 101 insertions(+), 63 deletions(-) delete mode 100644 site-cookbooks/kosmos-postgresql/templates/nginx_conf_empty.erb diff --git a/data_bags/credentials/postgresql.json b/data_bags/credentials/postgresql.json index e1af8ab..8c2fecc 100644 --- a/data_bags/credentials/postgresql.json +++ b/data_bags/credentials/postgresql.json @@ -1,30 +1,51 @@ { "id": "postgresql", "ejabberd_user_password": { - "encrypted_data": "egFuX4xov+JZUq/GUbCBEQUnxDKczzxdJiYeRDisNEIVPYLNO/piG701sw==\n", - "iv": "G0JpgKtcPnTQ5d6v\n", - "auth_tag": "NoNoLmZZT+2qgIuDBEdGKQ==\n", + "encrypted_data": "hz0xHS2wl66X6xxqLE5/6apQb8SvIR7r8hCd9ZzEcHf7VaWoFMNLmrmwqw==\n", + "iv": "PfEp9Jhqfp0o7Cje\n", + "auth_tag": "ckEADxPfymTvSVLLXUxTWA==\n", "version": 3, "cipher": "aes-256-gcm" }, "server_password": { - "encrypted_data": "vJ3cK8vzUKI97YJVLE11I9Ti/Z3Rits+UQjIDZMZDx4cvTiGN0QX\n", - "iv": "ENFE12MnoSta++6j\n", - "auth_tag": "JbeVb+zdrkHvj9g9end/2Q==\n", + "encrypted_data": "9aV4IykJB3lISayq/crmowTjrQjwSWSrh7+O9LMq0IgZaWZ6Bk6R\n", + "iv": "XFeNPuZAh4nCX9NU\n", + "auth_tag": "LoAIWrqSAmcuA+r3nyHu2Q==\n", "version": 3, "cipher": "aes-256-gcm" }, "mastodon_user_password": { - "encrypted_data": "PTCEBIB+qYe+lBoFjgLxendhx2ccJJ4UbUEwnPf8MT39fsF9MFQwFiytvg==\n", - "iv": "j59Ndhijtj/YQNp5\n", - "auth_tag": "bbdA+OmJvTfjwNHzrF19tg==\n", + "encrypted_data": "LGU8N2C9Ax17QvFCWNV9m1rbRpBT9YH1qVn/Cmz0/p+1aUcOUN8rzxb57Q==\n", + "iv": "FiYQKLmfJ/CYO50H\n", + "auth_tag": "t3NwAMqoGCJ/c/5H2KjQ+Q==\n", "version": 3, "cipher": "aes-256-gcm" }, "replication_password": { - "encrypted_data": "OFLn4FHP8BbCgBJzlqG+Zo3wjzXtklyKgk3OBKdkcUzzgno=\n", - "iv": "xHiYpKX90SF7Blqi\n", - "auth_tag": "VO/xnf+N+zX6F3DQ8EdSBQ==\n", + "encrypted_data": "6UildEd3UactuYufRp+UjHFlK3zLZ8Vmggfc8URBRNVfWHs=\n", + "iv": "e4SpyAt32vXuX4un\n", + "auth_tag": "AkCEvuEnb+E5jTC84tC8NA==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "ssl_cert": { + "encrypted_data": "loF7NMyOJXr8PfxsuN6zvp86hIqWYoGFiGq+ldirctWnmkeDmaROgzDW1oQp\nAubnEHZNx7IFRn/FGpGhhbX/DGjbL6EK0bSE6x6uzOEhpaFDAqmzzEfMXCMj\nDIsrM5WSmP1WBFd6g+/zk3EAXHeekOlLBEj13zzSJVj4piLFERKZRTgix0eP\nOmH+lGBoxy4hXKfa9ru7c5h4vLVQHSlHjrrsyeKdumbmXWSb3IJWtEsNQRqu\nKu6DZ+IRC8fH+DBs8/32dTbJ6uR29kbKfZrWTrpOKXWJLnT1snuiTMeRbTcO\nVbS1ZSeGcpGMFFayAui4KgPaDK8vT/mXcd2P3+c85GZtmmvIKfloIRmtb4in\nleUx3z70BxPFRg5wYfSiP/xJMpjJrh5/6P+96iMkgmU+wuXT+95yf4Agz7G5\n0gObs/sJCAV9qOoWIXSU3jyNvaYsZMPj8FHXlpnCXojHJ2WnqLCAPeVWYHbd\nvNSEOvmCN07xK1PkGZT9NGfPzRcZxqop5gJ3qP9Km33Z06SNF+28i2d4lpy+\n1oWqg5ow2CBhRrb0Bx8FplQug4EXCV7Sni4mc0jSX90rBv+e65Em+33x0A27\nPrp7lfcv+7ridU5AZXifFZSuIJF6LMXz+ji2zC2JMjS4xQ8/KXBd8E5/fRJH\nI18X+t/xx8gakmaDrz/3+4i8TVt1I8pIpN/SaAXTZqgme1QoISymf6LQzFxW\ns1kQGOwbtgx60+2BG7kF9XRRZJay8P1uxmVgjHWbqyL0KbYTlU2zTLuRs3ez\n+rPEsxB/hNfUeB9guALFLtvlkAob1Fh/Za6aukaFlaVJHbHoXehH/aXBPAVK\n0ld+3fql5Ib/OAD7prWaUCZ/tP357RWwCxz+ECjtJhFdREx8fT1aZGvmJ0yx\nESNhSjrn+b+rVc+HiD4hAytW+QP2yNqfKO9YzxXYfN5BBTxh/fvO2qVtQmSf\n+u9iatEaico44E7MX1ZOYAclTA289dwyu6R9PRa1p0zral5b+vJAOx1iH1uq\nzHUKTiRCRAcWrcciL8PH8MRXdcHSxmfyBSBbcz+dh/MURyQMx/LOQ31gYuYq\nzlgbJNsVl6V9rl9x2SargwJrD1WM863oyQumZc/M42GX0z9PilIhLQbF26MN\n2tUf5IDK7d42Z5A6ATxR+0qKh2/WvDXDbNHy+cuAjRJRX9vTgNqpR5qCOyT5\nIxA55rLvHYxbnqic124I1EdXGtoEXqsxt1YAq3ho9QCQz1t5Z/AP63oUEuLr\np4WIeo44fqZzjprRFEE3KbCGlUDx56xLg4a84JF1rMU0ce11BUtEEtRF2p4X\noecU8Z5vvhvsqXxYko6aFNcAvxO2FdZmC76lilNsHgH9VS02ctjOT7Mvi2XP\n3QEVOg==\n", + "iv": "v+wkuXO+2VZHRkOu\n", + "auth_tag": "C56+Qe/UNzR8k9HizIFyMA==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "ssl_key": { + "encrypted_data": "envd5qBpUVHD5+pFmtRm99y3n+Fi6PtEwjgQl1l1VTn/bRMosMGSbWJ9VmPk\nd1tu/Nr1Z1SZcNyBiUxhAaKI2vU6BsNIpy0lnZN3R0bT4OMH/lPIJyIRqAXU\nPu+73++H41SC47Nt+9UhwRkNifIl3lFo0AhqqeHpJQbhCPVVW6oJf2Q7TGDF\nGhU5y3sat5r7FNSRCNvErv8QX/cIOSTHn76350ktgVG29+31Qp9HDhg01jac\ne8XrAiZXPxzNO7tA6zFlsRr6WVaLJeMd4bTXQpfgy/wcl+UG91n02ODdveqj\n2P+Z+ZnKvgAgmTrWpwHalJ6KkWBjuYPdaawnRPbMVUCm7usPFOurpuvYwX61\ncysFOylwCaw3vCEBWFlQAaV5GJAiaMujI8OFkioQS0FZ8M7slLs9famJzz6c\nR24BJHHb7eJRHsGZptHnEx6JGA4WGQD1e5Z8JtKnUff0WVtiSe9lwEwWNPPx\ntMJX0H8+bXdLC5W+R7pbHQfSWmbk9CP9ehlReJw9Kj1neQfm4W1Vevi42Jz2\n9JkBZ+P0ympsYb+qk0juNUrP5mC8rfW+/RktRihp4sufOW4KcK2nwWka4HeQ\nql2Xh6gHyniB2pe60lFmt2XR/0k47/tz+i6Xim67apfr8vapDzA4vBnJRVNv\nz8OVgBjJ124K5j+V4jJkWem7YfgLVpmzbkOsQp6YAsNitYUeiRwF8ijckkYF\nqEOXq4HTvyCKiPsy+myd6fjyJGCTFz4lFwQa54PFb45BsjApN78SEzWj0fxL\nT/LZF3HxA4vR72zajAFs/Vf6W7Ho5mKG/h21vjw1gDeN7U8FLOzUQX6uSJZh\nDF46Bn9WOilKvUpJrrcFCWcypwtxc6oFvRl05P31Dm0+2R6gNhOlckSsXDjY\nBTOJWI2pN4En8oTN7EF7JkOwG/9O7wUOpGBKrIvn/Z0Ith8O99X8fJnBuqlw\nuz20B2q5KIfNvr2Aw1nALsmPEuQtj+JQ2wj4fxY9P5f6bK31psTymWvLe7Fl\n1t2ec4x6H6cEFBULax1WJaRGHsZJ+U3fxn3SMMVJwkCBvepWM7gM6LdKH0a9\n9qOk2mlLTtFmYjZxMkL5kt457XtAYlK6YZSMLZgIZob5Bfnltrmodv4BpJop\nV7Qffwqmh18E1k8hH4tQrQ7At/gvfMY4IQb/m9H7MCgFODn1NtIAD9+8VFRR\n9Lt3BjAwZpakv6tYBW3q7rr5+17fY5O0kZ7Ns8qnhc7/5ZBjuT38828rJO12\nhLNfp7xFm8oNTlDmQeN2RSmOnt42QYKsDdUG8hzhzOjeHMq/ZzTcKPCHTxlw\nln2F/t7PHV1lvOTzwueDuI8+KAGxhb6OVkQz0Fq60Feq4Bc1/YkX5jHNcPvQ\nL5z9pJJyZ1RhP5/Z9JekzaLn8TDigW3zri2YTKQZedLKHFjzRM9FjkXgn/l6\nETWwN2hK1iryFeoNKDBslRVx89LG96MdABF1x0ZRctZfWLPHmCosqw1rVJs7\nbK3vi1W+i8FVjimu0WH2mPwnP8rMxi+RPul5QJKakHlzUKcGGLfSaTxJ0cKr\nye4u68S8ikAGu9nVmy79NASgkoBETF5EcgjD+r+gH8eYv+Dt3qV+GJAZu5wK\n3ILwGn9HpCJGhwSQCOkj0JqH1fFOZXrGlrnbtCl8QfqILP6IjQvFMO8QvcJX\nDh+kfFKmuKMSAVUwplNHIF65TBpLEr6iFoC9wfTMmha5xdScLxYa9oxFeeQp\n3TdLBFm4X+rXufOp+L1oLgOtKaETvzxHTIi0A0ZPtG2NAgGIxxtmcl6Cl4mZ\nZkWJYAlbsh+suYTAiqtoBSbyl1y8/WayeINOwBWGGl3dvRfuJMH4oQDYhAZ+\ng5UBS5YcSBsIWYairl56w7OeF/1jq702HLqm0+j2qf1gLuefBPG8/Yxo1VSr\nctElIJZwobdtW27uaycczckEuc2rlOc7DSxcTWhz95oBzeWyeB8z8AmOHVsJ\nLKkAINcxyEUfwN0Sq2Z4mQ+vFADR22RPPUWAAM96Udc6cMZyHCWWA6D4nlSl\nLBUDXujfV/ssapX1n3WVR9cc7rsHxTQ0o6ci6YPk0SWUASKP+ITamz31T0HW\nH7urYZleUWKgthcm/7YoEuKUPYBD9RjHz1cIXCO7Xz8zwfVUnMCXaqJzJ7bn\nFUvFb2qmPqc4KxhVoWU7p6NQRQNJC/qtAb27/YwZM3/gEj0qL4eT1jr8DInE\nZxa4GPUCgNf8Q8H0BtXv/WWmee2KakHXoMcawmeJBtPpyo/eAHPTihxSjPDq\nEdTgqwSCzzRETU3ZgsRc3KpawUm8kPkyxoCGFt5FwS/PFJWredsSAHCWJQ==\n", + "iv": "sPYjnXdqpABH9wrl\n", + "auth_tag": "F5ajYZMx+6r333stbQ0E1Q==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "ssl_root_cert": { + "encrypted_data": "hwwHOg/kuJxMEOLpDC2zCrIRoWkbcNzui849HEtootXsL8YPFMIo0wKzC4JS\nc5R5A7MOqgoijjrhymMKkWZ4nqdx0ZVjlLQoBpFd2D6OYmomID/e4Qi2fR4Q\nZ9eS1xoPi0cAcKKML83yHJ3bRkZhqcZLIauqm3N+pAwEdYjHo9HrNPs9stqL\noSyLIG5IwNvwh8DJMb9XU5tBlMOpI0eUDRptBHjecAdmSv59jxse7dSHVove\ndsooWNdsz48318QMG3e2ALRIWZHFb0t2C/01wYqk9PrazIX9upC1BHZ7f4XZ\nAOkukFD/uVa3wLrzQnGhh8bLxZmsRaKaGlY79vg6HgYqUoqmEuB6FHVRX7xb\nh4zt3CcWQMwU0r+Po1a2Qo5HT9xP40QgrHwtJwlpLgIP/9yxhTjpb2qdJzY3\n88MI/wZLvyezTZwMmZikE9+IlwfUBBmsSJVHOtKlPQ27YAHXmALczQUPrYG9\nqWLnWoqmyYFMpPF4u7QQUXNjde+z5sZb2gELRy1nBtHGPEZQY/Ji9P4AT0jW\n3tTidly4yYa0sXLGFH/ZbePRwrUX1qd7RalOLWUYkPwEUVcO5FzzWvCr58S0\n570VoHhyTrYWwaRfiEhEsOV/aSrVERa7T89NvDGpaKQmzpWCF1uGbnmRUI+a\nyYhSzgXaFiKiE8JFvev83slqRpsxF2z2bdHEBvSIce69pzC5VjWKVuHG/Lf8\nVseTapbVXNptMTgm+ToZHcbtBFdWlh3rpyaAKj5uKkKenY0n/R7s4M0GFviY\nj+zLQhHGYXNCybKTfguDfcKe6XiktguwXTCaXo8HpaZr49i2HsAYmSEHw4oE\nYKoYUfm9v1n6O6uxWXV92OIpRS0bkb4hUMWY9K6oG/hbUCupX/RWnBZW4wAS\nvh561oz1Ef1NVI85l2DDG++oCgXgiqzulIQxyNFOyofX5KLmJ8/nLSUc2R3E\nITPaqEG/5NUSyeQMPbIVRN4bsXcogWB/779QiXP6nDEuucNH6kpesiDbEmxC\n5J9i3xKI97zDL8HEmT7Tgp5Tu9FOyOA36qS14cMo8Ue4MWDGV1NrnbWf7LvE\nnx65h8tk1LzimnTE/NqhrYgodylUnNf6c76CaHUhqBDi3JUMF9O/IwRuYH7w\nTvOGphtyix7Lph3wCJJf/VVgK4jy2erq9+mr82dKBBCynEbUJVhpVlAkdKqX\n44LC+KIvJBb4UPerutEYmOOy2Ha1elQyFebSgUR6bxxG9JvZEOYY+UCdeRnz\nQTCQYEvUO7nHSI1uKDW2/BC0f6vzQxYWBT1XgWt5D+wlqz3ysW2AKCK2j4xL\nEFZEQF4ibX0Acm/dp/BVztq8ymhTtqW7pMPHbub0/Q4kgFiPq66FHxJdQU4Q\nuS9w2ciiPGbCbgdww3RfEU3c0kTieyHRcL/pU3aaO6RTA3SeGRX6DqXX3Si3\npkLiyuXBBIskbn0RiBn1SXYMJ17Vaye4BvFlDc2PywhEsXkRGn6Ad1gLOkyZ\nycLnXizhLX0kePSgyn/0N9RI067dlv2lzdaVuheQQEX7efrFCC2zMzvdgP8=\n", + "iv": "TrPuASVYx7D2onkS\n", + "auth_tag": "Gzn4kJCs87LK3ZKJxCHAnw==\n", "version": 3, "cipher": "aes-256-gcm" } diff --git a/site-cookbooks/kosmos-postgresql/README.md b/site-cookbooks/kosmos-postgresql/README.md index 9d8bda5..eac2c26 100644 --- a/site-cookbooks/kosmos-postgresql/README.md +++ b/site-cookbooks/kosmos-postgresql/README.md @@ -6,7 +6,6 @@ Usage: -When the `tls` attribute is set to true, a TLS certificate for the FQDN (`node['fqdn']`, for example `andromeda.kosmos.org`) is generated using Let's Encrypt and copied to the PostgreSQL data directory and added to the `postgresql.conf` file @@ -16,7 +15,6 @@ Encrypt and copied to the PostgreSQL data directory and added to the ```ruby postgresql_custom_server "12" do role "primary" - tls true end ``` @@ -25,7 +23,6 @@ end ```ruby postgresql_custom_server "12" do role "replica" - tls true end ``` @@ -47,3 +44,47 @@ about PostgreSQL client authentication, see the The primary opens up the PostgreSQL port (5432 TCP) to replicas, and replicas to the primary. + +## TLS self-signed certificate + +A wildcard (`*.kosmos.org` certificate) was generated with the following +commands: + +``` +openssl req -new -nodes -text -out root.csr -keyout root.key \ + -subj "/CN=root.kosmos.org" +chmod og-rwx root.key +openssl x509 -req -in root.csr -text -days 3650 \ + -extfile /etc/ssl/openssl.cnf -extensions v3_ca \ + -signkey root.key -out root.crt +openssl req -new -nodes -text -out server.csr \ + -keyout server.key -subj "/CN=*.kosmos.org" +chmod og-rwx server.key +openssl x509 -req -in server.csr -text -days 1825 \ + -CA root.crt -CAkey root.key -CAcreateserial \ + -out server.crt +``` + +It is valid until May 12 2025. + +The content of `server.crt`, `server.key` and `root.crt` an stored in the +`postgresql` encrypted data bag. The root key is stored in LastPass +("Self-signed TLS root certificate"). `server.crt` & `server.key` are used by +the PostgreSQL server. + +The root certificate needs to be deployed to clients so they verify the cert +can be trusted. + +For example: + +```ruby +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 +``` + +`/etc/ssl/certs/root.kosmos.org.crt` can be used as the CA root cert path in +the client's configuration diff --git a/site-cookbooks/kosmos-postgresql/resources/server.rb b/site-cookbooks/kosmos-postgresql/resources/server.rb index 14a7fc2..b6919e8 100644 --- a/site-cookbooks/kosmos-postgresql/resources/server.rb +++ b/site-cookbooks/kosmos-postgresql/resources/server.rb @@ -2,7 +2,6 @@ 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 :tls, [TrueClass, FalseClass], default: false action :create do postgresql_version = new_resource.postgresql_version @@ -63,56 +62,33 @@ action :create do additional_config[:promote_trigger_file] = "#{postgresql_data_dir}/failover.trigger" end - if new_resource.tls - include_recipe "kosmos-nginx" - include_recipe "kosmos-base::letsencrypt" + ssl_cert = postgresql_data_bag_item['ssl_cert'] + ssl_cert_path = "#{postgresql_data_dir}/server.crt" + ssl_key = postgresql_data_bag_item['ssl_key'] + ssl_key_path = "#{postgresql_data_dir}/server.key" - domain = node[:fqdn] - - postgresql_post_hook = <<-EOF -#!/usr/bin/env bash - -set -e - -# Copy the postgresql certificate and restart the server if it has been renewed -# This is necessary because the postgresql user doesn't have access to the -# letsencrypt live folder -for domain in $RENEWED_DOMAINS; do - case $domain in - #{domain}) - cp "${RENEWED_LINEAGE}/privkey.pem" #{postgresql_data_dir}/#{domain}.key - cp "${RENEWED_LINEAGE}/fullchain.pem" #{postgresql_data_dir}/#{domain}.crt - chown postgres:postgres #{postgresql_data_dir}/#{domain}.* - chmod 600 #{postgresql_data_dir}/#{domain}.* - systemctl reload #{postgresql_service} - ;; - esac -done - EOF - - # This hook will be executed by certbot after every successful certificate - # creation or renewal - file "/etc/letsencrypt/renewal-hooks/post/postgresql" do - content postgresql_post_hook - mode 0755 - owner "root" - group "root" - end - - template "#{node['nginx']['dir']}/sites-available/#{domain}" do - source 'nginx_conf_empty.erb' - owner node["nginx"]["user"] - mode 0640 - notifies :reload, 'service[nginx]', :delayed - end - - nginx_certbot_site domain - - additional_config[:ssl] = "on" - additional_config[:ssl_cert_file] = "#{postgresql_data_dir}/#{domain}.crt" - additional_config[:ssl_key_file] = "#{postgresql_data_dir}/#{domain}.key" + file ssl_cert_path do + content ssl_cert + owner "postgres" + group "postgres" + mode "0640" + sensitive true end + file ssl_key_path do + content ssl_key + owner "postgres" + group "postgres" + mode "0600" + sensitive true + end + + additional_config[:ssl] = "on" + additional_config[:ssl_cert_file] = ssl_cert_path + additional_config[:ssl_key_file] = ssl_key_path + # ejabberd does not support 1.3 yet + additional_config[:ssl_min_protocol_version] = "TLSv1.2" + postgresql_server_conf "main" do version postgresql_version additional_config additional_config diff --git a/site-cookbooks/kosmos-postgresql/templates/nginx_conf_empty.erb b/site-cookbooks/kosmos-postgresql/templates/nginx_conf_empty.erb deleted file mode 100644 index e69de29..0000000 From 006377629734ed96019321f67961022f607ed1a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 13 May 2020 19:11:00 +0200 Subject: [PATCH 023/327] Remove unused dependencies --- site-cookbooks/kosmos-postgresql/metadata.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/site-cookbooks/kosmos-postgresql/metadata.rb b/site-cookbooks/kosmos-postgresql/metadata.rb index 938ee3f..c153631 100644 --- a/site-cookbooks/kosmos-postgresql/metadata.rb +++ b/site-cookbooks/kosmos-postgresql/metadata.rb @@ -21,5 +21,3 @@ chef_version '>= 12.14' if respond_to?(:chef_version) depends "postgresql", ">= 7.0.0" depends "build-essential" -depends "kosmos-base" -depends "kosmos-nginx" From 124ee5e6f3699e9c11bf0b3471d8d85ac1310d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 14 May 2020 12:36:20 +0200 Subject: [PATCH 024/327] Update the README --- site-cookbooks/kosmos-postgresql/README.md | 30 +++++----------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/site-cookbooks/kosmos-postgresql/README.md b/site-cookbooks/kosmos-postgresql/README.md index eac2c26..21ae024 100644 --- a/site-cookbooks/kosmos-postgresql/README.md +++ b/site-cookbooks/kosmos-postgresql/README.md @@ -1,36 +1,20 @@ # kosmos-postgresql -## Custom resources +## Usage -### `postgresql_custom_server` +### On the primary: -Usage: +Set the `postgresql_primary` role on the node -(`node['fqdn']`, for example `andromeda.kosmos.org`) is generated using Let's -Encrypt and copied to the PostgreSQL data directory and added to the -`postgresql.conf` file - -#### On the primary: - -```ruby -postgresql_custom_server "12" do - role "primary" -end -``` - -#### On a replica: - -```ruby -postgresql_custom_server "12" do - role "replica" -end -``` +### On the replica: +Add the `postgresql_replica` role to the node's run list. Run Chef on the node +a first time. After the initial Chef run on the replica, run Chef on the primary to add the firewall rules and PostgreSQL access rules, then run Chef again on the replica to set up replication. -#### Caveat +## Caveat [`firewall_rules`](https://github.com/chef-cookbooks/firewall/issues/134) and [`postgresql_access`](https://github.com/sous-chefs/postgresql/issues/648) are From dd92d6cdb79ab40b76ee9681011c3e74c5bc7002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 14 May 2020 13:14:42 +0200 Subject: [PATCH 025/327] Remove deploying the root cert to clients from the README We do not want to verify the root cert so this is not needed --- site-cookbooks/kosmos-postgresql/README.md | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/site-cookbooks/kosmos-postgresql/README.md b/site-cookbooks/kosmos-postgresql/README.md index 21ae024..2541424 100644 --- a/site-cookbooks/kosmos-postgresql/README.md +++ b/site-cookbooks/kosmos-postgresql/README.md @@ -55,20 +55,3 @@ The content of `server.crt`, `server.key` and `root.crt` an stored in the `postgresql` encrypted data bag. The root key is stored in LastPass ("Self-signed TLS root certificate"). `server.crt` & `server.key` are used by the PostgreSQL server. - -The root certificate needs to be deployed to clients so they verify the cert -can be trusted. - -For example: - -```ruby -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 -``` - -`/etc/ssl/certs/root.kosmos.org.crt` can be used as the CA root cert path in -the client's configuration From 069090bf4474f61fd2db56008465856ec2f372e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 14 May 2020 13:15:47 +0200 Subject: [PATCH 026/327] Remove TODOs Access rules will not be part of this cookbook, they need to be added to the cookbooks that use a PostgreSQL database --- site-cookbooks/kosmos-postgresql/recipes/default.rb | 3 --- site-cookbooks/kosmos-postgresql/recipes/replica.rb | 3 --- 2 files changed, 6 deletions(-) diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb index af092b5..5bb5a6c 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/default.rb @@ -71,6 +71,3 @@ postgresql_replicas.each do |replica| end end end - -# TODO: We need to set up firewall rules and access rules for clients too -# (Mastodon, ejabberd, etc) diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index 1d12d51..c82efa0 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -81,6 +81,3 @@ systemctl start #{postgresql_service} end end end - -# TODO: We need to set up firewall rules and access rules for clients too -# (Mastodon, ejabberd, etc) From 18973fe4f69b0594947485f709f350c261ff9d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 14 May 2020 15:09:15 +0200 Subject: [PATCH 027/327] Remove the deleted tls property from the resources --- site-cookbooks/kosmos-postgresql/recipes/default.rb | 1 - site-cookbooks/kosmos-postgresql/recipes/replica.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb index 5bb5a6c..d4bef39 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/default.rb @@ -29,7 +29,6 @@ postgresql_service = "postgresql@#{postgresql_version}-main" postgresql_custom_server postgresql_version do role "primary" - tls true unless node.chef_environment == "development" end service postgresql_service do diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index c82efa0..6bbcb75 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -29,7 +29,6 @@ postgresql_service = "postgresql@#{postgresql_version}-main" postgresql_custom_server postgresql_version do role "replica" - tls true unless node.chef_environment == "development" end service postgresql_service do From da278822f6c85c3faee2bb7ae0e74fed63fc8650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 14 May 2020 15:09:33 +0200 Subject: [PATCH 028/327] Use the new postgresql_primary role on andromeda --- nodes/andromeda.kosmos.org.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nodes/andromeda.kosmos.org.json b/nodes/andromeda.kosmos.org.json index fc8ce4d..08697e1 100644 --- a/nodes/andromeda.kosmos.org.json +++ b/nodes/andromeda.kosmos.org.json @@ -24,6 +24,7 @@ "ipaddress": "46.4.18.160", "roles": [ "base", + "postgresql_primary", "mastodon", "ejabberd" ], @@ -73,7 +74,6 @@ "nginx::commons_dir", "nginx::commons_script", "nginx::commons_conf", - "build-essential::default", "ark::default", "composer::default", "composer::install", @@ -107,7 +107,8 @@ "tor-full::default", "kosmos-base::letsencrypt", "git::default", - "git::package" + "git::package", + "build-essential::default" ], "platform": "ubuntu", "platform_version": "18.04", @@ -128,7 +129,7 @@ "recipe[kosmos-base::andromeda_firewall]", "recipe[kosmos-ipfs]", "recipe[kosmos-ipfs::public_gateway]", - "recipe[kosmos-postgresql]", + "role[postgresql_primary]", "recipe[kosmos-mediawiki]", "recipe[kosmos-btcpayserver::proxy]", "role[mastodon]", From 773aa3ddee1063845e2a4c643b7c97620957fdcf Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 14 May 2020 15:29:25 +0200 Subject: [PATCH 029/327] Update node configs --- clients/centaurus.kosmos.org.json | 4 +++ nodes/centaurus.kosmos.org.json | 56 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 clients/centaurus.kosmos.org.json create mode 100644 nodes/centaurus.kosmos.org.json diff --git a/clients/centaurus.kosmos.org.json b/clients/centaurus.kosmos.org.json new file mode 100644 index 0000000..0e663c4 --- /dev/null +++ b/clients/centaurus.kosmos.org.json @@ -0,0 +1,4 @@ +{ + "name": "centaurus.kosmos.org", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsVV0j8DQSlefAAAmafjx\nyT1j1idLQF0oltTp2p4jFEsnEdFeP4Plpluy+detra1gM9sBBBuvRKGt8NP+Yoc7\nbnn7qU13E/nWUQh9n15+jjgUirXg7CxluKfj2VvsdchJRIvzDwwZz5sqITiGG7/S\n2r2KBBBnuGlGShQJZhhcLW4P+3YgxW8DUgUsRdvreVuvF1hcnaSymldfos1CqYL8\nawtsZ2rtdZHmZxfguXl91WBCu2OxsT13i3kInnDQsFB0tYKq+TFSLAHxneKTYPRW\ngYgP9RSBZ51iQ+6R1CenYsr4SePVCmwaZGb8bmd0QLvGKlBhjX29a5bE5tjzeoBD\nuwIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/centaurus.kosmos.org.json b/nodes/centaurus.kosmos.org.json new file mode 100644 index 0000000..0a5fe83 --- /dev/null +++ b/nodes/centaurus.kosmos.org.json @@ -0,0 +1,56 @@ +{ + "name": "centaurus.kosmos.org", + "normal": { + "knife_zero": { + "host": "centaurus.kosmos.org" + } + }, + "automatic": { + "fqdn": "centaurus.kosmos.org", + "os": "linux", + "os_version": "4.15.0-96-generic", + "hostname": "centaurus", + "ipaddress": "78.46.59.98", + "roles": [ + "postgresql_replica" + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "kosmos-postgresql::replica", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default", + "firewall::default", + "chef-sugar::default", + "build-essential::default" + ], + "platform": "ubuntu", + "platform_version": "18.04", + "cloud": null, + "chef_packages": { + "ohai": { + "version": "15.9.1", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.9.1/lib/ohai" + }, + "chef": { + "version": "15.10.12", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12/lib" + } + } + }, + "run_list": [ + "recipe[kosmos-base]", + "role[postgresql_replica]" + ] +} \ No newline at end of file From bf60f9fca8df062838ebf0272eb40414222de81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 14 May 2020 15:34:10 +0200 Subject: [PATCH 030/327] Add the Chef client public keys for andromeda and barnard --- clients/andromeda.kosmos.org.json | 4 ++++ clients/barnard.kosmos.org.json | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 clients/andromeda.kosmos.org.json create mode 100644 clients/barnard.kosmos.org.json diff --git a/clients/andromeda.kosmos.org.json b/clients/andromeda.kosmos.org.json new file mode 100644 index 0000000..07fde6d --- /dev/null +++ b/clients/andromeda.kosmos.org.json @@ -0,0 +1,4 @@ +{ + "name": "andromeda.kosmos.org", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuAI/4XcdJQ4rL3JtQ86Q\nUtdFSBdMnSPxUoHbhXXTaFEB2D0hqyCjfGmt8JqoBaRmj0zNHQvOMixe+SeyfyDs\nDPHQZ5E45f0eBYPchvOjNOZTP6RYhfa1pBRW6D6JJ+2bYW1jfnTur1Tkeg0ZL6zg\nybmcsYeDYeNXEsAGQIz+zqgNHPsTLL7U+eY9u3AYhOPaBXSnaqxPxvYx9fBRWbrx\ntFz/oXjurvLS5rMhts0s6AyMKEs+5bLhSreqGsh+1CfAt2qGNPPY7J5VL1B+cAfk\nFWYD5uWo2NvYKm94UpKsmZgFKFQBglFYpMidYdbl/NNJFq3EJDRyRlzDB8VliOuG\nnwIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/clients/barnard.kosmos.org.json b/clients/barnard.kosmos.org.json new file mode 100644 index 0000000..1c3fb60 --- /dev/null +++ b/clients/barnard.kosmos.org.json @@ -0,0 +1,4 @@ +{ + "name": "barnard.kosmos.org", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5Rr+3giLkr0xqZPRPn9Z\ngxvmAaUo6VSs1qnMfznNNN/CGCYett0ndEJp4wI8xp2fq75b2TSm4jqhqjtgYVVD\nEeSOKTZEnoE7YSssodGTAK5YnrVIPNyWd61Ih/NkHzCjlcuVX6sJD7z/pgK+WMao\nAAxzMrefvHALFBmJIxbugakru/nvDcQeV8DOF+UjzsO5CTC0BUzCFeXBG7HD3W+6\nP2wQlMKteM9uQU6Agx7XegeWS2Lfnxg1em5TNbw1PbLofROwr1pCUPfVzQ0CAVxm\nXLzmA2xtMqCT2j83DU9WleZPYiS0rg+r9T1jsDX0TyH4NTV8gO2SJ9BMUNcX+3Ox\nmQIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file From 10f0460fd581381b284a973b23cf13e69fa5cceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 15 May 2020 13:54:34 +0200 Subject: [PATCH 031/327] Fix startup of the dirsrv@master Systemd unit on boot The symlink created by Chef's service resource was wrong. Creating the correct symlink fixes the automatic startup on boot --- site-cookbooks/kosmos-dirsrv/resources/instance.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-dirsrv/resources/instance.rb b/site-cookbooks/kosmos-dirsrv/resources/instance.rb index de6b6fd..956add8 100644 --- a/site-cookbooks/kosmos-dirsrv/resources/instance.rb +++ b/site-cookbooks/kosmos-dirsrv/resources/instance.rb @@ -56,7 +56,14 @@ action :create do end service service_name do - action [:enable, :start] + action [:start] + end + + # :enable on the dirsrv@master service creates the wrong file + # (/etc/systemd/system/dirsrv.target.wants/dirsrv@master.service), seems to + # be a Chef bug. Let's do it manually + link "/etc/systemd/system/multi-user.target.wants/dirsrv@master.service" do + to "/lib/systemd/system/dirsrv@.service" end cookbook_file "#{Chef::Config[:file_cache_path]}/users.ldif" do From b4209fa29431026ed54601f5613b315f9ffcd213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 15 May 2020 14:05:35 +0200 Subject: [PATCH 032/327] Fix the invalid ACIs on initial creation (for real) Follow-up to #156 I found another issue with the initial ACI creation, while creating a fresh VM. I thought I had fixed it in #156 but I was wrong. This time the ACIs are really set and the code runs successfully. The ACIs are set on the suffix, so modifying it is needed This won't be executed on a server that is already running, this is only done on the initial setup --- site-cookbooks/kosmos-dirsrv/files/acis.ldif | 5 +++++ site-cookbooks/kosmos-dirsrv/files/users.ldif | 8 -------- site-cookbooks/kosmos-dirsrv/resources/instance.rb | 13 +++++++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 site-cookbooks/kosmos-dirsrv/files/acis.ldif diff --git a/site-cookbooks/kosmos-dirsrv/files/acis.ldif b/site-cookbooks/kosmos-dirsrv/files/acis.ldif new file mode 100644 index 0000000..f882afc --- /dev/null +++ b/site-cookbooks/kosmos-dirsrv/files/acis.ldif @@ -0,0 +1,5 @@ +dn: dc=kosmos,dc=org +changetype: modify +replace: aci +aci: (target="ldap:///dc=kosmos,dc=org") (version 3.0; acl "user-deny-all"; deny (all) userdn="ldap:///dc=kosmos,dc=org";) +aci: (target="ldap:///dc=kosmos,dc=org")(targetattr="userPassword") (version 3.0; acl "user-write-own-password"; allow (write) userdn="ldap:///self";) diff --git a/site-cookbooks/kosmos-dirsrv/files/users.ldif b/site-cookbooks/kosmos-dirsrv/files/users.ldif index 3ae1306..5055e99 100644 --- a/site-cookbooks/kosmos-dirsrv/files/users.ldif +++ b/site-cookbooks/kosmos-dirsrv/files/users.ldif @@ -1,11 +1,3 @@ -# kosmos.org -dn: dc=kosmos,dc=org -objectClass: top -objectClass: domain -dc: kosmos -aci: (target="ldap:///dc=kosmos,dc=org") (version 3.0; acl "user-deny-all"; deny (all) userdn="ldap:///dc=kosmos,dc=org";) -aci: (target="ldap:///dc=kosmos,dc=org")(targetattr="userPassword") (version 3.0; acl "user-write-own-password"; allow (write) userdn="ldap:///self";) - dn: ou=users,dc=kosmos,dc=org objectClass: top objectClass: organizationalUnit diff --git a/site-cookbooks/kosmos-dirsrv/resources/instance.rb b/site-cookbooks/kosmos-dirsrv/resources/instance.rb index de6b6fd..3d66111 100644 --- a/site-cookbooks/kosmos-dirsrv/resources/instance.rb +++ b/site-cookbooks/kosmos-dirsrv/resources/instance.rb @@ -50,6 +50,7 @@ action :create do subscribes :run, "template[#{setup_config}]", :immediately notifies :restart, "service[#{service_name}]", :immediately notifies :delete, "template[#{setup_config}]", :immediately + notifies :run, "execute[set base acis]", :delayed notifies :run, "execute[add users group]", :delayed notifies :run, "execute[disable anonymous access]", :delayed end @@ -59,6 +60,18 @@ action :create do action [:enable, :start] end + cookbook_file "#{Chef::Config[:file_cache_path]}/acis.ldif" do + source "acis.ldif" + owner "root" + group "root" + end + + execute "set base acis" do + command "ldapmodify -x -w #{new_resource.admin_password} -D '#{new_resource.bind_dn}' -f '#{Chef::Config[:file_cache_path]}/acis.ldif' -p #{new_resource.port} -h localhost" + sensitive true + action :nothing + end + cookbook_file "#{Chef::Config[:file_cache_path]}/users.ldif" do source "users.ldif" owner "root" From 55b1cbc1d7a18c381407a5762545357ae6ebe7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 15 May 2020 18:41:31 +0200 Subject: [PATCH 033/327] Encrypt the Postgresql data dir on the replica (centaurus) 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 This is running on centaurus and is mounted automatically on boot by a system unit Refs #129 --- .../kosmos-postgresql/files/encfs.service | 10 ++++++ .../kosmos-postgresql/recipes/replica.rb | 1 + .../kosmos-postgresql/resources/server.rb | 35 +++++++++++++++++++ .../templates/mount_pg_encfs.erb | 3 ++ 4 files changed, 49 insertions(+) create mode 100644 site-cookbooks/kosmos-postgresql/files/encfs.service create mode 100644 site-cookbooks/kosmos-postgresql/templates/mount_pg_encfs.erb diff --git a/site-cookbooks/kosmos-postgresql/files/encfs.service b/site-cookbooks/kosmos-postgresql/files/encfs.service new file mode 100644 index 0000000..4fdef2a --- /dev/null +++ b/site-cookbooks/kosmos-postgresql/files/encfs.service @@ -0,0 +1,10 @@ +[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 diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index 6bbcb75..00345f2 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -29,6 +29,7 @@ postgresql_service = "postgresql@#{postgresql_version}-main" postgresql_custom_server postgresql_version do role "replica" + encfs true end service postgresql_service do diff --git a/site-cookbooks/kosmos-postgresql/resources/server.rb b/site-cookbooks/kosmos-postgresql/resources/server.rb index b6919e8..1aa074c 100644 --- a/site-cookbooks/kosmos-postgresql/resources/server.rb +++ b/site-cookbooks/kosmos-postgresql/resources/server.rb @@ -2,6 +2,7 @@ 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 @@ -43,6 +44,40 @@ action :create do 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 diff --git a/site-cookbooks/kosmos-postgresql/templates/mount_pg_encfs.erb b/site-cookbooks/kosmos-postgresql/templates/mount_pg_encfs.erb new file mode 100644 index 0000000..e2ce74e --- /dev/null +++ b/site-cookbooks/kosmos-postgresql/templates/mount_pg_encfs.erb @@ -0,0 +1,3 @@ +#!/bin/sh + +/bin/echo "<%= @password %>" | encfs /var/lib/postgresql_encrypted /var/lib/postgresql --public -S From 31dc14e88c8bd17e49b63a479e426a9e06fc1378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 15 May 2020 18:44:42 +0200 Subject: [PATCH 034/327] Fix the firewall rules for PostgreSQL I got the source and destination mixed up. --- site-cookbooks/kosmos-postgresql/recipes/default.rb | 4 ++-- site-cookbooks/kosmos-postgresql/recipes/replica.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb index d4bef39..7841577 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/default.rb @@ -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 diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index 6bbcb75..926ef9b 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -72,11 +72,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 From d79cdf087bba8aaa97c86b4ac816a136d7d91417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 15 May 2020 18:45:12 +0200 Subject: [PATCH 035/327] 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 --- site-cookbooks/kosmos-postgresql/recipes/replica.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index 926ef9b..8a3f7d5 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -48,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 From d0daa9cee7a6014490bc2fe8df8a9d8d0cacd762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 15 May 2020 18:46:24 +0200 Subject: [PATCH 036/327] Add the encryption password for encfs to the data bag --- data_bags/credentials/postgresql.json | 49 +++++++++++++++------------ 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/data_bags/credentials/postgresql.json b/data_bags/credentials/postgresql.json index 8c2fecc..5d8e2f0 100644 --- a/data_bags/credentials/postgresql.json +++ b/data_bags/credentials/postgresql.json @@ -1,51 +1,58 @@ { "id": "postgresql", "ejabberd_user_password": { - "encrypted_data": "hz0xHS2wl66X6xxqLE5/6apQb8SvIR7r8hCd9ZzEcHf7VaWoFMNLmrmwqw==\n", - "iv": "PfEp9Jhqfp0o7Cje\n", - "auth_tag": "ckEADxPfymTvSVLLXUxTWA==\n", + "encrypted_data": "VkxVfafoGq/Ukz3K+qzi3DYof/Grtnb959i+sN/hXOoKsjaZN8ULwgRL5g==\n", + "iv": "tK33+rqWL046OiFf\n", + "auth_tag": "pn/JmfpPo5XN2GuuM/+vkQ==\n", "version": 3, "cipher": "aes-256-gcm" }, "server_password": { - "encrypted_data": "9aV4IykJB3lISayq/crmowTjrQjwSWSrh7+O9LMq0IgZaWZ6Bk6R\n", - "iv": "XFeNPuZAh4nCX9NU\n", - "auth_tag": "LoAIWrqSAmcuA+r3nyHu2Q==\n", + "encrypted_data": "DH/BVULhNiKGbyu7V/FfO/TAZzjcejWibjJFil4AD/DFbzdFhSEY\n", + "iv": "+15nkwDEisb20xT3\n", + "auth_tag": "x+YPz9zooCHygimq8bM/tA==\n", "version": 3, "cipher": "aes-256-gcm" }, "mastodon_user_password": { - "encrypted_data": "LGU8N2C9Ax17QvFCWNV9m1rbRpBT9YH1qVn/Cmz0/p+1aUcOUN8rzxb57Q==\n", - "iv": "FiYQKLmfJ/CYO50H\n", - "auth_tag": "t3NwAMqoGCJ/c/5H2KjQ+Q==\n", + "encrypted_data": "/Yc0PWDzqtHUssXRjIZJVLMkEqQfwOkSYLqeQaExbBYUc0gn46lK8D8kzQ==\n", + "iv": "luUlGrrdLBdDaAjR\n", + "auth_tag": "GJQLTLplECVrRSid9EMk4g==\n", "version": 3, "cipher": "aes-256-gcm" }, "replication_password": { - "encrypted_data": "6UildEd3UactuYufRp+UjHFlK3zLZ8Vmggfc8URBRNVfWHs=\n", - "iv": "e4SpyAt32vXuX4un\n", - "auth_tag": "AkCEvuEnb+E5jTC84tC8NA==\n", + "encrypted_data": "llXPXgthRg6u3pM1oEKU8FKC076qHPSDt2EHtx38ErbIZN4=\n", + "iv": "3tB4+MUtjjW5WJQ2\n", + "auth_tag": "IBH35F0rkx9mu32+K60W7w==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "encfs_password": { + "encrypted_data": "HoIzFj86M16WfDbNxgKQ/i8uv+TqLg2ibAobfGgrClRkFnnLbINB\n", + "iv": "4trQmoynuo9J97fe\n", + "auth_tag": "d8DaGlrx5bQ37b5WlT13jg==\n", "version": 3, "cipher": "aes-256-gcm" }, "ssl_cert": { - "encrypted_data": "loF7NMyOJXr8PfxsuN6zvp86hIqWYoGFiGq+ldirctWnmkeDmaROgzDW1oQp\nAubnEHZNx7IFRn/FGpGhhbX/DGjbL6EK0bSE6x6uzOEhpaFDAqmzzEfMXCMj\nDIsrM5WSmP1WBFd6g+/zk3EAXHeekOlLBEj13zzSJVj4piLFERKZRTgix0eP\nOmH+lGBoxy4hXKfa9ru7c5h4vLVQHSlHjrrsyeKdumbmXWSb3IJWtEsNQRqu\nKu6DZ+IRC8fH+DBs8/32dTbJ6uR29kbKfZrWTrpOKXWJLnT1snuiTMeRbTcO\nVbS1ZSeGcpGMFFayAui4KgPaDK8vT/mXcd2P3+c85GZtmmvIKfloIRmtb4in\nleUx3z70BxPFRg5wYfSiP/xJMpjJrh5/6P+96iMkgmU+wuXT+95yf4Agz7G5\n0gObs/sJCAV9qOoWIXSU3jyNvaYsZMPj8FHXlpnCXojHJ2WnqLCAPeVWYHbd\nvNSEOvmCN07xK1PkGZT9NGfPzRcZxqop5gJ3qP9Km33Z06SNF+28i2d4lpy+\n1oWqg5ow2CBhRrb0Bx8FplQug4EXCV7Sni4mc0jSX90rBv+e65Em+33x0A27\nPrp7lfcv+7ridU5AZXifFZSuIJF6LMXz+ji2zC2JMjS4xQ8/KXBd8E5/fRJH\nI18X+t/xx8gakmaDrz/3+4i8TVt1I8pIpN/SaAXTZqgme1QoISymf6LQzFxW\ns1kQGOwbtgx60+2BG7kF9XRRZJay8P1uxmVgjHWbqyL0KbYTlU2zTLuRs3ez\n+rPEsxB/hNfUeB9guALFLtvlkAob1Fh/Za6aukaFlaVJHbHoXehH/aXBPAVK\n0ld+3fql5Ib/OAD7prWaUCZ/tP357RWwCxz+ECjtJhFdREx8fT1aZGvmJ0yx\nESNhSjrn+b+rVc+HiD4hAytW+QP2yNqfKO9YzxXYfN5BBTxh/fvO2qVtQmSf\n+u9iatEaico44E7MX1ZOYAclTA289dwyu6R9PRa1p0zral5b+vJAOx1iH1uq\nzHUKTiRCRAcWrcciL8PH8MRXdcHSxmfyBSBbcz+dh/MURyQMx/LOQ31gYuYq\nzlgbJNsVl6V9rl9x2SargwJrD1WM863oyQumZc/M42GX0z9PilIhLQbF26MN\n2tUf5IDK7d42Z5A6ATxR+0qKh2/WvDXDbNHy+cuAjRJRX9vTgNqpR5qCOyT5\nIxA55rLvHYxbnqic124I1EdXGtoEXqsxt1YAq3ho9QCQz1t5Z/AP63oUEuLr\np4WIeo44fqZzjprRFEE3KbCGlUDx56xLg4a84JF1rMU0ce11BUtEEtRF2p4X\noecU8Z5vvhvsqXxYko6aFNcAvxO2FdZmC76lilNsHgH9VS02ctjOT7Mvi2XP\n3QEVOg==\n", - "iv": "v+wkuXO+2VZHRkOu\n", - "auth_tag": "C56+Qe/UNzR8k9HizIFyMA==\n", + "encrypted_data": "isGzgg1D9HqY4GnhUHdCgkemO5Z84ynNRuPvF45sVoHkEoWeXhZDAkuFn73E\nI1QXJpkjZP/ZDCRJd1+xztxyt7rTNpgEjHdqeuDRyeQFr28mt5YEgpJUeenv\nSB+5dzqi3a1/6MBM624sBfuzO3zUYKT/mePneKgUfQjfRfd5IPT7vH7kD8km\nm3extHm12mtR9TeVBr89rRT0wIGl4WaIyZ2mgaVJ0eryxAOJ+WOPArf1HQVO\nLZODqPMBDC+vaMRoc1UvmzqYW8+HILzwL8zKYZROTIZFsiGK7Pbriy6788US\nnwOXUHGVErAtPIfoHw0B05LsUGA5ISgiQHt5zoELnTO35rdEjUX/QMeloLcQ\nLg/E6Hazlxq98k6sGjf1Maqc7RShJowZBb94p5/L0pjqSYfar5eGtIYN9J39\nu/J+C/2lKRm+H657up20dv2RzZp37U9u6lMJ+tGdSEh2MYhofWuYCQ9vVHsv\nOp5mmI0H140UCzLoQr/TYYdVJc5v/HmResklZxOiDJHi+JC5MxFX3/BrkHtw\nYrknWvDZLQlDWwY2eAQvTOL50jrbcXcPBjfq9g8LrGGd5KUWPHNa3l4waCgH\nzVwgPVy1OfkNaTmVN+VTb2XtjxKO13H1IKZ3Ekld4VDVI2+fmwleVvL1UC4+\nPY77SRXY4N83fDNUSXm4pOHbNoaXD5IrSKZLPMlFt8hv1F/Uo+5AH7h+mrIb\nCoux7xCYFSrZ7GEwasQKMCuTQuHYy3fHWm2hWEJRQ3A0pYjXgqKyBjkGdicf\nH01HaE3xMtRotQlvin7BuCi9sv+it9HyXtmH51abc6DLZ3/2ufN9OPtkI/LV\n/eF4l+ee4ilSk2BGJXlSkd/oX0KKkWZnMrQBQWz95Btlv5x9ViEDNtrZaYTz\nDrenWw7/d572VWuOgfxjHzUg8igBx4R7v15xTZiV3qXNx0MFHrg014BmBOyD\nYo8IKT7I69kcU49Ek1WGs1vzaCwmFDdnxpWWhj7fyiULDBwIilImOwm1DTH5\n6Q9qeyjq8R4rBZ6SwshzD0Y66WfU/+VEe8qgj/Kke7Y8Jb3jtS1Pal/ehSgc\nszR89bfp6YLToEYc0fWPriWraGhusEg8Y73eI5uqT8oS82eHoXqPJ/LDhwaQ\nCunqVtnSikJCeD6jD3peulOq2Tpwgj6iyn4xZ+Jv8lknX2nlZkzuSgygp+2y\n+ZBgdCvSvLjhyiunqfzkp47opb2GZDOgInWfHt2VSeanA4t9h/93xn9uMyL1\ngp7m8bnfc+tYrwdrTQtr25lmgTiZ19qkIz8jQAMYmUgrEboRcBT5HCLv0NYB\n9kWK5LUwwxQnpmUpNtJQnhN4CbLci1n5h5y3AM0PIlL/vOASOnbxvomDXero\n0cTCdQ==\n", + "iv": "fEOQtF6urAwLwXq3\n", + "auth_tag": "mOkGJBqHs8eZcenCoocxFQ==\n", "version": 3, "cipher": "aes-256-gcm" }, "ssl_key": { - "encrypted_data": "envd5qBpUVHD5+pFmtRm99y3n+Fi6PtEwjgQl1l1VTn/bRMosMGSbWJ9VmPk\nd1tu/Nr1Z1SZcNyBiUxhAaKI2vU6BsNIpy0lnZN3R0bT4OMH/lPIJyIRqAXU\nPu+73++H41SC47Nt+9UhwRkNifIl3lFo0AhqqeHpJQbhCPVVW6oJf2Q7TGDF\nGhU5y3sat5r7FNSRCNvErv8QX/cIOSTHn76350ktgVG29+31Qp9HDhg01jac\ne8XrAiZXPxzNO7tA6zFlsRr6WVaLJeMd4bTXQpfgy/wcl+UG91n02ODdveqj\n2P+Z+ZnKvgAgmTrWpwHalJ6KkWBjuYPdaawnRPbMVUCm7usPFOurpuvYwX61\ncysFOylwCaw3vCEBWFlQAaV5GJAiaMujI8OFkioQS0FZ8M7slLs9famJzz6c\nR24BJHHb7eJRHsGZptHnEx6JGA4WGQD1e5Z8JtKnUff0WVtiSe9lwEwWNPPx\ntMJX0H8+bXdLC5W+R7pbHQfSWmbk9CP9ehlReJw9Kj1neQfm4W1Vevi42Jz2\n9JkBZ+P0ympsYb+qk0juNUrP5mC8rfW+/RktRihp4sufOW4KcK2nwWka4HeQ\nql2Xh6gHyniB2pe60lFmt2XR/0k47/tz+i6Xim67apfr8vapDzA4vBnJRVNv\nz8OVgBjJ124K5j+V4jJkWem7YfgLVpmzbkOsQp6YAsNitYUeiRwF8ijckkYF\nqEOXq4HTvyCKiPsy+myd6fjyJGCTFz4lFwQa54PFb45BsjApN78SEzWj0fxL\nT/LZF3HxA4vR72zajAFs/Vf6W7Ho5mKG/h21vjw1gDeN7U8FLOzUQX6uSJZh\nDF46Bn9WOilKvUpJrrcFCWcypwtxc6oFvRl05P31Dm0+2R6gNhOlckSsXDjY\nBTOJWI2pN4En8oTN7EF7JkOwG/9O7wUOpGBKrIvn/Z0Ith8O99X8fJnBuqlw\nuz20B2q5KIfNvr2Aw1nALsmPEuQtj+JQ2wj4fxY9P5f6bK31psTymWvLe7Fl\n1t2ec4x6H6cEFBULax1WJaRGHsZJ+U3fxn3SMMVJwkCBvepWM7gM6LdKH0a9\n9qOk2mlLTtFmYjZxMkL5kt457XtAYlK6YZSMLZgIZob5Bfnltrmodv4BpJop\nV7Qffwqmh18E1k8hH4tQrQ7At/gvfMY4IQb/m9H7MCgFODn1NtIAD9+8VFRR\n9Lt3BjAwZpakv6tYBW3q7rr5+17fY5O0kZ7Ns8qnhc7/5ZBjuT38828rJO12\nhLNfp7xFm8oNTlDmQeN2RSmOnt42QYKsDdUG8hzhzOjeHMq/ZzTcKPCHTxlw\nln2F/t7PHV1lvOTzwueDuI8+KAGxhb6OVkQz0Fq60Feq4Bc1/YkX5jHNcPvQ\nL5z9pJJyZ1RhP5/Z9JekzaLn8TDigW3zri2YTKQZedLKHFjzRM9FjkXgn/l6\nETWwN2hK1iryFeoNKDBslRVx89LG96MdABF1x0ZRctZfWLPHmCosqw1rVJs7\nbK3vi1W+i8FVjimu0WH2mPwnP8rMxi+RPul5QJKakHlzUKcGGLfSaTxJ0cKr\nye4u68S8ikAGu9nVmy79NASgkoBETF5EcgjD+r+gH8eYv+Dt3qV+GJAZu5wK\n3ILwGn9HpCJGhwSQCOkj0JqH1fFOZXrGlrnbtCl8QfqILP6IjQvFMO8QvcJX\nDh+kfFKmuKMSAVUwplNHIF65TBpLEr6iFoC9wfTMmha5xdScLxYa9oxFeeQp\n3TdLBFm4X+rXufOp+L1oLgOtKaETvzxHTIi0A0ZPtG2NAgGIxxtmcl6Cl4mZ\nZkWJYAlbsh+suYTAiqtoBSbyl1y8/WayeINOwBWGGl3dvRfuJMH4oQDYhAZ+\ng5UBS5YcSBsIWYairl56w7OeF/1jq702HLqm0+j2qf1gLuefBPG8/Yxo1VSr\nctElIJZwobdtW27uaycczckEuc2rlOc7DSxcTWhz95oBzeWyeB8z8AmOHVsJ\nLKkAINcxyEUfwN0Sq2Z4mQ+vFADR22RPPUWAAM96Udc6cMZyHCWWA6D4nlSl\nLBUDXujfV/ssapX1n3WVR9cc7rsHxTQ0o6ci6YPk0SWUASKP+ITamz31T0HW\nH7urYZleUWKgthcm/7YoEuKUPYBD9RjHz1cIXCO7Xz8zwfVUnMCXaqJzJ7bn\nFUvFb2qmPqc4KxhVoWU7p6NQRQNJC/qtAb27/YwZM3/gEj0qL4eT1jr8DInE\nZxa4GPUCgNf8Q8H0BtXv/WWmee2KakHXoMcawmeJBtPpyo/eAHPTihxSjPDq\nEdTgqwSCzzRETU3ZgsRc3KpawUm8kPkyxoCGFt5FwS/PFJWredsSAHCWJQ==\n", - "iv": "sPYjnXdqpABH9wrl\n", - "auth_tag": "F5ajYZMx+6r333stbQ0E1Q==\n", + "encrypted_data": "FLiuBWfy+212uLjshsT4jI4XEf3wk1+fb+lyQWXeH1XA4hVBawzjgVWbDRPb\nbWCnK20hEddDjL1y0NDtp4boHR1XByCw8hztFTUm5cfVbtMuJgh4yMDZtuOo\nNuZuL+mAml2tgcl7erA4oRSWUITp9oWOk/Tk+fCiLUxKlzWROxH7qjhGjAh0\nzfPFcFnK2qIHrCMWKy3zDIu0804VdcixTwXVx6/15VmNcK7KBCNK+/aU+WZc\nYNxUEmDDbzoQba6GNHYgieThB8Ywuam3m/Ys+aJMtv++MQZNNvG5kVGtkOhi\nR4/19JPz2+lgcw6CbpUBrONv1FP5QPxPqwIRI1NnXysnuDzShV5JXV5qAM3x\nFVuexvRO63NdScMprxXP1kcKMm7UNmfZVaLAjX/N34j19qP3CF9qZkdXqkWg\ndgyAlTR33f0KZAd8gBy8rx+jAuB8Xoi2St/VBZ8cuu8DJZywLQ8EiKdG7ite\nSL6Yb+PoISx0ribcBXBlLM5sMWl/pJW8WUh4F8hFYDUwkBq3fVFJQJ3QMNbj\nZup1YqR3OQiV0J1wCwj3OXcDNEv1qWN0DPIbSWHFvsxdZWP+QE03XZx/7laJ\nsdAHf4Zk1dCatk5sBpMxkpgQsbRGn+JZxrecraysOTI7zsn2BQevO7O5MTLD\nK7jwM06FdzJY0osum6rQ8P8r60fUIRKGsFpVgalZ406cp0+fT7/uCHVNrrw6\nxC24eKMEhRN93/8AuBGbeLgeVDH/ypX5eSOwQVCs3cRNUnfhdkZxYKLBuAqB\nSPAe3Fl7DgOGYbVZayuNO1Jd1JcWkqaDaheRwr6ZDGwoJZQOknhcyIAwHbLI\njyyMdPmPAogRYNm077sCU1va4Mco3+6liLjvZMJuacEp+5LRFbSg3dvXNQx2\nJdInxc6NUcPwPwd6d3v4uNUwwS24vFrMHnWXyV9NnMX60ihqBW6As0bPkr4E\nC67klJzBwtnyRc4Igd0AKJ4EMWprAofMkD5U5kEG6lMT1fVkNniWOwlwk/iS\niwYr5lYD1ypo8HOrcrremztD0Sctn3JUiDSjwdV5WKXf4wHxhOTDNLBDCRpF\nVfDbqDI6qAhKymv6N/oAQFkSVtfcqUvwavtl/tgWZSRS1Iu9BOuPWJZpiDLO\nPSiIwSv083fu6BacxsSWnVAStgUI7tULstNt5N3dGgZ3yWrTZQWL04DNJumd\n0oh+bYup7+ctkKDWEd9d73UhaJtyIxaMUbI1QbpYyIAhhDd/ISVUdoxVGM3n\nDXm7Kt0luYdO3xSXpoX+cvztaU7ppPrqNOQ1xbStqWOzaOJPjLsGiNna1iIO\nrAkJJtPl9cwWkOPPtPPbXb+urM8NaOxp5vhHrusgmDMSKQ/B4FjjYKpVAii1\nTRwzNBzvMKFkRvbOzypdGkx6G+qNhcRpMxgcAoEwL6YflrohPlPvXwDyqS5U\nxuC2VZoTXGCOaMDYzs1f5mUKaRzc4UaD0277Mwxem91m9AB/oydm8m+14GPP\ntoM1Y9WiaLcbRazwlDuSE+JxsifcunjO32hZAvDAwNLqP/q/OBq+iDFSYtKy\nnFpA2EC7rJ0FeXqWxPHYlg2k2/yBscSvJs8+hf7DYOatBvWo9zR9jqoiul8S\nD5i+riJ3dxXYLi91eaW03AtHHebfiikh2zrvV8sThkXVUNUkKk/K+Uy6VeyO\nYRRftFDl7K0090JWknFsHIwICFjZnwQjU7/+yO6NtuGfbKuMIu2+w3dmWrXh\nkRD+p3QcHBvznaZdKzjCaSa8iwVCIpDtnw4QPkr9tjMor09k2CArLM6+QHUn\n2/x4e9RrHAKHmzYaYt3BeNIyano9QNPq359s4RpJOMEYYMALHYi9oPxM1rSb\nEhr/WLR2vKU7mT42QSWxe2yAx0FQBQdnPCyGbsESerEKPMn+DiNwHksxa/82\ncvMXd4k0pGo8c5MQpsSoanHascjrhoeYdlhKIEQKODPxOGgy9ajP2bCJ6yWy\nbufgmD7176BHOg9U3fkulx6vzWx4zPCG+6QHTYLT/4zuwx6PcLc9GhmsZttQ\n+WkOhOfUKCLhwfjsIU+9l6A3uRygdIx2urvWaCe/77ndvS0J0HjEVa19pi5r\ndtmoTEASqd2Z/dYGw2zmPMoHCAkG6XPnXdjyzobc6dz7/4NPoEXNh1J3B2k1\nsfmSaPHInOgliXXxIGL/1tI7GCvyWvyoHk9vDDpHU/cjsp3hzWBahw3DI0XP\naab/TxjGq3Urx5Sk9Px9Z+6PtkpvnlBhuFsejdJYmlaXob/f3HtCse/4sZJp\njjwxrwlnVgMi4r1MBAY6OlyuWqS/xzhNu/Oa4PID5gmWxozynGgrp7yrlQ==\n", + "iv": "OmX0r4ZCilDY84Eq\n", + "auth_tag": "LUU8Z9q/h/OIy5Pvw1kQVQ==\n", "version": 3, "cipher": "aes-256-gcm" }, "ssl_root_cert": { - "encrypted_data": "hwwHOg/kuJxMEOLpDC2zCrIRoWkbcNzui849HEtootXsL8YPFMIo0wKzC4JS\nc5R5A7MOqgoijjrhymMKkWZ4nqdx0ZVjlLQoBpFd2D6OYmomID/e4Qi2fR4Q\nZ9eS1xoPi0cAcKKML83yHJ3bRkZhqcZLIauqm3N+pAwEdYjHo9HrNPs9stqL\noSyLIG5IwNvwh8DJMb9XU5tBlMOpI0eUDRptBHjecAdmSv59jxse7dSHVove\ndsooWNdsz48318QMG3e2ALRIWZHFb0t2C/01wYqk9PrazIX9upC1BHZ7f4XZ\nAOkukFD/uVa3wLrzQnGhh8bLxZmsRaKaGlY79vg6HgYqUoqmEuB6FHVRX7xb\nh4zt3CcWQMwU0r+Po1a2Qo5HT9xP40QgrHwtJwlpLgIP/9yxhTjpb2qdJzY3\n88MI/wZLvyezTZwMmZikE9+IlwfUBBmsSJVHOtKlPQ27YAHXmALczQUPrYG9\nqWLnWoqmyYFMpPF4u7QQUXNjde+z5sZb2gELRy1nBtHGPEZQY/Ji9P4AT0jW\n3tTidly4yYa0sXLGFH/ZbePRwrUX1qd7RalOLWUYkPwEUVcO5FzzWvCr58S0\n570VoHhyTrYWwaRfiEhEsOV/aSrVERa7T89NvDGpaKQmzpWCF1uGbnmRUI+a\nyYhSzgXaFiKiE8JFvev83slqRpsxF2z2bdHEBvSIce69pzC5VjWKVuHG/Lf8\nVseTapbVXNptMTgm+ToZHcbtBFdWlh3rpyaAKj5uKkKenY0n/R7s4M0GFviY\nj+zLQhHGYXNCybKTfguDfcKe6XiktguwXTCaXo8HpaZr49i2HsAYmSEHw4oE\nYKoYUfm9v1n6O6uxWXV92OIpRS0bkb4hUMWY9K6oG/hbUCupX/RWnBZW4wAS\nvh561oz1Ef1NVI85l2DDG++oCgXgiqzulIQxyNFOyofX5KLmJ8/nLSUc2R3E\nITPaqEG/5NUSyeQMPbIVRN4bsXcogWB/779QiXP6nDEuucNH6kpesiDbEmxC\n5J9i3xKI97zDL8HEmT7Tgp5Tu9FOyOA36qS14cMo8Ue4MWDGV1NrnbWf7LvE\nnx65h8tk1LzimnTE/NqhrYgodylUnNf6c76CaHUhqBDi3JUMF9O/IwRuYH7w\nTvOGphtyix7Lph3wCJJf/VVgK4jy2erq9+mr82dKBBCynEbUJVhpVlAkdKqX\n44LC+KIvJBb4UPerutEYmOOy2Ha1elQyFebSgUR6bxxG9JvZEOYY+UCdeRnz\nQTCQYEvUO7nHSI1uKDW2/BC0f6vzQxYWBT1XgWt5D+wlqz3ysW2AKCK2j4xL\nEFZEQF4ibX0Acm/dp/BVztq8ymhTtqW7pMPHbub0/Q4kgFiPq66FHxJdQU4Q\nuS9w2ciiPGbCbgdww3RfEU3c0kTieyHRcL/pU3aaO6RTA3SeGRX6DqXX3Si3\npkLiyuXBBIskbn0RiBn1SXYMJ17Vaye4BvFlDc2PywhEsXkRGn6Ad1gLOkyZ\nycLnXizhLX0kePSgyn/0N9RI067dlv2lzdaVuheQQEX7efrFCC2zMzvdgP8=\n", - "iv": "TrPuASVYx7D2onkS\n", - "auth_tag": "Gzn4kJCs87LK3ZKJxCHAnw==\n", + "encrypted_data": "QHpsC7dOw6Jwbo8DBNMxycC/cnVGieKHXCJBP4C8zVJgJjcO11q+/efX/JZp\nm1j5EfaP1NRrHsNO7ruaRY3GywxHzPsWSbYWUvwi/Vo5e3kNASipUVOSH14U\nB84OjTtVoVOCvdA/jtO8vhf7LjrFkTgOHSGDco6plsFAsVe1aq0LxnHFBOp7\nslK8fxQTqbQpDaG3xwUcBgvqdNe9yiTmmFc0DYAp2Nv4Iy/CC32RmiYlWS45\npO+wdF3uz7kQkA60ZZC2FDq8MeHiMIX5xIH1Fc9vFhCyGhkkCXOx7+DFj37p\nK1xZnhpDSMCcwQUFeMW+J+aQdIQLPm8nbm3XWLSHXaveqb5trRhzgu9H4/UN\nTCfoXAfdNEsOv64vyMgRn76CJ4VC3SHR3b4LIek+Nh68wdZN7M1gKMC1/hRn\nvrJVtdpyVnp5BGRceQ70M46KFAKcDum8npHWU43GEmKU6kmWxcX/wlufS/If\n2UbJnAtqtQmqv1ZPOnQlQJC06IsYszkQ8oj18ileQbkW8M+Gnm+HoHKvnke1\nkX0BFh0ybM7DGWIetqclIwcE2ggqo534oeAJFvQgSvgpp3gYWb/rjYstE94K\no3y1Hss+Qmt+cUcVqdtAHtDoQlMiPkfQ29XjJKMyXPXoMaxIIN/Ik9sEPATm\nfH9NEXB6VKkgpmyDGfzkURAOv5+RdtEZE18GW75ClqfWFs/41qiquVL+eYNe\nVnSINfxyV28SXAS9k67L/r7b+JniLZMkJ1py14xoGtTR4zOfgHs8WLyLEUxK\nePMJ0G8+LZSJaikmmHn6Paw+sOKe8XoeHrO0kyf1H8rpN83/1OAREWj5Buqm\n+IrbU6rsEyC24fWmNtPyG3wgO792ePMItDalNue7dKRLwQco96NS5q81nRwx\nCkxdqC3XQ+m+ikLbgErwTh0PGAZYI6uLc5kgXffXkIuHvVEKmDpN9luzSqds\nwV53ajCXx8wxPY2gd3gUvTdcDfzA0LCZSvZONB7RpuW5DFtQ1YgKmbFk3j6+\n/N7AAgoPXpkZ1FAfLrlrbKdkByk/V38zT4zpJBXYA1Yg9X/lmghfr4g8nKHo\nk7S41O3OqHS+19MPhkusYeipy6PjbemoAl0puL/DyZy8G95esrQ2nTBYViI5\nGEibkAsLva4SMeHNsnri/4pANA3UgTXhKeAb/yOHidKXzfwThDjbRUwl6ozH\n0ttbsM76m30ck3O+lXSYYhoXTWkQaHVyQ2q1ySnXssybHWmjShIKCP8PPDsy\n78L2fNm/RixaIW9My730XbAZSZYKtgB9PJf9b3swHgSJOh28u9Qgh+XupHv+\nI1qCHsdD7rAT6s2eK2kJQbx1qG0mxgdvwjlWoThFeZJDQl9rz/Qry4s7H7ZL\nLsF5GdvlHL7UvkylFrum36Qmi9zo8Xiu7IIyNP/MvgNQ0okVTrxuexHMaPFH\nLqhYejJdzhlYqdmlzVWW3z5W1pzpFPuv+IcRAaIfPPZpW90j7f8BnfqSjEtw\nwL33r6rsR6uDBE9f0t4Z2NoAWx2BmNhQaNfgaHh5C8FofZe3bFPKPlrAgts=\n", + "iv": "3shuH3d/FnBBXkKQ\n", + "auth_tag": "Wc+FTViVXmdRjLJ6aFoyZA==\n", "version": 3, "cipher": "aes-256-gcm" } From 20cbc678bc9794a7a8d2b62260386ce1e85fbe5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 18 May 2020 19:38:37 +0200 Subject: [PATCH 037/327] Add a method that returns the PostgreSQL service --- site-cookbooks/kosmos-postgresql/libraries/helpers.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/site-cookbooks/kosmos-postgresql/libraries/helpers.rb b/site-cookbooks/kosmos-postgresql/libraries/helpers.rb index a3331b6..775977e 100644 --- a/site-cookbooks/kosmos-postgresql/libraries/helpers.rb +++ b/site-cookbooks/kosmos-postgresql/libraries/helpers.rb @@ -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 From 51d4d8856811a5e834cf48016b5acbe925f3ab2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 18 May 2020 19:39:43 +0200 Subject: [PATCH 038/327] 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 --- data_bags/credentials/gitea.json | 31 ++++ site-cookbooks/kosmos_gitea/.gitignore | 22 +++ site-cookbooks/kosmos_gitea/CHANGELOG.md | 7 + site-cookbooks/kosmos_gitea/LICENSE | 20 +++ site-cookbooks/kosmos_gitea/README.md | 4 + .../kosmos_gitea/attributes/default.rb | 3 + site-cookbooks/kosmos_gitea/chefignore | 110 +++++++++++++ .../files/custom/options/label/Kosmos | 15 ++ site-cookbooks/kosmos_gitea/metadata.rb | 23 +++ site-cookbooks/kosmos_gitea/recipes/backup.rb | 25 +++ .../kosmos_gitea/recipes/default.rb | 153 ++++++++++++++++++ site-cookbooks/kosmos_gitea/recipes/pg_db.rb | 37 +++++ .../templates/default/app.ini.erb | 81 ++++++++++ .../templates/default/gitea.service.erb | 35 ++++ .../templates/default/nginx_conf.erb | 28 ++++ 15 files changed, 594 insertions(+) create mode 100644 data_bags/credentials/gitea.json create mode 100644 site-cookbooks/kosmos_gitea/.gitignore create mode 100644 site-cookbooks/kosmos_gitea/CHANGELOG.md create mode 100644 site-cookbooks/kosmos_gitea/LICENSE create mode 100644 site-cookbooks/kosmos_gitea/README.md create mode 100644 site-cookbooks/kosmos_gitea/attributes/default.rb create mode 100644 site-cookbooks/kosmos_gitea/chefignore create mode 100644 site-cookbooks/kosmos_gitea/files/custom/options/label/Kosmos create mode 100644 site-cookbooks/kosmos_gitea/metadata.rb create mode 100644 site-cookbooks/kosmos_gitea/recipes/backup.rb create mode 100644 site-cookbooks/kosmos_gitea/recipes/default.rb create mode 100644 site-cookbooks/kosmos_gitea/recipes/pg_db.rb create mode 100644 site-cookbooks/kosmos_gitea/templates/default/app.ini.erb create mode 100644 site-cookbooks/kosmos_gitea/templates/default/gitea.service.erb create mode 100644 site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb diff --git a/data_bags/credentials/gitea.json b/data_bags/credentials/gitea.json new file mode 100644 index 0000000..92f9d8d --- /dev/null +++ b/data_bags/credentials/gitea.json @@ -0,0 +1,31 @@ +{ + "id": "gitea", + "jwt_secret": { + "encrypted_data": "qHUcKXEhYWXZziyiI9URzLiyIRVWlVJmAuOyBhTe/xogUzURgCmbcgeEfOkb\n2GT2E2Qot5MDdV2+PgjwkyY=\n", + "iv": "LCl4UrlOrhcaHgaW\n", + "auth_tag": "UxyCH/obwVyR6fpIdmr/KA==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "internal_token": { + "encrypted_data": "lIeZaN6Dx6Jq+/1m0CzBzDa+/gGE+lA0CfzdMn5c0cKVmISIRfdxDE1PfawL\nFm7zvktC1DdlHnCLPKK03U6Lzy2VWRIn6HCZC8IbeFzf7zmWvHrpjOw5pEqA\nGdQmLZ2IDHcs7VcM7Xml0olH9cvccFCAGahdp5wrwB+14w==\n", + "iv": "ZPl9OJkrJAgneqvW\n", + "auth_tag": "QwqSj0q+olo811kiN+FbgQ==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "secret_key": { + "encrypted_data": "z4nxVYGEo/hqSHZ4qa5s+a9wMHUOnms5cOsSd07Nuth8YntyS3KOKfhhjvRe\n5oSDShD6IPIWGjDI481HbiJkLFufyQGHV8oR5HDvel/dKNCrokw=\n", + "iv": "xF8mlqQQVC5Senbt\n", + "auth_tag": "Un/oE3NxQMtpJQUutH19uw==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "postgresql_password": { + "encrypted_data": "qflAQFt3eMkODtNP86zjH77Y3fRvc3BWXeV0Zra4Zezkaa6vsZOWePaqSg==\n", + "iv": "SrpWet9nSiEeRMma\n", + "auth_tag": "SAvgZ5pmwWDsx3uud1EeTg==\n", + "version": 3, + "cipher": "aes-256-gcm" + } +} \ No newline at end of file diff --git a/site-cookbooks/kosmos_gitea/.gitignore b/site-cookbooks/kosmos_gitea/.gitignore new file mode 100644 index 0000000..9abf29f --- /dev/null +++ b/site-cookbooks/kosmos_gitea/.gitignore @@ -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 diff --git a/site-cookbooks/kosmos_gitea/CHANGELOG.md b/site-cookbooks/kosmos_gitea/CHANGELOG.md new file mode 100644 index 0000000..9f0ab30 --- /dev/null +++ b/site-cookbooks/kosmos_gitea/CHANGELOG.md @@ -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. diff --git a/site-cookbooks/kosmos_gitea/LICENSE b/site-cookbooks/kosmos_gitea/LICENSE new file mode 100644 index 0000000..f518b02 --- /dev/null +++ b/site-cookbooks/kosmos_gitea/LICENSE @@ -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. diff --git a/site-cookbooks/kosmos_gitea/README.md b/site-cookbooks/kosmos_gitea/README.md new file mode 100644 index 0000000..c521348 --- /dev/null +++ b/site-cookbooks/kosmos_gitea/README.md @@ -0,0 +1,4 @@ +# kosmos_gitea + +TODO: Enter the cookbook description here. + diff --git a/site-cookbooks/kosmos_gitea/attributes/default.rb b/site-cookbooks/kosmos_gitea/attributes/default.rb new file mode 100644 index 0000000..2010650 --- /dev/null +++ b/site-cookbooks/kosmos_gitea/attributes/default.rb @@ -0,0 +1,3 @@ +node.default["kosmos_gitea"]["version"] = "1.11.5" +node.default["kosmos_gitea"]["binary_checksum"] = "d8d43c13e71596c79b541e85e29defe065b4f70ac5155e6d0212bcfc669e1b9c" +node.default["kosmos_gitea"]["nginx"]["domain"] = "gitea.kosmos.org" diff --git a/site-cookbooks/kosmos_gitea/chefignore b/site-cookbooks/kosmos_gitea/chefignore new file mode 100644 index 0000000..5039e1c --- /dev/null +++ b/site-cookbooks/kosmos_gitea/chefignore @@ -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 diff --git a/site-cookbooks/kosmos_gitea/files/custom/options/label/Kosmos b/site-cookbooks/kosmos_gitea/files/custom/options/label/Kosmos new file mode 100644 index 0000000..5ca0cb3 --- /dev/null +++ b/site-cookbooks/kosmos_gitea/files/custom/options/label/Kosmos @@ -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 diff --git a/site-cookbooks/kosmos_gitea/metadata.rb b/site-cookbooks/kosmos_gitea/metadata.rb new file mode 100644 index 0000000..6582a1c --- /dev/null +++ b/site-cookbooks/kosmos_gitea/metadata.rb @@ -0,0 +1,23 @@ +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//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//kosmos_gitea' + +depends "kosmos-nginx" +depends "kosmos-postgresql" diff --git a/site-cookbooks/kosmos_gitea/recipes/backup.rb b/site-cookbooks/kosmos_gitea/recipes/backup.rb new file mode 100644 index 0000000..f4779a6 --- /dev/null +++ b/site-cookbooks/kosmos_gitea/recipes/backup.rb @@ -0,0 +1,25 @@ +# +# 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. diff --git a/site-cookbooks/kosmos_gitea/recipes/default.rb b/site-cookbooks/kosmos_gitea/recipes/default.rb new file mode 100644 index 0000000..1dd63e8 --- /dev/null +++ b/site-cookbooks/kosmos_gitea/recipes/default.rb @@ -0,0 +1,153 @@ +# +# 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 = "/var/lib/gitea" +git_home_directory = "/home/git" +config_directory = "/etc/gitea" +gitea_binary_path = "/usr/local/bin/gitea" +gitea_version = node['kosmos_gitea']['version'] +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] + +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 "https://dl.gitea.io/gitea/#{gitea_version}/gitea-#{gitea_version}-linux-amd64" + 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 diff --git a/site-cookbooks/kosmos_gitea/recipes/pg_db.rb b/site-cookbooks/kosmos_gitea/recipes/pg_db.rb new file mode 100644 index 0000000..b4577e6 --- /dev/null +++ b/site-cookbooks/kosmos_gitea/recipes/pg_db.rb @@ -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 diff --git a/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb b/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb new file mode 100644 index 0000000..bc783df --- /dev/null +++ b/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb @@ -0,0 +1,81 @@ +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 +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 diff --git a/site-cookbooks/kosmos_gitea/templates/default/gitea.service.erb b/site-cookbooks/kosmos_gitea/templates/default/gitea.service.erb new file mode 100644 index 0000000..c422bfa --- /dev/null +++ b/site-cookbooks/kosmos_gitea/templates/default/gitea.service.erb @@ -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 diff --git a/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb b/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb new file mode 100644 index 0000000..6dff6f4 --- /dev/null +++ b/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb @@ -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; + } +} From 1f0e2ccbdda42abdb768fa3ddb3f5967312de158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 21 May 2020 11:51:06 +0200 Subject: [PATCH 039/327] Move the binary URL to an attribute --- site-cookbooks/kosmos_gitea/attributes/default.rb | 4 +++- site-cookbooks/kosmos_gitea/recipes/default.rb | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/site-cookbooks/kosmos_gitea/attributes/default.rb b/site-cookbooks/kosmos_gitea/attributes/default.rb index 2010650..09bfaf8 100644 --- a/site-cookbooks/kosmos_gitea/attributes/default.rb +++ b/site-cookbooks/kosmos_gitea/attributes/default.rb @@ -1,3 +1,5 @@ -node.default["kosmos_gitea"]["version"] = "1.11.5" +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" diff --git a/site-cookbooks/kosmos_gitea/recipes/default.rb b/site-cookbooks/kosmos_gitea/recipes/default.rb index 1dd63e8..5f02f09 100644 --- a/site-cookbooks/kosmos_gitea/recipes/default.rb +++ b/site-cookbooks/kosmos_gitea/recipes/default.rb @@ -32,7 +32,6 @@ working_directory = "/var/lib/gitea" git_home_directory = "/home/git" config_directory = "/etc/gitea" gitea_binary_path = "/usr/local/bin/gitea" -gitea_version = node['kosmos_gitea']['version'] gitea_data_bag_item = data_bag_item("credentials", "gitea") smtp_credentials = data_bag_item("credentials", "smtp") jwt_secret = gitea_data_bag_item["jwt_secret"] @@ -107,7 +106,7 @@ template "#{config_directory}/app.ini" do end remote_file gitea_binary_path do - source "https://dl.gitea.io/gitea/#{gitea_version}/gitea-#{gitea_version}-linux-amd64" + source node['kosmos_gitea']['binary_url'] checksum node['kosmos_gitea']['binary_checksum'] mode "0755" end From f92b43e0f4d2743ae78edcaaed9dfd42bf1776da Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 25 May 2020 16:57:09 +0200 Subject: [PATCH 040/327] Configure Zoom meeting whitelist So we only log contributions for actual Kosmos calls --- site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb index 98da72d..acfb650 100644 --- a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb +++ b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb @@ -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 From 5fcb047505efef0dc2c8f1aad2b079986bf9e567 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 25 May 2020 17:49:22 +0200 Subject: [PATCH 041/327] Update Mastodon system dependencies Needs new Ruby, and why not upgrade Yarn in the process. Running in production. --- nodes/andromeda.kosmos.org.json | 3 ++- site-cookbooks/kosmos-mastodon/recipes/default.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/nodes/andromeda.kosmos.org.json b/nodes/andromeda.kosmos.org.json index 08697e1..ace8d73 100644 --- a/nodes/andromeda.kosmos.org.json +++ b/nodes/andromeda.kosmos.org.json @@ -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", diff --git a/site-cookbooks/kosmos-mastodon/recipes/default.rb b/site-cookbooks/kosmos-mastodon/recipes/default.rb index 5e193c4..634a9d0 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/default.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/default.rb @@ -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" From 210c76c4794f5491ddadba17352ebe0b973f5ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 26 May 2020 14:10:47 +0200 Subject: [PATCH 042/327] 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 --- site-cookbooks/kosmos-dirsrv/resources/instance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-dirsrv/resources/instance.rb b/site-cookbooks/kosmos-dirsrv/resources/instance.rb index 89174e5..7faf1cd 100644 --- a/site-cookbooks/kosmos-dirsrv/resources/instance.rb +++ b/site-cookbooks/kosmos-dirsrv/resources/instance.rb @@ -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 From 3332a1b2e82fd5b8e85a6c76e211a01ca98837b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 26 May 2020 15:21:07 +0200 Subject: [PATCH 043/327] Write initial README --- site-cookbooks/kosmos_gitea/README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_gitea/README.md b/site-cookbooks/kosmos_gitea/README.md index c521348..09cb8bb 100644 --- a/site-cookbooks/kosmos_gitea/README.md +++ b/site-cookbooks/kosmos_gitea/README.md @@ -1,4 +1,18 @@ # kosmos_gitea -TODO: Enter the cookbook description here. +## 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 From baa073993643344e9a403c40204a6bf59eb956be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 26 May 2020 15:21:26 +0200 Subject: [PATCH 044/327] Add the backup recipe Also move the Gitea data dir to an attribute --- site-cookbooks/kosmos_gitea/attributes/default.rb | 1 + site-cookbooks/kosmos_gitea/metadata.rb | 1 + site-cookbooks/kosmos_gitea/recipes/backup.rb | 6 ++++++ site-cookbooks/kosmos_gitea/recipes/default.rb | 2 +- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_gitea/attributes/default.rb b/site-cookbooks/kosmos_gitea/attributes/default.rb index 09bfaf8..90251d8 100644 --- a/site-cookbooks/kosmos_gitea/attributes/default.rb +++ b/site-cookbooks/kosmos_gitea/attributes/default.rb @@ -3,3 +3,4 @@ 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" diff --git a/site-cookbooks/kosmos_gitea/metadata.rb b/site-cookbooks/kosmos_gitea/metadata.rb index 6582a1c..9ceba2a 100644 --- a/site-cookbooks/kosmos_gitea/metadata.rb +++ b/site-cookbooks/kosmos_gitea/metadata.rb @@ -21,3 +21,4 @@ chef_version '>= 14.0' depends "kosmos-nginx" depends "kosmos-postgresql" +depends "backup" diff --git a/site-cookbooks/kosmos_gitea/recipes/backup.rb b/site-cookbooks/kosmos_gitea/recipes/backup.rb index f4779a6..83704f2 100644 --- a/site-cookbooks/kosmos_gitea/recipes/backup.rb +++ b/site-cookbooks/kosmos_gitea/recipes/backup.rb @@ -23,3 +23,9 @@ # 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 diff --git a/site-cookbooks/kosmos_gitea/recipes/default.rb b/site-cookbooks/kosmos_gitea/recipes/default.rb index 5f02f09..22bfcdc 100644 --- a/site-cookbooks/kosmos_gitea/recipes/default.rb +++ b/site-cookbooks/kosmos_gitea/recipes/default.rb @@ -28,7 +28,7 @@ include_recipe "kosmos-nginx" domain = node["kosmos_gitea"]["nginx"]["domain"] -working_directory = "/var/lib/gitea" +working_directory = node["kosmos_gitea"]["working_directory"] git_home_directory = "/home/git" config_directory = "/etc/gitea" gitea_binary_path = "/usr/local/bin/gitea" From 94330f2052713c24dd6f13131f836b0820f7200e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 28 May 2020 18:43:31 +0200 Subject: [PATCH 045/327] 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 --- site-cookbooks/kosmos_gitea/templates/default/app.ini.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb b/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb index bc783df..4597dcc 100644 --- a/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb +++ b/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb @@ -30,7 +30,8 @@ SSL_MODE = verify-ca [session] PROVIDER = file PROVIDER_CONFIG = sessions -COOKIE_SECURE = true +# Enable when TLS is enabled +# COOKIE_SECURE = true [mailer] ENABLED = true From 2d6c5142572a5955f5f7cf6f85e0870513b26724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 2 Jun 2020 11:22:10 +0200 Subject: [PATCH 046/327] Add the gitea role --- roles/gitea.rb | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 roles/gitea.rb diff --git a/roles/gitea.rb b/roles/gitea.rb new file mode 100644 index 0000000..b6f5069 --- /dev/null +++ b/roles/gitea.rb @@ -0,0 +1,6 @@ +name "gitea" + +run_list %w( + kosmos_gitea::default + kosmos_gitea::backup +) From c8e50fd226d6f2aaf73b5bed4d836b12b8078bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 2 Jun 2020 11:41:19 +0200 Subject: [PATCH 047/327] 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 --- site-cookbooks/kosmos_gitea/recipes/default.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/site-cookbooks/kosmos_gitea/recipes/default.rb b/site-cookbooks/kosmos_gitea/recipes/default.rb index 22bfcdc..3d8f370 100644 --- a/site-cookbooks/kosmos_gitea/recipes/default.rb +++ b/site-cookbooks/kosmos_gitea/recipes/default.rb @@ -42,6 +42,9 @@ 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" From 27845525da8074e483099af171ba003e79389c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 2 Jun 2020 12:12:59 +0200 Subject: [PATCH 048/327] Use the same JWT_SECRET as on our previous Gitea A different one breaks 2FA --- data_bags/credentials/gitea.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/data_bags/credentials/gitea.json b/data_bags/credentials/gitea.json index 92f9d8d..f8431b2 100644 --- a/data_bags/credentials/gitea.json +++ b/data_bags/credentials/gitea.json @@ -1,30 +1,30 @@ { "id": "gitea", "jwt_secret": { - "encrypted_data": "qHUcKXEhYWXZziyiI9URzLiyIRVWlVJmAuOyBhTe/xogUzURgCmbcgeEfOkb\n2GT2E2Qot5MDdV2+PgjwkyY=\n", - "iv": "LCl4UrlOrhcaHgaW\n", - "auth_tag": "UxyCH/obwVyR6fpIdmr/KA==\n", + "encrypted_data": "jTNhXpJ1mhUXjfRZ3OAR8lrGgxyyob44kN0TyNec5zO2Wb46hJgYMWwtKlZ9\nohNexOKV+wXCjZNeVw0kNgI=\n", + "iv": "NYkJTeTzLilMLptE\n", + "auth_tag": "a/PuBmOmhyCx0ooepz7n1w==\n", "version": 3, "cipher": "aes-256-gcm" }, "internal_token": { - "encrypted_data": "lIeZaN6Dx6Jq+/1m0CzBzDa+/gGE+lA0CfzdMn5c0cKVmISIRfdxDE1PfawL\nFm7zvktC1DdlHnCLPKK03U6Lzy2VWRIn6HCZC8IbeFzf7zmWvHrpjOw5pEqA\nGdQmLZ2IDHcs7VcM7Xml0olH9cvccFCAGahdp5wrwB+14w==\n", - "iv": "ZPl9OJkrJAgneqvW\n", - "auth_tag": "QwqSj0q+olo811kiN+FbgQ==\n", + "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": "z4nxVYGEo/hqSHZ4qa5s+a9wMHUOnms5cOsSd07Nuth8YntyS3KOKfhhjvRe\n5oSDShD6IPIWGjDI481HbiJkLFufyQGHV8oR5HDvel/dKNCrokw=\n", - "iv": "xF8mlqQQVC5Senbt\n", - "auth_tag": "Un/oE3NxQMtpJQUutH19uw==\n", + "encrypted_data": "bvxdPokzagjZkdGG37hbWBi6ywu+1UuOrlJJ4p5zOG03b4PN4N40ztO4fWr5\ncMHfO7FER779fRc+tA2H7L1SKqSvlJThgk7X8R7AGGQmrQy7Jvc=\n", + "iv": "0uTGeUjnbvnW2WGp\n", + "auth_tag": "Dzfb3Jiim5eYWfwpN3HO5Q==\n", "version": 3, "cipher": "aes-256-gcm" }, "postgresql_password": { - "encrypted_data": "qflAQFt3eMkODtNP86zjH77Y3fRvc3BWXeV0Zra4Zezkaa6vsZOWePaqSg==\n", - "iv": "SrpWet9nSiEeRMma\n", - "auth_tag": "SAvgZ5pmwWDsx3uud1EeTg==\n", + "encrypted_data": "yv2gQYUxMTa7eeC0GJqE+fujOvM9GIwj/OL/L1wvn7uNTjJE97Xt1gYXRw==\n", + "iv": "F6yrDSav9EShCf2N\n", + "auth_tag": "08b4vT71g41qu6A6jZ6opw==\n", "version": 3, "cipher": "aes-256-gcm" } From 0c502580c2d81d87540ea3785b1467a7893bfd0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 2 Jun 2020 16:16:30 +0200 Subject: [PATCH 049/327] Fix the condition for the Let's Encrypt cert in the template The line contained an extra ! --- site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb b/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb index 6dff6f4..4f67da8 100644 --- a/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb +++ b/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb @@ -4,7 +4,7 @@ upstream _gitea { } server { -<% if File.exist?(@ssl_cert) && !File.exist?(@ssl_key) -%> +<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%> listen 443 ssl http2; listen [::]:443 ssl http2; server_name <%= @server_name %>; From 55865c526ca37cef94bf74a9e0deea2cde9a6bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 2 Jun 2020 16:17:34 +0200 Subject: [PATCH 050/327] Add the Let's Encrypt hook dir to the config Only enabled when there is no TLS cert. This is already part of the certbot nginx vhost --- site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb b/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb index 4f67da8..a77bc02 100644 --- a/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb +++ b/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb @@ -16,6 +16,10 @@ server { <% else -%> listen 80; server_name <%= @server_name %>; + + location /.well-known { + root "/var/www/<%= @server_name %>"; + } <% end -%> location / { From 0f10723c8127e59a7d60e6af4b6d65c42dd0ede3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 2 Jun 2020 16:18:48 +0200 Subject: [PATCH 051/327] Enable secure cookies --- site-cookbooks/kosmos_gitea/templates/default/app.ini.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb b/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb index 4597dcc..68b771f 100644 --- a/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb +++ b/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb @@ -31,7 +31,7 @@ SSL_MODE = verify-ca PROVIDER = file PROVIDER_CONFIG = sessions # Enable when TLS is enabled -# COOKIE_SECURE = true +COOKIE_SECURE = true [mailer] ENABLED = true From 759fa52e0397b59c0415c8c0f53d47aacebcb12b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 2 Jun 2020 16:19:05 +0200 Subject: [PATCH 052/327] Enable the certbot resource --- site-cookbooks/kosmos_gitea/recipes/default.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos_gitea/recipes/default.rb b/site-cookbooks/kosmos_gitea/recipes/default.rb index 3d8f370..e159833 100644 --- a/site-cookbooks/kosmos_gitea/recipes/default.rb +++ b/site-cookbooks/kosmos_gitea/recipes/default.rb @@ -147,8 +147,7 @@ nginx_site domain do action :enable end -# Enable when we switch the IP of gitea.kosmos.org -# nginx_certbot_site domain +nginx_certbot_site domain unless node.chef_environment == "development" include_recipe "firewall" From ccd49aefa4ea068033b96f1d1c2dcd45781f5c4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 2 Jun 2020 16:19:21 +0200 Subject: [PATCH 053/327] Add Gitea to the run lists for Andromeda and Centaurus --- nodes/andromeda.kosmos.org.json | 7 ++++--- nodes/centaurus.kosmos.org.json | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/nodes/andromeda.kosmos.org.json b/nodes/andromeda.kosmos.org.json index ace8d73..dea7894 100644 --- a/nodes/andromeda.kosmos.org.json +++ b/nodes/andromeda.kosmos.org.json @@ -47,6 +47,7 @@ "kosmos-ejabberd::default", "kosmos-ejabberd::letsencrypt", "kosmos-ejabberd::backup", + "kosmos_gitea::pg_db", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -108,8 +109,7 @@ "kosmos-base::letsencrypt", "git::default", "git::package", - "build-essential::default", - "poise-git::default" + "build-essential::default" ], "platform": "ubuntu", "platform_version": "18.04", @@ -134,6 +134,7 @@ "recipe[kosmos-mediawiki]", "recipe[kosmos-btcpayserver::proxy]", "role[mastodon]", - "role[ejabberd]" + "role[ejabberd]", + "recipe[kosmos_gitea::pg_db]" ] } \ No newline at end of file diff --git a/nodes/centaurus.kosmos.org.json b/nodes/centaurus.kosmos.org.json index 0a5fe83..abd2780 100644 --- a/nodes/centaurus.kosmos.org.json +++ b/nodes/centaurus.kosmos.org.json @@ -8,16 +8,20 @@ "automatic": { "fqdn": "centaurus.kosmos.org", "os": "linux", - "os_version": "4.15.0-96-generic", + "os_version": "4.15.0-101-generic", "hostname": "centaurus", "ipaddress": "78.46.59.98", "roles": [ - "postgresql_replica" + "postgresql_replica", + "gitea" ], "recipes": [ "kosmos-base", "kosmos-base::default", "kosmos-postgresql::replica", + "kosmos_gitea", + "kosmos_gitea::default", + "kosmos_gitea::backup", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -33,7 +37,19 @@ "hostname::default", "firewall::default", "chef-sugar::default", - "build-essential::default" + "kosmos-nginx::default", + "nginx::default", + "nginx::package", + "nginx::ohai_plugin", + "nginx::repo", + "nginx::commons", + "nginx::commons_dir", + "nginx::commons_script", + "nginx::commons_conf", + "backup::default", + "logrotate::default", + "build-essential::default", + "kosmos-base::letsencrypt" ], "platform": "ubuntu", "platform_version": "18.04", @@ -51,6 +67,7 @@ }, "run_list": [ "recipe[kosmos-base]", - "role[postgresql_replica]" + "role[postgresql_replica]", + "role[gitea]" ] } \ No newline at end of file From 1e60722ec489b218f7e6e0558d4fac48fc99099e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 4 Jun 2020 19:50:20 +0200 Subject: [PATCH 054/327] 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 --- data_bags/credentials/encfs.json | 10 ++ .../kosmos-postgresql/files/encfs.service | 10 -- .../kosmos-postgresql/recipes/replica.rb | 1 - .../kosmos-postgresql/resources/server.rb | 59 +++------- .../templates/mount_pg_encfs.erb | 3 - site-cookbooks/kosmos_encfs/.gitignore | 22 ++++ site-cookbooks/kosmos_encfs/CHANGELOG.md | 7 ++ site-cookbooks/kosmos_encfs/LICENSE | 20 ++++ site-cookbooks/kosmos_encfs/README.md | 3 + site-cookbooks/kosmos_encfs/chefignore | 110 ++++++++++++++++++ .../kosmos_encfs/files/encfs.service | 11 ++ site-cookbooks/kosmos_encfs/metadata.rb | 20 ++++ .../kosmos_encfs/recipes/default.rb | 70 +++++++++++ .../kosmos_encfs/templates/mount_encfs.erb | 3 + 14 files changed, 293 insertions(+), 56 deletions(-) create mode 100644 data_bags/credentials/encfs.json delete mode 100644 site-cookbooks/kosmos-postgresql/files/encfs.service delete mode 100644 site-cookbooks/kosmos-postgresql/templates/mount_pg_encfs.erb create mode 100644 site-cookbooks/kosmos_encfs/.gitignore create mode 100644 site-cookbooks/kosmos_encfs/CHANGELOG.md create mode 100644 site-cookbooks/kosmos_encfs/LICENSE create mode 100644 site-cookbooks/kosmos_encfs/README.md create mode 100644 site-cookbooks/kosmos_encfs/chefignore create mode 100644 site-cookbooks/kosmos_encfs/files/encfs.service create mode 100644 site-cookbooks/kosmos_encfs/metadata.rb create mode 100644 site-cookbooks/kosmos_encfs/recipes/default.rb create mode 100644 site-cookbooks/kosmos_encfs/templates/mount_encfs.erb diff --git a/data_bags/credentials/encfs.json b/data_bags/credentials/encfs.json new file mode 100644 index 0000000..88377e1 --- /dev/null +++ b/data_bags/credentials/encfs.json @@ -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" + } +} \ No newline at end of file diff --git a/site-cookbooks/kosmos-postgresql/files/encfs.service b/site-cookbooks/kosmos-postgresql/files/encfs.service deleted file mode 100644 index 4fdef2a..0000000 --- a/site-cookbooks/kosmos-postgresql/files/encfs.service +++ /dev/null @@ -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 diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index 357ce4a..8a3f7d5 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -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 diff --git a/site-cookbooks/kosmos-postgresql/resources/server.rb b/site-cookbooks/kosmos-postgresql/resources/server.rb index 1aa074c..652a0ee 100644 --- a/site-cookbooks/kosmos-postgresql/resources/server.rb +++ b/site-cookbooks/kosmos-postgresql/resources/server.rb @@ -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 diff --git a/site-cookbooks/kosmos-postgresql/templates/mount_pg_encfs.erb b/site-cookbooks/kosmos-postgresql/templates/mount_pg_encfs.erb deleted file mode 100644 index e2ce74e..0000000 --- a/site-cookbooks/kosmos-postgresql/templates/mount_pg_encfs.erb +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -/bin/echo "<%= @password %>" | encfs /var/lib/postgresql_encrypted /var/lib/postgresql --public -S diff --git a/site-cookbooks/kosmos_encfs/.gitignore b/site-cookbooks/kosmos_encfs/.gitignore new file mode 100644 index 0000000..9abf29f --- /dev/null +++ b/site-cookbooks/kosmos_encfs/.gitignore @@ -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 diff --git a/site-cookbooks/kosmos_encfs/CHANGELOG.md b/site-cookbooks/kosmos_encfs/CHANGELOG.md new file mode 100644 index 0000000..019f310 --- /dev/null +++ b/site-cookbooks/kosmos_encfs/CHANGELOG.md @@ -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. diff --git a/site-cookbooks/kosmos_encfs/LICENSE b/site-cookbooks/kosmos_encfs/LICENSE new file mode 100644 index 0000000..f518b02 --- /dev/null +++ b/site-cookbooks/kosmos_encfs/LICENSE @@ -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. diff --git a/site-cookbooks/kosmos_encfs/README.md b/site-cookbooks/kosmos_encfs/README.md new file mode 100644 index 0000000..821ae83 --- /dev/null +++ b/site-cookbooks/kosmos_encfs/README.md @@ -0,0 +1,3 @@ +# kosmos_encfs + +Install encfs and set up encryption for a data directory diff --git a/site-cookbooks/kosmos_encfs/chefignore b/site-cookbooks/kosmos_encfs/chefignore new file mode 100644 index 0000000..5039e1c --- /dev/null +++ b/site-cookbooks/kosmos_encfs/chefignore @@ -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 diff --git a/site-cookbooks/kosmos_encfs/files/encfs.service b/site-cookbooks/kosmos_encfs/files/encfs.service new file mode 100644 index 0000000..f0f8da9 --- /dev/null +++ b/site-cookbooks/kosmos_encfs/files/encfs.service @@ -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 diff --git a/site-cookbooks/kosmos_encfs/metadata.rb b/site-cookbooks/kosmos_encfs/metadata.rb new file mode 100644 index 0000000..0920b48 --- /dev/null +++ b/site-cookbooks/kosmos_encfs/metadata.rb @@ -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//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//kosmos_encfs' diff --git a/site-cookbooks/kosmos_encfs/recipes/default.rb b/site-cookbooks/kosmos_encfs/recipes/default.rb new file mode 100644 index 0000000..05ce02a --- /dev/null +++ b/site-cookbooks/kosmos_encfs/recipes/default.rb @@ -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 diff --git a/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb b/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb new file mode 100644 index 0000000..10555ca --- /dev/null +++ b/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb @@ -0,0 +1,3 @@ +#!/bin/sh + +systemd-ask-password --echo "encfs password:" | encfs <%= @encrypted_directory %> <%= @mount_directory %> --public -S From bd99b76287a6e4182b6771de5348261ab1659e02 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 6 Jun 2020 12:24:08 +0200 Subject: [PATCH 055/327] Use human-readable flag for encfs mount script In case someone wants to see what it does without reading a manual in the future. --- site-cookbooks/kosmos_encfs/templates/mount_encfs.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb b/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb index 10555ca..74e1221 100644 --- a/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb +++ b/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb @@ -1,3 +1,3 @@ #!/bin/sh -systemd-ask-password --echo "encfs password:" | encfs <%= @encrypted_directory %> <%= @mount_directory %> --public -S +systemd-ask-password --echo "encfs password:" | encfs <%= @encrypted_directory %> <%= @mount_directory %> --public --stdinpass From 4fe0e913f8659658969a5829a9bde6fb92803d80 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 7 Jun 2020 12:29:06 +0200 Subject: [PATCH 056/327] Use our own fork of the postgresql cookbook --- .gitmodules | 3 + Berksfile | 2 +- Berksfile.lock | 2 - cookbooks/postgresql/CHANGELOG.md | 171 ------- cookbooks/postgresql/CONTRIBUTING.md | 21 - cookbooks/postgresql/README.md | 431 ------------------ cookbooks/postgresql/libraries/helpers.rb | 254 ----------- cookbooks/postgresql/metadata.json | 1 - cookbooks/postgresql/metadata.rb | 14 - cookbooks/postgresql/resources/access.rb | 59 --- .../postgresql/resources/client_install.rb | 35 -- cookbooks/postgresql/resources/database.rb | 67 --- cookbooks/postgresql/resources/extension.rb | 51 --- cookbooks/postgresql/resources/ident.rb | 55 --- cookbooks/postgresql/resources/repository.rb | 90 ---- cookbooks/postgresql/resources/server_conf.rb | 52 --- .../postgresql/resources/server_install.rb | 93 ---- cookbooks/postgresql/resources/user.rb | 91 ---- .../templates/createcluster.conf.erb | 41 -- .../postgresql/templates/pg_hba.conf.erb | 33 -- .../postgresql/templates/pg_ident.conf.erb | 49 -- .../postgresql/templates/pgsql.sysconfig.erb | 2 - .../postgresql/templates/postgresql.conf.erb | 26 -- .../templates/postgresql.service.erb | 6 - site-cookbooks/postgresql | 1 + 25 files changed, 5 insertions(+), 1645 deletions(-) create mode 100644 .gitmodules delete mode 100644 cookbooks/postgresql/CHANGELOG.md delete mode 100644 cookbooks/postgresql/CONTRIBUTING.md delete mode 100644 cookbooks/postgresql/README.md delete mode 100644 cookbooks/postgresql/libraries/helpers.rb delete mode 100644 cookbooks/postgresql/metadata.json delete mode 100644 cookbooks/postgresql/metadata.rb delete mode 100644 cookbooks/postgresql/resources/access.rb delete mode 100644 cookbooks/postgresql/resources/client_install.rb delete mode 100644 cookbooks/postgresql/resources/database.rb delete mode 100644 cookbooks/postgresql/resources/extension.rb delete mode 100644 cookbooks/postgresql/resources/ident.rb delete mode 100644 cookbooks/postgresql/resources/repository.rb delete mode 100644 cookbooks/postgresql/resources/server_conf.rb delete mode 100644 cookbooks/postgresql/resources/server_install.rb delete mode 100644 cookbooks/postgresql/resources/user.rb delete mode 100644 cookbooks/postgresql/templates/createcluster.conf.erb delete mode 100644 cookbooks/postgresql/templates/pg_hba.conf.erb delete mode 100644 cookbooks/postgresql/templates/pg_ident.conf.erb delete mode 100644 cookbooks/postgresql/templates/pgsql.sysconfig.erb delete mode 100644 cookbooks/postgresql/templates/postgresql.conf.erb delete mode 100644 cookbooks/postgresql/templates/postgresql.service.erb create mode 160000 site-cookbooks/postgresql diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..eb1875a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "site-cookbooks/postgresql"] + path = site-cookbooks/postgresql + url = git@github.com:67P/postgresql.git diff --git a/Berksfile b/Berksfile index 04f18ed..05704ee 100644 --- a/Berksfile +++ b/Berksfile @@ -30,7 +30,7 @@ cookbook 'nginx', '= 9.0.0' # part of Chef 14 (https://docs.chef.io/resource_build_essential.html) cookbook 'build-essential', '~> 8.2.1' cookbook 'mysql', '~> 8.5.1' -cookbook 'postgresql', '= 7.1.8' +# cookbook 'postgresql', '= 7.1.8' cookbook 'apt', '~> 7.0.0' cookbook 'git', '= 6.0.0' cookbook 'hostsfile', '= 2.4.5' diff --git a/Berksfile.lock b/Berksfile.lock index 271a16b..8d531d9 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -44,7 +44,6 @@ DEPENDENCIES poise-ruby-build (~> 1.1.0) poise-service (~> 1.5.2) postfix (= 5.0.2) - postgresql (= 7.1.8) redis git: https://github.com/phlipper/chef-redis.git revision: 7476279fc9c8727f082b8d77b5e1922dc2ef437b @@ -154,7 +153,6 @@ GRAPH poise-service (1.5.2) poise (~> 2.0) postfix (5.0.2) - postgresql (7.1.8) redis (0.5.6) apt (>= 0.0.0) seven_zip (3.1.1) diff --git a/cookbooks/postgresql/CHANGELOG.md b/cookbooks/postgresql/CHANGELOG.md deleted file mode 100644 index ce810eb..0000000 --- a/cookbooks/postgresql/CHANGELOG.md +++ /dev/null @@ -1,171 +0,0 @@ -# postgresql Cookbook CHANGELOG - -This file is used to list changes made in the last 3 major versions of the postgresql cookbook. - -## v7.1.8 (2020-02-22) - -- Fix incorrect ubuntu platform family value in `postgresql_server_install` -- Re-add unit tests that were skipped - -## v7.1.7 (2020-02-21) - -- Correctly configure postgres-common on Ubuntu hosts (fixes #596) - -## v7.1.6 (2020-02-20) - -- Remove unnecessary nil default in resource properties -- Migrate to GitHub Actions for testing - -## v7.1.5 (2019-11-18) - -- Allow to install extensions with hyphens, ex: `postgresql_extension '"uuid-ossp"'` -- Update Circle CI config to match sous-chefs defaults #617 -- Remove Fedora testing from CI, not an official supported OS by sous-chefs, PR welcome #617 - -## v7.1.4 (2019-03-28) - -- Fix installation of extensions. - -## v7.1.3 (2019-01-15) - -- Added support for dash in database role name. - -## v7.1.2 (2019-06-01) - -- Cleanup and update the user resource documentation and code. Removed extraneous 'sensitive' property which is a common property in all Chef resources. -- Change default permissions on the postgres.conf to be world readable so that psql can work. - -## v7.1.1 (2018-09-26) - -- Rename slave to follower -- Use CircleCI for testing -- Simplyfy extension resource - -## v7.1.0 (2018-06-22) - -- Update the `initdb` script to use initdb rather than a service. #542 -- Refactor database commands to use the common connect method. #535 -- Increase the unit test coverage. - -## v7.0.0 (2018-05-25) - -_Breaking Change_ Please see UPGRADING.md and the README.md for information how to use. - -- Add custom resources for: - - - `postgresql_client_install` - - `postgresql_server_install` - - `postgresql_repository` - - `postgresql_pg_gem` - -- Deprecate recipes: - - - `apt_pgdg_postgresql` - - `config_initdb` - - `config_pgtune` - - `contrib` - - `ruby` - - `yum_pgdg_postgresql` - -- Remove deprecated tests - -## v6.1.3 (2018-04-18) - -- Fix recipes referencing the old helpers - -## v6.1.2 (2018-04-16) - -this will be the last release of the 6.0 series before all recipes are removed from the cookbook - -- Deprecate all recipes - -## v6.1.1 (2017-03-08) - -- Fix pg gem installation on non-omnibus chef runs -- Resolve resource cloning deprecation warnings in the ruby recipe -- Fix issues resolving the timezone on CentOS 7 and probably other distros -- Test with Delivery local instead of Rake - -## v6.1.0 (2017-02-18) - -- Fix a method name conflict that caused errors if Chef Sugar was also being used on the run list -- Revert a previous PR that added support for Postgresql 9.6 as it introduced incorrect configuration values -- Added Fedora 25 support for pgdg packages -- Added RHEL 5 support for Postgresql 9.4 pgdg packages -- Removed testing for RHEL 5 and Ubuntu 12.04 as they are scheduled for EoL in the near future -- Improvements to Test Kitchen testing to allow more extensive testing in Travis CI -- Fixed the client recipe on Fedora -- Added Inspec tests for client installs - -## v6.0.1 (2017-01-04 - -- Fix systemd unit file template - -## v6.0.0 (2017-01-03) - -- This cookbook now requires Chef 12.1 or later -- Removed the dependency on the apt cookbook as this functionality is built into modern chef client releases -- Added a new custom resource for installing extensions. This acts as a replacement for the contrib recipe with minimal backwards compatibility. You can now install / remove extensions into any database. This adds the compat_resource cookbook dependency so we can continue to support Chef 12.1-12.4, which lack custom resource support. -- The unused get_result_orig helper has been removed. If you utilized this you'll want to move it to your own wrapper cookbook -- Updates for compatibility with Postgresql 9.5 and 9.6 -- Fixed client package installation on openSUSE Leap 42.2 -- ca-certificates recipe has been deprecated. If ca-certificates package needs to be upgraded the user should do so prior to including this recipe. Package upgrades in community cookbooks are generally a bad idea as this bring in updated packages to production systems. The recipe currently warns if used and will be removed with the next major cookbook release. -- Fixed RHEL platform detection in the Ruby recipe -- systemd fixes for RHEL systems -- Fix systemd service file include when using pgdg packages -- Package installation now uses multi-package installs to speed up converge times -- Added integration testing in Travis of the client recipe using a new test cookbook. This will be expanded in the future to cover server installation as well -- Expanded the specs to test converges on multiple platforms - -## v5.2.0 (2016-12-30) - -- Updated contacts and links to point to Sous Chefs now -- Added a Code of Conduct (the Chef CoC) -- Removed duplicate platforms in the metadata -- Fix Chef runs with local mode in the server recipe -- Fix the ruby recipe to not fail when you specify enabling both the apt and yum repos for mixed distro environments -- Set the postgresql data directory to 700 permissions -- Added node['postgresql']['pg_gem']['version'] to specify the version of the pg gem to install -- Cookstyle fixes for the latest cookstyle release -- Removed test deps from the Gemfile. Rely on ChefDK for base testing deps instead - -## v5.1.0 (2016-11-01) - -- Maintenance of this cookbook has been migrated from Heavy Water to Sous Chefs - -- Add support for Chef-Zero (local mode) -- Don't hardcode the UID / GID on RHEL/Amazon/Suse platforms -- Add PGDG yum RPMs for 9.5 / 9.6 - -## v5.0.0 (2016-10-25) - -### Breaking changes - -- Switched from Librarian to Berkshelf -- Remove support for the following platforms - - - SLES < 12 - - openSUSE < 13 - - Debian < 7 - - Ubuntu < 12.04 - - RHEL < 6 - - Amazon < 2013 - - Unsupported (EOL) Fedora releases - -### Other changes - -- Added support for Ubuntu 16.04 -- Loosened cookbook dependencies to not prevent pulling in the latest community cookbooks -- Added chef_version metadata -- Switched from rubocop to cookstyle and fix all warnings -- Removed minitests and the minitest handler -- Added support for opensuse / opensuseleap -- Added support for Fedora 23/24 -- Added a chefignore file to limit the files uploaded to the chef server -- Updated Test Kitchen config to test on modern platform releases -- Added a Rakefile and updated Travis to test with ChefDK and that rakefile -- Avoid installing packages included in build-essential twice in the ruby recipe -- Require at least build-essential 2.0 -- Don't cleanup the old PPA files in the apt_pgdg_postgresql recipe anymore. These should be long gone everywhere -- Remove logic in the apt_pgdg_postgresql recipe that made Chef fail when new distro releases came out -- Avoid node.set deprecation warnings -- Avoid managed_home deprecation warnings in server_redhat recipe diff --git a/cookbooks/postgresql/CONTRIBUTING.md b/cookbooks/postgresql/CONTRIBUTING.md deleted file mode 100644 index e28e2a6..0000000 --- a/cookbooks/postgresql/CONTRIBUTING.md +++ /dev/null @@ -1,21 +0,0 @@ -# Contributing - -## Branches - -### `master` branch - -The master branch is the current committed changes. These changes may not yet be released although we try to release often. - -## Tags - -All releases are tagged in git. To see the releases available to you see the changelog or the tags directly. - -## Pull requests - -- - -## Issues - -Need to report an issue? Use the github issues: - -- diff --git a/cookbooks/postgresql/README.md b/cookbooks/postgresql/README.md deleted file mode 100644 index d8ebb76..0000000 --- a/cookbooks/postgresql/README.md +++ /dev/null @@ -1,431 +0,0 @@ -# PostgreSQL cookbook - -[![Cookbook Version](https://img.shields.io/cookbook/v/postgresql.svg)](https://supermarket.chef.io/cookbooks/postgresql) -[![Build Status](https://img.shields.io/circleci/project/github/sous-chefs/postgresql/master.svg)](https://circleci.com/gh/sous-chefs/postgresql) -[![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) -[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) -[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) - -Installs and configures PostgreSQL as a client or a server. - -## Maintainers - -This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF). - -## Upgrading - -If you are wondering where all the recipes went in v7.0+, or how on earth I use this new cookbook please see upgrading.md for a full description. - -## Requirements - -### Platforms - -- Amazon Linux -- Debian 7+ -- Ubuntu 14.04+ -- Red Hat/CentOS/Scientific 6+ - -### PostgreSQL version - -We follow the currently supported versions listed on - -### Chef - -- Chef 13.8+ - -### Cookbook Dependencies - -None. - -## Resources - -### postgresql_client_install - -This resource installs PostgreSQL client packages. - -#### Actions - -- `install` - (default) Install client packages - -#### Properties - -Name | Types | Description | Default | Required? -------------------- | ----------------- | ------------------------------------------------------------- | ----------------------------------------- | --------- -`version` | String | Version of PostgreSQL to install | '9.6' | no -`setup_repo` | Boolean | Define if you want to add the PostgreSQL repo | true | no -`hba_file` | String | | `#{conf_dir}/main/pg_hba.conf` | no -`ident_file` | String | | `#{conf_dir}/main/pg_ident.conf` | no -`external_pid_file` | String | | `/var/run/postgresql/#{version}-main.pid` | no -`password` | String, nil | Pass in a password, or have the cookbook generate one for you | random string | no - -#### Examples - -To install version 9.5: - -```ruby -postgresql_client_install 'My PostgreSQL Client install' do - version '9.5' -end -``` - -### postgresql_server_install - -This resource installs PostgreSQL client and server packages. - -#### Actions - -- `install` - (default) Install client and server packages -- `create` - Initialize the database - -#### Properties - -Name | Types | Description | Default | Required? -------------------- | --------------- | --------------------------------------------- | -------------------------------------------------- | --------- -`version` | String | Version of PostgreSQL to install | '9.6' | no -`setup_repo` | Boolean | Define if you want to add the PostgreSQL repo | true | no -`hba_file` | String | Path of pg_hba.conf file | `/pg_hba.conf'` | no -`ident_file` | String | Path of pg_ident.conf file | `/pg_ident.conf` | no -`external_pid_file` | String | Path of PID file | `/var/run/postgresql/-main.pid` | no -`password` | String, nil | Set PostgreSQL user password | 'generate' | no -`port` | Integer | Set listen port of PostgreSQL service | 5432 | no -`initdb_locale` | String | Locale to initialise the database with | 'C' | no - -#### Examples - -To install PostgreSQL server, set your own postgres password using non-default service port. - -```ruby -postgresql_server_install 'My PostgreSQL Server install' do - action :install -end - -postgresql_server_install 'Setup my PostgreSQL 9.6 server' do - password 'MyP4ssw0rd' - port 5433 - action :create -end -``` - -#### Known issues - -On some platforms (e.g. Ubuntu 18.04), your `initdb_locale` should be set to the -same as the template database [GH-555](https://github.com/sous-chefs/postgresql/issues/555). - -### postgresql_server_conf - -This resource manages postgresql.conf configuration file. - -#### Actions - -- `modify` - (default) Manager PostgreSQL configuration file (postgresql.conf) - -#### Properties - -Name | Types | Description | Default | Required? ----------------------- | ------- | --------------------------------------- | --------------------------------------------------- | --------- -`version` | String | Version of PostgreSQL to install | '9.6' | no -`data_directory` | String | Path of PostgreSQL data directory | `` | no -`hba_file` | String | Path of pg_hba.conf file | `/pg_hba.conf` | no -`ident_file` | String | Path of pg_ident.conf file | `/pg_ident.conf` | no -`external_pid_file` | String | Path of PID file | `/var/run/postgresql/-main.pid` | no -`stats_temp_directory` | String | Path of stats file | `/var/run/postgresql/version>-main.pg_stat_tmp` | no -`port` | Integer | Set listen port of PostgreSQL service | 5432 | no -`additional_config` | Hash | Extra configuration for the config file | {} | no - -#### Examples - -To setup your PostgreSQL configuration with a specific data directory. If you have installed a specific version of PostgreSQL (different from 9.6), you must specify version in this resource too. - -```ruby -postgresql_server_conf 'My PostgreSQL Config' do - version '9.5' - data_directory '/data/postgresql/9.5/main' - notifies :reload, 'service[postgresql]' -end -``` - -### postgresql_extension - -This resource manages PostgreSQL extensions for a given database. - -#### Actions - -- `create` - (default) Creates an extension in a given database -- `drop` - Drops an extension from the database - -#### Properties - -Name | Types | Description | Default | Required? -------------- | ------ | -------------------------------------------------------------------------------- | ---------------- | --------- -`database` | String | Name of the database to install the extension into | | yes -`extension` | String | Name of the extension to install the database | Name of resource | yes -`version` | String | Version of the extension to install | | no -`old_version` | String | Older module name for new extension replacement. Appends FROM to extension query | | no - -#### Examples - -To install the `adminpack` extension: - -```ruby -# Add the contrib package in Ubuntu/Debian -package 'postgresql-contrib-9.6' - -# Install adminpack extension -postgresql_extension 'postgres adminpack' do - database 'postgres' - extension 'adminpack' -end -``` - -### postgresql_access - -This resource uses the accumulator pattern to build up the `pg_hba.conf` file via chef resources instead of piling on a mountain of chef attributes to make this cookbook more reusable. It directly mirrors the configuration options of the postgres hba file in the resource and by default notifies the server with a reload to avoid a full restart, causing a potential outage of service. To revoke access, simply remove the resource and the access change won't be computed into the final `pg_hba.conf` - -#### Actions - -- `grant` - (default) Creates an access line inside of `pg_hba.conf` - -#### Properties - -Name | Types | Description | Default | Required? ---------------- | ------ | ----------------------------------------------------------------------------------------- | ----------------- | --------- -`name` | String | Name of the access resource, this is left as a comment inside the `pg_hba` config | Resource name | yes -`source` | String | The cookbook template filename if you want to use your own custom template | 'pg_hba.conf.erb' | yes -`cookbook` | String | The cookbook to look in for the template source | 'postgresql' | yes -`comment` | String | A comment to leave above the entry in `pg_hba` | nil | no -`access_type` | String | The type of access, e.g. local or host | 'local' | yes -`access_db` | String | The database to access. Can use 'all' for all databases | 'all' | yes -`access_user` | String | The user accessing the database. Can use 'all' for any user | 'all' | yes -`access_addr` | String | The address(es) allowed access. Can be nil if method ident is used since it is local then | nil | no -`access_method` | String | Authentication method to use | 'ident' | yes - -#### Examples - -To grant access to the PostgreSQL user with ident authentication: - -```ruby -postgresql_access 'local_postgres_superuser' do - comment 'Local postgres superuser access' - access_type 'local' - access_db 'all' - access_user 'postgres' - access_addr nil - access_method 'ident' -end -``` - -This generates the following line in the `pg_hba.conf`: - -```config -# Local postgres superuser access -local all postgres ident -``` - -**Note**: The template by default generates a local access for Unix domain sockets only to support running the SQL execute resources. In Postgres version 9.1 and higher, the method is 'peer' instead of 'ident' which is identical. It looks like this: - -```config -# "local" is for Unix domain socket connections only -local all all peer -``` - -### postgresql_ident - -This resource generate `pg_ident.conf` configuration file to manage user mapping between system and PostgreSQL users. - -#### Actions - -- `create` - (default) Creates an mapping line inside of `pg_ident.conf` - -#### Properties - -Name | Types | Description | Default | Required? --------------- | ----------- | -------------------------------------------------------------------------- | ------------------- | --------- -`mapname` | String | Name of the user mapping | Resource name | yes -`source` | String | The cookbook template filename if you want to use your own custom template | 'pg_ident.conf.erb' | no -`cookbook` | String | The cookbook to look in for the template source | 'postgresql' | no -`comment` | String, nil | A comment to leave above the entry in `pg_ident` | nil | no -`system_user` | String | System user or regexp used for the mapping | None | yes -`pg_user` | String | Pg user or regexp used for the mapping | None | yes - -#### Examples - -Creates a `mymapping` mapping that map `john` system user to `user1` PostgreSQL user: - -```ruby -postgresql_ident 'Map john to user1' do - comment 'John Mapping' - mapname 'mymapping' - system_user 'john' - pg_user 'user1' -end -``` - -This generates the following line in the `pg_ident.conf`: - -```config -# MAPNAME SYSTEM-USERNAME PG-USERNAME - -# John Mapping -mymapping john user1 -``` - -To grant access to the foo user with password authentication: - -```ruby -postgresql_access 'local_foo_user' do - comment 'Foo user access' - access_type 'host' - access_db 'all' - access_user 'foo' - access_addr '127.0.0.1/32' - access_method 'md5' -end -``` - -This generates the following line in the `pg_hba.conf`: - -```config -# Local postgres superuser access -host all foo 127.0.0.1/32 ident -``` - -### postgresql_database - -This resource manages PostgreSQL databases. - -#### Actions - -- `create` - (default) Creates the given database. -- `drop` - Drops the given database. - -#### Properties - -Name | Types | Description | Default | Required? ----------- | ------- | ------------------------------------------------------------------- | ------------------- | --------- -`database` | String | Name of the database to create | Resource name | yes -`user` | String | User which run psql command | 'postgres' | no -`template` | String | Template used to create the new database | 'template1' | no -`host` | String | Define the host server where the database creation will be executed | Not set (localhost) | no -`port` | Integer | Define the port of PostgreSQL server | 5432 | no -`encoding` | String | Define database encoding | 'UTF-8' | no -`locale` | String | Define database locale | 'en_US.UTF-8' | no -`owner` | String | Define the owner of the database | Not set | no - -#### Examples - -To create database named 'my_app' with owner 'user1': - -```ruby -postgresql_database 'my_app' do - owner 'user1' -end -``` - -#### Known issues - -On some platforms (e.g. Ubuntu 18.04), your `initdb_locale` should be set to the -same as the template database [GH-555](https://github.com/sous-chefs/postgresql/issues/555). - -### postgresql_user - -This resource manage PostgreSQL users. - -#### Actions - -- `create` - (default) Creates the given user with default or given privileges. -- `update` - Update user privilieges. -- `drop` - Deletes the given user. - -#### Properties - -Name | Types | Description | Default | Required? --------------------- | ------- | ----------------------------------------------- | -------- | --------- -`create_user` | String | User to create (defaults to the resource name) | | Yes -`superuser` | Boolean | Define if user needs superuser role | false | no -`createdb` | Boolean | Define if user needs createdb role | false | no -`createrole` | Boolean | Define if user needs createrole role | false | no -`inherit` | Boolean | Define if user inherits the privileges of roles | true | no -`replication` | Boolean | Define if user needs replication role | false | no -`login` | Boolean | Define if user can login | true | no -`password` | String | Set user's password | | no -`encrypted_password` | String | Set user's password with an hashed password | | no -`valid_until` | String | Define an account expiration date | | no -`attributes` | Hash | Additional attributes for :update action | {} | no -`user` | String | User for command | postgres | no -`database` | String | Database for command | | no -`host` | String | Hostname for command | | no -`port` | Integer | Port number to connect to postgres | 5432 | no - -#### Examples - -Create a user `user1` with a password, with `createdb` role and set an expiration date to 2018, Dec 21. - -```ruby -postgresql_user 'user1' do - password 'UserP4ssword' - createdb true - valid_until '2018-12-31' -end -``` - -Create a user `user1` with a password, with `createdb` role and set an expiration date to 2018, Dec 21. - -```ruby -postgresql_user 'user1' do - password 'UserP4ssword' - createdb true - valid_until '2018-12-31' -end -``` - -## Usage - -To install and configure your PostgreSQL instance you need to create your own cookbook and call needed resources with your own parameters. - -More examples can be found in `test/cookbooks/test/recipes` - -## Example Usage - -```ruby -# cookbooks/my_postgresql/recipes/default.rb - -postgresql_client_install 'PostgreSQL Client' do - setup_repo false - version '10.6' -end - -postgresql_server_install 'PostgreSQL Server' do - version '10.6' - setup_repo false - password 'P0stgresP4ssword' -end - -postgresql_server_conf 'PostgreSQL Config' do - notifies :reload, 'service[postgresql]' -end -``` - -## Contributors - -This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) - -### Backers - -Thank you to all our backers! - -![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) - -### Sponsors - -Support this project by becoming a sponsor. Your logo will show up here with a link to your website. - -![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) -![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) diff --git a/cookbooks/postgresql/libraries/helpers.rb b/cookbooks/postgresql/libraries/helpers.rb deleted file mode 100644 index b8d2a2b..0000000 --- a/cookbooks/postgresql/libraries/helpers.rb +++ /dev/null @@ -1,254 +0,0 @@ -# -# Cookbook:: postgresql -# Library:: helpers -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -module PostgresqlCookbook - module Helpers - include Chef::Mixin::ShellOut - - require 'securerandom' - - def psql_command_string(new_resource, query, grep_for: nil, value_only: false) - cmd = %(/usr/bin/psql -c "#{query}") - cmd << " -d #{new_resource.database}" if new_resource.database - cmd << " -U #{new_resource.user}" if new_resource.user - cmd << " --host #{new_resource.host}" if new_resource.host - cmd << " --port #{new_resource.port}" if new_resource.port - cmd << ' --tuples-only' if value_only - cmd << " | grep #{grep_for}" if grep_for - cmd - end - - def execute_sql(new_resource, query) - # If we don't pass in a user to the resource - # default to the postgres user - user = new_resource.user || 'postgres' - - # Query could be a String or an Array of Strings - statement = query.is_a?(String) ? query : query.join("\n") - - cmd = shell_out(statement, user: user, environment: psql_environment) - - # Pass back cmd so we can decide what to do with it in the calling method. - cmd - end - - def database_exists?(new_resource) - sql = %(SELECT datname from pg_database WHERE datname='#{new_resource.database}') - - exists = psql_command_string(new_resource, sql, grep_for: new_resource.database) - - cmd = execute_sql(new_resource, exists) - cmd.exitstatus == 0 - end - - def user_exists?(new_resource) - sql = %(SELECT rolname FROM pg_roles WHERE rolname='#{new_resource.create_user}';) - - exists = psql_command_string(new_resource, sql, grep_for: new_resource.create_user) - - cmd = execute_sql(new_resource, exists) - cmd.exitstatus == 0 - end - - def extension_installed?(new_resource) - query = %(SELECT extversion FROM pg_extension WHERE extname='#{new_resource.extension}';) - check_extension_version = psql_command_string(new_resource, query, value_only: true) - version_result = execute_sql(new_resource, check_extension_version) - if new_resource.version - version_result.stdout == new_resource.version - else - !version_result.stdout.chomp.empty? - end - end - - def alter_role_sql(new_resource) - sql = %(ALTER ROLE postgres ENCRYPTED PASSWORD '#{postgres_password(new_resource)}';) - psql_command_string(new_resource, sql) - end - - def create_extension_sql(new_resource) - sql = %(CREATE EXTENSION IF NOT EXISTS #{new_resource.extension}) - sql << " FROM \"#{new_resource.old_version}\"" if new_resource.old_version - - psql_command_string(new_resource, sql) - end - - def user_has_password?(new_resource) - sql = %(SELECT rolpassword from pg_authid WHERE rolname='postgres' AND rolpassword IS NOT NULL;) - cmd = psql_command_string(new_resource, sql) - - res = execute_sql(new_resource, cmd) - res.stdout =~ /1 row/ ? true : false - end - - def role_sql(new_resource) - sql = %(\\"#{new_resource.create_user}\\" WITH ) - - %w(superuser createdb createrole inherit replication login).each do |perm| - sql << "#{'NO' unless new_resource.send(perm)}#{perm.upcase} " - end - - sql << if new_resource.encrypted_password - "ENCRYPTED PASSWORD '#{new_resource.encrypted_password}'" - elsif new_resource.password - "PASSWORD '#{new_resource.password}'" - else - '' - end - - sql << if new_resource.valid_until - " VALID UNTIL '#{new_resource.valid_until}'" - else - '' - end - end - - def create_user_sql(new_resource) - sql = %(CREATE ROLE #{role_sql(new_resource)}) - psql_command_string(new_resource, sql) - end - - def update_user_sql(new_resource) - sql = %(ALTER ROLE #{role_sql(new_resource)}) - psql_command_string(new_resource, sql) - end - - def update_user_with_attributes_sql(new_resource, value) - sql = %(ALTER ROLE '#{new_resource.create_user}' SET #{attr} = #{value}) - psql_command_string(new_resource, sql) - end - - def drop_user_sql(new_resource) - sql = %(DROP ROLE IF EXISTS '#{new_resource.create_user}') - psql_command_string(new_resource, sql) - end - - def data_dir(version = node.run_state['postgresql']['version']) - case node['platform_family'] - when 'rhel', 'fedora' - "/var/lib/pgsql/#{version}/data" - when 'amazon' - if node['virtualization']['system'] == 'docker' - "/var/lib/pgsql#{version.delete('.')}/data" - else - "/var/lib/pgsql/#{version}/data" - end - when 'debian' - "/var/lib/postgresql/#{version}/main" - end - end - - def conf_dir(version = node.run_state['postgresql']['version']) - case node['platform_family'] - when 'rhel', 'fedora' - "/var/lib/pgsql/#{version}/data" - when 'amazon' - if node['virtualization']['system'] == 'docker' - "/var/lib/pgsql#{version.delete('.')}/data" - else - "/var/lib/pgsql/#{version}/data" - end - when 'debian' - "/etc/postgresql/#{version}/main" - end - end - - # determine the platform specific service name - def platform_service_name(version = node.run_state['postgresql']['version']) - case node['platform_family'] - when 'rhel', 'fedora' - "postgresql-#{version}" - when 'amazon' - if node['virtualization']['system'] == 'docker' - "postgresql#{version.delete('.')}" - else - "postgresql-#{version}" - end - else - 'postgresql' - end - end - - def follower? - ::File.exist? "#{data_dir}/recovery.conf" - end - - def initialized? - return true if ::File.exist?("#{conf_dir}/PG_VERSION") - false - end - - def secure_random - r = SecureRandom.hex - Chef::Log.debug "Generated password: #{r}" - r - end - - # determine the platform specific server package name - def server_pkg_name - platform_family?('debian') ? "postgresql-#{new_resource.version}" : "postgresql#{new_resource.version.delete('.')}-server" - end - - # determine the appropriate DB init command to run based on RHEL/Fedora/Amazon release - # initdb defaults to the execution environment. - # https://www.postgresql.org/docs/9.5/static/locale.html - def rhel_init_db_command(new_resource) - cmd = if platform_family?('amazon') - '/usr/bin/initdb' - else - "/usr/pgsql-#{new_resource.version}/bin/initdb" - end - cmd << " --locale '#{new_resource.initdb_locale}'" if new_resource.initdb_locale - cmd << " -E '#{new_resource.initdb_encoding}'" if new_resource.initdb_encoding - cmd << " -D '#{data_dir(new_resource.version)}'" - end - - # Given the base URL build the complete URL string for a yum repo - def yum_repo_url(base_url) - "#{base_url}/#{new_resource.version}/#{yum_repo_platform_family_string}/#{yum_repo_platform_string}" - end - - # The postgresql yum repos URLs are organized into redhat and fedora directories.s - # route things to the right place based on platform_family - def yum_repo_platform_family_string - platform_family?('fedora') ? 'fedora' : 'redhat' - end - - # Build the platform string that makes up the final component of the yum repo URL - def yum_repo_platform_string - platform = platform?('fedora') ? 'fedora' : 'rhel' - release = platform?('amazon') ? '6' : '$releasever' - "#{platform}-#{release}-$basearch" - end - - # On Amazon use the RHEL 6 packages. Otherwise use the releasever yum variable - def yum_releasever - platform?('amazon') ? '6' : '$releasever' - end - - # Fedora doesn't seem to know the right symbols for psql - def psql_environment - return {} unless platform?('fedora') - { LD_LIBRARY_PATH: '/usr/lib64' } - end - - # Generate a password if the value is set to generate. - def postgres_password(new_resource) - new_resource.password == 'generate' ? secure_random : new_resource.password - end - end -end diff --git a/cookbooks/postgresql/metadata.json b/cookbooks/postgresql/metadata.json deleted file mode 100644 index 74f89dd..0000000 --- a/cookbooks/postgresql/metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"postgresql","version":"7.1.8","description":"Installs and configures postgresql for clients or servers","long_description":"","maintainer":"Sous Chefs","maintainer_email":"help@sous-chefs.org","license":"Apache-2.0","platforms":{"ubuntu":">= 0.0.0","debian":">= 0.0.0","fedora":">= 0.0.0","amazon":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","scientific":">= 0.0.0","oracle":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/sous-chefs/postgresql","issues_url":"https://github.com/sous-chefs/postgresql/issues","chef_version":[[">= 13.8"]],"ohai_version":[]} \ No newline at end of file diff --git a/cookbooks/postgresql/metadata.rb b/cookbooks/postgresql/metadata.rb deleted file mode 100644 index b4b193b..0000000 --- a/cookbooks/postgresql/metadata.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true -name 'postgresql' -maintainer 'Sous Chefs' -maintainer_email 'help@sous-chefs.org' -license 'Apache-2.0' -description 'Installs and configures postgresql for clients or servers' -version '7.1.8' -source_url 'https://github.com/sous-chefs/postgresql' -issues_url 'https://github.com/sous-chefs/postgresql/issues' -chef_version '>= 13.8' - -%w(ubuntu debian fedora amazon redhat centos scientific oracle).each do |os| - supports os -end diff --git a/cookbooks/postgresql/resources/access.rb b/cookbooks/postgresql/resources/access.rb deleted file mode 100644 index 8c5ba63..0000000 --- a/cookbooks/postgresql/resources/access.rb +++ /dev/null @@ -1,59 +0,0 @@ -# frozen_string_literal: true -# -# Cookbook:: postgresql -# Resource:: access -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -property :access_type, String, default: 'local' -property :access_db, String, default: 'all' -property :access_user, String, default: 'postgres' -property :access_method, String, default: 'ident' -property :cookbook, String, default: 'postgresql' -property :source, String, default: 'pg_hba.conf.erb' -property :access_addr, String -property :comment, String - -action :grant do - config_resource = new_resource - with_run_context :root do # ~FC037 - edit_resource(:template, "#{conf_dir}/pg_hba.conf") do |new_resource| - source new_resource.source - cookbook new_resource.cookbook - owner 'postgres' - group 'postgres' - mode '0600' - variables[:pg_hba] ||= {} - variables[:pg_hba][new_resource.name] = { - comment: new_resource.comment, - type: new_resource.access_type, - db: new_resource.access_db, - user: new_resource.access_user, - addr: new_resource.access_addr, - method: new_resource.access_method, - } - action :nothing - delayed_action :create - notifies :trigger, config_resource, :immediately - end - end -end - -action :trigger do - new_resource.updated_by_last_action(true) # ~FC085 -end - -action_class do - include PostgresqlCookbook::Helpers -end diff --git a/cookbooks/postgresql/resources/client_install.rb b/cookbooks/postgresql/resources/client_install.rb deleted file mode 100644 index 2698d00..0000000 --- a/cookbooks/postgresql/resources/client_install.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true -# -# Cookbook:: postgresql -# Resource:: client_install -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -property :version, String, default: '9.6' -property :setup_repo, [true, false], default: true - -action :install do - postgresql_repository 'Add downloads.postgresql.org repository' do - version new_resource.version - only_if { new_resource.setup_repo } - end - - case node['platform_family'] - when 'debian' - package "postgresql-client-#{new_resource.version}" - when 'rhel', 'fedora', 'amazon' - ver = new_resource.version.delete('.') - package "postgresql#{ver}" - end -end diff --git a/cookbooks/postgresql/resources/database.rb b/cookbooks/postgresql/resources/database.rb deleted file mode 100644 index f4f0377..0000000 --- a/cookbooks/postgresql/resources/database.rb +++ /dev/null @@ -1,67 +0,0 @@ -# -# Cookbook:: postgresql -# Resource:: database -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -property :template, String, default: 'template1' -property :encoding, String, default: 'UTF-8' -property :locale, String, default: 'en_US.UTF-8' -property :owner, String - -# Connection prefernces -property :user, String, default: 'postgres' -property :database, String, name_property: true -property :host, String -property :port, Integer, default: 5432 - -action :create do - createdb = 'createdb' - createdb << " -E #{new_resource.encoding}" if new_resource.encoding - createdb << " -l #{new_resource.locale}" if new_resource.locale - createdb << " -T #{new_resource.template}" unless new_resource.template.empty? - createdb << " -O #{new_resource.owner}" if new_resource.owner - createdb << " -U #{new_resource.user}" if new_resource.user - createdb << " -h #{new_resource.host}" if new_resource.host - createdb << " -p #{new_resource.port}" if new_resource.port - createdb << " #{new_resource.database}" - - bash "Create Database #{new_resource.database}" do - code createdb - user new_resource.user - not_if { follower? } - not_if { database_exists?(new_resource) } - end -end - -action :drop do - converge_by "Drop PostgreSQL Database #{new_resource.database}" do - dropdb = 'dropdb' - dropdb << " -U #{new_resource.user}" if new_resource.user - dropdb << " --host #{new_resource.host}" if new_resource.host - dropdb << " --port #{new_resource.port}" if new_resource.port - dropdb << " #{new_resource.database}" - - bash "drop postgresql database #{new_resource.database})" do - user 'postgres' - code dropdb - not_if { follower? } - only_if { database_exists?(new_resource) } - end - end -end - -action_class do - include PostgresqlCookbook::Helpers -end diff --git a/cookbooks/postgresql/resources/extension.rb b/cookbooks/postgresql/resources/extension.rb deleted file mode 100644 index f8987b6..0000000 --- a/cookbooks/postgresql/resources/extension.rb +++ /dev/null @@ -1,51 +0,0 @@ -# -# Cookbook:: postgresql -# Resource:: extension -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -property :extension, String, name_property: true -property :old_version, String -property :version, String - -# Connection prefernces -property :user, String, default: 'postgres' -property :database, String, required: true -property :host, [String, nil] -property :port, Integer, default: 5432 - -action :create do - bash "CREATE EXTENSION #{new_resource.name}" do - code create_extension_sql(new_resource) - user 'postgres' - action :run - environment(psql_environment) - not_if { follower? || extension_installed?(new_resource) } - end -end - -action :drop do - bash "DROP EXTENSION #{new_resource.name}" do - code psql_command_string(new_resource, "DROP EXTENSION IF EXISTS \"#{new_resource.extension}\"") - user 'postgres' - action :run - environment(psql_environment) - not_if { follower? } - only_if { extension_installed?(new_resource) } - end -end - -action_class do - include PostgresqlCookbook::Helpers -end diff --git a/cookbooks/postgresql/resources/ident.rb b/cookbooks/postgresql/resources/ident.rb deleted file mode 100644 index 52fdec3..0000000 --- a/cookbooks/postgresql/resources/ident.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true -# -# Cookbook:: postgresql -# Resource:: access -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -property :mapname, String, required: true -property :source, String, default: 'pg_ident.conf.erb' -property :cookbook, String, default: 'postgresql' -property :system_user, String, required: true -property :pg_user, String, required: true -property :comment, String - -action :create do - ident_resource = new_resource - with_run_context :root do - edit_resource(:template, "#{conf_dir}/pg_ident.conf") do |new_resource| - source new_resource.source - cookbook new_resource.cookbook - owner 'postgres' - group 'postgres' - mode '0640' - variables[:pg_ident] ||= {} - variables[:pg_ident][new_resource.name] = { - comment: new_resource.comment, - mapname: new_resource.mapname, - system_user: new_resource.system_user, - pg_user: new_resource.pg_user, - } - action :nothing - delayed_action :create - notifies :trigger, ident_resource, :immediately - end - end -end - -action :trigger do - new_resource.updated_by_last_action(true) # ~FC085 -end - -action_class do - include PostgresqlCookbook::Helpers -end diff --git a/cookbooks/postgresql/resources/repository.rb b/cookbooks/postgresql/resources/repository.rb deleted file mode 100644 index 7040c6b..0000000 --- a/cookbooks/postgresql/resources/repository.rb +++ /dev/null @@ -1,90 +0,0 @@ -# frozen_string_literal: true -# -# Cookbook:: postgresql -# Resource:: repository -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -property :version, String, default: '9.6' -property :enable_pgdg, [true, false], default: true -property :enable_pgdg_source, [true, false], default: false -property :enable_pgdg_updates_testing, [true, false], default: false -property :enable_pgdg_source_updates_testing, [true, false], default: false -property :yum_gpg_key_uri, String, default: 'https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG' -property :apt_gpg_key_uri, String, default: 'https://download.postgresql.org/pub/repos/apt/ACCC4CF8.asc' - -action :add do - case node['platform_family'] - - when 'rhel', 'fedora', 'amazon' - remote_file "/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-#{new_resource.version}" do - source new_resource.yum_gpg_key_uri - end - - yum_repository "PostgreSQL #{new_resource.version}" do # ~FC005 - repositoryid "pgdg#{new_resource.version}" - description "PostgreSQL.org #{new_resource.version}" - baseurl yum_repo_url('https://download.postgresql.org/pub/repos/yum') - enabled new_resource.enable_pgdg - gpgcheck true - gpgkey "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-#{new_resource.version}" - end - - yum_repository "PostgreSQL #{new_resource.version} - source " do - repositoryid "pgdg#{new_resource.version}-source" - description "PostgreSQL.org #{new_resource.version} Source" - baseurl yum_repo_url('https://download.postgresql.org/pub/repos/yum/srpms') - enabled new_resource.enable_pgdg_source - gpgcheck true - gpgkey "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-#{new_resource.version}" - end - - yum_repository "PostgreSQL #{new_resource.version} - updates testing" do - repositoryid "pgdg#{new_resource.version}-updates-testing" - description "PostgreSQL.org #{new_resource.version} Updates Testing" - baseurl yum_repo_url('https://download.postgresql.org/pub/repos/yum/testing') - enabled new_resource.enable_pgdg_updates_testing - gpgcheck true - gpgkey "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-#{new_resource.version}" - end - - yum_repository "PostgreSQL #{new_resource.version} - source - updates testing" do - repositoryid "pgdg#{new_resource.version}-source-updates-testing" - description "PostgreSQL.org #{new_resource.version} Source Updates Testing" - baseurl yum_repo_url('https://download.postgresql.org/pub/repos/yum/srpms/testing') - enabled new_resource.enable_pgdg_source_updates_testing - gpgcheck true - gpgkey "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-#{new_resource.version}" - end - - when 'debian' - apt_update - - package 'apt-transport-https' - - apt_repository 'postgresql_org_repository' do - uri 'https://download.postgresql.org/pub/repos/apt/' - components ['main', new_resource.version.to_s] - distribution "#{node['lsb']['codename']}-pgdg" - key new_resource.apt_gpg_key_uri - cache_rebuild true - end - else - raise "The platform_family '#{node['platform_family']}' or platform '#{node['platform']}' is not supported by the postgresql_repository resource. If you believe this platform can/should be supported by this resource please file and issue or open a pull request at https://github.com/sous-chefs/postgresql" - end -end - -action_class do - include PostgresqlCookbook::Helpers -end diff --git a/cookbooks/postgresql/resources/server_conf.rb b/cookbooks/postgresql/resources/server_conf.rb deleted file mode 100644 index 3c44c22..0000000 --- a/cookbooks/postgresql/resources/server_conf.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true -# -# Cookbook:: postgresql -# Resource:: server_conf -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -include PostgresqlCookbook::Helpers - -property :version, String, default: '9.6' -property :data_directory, String, default: lazy { data_dir } -property :hba_file, String, default: lazy { "#{conf_dir}/pg_hba.conf" } -property :ident_file, String, default: lazy { "#{conf_dir}/pg_ident.conf" } -property :external_pid_file, String, default: lazy { "/var/run/postgresql/#{version}-main.pid" } -property :stats_temp_directory, String, default: lazy { "/var/run/postgresql/#{version}-main.pg_stat_tmp" } -property :port, Integer, default: 5432 -property :additional_config, Hash, default: {} -property :cookbook, String, default: 'postgresql' - -action :modify do - template "#{conf_dir}/postgresql.conf" do - cookbook new_resource.cookbook - source 'postgresql.conf.erb' - owner 'postgres' - group 'postgres' - mode '0644' - variables( - data_dir: new_resource.data_directory, - hba_file: new_resource.hba_file, - ident_file: new_resource.ident_file, - external_pid_file: new_resource.external_pid_file, - stats_temp_directory: new_resource.stats_temp_directory, - port: new_resource.port, - additional_config: new_resource.additional_config - ) - end -end - -action_class do - include PostgresqlCookbook::Helpers -end diff --git a/cookbooks/postgresql/resources/server_install.rb b/cookbooks/postgresql/resources/server_install.rb deleted file mode 100644 index 290713b..0000000 --- a/cookbooks/postgresql/resources/server_install.rb +++ /dev/null @@ -1,93 +0,0 @@ -# -# Cookbook:: postgresql -# Resource:: server_install -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -include PostgresqlCookbook::Helpers - -property :version, String, default: '9.6' -property :setup_repo, [true, false], default: true -property :hba_file, String, default: lazy { "#{conf_dir}/main/pg_hba.conf" } -property :ident_file, String, default: lazy { "#{conf_dir}/main/pg_ident.conf" } -property :external_pid_file, String, default: lazy { "/var/run/postgresql/#{version}-main.pid" } -property :password, [String, nil], default: 'generate' # Set to nil if we do not want to set a password -property :port, Integer, default: 5432 -property :initdb_locale, String -property :initdb_encoding, String - -# Connection preferences -property :user, String, default: 'postgres' -property :database, String -property :host, [String, nil] - -action :install do - node.run_state['postgresql'] ||= {} - node.run_state['postgresql']['version'] = new_resource.version - - postgresql_client_install 'Install PostgreSQL Client' do - version new_resource.version - setup_repo new_resource.setup_repo - end - - # First install the postgresql-common package - if platform_family?('debian') - package 'postgresql-common' - - initdb_options = '' - initdb_options << "--locale #{new_resource.initdb_locale}" if new_resource.initdb_locale - initdb_options << " -E #{new_resource.initdb_encoding}" if new_resource.initdb_encoding - - template '/etc/postgresql-common/createcluster.conf' do - source 'createcluster.conf.erb' - cookbook 'postgresql' - variables( - initdb_options: initdb_options - ) - end - end - - package server_pkg_name -end - -action :create do - execute 'init_db' do - command rhel_init_db_command(new_resource) - user new_resource.user - not_if { initialized? } - only_if { platform_family?('rhel', 'fedora', 'amazon') } - end - - # We use to use find_resource here. - # But that required the user to do the same in their recipe. - # This also seemed to never trigger notifications, therefore requiring a log resource - # to notify the enable/start on the service, which always fires (Check v7.0 tag for more) - service 'postgresql' do - service_name platform_service_name - supports restart: true, status: true, reload: true - action [:enable, :start] - end - - # Generate a random password or set it as per new_resource.password. - bash 'generate-postgres-password' do - user 'postgres' - code alter_role_sql(new_resource) - not_if { user_has_password?(new_resource) } - not_if { new_resource.password.nil? } - end -end - -action_class do - include PostgresqlCookbook::Helpers -end diff --git a/cookbooks/postgresql/resources/user.rb b/cookbooks/postgresql/resources/user.rb deleted file mode 100644 index 17b8b18..0000000 --- a/cookbooks/postgresql/resources/user.rb +++ /dev/null @@ -1,91 +0,0 @@ -# -# Cookbook:: postgresql -# Resource:: user -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -property :create_user, String, name_property: true -property :superuser, [true, false], default: false -property :createdb, [true, false], default: false -property :createrole, [true, false], default: false -property :inherit, [true, false], default: true -property :replication, [true, false], default: false -property :login, [true, false], default: true -property :password, String -property :encrypted_password, String -property :valid_until, String -property :attributes, Hash, default: {} - -# Connection prefernces -property :user, String, default: 'postgres' -property :database, String -property :host, String -property :port, Integer, default: 5432 - -action :create do - Chef::Log.warn('You cannot use "attributes" property with create action.') unless new_resource.attributes.empty? - - execute "create postgresql user #{new_resource.create_user}" do # ~FC009 - user 'postgres' - command create_user_sql(new_resource) - sensitive new_resource.sensitive - environment(psql_environment) - not_if { follower? || user_exists?(new_resource) } - end -end - -action :update do - if new_resource.attributes.empty? - execute "update postgresql user #{new_resource.create_user}" do - user 'postgres' - command update_user_sql(new_resource) - environment(psql_environment) - sensitive true - not_if { follower? } - only_if { user_exists?(new_resource) } - end - else - new_resource.attributes.each do |attr, value| - v = if value.is_a?(TrueClass) || value.is_a?(FalseClass) - value.to_s - else - "'#{value}'" - end - - execute "Update postgresql user #{new_resource.create_user} to set #{attr}" do - user 'postgres' - command update_user_with_attributes_sql(new_resource, v) - environment(psql_environment) - sensitive true - not_if { follower? } - only_if { user_exists?(new_resource) } - end - end - end -end - -action :drop do - execute "drop postgresql user #{new_resource.create_user}" do - user 'postgres' - command drop_user_sql(new_resource) - environment(psql_environment) - sensitive true - not_if { follower? } - only_if { user_exists?(new_resource) } - end -end - -action_class do - include PostgresqlCookbook::Helpers -end diff --git a/cookbooks/postgresql/templates/createcluster.conf.erb b/cookbooks/postgresql/templates/createcluster.conf.erb deleted file mode 100644 index b85e2b5..0000000 --- a/cookbooks/postgresql/templates/createcluster.conf.erb +++ /dev/null @@ -1,41 +0,0 @@ -# Default values for pg_createcluster(8) -# Occurrences of '%v' are replaced by the major version number, -# and '%c' by the cluster name. Use '%%' for a literal '%'. - -# Create a "main" cluster when a new postgresql-x.y server package is installed -#create_main_cluster = true - -# Default start.conf value, must be one of "auto", "manual", and "disabled". -# See pg_createcluster(8) for more documentation. -#start_conf = 'auto' - -# Default data directory. -#data_directory = '/var/lib/postgresql/%v/%c' - -# Default directory for transaction logs -# Unset by default, i.e. transaction logs remain in the data directory. -#waldir = '/var/lib/postgresql/wal/%v/%c/pg_wal' - -# Options to pass to initdb. -initdb_options = '<%= @initdb_options %>' - -# The following options are copied into the new cluster's postgresql.conf: - -# Enable SSL by default (using the "snakeoil" certificates installed by the -# ssl-cert package, unless configured otherwise here) -ssl = on - -# Show cluster name in process title -cluster_name = '%v/%c' - -# Put stats_temp_directory on tmpfs -stats_temp_directory = '/var/run/postgresql/%v-%c.pg_stat_tmp' - -# Add prefix to log lines -log_line_prefix = '%%m [%%p] %%q%%u@%%d ' - -# Add "include_dir" in postgresql.conf -add_include_dir = 'conf.d' - -# Directory for additional createcluster config -include_dir '/etc/postgresql-common/createcluster.d' diff --git a/cookbooks/postgresql/templates/pg_hba.conf.erb b/cookbooks/postgresql/templates/pg_hba.conf.erb deleted file mode 100644 index 9eab8a9..0000000 --- a/cookbooks/postgresql/templates/pg_hba.conf.erb +++ /dev/null @@ -1,33 +0,0 @@ -# This file was automatically generated and dropped off by Chef! - -# PostgreSQL Client Authentication Configuration File -# =================================================== -# -# Refer to the "Client Authentication" section in the PostgreSQL -# documentation for a complete description of this file. - -local all postgres peer - -# TYPE DATABASE USER ADDRESS METHOD - -# "local" is for Unix domain socket connections only -local all all peer -# IPv4 local connections: -host all all 127.0.0.1/32 md5 -# IPv6 local connections: -host all all ::1/128 md5 - -########### -# From the postgresql_access resources -########### -<% @pg_hba.each do |k,v| -%> -# <%= k %> -<% if v[:comment] -%> -# <%= v[:comment] %> -<% end -%> -<% if v[:addr] %> -<%= v[:type].ljust(7) %> <%= v[:db].ljust(15) %> <%= v[:user].ljust(15) %> <%= v[:addr].ljust(23) %> <%= v[:method] %> -<% else %> -<%= v[:type].ljust(7) %> <%= v[:db].ljust(15) %> <%= v[:user].ljust(15) %> <%= v[:method] %> -<% end %> -<% end %> diff --git a/cookbooks/postgresql/templates/pg_ident.conf.erb b/cookbooks/postgresql/templates/pg_ident.conf.erb deleted file mode 100644 index f3ba499..0000000 --- a/cookbooks/postgresql/templates/pg_ident.conf.erb +++ /dev/null @@ -1,49 +0,0 @@ -# PostgreSQL User Name Maps -# ========================= -# -# Refer to the PostgreSQL documentation, chapter "Client -# Authentication" for a complete description. A short synopsis -# follows. -# -# This file controls PostgreSQL user name mapping. It maps external -# user names to their corresponding PostgreSQL user names. Records -# are of the form: -# -# MAPNAME SYSTEM-USERNAME PG-USERNAME -# -# (The uppercase quantities must be replaced by actual values.) -# -# MAPNAME is the (otherwise freely chosen) map name that was used in -# pg_hba.conf. SYSTEM-USERNAME is the detected user name of the -# client. PG-USERNAME is the requested PostgreSQL user name. The -# existence of a record specifies that SYSTEM-USERNAME may connect as -# PG-USERNAME. -# -# If SYSTEM-USERNAME starts with a slash (/), it will be treated as a -# regular expression. Optionally this can contain a capture (a -# parenthesized subexpression). The substring matching the capture -# will be substituted for \1 (backslash-one) if present in -# PG-USERNAME. -# -# Multiple maps may be specified in this file and used by pg_hba.conf. -# -# No map names are defined in the default configuration. If all -# system user names and PostgreSQL user names are the same, you don't -# need anything in this file. -# -# This file is read on server startup and when the postmaster receives -# a SIGHUP signal. If you edit the file on a running system, you have -# to SIGHUP the postmaster for the changes to take effect. You can -# use "pg_ctl reload" to do that. - -# Put your actual configuration here -# ---------------------------------- - -# MAPNAME SYSTEM-USERNAME PG-USERNAME -<% @pg_ident.each do |k,v| -%> - <% if v[:comment] -%> - -# <%= v[:comment] %> - <% end -%> -<%= v[:mapname].ljust(15) %> <%= v[:system_user].ljust(23) %> <%= v[:pg_user].ljust(15) %> -<% end %> diff --git a/cookbooks/postgresql/templates/pgsql.sysconfig.erb b/cookbooks/postgresql/templates/pgsql.sysconfig.erb deleted file mode 100644 index 2740356..0000000 --- a/cookbooks/postgresql/templates/pgsql.sysconfig.erb +++ /dev/null @@ -1,2 +0,0 @@ -PGDATA=<%= @postgresql_dir %> -PGPORT=<%= @port %> diff --git a/cookbooks/postgresql/templates/postgresql.conf.erb b/cookbooks/postgresql/templates/postgresql.conf.erb deleted file mode 100644 index 7656770..0000000 --- a/cookbooks/postgresql/templates/postgresql.conf.erb +++ /dev/null @@ -1,26 +0,0 @@ -# PostgreSQL configuration file -# This file was automatically generated and dropped off by chef! -# Please refer to the PostgreSQL documentation for details on -# configuration settings. - -data_directory = '<%= @data_dir %>' -hba_file = '<%= @hba_file %>' -ident_file = '<%= @ident_file %>' -external_pid_file = '<%= @external_pid_file %>' -stats_temp_directory = '<%= @stats_temp_directory %>' -port = <%= @port %> -<% @additional_config.sort.each do |key, value| %> -<% next if value.nil? -%> -<%= key %> = <%= - case value - when String - "'#{value}'" - when TrueClass - 'on' - when FalseClass - 'off' - else - value - end -%> -<% end %> diff --git a/cookbooks/postgresql/templates/postgresql.service.erb b/cookbooks/postgresql/templates/postgresql.service.erb deleted file mode 100644 index 688e7d5..0000000 --- a/cookbooks/postgresql/templates/postgresql.service.erb +++ /dev/null @@ -1,6 +0,0 @@ -[Service] -.include /usr/lib/systemd/system/<%= @svc_name %>.service - -Environment= -Environment=PGPORT=<%= @port %> -Environment=PGDATA=<%= @data_dir %> diff --git a/site-cookbooks/postgresql b/site-cookbooks/postgresql new file mode 160000 index 0000000..bf68433 --- /dev/null +++ b/site-cookbooks/postgresql @@ -0,0 +1 @@ +Subproject commit bf68433d82f12fc41bd9a0e3e2ba177282012833 From 501626de1f9e1879ed04458e5eb0d11d9539bb12 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 7 Jun 2020 12:30:00 +0200 Subject: [PATCH 057/327] Add encfs to Vagrantfile --- Vagrantfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index 3cf15c5..cc353fa 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -94,7 +94,8 @@ Vagrant.configure(2) do |config| chef.encrypted_data_bag_secret_key_path = '.chef/encrypted_data_bag_secret' chef.environment = 'development' chef.add_recipe 'kosmos-base' - # chef.add_recipe 'kosmos-mediawiki' + chef.add_recipe 'kosmos_encfs' + # chef.add_recipe 'kosmos-postgresql::default' # chef.add_recipe 'kosmos-wordpress' # chef.add_recipe 'kosmos-ejabberd' # chef.add_recipe 'kosmos-hubot::botka_freenode' From 8918452fc56652efd3a3451af16d83129028c1f8 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 7 Jun 2020 12:40:39 +0200 Subject: [PATCH 058/327] Use latest postgresql fork --- site-cookbooks/postgresql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/postgresql b/site-cookbooks/postgresql index bf68433..9389178 160000 --- a/site-cookbooks/postgresql +++ b/site-cookbooks/postgresql @@ -1 +1 @@ -Subproject commit bf68433d82f12fc41bd9a0e3e2ba177282012833 +Subproject commit 9389178e116528ad22b1d05e93ca93c2a485c727 From 353f2c13f11c8cf096885803dc7190546df30a9d Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 7 Jun 2020 12:45:33 +0200 Subject: [PATCH 059/327] Improve encfs cookbook Fix some things, and prepare for path-based activation. Also, comment the buggy initial dir creation and explain manual provisioning in README for now. --- site-cookbooks/kosmos_encfs/README.md | 14 +++++++- .../kosmos_encfs/files/encfs.service | 4 +-- .../kosmos_encfs/recipes/default.rb | 35 ++++++++++++------- .../kosmos_encfs/templates/mount_encfs.erb | 1 + .../templates/systemd_unit.path.erb | 9 +++++ .../kosmos_encfs/templates/unmount_encfs.erb | 4 +++ 6 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 site-cookbooks/kosmos_encfs/templates/systemd_unit.path.erb create mode 100644 site-cookbooks/kosmos_encfs/templates/unmount_encfs.erb diff --git a/site-cookbooks/kosmos_encfs/README.md b/site-cookbooks/kosmos_encfs/README.md index 821ae83..5c5ed8e 100644 --- a/site-cookbooks/kosmos_encfs/README.md +++ b/site-cookbooks/kosmos_encfs/README.md @@ -1,3 +1,15 @@ # kosmos_encfs -Install encfs and set up encryption for a data directory +Install encfs and set up encryption for a data directory. + +## Provisioning a new machine + +Add encfs to the run list and run chef before adding other cookbooks that +depends on the encfs mount. + +Log into the system and create the data directory like so: + + encfs /usr/local/lib/encrypted_data /mnt/data --public + +When asked for config options, choose nothing (i.e. "standard"). Do NOT choose +paranoia mode, as it breaks some software, like e.g. PostgreSQL. diff --git a/site-cookbooks/kosmos_encfs/files/encfs.service b/site-cookbooks/kosmos_encfs/files/encfs.service index f0f8da9..12eed81 100644 --- a/site-cookbooks/kosmos_encfs/files/encfs.service +++ b/site-cookbooks/kosmos_encfs/files/encfs.service @@ -1,11 +1,9 @@ [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 +ExecStop=/usr/local/bin/unmount_encfs [Install] WantedBy=multi-user.target diff --git a/site-cookbooks/kosmos_encfs/recipes/default.rb b/site-cookbooks/kosmos_encfs/recipes/default.rb index 05ce02a..ce4832f 100644 --- a/site-cookbooks/kosmos_encfs/recipes/default.rb +++ b/site-cookbooks/kosmos_encfs/recipes/default.rb @@ -35,11 +35,17 @@ mount_directory = "/mnt/data" template "/usr/local/bin/mount_encfs" do source "mount_encfs.erb" - mode "0700" + mode "0755" variables encrypted_directory: encrypted_directory, mount_directory: mount_directory end +template "/usr/local/bin/unmount_encfs" do + source "unmount_encfs.erb" + mode "0700" + variables mount_directory: mount_directory +end + execute "systemctl daemon-reload" do command "systemctl daemon-reload" action :nothing @@ -50,19 +56,22 @@ directory mount_directory do 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 +# FIXME the password that is stored using this script does not match the actual password +# execute "create encrypted file system" do +# command <<-EOF +# echo "y\\\n +# y\\\n +# FIXME paranoia mode breaks hard links, which postgres relies on +# 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 +# FIXME there seems to be half a comment missing here # The service will automatically cookbook_file "/lib/systemd/system/encfs.service" do source "encfs.service" diff --git a/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb b/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb index 74e1221..d669e34 100644 --- a/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb +++ b/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb @@ -1,3 +1,4 @@ #!/bin/sh systemd-ask-password --echo "encfs password:" | encfs <%= @encrypted_directory %> <%= @mount_directory %> --public --stdinpass +echo "Encrypted data directory mounted as <%= @mount_directory %>" > /tmp/data-dir-mounted.txt diff --git a/site-cookbooks/kosmos_encfs/templates/systemd_unit.path.erb b/site-cookbooks/kosmos_encfs/templates/systemd_unit.path.erb new file mode 100644 index 0000000..c559ac0 --- /dev/null +++ b/site-cookbooks/kosmos_encfs/templates/systemd_unit.path.erb @@ -0,0 +1,9 @@ +[Unit] +Description=Start <%= @service_unit %> when encrypted data directory is mounted + +[Path] +PathExists=/tmp/data-dir-mounted.txt +Unit=<%= @service_unit %> + +[Install] +WantedBy=multi-user.target diff --git a/site-cookbooks/kosmos_encfs/templates/unmount_encfs.erb b/site-cookbooks/kosmos_encfs/templates/unmount_encfs.erb new file mode 100644 index 0000000..02690a7 --- /dev/null +++ b/site-cookbooks/kosmos_encfs/templates/unmount_encfs.erb @@ -0,0 +1,4 @@ +#!/bin/sh + +rm /tmp/data-dir-mounted.txt +/bin/umount <%= @mount_directory %> From 379161eb1e543b4e73c67f597435d84bd755aa98 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 7 Jun 2020 12:47:06 +0200 Subject: [PATCH 060/327] Fix postgres installation Also, do not start at boot anymore, in favor of path-based activation. --- .../kosmos-postgresql/recipes/default.rb | 10 ++++---- .../kosmos-postgresql/resources/server.rb | 23 +++++++++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb index 7841577..fd635df 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/default.rb @@ -27,13 +27,13 @@ postgresql_version = "12" postgresql_service = "postgresql@#{postgresql_version}-main" -postgresql_custom_server postgresql_version do - role "primary" +# TODO check if still necessary +user "postgres" do + manage_home false end -service postgresql_service do - supports restart: true, status: true, reload: true - action [:enable] +postgresql_custom_server postgresql_version do + role "primary" end # This will only be run once, if the /var/lib/postgresql/10/main directory diff --git a/site-cookbooks/kosmos-postgresql/resources/server.rb b/site-cookbooks/kosmos-postgresql/resources/server.rb index 652a0ee..7163a5d 100644 --- a/site-cookbooks/kosmos-postgresql/resources/server.rb +++ b/site-cookbooks/kosmos-postgresql/resources/server.rb @@ -11,12 +11,15 @@ action :create do node.override['build-essential']['compile_time'] = true include_recipe 'build-essential::default' - directory postgresql_data_dir do + # TODO should likely go in the encfs cookbook somewhere + directory "/mnt/data" do + mode "0755" + end + + directory "/mnt/data/postgresql" do owner "postgres" group "postgres" mode "0750" - recursive true - action :create end package("libpq-dev") { action :nothing }.run_action(:install) @@ -31,18 +34,19 @@ action :create do version postgresql_version setup_repo true password postgresql_data_bag_item['server_password'] + data_directory postgresql_data_dir action :install end service postgresql_service do supports restart: true, status: true, reload: true - # action [:enable, :start] + action :start end - postgresql_client_install "main" do - version postgresql_version - setup_repo true - action :install + # This service is a dependency that will auto-start our cluster service on + # boot if it's enabled, so we disable it explicitly + service "postgresql" do + action :disable end shared_buffers = if node['memory']['total'].to_i / 1024 < 1024 # > 1GB RAM @@ -95,7 +99,7 @@ action :create do postgresql_server_conf "main" do version postgresql_version additional_config additional_config - notifies :reload, "service[#{postgresql_service}]" + notifies :reload, "service[#{postgresql_service}]", :delayed end postgresql_user "replication" do @@ -103,7 +107,6 @@ action :create do replication true password postgresql_data_bag_item['replication_password'] end - end action_class do From b662c041839731fd0873745c7ccec29b3f1f0131 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 8 Jun 2020 17:01:24 +0200 Subject: [PATCH 061/327] Finish initial encfs cookbook and postgres adaptations --- site-cookbooks/kosmos-postgresql/metadata.rb | 1 + .../kosmos-postgresql/recipes/default.rb | 5 ----- .../kosmos-postgresql/resources/server.rb | 13 +++++++----- .../kosmos_encfs/attributes/default.rb | 1 + .../kosmos_encfs/recipes/default.rb | 4 ++-- .../resources/encfs_path_activation_unit.rb | 21 +++++++++++++++++++ .../kosmos_encfs/templates/mount_encfs.erb | 1 + .../templates/systemd_unit.path.erb | 9 -------- 8 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 site-cookbooks/kosmos_encfs/attributes/default.rb create mode 100644 site-cookbooks/kosmos_encfs/resources/encfs_path_activation_unit.rb delete mode 100644 site-cookbooks/kosmos_encfs/templates/systemd_unit.path.erb diff --git a/site-cookbooks/kosmos-postgresql/metadata.rb b/site-cookbooks/kosmos-postgresql/metadata.rb index c153631..29416f2 100644 --- a/site-cookbooks/kosmos-postgresql/metadata.rb +++ b/site-cookbooks/kosmos-postgresql/metadata.rb @@ -21,3 +21,4 @@ chef_version '>= 12.14' if respond_to?(:chef_version) depends "postgresql", ">= 7.0.0" depends "build-essential" +depends "kosmos_encfs" diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb index fd635df..53ec336 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/default.rb @@ -27,11 +27,6 @@ postgresql_version = "12" postgresql_service = "postgresql@#{postgresql_version}-main" -# TODO check if still necessary -user "postgres" do - manage_home false -end - postgresql_custom_server postgresql_version do role "primary" end diff --git a/site-cookbooks/kosmos-postgresql/resources/server.rb b/site-cookbooks/kosmos-postgresql/resources/server.rb index 7163a5d..ba61142 100644 --- a/site-cookbooks/kosmos-postgresql/resources/server.rb +++ b/site-cookbooks/kosmos-postgresql/resources/server.rb @@ -4,19 +4,19 @@ property :postgresql_version, String, required: true, name_property: true property :role, String, required: true # Can be primary or replica action :create do + encfs_data_dir = node["kosmos_encfs"]["data_directory"] postgresql_version = new_resource.postgresql_version - postgresql_data_dir = "/mnt/data/postgresql/#{postgresql_version}/main" + postgresql_data_dir = "#{encfs_data_dir}/postgresql/#{postgresql_version}/main" postgresql_service = "postgresql@#{postgresql_version}-main" node.override['build-essential']['compile_time'] = true include_recipe 'build-essential::default' - # TODO should likely go in the encfs cookbook somewhere - directory "/mnt/data" do - mode "0755" + user "postgres" do + manage_home false end - directory "/mnt/data/postgresql" do + directory "#{encfs_data_dir}/postgresql" do owner "postgres" group "postgres" mode "0750" @@ -43,6 +43,9 @@ action :create do action :start end + # Activates the postgres service when encrypted data dir is mounted + encfs_path_activation_unit postgresql_service + # This service is a dependency that will auto-start our cluster service on # boot if it's enabled, so we disable it explicitly service "postgresql" do diff --git a/site-cookbooks/kosmos_encfs/attributes/default.rb b/site-cookbooks/kosmos_encfs/attributes/default.rb new file mode 100644 index 0000000..98a918b --- /dev/null +++ b/site-cookbooks/kosmos_encfs/attributes/default.rb @@ -0,0 +1 @@ +node.default["kosmos_encfs"]["data_directory"] = "/mnt/data" diff --git a/site-cookbooks/kosmos_encfs/recipes/default.rb b/site-cookbooks/kosmos_encfs/recipes/default.rb index ce4832f..91351fb 100644 --- a/site-cookbooks/kosmos_encfs/recipes/default.rb +++ b/site-cookbooks/kosmos_encfs/recipes/default.rb @@ -31,7 +31,7 @@ encfs_password = encfs_data_bag_item["password"] package "encfs" encrypted_directory = "/usr/local/lib/encrypted_data" -mount_directory = "/mnt/data" +mount_directory = node["kosmos_encfs"]["data_directory"] template "/usr/local/bin/mount_encfs" do source "mount_encfs.erb" @@ -53,7 +53,7 @@ end directory mount_directory do action :create - mode "0775" + mode "0755" end # FIXME the password that is stored using this script does not match the actual password diff --git a/site-cookbooks/kosmos_encfs/resources/encfs_path_activation_unit.rb b/site-cookbooks/kosmos_encfs/resources/encfs_path_activation_unit.rb new file mode 100644 index 0000000..f8e3cfd --- /dev/null +++ b/site-cookbooks/kosmos_encfs/resources/encfs_path_activation_unit.rb @@ -0,0 +1,21 @@ +resource_name :encfs_path_activation_unit + +property :service_name, String, required: true, name_property: true + +action :create do + systemd_unit "#{new_resource.service_name}.path" do + content <<-EOF +[Unit] +Description=Start #{new_resource.service_name} when encrypted data directory is mounted + +[Path] +PathExists=/tmp/data-dir-mounted.txt +Unit=#{new_resource.service_name} + +[Install] +WantedBy=multi-user.target + EOF + triggers_reload true + action [:create, :enable, :start] + end +end diff --git a/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb b/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb index d669e34..e5a1c02 100644 --- a/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb +++ b/site-cookbooks/kosmos_encfs/templates/mount_encfs.erb @@ -1,4 +1,5 @@ #!/bin/sh systemd-ask-password --echo "encfs password:" | encfs <%= @encrypted_directory %> <%= @mount_directory %> --public --stdinpass +/bin/chmod go+rx <%= @mount_directory %> echo "Encrypted data directory mounted as <%= @mount_directory %>" > /tmp/data-dir-mounted.txt diff --git a/site-cookbooks/kosmos_encfs/templates/systemd_unit.path.erb b/site-cookbooks/kosmos_encfs/templates/systemd_unit.path.erb deleted file mode 100644 index c559ac0..0000000 --- a/site-cookbooks/kosmos_encfs/templates/systemd_unit.path.erb +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Start <%= @service_unit %> when encrypted data directory is mounted - -[Path] -PathExists=/tmp/data-dir-mounted.txt -Unit=<%= @service_unit %> - -[Install] -WantedBy=multi-user.target From 229e9cfbd22be1ba2860186f02229f1f5bd1edbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 10 Jun 2020 14:40:01 +0200 Subject: [PATCH 062/327] Add the kosmos_encfs recipe to centaurus --- nodes/centaurus.kosmos.org.json | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/nodes/centaurus.kosmos.org.json b/nodes/centaurus.kosmos.org.json index abd2780..777e9cd 100644 --- a/nodes/centaurus.kosmos.org.json +++ b/nodes/centaurus.kosmos.org.json @@ -12,16 +12,18 @@ "hostname": "centaurus", "ipaddress": "78.46.59.98", "roles": [ - "postgresql_replica", - "gitea" + "gitea", + "postgresql_replica" ], "recipes": [ "kosmos-base", "kosmos-base::default", - "kosmos-postgresql::replica", + "kosmos_encfs", + "kosmos_encfs::default", "kosmos_gitea", "kosmos_gitea::default", "kosmos_gitea::backup", + "kosmos-postgresql::replica", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -35,8 +37,6 @@ "postfix::_attributes", "postfix::sasl_auth", "hostname::default", - "firewall::default", - "chef-sugar::default", "kosmos-nginx::default", "nginx::default", "nginx::package", @@ -46,10 +46,12 @@ "nginx::commons_dir", "nginx::commons_script", "nginx::commons_conf", + "firewall::default", + "chef-sugar::default", "backup::default", "logrotate::default", - "build-essential::default", - "kosmos-base::letsencrypt" + "kosmos-base::letsencrypt", + "build-essential::default" ], "platform": "ubuntu", "platform_version": "18.04", @@ -67,7 +69,8 @@ }, "run_list": [ "recipe[kosmos-base]", - "role[postgresql_replica]", - "role[gitea]" + "recipe[kosmos_encfs]", + "role[gitea]", + "role[postgresql_replica]" ] } \ No newline at end of file From dba662986941735f1b3fb67f38b42a323bb3d421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 10 Jun 2020 14:40:16 +0200 Subject: [PATCH 063/327] Use the attribute from the encfs recipe for the data directory --- site-cookbooks/kosmos-postgresql/recipes/replica.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index 8a3f7d5..9c6102e 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -41,7 +41,7 @@ postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') primary = postgresql_primary unless primary.nil? - postgresql_data_dir = "/var/lib/postgresql/#{postgresql_version}/main" + postgresql_data_dir = "#{node["kosmos_encfs"]["data_directory"]}/postgresql/#{postgresql_version}/main" if node['kosmos-postgresql']['ready_to_set_up_replica'] execute "set up replication" do From e3e726097f105004f45a634467c57452e00f8dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 8 Jun 2020 18:38:32 +0200 Subject: [PATCH 064/327] Do not enable the postgresql@12-main service We want it to run only once the encrypted data directory has been mounted --- site-cookbooks/kosmos-postgresql/recipes/replica.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index 9c6102e..b063edf 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -33,7 +33,6 @@ end service postgresql_service do supports restart: true, status: true, reload: true - action [:enable] end postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') From a0db6adaf2141518d3529f499a3bd60404539af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Mon, 8 Jun 2020 18:39:05 +0200 Subject: [PATCH 065/327] Pass the data_directory to the postgresql_server_conf resource Previously we were passing it as an additional config, but it is set by default. The last value was used, the custom one, so the server still used the correct file --- site-cookbooks/kosmos-postgresql/resources/server.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-postgresql/resources/server.rb b/site-cookbooks/kosmos-postgresql/resources/server.rb index ba61142..b677c77 100644 --- a/site-cookbooks/kosmos-postgresql/resources/server.rb +++ b/site-cookbooks/kosmos-postgresql/resources/server.rb @@ -64,8 +64,7 @@ action :create do unix_socket_directories: "/var/run/postgresql", dynamic_shared_memory_type: "posix", timezone: "UTC", # default is GMT - listen_addresses: "0.0.0.0", - data_directory: postgresql_data_dir + listen_addresses: "0.0.0.0" } if new_resource.role == "replica" @@ -101,6 +100,7 @@ action :create do postgresql_server_conf "main" do version postgresql_version + data_directory postgresql_data_dir additional_config additional_config notifies :reload, "service[#{postgresql_service}]", :delayed end From 091a46e9728ed5594e6fa1025581532e52ae924d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 10 Jun 2020 18:37:36 +0200 Subject: [PATCH 066/327] Do not pass the pgsql_password variable to ejabberd.yml The password is only used in the config files for the vhosts --- site-cookbooks/kosmos-ejabberd/recipes/default.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index 1572727..c43f2f0 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -152,8 +152,7 @@ template "/opt/ejabberd/conf/ejabberd.yml" do source "ejabberd.yml.erb" mode 0640 sensitive true - variables pgsql_password: postgresql_data_bag_item['ejabberd_user_password'], - hosts: hosts, + variables hosts: hosts, admin_users: admin_users, stun_auth_realm: "kosmos.org", turn_ip_address: node['ipaddress'], From 2c21d6255b7fb20b92ad06e9050e4ca9a3b0e457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 10 Jun 2020 18:38:40 +0200 Subject: [PATCH 067/327] Add PostgreSQL primary support to the kosmos-ejabberd cookbook * Move the PostgreSQL user and database creation to a pg_db recipe * Generate access rights for the ejabberd servers in the pg_db recipe * Connect to the PostgreSQL primary instead of localhost Refs #180 --- .../kosmos-ejabberd/recipes/default.rb | 28 ++----- .../kosmos-ejabberd/recipes/pg_db.rb | 76 +++++++++++++++++++ .../kosmos-ejabberd/templates/vhost.yml.erb | 2 +- 3 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 site-cookbooks/kosmos-ejabberd/recipes/pg_db.rb diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index c43f2f0..6e60685 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -28,11 +28,6 @@ include_recipe "kosmos-postgresql" ejabberd_credentials = data_bag_item("credentials", "ejabberd") -cookbook_file "#{Chef::Config[:file_cache_path]}/pg.sql" do - source "pg.sql" - mode "0664" -end - ejabberd_version = node["kosmos-ejabberd"]["version"] package_checksum = node["kosmos-ejabberd"]["checksum"] package_path = "#{Chef::Config['file_cache_path']}/ejabberd_#{ejabberd_version}-0_amd64.deb" @@ -52,11 +47,6 @@ end postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') -postgresql_user 'ejabberd' do - action :create - password postgresql_data_bag_item['ejabberd_user_password'] -end - hosts = [ { name: "kosmos.org", @@ -111,21 +101,14 @@ ldap_base = "cn=users,dc=kosmos,dc=org" admin_users = ejabberd_credentials['admins'] +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] + hosts.each do |host| ldap_rootdn = "uid=xmpp,ou=#{host[:name]},cn=applications,dc=kosmos,dc=org" - postgresql_database host[:sql_database] do - owner 'ejabberd' - action :create - notifies :run, "execute[create db schema #{host[:sql_database]}]", :delayed - end - - execute "create db schema #{host[:sql_database]}" do - user "ejabberd" - command "psql #{host[:sql_database]} < #{Chef::Config[:file_cache_path]}/pg.sql" - action :nothing - end - template "/opt/ejabberd/conf/#{host[:name]}.yml" do source "vhost.yml.erb" mode 0640 @@ -133,6 +116,7 @@ hosts.each do |host| group 'ejabberd' sensitive true variables pgsql_password: postgresql_data_bag_item['ejabberd_user_password'], + sql_server: postgresql_server, host: host, ldap_base: ldap_base, ldap_server: ldap_domain, diff --git a/site-cookbooks/kosmos-ejabberd/recipes/pg_db.rb b/site-cookbooks/kosmos-ejabberd/recipes/pg_db.rb new file mode 100644 index 0000000..326ffda --- /dev/null +++ b/site-cookbooks/kosmos-ejabberd/recipes/pg_db.rb @@ -0,0 +1,76 @@ +# +# Cookbook:: kosmos-ejabberd +# Recipe:: pg_db +# +# 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. +# + +postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') + +postgresql_service = "service[#{postgresql_service_name}]" + +service postgresql_service do + supports restart: true, status: true, reload: true +end + +postgresql_user 'ejabberd' do + action :create + password postgresql_data_bag_item['ejabberd_user_password'] +end + +databases = ["ejabberd", "ejabberd_5apps"] + +ejabberd_servers = search(:node, "role:ejabberd AND chef_environment:#{node.chef_environment}") + +databases.each do |database| + postgresql_database database do + owner 'ejabberd' + action :create + notifies :run, "execute[create db schema #{database}]", :delayed + end + + cookbook_file "#{Chef::Config[:file_cache_path]}/pg.sql" do + source "pg.sql" + mode "0664" + end + + execute "create db schema #{database}" do + user "postgres" + command "psql #{database} < #{Chef::Config[:file_cache_path]}/pg.sql" + action :nothing + end + + ejabberd_servers.each do |ejabberd_server| + ip = ip_for(ejabberd_server) + hostname = ejabberd_server[:hostname] + + postgresql_access "ejabberd #{hostname}" do + access_type "host" + access_db "ejabberd" + access_user "ejabberd" + access_addr "#{ip}/32" + access_method "md5" + notifies :reload, postgresql_service, :delayed + end + end +end diff --git a/site-cookbooks/kosmos-ejabberd/templates/vhost.yml.erb b/site-cookbooks/kosmos-ejabberd/templates/vhost.yml.erb index 32c064d..eb6c943 100644 --- a/site-cookbooks/kosmos-ejabberd/templates/vhost.yml.erb +++ b/site-cookbooks/kosmos-ejabberd/templates/vhost.yml.erb @@ -7,7 +7,7 @@ certfiles: host_config: "<%= @host[:name] %>": sql_type: pgsql - sql_server: "localhost" + sql_server: "<%= @sql_server %>" sql_database: "<%= @host[:sql_database] %>" sql_username: "ejabberd" sql_password: "<%= @pgsql_password %>" From 1a6ce44758bedb59b6020d45937af27c4f8467ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 10 Jun 2020 18:43:34 +0200 Subject: [PATCH 068/327] Create a minimalist ejabberd role for development No Let's Encrypt, no backups --- roles/ejabberd.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/roles/ejabberd.rb b/roles/ejabberd.rb index e126017..4034261 100644 --- a/roles/ejabberd.rb +++ b/roles/ejabberd.rb @@ -1,7 +1,16 @@ name "ejabberd" -run_list %w( +default_run_list = %w( + kosmos-ejabberd::default +) + +production_run_list = %w( kosmos-ejabberd::default kosmos-ejabberd::letsencrypt kosmos-ejabberd::backup ) +env_run_lists( + 'production' => production_run_list, + 'development' => default_run_list, + '_default' => default_run_list +) From 26097a7584c81451b7a4947b9584032b249d0b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 11 Jun 2020 09:00:50 +0200 Subject: [PATCH 069/327] Use the correct database name for the access rights --- site-cookbooks/kosmos-ejabberd/recipes/pg_db.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-ejabberd/recipes/pg_db.rb b/site-cookbooks/kosmos-ejabberd/recipes/pg_db.rb index 326ffda..4304ed5 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/pg_db.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/pg_db.rb @@ -64,9 +64,9 @@ databases.each do |database| ip = ip_for(ejabberd_server) hostname = ejabberd_server[:hostname] - postgresql_access "ejabberd #{hostname}" do + postgresql_access "#{database} #{hostname}" do access_type "host" - access_db "ejabberd" + access_db database access_user "ejabberd" access_addr "#{ip}/32" access_method "md5" From 6f696d7634bb78d3698c0677067923de0f44c291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 11 Jun 2020 18:20:04 +0200 Subject: [PATCH 070/327] Define access rules in the PostgreSQL primary recipe Access is done for the IP of a server for all users and all databases for ejabberd and gitea --- .../kosmos-ejabberd/recipes/pg_db.rb | 21 ----------------- .../kosmos-postgresql/recipes/default.rb | 23 +++++++++++++++++++ site-cookbooks/kosmos_gitea/recipes/pg_db.rb | 20 ---------------- 3 files changed, 23 insertions(+), 41 deletions(-) diff --git a/site-cookbooks/kosmos-ejabberd/recipes/pg_db.rb b/site-cookbooks/kosmos-ejabberd/recipes/pg_db.rb index 4304ed5..85fba8c 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/pg_db.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/pg_db.rb @@ -27,12 +27,6 @@ postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') -postgresql_service = "service[#{postgresql_service_name}]" - -service postgresql_service do - supports restart: true, status: true, reload: true -end - postgresql_user 'ejabberd' do action :create password postgresql_data_bag_item['ejabberd_user_password'] @@ -40,8 +34,6 @@ end databases = ["ejabberd", "ejabberd_5apps"] -ejabberd_servers = search(:node, "role:ejabberd AND chef_environment:#{node.chef_environment}") - databases.each do |database| postgresql_database database do owner 'ejabberd' @@ -60,17 +52,4 @@ databases.each do |database| action :nothing end - ejabberd_servers.each do |ejabberd_server| - ip = ip_for(ejabberd_server) - hostname = ejabberd_server[:hostname] - - postgresql_access "#{database} #{hostname}" do - access_type "host" - access_db database - access_user "ejabberd" - access_addr "#{ip}/32" - access_method "md5" - notifies :reload, postgresql_service, :delayed - end - end end diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb index 53ec336..5fe7ba0 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/default.rb @@ -27,6 +27,10 @@ postgresql_version = "12" postgresql_service = "postgresql@#{postgresql_version}-main" +service postgresql_service do + supports restart: true, status: true, reload: true +end + postgresql_custom_server postgresql_version do role "primary" end @@ -54,6 +58,25 @@ postgresql_replicas.each do |replica| notifies :reload, "service[#{postgresql_service}]", :immediately end + gitea_servers = search(:node, "role:gitea AND chef_environment:#{node.chef_environment}") || [] + ejabberd_servers = search(:node, "role:ejabberd AND chef_environment:#{node.chef_environment}") || [] + + servers = (gitea_servers + ejabberd_servers).uniq + + servers.each do |server| + ip = ip_for(server) + hostname = server[:hostname] + + postgresql_access "#{hostname} all" do + access_type "host" + access_db "all" + access_user "all" + access_addr "#{ip}/32" + access_method "md5" + notifies :reload, "service[#{postgresql_service}]", :immediately + end + end + unless node.chef_environment == "development" include_recipe "firewall" diff --git a/site-cookbooks/kosmos_gitea/recipes/pg_db.rb b/site-cookbooks/kosmos_gitea/recipes/pg_db.rb index b4577e6..2cf4d19 100644 --- a/site-cookbooks/kosmos_gitea/recipes/pg_db.rb +++ b/site-cookbooks/kosmos_gitea/recipes/pg_db.rb @@ -6,12 +6,6 @@ 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"] @@ -21,17 +15,3 @@ 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 From ee9c241a4d0f958b5c2b856779d997c94500924a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 12 Jun 2020 16:54:58 +0200 Subject: [PATCH 071/327] Add a postgresql_client role The role is empty but is used to explicitly define servers that have access rights to all PostgreSQL databases and users --- roles/ejabberd.rb | 2 + roles/gitea.rb | 1 + roles/postgresql_client.rb | 5 +++ .../kosmos-postgresql/recipes/default.rb | 37 +++++++++---------- 4 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 roles/postgresql_client.rb diff --git a/roles/ejabberd.rb b/roles/ejabberd.rb index 4034261..561ca33 100644 --- a/roles/ejabberd.rb +++ b/roles/ejabberd.rb @@ -1,10 +1,12 @@ name "ejabberd" default_run_list = %w( + role[postgresql_client] kosmos-ejabberd::default ) production_run_list = %w( + role[postgresql_client] kosmos-ejabberd::default kosmos-ejabberd::letsencrypt kosmos-ejabberd::backup diff --git a/roles/gitea.rb b/roles/gitea.rb index b6f5069..5f7fd2a 100644 --- a/roles/gitea.rb +++ b/roles/gitea.rb @@ -1,6 +1,7 @@ name "gitea" run_list %w( + role[postgresql_client] kosmos_gitea::default kosmos_gitea::backup ) diff --git a/roles/postgresql_client.rb b/roles/postgresql_client.rb new file mode 100644 index 0000000..18771f2 --- /dev/null +++ b/roles/postgresql_client.rb @@ -0,0 +1,5 @@ +# This role is used by the kosmos-postgresql::default recipe to add access +# rules to every server that is a PostgreSQL client +name "postgresql_client" + +run_list [] diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb index 5fe7ba0..c7d289b 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/default.rb @@ -48,6 +48,24 @@ systemctl start postgresql@12-main only_if { ::File.exist? "/var/lib/postgresql/10/main" } end +# Services that connect to PostgreSQL need to have the postgresql_client role +# as part of their run list. See the gitea and ejabberd roles. +postgresql_clients = search(:node, "roles:postgresql_client AND chef_environment:#{node.chef_environment}") || [] + +postgresql_clients.each do |client| + ip = ip_for(client) + hostname = client[:hostname] + + postgresql_access "#{hostname} all" do + access_type "host" + access_db "all" + access_user "all" + access_addr "#{ip}/32" + access_method "md5" + notifies :reload, "service[#{postgresql_service}]", :immediately + end +end + postgresql_replicas.each do |replica| postgresql_access "#{replica[:hostname]} replication" do access_type "host" @@ -58,25 +76,6 @@ postgresql_replicas.each do |replica| notifies :reload, "service[#{postgresql_service}]", :immediately end - gitea_servers = search(:node, "role:gitea AND chef_environment:#{node.chef_environment}") || [] - ejabberd_servers = search(:node, "role:ejabberd AND chef_environment:#{node.chef_environment}") || [] - - servers = (gitea_servers + ejabberd_servers).uniq - - servers.each do |server| - ip = ip_for(server) - hostname = server[:hostname] - - postgresql_access "#{hostname} all" do - access_type "host" - access_db "all" - access_user "all" - access_addr "#{ip}/32" - access_method "md5" - notifies :reload, "service[#{postgresql_service}]", :immediately - end - end - unless node.chef_environment == "development" include_recipe "firewall" From 5e483240c391201235864d4761d204a88776f958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 12 Jun 2020 17:22:34 +0200 Subject: [PATCH 072/327] Set the Gitea root URL to HTTPS It fixes U2F security keys support, that was broken because the protocol did not match Fixes #182 --- site-cookbooks/kosmos_gitea/templates/default/app.ini.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb b/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb index 68b771f..d85c896 100644 --- a/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb +++ b/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb @@ -8,7 +8,8 @@ DISABLE_SSH = false SSH_PORT = 22 PROTOCOL = http DOMAIN = gitea.kosmos.org -ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s +# Gitea is running behind an nginx reverse load balancer, use an HTTPS root URL +ROOT_URL = https://%(DOMAIN)s # REDIRECT_OTHER_PORT = true # PORT_TO_REDIRECT = 3001 # ENABLE_LETSENCRYPT = true From e7edb5a4640175eeaba0cefa41d8a73989fb4a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 19 Jun 2020 16:21:35 +0200 Subject: [PATCH 073/327] Update apt to 7.3.0 It now includes unattended-upgrades support --- Berksfile | 2 +- Berksfile.lock | 4 +- cookbooks/apt/CHANGELOG.md | 30 ++++++++++++- cookbooks/apt/README.md | 6 ++- cookbooks/apt/attributes/default.rb | 7 ++- cookbooks/apt/libraries/helpers.rb | 12 ++--- cookbooks/apt/metadata.json | 2 +- cookbooks/apt/metadata.rb | 13 ++++++ cookbooks/apt/recipes/cacher-client.rb | 4 +- cookbooks/apt/recipes/cacher-ng.rb | 2 +- cookbooks/apt/recipes/default.rb | 9 ++-- cookbooks/apt/recipes/unattended-upgrades.rb | 2 +- .../apt/templates/50unattended-upgrades.erb | 45 +++++++++++++++---- 13 files changed, 108 insertions(+), 30 deletions(-) create mode 100644 cookbooks/apt/metadata.rb diff --git a/Berksfile b/Berksfile index 05704ee..288f290 100644 --- a/Berksfile +++ b/Berksfile @@ -31,7 +31,7 @@ cookbook 'nginx', '= 9.0.0' cookbook 'build-essential', '~> 8.2.1' cookbook 'mysql', '~> 8.5.1' # cookbook 'postgresql', '= 7.1.8' -cookbook 'apt', '~> 7.0.0' +cookbook 'apt', '~> 7.3.0' cookbook 'git', '= 6.0.0' cookbook 'hostsfile', '= 2.4.5' cookbook 'ohai', '~> 5.2.5' diff --git a/Berksfile.lock b/Berksfile.lock index 8d531d9..985d29b 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -3,7 +3,7 @@ DEPENDENCIES application (~> 5.2.0) application_git (= 1.1.0) application_javascript (~> 1.0.0) - apt (~> 7.0.0) + apt (~> 7.3.0) ark (= 3.1.0) build-essential (~> 8.2.1) chef-sugar (= 3.3.0) @@ -66,7 +66,7 @@ GRAPH poise (~> 2.0) poise-javascript (~> 1.0) poise-service (~> 1.0) - apt (7.0.0) + apt (7.3.0) ark (3.1.0) build-essential (>= 0.0.0) seven_zip (>= 0.0.0) diff --git a/cookbooks/apt/CHANGELOG.md b/cookbooks/apt/CHANGELOG.md index 2d89fee..dbcb39f 100644 --- a/cookbooks/apt/CHANGELOG.md +++ b/cookbooks/apt/CHANGELOG.md @@ -2,6 +2,34 @@ This file is used to list changes made in each version of the apt cookbook. +## 7.3.0 (2020-05-01) + +- Cookstyle fixes - [@tas50](https://github.com/tas50) +- Remove unnecessary Foodcritic comments - [@tas50](https://github.com/tas50) +- Simplify the metadata.rb to resolve cookstyle warnings - [@tas50](https://github.com/tas50) +- Prevent helper collisions in Chef Infra Client 16 - [@tas50](https://github.com/tas50) + +## 7.2.0 (2019-08-05) + +- Allow you to specify dpkg options just for unattended upgrades - [@majormoses](https://github.com/majormoses) +- Adding documentation and tests for setting dpkg options unattended upgrades - [@majormoses](https://github.com/majormoses) +- Test on Chef 15 + Chef Workstation - [@tas50](https://github.com/tas50) +- Remove tests of the resources now built into Chef - [@tas50](https://github.com/tas50) +- Remove respond_to from the metadata - [@tas50](https://github.com/tas50) +- Remove the recipe description from the metadata as these aren't used - [@tas50](https://github.com/tas50) +- Replace Chef 12 testing with 13.3 - [@tas50](https://github.com/tas50) +- Remove Ubuntu 14.04 / Debian 8 testing and add Debian 10 testing - [@tas50](https://github.com/tas50) + +## 7.1.1 (2018-10-11) + +- Allow to customize sender email for unattended-upgrades + +## 7.1.0 (2018-09-05) + +- Add the installation of dirmngr and gnupg to the apt default cookbook to support secure repositories +- Added support for the unattended-upgrade SyslogEnable configuration feature +- Added support for the unattended-upgrade SyslogFacility configuration feature + ## 7.0.0 (2018-04-06) ### Breaking Change @@ -16,7 +44,7 @@ This file is used to list changes made in each version of the apt cookbook. ## 6.1.3 (2017-07-19) - Fixed typo in readme -- Fixed config namespace in the 10dpkg-options file +- Fixed config namespace in the 10dpkg-options file ## 6.1.2 (2017-06-20) diff --git a/cookbooks/apt/README.md b/cookbooks/apt/README.md index 3508386..d54e58a 100644 --- a/cookbooks/apt/README.md +++ b/cookbooks/apt/README.md @@ -83,7 +83,7 @@ For example, to prevent caching and directly connect to the repository at `downl "cacher_server": { "cache_bypass": { "download.oracle.com": "http", - "nginx.org": "https" + "nginx.org": "https" } } } @@ -129,11 +129,15 @@ To pull just security updates, set `origins_patterns` to something like `["origi - `['apt']['unattended_upgrades']['minimal_steps']` - Split the upgrade into the smallest possible chunks. This makes the upgrade a bit slower but it has the benefit that shutdown while a upgrade is running is possible (with a small delay). Defaults to false. - `['apt']['unattended_upgrades']['install_on_shutdown']` - Install upgrades when the machine is shuting down instead of doing it in the background while the machine is running. This will (obviously) make shutdown slower. Defaults to false. - `['apt']['unattended_upgrades']['mail']` - Send email to this address for problems or packages upgrades. Defaults to no email. +- `['apt']['unattended_upgrades']['sender']` - Send email from this address for problems or packages upgrades. Defaults to 'root'. - `['apt']['unattended_upgrades']['mail_only_on_error']` - If set, email will only be set on upgrade errors. Otherwise, an email will be sent after each upgrade. Defaults to true. - `['apt']['unattended_upgrades']['remove_unused_dependencies']` Do automatic removal of new unused dependencies after the upgrade. Defaults to false. - `['apt']['unattended_upgrades']['automatic_reboot']` - Automatically reboots _without confirmation_ if a restart is required after the upgrade. Defaults to false. - `['apt']['unattended_upgrades']['dl_limit']` - Limits the bandwidth used by apt to download packages. Value given as an integer in kb/sec. Defaults to nil (no limit). - `['apt']['unattended_upgrades']['random_sleep']` - Wait a random number of seconds up to this value before running daily periodic apt actions. System default is 1800 seconds (30 minutes). +- `['apt']['unattended_upgrades']['syslog_enable']` - Enable logging to syslog. Defaults to false. +- `['apt']['unattended_upgrades']['syslog_facility']` - Specify syslog facility. Defaults to 'daemon'. +- `['apt']['unattended_upgrades']['dpkg_options']` An array of dpkg options to be used specifically only for unattended upgrades. Defaults to `[]` which will prevent it from being rendered from the template in the resulting file. ### Configuration for APT diff --git a/cookbooks/apt/attributes/default.rb b/cookbooks/apt/attributes/default.rb index b382ab5..102f4e5 100644 --- a/cookbooks/apt/attributes/default.rb +++ b/cookbooks/apt/attributes/default.rb @@ -2,7 +2,7 @@ # Cookbook:: apt # Attributes:: default # -# Copyright:: 2009-2017, Chef Software, Inc. +# Copyright:: 2009-2019, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -41,12 +41,17 @@ default['apt']['unattended_upgrades']['auto_fix_interrupted_dpkg'] = false default['apt']['unattended_upgrades']['minimal_steps'] = false default['apt']['unattended_upgrades']['install_on_shutdown'] = false default['apt']['unattended_upgrades']['mail'] = nil +default['apt']['unattended_upgrades']['sender'] = nil default['apt']['unattended_upgrades']['mail_only_on_error'] = true default['apt']['unattended_upgrades']['remove_unused_dependencies'] = false default['apt']['unattended_upgrades']['automatic_reboot'] = false default['apt']['unattended_upgrades']['automatic_reboot_time'] = 'now' default['apt']['unattended_upgrades']['dl_limit'] = nil default['apt']['unattended_upgrades']['random_sleep'] = nil +default['apt']['unattended_upgrades']['syslog_enable'] = false +default['apt']['unattended_upgrades']['syslog_facility'] = 'daemon' + +default['apt']['unattended_upgrades']['dpkg_options'] = [] default['apt']['confd']['force_confask'] = false default['apt']['confd']['force_confdef'] = false diff --git a/cookbooks/apt/libraries/helpers.rb b/cookbooks/apt/libraries/helpers.rb index 6d98060..a8e2286 100644 --- a/cookbooks/apt/libraries/helpers.rb +++ b/cookbooks/apt/libraries/helpers.rb @@ -2,7 +2,7 @@ # Cookbook:: apt # Library:: helpers # -# Copyright:: 2013-2017, Chef Software, Inc. +# Copyright:: 2013-2019, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,13 +24,13 @@ module Apt # # @return [Boolean] def apt_installed? - !which('apt-get').nil? + !apt_which('apt-get').nil? end # Finds a command in $PATH # # @return [String, nil] - def which(cmd) + def apt_which(cmd) ENV['PATH'] = '' if ENV['PATH'].nil? paths = (ENV['PATH'].split(::File::PATH_SEPARATOR) + %w(/bin /usr/bin /sbin /usr/sbin)) @@ -44,6 +44,6 @@ module Apt end end -Chef::Recipe.send(:include, ::Apt::Helpers) -Chef::Resource.send(:include, ::Apt::Helpers) -Chef::Provider.send(:include, ::Apt::Helpers) +Chef::Recipe.include ::Apt::Helpers +Chef::Resource.include ::Apt::Helpers +Chef::Provider.include ::Apt::Helpers diff --git a/cookbooks/apt/metadata.json b/cookbooks/apt/metadata.json index ce9957d..bf61909 100644 --- a/cookbooks/apt/metadata.json +++ b/cookbooks/apt/metadata.json @@ -1 +1 @@ -{"name":"apt","version":"7.0.0","description":"Configures apt and apt caching.","long_description":"# apt Cookbook\n\n[![Build Status](https://img.shields.io/travis/chef-cookbooks/apt.svg)][travis] [![Cookbook Version](https://img.shields.io/cookbook/v/apt.svg)][cookbook]\n\nThis cookbook includes recipes to execute apt-get update to ensure the local APT package cache is up to date. There are recipes for managing the apt-cacher-ng caching proxy and proxy clients. It also includes a custom resource for pinning packages via /etc/apt/preferences.d.\n\n## Requirements\n\n### Platforms\n\n- Ubuntu 12.04+\n- Debian 7+\n\nMay work with or without modification on other Debian derivatives.\n\n### Chef\n\n- Chef 13.3+\n\n### Cookbooks\n\n- None\n\n## Recipes\n\n### default\n\nThis recipe manually updates the timestamp file used to only run `apt-get update` if the cache is more than one day old.\n\nThis recipe should appear first in the run list of Debian or Ubuntu nodes to ensure that the package cache is up to date before managing any `package` resources with Chef.\n\nThis recipe also sets up a local cache directory for preseeding packages.\n\n**Including the default recipe on a node that does not support apt (such as Windows or RHEL) results in a noop.**\n\n### cacher-client\n\nConfigures the node to use a `apt-cacher-ng` server to cache apt requests. Configuration of the server to use is located in `default['apt']['cacher_client']['cacher_server']` which is a hash containing `host`, `port`, `proxy_ssl`, and `bypass` keys. Example:\n\n```json\n{\n \"apt\": {\n \"cacher_client\": {\n \"cacher_server\": {\n \"host\": \"cache_server.mycorp.dmz\",\n \"port\": 1234,\n \"proxy_ssl\": true,\n \"cache_bypass\": {\n \"download.oracle.com\": \"http\"\n }\n }\n }\n }\n}\n```\n\n#### Bypassing the cache\n\nOccasionally you may come across repositories that do not play nicely when the node is using an `apt-cacher-ng` server. You can configure `cacher-client` to bypass the server and connect directly to the repository with the `cache_bypass` attribute.\n\nTo do this, you need to override the `cache_bypass` attribute with an hash of repositories, with each key as the repository URL and value as the protocol to use:\n\n```json\n{\n \"apt\": {\n \"cacher_client\": {\n \"cacher_server\": {\n \"cache_bypass\": {\n \"URL\": \"PROTOCOL\"\n }\n }\n }\n }\n}\n```\n\nFor example, to prevent caching and directly connect to the repository at `download.oracle.com` via http and the repo at `nginx.org` via https\n\n```json\n{\n \"apt\": {\n \"cacher_client\": {\n \"cacher_server\": {\n \"cache_bypass\": {\n \"download.oracle.com\": \"http\",\n \"nginx.org\": \"https\" \n }\n }\n }\n }\n}\n```\n\n### cacher-ng\n\nInstalls the `apt-cacher-ng` package and service so the system can provide APT caching. You can check the usage report at .\n\nIf you wish to help the `cacher-ng` recipe seed itself, you must now explicitly include the `cacher-client` recipe in your run list **after** `cacher-ng` or you will block your ability to install any packages (ie. `apt-cacher-ng`).\n\n### unattended-upgrades\n\nInstalls and configures the `unattended-upgrades` package to provide automatic package updates. This can be configured to upgrade all packages or to just install security updates by setting `['apt']['unattended_upgrades']['allowed_origins']`.\n\nTo pull just security updates, set `origins_patterns` to something like `[\"origin=Ubuntu,archive=trusty-security\"]` (for Ubuntu trusty) or `[\"origin=Debian,label=Debian-Security\"]` (for Debian).\n\n## Attributes\n\n### General\n\n- `['apt']['compile_time_update']` - force the default recipe to run `apt-get update` at compile time.\n- `['apt']['periodic_update_min_delay']` - minimum delay (in seconds) between two actual executions of `apt-get update` by the `execute[apt-get-update-periodic]` resource, default is '86400' (24 hours)\n\n### Caching\n\n- `['apt']['cacher_client']['cacher_server']` - Hash containing server information used by clients for caching. See the example in the recipes section above for the full format of the hash.\n- `['apt']['cacher_interface']` - interface to connect to the cacher-ng service, no default.\n- `['apt']['cacher_port']` - port for the cacher-ng service (used by server recipe only), default is '3142'\n- `['apt']['cacher_dir']` - directory used by cacher-ng service, default is '/var/cache/apt-cacher-ng'\n- `['apt']['compiletime']` - force the `cacher-client` recipe to run before other recipes. It forces apt to use the proxy before other recipes run. Useful if your nodes have limited access to public apt repositories. This is overridden if the `cacher-ng` recipe is in your run list. Default is 'false'\n\n### Unattended Upgrades\n\n- `['apt']['unattended_upgrades']['enable']` - enables unattended upgrades, default is false\n- `['apt']['unattended_upgrades']['update_package_lists']` - automatically update package list (`apt-get update`) daily, default is true\n- `['apt']['unattended_upgrades']['allowed_origins']` - array of allowed apt origins from which to pull automatic upgrades, defaults to a guess at the system's main origin and should almost always be overridden\n- `['apt']['unattended_upgrades']['origins_patterns']` - array of allowed apt origin patterns from which to pull automatic upgrades, defaults to none.\n- `['apt']['unattended_upgrades']['package_blacklist']` - an array of package which should never be automatically upgraded, defaults to none\n- `['apt']['unattended_upgrades']['auto_fix_interrupted_dpkg']` - attempts to repair dpkg state with `dpkg --force-confold --configure -a` if it exits uncleanly, defaults to false (contrary to the unattended-upgrades default)\n- `['apt']['unattended_upgrades']['minimal_steps']` - Split the upgrade into the smallest possible chunks. This makes the upgrade a bit slower but it has the benefit that shutdown while a upgrade is running is possible (with a small delay). Defaults to false.\n- `['apt']['unattended_upgrades']['install_on_shutdown']` - Install upgrades when the machine is shuting down instead of doing it in the background while the machine is running. This will (obviously) make shutdown slower. Defaults to false.\n- `['apt']['unattended_upgrades']['mail']` - Send email to this address for problems or packages upgrades. Defaults to no email.\n- `['apt']['unattended_upgrades']['mail_only_on_error']` - If set, email will only be set on upgrade errors. Otherwise, an email will be sent after each upgrade. Defaults to true.\n- `['apt']['unattended_upgrades']['remove_unused_dependencies']` Do automatic removal of new unused dependencies after the upgrade. Defaults to false.\n- `['apt']['unattended_upgrades']['automatic_reboot']` - Automatically reboots _without confirmation_ if a restart is required after the upgrade. Defaults to false.\n- `['apt']['unattended_upgrades']['dl_limit']` - Limits the bandwidth used by apt to download packages. Value given as an integer in kb/sec. Defaults to nil (no limit).\n- `['apt']['unattended_upgrades']['random_sleep']` - Wait a random number of seconds up to this value before running daily periodic apt actions. System default is 1800 seconds (30 minutes).\n\n### Configuration for APT\n\n- `['apt']['confd']['force_confask']` - Prompt when overwriting configuration files. (default: false)\n- `['apt']['confd']['force_confdef']` - Don't prompt when overwriting configuration files. (default: false)\n- `['apt']['confd']['force_confmiss']` - Install removed configuration files when upgrading packages. (default: false)\n- `['apt']['confd']['force_confnew']` - Overwrite configuration files when installing packages. (default: false)\n- `['apt']['confd']['force_confold']` - Keep modified configuration files when installing packages. (default: false)\n- `['apt']['confd']['install_recommends']` - Consider recommended packages as a dependency for installing. (default: true)\n- `['apt']['confd']['install_suggests']` - Consider suggested packages as a dependency for installing. (default: false)\n\n## Libraries\n\nThere is an `interface_ipaddress` method that returns the IP address for a particular host and interface, used by the `cacher-client` recipe. To enable it on the server use the `['apt']['cacher_interface']` attribute.\n\n## Usage\n\nPut `recipe[apt]` first in the run list. If you have other recipes that you want to use to configure how apt behaves, like new sources, notify the execute resource to run, e.g.:\n\n```ruby\ntemplate '/etc/apt/sources.list.d/my_apt_sources.list' do\n notifies :run, 'execute[apt-get update]', :immediately\nend\n```\n\nThe above will run during execution phase since it is a normal template resource, and should appear before other package resources that need the sources in the template.\n\nPut `recipe[apt::cacher-ng]` in the run_list for a server to provide APT caching and add `recipe[apt::cacher-client]` on the rest of the Debian-based nodes to take advantage of the caching server.\n\nIf you want to cleanup unused packages, there is also the `apt-get autoclean` and `apt-get autoremove` resources provided for automated cleanup.\n\n## Resources\n\n### apt_preference\n\nThe apt_preference resource has been moved into chef-client in Chef 13.3.\n\nSee for usage details\n\n### apt_repository\n\nThe apt_repository resource has been moved into chef-client in Chef 12.9.\n\nSee for usage details\n\n### apt_update\n\nThe apt_update resource has been moved into chef-client in Chef 12.7.\n\nSee for usage details\n\n## Maintainers\n\nThis cookbook is maintained by Chef's Community Cookbook Engineering team. Our goal is to improve cookbook quality and to aid the community in contributing to cookbooks. To learn more about our team, process, and design goals see our [team documentation](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/COOKBOOK_TEAM.MD). To learn more about contributing to cookbooks like this see our [contributing documentation](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD), or if you have general questions about this cookbook come chat with us in #cookbok-engineering on the [Chef Community Slack](http://community-slack.chef.io/)\n\n## License\n\n**Copyright:** 2009-2017, Chef Software, Inc.\n\n```\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n\n[cookbook]: https://community.chef.io/cookbooks/apt\n[travis]: https://travis-ci.org/chef-cookbooks/apt\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache-2.0","platforms":{"ubuntu":">= 0.0.0","debian":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{"apt::default":"Runs apt-get update during compile phase and sets up preseed directories","apt::cacher-ng":"Set up an apt-cacher-ng caching proxy","apt::cacher-client":"Client for the apt::cacher-ng caching proxy"},"source_url":"https://github.com/chef-cookbooks/apt","issues_url":"https://github.com/chef-cookbooks/apt/issues","chef_version":[[">= 13.3"]],"ohai_version":[]} \ No newline at end of file +{"name":"apt","version":"7.3.0","description":"Configures apt and apt caching.","long_description":"","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache-2.0","platforms":{"ubuntu":">= 0.0.0","debian":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chef-cookbooks/apt","issues_url":"https://github.com/chef-cookbooks/apt/issues","chef_version":[[">= 13.3"]],"ohai_version":[]} \ No newline at end of file diff --git a/cookbooks/apt/metadata.rb b/cookbooks/apt/metadata.rb new file mode 100644 index 0000000..4da791b --- /dev/null +++ b/cookbooks/apt/metadata.rb @@ -0,0 +1,13 @@ +name 'apt' +maintainer 'Chef Software, Inc.' +maintainer_email 'cookbooks@chef.io' +license 'Apache-2.0' +description 'Configures apt and apt caching.' +version '7.3.0' + +supports 'ubuntu' +supports 'debian' + +source_url 'https://github.com/chef-cookbooks/apt' +issues_url 'https://github.com/chef-cookbooks/apt/issues' +chef_version '>= 13.3' diff --git a/cookbooks/apt/recipes/cacher-client.rb b/cookbooks/apt/recipes/cacher-client.rb index 1bbf92c..dafa876 100644 --- a/cookbooks/apt/recipes/cacher-client.rb +++ b/cookbooks/apt/recipes/cacher-client.rb @@ -2,7 +2,7 @@ # Cookbook:: apt # Recipe:: cacher-client # -# Copyright:: 2011-2017, Chef Software, Inc. +# Copyright:: 2011-2019, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -49,4 +49,4 @@ else t.run_action(:create) if node['apt']['compiletime'] end -include_recipe 'apt::default' +include_recipe 'apt::default' # rubocop: disable ChefModernize/IncludingAptDefaultRecipe diff --git a/cookbooks/apt/recipes/cacher-ng.rb b/cookbooks/apt/recipes/cacher-ng.rb index 5d7e846..81edb50 100644 --- a/cookbooks/apt/recipes/cacher-ng.rb +++ b/cookbooks/apt/recipes/cacher-ng.rb @@ -2,7 +2,7 @@ # Cookbook:: apt # Recipe:: cacher-ng # -# Copyright:: 2008-2017, Chef Software, Inc. +# Copyright:: 2008-2019, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License. diff --git a/cookbooks/apt/recipes/default.rb b/cookbooks/apt/recipes/default.rb index 23e54a2..42ff17a 100644 --- a/cookbooks/apt/recipes/default.rb +++ b/cookbooks/apt/recipes/default.rb @@ -2,8 +2,8 @@ # Cookbook:: apt # Recipe:: default # -# Copyright:: 2008-2017, Chef Software, Inc. -# Copyright:: 2009-2017, Bryan McLellan +# Copyright:: 2008-2019, Chef Software, Inc. +# Copyright:: 2009-2019, Bryan McLellan # # Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License. @@ -42,8 +42,7 @@ apt_update 'periodic' do end # For other recipes to call to force an update -execute 'apt-get update' do - command 'apt-get update' +execute 'apt-get update' do # rubocop: disable ChefModernize/ExecuteAptUpdate ignore_failure true action :nothing notifies :touch, 'file[/var/lib/apt/periodic/update-success-stamp]', :immediately @@ -93,6 +92,6 @@ template '/etc/apt/apt.conf.d/10recommends' do only_if { apt_installed? } end -package 'apt-transport-https' do +package %w(apt-transport-https gnupg dirmngr) do only_if { apt_installed? } end diff --git a/cookbooks/apt/recipes/unattended-upgrades.rb b/cookbooks/apt/recipes/unattended-upgrades.rb index ee2cb6e..f6c829c 100644 --- a/cookbooks/apt/recipes/unattended-upgrades.rb +++ b/cookbooks/apt/recipes/unattended-upgrades.rb @@ -2,7 +2,7 @@ # Cookbook:: apt # Recipe:: unattended-upgrades # -# Copyright:: 2014-2017, Chef Software, Inc. +# Copyright:: 2014-2019, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License. diff --git a/cookbooks/apt/templates/50unattended-upgrades.erb b/cookbooks/apt/templates/50unattended-upgrades.erb index 9bf0380..de9cd82 100644 --- a/cookbooks/apt/templates/50unattended-upgrades.erb +++ b/cookbooks/apt/templates/50unattended-upgrades.erb @@ -25,7 +25,7 @@ Unattended-Upgrade::Package-Blacklist { }; // This option allows you to control if on a unclean dpkg exit -// unattended-upgrades will automatically run +// unattended-upgrades will automatically run // dpkg --force-confold --configure -a // The default is true, to ensure updates keep getting installed Unattended-Upgrade::AutoFixInterruptedDpkg "<%= node['apt']['unattended_upgrades']['auto_fix_interrupted_dpkg'] ? 'true' : 'false' %>"; @@ -41,14 +41,20 @@ Unattended-Upgrade::MinimalSteps "<%= node['apt']['unattended_upgrades']['minima // This will (obviously) make shutdown slower Unattended-Upgrade::InstallOnShutdown "<%= node['apt']['unattended_upgrades']['install_on_shutdown'] ? 'true' : 'false' %>"; +<% if node['apt']['unattended_upgrades']['mail'] -%> // Send email to this address for problems or packages upgrades // If empty or unset then no email is sent, make sure that you // have a working mail setup on your system. A package that provides // 'mailx' must be installed. -<% if node['apt']['unattended_upgrades']['mail'] -%> Unattended-Upgrade::Mail "<%= node['apt']['unattended_upgrades']['mail'] %>"; <% end -%> +<% if node['apt']['unattended_upgrades']['sender'] -%> +// This option allows to customize the email address used in the +// 'From' header. unattended-upgrades will use "root" if unset. +Unattended-Upgrade::Sender "<%= node['apt']['unattended_upgrades']['sender'] %>"; +<% end -%> + // Set this value to "true" to get emails only on errors. Default // is to always send a mail if Unattended-Upgrade::Mail is set Unattended-Upgrade::MailOnlyOnError "<%= node['apt']['unattended_upgrades']['mail_only_on_error'] ? 'true' : 'false' %>"; @@ -57,19 +63,42 @@ Unattended-Upgrade::MailOnlyOnError "<%= node['apt']['unattended_upgrades']['mai // (equivalent to apt-get autoremove) Unattended-Upgrade::Remove-Unused-Dependencies "<%= node['apt']['unattended_upgrades']['remove_unused_dependencies'] ? 'true' : 'false' %>"; -// Automatically reboot *WITHOUT CONFIRMATION* if a -// the file /var/run/reboot-required is found after the upgrade +// Automatically reboot *WITHOUT CONFIRMATION* if a +// the file /var/run/reboot-required is found after the upgrade Unattended-Upgrade::Automatic-Reboot "<%= node['apt']['unattended_upgrades']['automatic_reboot'] ? 'true' : 'false' %>"; -// If automatic reboot is enabled and needed, reboot at the specific -// time instead of immediately -// Default: "now" <% if node['apt']['unattended_upgrades']['automatic_reboot'] -%> +// If automatic reboot is enabled and needed, reboot at the specific +// time instead of immediately. Default is "now" Unattended-Upgrade::Automatic-Reboot-Time "<%= node['apt']['unattended_upgrades']['automatic_reboot_time'] %>"; <% end %> +<% if node['apt']['unattended_upgrades']['dl_limit'] -%> // Use apt bandwidth limit feature, this example limits the download // speed to 70kb/sec -<% if node['apt']['unattended_upgrades']['dl_limit'] -%> +// Acquire::http::Dl-Limit "70"; Acquire::http::Dl-Limit "<%= node['apt']['unattended_upgrades']['dl_limit'] %>"; <% end -%> + +// Enable logging to syslog. Default is False +Unattended-Upgrade::SyslogEnable "<%= node['apt']['unattended_upgrades']['syslog_enable'] ? 'true' : 'false' %>"; + +// Specify syslog facility. Default is daemon +Unattended-Upgrade::SyslogFacility "<%= node['apt']['unattended_upgrades']['syslog_facility'] %>"; + +// specify any dpkg options you want to run +// for example if you wanted to upgrade and use +// the installed version of config files when +// resolving conflicts during an upgrade you +// typically need: +// Dpkg::Options { +// "--force-confdef"; +// "--force-confold"; +//}; +<% unless node['apt']['unattended_upgrades']['dpkg_options'].empty? -%> +Dpkg::Options { +<% node['apt']['unattended_upgrades']['dpkg_options'].each do |option|%> + "<%= option %>"; +<% end -%> +}; +<% end -%> From b4357df471d027f0291950a476f08651cdf610b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 19 Jun 2020 16:25:57 +0200 Subject: [PATCH 074/327] Enable unattended-upgrades (security and updates repositories) ... with email notifications on failure and logging with syslog --- site-cookbooks/kosmos-base/recipes/default.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/site-cookbooks/kosmos-base/recipes/default.rb b/site-cookbooks/kosmos-base/recipes/default.rb index 25673f6..e4c694c 100644 --- a/site-cookbooks/kosmos-base/recipes/default.rb +++ b/site-cookbooks/kosmos-base/recipes/default.rb @@ -29,6 +29,14 @@ include_recipe 'timezone_iii' include_recipe 'ntp' include_recipe 'kosmos-base::systemd_emails' +node.override["apt"]["unattended_upgrades"]["allowed_origins"] = [ + "${distro_id}:${distro_codename}-security", + "${distro_id}:${distro_codename}-updates" +] +node.override["apt"]["unattended_upgrades"]["mail"] = "ops@kosmos.org" +node.override["apt"]["unattended_upgrades"]["syslog_enable"] = true +include_recipe 'apt::unattended-upgrades' + package 'mailutils' package 'mosh' From 84cf008bac1992b97224dce6ef7f6144d5f5ad7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 19 Jun 2020 16:22:51 +0200 Subject: [PATCH 075/327] Install vim --- site-cookbooks/kosmos-base/recipes/default.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/site-cookbooks/kosmos-base/recipes/default.rb b/site-cookbooks/kosmos-base/recipes/default.rb index e4c694c..9ee8ab8 100644 --- a/site-cookbooks/kosmos-base/recipes/default.rb +++ b/site-cookbooks/kosmos-base/recipes/default.rb @@ -39,6 +39,7 @@ include_recipe 'apt::unattended-upgrades' package 'mailutils' package 'mosh' +package 'vim' # Don't create users and rewrite the sudo config in development environment. # It breaks the vagrant user From 8386dae46f6bedba3b33aa25ef1af7dd4c81a26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 19 Jun 2020 16:26:39 +0200 Subject: [PATCH 076/327] Add the new Hetzner server, draco.kosmos.org --- clients/draco.kosmos.org.json | 4 +++ nodes/draco.kosmos.org.json | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 clients/draco.kosmos.org.json create mode 100644 nodes/draco.kosmos.org.json diff --git a/clients/draco.kosmos.org.json b/clients/draco.kosmos.org.json new file mode 100644 index 0000000..e3154f6 --- /dev/null +++ b/clients/draco.kosmos.org.json @@ -0,0 +1,4 @@ +{ + "name": "draco.kosmos.org", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqJiREO7WJyKWzOltXREs\n6bCMBzHTeyBSLxK/50xPvk43A8e+8qW1V52oO/uQkHh8YJ8BCDdSsWTNTudTuMhm\nEFLYP7n+ESYyz7nBgcwLX19lSo3dGnyuQBwlno6W/F1uEdTxfY6MtxJdiPZQDIt0\noijEwOF4ZhA5A+kqx6fpp+rX48r9wdidjdhrJimQixL0SsJFkoStc17BxrnqPpv9\n/sd4xYKgK9hEmEovhghBN3ULsxDOj63cGmM4uWLjbO4ZpL6g1lZRJR5kmcziL9KH\n23M7ShaJu90PnPiFSCUFgNN24zA7aKTkKulNs4g2OYovWVG/z8WglGqHNY83dBP0\nLwIDAQAB\n-----END PUBLIC KEY-----\n" +} diff --git a/nodes/draco.kosmos.org.json b/nodes/draco.kosmos.org.json new file mode 100644 index 0000000..f370077 --- /dev/null +++ b/nodes/draco.kosmos.org.json @@ -0,0 +1,51 @@ +{ + "name": "draco.kosmos.org", + "normal": { + "knife_zero": { + "host": "draco.kosmos.org" + } + }, + "automatic": { + "fqdn": "draco.kosmos.org", + "os": "linux", + "os_version": "5.4.0-37-generic", + "hostname": "draco", + "ipaddress": "148.251.237.73", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "ohai": { + "version": "15.9.1", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.9.1/lib/ohai" + }, + "chef": { + "version": "15.11.8", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.11.8/lib" + } + } + }, + "run_list": [ + "recipe[kosmos-base]" + ] +} \ No newline at end of file From f7dfffd96715b779f2bd9d0104c9d2ce61eda51c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 19 Jun 2020 16:43:42 +0200 Subject: [PATCH 077/327] Add the kosmos_encfs recipe to draco --- nodes/draco.kosmos.org.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nodes/draco.kosmos.org.json b/nodes/draco.kosmos.org.json index f370077..25f4a36 100644 --- a/nodes/draco.kosmos.org.json +++ b/nodes/draco.kosmos.org.json @@ -17,6 +17,8 @@ "recipes": [ "kosmos-base", "kosmos-base::default", + "kosmos_encfs", + "kosmos_encfs::default", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -46,6 +48,7 @@ } }, "run_list": [ - "recipe[kosmos-base]" + "recipe[kosmos-base]", + "recipe[kosmos_encfs]" ] } \ No newline at end of file From fb8687b63c696f5f0e6ac21e23be83888b148037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 19 Jun 2020 17:13:26 +0200 Subject: [PATCH 078/327] Add the postgresql_replica role to draco --- nodes/draco.kosmos.org.json | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/nodes/draco.kosmos.org.json b/nodes/draco.kosmos.org.json index 25f4a36..e266fe1 100644 --- a/nodes/draco.kosmos.org.json +++ b/nodes/draco.kosmos.org.json @@ -12,13 +12,14 @@ "hostname": "draco", "ipaddress": "148.251.237.73", "roles": [ - + "postgresql_replica" ], "recipes": [ "kosmos-base", "kosmos-base::default", "kosmos_encfs", "kosmos_encfs::default", + "kosmos-postgresql::replica", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -31,7 +32,10 @@ "postfix::_common", "postfix::_attributes", "postfix::sasl_auth", - "hostname::default" + "hostname::default", + "firewall::default", + "chef-sugar::default", + "build-essential::default" ], "platform": "ubuntu", "platform_version": "20.04", @@ -49,6 +53,7 @@ }, "run_list": [ "recipe[kosmos-base]", - "recipe[kosmos_encfs]" + "recipe[kosmos_encfs]", + "role[postgresql_replica]" ] } \ No newline at end of file From 004a6913b4a9002b11d6821be6714e46dc3d89ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 26 Jun 2020 15:18:54 +0200 Subject: [PATCH 079/327] Remove dependency to an old PostgreSQL in the Systemd unit Refs #186 --- .../templates/default/mastodon-web.systemd.service.erb | 2 -- 1 file changed, 2 deletions(-) diff --git a/site-cookbooks/kosmos-mastodon/templates/default/mastodon-web.systemd.service.erb b/site-cookbooks/kosmos-mastodon/templates/default/mastodon-web.systemd.service.erb index 94a6346..2fedefa 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/mastodon-web.systemd.service.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/mastodon-web.systemd.service.erb @@ -2,8 +2,6 @@ Description=mastodon-web Requires=redis-server.service After=redis-server.service -Requires=postgresql@9.4-main.service -After=postgresql@9.4-main.service [Service] Type=simple From 458342159740c50288a94275d07bc01809dc4e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 26 Jun 2020 15:20:59 +0200 Subject: [PATCH 080/327] Connect to the PostgreSQL primary server instead of localhost Move the db and user creation to its own recipe Refs #186 --- .../kosmos-mastodon/recipes/default.rb | 40 +++----------- .../kosmos-mastodon/recipes/pg_db.rb | 52 +++++++++++++++++++ .../templates/default/env.production.erb | 8 +-- 3 files changed, 60 insertions(+), 40 deletions(-) create mode 100644 site-cookbooks/kosmos-mastodon/recipes/pg_db.rb diff --git a/site-cookbooks/kosmos-mastodon/recipes/default.rb b/site-cookbooks/kosmos-mastodon/recipes/default.rb index 634a9d0..053b232 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/default.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/default.rb @@ -26,7 +26,6 @@ include_recipe "kosmos-nodejs" include_recipe "kosmos-redis" -include_recipe "kosmos-postgresql" include_recipe "java" elasticsearch_user 'elasticsearch' @@ -42,22 +41,11 @@ end elasticsearch_service 'elasticsearch' -# TODO: Remove the condition once we have migrated mastodon to andromeda -unless platform?('ubuntu') && node[:platform_version].to_f < 18.04 - postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') - - postgresql_user 'mastodon' do - action :create - password postgresql_data_bag_item['mastodon_user_password'] - end - - postgresql_database 'mastodon' do - owner 'mastodon' - action :create - end -else - postgresql_data_bag_item = {} -end +postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') +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] mastodon_path = node["kosmos-mastodon"]["directory"] @@ -169,7 +157,8 @@ application mastodon_path do s3_region: "eu-west-1", vapid_private_key: mastodon_credentials['vapid_private_key'], vapid_public_key: mastodon_credentials['vapid_public_key'], - db_pass: postgresql_data_bag_item['mastodon_user_password'] + db_pass: postgresql_data_bag_item['mastodon_user_password'], + db_host: postgresql_server end execute "bundle install" do @@ -214,18 +203,3 @@ application mastodon_path do action [:enable, :start] end end - -# -# Backup -# - -unless node.chef_environment == "development" - unless node["backup"]["postgresql"]["databases"].keys.include? 'mastodon' - node.override["backup"]["postgresql"]["databases"]["mastodon"] = { - username: "mastodon", - password: postgresql_data_bag_item['mastodon_user_password'] - } - end - - include_recipe "backup" -end diff --git a/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb b/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb new file mode 100644 index 0000000..4f0ee9f --- /dev/null +++ b/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb @@ -0,0 +1,52 @@ +# +# Cookbook Name:: kosmos-mastodon +# Recipe:: pg_db +# +# 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. + +postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') + +postgresql_user 'mastodon' do + action :create + password postgresql_data_bag_item['mastodon_user_password'] +end + +postgresql_database 'mastodon' do + owner 'mastodon' + action :create +end + +# +# Backup +# + +unless node.chef_environment == "development" + unless node["backup"]["postgresql"]["databases"].keys.include? 'mastodon' + node.override["backup"]["postgresql"]["databases"]["mastodon"] = { + username: "mastodon", + password: postgresql_data_bag_item['mastodon_user_password'] + } + end + + include_recipe "backup" +end diff --git a/site-cookbooks/kosmos-mastodon/templates/default/env.production.erb b/site-cookbooks/kosmos-mastodon/templates/default/env.production.erb index eb3b559..7cb7adc 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/env.production.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/env.production.erb @@ -1,15 +1,9 @@ # Service dependencies REDIS_URL=<%= @redis_url %> -DB_HOST=localhost +DB_HOST=<%= @db_host %> DB_NAME=mastodon -# TODO: Remove the condition once we have migrated mastodon to andromeda -<% if node[:platform_version].to_f < 18.04 -%> -DB_USER=postgres -DB_PASS=<%= node['postgresql']['password']['postgres'] %> -<% else -%> DB_USER=mastodon DB_PASS=<%= @db_pass %> -<% end -%> DB_PORT=5432 # Federation From d2126f6153e8880bd2407f7d0889e84509f1cce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 22 Jul 2020 15:59:27 +0200 Subject: [PATCH 081/327] Use the right variable for the TLS cert's domain `domain` was undefined. `new_resource.hostname` is ldap.kosmos.org and is what we need Fixes #193 --- site-cookbooks/kosmos-dirsrv/resources/instance.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/site-cookbooks/kosmos-dirsrv/resources/instance.rb b/site-cookbooks/kosmos-dirsrv/resources/instance.rb index 7faf1cd..79c5b5d 100644 --- a/site-cookbooks/kosmos-dirsrv/resources/instance.rb +++ b/site-cookbooks/kosmos-dirsrv/resources/instance.rb @@ -157,16 +157,16 @@ done end nginx_certbot_site new_resource.hostname do - notifies :run, "execute[letsencrypt cert for #{domain}]", :delayed + notifies :run, "execute[letsencrypt cert for #{new_resource.hostname}]", :delayed end # Generate a Let's Encrypt cert (only if the nginx vhost exists and no cert # has been generated before. The renew cron will take care of renewing - execute "letsencrypt cert for #{domain}" do - command "/usr/bin/certbot certonly --webroot --agree-tos --email ops@kosmos.org --webroot-path #{root_directory} --deploy-hook /etc/letsencrypt/renewal-hooks/deploy/dirsrv -d #{domain} -n" + execute "letsencrypt cert for #{new_resource.hostname}" do + command "/usr/bin/certbot certonly --webroot --agree-tos --email ops@kosmos.org --webroot-path #{root_directory} --deploy-hook /etc/letsencrypt/renewal-hooks/deploy/dirsrv -d #{new_resource.hostname} -n" only_if do - ::File.exist?("#{node['nginx']['dir']}/sites-enabled/#{domain}_certbot") && - !::File.exist?("/etc/letsencrypt/live/#{domain}/fullchain.pem") + ::File.exist?("#{node['nginx']['dir']}/sites-enabled/#{new_resource.hostname}_certbot") && + !::File.exist?("/etc/letsencrypt/live/#{new_resource.hostname}/fullchain.pem") end notifies :run, "execute[add tls config]", :immediately end From 44b49ddd571dab0baec24d2e3c397f613747268f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 30 Jul 2020 11:58:52 +0200 Subject: [PATCH 082/327] Upgrade nginx to the latest mainline version --- site-cookbooks/kosmos-nginx/recipes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-nginx/recipes/default.rb b/site-cookbooks/kosmos-nginx/recipes/default.rb index ddff5b2..87f386f 100644 --- a/site-cookbooks/kosmos-nginx/recipes/default.rb +++ b/site-cookbooks/kosmos-nginx/recipes/default.rb @@ -47,7 +47,7 @@ include_recipe 'nginx' # Override the nginx package resource to set a specific version, allowing # to upgrade it edit_resource!(:package, 'nginx') do - version "1.17.3-1~#{node['lsb']['codename']}" + version "1.19.1-1~#{node['lsb']['codename']}" notifies :reload, 'ohai[reload_nginx]', :immediately end From 3f7894bd46474a2489752b0d317cd23ca933bb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 30 Jul 2020 11:59:30 +0200 Subject: [PATCH 083/327] Run Chef again after upgrading centaurus to Ubuntu 20.04 Closes #195 --- nodes/centaurus.kosmos.org.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nodes/centaurus.kosmos.org.json b/nodes/centaurus.kosmos.org.json index 777e9cd..3fd6a8b 100644 --- a/nodes/centaurus.kosmos.org.json +++ b/nodes/centaurus.kosmos.org.json @@ -8,11 +8,12 @@ "automatic": { "fqdn": "centaurus.kosmos.org", "os": "linux", - "os_version": "4.15.0-101-generic", + "os_version": "5.4.0-42-generic", "hostname": "centaurus", "ipaddress": "78.46.59.98", "roles": [ "gitea", + "postgresql_client", "postgresql_replica" ], "recipes": [ @@ -30,6 +31,7 @@ "ntp::default", "ntp::apparmor", "kosmos-base::systemd_emails", + "apt::unattended-upgrades", "kosmos-base::firewall", "kosmos-postfix::default", "postfix::default", @@ -54,7 +56,7 @@ "build-essential::default" ], "platform": "ubuntu", - "platform_version": "18.04", + "platform_version": "20.04", "cloud": null, "chef_packages": { "ohai": { From 5e5bbe07dc9fc18c71694f1cfa3839ce9dd06292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 30 Jul 2020 12:16:04 +0200 Subject: [PATCH 084/327] Restart gitea after upgrading it --- site-cookbooks/kosmos_gitea/recipes/default.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/site-cookbooks/kosmos_gitea/recipes/default.rb b/site-cookbooks/kosmos_gitea/recipes/default.rb index e159833..dea96a4 100644 --- a/site-cookbooks/kosmos_gitea/recipes/default.rb +++ b/site-cookbooks/kosmos_gitea/recipes/default.rb @@ -112,6 +112,7 @@ remote_file gitea_binary_path do source node['kosmos_gitea']['binary_url'] checksum node['kosmos_gitea']['binary_checksum'] mode "0755" + notifies :restart, "service[gitea]", :delayed end execute "systemctl daemon-reload" do From 924f67d8a84bee048d1dc22070271f4c9094c62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 30 Jul 2020 12:16:31 +0200 Subject: [PATCH 085/327] Update Gitea to 1.12.3 Closes #189 --- site-cookbooks/kosmos_gitea/attributes/default.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos_gitea/attributes/default.rb b/site-cookbooks/kosmos_gitea/attributes/default.rb index 90251d8..3fa3473 100644 --- a/site-cookbooks/kosmos_gitea/attributes/default.rb +++ b/site-cookbooks/kosmos_gitea/attributes/default.rb @@ -1,6 +1,6 @@ -gitea_version = "1.11.5" +gitea_version = "1.12.3" 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"]["binary_checksum"] = "6bfda9a12dc248360d34954b087ca6319f7310c61dc32b34c5e0675fdd45e0f4" node.default["kosmos_gitea"]["nginx"]["domain"] = "gitea.kosmos.org" node.default["kosmos_gitea"]["working_directory"] = "/var/lib/gitea" From 41fd1576ad862553567b372a2efb3650964fd525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 30 Jul 2020 12:33:09 +0200 Subject: [PATCH 086/327] Override the header template to remove the Roboto font Using the system font instead --- .../files/custom/templates/custom/header.tmpl | 3 +++ site-cookbooks/kosmos_gitea/recipes/default.rb | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 site-cookbooks/kosmos_gitea/files/custom/templates/custom/header.tmpl diff --git a/site-cookbooks/kosmos_gitea/files/custom/templates/custom/header.tmpl b/site-cookbooks/kosmos_gitea/files/custom/templates/custom/header.tmpl new file mode 100644 index 0000000..61f1c59 --- /dev/null +++ b/site-cookbooks/kosmos_gitea/files/custom/templates/custom/header.tmpl @@ -0,0 +1,3 @@ + diff --git a/site-cookbooks/kosmos_gitea/recipes/default.rb b/site-cookbooks/kosmos_gitea/recipes/default.rb index dea96a4..2cc43c5 100644 --- a/site-cookbooks/kosmos_gitea/recipes/default.rb +++ b/site-cookbooks/kosmos_gitea/recipes/default.rb @@ -56,7 +56,7 @@ directory working_directory do mode "0750" end -%w(custom custom/options custom/options/label).each do |path| +%w(custom custom/options custom/options/label custom/templates custom/templates/custom).each do |path| directory "#{working_directory}/#{path}" do owner "git" group "git" @@ -70,6 +70,16 @@ cookbook_file "#{working_directory}/custom/options/label/Kosmos" do owner "git" group "git" mode "0640" + notifies :restart, "service[gitea]", :delayed +end + +# Kosmos header template +cookbook_file "#{working_directory}/custom/templates/custom/header.tmpl" do + source "custom/templates/custom/header.tmpl" + owner "git" + group "git" + mode "0640" + notifies :restart, "service[gitea]", :delayed end directory config_directory do From af0717a65b898f79f444a7dc173bd3ef098a01ea Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 2 Aug 2020 21:00:10 +0200 Subject: [PATCH 087/327] Fix comet icon on maintenance page The data URI declares an SVG source, but this was actually a PNG. Hence the failure in Chrome. This change turns it into an actual inline SVG and uses UTF8 encoding instead of base64, because SVG is just text anyway. fixes #61 --- site-cookbooks/kosmos-nginx/files/default/maintenance.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-nginx/files/default/maintenance.html b/site-cookbooks/kosmos-nginx/files/default/maintenance.html index da2e94e..e387786 100644 --- a/site-cookbooks/kosmos-nginx/files/default/maintenance.html +++ b/site-cookbooks/kosmos-nginx/files/default/maintenance.html @@ -22,7 +22,7 @@

Back soon

From 9a28a03265f79bc6f9ac8c2ff419de787c5b9770 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 5 Aug 2020 15:53:13 +0200 Subject: [PATCH 088/327] Increase size limit for Gitea uploads/attachments The default limit in nginx is only 1MB. This increases it to 20MB. fixes #188 --- site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb b/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb index a77bc02..2540434 100644 --- a/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb +++ b/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb @@ -22,6 +22,8 @@ server { } <% end -%> + client_max_body_size 20M; + location / { # Increase number of buffers. Default is 8 proxy_buffers 1024 8k; From 47105b2a1cf0cb6d26a5faf5899fbff0b9f598ec Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 5 Dec 2019 12:28:00 +0300 Subject: [PATCH 089/327] Initial version of bitcoin cookbook --- .../kosmos-bitcoin/.delivery/project.toml | 34 ++++++ site-cookbooks/kosmos-bitcoin/.gitignore | 22 ++++ site-cookbooks/kosmos-bitcoin/CHANGELOG.md | 11 ++ site-cookbooks/kosmos-bitcoin/LICENSE | 3 + site-cookbooks/kosmos-bitcoin/Policyfile.rb | 16 +++ site-cookbooks/kosmos-bitcoin/README.md | 3 + .../kosmos-bitcoin/attributes/default.rb | 2 + site-cookbooks/kosmos-bitcoin/chefignore | 110 ++++++++++++++++++ site-cookbooks/kosmos-bitcoin/kitchen.yml | 32 +++++ site-cookbooks/kosmos-bitcoin/metadata.rb | 20 ++++ .../kosmos-bitcoin/recipes/default.rb | 44 +++++++ .../kosmos-bitcoin/spec/spec_helper.rb | 2 + .../spec/unit/recipes/default_spec.rb | 29 +++++ .../test/integration/default/default_test.rb | 16 +++ 14 files changed, 344 insertions(+) create mode 100644 site-cookbooks/kosmos-bitcoin/.delivery/project.toml create mode 100644 site-cookbooks/kosmos-bitcoin/.gitignore create mode 100644 site-cookbooks/kosmos-bitcoin/CHANGELOG.md create mode 100644 site-cookbooks/kosmos-bitcoin/LICENSE create mode 100644 site-cookbooks/kosmos-bitcoin/Policyfile.rb create mode 100644 site-cookbooks/kosmos-bitcoin/README.md create mode 100644 site-cookbooks/kosmos-bitcoin/attributes/default.rb create mode 100644 site-cookbooks/kosmos-bitcoin/chefignore create mode 100644 site-cookbooks/kosmos-bitcoin/kitchen.yml create mode 100644 site-cookbooks/kosmos-bitcoin/metadata.rb create mode 100644 site-cookbooks/kosmos-bitcoin/recipes/default.rb create mode 100644 site-cookbooks/kosmos-bitcoin/spec/spec_helper.rb create mode 100644 site-cookbooks/kosmos-bitcoin/spec/unit/recipes/default_spec.rb create mode 100644 site-cookbooks/kosmos-bitcoin/test/integration/default/default_test.rb diff --git a/site-cookbooks/kosmos-bitcoin/.delivery/project.toml b/site-cookbooks/kosmos-bitcoin/.delivery/project.toml new file mode 100644 index 0000000..2868a95 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/.delivery/project.toml @@ -0,0 +1,34 @@ +# Delivery for Local Phases Execution +# +# This file allows you to execute test phases locally on a workstation or +# in a CI pipeline. The delivery-cli will read this file and execute the +# command(s) that are configured for each phase. You can customize them +# by just modifying the phase key on this file. +# +# By default these phases are configured for Cookbook Workflow only +# + +[local_phases] +unit = "chef exec rspec spec/" +lint = "chef exec cookstyle" +# Foodcritic includes rules only appropriate for community cookbooks +# uploaded to Supermarket. We turn off any rules tagged "supermarket" +# by default. If you plan to share this cookbook you should remove +# '-t ~supermarket' below to enable supermarket rules. +syntax = "chef exec foodcritic . -t ~supermarket" +provision = "chef exec kitchen create" +deploy = "chef exec kitchen converge" +smoke = "chef exec kitchen verify" +# The functional phase is optional, you can define it by uncommenting +# the line below and running the command: `delivery local functional` +# functional = "" +cleanup = "chef exec kitchen destroy" + +# Remote project.toml file +# +# Instead of the local phases above, you may specify a remote URI location for +# the `project.toml` file. This is useful for teams that wish to centrally +# manage the behavior of the `delivery local` command across many different +# projects. +# +# remote_file = "https://url/project.toml" diff --git a/site-cookbooks/kosmos-bitcoin/.gitignore b/site-cookbooks/kosmos-bitcoin/.gitignore new file mode 100644 index 0000000..9abf29f --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/.gitignore @@ -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 diff --git a/site-cookbooks/kosmos-bitcoin/CHANGELOG.md b/site-cookbooks/kosmos-bitcoin/CHANGELOG.md new file mode 100644 index 0000000..533e3aa --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/CHANGELOG.md @@ -0,0 +1,11 @@ +# kosmos-bitcoin CHANGELOG + +This file is used to list changes made in each version of the kosmos-bitcoin cookbook. + +# 0.1.0 + +Initial release. + +- change 0 +- change 1 + diff --git a/site-cookbooks/kosmos-bitcoin/LICENSE b/site-cookbooks/kosmos-bitcoin/LICENSE new file mode 100644 index 0000000..10b5688 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/LICENSE @@ -0,0 +1,3 @@ +Copyright 2019 The Authors + +All rights reserved, do not redistribute. diff --git a/site-cookbooks/kosmos-bitcoin/Policyfile.rb b/site-cookbooks/kosmos-bitcoin/Policyfile.rb new file mode 100644 index 0000000..333e86e --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/Policyfile.rb @@ -0,0 +1,16 @@ +# Policyfile.rb - Describe how you want Chef Infra Client to build your system. +# +# For more information on the Policyfile feature, visit +# https://docs.chef.io/policyfile.html + +# A name that describes what the system you're building with Chef does. +name 'kosmos-bitcoin' + +# Where to find external cookbooks: +default_source :supermarket + +# run_list: chef-client will run these recipes in the order specified. +run_list 'kosmos-bitcoin::default' + +# Specify a custom source for a single cookbook: +cookbook 'kosmos-bitcoin', path: '.' diff --git a/site-cookbooks/kosmos-bitcoin/README.md b/site-cookbooks/kosmos-bitcoin/README.md new file mode 100644 index 0000000..85db7e1 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/README.md @@ -0,0 +1,3 @@ +# kosmos-bitcoin + +Installs/configures bitcoin core node diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb new file mode 100644 index 0000000..c0b0831 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -0,0 +1,2 @@ +node.default['bitcoin']['username'] = 'satoshi' +node.default['bitcoin']['datadir'] = '/mnt/data/bitcoin' diff --git a/site-cookbooks/kosmos-bitcoin/chefignore b/site-cookbooks/kosmos-bitcoin/chefignore new file mode 100644 index 0000000..5039e1c --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/chefignore @@ -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 diff --git a/site-cookbooks/kosmos-bitcoin/kitchen.yml b/site-cookbooks/kosmos-bitcoin/kitchen.yml new file mode 100644 index 0000000..e5bbf3c --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/kitchen.yml @@ -0,0 +1,32 @@ +--- +driver: + name: vagrant + +## The forwarded_port port feature lets you connect to ports on the VM guest via +## localhost on the host. +## see also: https://www.vagrantup.com/docs/networking/forwarded_ports.html + +# network: +# - ["forwarded_port", {guest: 80, host: 8080}] + +provisioner: + name: chef_zero + + ## product_name and product_version specifies a specific Chef product and version to install. + ## see the Chef documentation for more details: https://docs.chef.io/config_yml_kitchen.html + # product_name: chef + # product_version: 15 + +verifier: + name: inspec + +platforms: + - name: ubuntu-18.04 + - name: centos-7 + +suites: + - name: default + verifier: + inspec_tests: + - test/integration/default + attributes: diff --git a/site-cookbooks/kosmos-bitcoin/metadata.rb b/site-cookbooks/kosmos-bitcoin/metadata.rb new file mode 100644 index 0000000..f2f0bb3 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/metadata.rb @@ -0,0 +1,20 @@ +name 'kosmos-bitcoin' +maintainer 'The Authors' +maintainer_email 'you@example.com' +license 'All Rights Reserved' +description 'Installs/Configures kosmos-bitcoin' +long_description 'Installs/Configures kosmos-bitcoin' +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//kosmos-bitcoin/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//kosmos-bitcoin' diff --git a/site-cookbooks/kosmos-bitcoin/recipes/default.rb b/site-cookbooks/kosmos-bitcoin/recipes/default.rb new file mode 100644 index 0000000..594251e --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/recipes/default.rb @@ -0,0 +1,44 @@ +# +# Cookbook:: kosmos-bitcoin +# Recipe:: default +# +# The MIT License (MIT) +# +# Copyright:: 2019, 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. +# + +package 'snapd' + +snap_package 'bitcoin-core' + +bitcoin_user = node['bitcoin']['username'] + +# TODO create bitcoin datadir +# TODO create bitcoin.conf in datadir + +mount "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin" do + device node['bitcoin']['data_dir'] + fstype 'none' + options 'bind' + action [:mount] +end + +# TODO create systemd service for bitcoin-core.daemon diff --git a/site-cookbooks/kosmos-bitcoin/spec/spec_helper.rb b/site-cookbooks/kosmos-bitcoin/spec/spec_helper.rb new file mode 100644 index 0000000..6cd61e5 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/spec/spec_helper.rb @@ -0,0 +1,2 @@ +require 'chefspec' +require 'chefspec/policyfile' diff --git a/site-cookbooks/kosmos-bitcoin/spec/unit/recipes/default_spec.rb b/site-cookbooks/kosmos-bitcoin/spec/unit/recipes/default_spec.rb new file mode 100644 index 0000000..f4b411c --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/spec/unit/recipes/default_spec.rb @@ -0,0 +1,29 @@ +# +# Cookbook:: kosmos-bitcoin +# Spec:: default +# +# Copyright:: 2019, The Authors, All Rights Reserved. + +require 'spec_helper' + +describe 'kosmos-bitcoin::default' do + context 'When all attributes are default, on Ubuntu 18.04' do + # for a complete list of available platforms and versions see: + # https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md + platform 'ubuntu', '18.04' + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end + end + + context 'When all attributes are default, on CentOS 7' do + # for a complete list of available platforms and versions see: + # https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md + platform 'centos', '7' + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end + end +end diff --git a/site-cookbooks/kosmos-bitcoin/test/integration/default/default_test.rb b/site-cookbooks/kosmos-bitcoin/test/integration/default/default_test.rb new file mode 100644 index 0000000..71aba37 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/test/integration/default/default_test.rb @@ -0,0 +1,16 @@ +# InSpec test for recipe kosmos-bitcoin::default + +# The InSpec reference, with examples and extensive documentation, can be +# found at https://www.inspec.io/docs/reference/resources/ + +unless os.windows? + # This is an example test, replace with your own test. + describe user('root'), :skip do + it { should exist } + end +end + +# This is an example test, replace it with your own test. +describe port(80), :skip do + it { should_not be_listening } +end From 09527e693b3ff0644b90e33748e0b62e22f6eff4 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 21 Jan 2020 15:18:10 -0500 Subject: [PATCH 090/327] WIP bitcoind config --- Vagrantfile | 3 +- .../kosmos-bitcoin/attributes/default.rb | 26 ++++++- .../recipes/{default.rb => snapd.rb} | 26 +++++-- .../kosmos-bitcoin/templates/andromeda.conf | 69 +++++++++++++++++++ .../kosmos-bitcoin/templates/bitcoin.conf.erb | 34 +++++++++ 5 files changed, 151 insertions(+), 7 deletions(-) rename site-cookbooks/kosmos-bitcoin/recipes/{default.rb => snapd.rb} (68%) create mode 100644 site-cookbooks/kosmos-bitcoin/templates/andromeda.conf create mode 100644 site-cookbooks/kosmos-bitcoin/templates/bitcoin.conf.erb diff --git a/Vagrantfile b/Vagrantfile index cc353fa..2b3b4aa 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -95,7 +95,8 @@ Vagrant.configure(2) do |config| chef.environment = 'development' chef.add_recipe 'kosmos-base' chef.add_recipe 'kosmos_encfs' - # chef.add_recipe 'kosmos-postgresql::default' + # chef.add_recipe 'kosmos-bitcoin::snapd' + # chef.add_recipe 'kosmos-mediawiki' # chef.add_recipe 'kosmos-wordpress' # chef.add_recipe 'kosmos-ejabberd' # chef.add_recipe 'kosmos-hubot::botka_freenode' diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index c0b0831..62d6aca 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -1,2 +1,24 @@ -node.default['bitcoin']['username'] = 'satoshi' -node.default['bitcoin']['datadir'] = '/mnt/data/bitcoin' +node.default['bitcoin']['username'] = 'bitcoind' +node.default['bitcoin']['usergroup'] = 'bitcoind' +node.default['bitcoin']['datadir'] = '/mnt/data/bitcoin' + +node.default['bitcoin']['conf'] = { + testnet: 0, + irc: 1, + dnsseed: 1, + upnp: 1, + checkblocks: 10, + checklevel: 1, + txindex: 1, + whitelist: "127.0.0.1", + listen: 1, + server: 1, + rpcport: 8332, + rpcssl: 0, + rpcuser: 'bitcoind', + rpcbind: "127.0.0.1:8336", + port: 8335, + gen: 0, + zmqpubrawblock: "tcp://127.0.0.1:8337", + zmqpubrawtx: "tcp://127.0.0.1:8338" +} diff --git a/site-cookbooks/kosmos-bitcoin/recipes/default.rb b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb similarity index 68% rename from site-cookbooks/kosmos-bitcoin/recipes/default.rb rename to site-cookbooks/kosmos-bitcoin/recipes/snapd.rb index 594251e..a19b861 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb @@ -1,6 +1,6 @@ # # Cookbook:: kosmos-bitcoin -# Recipe:: default +# Recipe:: snapd # # The MIT License (MIT) # @@ -29,10 +29,28 @@ package 'snapd' snap_package 'bitcoin-core' -bitcoin_user = node['bitcoin']['username'] +bitcoin_user = node['bitcoin']['username'] +bitcoin_group = node['bitcoin']['usergroup'] +bitcoin_datadir = node['bitcoin']['datadir'] -# TODO create bitcoin datadir -# TODO create bitcoin.conf in datadir +directory bitcoin_datadir do + owner bitcoin_user + group bitcoin_group + mode '0755' + recursive true + action :create +end + +template "#{bitcoin_datadir}/bitcoin.conf" do + owner bitcoin_user + group bitcoin_group + variables conf: node['bitcoin']['conf'], + mainnet_conf: node['bitcoin']['mainnet_conf'], + testnet_conf: node['bitcoin']['testnet_conf'], + regtest_conf: node['bitcoin']['regtest_conf'] + action :create + # notifies :reload, "service[bitcoin]", :delayed +end mount "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin" do device node['bitcoin']['data_dir'] diff --git a/site-cookbooks/kosmos-bitcoin/templates/andromeda.conf b/site-cookbooks/kosmos-bitcoin/templates/andromeda.conf new file mode 100644 index 0000000..12ad02b --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/templates/andromeda.conf @@ -0,0 +1,69 @@ +# Network-related settings: + +testnet=0 +irc=1 +dnsseed=1 +upnp=1 +checkblocks=10 +checklevel=1 +txindex=1 +whitelist=127.0.0.1 + +# Maximum number of inbound+outbound connections. +#maxconnections= + +listen=1 + + +# JSON-RPC options (for controlling a running Bitcoin/bitcoind process) + +# server=1 tells Bitcoin to accept JSON-RPC commands. +server=1 + +# You must set rpcuser and rpcpassword to secure the JSON-RPC api +rpcuser=kosmos +rpcpassword=yunobuttcoin + +# By default, only RPC connections from localhost are allowed. Specify +# as many rpcallowip= settings as you like to allow connections from +# other hosts (and you may use * as a wildcard character): +#rpcallowip=192.168.1.* +rpcallowip=127.0.0.1 + +# Listen for RPC connections on this TCP port: +rpcbind=127.0.0.1:8336 + + +# Listen for P2P connections on this TCP port: +port=8335 + +# Use Secure Sockets Layer (also known as TLS or HTTPS) to communicate +# with Bitcoin -server or bitcoind +rpcssl=0 + +# OpenSSL settings used when rpcssl=1 +#rpcsslciphers=TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH + + +# Miscellaneous options + +# Set gen=1 to attempt to generate bitcoins +gen=0 + +# Use SSE instructions to try to generate bitcoins faster. +#4way=1 + +# Pre-generate this many public/private key pairs, so wallet backups will be valid for +# both prior transactions and several dozen future transactions. +#keypool=100 + +# Pay an optional transaction fee every time you send bitcoins. Transactions with fees +# are more likely than free transactions to be included in generated blocks, so may +# be validated sooner. +#paytxfee=0.00 + +# Allow direct connections for the 'pay via IP address' feature. +#allowreceivebyip=1 + +zmqpubrawblock=tcp://127.0.0.1:8337 +zmqpubrawtx=tcp://127.0.0.1:8338 diff --git a/site-cookbooks/kosmos-bitcoin/templates/bitcoin.conf.erb b/site-cookbooks/kosmos-bitcoin/templates/bitcoin.conf.erb new file mode 100644 index 0000000..9e04e05 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/templates/bitcoin.conf.erb @@ -0,0 +1,34 @@ +## +## bitcoin.conf configuration file. Lines beginning with # are comments. +## +## Generated by Chef. Do not edit directly, or your changes will be overwritten +## during the next Chef run! +## + +<% @conf.each do |key, value| %> + <%= "#{key}=#{value}" %> +<% end %> + +<% if @mainnet_conf %> +# Options only for mainnet +[main] +<% @mainnet_conf.each do |key, value| %> + <%= "#{key}=#{value}" %> +<% end %> +<% end %> + +<% if @testnet_conf %> +# Options only for testnet +[test] +<% @testnet_conf.each do |key, value| %> + <%= "#{key}=#{value}" %> +<% end %> +<% end %> + +<% if @regtest_conf %> +# Options only for regtest +[regtest] +<% @regtest_conf.each do |key, value| %> + <%= "#{key}=#{value}" %> +<% end %> +<% end %> From 1b9a4aad17024c31f5e5a13f96fa29c705b2fd1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 22 Jan 2020 12:32:38 +0100 Subject: [PATCH 091/327] Work around a bug in Chef's snap_package resource https://github.com/chef/chef/issues/8827 `snap install` returns 0 when a package is already installed, so no need for a guard clause --- site-cookbooks/kosmos-bitcoin/recipes/snapd.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb index a19b861..0a777fc 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb @@ -25,9 +25,9 @@ # THE SOFTWARE. # -package 'snapd' - -snap_package 'bitcoin-core' +# FIXME: Switch to the snap_package resource when it gets fixed: +# https://github.com/chef/chef/issues/8827 +execute "snap install bitcoin-core" bitcoin_user = node['bitcoin']['username'] bitcoin_group = node['bitcoin']['usergroup'] From 069246cf4103924cc932acccaabc4a89aebc3a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 22 Jan 2020 12:33:29 +0100 Subject: [PATCH 092/327] Create the bitcoind user and its home directory --- site-cookbooks/kosmos-bitcoin/recipes/snapd.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb index 0a777fc..9cf8895 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb @@ -33,6 +33,10 @@ bitcoin_user = node['bitcoin']['username'] bitcoin_group = node['bitcoin']['usergroup'] bitcoin_datadir = node['bitcoin']['datadir'] +user bitcoin_user do + manage_home true +end + directory bitcoin_datadir do owner bitcoin_user group bitcoin_group From aedf7bcb62ed3353d337635ba7b9644859cce6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 22 Jan 2020 12:34:18 +0100 Subject: [PATCH 093/327] Create the snap mount directory in the user's home --- site-cookbooks/kosmos-bitcoin/recipes/snapd.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb index 9cf8895..7b0e6f4 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb @@ -56,6 +56,14 @@ template "#{bitcoin_datadir}/bitcoin.conf" do # notifies :reload, "service[bitcoin]", :delayed end +directory "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin" do + owner bitcoin_user + group bitcoin_group + mode '0750' + recursive true + action :create +end + mount "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin" do device node['bitcoin']['data_dir'] fstype 'none' From e31f480f2775b386c51f5358128d0ecd1690ada0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 22 Jan 2020 12:34:38 +0100 Subject: [PATCH 094/327] Fix the attribute name --- site-cookbooks/kosmos-bitcoin/recipes/snapd.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb index 7b0e6f4..e9c9b03 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb @@ -65,7 +65,7 @@ directory "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin" do end mount "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin" do - device node['bitcoin']['data_dir'] + device node['bitcoin']['datadir'] fstype 'none' options 'bind' action [:mount] From 4a6a02c137d868eec492e00a586ecebc58983096 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 22 Jan 2020 13:35:52 -0500 Subject: [PATCH 095/327] Use 0.19 stable channel Instead of relying on the default channel --- site-cookbooks/kosmos-bitcoin/recipes/snapd.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb index e9c9b03..405e6f7 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb @@ -27,7 +27,7 @@ # FIXME: Switch to the snap_package resource when it gets fixed: # https://github.com/chef/chef/issues/8827 -execute "snap install bitcoin-core" +execute "snap install bitcoin-core --channel=0.19/stable" bitcoin_user = node['bitcoin']['username'] bitcoin_group = node['bitcoin']['usergroup'] From c8122a44f1e572d5105eed001bfd1405288b6c68 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 22 Jan 2020 13:37:00 -0500 Subject: [PATCH 096/327] Add systemd service Plus some refactoring --- .../kosmos-bitcoin/recipes/snapd.rb | 36 ++++++++-- .../kosmos-bitcoin/templates/andromeda.conf | 69 ------------------- .../kosmos-bitcoin/templates/bitcoin.conf.erb | 8 +-- 3 files changed, 35 insertions(+), 78 deletions(-) delete mode 100644 site-cookbooks/kosmos-bitcoin/templates/andromeda.conf diff --git a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb index 405e6f7..43e8153 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb @@ -32,9 +32,11 @@ execute "snap install bitcoin-core --channel=0.19/stable" bitcoin_user = node['bitcoin']['username'] bitcoin_group = node['bitcoin']['usergroup'] bitcoin_datadir = node['bitcoin']['datadir'] +bitcoin_snapdir = "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin" user bitcoin_user do manage_home true + shell "/bin/bash" end directory bitcoin_datadir do @@ -53,10 +55,10 @@ template "#{bitcoin_datadir}/bitcoin.conf" do testnet_conf: node['bitcoin']['testnet_conf'], regtest_conf: node['bitcoin']['regtest_conf'] action :create - # notifies :reload, "service[bitcoin]", :delayed + # notifies :reload, "service[bitcoind]", :delayed end -directory "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin" do +directory bitcoin_snapdir do owner bitcoin_user group bitcoin_group mode '0750' @@ -64,11 +66,35 @@ directory "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin" do action :create end -mount "/home/#{bitcoin_user}/snap/bitcoin-core/common/.bitcoin" do - device node['bitcoin']['datadir'] +execute "chown -R #{bitcoin_user}:#{bitcoin_group} /home/#{bitcoin_user}/snap" + +mount bitcoin_snapdir do + device bitcoin_datadir fstype 'none' options 'bind' action [:mount] end -# TODO create systemd service for bitcoin-core.daemon +systemd_unit 'bitcoind.service' do + content({ + Unit: { + Description: 'Bitcoin Core daemon', + Documentation: ['https://bitcoincore.org'], + After: 'network.target' + }, + Service: { + User: bitcoin_user, + Type: 'exec', + ExecStart: '/snap/bin/bitcoin-core.daemon', + PIDFile: "#{bitcoin_snapdir}/bitcoind.pid", + Restart: 'on-failure', + }, + Install: { + WantedBy: 'multi-user.target' + } + }) + + verify false + triggers_reload true + action :create +end diff --git a/site-cookbooks/kosmos-bitcoin/templates/andromeda.conf b/site-cookbooks/kosmos-bitcoin/templates/andromeda.conf deleted file mode 100644 index 12ad02b..0000000 --- a/site-cookbooks/kosmos-bitcoin/templates/andromeda.conf +++ /dev/null @@ -1,69 +0,0 @@ -# Network-related settings: - -testnet=0 -irc=1 -dnsseed=1 -upnp=1 -checkblocks=10 -checklevel=1 -txindex=1 -whitelist=127.0.0.1 - -# Maximum number of inbound+outbound connections. -#maxconnections= - -listen=1 - - -# JSON-RPC options (for controlling a running Bitcoin/bitcoind process) - -# server=1 tells Bitcoin to accept JSON-RPC commands. -server=1 - -# You must set rpcuser and rpcpassword to secure the JSON-RPC api -rpcuser=kosmos -rpcpassword=yunobuttcoin - -# By default, only RPC connections from localhost are allowed. Specify -# as many rpcallowip= settings as you like to allow connections from -# other hosts (and you may use * as a wildcard character): -#rpcallowip=192.168.1.* -rpcallowip=127.0.0.1 - -# Listen for RPC connections on this TCP port: -rpcbind=127.0.0.1:8336 - - -# Listen for P2P connections on this TCP port: -port=8335 - -# Use Secure Sockets Layer (also known as TLS or HTTPS) to communicate -# with Bitcoin -server or bitcoind -rpcssl=0 - -# OpenSSL settings used when rpcssl=1 -#rpcsslciphers=TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH - - -# Miscellaneous options - -# Set gen=1 to attempt to generate bitcoins -gen=0 - -# Use SSE instructions to try to generate bitcoins faster. -#4way=1 - -# Pre-generate this many public/private key pairs, so wallet backups will be valid for -# both prior transactions and several dozen future transactions. -#keypool=100 - -# Pay an optional transaction fee every time you send bitcoins. Transactions with fees -# are more likely than free transactions to be included in generated blocks, so may -# be validated sooner. -#paytxfee=0.00 - -# Allow direct connections for the 'pay via IP address' feature. -#allowreceivebyip=1 - -zmqpubrawblock=tcp://127.0.0.1:8337 -zmqpubrawtx=tcp://127.0.0.1:8338 diff --git a/site-cookbooks/kosmos-bitcoin/templates/bitcoin.conf.erb b/site-cookbooks/kosmos-bitcoin/templates/bitcoin.conf.erb index 9e04e05..b28ceea 100644 --- a/site-cookbooks/kosmos-bitcoin/templates/bitcoin.conf.erb +++ b/site-cookbooks/kosmos-bitcoin/templates/bitcoin.conf.erb @@ -6,14 +6,14 @@ ## <% @conf.each do |key, value| %> - <%= "#{key}=#{value}" %> +<%= "#{key}=#{value}" %> <% end %> <% if @mainnet_conf %> # Options only for mainnet [main] <% @mainnet_conf.each do |key, value| %> - <%= "#{key}=#{value}" %> +<%= "#{key}=#{value}" %> <% end %> <% end %> @@ -21,7 +21,7 @@ # Options only for testnet [test] <% @testnet_conf.each do |key, value| %> - <%= "#{key}=#{value}" %> +<%= "#{key}=#{value}" %> <% end %> <% end %> @@ -29,6 +29,6 @@ # Options only for regtest [regtest] <% @regtest_conf.each do |key, value| %> - <%= "#{key}=#{value}" %> +<%= "#{key}=#{value}" %> <% end %> <% end %> From 4889f40c6a9e1e219d13236053b1a4d748c571ea Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 15 Feb 2020 13:14:56 -0500 Subject: [PATCH 097/327] WIP --- environments/development.json | 22 +++++++++++++++++++ .../kosmos-bitcoin/attributes/default.rb | 10 ++++----- .../kosmos-bitcoin/recipes/snapd.rb | 5 ++--- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/environments/development.json b/environments/development.json index a6f79ca..7f8bff0 100644 --- a/environments/development.json +++ b/environments/development.json @@ -16,6 +16,28 @@ }, "kosmos-dirsrv": { "master_hostname": "localhost" + }, + "bitcoin": { + "conf": { + "testnet": 1, + "irc": 1, + "dnsseed": 1, + "upnp": 1, + "checkblocks": 10, + "checklevel": 1, + "txindex": 1, + "whitelist": "127.0.0.1", + "listen": 1, + "server": 1, + "rpcport": 8332, + "rpcssl": 0, + "rpcuser": "bitcoind", + "rpcbind": "127.0.0.1:8336", + "port": 8335, + "gen": 0, + "zmqpubrawblock": "tcp://127.0.0.1:8337", + "zmqpubrawtx": "tcp://127.0.0.1:8338" + } } } } diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 62d6aca..591a364 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -1,24 +1,22 @@ node.default['bitcoin']['username'] = 'bitcoind' node.default['bitcoin']['usergroup'] = 'bitcoind' node.default['bitcoin']['datadir'] = '/mnt/data/bitcoin' +node.default['bitcoin']['network'] = 'mainnet' node.default['bitcoin']['conf'] = { - testnet: 0, irc: 1, dnsseed: 1, upnp: 1, checkblocks: 10, checklevel: 1, txindex: 1, - whitelist: "127.0.0.1", + whitelist: '127.0.0.1', listen: 1, server: 1, - rpcport: 8332, rpcssl: 0, rpcuser: 'bitcoind', rpcbind: "127.0.0.1:8336", - port: 8335, gen: 0, - zmqpubrawblock: "tcp://127.0.0.1:8337", - zmqpubrawtx: "tcp://127.0.0.1:8338" + zmqpubrawblock: 'tcp://127.0.0.1:8337', + zmqpubrawtx: 'tcp://127.0.0.1:8338' } diff --git a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb index 43e8153..5d233aa 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb @@ -55,7 +55,7 @@ template "#{bitcoin_datadir}/bitcoin.conf" do testnet_conf: node['bitcoin']['testnet_conf'], regtest_conf: node['bitcoin']['regtest_conf'] action :create - # notifies :reload, "service[bitcoind]", :delayed + notifies :restart, "systemd_unit[bitcoind.service]", :delayed end directory bitcoin_snapdir do @@ -93,8 +93,7 @@ systemd_unit 'bitcoind.service' do WantedBy: 'multi-user.target' } }) - verify false triggers_reload true - action :create + action [:create, :enable, :start] end From 476316e13b509eb575c2fa70ed1a387a6cec68c6 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 16 Aug 2020 16:20:43 +0200 Subject: [PATCH 098/327] Always use latest/stable channel for bitcoind snap --- site-cookbooks/kosmos-bitcoin/recipes/snapd.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb index 5d233aa..7970f59 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb @@ -27,7 +27,7 @@ # FIXME: Switch to the snap_package resource when it gets fixed: # https://github.com/chef/chef/issues/8827 -execute "snap install bitcoin-core --channel=0.19/stable" +execute "snap install bitcoin-core --channel=latest/stable" bitcoin_user = node['bitcoin']['username'] bitcoin_group = node['bitcoin']['usergroup'] From bbbd0f7408c56e3be8042e8099ba02078c73c792 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 16 Aug 2020 16:25:06 +0200 Subject: [PATCH 099/327] Change default username --- site-cookbooks/kosmos-bitcoin/attributes/default.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 591a364..cb33666 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -1,5 +1,5 @@ -node.default['bitcoin']['username'] = 'bitcoind' -node.default['bitcoin']['usergroup'] = 'bitcoind' +node.default['bitcoin']['username'] = 'satoshi' +node.default['bitcoin']['usergroup'] = 'satoshi' node.default['bitcoin']['datadir'] = '/mnt/data/bitcoin' node.default['bitcoin']['network'] = 'mainnet' From 4606773440b43dc808947b7edfd0d1a0152308a1 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 16 Aug 2020 16:25:14 +0200 Subject: [PATCH 100/327] Update license note --- site-cookbooks/kosmos-bitcoin/recipes/snapd.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb index 7970f59..4339bf5 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb @@ -4,7 +4,7 @@ # # The MIT License (MIT) # -# Copyright:: 2019, Kosmos Developers +# 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 From 9795e77fdef09cbc167ffeebcf71edcbf06cff1e Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 16 Aug 2020 19:27:10 +0200 Subject: [PATCH 101/327] Bitcoin source recipe --- data_bags/credentials/bitcoin.json | 10 ++ nodes/draco.kosmos.org.json | 7 +- .../kosmos-bitcoin/attributes/default.rb | 10 +- site-cookbooks/kosmos-bitcoin/metadata.rb | 14 +- .../kosmos-bitcoin/recipes/source.rb | 144 ++++++++++++++++++ .../kosmos-bitcoin/templates/bitcoin.conf.erb | 8 +- 6 files changed, 178 insertions(+), 15 deletions(-) create mode 100644 data_bags/credentials/bitcoin.json create mode 100644 site-cookbooks/kosmos-bitcoin/recipes/source.rb diff --git a/data_bags/credentials/bitcoin.json b/data_bags/credentials/bitcoin.json new file mode 100644 index 0000000..3be7b2d --- /dev/null +++ b/data_bags/credentials/bitcoin.json @@ -0,0 +1,10 @@ +{ + "id": "bitcoin", + "rpcpassword": { + "encrypted_data": "dBXJXEYJIoWzo+TPg8CzaKfTo94SdowFDdQKVL/njQ==\n", + "iv": "UNragm2xuewXZu0v\n", + "auth_tag": "tfjO8qfvti3k5L3Ms2jPLw==\n", + "version": 3, + "cipher": "aes-256-gcm" + } +} \ No newline at end of file diff --git a/nodes/draco.kosmos.org.json b/nodes/draco.kosmos.org.json index e266fe1..34a8a7c 100644 --- a/nodes/draco.kosmos.org.json +++ b/nodes/draco.kosmos.org.json @@ -8,7 +8,7 @@ "automatic": { "fqdn": "draco.kosmos.org", "os": "linux", - "os_version": "5.4.0-37-generic", + "os_version": "5.4.0-42-generic", "hostname": "draco", "ipaddress": "148.251.237.73", "roles": [ @@ -20,6 +20,7 @@ "kosmos_encfs", "kosmos_encfs::default", "kosmos-postgresql::replica", + "kosmos-bitcoin::source", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -35,6 +36,7 @@ "hostname::default", "firewall::default", "chef-sugar::default", + "ark::default", "build-essential::default" ], "platform": "ubuntu", @@ -54,6 +56,7 @@ "run_list": [ "recipe[kosmos-base]", "recipe[kosmos_encfs]", - "role[postgresql_replica]" + "role[postgresql_replica]", + "recipe[kosmos-bitcoin::source]" ] } \ No newline at end of file diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index cb33666..4c01630 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -1,7 +1,9 @@ +node.default['bitcoin']['version'] = '0.20.1' +node.default['bitcoin']['checksum'] = '4bbd62fd6acfa5e9864ebf37a24a04bc2dcfe3e3222f056056288d854c53b978' node.default['bitcoin']['username'] = 'satoshi' -node.default['bitcoin']['usergroup'] = 'satoshi' -node.default['bitcoin']['datadir'] = '/mnt/data/bitcoin' +node.default['bitcoin']['usergroup'] = 'bitcoin' node.default['bitcoin']['network'] = 'mainnet' +node.default['bitcoin']['datadir'] = '/mnt/data/bitcoin' node.default['bitcoin']['conf'] = { irc: 1, @@ -14,8 +16,8 @@ node.default['bitcoin']['conf'] = { listen: 1, server: 1, rpcssl: 0, - rpcuser: 'bitcoind', - rpcbind: "127.0.0.1:8336", + rpcuser: 'satoshi', + rpcbind: "127.0.0.1:8332", gen: 0, zmqpubrawblock: 'tcp://127.0.0.1:8337', zmqpubrawtx: 'tcp://127.0.0.1:8338' diff --git a/site-cookbooks/kosmos-bitcoin/metadata.rb b/site-cookbooks/kosmos-bitcoin/metadata.rb index f2f0bb3..60121e3 100644 --- a/site-cookbooks/kosmos-bitcoin/metadata.rb +++ b/site-cookbooks/kosmos-bitcoin/metadata.rb @@ -1,9 +1,9 @@ name 'kosmos-bitcoin' -maintainer 'The Authors' -maintainer_email 'you@example.com' -license 'All Rights Reserved' -description 'Installs/Configures kosmos-bitcoin' -long_description 'Installs/Configures kosmos-bitcoin' +maintainer 'Kosmos Developers' +maintainer_email 'mail@kosmos.org' +license 'MIT' +description 'Installs/Configures Bitcoin Core' +long_description 'Installs/Configures Bitcoin Core' version '0.1.0' chef_version '>= 14.0' @@ -18,3 +18,7 @@ chef_version '>= 14.0' # a Supermarket. # # source_url 'https://github.com//kosmos-bitcoin' + +depends "ark" +depends "kosmos_encfs" +depends "ulimit" diff --git a/site-cookbooks/kosmos-bitcoin/recipes/source.rb b/site-cookbooks/kosmos-bitcoin/recipes/source.rb new file mode 100644 index 0000000..2766420 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/recipes/source.rb @@ -0,0 +1,144 @@ +# +# Cookbook:: kosmos-bitcoin +# Recipe:: source +# +# 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 'ark' + +build_essential + +%w{ libtool autotools-dev make automake cmake curl g++-multilib libtool + binutils-gold bsdmainutils pkg-config python3 patch }.each do |pkg| + apt_package pkg +end + +ark 'bitcoind' do + url "https://bitcoincore.org/bin/bitcoin-core-#{node['bitcoin']['version']}/bitcoin-#{node['bitcoin']['version']}.tar.gz" + checksum node['bitcoin']['checksum'] + action :put +end + +execute "Compile bitcoin-core dependencies" do + cwd "/usr/local/bitcoind/depends" + command "make NO_QT=1" + not_if { ::File.directory?("/usr/local/bitcoind/depends/x86_64-pc-linux-gnu") } +end + +execute "Configure bitcoin-core" do + cwd "/usr/local/bitcoind" + command [ + "./autogen.sh", + "./configure --prefix=$PWD/depends/x86_64-pc-linux-gnu" + ] + not_if { ::File.exist?("/usr/local/bitcoind/src/bitcoind") } +end + +execute "Compile bitcoin-core" do + cwd "/usr/local/bitcoind" + command "make" + not_if { ::File.exist?("/usr/local/bitcoind/src/bitcoind") } +end + +link "/usr/local/bin/bitcoind" do + to "/usr/local/bitcoind/src/bitcoind" +end + +link "/usr/local/bin/bitcoin-cli" do + to "/usr/local/bitcoind/src/bitcoin-cli" +end + +bitcoin_user = node['bitcoin']['username'] +bitcoin_group = node['bitcoin']['usergroup'] +bitcoin_datadir = node['bitcoin']['datadir'] +credentials = Chef::EncryptedDataBagItem.load('credentials', 'bitcoin') + +group bitcoin_group + +user bitcoin_user do + manage_home true + gid bitcoin_group + shell "/bin/bash" +end + +directory bitcoin_datadir do + owner bitcoin_user + group bitcoin_group + mode '0750' + recursive true + action :create +end + +template "#{bitcoin_datadir}/bitcoin.conf" do + owner bitcoin_user + group bitcoin_group + mode '0640' + # TODO Create new in data bag and use here + variables conf: node['bitcoin']['conf'].merge({rpcpassword: credentials["rpcpassword"]}), + mainnet_conf: node['bitcoin']['mainnet_conf'], + testnet_conf: node['bitcoin']['testnet_conf'], + regtest_conf: node['bitcoin']['regtest_conf'] + action :create + notifies :restart, "systemd_unit[bitcoind.service]", :delayed +end + +systemd_unit 'bitcoind.service' do + content({ + Unit: { + Description: 'Bitcoin Core daemon', + Documentation: ['https://bitcoincore.org'], + After: 'network.target' + }, + Service: { + User: bitcoin_user, + Type: 'simple', + ExecStart: "bitcoind -datadir=#{bitcoin_datadir} -pid=#{bitcoin_datadir}/bitcoind.pid", + PIDFile: "#{bitcoin_datadir}/bitcoind.pid", + Restart: 'always', + PrivateTmp: true, + LimitNOFILE: 'infinity', + TimeoutStopSec: '60s', + TimeoutStartSec: '20s', + StartLimitInterval: '60s', + StartLimitBurst: '2' + }, + Install: { + WantedBy: 'multi-user.target' + } + }) + verify false + triggers_reload true + action [:create, :start] +end + +# Creates/starts a Path unit which starts the bitcoind service when the +# encrypted data directory is mounted +# TODO move to custom kosmos cookbook before publishing bitcoin cookbook +encfs_path_activation_unit 'bitcoind.service' + +firewall_rule 'bitcoind' do + port [8333] # TODO adjust for testnet + protocol :tcp + command :allow +end diff --git a/site-cookbooks/kosmos-bitcoin/templates/bitcoin.conf.erb b/site-cookbooks/kosmos-bitcoin/templates/bitcoin.conf.erb index b28ceea..d2a8438 100644 --- a/site-cookbooks/kosmos-bitcoin/templates/bitcoin.conf.erb +++ b/site-cookbooks/kosmos-bitcoin/templates/bitcoin.conf.erb @@ -5,14 +5,14 @@ ## during the next Chef run! ## -<% @conf.each do |key, value| %> +<% @conf.sort.each do |key, value| %> <%= "#{key}=#{value}" %> <% end %> <% if @mainnet_conf %> # Options only for mainnet [main] -<% @mainnet_conf.each do |key, value| %> +<% @mainnet_conf.sort.each do |key, value| %> <%= "#{key}=#{value}" %> <% end %> <% end %> @@ -20,7 +20,7 @@ <% if @testnet_conf %> # Options only for testnet [test] -<% @testnet_conf.each do |key, value| %> +<% @testnet_conf.sort.each do |key, value| %> <%= "#{key}=#{value}" %> <% end %> <% end %> @@ -28,7 +28,7 @@ <% if @regtest_conf %> # Options only for regtest [regtest] -<% @regtest_conf.each do |key, value| %> +<% @regtest_conf.sort.each do |key, value| %> <%= "#{key}=#{value}" %> <% end %> <% end %> From d65363f964df127da92fed03bc534e186cdd686d Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 17 Aug 2020 10:51:54 +0200 Subject: [PATCH 102/327] Remove obsolete ulimit dep --- site-cookbooks/kosmos-bitcoin/metadata.rb | 1 - site-cookbooks/kosmos-bitcoin/recipes/source.rb | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/metadata.rb b/site-cookbooks/kosmos-bitcoin/metadata.rb index 60121e3..37f95f4 100644 --- a/site-cookbooks/kosmos-bitcoin/metadata.rb +++ b/site-cookbooks/kosmos-bitcoin/metadata.rb @@ -21,4 +21,3 @@ chef_version '>= 14.0' depends "ark" depends "kosmos_encfs" -depends "ulimit" diff --git a/site-cookbooks/kosmos-bitcoin/recipes/source.rb b/site-cookbooks/kosmos-bitcoin/recipes/source.rb index 2766420..e3c8e8f 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/source.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/source.rb @@ -137,6 +137,7 @@ end # TODO move to custom kosmos cookbook before publishing bitcoin cookbook encfs_path_activation_unit 'bitcoind.service' +# TODO move to custom kosmos cookbook before publishing bitcoin cookbook firewall_rule 'bitcoind' do port [8333] # TODO adjust for testnet protocol :tcp From b0daa3d463b1a4e1ca92666ba7a143ae56379019 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 17 Aug 2020 16:46:59 +0200 Subject: [PATCH 103/327] Only store wallet in encrypted dir Storing all chain data in encfs caused unsolvable issues with leveldb. So now we're only storing wallet data in the encrypted dir. --- .../kosmos-bitcoin/attributes/default.rb | 3 +- .../kosmos-bitcoin/recipes/source.rb | 30 +++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 4c01630..33fd5ca 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -3,7 +3,8 @@ node.default['bitcoin']['checksum'] = '4bbd62fd6acfa5e9864ebf37a24a04bc2dcfe3e3 node.default['bitcoin']['username'] = 'satoshi' node.default['bitcoin']['usergroup'] = 'bitcoin' node.default['bitcoin']['network'] = 'mainnet' -node.default['bitcoin']['datadir'] = '/mnt/data/bitcoin' +node.default['bitcoin']['datadir'] = '/home/satoshi/.bitcoin' +node.default['bitcoin']['walletdir'] = '/mnt/data/bitcoin' node.default['bitcoin']['conf'] = { irc: 1, diff --git a/site-cookbooks/kosmos-bitcoin/recipes/source.rb b/site-cookbooks/kosmos-bitcoin/recipes/source.rb index e3c8e8f..2c32084 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/source.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/source.rb @@ -69,10 +69,11 @@ link "/usr/local/bin/bitcoin-cli" do to "/usr/local/bitcoind/src/bitcoin-cli" end -bitcoin_user = node['bitcoin']['username'] -bitcoin_group = node['bitcoin']['usergroup'] -bitcoin_datadir = node['bitcoin']['datadir'] -credentials = Chef::EncryptedDataBagItem.load('credentials', 'bitcoin') +bitcoin_user = node['bitcoin']['username'] +bitcoin_group = node['bitcoin']['usergroup'] +bitcoin_datadir = node['bitcoin']['datadir'] +bitcoin_walletdir = node['bitcoin']['walletdir'] +credentials = Chef::EncryptedDataBagItem.load('credentials', 'bitcoin') group bitcoin_group @@ -82,20 +83,25 @@ user bitcoin_user do shell "/bin/bash" end -directory bitcoin_datadir do - owner bitcoin_user - group bitcoin_group - mode '0750' - recursive true - action :create +[bitcoin_datadir, bitcoin_walletdir].each do |path| + directory path do + owner bitcoin_user + group bitcoin_group + mode '0750' + recursive true + action :create + end end +config = node['bitcoin']['conf'].merge({ + rpcpassword: credentials["rpcpassword"] +}) + template "#{bitcoin_datadir}/bitcoin.conf" do owner bitcoin_user group bitcoin_group mode '0640' - # TODO Create new in data bag and use here - variables conf: node['bitcoin']['conf'].merge({rpcpassword: credentials["rpcpassword"]}), + variables conf: config, mainnet_conf: node['bitcoin']['mainnet_conf'], testnet_conf: node['bitcoin']['testnet_conf'], regtest_conf: node['bitcoin']['regtest_conf'] From 23588760fa3a5b7e34f28963546af3983da8196a Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 17 Aug 2020 21:43:56 +0200 Subject: [PATCH 104/327] Add walletdir flag to bitcoind service start --- site-cookbooks/kosmos-bitcoin/recipes/source.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/source.rb b/site-cookbooks/kosmos-bitcoin/recipes/source.rb index 2c32084..5f5f02f 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/source.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/source.rb @@ -119,7 +119,7 @@ systemd_unit 'bitcoind.service' do Service: { User: bitcoin_user, Type: 'simple', - ExecStart: "bitcoind -datadir=#{bitcoin_datadir} -pid=#{bitcoin_datadir}/bitcoind.pid", + ExecStart: "bitcoind -datadir=#{bitcoin_datadir} -walletdir=#{bitcoin_walletdir} -pid=#{bitcoin_datadir}/bitcoind.pid", PIDFile: "#{bitcoin_datadir}/bitcoind.pid", Restart: 'always', PrivateTmp: true, From 97ae73c987e73f6a4ccff31c5e9dc816a36bd20c Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 18 Aug 2020 14:38:16 +0200 Subject: [PATCH 105/327] Improve variable name --- site-cookbooks/kosmos-bitcoin/recipes/source.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/source.rb b/site-cookbooks/kosmos-bitcoin/recipes/source.rb index 5f5f02f..c1261c8 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/source.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/source.rb @@ -93,7 +93,7 @@ end end end -config = node['bitcoin']['conf'].merge({ +bitcoin_config = node['bitcoin']['conf'].merge({ rpcpassword: credentials["rpcpassword"] }) @@ -101,7 +101,7 @@ template "#{bitcoin_datadir}/bitcoin.conf" do owner bitcoin_user group bitcoin_group mode '0640' - variables conf: config, + variables conf: bitcoin_config, mainnet_conf: node['bitcoin']['mainnet_conf'], testnet_conf: node['bitcoin']['testnet_conf'], regtest_conf: node['bitcoin']['regtest_conf'] From c98be94404ea6feac4544354b38876d2017f4d2c Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 18 Aug 2020 14:44:23 +0200 Subject: [PATCH 106/327] Add rpcpassword support to bitcoin snap recipe --- site-cookbooks/kosmos-bitcoin/recipes/snapd.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb index 4339bf5..59d15f4 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/snapd.rb @@ -47,10 +47,14 @@ directory bitcoin_datadir do action :create end +bitcoin_config = node['bitcoin']['conf'].merge({ + rpcpassword: credentials["rpcpassword"] +}) + template "#{bitcoin_datadir}/bitcoin.conf" do owner bitcoin_user group bitcoin_group - variables conf: node['bitcoin']['conf'], + variables conf: bitcoin_config, mainnet_conf: node['bitcoin']['mainnet_conf'], testnet_conf: node['bitcoin']['testnet_conf'], regtest_conf: node['bitcoin']['regtest_conf'] From 1a8c3e4350f8a9ed4239cb46a2096c5a13f416fb Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 19 Aug 2020 15:28:00 +0200 Subject: [PATCH 107/327] Suggest bitcoin source recipe for dev --- Vagrantfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index 2b3b4aa..4cf5ee3 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -95,7 +95,7 @@ Vagrant.configure(2) do |config| chef.environment = 'development' chef.add_recipe 'kosmos-base' chef.add_recipe 'kosmos_encfs' - # chef.add_recipe 'kosmos-bitcoin::snapd' + # chef.add_recipe 'kosmos-bitcoin::source' # chef.add_recipe 'kosmos-mediawiki' # chef.add_recipe 'kosmos-wordpress' # chef.add_recipe 'kosmos-ejabberd' From 5c105f00d1c9b245b0effeae97e73d66c2200ea2 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 19 Aug 2020 15:29:18 +0200 Subject: [PATCH 108/327] Use MIT license for bitcoin cookbook --- site-cookbooks/kosmos-bitcoin/LICENSE | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-bitcoin/LICENSE b/site-cookbooks/kosmos-bitcoin/LICENSE index 10b5688..f518b02 100644 --- a/site-cookbooks/kosmos-bitcoin/LICENSE +++ b/site-cookbooks/kosmos-bitcoin/LICENSE @@ -1,3 +1,20 @@ -Copyright 2019 The Authors +Copyright (c) 2020 Kosmos Developers -All rights reserved, do not redistribute. +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. From 217ab471cef459224f96f315ba23a4dc7f52ab8b Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 22 Aug 2020 23:15:17 +0200 Subject: [PATCH 109/327] Moving bitcoin-core to VM --- clients/bitcoin-2.json | 4 ++ nodes/bitcoin-2.json | 55 +++++++++++++++++++ .../kosmos-bitcoin/attributes/default.rb | 5 +- .../kosmos-bitcoin/recipes/source.rb | 47 ++++++++++------ 4 files changed, 93 insertions(+), 18 deletions(-) create mode 100644 clients/bitcoin-2.json create mode 100644 nodes/bitcoin-2.json diff --git a/clients/bitcoin-2.json b/clients/bitcoin-2.json new file mode 100644 index 0000000..3cca107 --- /dev/null +++ b/clients/bitcoin-2.json @@ -0,0 +1,4 @@ +{ + "name": "bitcoin-2", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuNy0NZUQo93anCe3YkGI\nGTzHnH1SUqc7315ShEEgp9GC9ghEaFe9YX6fdYma4KLfehi1LNoYhibpaVvF6qMB\n5p2pCk4eM9EjRYve3byqt0ZJZzLEcR4zfoiqJHLMBfB1tDiGj3BbahY6LJ0WH/q2\nTek61LOp2nB/9HYSIRlYz8EJtt2YyjV57oqQD5rnEDCJyBf34VI81SZFBeSHCeHQ\nUDALdnkro840FHfFKMUTdUmtpq/bhBA13EkFqVObnc0xZQP3eW6pRNeZ5oUpBLK3\nbAXahd8YEW6c6XerK3JqROs/l2ZRXmfmOMB5RjzmTEuCDsZFuCnJDQEY1nWCyUmu\nhQIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/bitcoin-2.json b/nodes/bitcoin-2.json new file mode 100644 index 0000000..0d9d007 --- /dev/null +++ b/nodes/bitcoin-2.json @@ -0,0 +1,55 @@ +{ + "name": "bitcoin-2", + "normal": { + "knife_zero": { + "host": "10.147.20.163" + } + }, + "automatic": { + "fqdn": "bitcoin-2", + "os": "linux", + "os_version": "5.4.0-42-generic", + "hostname": "bitcoin-2", + "ipaddress": "192.168.122.148", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "kosmos-bitcoin::source", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default", + "ark::default" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + }, + "chef": { + "version": "15.13.8", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.13.8/lib" + } + } + }, + "run_list": [ + "recipe[kosmos-base]", + "recipe[kosmos-bitcoin::source]" + ] +} \ No newline at end of file diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 33fd5ca..70dca3c 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -3,8 +3,9 @@ node.default['bitcoin']['checksum'] = '4bbd62fd6acfa5e9864ebf37a24a04bc2dcfe3e3 node.default['bitcoin']['username'] = 'satoshi' node.default['bitcoin']['usergroup'] = 'bitcoin' node.default['bitcoin']['network'] = 'mainnet' -node.default['bitcoin']['datadir'] = '/home/satoshi/.bitcoin' -node.default['bitcoin']['walletdir'] = '/mnt/data/bitcoin' +node.default['bitcoin']['conf_path'] = '/home/satoshi/.bitcoin/bitcoin.conf' +node.default['bitcoin']['walletdir'] = '/home/satoshi/.bitcoin' +node.default['bitcoin']['datadir'] = '/mnt/data/bitcoin' node.default['bitcoin']['conf'] = { irc: 1, diff --git a/site-cookbooks/kosmos-bitcoin/recipes/source.rb b/site-cookbooks/kosmos-bitcoin/recipes/source.rb index c1261c8..d93f004 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/source.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/source.rb @@ -25,6 +25,28 @@ # THE SOFTWARE. # +# TODO move to custom kosmos cookbook before publshing bitcoin cookbook +systemd_unit "mnt-data-bitcoin.mount" do + content({ + Unit: { + Description: 'Bitcoin Core data directory', + }, + Mount: { + What: '/var/lib/vmshare-bitcoin', + Where: '/mnt/data/bitcoin', + Type: '9p', + Options: 'trans=virtio,version=9p2000.L' + }, + Install: { + WantedBy: 'multi-user.target' + } + }) + verify false + triggers_reload true + action [:create, :enable, :start] +end + + include_recipe 'ark' build_essential @@ -46,21 +68,17 @@ execute "Compile bitcoin-core dependencies" do not_if { ::File.directory?("/usr/local/bitcoind/depends/x86_64-pc-linux-gnu") } end -execute "Configure bitcoin-core" do +execute "Configure, compile bitcoin-core" do cwd "/usr/local/bitcoind" + # FIXME only executes first array item? command [ "./autogen.sh", - "./configure --prefix=$PWD/depends/x86_64-pc-linux-gnu" + "./configure --prefix=$PWD/depends/x86_64-pc-linux-gnu", + "make" ] not_if { ::File.exist?("/usr/local/bitcoind/src/bitcoind") } end -execute "Compile bitcoin-core" do - cwd "/usr/local/bitcoind" - command "make" - not_if { ::File.exist?("/usr/local/bitcoind/src/bitcoind") } -end - link "/usr/local/bin/bitcoind" do to "/usr/local/bitcoind/src/bitcoind" end @@ -73,12 +91,14 @@ bitcoin_user = node['bitcoin']['username'] bitcoin_group = node['bitcoin']['usergroup'] bitcoin_datadir = node['bitcoin']['datadir'] bitcoin_walletdir = node['bitcoin']['walletdir'] +bitcoin_conf_path = node['bitcoin']['conf_path'] credentials = Chef::EncryptedDataBagItem.load('credentials', 'bitcoin') group bitcoin_group user bitcoin_user do manage_home true + uid 1006 gid bitcoin_group shell "/bin/bash" end @@ -97,7 +117,7 @@ bitcoin_config = node['bitcoin']['conf'].merge({ rpcpassword: credentials["rpcpassword"] }) -template "#{bitcoin_datadir}/bitcoin.conf" do +template bitcoin_conf_path do owner bitcoin_user group bitcoin_group mode '0640' @@ -119,7 +139,7 @@ systemd_unit 'bitcoind.service' do Service: { User: bitcoin_user, Type: 'simple', - ExecStart: "bitcoind -datadir=#{bitcoin_datadir} -walletdir=#{bitcoin_walletdir} -pid=#{bitcoin_datadir}/bitcoind.pid", + ExecStart: "bitcoind -conf=#{bitcoin_conf_path} -datadir=#{bitcoin_datadir} -walletdir=#{bitcoin_walletdir} -pid=#{bitcoin_datadir}/bitcoind.pid", PIDFile: "#{bitcoin_datadir}/bitcoind.pid", Restart: 'always', PrivateTmp: true, @@ -135,14 +155,9 @@ systemd_unit 'bitcoind.service' do }) verify false triggers_reload true - action [:create, :start] + action [:create, :enable, :start] end -# Creates/starts a Path unit which starts the bitcoind service when the -# encrypted data directory is mounted -# TODO move to custom kosmos cookbook before publishing bitcoin cookbook -encfs_path_activation_unit 'bitcoind.service' - # TODO move to custom kosmos cookbook before publishing bitcoin cookbook firewall_rule 'bitcoind' do port [8333] # TODO adjust for testnet From 0005f9ab7d11e4a50a125d522f5f859d4caf71b8 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 23 Aug 2020 11:01:05 +0200 Subject: [PATCH 110/327] Add golang cookbook Needs updating of ark and git cookbooks --- Berksfile | 6 +- Berksfile.lock | 17 +- cookbooks/ark/.foodcritic | 1 - cookbooks/ark/CHANGELOG.md | 23 ++- cookbooks/ark/MAINTAINERS.md | 15 -- cookbooks/ark/README.md | 10 +- cookbooks/ark/libraries/default.rb | 1 - cookbooks/ark/libraries/matchers.rb | 44 ----- .../ark/libraries/sevenzip_command_builder.rb | 4 +- cookbooks/ark/metadata.json | 2 +- cookbooks/ark/metadata.rb | 16 ++ cookbooks/ark/recipes/default.rb | 4 +- cookbooks/ark/resources/default.rb | 12 +- .../{default => }/add_to_path.sh.erb | 0 cookbooks/dmg/CHANGELOG.md | 142 --------------- cookbooks/dmg/CONTRIBUTING.md | 2 - cookbooks/dmg/README.md | 149 ---------------- cookbooks/dmg/metadata.json | 1 - cookbooks/dmg/recipes/default.rb | 20 --- cookbooks/dmg/resources/package.rb | 102 ----------- cookbooks/git/.foodcritic | 1 - cookbooks/git/CHANGELOG.md | 57 ++++++ cookbooks/git/MAINTAINERS.md | 15 -- cookbooks/git/README.md | 58 +++--- cookbooks/git/attributes/default.rb | 12 +- cookbooks/git/libraries/helpers.rb | 7 +- cookbooks/git/libraries/matchers.rb | 16 -- .../git/libraries/provider_git_client.rb | 6 - .../git/libraries/provider_git_client_osx.rb | 14 +- .../libraries/provider_git_client_package.rb | 5 - .../libraries/provider_git_client_source.rb | 26 +-- .../libraries/provider_git_client_windows.rb | 6 +- .../git/libraries/provider_git_service.rb | 8 +- .../libraries/provider_git_service_xinetd.rb | 55 ------ cookbooks/git/metadata.json | 2 +- cookbooks/git/metadata.rb | 26 +++ cookbooks/git/recipes/default.rb | 2 +- cookbooks/git/recipes/package.rb | 13 +- cookbooks/git/recipes/server.rb | 2 +- cookbooks/git/recipes/windows.rb | 2 +- cookbooks/git/resources/config.rb | 8 +- .../default/sv-git-daemon-log-run.erb | 2 - .../templates/default/sv-git-daemon-run.erb | 3 - .../templates/{default => }/git-xinetd.d.erb | 0 cookbooks/golang/CHANGELOG.md | 98 ++++++++++ cookbooks/golang/CONTRIBUTING.md | 4 + cookbooks/golang/README.md | 77 ++++++++ cookbooks/golang/attributes/default.rb | 15 ++ cookbooks/golang/metadata.json | 1 + cookbooks/golang/metadata.rb | 20 +++ cookbooks/golang/recipes/default.rb | 30 ++++ cookbooks/golang/resources/default.rb | 167 ++++++++++++++++++ cookbooks/golang/resources/package.rb | 52 ++++++ cookbooks/golang/templates/golang.sh.erb | 3 + site-cookbooks/kosmos-bitcoin/metadata.rb | 2 +- 55 files changed, 670 insertions(+), 716 deletions(-) delete mode 100644 cookbooks/ark/.foodcritic delete mode 100644 cookbooks/ark/MAINTAINERS.md delete mode 100644 cookbooks/ark/libraries/matchers.rb create mode 100644 cookbooks/ark/metadata.rb rename cookbooks/ark/templates/{default => }/add_to_path.sh.erb (100%) delete mode 100644 cookbooks/dmg/CHANGELOG.md delete mode 100644 cookbooks/dmg/CONTRIBUTING.md delete mode 100644 cookbooks/dmg/README.md delete mode 100644 cookbooks/dmg/metadata.json delete mode 100644 cookbooks/dmg/recipes/default.rb delete mode 100644 cookbooks/dmg/resources/package.rb delete mode 100644 cookbooks/git/.foodcritic delete mode 100644 cookbooks/git/MAINTAINERS.md delete mode 100644 cookbooks/git/libraries/matchers.rb delete mode 100644 cookbooks/git/libraries/provider_git_service_xinetd.rb create mode 100644 cookbooks/git/metadata.rb delete mode 100644 cookbooks/git/templates/default/sv-git-daemon-log-run.erb delete mode 100644 cookbooks/git/templates/default/sv-git-daemon-run.erb rename cookbooks/git/templates/{default => }/git-xinetd.d.erb (100%) create mode 100644 cookbooks/golang/CHANGELOG.md create mode 100644 cookbooks/golang/CONTRIBUTING.md create mode 100644 cookbooks/golang/README.md create mode 100644 cookbooks/golang/attributes/default.rb create mode 100644 cookbooks/golang/metadata.json create mode 100644 cookbooks/golang/metadata.rb create mode 100644 cookbooks/golang/recipes/default.rb create mode 100644 cookbooks/golang/resources/default.rb create mode 100644 cookbooks/golang/resources/package.rb create mode 100644 cookbooks/golang/templates/golang.sh.erb diff --git a/Berksfile b/Berksfile index 288f290..7ffb698 100644 --- a/Berksfile +++ b/Berksfile @@ -32,12 +32,12 @@ cookbook 'build-essential', '~> 8.2.1' cookbook 'mysql', '~> 8.5.1' # cookbook 'postgresql', '= 7.1.8' cookbook 'apt', '~> 7.3.0' -cookbook 'git', '= 6.0.0' +cookbook 'git', '>= 6.0.0' cookbook 'hostsfile', '= 2.4.5' cookbook 'ohai', '~> 5.2.5' cookbook 'nodejs', '~> 5.0.0' cookbook 'timezone_iii', '= 1.0.4' -cookbook 'ark', '= 3.1.0' +cookbook 'ark', '>= 3.1.0' cookbook 'logrotate', '= 2.2.0' cookbook 'openssl', '~> 8.5.5' cookbook 'ntp', '= 3.4.0' @@ -51,5 +51,5 @@ cookbook 'ipfs', ref: 'v0.4.1' cookbook 'elasticsearch', '= 4.2.0' cookbook 'java', '~> 4.3.0' - cookbook 'ulimit', '~> 1.0.0' +cookbook 'golang', '~> 4.1.0' diff --git a/Berksfile.lock b/Berksfile.lock index 985d29b..1e3996b 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -4,14 +4,15 @@ DEPENDENCIES application_git (= 1.1.0) application_javascript (~> 1.0.0) apt (~> 7.3.0) - ark (= 3.1.0) + ark (>= 3.1.0) build-essential (~> 8.2.1) chef-sugar (= 3.3.0) compat_resource (= 12.19.0) composer (~> 2.6.1) elasticsearch (= 4.2.0) firewall (~> 2.6.3) - git (= 6.0.0) + git (>= 6.0.0) + golang (~> 4.1.0) homebrew (= 3.0.0) hostname (= 0.4.2) hostsfile (= 2.4.5) @@ -67,10 +68,8 @@ GRAPH poise-javascript (~> 1.0) poise-service (~> 1.0) apt (7.3.0) - ark (3.1.0) - build-essential (>= 0.0.0) + ark (5.0.0) seven_zip (>= 0.0.0) - windows (>= 0.0.0) build-essential (8.2.1) mingw (>= 1.1) seven_zip (>= 0.0.0) @@ -80,7 +79,6 @@ GRAPH apt (>= 0.0.0) php (>= 0.0.0) windows (>= 0.0.0) - dmg (4.1.1) elasticsearch (4.2.0) apt (>= 0.0.0) ark (>= 0.0.0) @@ -88,10 +86,9 @@ GRAPH yum (>= 0.0.0) firewall (2.6.5) chef-sugar (>= 0.0.0) - git (6.0.0) - build-essential (>= 0.0.0) - dmg (>= 0.0.0) - yum-epel (>= 0.0.0) + git (10.0.0) + golang (4.1.0) + ark (~> 5.0) homebrew (3.0.0) hostname (0.4.2) hostsfile (>= 0.0.0) diff --git a/cookbooks/ark/.foodcritic b/cookbooks/ark/.foodcritic deleted file mode 100644 index b9f8767..0000000 --- a/cookbooks/ark/.foodcritic +++ /dev/null @@ -1 +0,0 @@ -~FC016 diff --git a/cookbooks/ark/CHANGELOG.md b/cookbooks/ark/CHANGELOG.md index 0639bc9..4e02c20 100644 --- a/cookbooks/ark/CHANGELOG.md +++ b/cookbooks/ark/CHANGELOG.md @@ -2,6 +2,27 @@ This file is used to list changes made in each version of the ark cookbook. +## 5.0.0 (2020-01-02) + +- Require Chef Infra Client 14+ and remove the need for the build_essential dependency - [@tas50](https://github.com/tas50) +- Use Ruby classes in resource properties - [@tas50](https://github.com/tas50) +- Simplify the platform check logic - [@tas50](https://github.com/tas50) +- Remove the .foocritic file - [@tas50](https://github.com/tas50) +- Remove long_description and recipe metadata - [@tas50](https://github.com/tas50) +- Expand testing - [@tas50](https://github.com/tas50) +- Remove Ubuntu 14.04 testing - [@tas50](https://github.com/tas50) + +## 4.0.0 (2018-07-25) + +- Support append_env_path property on Windows, which increases the minimum required Chef release to Chef 13.4 + +## 3.1.1 (2018-07-24) + +- Remove ChefSpec matchers since these are autogenerated now +- Update specs to the latest platform versions +- Remove template out of defaults directory +- Remove dependency on the Windows cookbook + ## 3.1.0 (2017-05-06) - Ensure the dependencies get installed on Chef 13 Amazon Linux systems @@ -12,7 +33,7 @@ This file is used to list changes made in each version of the ark cookbook. - Rewrite of resource to custom resources. - Remove EOL platforms from testing. - Update zlib URL -- +- ## 2.2.1 (2016-12-16) - Use Ohai root_group attribute to avoid trying to set the group to root on BSD/macOS. - Add missing accessor for owner property diff --git a/cookbooks/ark/MAINTAINERS.md b/cookbooks/ark/MAINTAINERS.md deleted file mode 100644 index 645ed14..0000000 --- a/cookbooks/ark/MAINTAINERS.md +++ /dev/null @@ -1,15 +0,0 @@ - - -# Maintainers - -This file lists how this cookbook project is maintained. When making changes to the system, this file tells you who needs to review your patch - you need a review from an existing maintainer for the cookbook to provide a :+1: on your pull request. Additionally, you need to not receive a veto from a Lieutenant or the Project Lead. - -Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) for details on the process and how to become a maintainer or the project lead. - -# Project Maintainer -* [Tim Smith](https://github.com/tas50) - -# Maintainers -* [Jennifer Davis](https://github.com/sigje) -* [Tim Smith](https://github.com/tas50) -* [Thom May](https://github.com/thommay) diff --git a/cookbooks/ark/README.md b/cookbooks/ark/README.md index 42f7cb6..35309a3 100644 --- a/cookbooks/ark/README.md +++ b/cookbooks/ark/README.md @@ -25,7 +25,7 @@ The `ark` resource will: By default, the ark will not run again if the `:path` is not empty. Ark provides many actions to accommodate different use cases, such as `:dump`, `:cherry_pick`, `:put`, and `:install_with_make`. -At this time ark only handles files available from URLs using the [remote_file](http://docs.chef.io/resource_remote_file.html) provider. It does handle local files using the `file://` protocol. +For remote files ark supports URLs using the [remote_file](http://docs.chef.io/resource_remote_file.html) resource. Local files are accessed with the `file://` syntax. ## Requirements @@ -36,7 +36,7 @@ At this time ark only handles files available from URLs using the [remote_file]( - Fedora - FreeBSD - SmartOS -- Mac OS X +- macOS - openSUSE / SUSE Linux Enterprises - Windows @@ -44,13 +44,11 @@ Should work on common Unix/Linux systems with typical userland utilities like ta ### Chef -- Chef 12.7+ +- Chef 14+ ### Cookbooks -- build-essential - seven_zip -- windows ## Attributes @@ -66,7 +64,7 @@ Customize the attributes to suit site specific conventions and defaults. ## Resources -- `ark` - does the extract/build/configure +- `ark` - does the extract/build/configure ### Actions diff --git a/cookbooks/ark/libraries/default.rb b/cookbooks/ark/libraries/default.rb index 24b09e6..635695c 100644 --- a/cookbooks/ark/libraries/default.rb +++ b/cookbooks/ark/libraries/default.rb @@ -58,7 +58,6 @@ module Ark new_resource.path = defaults.path new_resource.release_file = defaults.release_file end - # rubocop:enable Metrics/AbcSize def set_put_paths new_resource.extension = defaults.extension diff --git a/cookbooks/ark/libraries/matchers.rb b/cookbooks/ark/libraries/matchers.rb deleted file mode 100644 index aa8901b..0000000 --- a/cookbooks/ark/libraries/matchers.rb +++ /dev/null @@ -1,44 +0,0 @@ - -if defined?(ChefSpec) - ChefSpec.define_matcher :ark - - def install_ark(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:ark, :install, resource_name) - end - - def dump_ark(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:ark, :dump, resource_name) - end - - def cherry_pick_ark(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:ark, :cherry_pick, resource_name) - end - - def put_ark(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:ark, :put, resource_name) - end - - def install_with_make_ark(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:ark, :install_with_make, resource_name) - end - - def configure_ark(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:ark, :configure, resource_name) - end - - def setup_py_build_ark(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:ark, :setup_py_build, resource_name) - end - - def setup_py_install_ark(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:ark, :setup_py_install, resource_name) - end - - def setup_py_ark(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:ark, :setup_py, resource_name) - end - - def unzip_ark(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:ark, :unzip, resource_name) - end -end diff --git a/cookbooks/ark/libraries/sevenzip_command_builder.rb b/cookbooks/ark/libraries/sevenzip_command_builder.rb index 7319a0e..2482ac6 100644 --- a/cookbooks/ark/libraries/sevenzip_command_builder.rb +++ b/cookbooks/ark/libraries/sevenzip_command_builder.rb @@ -25,9 +25,7 @@ module Ark end def sevenzip_command - if resource.strip_components <= 0 - return sevenzip_command_builder(resource.path, 'x') - end + return sevenzip_command_builder(resource.path, 'x') if resource.strip_components <= 0 tmpdir = make_temp_directory.tr('/', '\\') cmd = sevenzip_command_builder(tmpdir, 'x') diff --git a/cookbooks/ark/metadata.json b/cookbooks/ark/metadata.json index a531332..cdbcc1c 100644 --- a/cookbooks/ark/metadata.json +++ b/cookbooks/ark/metadata.json @@ -1 +1 @@ -{"name":"ark","version":"3.1.0","description":"Provides a custom resource for installing runtime artifacts in a predictable fashion","long_description":"# ark cookbook\n\n[![Build Status](https://travis-ci.org/chef-cookbooks/ark.svg?branch=master)](https://travis-ci.org/chef-cookbooks/ark) [![Cookbook Version](https://img.shields.io/cookbook/v/ark.svg)](https://supermarket.chef.io/cookbooks/ark)\n\n## Overview\n\nThis cookbook provides `ark`, a resource for managing software archives. It manages the fetch-unpack-configure-build-install process common to installing software from source, or from binary distributions that are not fully fledged OS packages.\n\nThis cookbook started its life as a modified version of Infochimp's install_from cookbook. It has since been heavily refactored and extended to meet different use cases.\n\nGiven a simple project archive available at a url:\n\n```ruby\nark 'pig' do\n url 'http://apache.org/pig/pig-0.8.0.tar.gz'\nend\n```\n\nThe `ark` resource will:\n\n- fetch it to to `/var/cache/chef/`\n- unpack it to the default path (`/usr/local/pig-0.8.0`)\n- create a symlink for `:home_dir` (`/usr/local/pig`) pointing to path\n- add specified binary commands to the environment `PATH` variable\n\nBy default, the ark will not run again if the `:path` is not empty. Ark provides many actions to accommodate different use cases, such as `:dump`, `:cherry_pick`, `:put`, and `:install_with_make`.\n\nAt this time ark only handles files available from URLs using the [remote_file](http://docs.chef.io/resource_remote_file.html) provider. It does handle local files using the `file://` protocol.\n\n## Requirements\n\n### Platforms\n\n- Debian/Ubuntu\n- RHEL/CentOS/Scientific/Oracle\n- Fedora\n- FreeBSD\n- SmartOS\n- Mac OS X\n- openSUSE / SUSE Linux Enterprises\n- Windows\n\nShould work on common Unix/Linux systems with typical userland utilities like tar, gzip, etc. May require the installation of build tools for compiling from source, but that installation is outside the scope of this cookbook.\n\n### Chef\n\n- Chef 12.7+\n\n### Cookbooks\n\n- build-essential\n- seven_zip\n- windows\n\n## Attributes\n\nCustomize the attributes to suit site specific conventions and defaults.\n\n- `node['ark']['apache_mirror']` - if the URL is an apache mirror, use the attribute as the default. default: `http://apache.mirrors.tds.net`\n- `node['ark']['prefix_root']` - default base location if the `prefix_root` is not passed into the resource. default: `/usr/local`\n- `node['ark']['prefix_bin']` - default binary location if the `prefix_bin` is not passed into the resource. default: `/usr/local/bin`\n- `node['ark']['prefix_home']` - default home location if the `prefix_home` is not passed into the resource. default: `/usr/local`\n- `node['ark']['package_dependencies']` - prerequisite system packages that need to be installed to support ark. default: varies based on platform\n- `node['ark']['tar']` - allows overriding the default path to the tar binary, which varies based on platform\n- `node['ark']['sevenzip_binary']` - allows overriding the default path to the 7zip binary, which is determined based on registry key value\n\n## Resources\n\n- `ark` - does the extract/build/configure \n\n### Actions\n\n- `:install`: extracts the file and creates a 'friendly' symbolic link to the extracted directory path\n- `:configure`: configure ahead of the install action\n- `:install_with_make`: extracts the archive to a path, runs `configure`, `make`, and `make install`.\n- `:dump`: strips all directories from the archive and dumps the contained files into a specified path\n- `:cherry_pick`: extract a specified file from an archive and places in specified path\n- `:put`: extract the archive to a specified path, does not create any symbolic links\n- `:remove`: removes the extracted directory and related symlink #TODO\n- `:setup_py`: runs the command \"python setup.py\" in the extracted directory\n- `:setup_py_build`: runs the command \"python setup.py build\" in the extracted directory\n- `:setup_py_install`: runs the command \"python setup.py install\" in the extracted directory\n\n### :cherry_pick\n\nExtract a specified file from an archive and places in specified path.\n\n#### Relevant Attribute Parameters for :cherry_pick\n\n- `path`: directory to place file in.\n- `creates`: specific file to cherry-pick.\n\n### :dump\n\nStrips all directories from the archive and dumps the contained files into a specified path.\n\nNOTE: This currently only works for zip archives\n\n#### Attribute Parameters for :dump\n\n- `path`: path to dump files to.\n- `mode`: file mode for `app_home`, as an integer.\n\n - Example: `0775`\n\n- `creates`: if you are appending files to a given directory, ark needs a condition to test whether the file has already been extracted. You can specify with creates, a file whose existence indicates the ark has previously been extracted and does not need to be extracted again.\n\n### :put\n\nExtract the archive to a specified path, does not create any symbolic links.\n\n#### Attribute Parameters for :put\n\n- `path`: path to extract to.\n\n - Default: `/usr/local`\n\n- `append_env_path`: boolean, if true, append the `./bin` directory of the extracted directory to the global `PATH` variable for all users.\n\n### Attribute Parameters\n\n- `name`: name of the package, defaults to the resource name.\n- `url`: url for tarball, `.tar.gz`, `.bin` (oracle-specific), `.war`, and `.zip` currently supported. Also supports special syntax\n- `:name:version:apache_mirror:` that will auto-magically construct download url from the apache mirrors site.\n- `version`: software version, defaults to `1`.\n- `mode`: file mode for `app_home`, is an integer.\n- `prefix_root`: default `prefix_root`, for use with `:install*` actions.\n- `prefix_home`: default directory prefix for a friendly symlink to the path.\n\n - Example: `/usr/local/maven` -> `/usr/local/maven-2.2.1`\n\n- `prefix_bin`: default directory to place a symlink to a binary command.\n\n - Example: `/opt/bin/mvn` -> `/opt/maven-2.2.1/bin/mvn`, where the `prefix_bin` is `/opt/bin`\n\n- `path`: path to extract the ark to. The `:install*` actions overwrite any user-provided values for `:path`.\n\n - Default: `/usr/local/-` for the `:install`, `:install_with_make` actions\n\n- `home_dir`: symbolic link to the path `:prefix_root/:name-:version`, does not apply to `:dump`, `:put`, or `:cherry_pick` actions.\n\n - Default: `:prefix_root/:name`\n\n- `has_binaries`: array of binary commands to symlink into `/usr/local/bin/`, you must specify the relative path.\n\n - Example: `[ 'bin/java', 'bin/javaws' ]`\n\n- `append_env_path`: boolean, similar to `has_binaries` but less granular. If true, append the `./bin` directory of the extracted directory to. the `PATH` environment variable for all users, by placing a file in `/etc/profile.d/`. The commands are symbolically linked into `/usr/bin/*`. This option provides more granularity than the boolean option.\n\n - Example: `mvn`, `java`, `javac`, etc.\n\n- `environment`: hash of environment variables to pass to invoked shell commands like `tar`, `unzip`, `configure`, and `make`.\n\n- `strip_components`: number of components in path to strip when extracting archive. With default value of `1`, ark strips the leading directory from an archive, which is the default for both `unzip` and `tar` commands.\n\n- `autoconf_opts`: an array of command line options for use with the GNU `autoconf` script.\n\n - Example: `[ '--include=/opt/local/include', '--force' ]`\n\n- `make_opts`: an array of command line options for use with `make`.\n\n - Example: `[ '--warn-undefined-variables', '--load-average=2' ]`\n\n- `owner`: owner of extracted directory.\n\n - Default: `root`\n\n- `group`: group of extracted directory.\n\n - Default: `root`\n\n- `backup`: The number of backups to be kept in /var/chef/backup (for UNIX- and Linux-based platforms) or C:/chef/backup (for the Microsoft Windows platform). Set to false to prevent backups from being kept.\n\n - Default: `5`\n\n#### Examples\n\nThis example copies `ivy.tar.gz` to `/var/cache/chef/ivy-2.2.0.tar.gz`, unpacks its contents to `/usr/local/ivy-2.2.0/` -- stripping the leading directory, and symlinks `/usr/local/ivy` to `/usr/local/ivy-2.2.0`\n\n```ruby\n # install Apache Ivy dependency resolution tool\n ark \"ivy\" do\n url 'http://someurl.example.com/ivy.tar.gz'\n version '2.2.0'\n checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'\n action :install\n end\n```\n\nThis example copies `jdk-7u2-linux-x64.tar.gz` to `/var/cache/chef/jdk-7.2.tar.gz`, unpacks its contents to `/usr/local/jvm/jdk-7.2/` -- stripping the leading directory, symlinks `/usr/local/jvm/default` to `/usr/local/jvm/jdk-7.2`, and adds `/usr/local/jvm/jdk-7.2/bin/` to the global `PATH` for all users. The user 'foobar' is the owner of the `/usr/local/jvm/jdk-7.2` directory:\n\n```ruby\n ark 'jdk' do\n url 'http://download.example.com/jdk-7u2-linux-x64.tar.gz'\n version '7.2'\n path \"/usr/local/jvm/\"\n home_dir \"/usr/local/jvm/default\"\n checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'\n append_env_path true\n owner 'foobar'\n end\n```\n\nInstall Apache Ivy dependency resolution tool in `/resource_name` in this case `/usr/local/ivy`, do not symlink, and strip any leading directory if one exists in the tarball:\n\n```ruby\n ark \"ivy\" do\n url 'http://someurl.example.com/ivy.tar.gz'\n checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'\n action :put\n end\n```\n\nInstall Apache Ivy dependency resolution tool in `/home/foobar/ivy`, strip any leading directory if one exists, don't keep backup copies of `ivy.tar.gz`:\n\n```ruby\n ark \"ivy\" do\n path \"/home/foobar\"\n url 'http://someurl.example.com/ivy.tar.gz'\n checksum '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'\n action :put\n backup false\n end\n```\n\nStrip all directories and dump files into path specified by the path attribute. You must specify the `creates` attribute in order to keep the extraction from running every time. The directory path will be created if it doesn't already exist:\n\n```ruby\n ark \"my_jars\" do\n url \"http://example.com/bunch_of_jars.zip\"\n path \"/usr/local/tomcat/lib\"\n creates \"mysql.jar\"\n owner \"tomcat\"\n action :dump\n end\n```\n\nExtract specific files from a tarball (currently only handles one named file):\n\n```ruby\n ark 'mysql-connector-java' do\n url 'http://oracle.com/mysql-connector.zip'\n creates 'mysql-connector-java-5.0.8-bin.jar'\n path '/usr/local/tomcat/lib'\n action :cherry_pick\n end\n```\n\nBuild and install haproxy and use alternative values for `prefix_root`, `prefix_home`, and `prefix_bin`:\n\n```ruby\n ark \"haproxy\" do\n url \"http://haproxy.1wt.eu/download/1.5/src/snapshot/haproxy-ss-20120403.tar.gz\"\n version \"1.5\"\n checksum 'ba0424bf7d23b3a607ee24bbb855bb0ea347d7ffde0bec0cb12a89623cbaf911'\n make_opts [ 'TARGET=linux26' ]\n prefix_root '/opt'\n prefix_home '/opt'\n prefix_bin '/opt/bin'\n action :install_with_make\n end\n```\n\nYou can also supply the file extension in case the file extension can not be determined by the URL:\n\n```ruby\n ark \"test_autogen\" do\n url 'https://github.com/zeromq/libzmq/tarball/master'\n extension \"tar.gz\"\n action :install_with_make\n end\n```\n\n## License & Authors\n\n- Author: Philip (flip) Kromer - Infochimps, Inc([coders@infochimps.com](mailto:coders@infochimps.com))\n- Author: Bryan W. Berry ([bryan.berry@gmail.com](mailto:bryan.berry@gmail.com))\n- Author: Denis Barishev ([denis.barishev@gmail.com](mailto:denis.barishev@gmail.com))\n- Author: Sean OMeara ([someara@chef.io](mailto:someara@chef.io))\n- Author: John Bellone ([jbellone@bloomberg.net](mailto:jbellone@bloomberg.net))\n- Copyright: 2011, Philip (flip) Kromer - Infochimps, Inc\n- Copyright: 2012, Bryan W. Berry\n- Copyright: 2012, Denis Barishev\n- Copyright: 2013-2017, Chef Software, Inc\n- Copyright: 2014, Bloomberg L.P.\n\n```\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache-2.0","platforms":{"ubuntu":">= 0.0.0","debian":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","suse":">= 0.0.0","opensuse":">= 0.0.0","opensuseleap":">= 0.0.0","scientific":">= 0.0.0","oracle":">= 0.0.0","amazon":">= 0.0.0","windows":">= 0.0.0","mac_os_x":">= 0.0.0","smartos":">= 0.0.0","freebsd":">= 0.0.0"},"dependencies":{"build-essential":">= 0.0.0","windows":">= 0.0.0","seven_zip":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{"ark::default":"Installs packages needed by the custom resource"},"source_url":"https://github.com/chef-cookbooks/ark","issues_url":"https://github.com/chef-cookbooks/ark/issues","chef_version":[[">= 12.7"]],"ohai_version":[]} \ No newline at end of file +{"name":"ark","version":"5.0.0","description":"Provides a custom resource for installing runtime artifacts in a predictable fashion","long_description":"","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache-2.0","platforms":{"ubuntu":">= 0.0.0","debian":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","suse":">= 0.0.0","opensuse":">= 0.0.0","opensuseleap":">= 0.0.0","scientific":">= 0.0.0","oracle":">= 0.0.0","amazon":">= 0.0.0","windows":">= 0.0.0","mac_os_x":">= 0.0.0","smartos":">= 0.0.0","freebsd":">= 0.0.0"},"dependencies":{"seven_zip":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chef-cookbooks/ark","issues_url":"https://github.com/chef-cookbooks/ark/issues","chef_version":[[">= 14.0"]],"ohai_version":[]} \ No newline at end of file diff --git a/cookbooks/ark/metadata.rb b/cookbooks/ark/metadata.rb new file mode 100644 index 0000000..1f4bb50 --- /dev/null +++ b/cookbooks/ark/metadata.rb @@ -0,0 +1,16 @@ +name 'ark' +maintainer 'Chef Software, Inc.' +maintainer_email 'cookbooks@chef.io' +license 'Apache-2.0' +description 'Provides a custom resource for installing runtime artifacts in a predictable fashion' +version '5.0.0' + +%w(ubuntu debian redhat centos suse opensuse opensuseleap scientific oracle amazon windows mac_os_x smartos freebsd).each do |os| + supports os +end + +depends 'seven_zip' # for windows os + +source_url 'https://github.com/chef-cookbooks/ark' +issues_url 'https://github.com/chef-cookbooks/ark/issues' +chef_version '>= 14.0' diff --git a/cookbooks/ark/recipes/default.rb b/cookbooks/ark/recipes/default.rb index 9a482aa..cd3d43a 100644 --- a/cookbooks/ark/recipes/default.rb +++ b/cookbooks/ark/recipes/default.rb @@ -18,6 +18,6 @@ # limitations under the License. # -package node['ark']['package_dependencies'] unless %w(windows mac_os_x).include?(node['platform_family']) +package node['ark']['package_dependencies'] unless platform_family?('windows', 'mac_os_x') -include_recipe 'seven_zip' if node['platform_family'] == 'windows' +include_recipe 'seven_zip' if platform_family?('windows') diff --git a/cookbooks/ark/resources/default.rb b/cookbooks/ark/resources/default.rb index 3bcb4c4..1551df2 100644 --- a/cookbooks/ark/resources/default.rb +++ b/cookbooks/ark/resources/default.rb @@ -83,8 +83,16 @@ action :install do action :nothing end - # usually on windows there is no central directory with executables where the applications are linked - unless node['platform_family'] == 'windows' + if platform_family?('windows') + # usually on windows there is no central directory with executables where the applications are linked + # so ignore has_binaries for now + + # Add to PATH permanently on Windows if append_env_path + windows_path "#{new_resource.path}/bin" do + action :add + only_if { new_resource.append_env_path } + end + else # symlink binaries new_resource.has_binaries.each do |bin| link ::File.join(new_resource.prefix_bin, ::File.basename(bin)) do diff --git a/cookbooks/ark/templates/default/add_to_path.sh.erb b/cookbooks/ark/templates/add_to_path.sh.erb similarity index 100% rename from cookbooks/ark/templates/default/add_to_path.sh.erb rename to cookbooks/ark/templates/add_to_path.sh.erb diff --git a/cookbooks/dmg/CHANGELOG.md b/cookbooks/dmg/CHANGELOG.md deleted file mode 100644 index a5f10e0..0000000 --- a/cookbooks/dmg/CHANGELOG.md +++ /dev/null @@ -1,142 +0,0 @@ -# dmg Cookbook CHANGELOG - -This file is used to list changes made in each version of the dmg cookbook. - -## 4.1.1 (2018-04-06) - -- The dmg_package resource is now included in Chef 14 and this cookbook has been deprecated. We highly recommend updating to Chef 14 so you can use this resource without the need for a cookbook dependency. -- Validate the type field in the resource -- Remove the now autogenerated ChefSpec matchers - -## 4.1.0 (2017-11-15) - -- Adds allow_untrusted property for older packages that aren't signed -- Resolve Chef 14 deprecation warnings -- Minor testing updates and cleanup - -## 4.0.0 (2017-04-27) - -- Converted the existing LWRP to a custom resource which increases the required chef-client release to 12.5+ -- Added Test Kitchen config with private atlas boxes for 10.10 and 10.11 -- Added a test recipe to installed Tunnelblick -- Added an Inspec test to confirm that Tunnelblick actually installs -- Remove unused attributes and the entire attributes file -- Add a warning if you include the default recipe on your runlist -- Update specs to run on 10.12 and against the test recipe since dmg::default is empty and the existing spec tested nothing - -## 3.1.1 (2017-04-11) - -- Cookstyle updates -- Test with Local Delivery and not Rake -- Update apache2 license string -- Remove foodcritic exclusions - -## 3.1.0 (2017-01-18) - -- Fixed pkg,mpkg installation when it was using mounted app name while it was actually mounted under different name for some applications -- Cookstyle fixes - -## 3.0.0 (2016-09-06) - -- Add chef_version metadata -- Run the specs against a mock of OS X -- Testing updates -- Require Chef 12+ - -## v2.4.0 (2016-04-26) - -- Added support for local .dmg files with the file property. See the readme for details -- Resolved all rubocop warnings - -## v2.3.0 (2015-10-20) - -- Add new headers property to the LWRP for custom http headers. See the readme for more information -- Removed pivotal tracker example in the readme -- Added travis and cookbook version badges to the readme -- Added a .foodcritic file to exclude rules -- Updated chefignore and .gitignore files -- Updated platforms in Test Kitchen -- Added standard Rubocop file -- Updated Travis to test using ChefDK for the latest deps -- Added a Berksfile -- Updated contributing and testing docs -- Updated Gemfile with the latest testing deps -- Added maintainers.md and maintainers.toml -- Added rakefile for simplified testing -- Added source_url and issues_url metadata -- Added basic converge chefspec - -## v2.2.2 (2014-11-12) - -- # 23, add chefspec matchers - -## v2.2.0 (2014-02-25) - -- [COOK-4285] Accept long EULAs - -## v2.1.4 (2014-01-26) - -- [COOK-4157] - dmg_package LWRP broken due to "puts" instead of "system" -- [COOK-4065] - dmg cookbook outputs the name of packages when checking if they are installed - -## v2.1.2 - -Cleaning up merge errors - -## v2.1.0 - -### Bug - -- **[COOK-3946](https://tickets.chef.io/browse/COOK-3946)** - Syntax error in resources/package.rb -- **[COOK-2672](https://tickets.chef.io/browse/COOK-2672)** - EULA for package is displayed instead accepted - -## v2.0.8 - -Adding a Chef 10 compatibility check in provider - -## v2.0.6 - -# BUG - -- [COOK-3302] - Sometimes hdiutil detach fails due to cfprefsd running in background - - # IMPROVEMENT - -- Adding foodcritic and rubocop to .travis.yml - -## v2.0.4 - -### Bug - -- **[COOK-3331](https://tickets.chef.io/browse/COOK-3331)** - Fix an issue where `dmg_package` with no source raises an exception - -## v2.0.2 - -### Bug - -- **[COOK-3578](https://tickets.chef.io/browse/COOK-3578)** - Support `package_id`s with spaces -- **[COOK-3302](https://tickets.chef.io/browse/COOK-3302)** - Fix an issue where `hdiutil detach` fails due to `cfprefsd` running in the background - -## v2.0.0 - -### Bug - -- **[COOK-3389](https://tickets.chef.io/browse/COOK-3389)** - Use `rsync` instead of `cp` (potentially a breaking change on some systems) - -## v1.1.0 - -- [COOK-1847] - accept owner parameter for installing packages - -## v1.0.0 - -- [COOK-852] - Support "pkg" in addition to "mpkg" package types - -## v0.7.0 - -- [COOK-854] - use `cp -R` instead of `cp -r` -- [COOK-855] - specify a file or directory to check for prior install - -## v0.6.0 - -- option to install software that is an .mpkg inside a .dmg -- ignore failure on chmod in case mode is already set, or is root owned diff --git a/cookbooks/dmg/CONTRIBUTING.md b/cookbooks/dmg/CONTRIBUTING.md deleted file mode 100644 index ef2f2b8..0000000 --- a/cookbooks/dmg/CONTRIBUTING.md +++ /dev/null @@ -1,2 +0,0 @@ -Please refer to -https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD diff --git a/cookbooks/dmg/README.md b/cookbooks/dmg/README.md deleted file mode 100644 index 86f95aa..0000000 --- a/cookbooks/dmg/README.md +++ /dev/null @@ -1,149 +0,0 @@ -The dmg_package resource is now included in Chef 14 and this cookbook has been deprecated. We highly recommend updating to Chef 14 so you can use this resource without the need for a cookbook dependency. - -# dmg Cookbook - -[![Build Status](https://travis-ci.org/chef-cookbooks/dmg.svg?branch=master)](https://travis-ci.org/chef-cookbooks/dmg) [![Cookbook Version](https://img.shields.io/cookbook/v/dmg.svg)](https://supermarket.chef.io/cookbooks/dmg) - -Resource to install OS X applications (.app) from dmg files. - -## Requirements - -### Platforms - -- macOS - -### Chef - -- Chef 12.5+ - -### Cookbooks - -- none - -## Resources/Providers - -### dmg_package - -This resource will install a DMG "Package". It will retrieve the DMG from a remote URL, mount it using OS X's `hdid`, copy the application (.app directory) to the specified destination (/Applications), and detach the image using `hdiutil`. The dmg file will be stored in the `Chef::Config[:file_cache_path]`. If you want to install an application that has already been downloaded (not using the `source` parameter), copy it to the appropriate location. You can find out what directory this is with the following command on the node to run chef: - -```bash -knife exec -E 'p Chef::Config[:file_cache_path]' -c /etc/chef/client.rb -``` - -Optionally, the LWRP can install an "mpkg" or "pkg" package using installer(8). - -#### Actions - -- :install - Installs the application. - -#### Parameter attributes: - -- `app` - This is the name of the application used by default for the /Volumes directory and the .app directory copied to /Applications. -- `source` - remote URL for the dmg to download if specified. Default is nil. -- `file` - local dmg full file path. Default is nil. -- `owner` - owner that should own the package installation. -- `destination` - directory to copy the .app into. Default is /Applications. -- `checksum` - sha256 checksum of the dmg to download. Default is nil. -- `type` - type of package, "app", "pkg" or "mpkg". Default is "app". When using "pkg" or "mpkg", the destination must be /Applications. -- `volumes_dir` - Directory under /Volumes where the dmg is mounted. Not all dmgs are mounted into a /Volumes location matching the name of the dmg. If not specified, this will use the name attribute. -- `package_id` - Package id registered with pkgutil when a pkg or mpkg is installed -- `dmg_name` - Specify the name of the dmg if it is not the same as `app`, or if the name has spaces. -- `dmg_passphrase` - Specify a passphrase to use to unencrypt the dmg while mounting. -- `accept_eula` - Specify whether to accept the EULA. Certain dmgs require acceptance of EULA before mounting. Can be true or false, defaults to false. -- `headers` - Allows custom HTTP headers (like cookies) to be set on the remote_file resource. -- `allow_untrusted` - Allows packages with untrusted certs to be installed. - -#### Examples - -Install `/Applications/Tunnelblick.app` from the primary download site. - -```ruby -dmg_package 'Tunnelblick' do - source 'https://tunnelblick.net/release/Tunnelblick_3.7.0_build_4790.dmg' - checksum '5053038aa8caf7dea66dcab11d6d240672216e6546eff4c2622e216c61af85e5' - action :install -end -``` - -Install Google Chrome. Uses the `dmg_name` because the application name has spaces. Installs in `/Applications/Google Chrome.app`. - -```ruby -dmg_package 'Google Chrome' do - dmg_name 'googlechrome' - source 'https://dl-ssl.google.com/chrome/mac/stable/GGRM/googlechrome.dmg' - checksum '7daa2dc5c46d9bfb14f1d7ff4b33884325e5e63e694810adc58f14795165c91a' - action :install -end -``` - -Install Dropbox. Uses `volumes_dir` because the mounted directory is different than the name of the application directory. Installs in `/Applications/Dropbox.app`. - -```ruby -dmg_package 'Dropbox' do - volumes_dir 'Dropbox Installer' - source 'http://www.dropbox.com/download?plat=mac' - checksum 'b4ea620ca22b0517b75753283ceb82326aca8bc3c86212fbf725de6446a96a13' - action :install -end -``` - -Install MacIrssi to `~/Applications` from the local file downloaded to the cache path into an Applications directory in the current user's home directory. Chef should run as a non-root user for this. - -```ruby -directory "#{ENV['HOME']}/Applications" - -dmg_package 'MacIrssi' do - destination "#{ENV['HOME']}/Applications" - action :install -end -``` - -Install Virtualbox to `/Applications` from the .mpkg: - -```ruby -dmg_package 'Virtualbox' do - source 'http://dlc.sun.com.edgesuite.net/virtualbox/4.0.8/VirtualBox-4.0.8-71778-OSX.dmg' - type 'mpkg' -end -``` - -Install pgAdmin to `/Applications` and automatically accept the EULA: - -```ruby -dmg_package 'pgAdmin3' do - source 'http://wwwmaster.postgresql.org/redir/198/h/pgadmin3/release/v1.12.3/osx/pgadmin3-1.12.3.dmg' - checksum '9435f79d5b52d0febeddfad392adf82db9df159196f496c1ab139a6957242ce9' - accept_eula true -end -``` - -Install Silverlight, with idempotence check based on pkgutil: - -```ruby -dmg_package 'Silerlight' do - source 'http://silverlight.dlservice.microsoft.com/download/D/C/2/DC2D5838-9138-4D25-AA92-52F61F7C51E6/runtime/Silverlight.dmg' - type 'pkg' - checksum '6d4a0ad4552d9815531463eb3f467fb8cf4bffcc' - package_id 'com.microsoft.installSilverlightPlugin' -end -``` - -## License & Authors - -**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io)) - -**Copyright:** 2011-2017, Chef Software, Inc. - -``` -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -``` diff --git a/cookbooks/dmg/metadata.json b/cookbooks/dmg/metadata.json deleted file mode 100644 index 7c3f674..0000000 --- a/cookbooks/dmg/metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"dmg","version":"4.1.1","description":"Resource for installing macOS applications from DMGs","long_description":"The dmg_package resource is now included in Chef 14 and this cookbook has been deprecated. We highly recommend updating to Chef 14 so you can use this resource without the need for a cookbook dependency.\n\n# dmg Cookbook\n\n[![Build Status](https://travis-ci.org/chef-cookbooks/dmg.svg?branch=master)](https://travis-ci.org/chef-cookbooks/dmg) [![Cookbook Version](https://img.shields.io/cookbook/v/dmg.svg)](https://supermarket.chef.io/cookbooks/dmg)\n\nResource to install OS X applications (.app) from dmg files.\n\n## Requirements\n\n### Platforms\n\n- macOS\n\n### Chef\n\n- Chef 12.5+\n\n### Cookbooks\n\n- none\n\n## Resources/Providers\n\n### dmg_package\n\nThis resource will install a DMG \"Package\". It will retrieve the DMG from a remote URL, mount it using OS X's `hdid`, copy the application (.app directory) to the specified destination (/Applications), and detach the image using `hdiutil`. The dmg file will be stored in the `Chef::Config[:file_cache_path]`. If you want to install an application that has already been downloaded (not using the `source` parameter), copy it to the appropriate location. You can find out what directory this is with the following command on the node to run chef:\n\n```bash\nknife exec -E 'p Chef::Config[:file_cache_path]' -c /etc/chef/client.rb\n```\n\nOptionally, the LWRP can install an \"mpkg\" or \"pkg\" package using installer(8).\n\n#### Actions\n\n- :install - Installs the application.\n\n#### Parameter attributes:\n\n- `app` - This is the name of the application used by default for the /Volumes directory and the .app directory copied to /Applications.\n- `source` - remote URL for the dmg to download if specified. Default is nil.\n- `file` - local dmg full file path. Default is nil.\n- `owner` - owner that should own the package installation.\n- `destination` - directory to copy the .app into. Default is /Applications.\n- `checksum` - sha256 checksum of the dmg to download. Default is nil.\n- `type` - type of package, \"app\", \"pkg\" or \"mpkg\". Default is \"app\". When using \"pkg\" or \"mpkg\", the destination must be /Applications.\n- `volumes_dir` - Directory under /Volumes where the dmg is mounted. Not all dmgs are mounted into a /Volumes location matching the name of the dmg. If not specified, this will use the name attribute.\n- `package_id` - Package id registered with pkgutil when a pkg or mpkg is installed\n- `dmg_name` - Specify the name of the dmg if it is not the same as `app`, or if the name has spaces.\n- `dmg_passphrase` - Specify a passphrase to use to unencrypt the dmg while mounting.\n- `accept_eula` - Specify whether to accept the EULA. Certain dmgs require acceptance of EULA before mounting. Can be true or false, defaults to false.\n- `headers` - Allows custom HTTP headers (like cookies) to be set on the remote_file resource.\n- `allow_untrusted` - Allows packages with untrusted certs to be installed.\n\n#### Examples\n\nInstall `/Applications/Tunnelblick.app` from the primary download site.\n\n```ruby\ndmg_package 'Tunnelblick' do\n source 'https://tunnelblick.net/release/Tunnelblick_3.7.0_build_4790.dmg'\n checksum '5053038aa8caf7dea66dcab11d6d240672216e6546eff4c2622e216c61af85e5'\n action :install\nend\n```\n\nInstall Google Chrome. Uses the `dmg_name` because the application name has spaces. Installs in `/Applications/Google Chrome.app`.\n\n```ruby\ndmg_package 'Google Chrome' do\n dmg_name 'googlechrome'\n source 'https://dl-ssl.google.com/chrome/mac/stable/GGRM/googlechrome.dmg'\n checksum '7daa2dc5c46d9bfb14f1d7ff4b33884325e5e63e694810adc58f14795165c91a'\n action :install\nend\n```\n\nInstall Dropbox. Uses `volumes_dir` because the mounted directory is different than the name of the application directory. Installs in `/Applications/Dropbox.app`.\n\n```ruby\ndmg_package 'Dropbox' do\n volumes_dir 'Dropbox Installer'\n source 'http://www.dropbox.com/download?plat=mac'\n checksum 'b4ea620ca22b0517b75753283ceb82326aca8bc3c86212fbf725de6446a96a13'\n action :install\nend\n```\n\nInstall MacIrssi to `~/Applications` from the local file downloaded to the cache path into an Applications directory in the current user's home directory. Chef should run as a non-root user for this.\n\n```ruby\ndirectory \"#{ENV['HOME']}/Applications\"\n\ndmg_package 'MacIrssi' do\n destination \"#{ENV['HOME']}/Applications\"\n action :install\nend\n```\n\nInstall Virtualbox to `/Applications` from the .mpkg:\n\n```ruby\ndmg_package 'Virtualbox' do\n source 'http://dlc.sun.com.edgesuite.net/virtualbox/4.0.8/VirtualBox-4.0.8-71778-OSX.dmg'\n type 'mpkg'\nend\n```\n\nInstall pgAdmin to `/Applications` and automatically accept the EULA:\n\n```ruby\ndmg_package 'pgAdmin3' do\n source 'http://wwwmaster.postgresql.org/redir/198/h/pgadmin3/release/v1.12.3/osx/pgadmin3-1.12.3.dmg'\n checksum '9435f79d5b52d0febeddfad392adf82db9df159196f496c1ab139a6957242ce9'\n accept_eula true\nend\n```\n\nInstall Silverlight, with idempotence check based on pkgutil:\n\n```ruby\ndmg_package 'Silerlight' do\n source 'http://silverlight.dlservice.microsoft.com/download/D/C/2/DC2D5838-9138-4D25-AA92-52F61F7C51E6/runtime/Silverlight.dmg'\n type 'pkg'\n checksum '6d4a0ad4552d9815531463eb3f467fb8cf4bffcc'\n package_id 'com.microsoft.installSilverlightPlugin'\nend\n```\n\n## License & Authors\n\n**Author:** Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io))\n\n**Copyright:** 2011-2017, Chef Software, Inc.\n\n```\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache-2.0","platforms":{"mac_os_x":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chef-cookbooks/dmg","issues_url":"https://github.com/chef-cookbooks/dmg/issues","chef_version":[[">= 12.5"]],"ohai_version":[]} \ No newline at end of file diff --git a/cookbooks/dmg/recipes/default.rb b/cookbooks/dmg/recipes/default.rb deleted file mode 100644 index 2690d0c..0000000 --- a/cookbooks/dmg/recipes/default.rb +++ /dev/null @@ -1,20 +0,0 @@ -# -# Cookbook:: dmg -# Recipe:: default -# -# Copyright:: 2011-2017, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Chef::Log.warn('The dmg::default recipe does not contain any resources and should not be applied to a node') diff --git a/cookbooks/dmg/resources/package.rb b/cookbooks/dmg/resources/package.rb deleted file mode 100644 index 71b5327..0000000 --- a/cookbooks/dmg/resources/package.rb +++ /dev/null @@ -1,102 +0,0 @@ -# -# Author:: Joshua Timberman () -# Cookbook:: dmg -# Resource:: package -# -# Copyright:: 2011-2017, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -property :app, String, name_property: true -property :source, String -property :file, String -property :owner, String -property :destination, String, default: '/Applications' -property :checksum, String -property :volumes_dir, String -property :dmg_name, String -property :type, String, default: 'app', equal_to: %w(app pkg mpkg) -property :installed, [true, false], default: false, desired_state: false -property :package_id, String -property :dmg_passphrase, String -property :accept_eula, [true, false], default: false -property :headers, [Hash, nil], default: nil -property :allow_untrusted, [true, false], default: false - -load_current_value do |new_resource| - if ::File.directory?("#{new_resource.destination}/#{new_resource.app}.app") - Chef::Log.info "Already installed; to upgrade, remove \"#{new_resource.destination}/#{new_resource.app}.app\"" - installed true - elsif shell_out("pkgutil --pkgs='#{new_resource.package_id}'").exitstatus == 0 - Chef::Log.info "Already installed; to upgrade, try \"sudo pkgutil --forget '#{new_resource.package_id}'\"" - installed true - else - installed false - end -end - -action :install do - unless current_resource.installed - - volumes_dir = new_resource.volumes_dir ? new_resource.volumes_dir : new_resource.app - dmg_name = new_resource.dmg_name ? new_resource.dmg_name : new_resource.app - - dmg_file = if new_resource.file.nil? - "#{Chef::Config[:file_cache_path]}/#{dmg_name}.dmg" - else - new_resource.file - end - - remote_file "#{dmg_file} - #{new_resource.name}" do - path dmg_file - source new_resource.source - headers new_resource.headers if new_resource.headers - checksum new_resource.checksum if new_resource.checksum - end if new_resource.source - - passphrase_cmd = new_resource.dmg_passphrase ? "-passphrase #{new_resource.dmg_passphrase}" : '' - ruby_block "attach #{dmg_file}" do - block do - cmd = shell_out("hdiutil imageinfo #{passphrase_cmd} '#{dmg_file}' | grep -q 'Software License Agreement: true'") - software_license_agreement = cmd.exitstatus == 0 - raise "Requires EULA Acceptance; add 'accept_eula true' to package resource" if software_license_agreement && !new_resource.accept_eula - accept_eula_cmd = new_resource.accept_eula ? 'echo Y | PAGER=true' : '' - shell_out!("#{accept_eula_cmd} hdiutil attach #{passphrase_cmd} '#{dmg_file}' -mountpoint '/Volumes/#{volumes_dir}' -quiet") - end - not_if "hdiutil info #{passphrase_cmd} | grep -q 'image-path.*#{dmg_file}'" - end - - case new_resource.type - when 'app' - execute "rsync --force --recursive --links --perms --executability --owner --group --times '/Volumes/#{volumes_dir}/#{new_resource.app}.app' '#{new_resource.destination}'" do - user new_resource.owner if new_resource.owner - end - - declare_resource(:file, "#{new_resource.destination}/#{new_resource.app}.app/Contents/MacOS/#{new_resource.app}") do - mode '755' - ignore_failure true - end - when 'mpkg', 'pkg' - install_cmd = "installation_file=$(ls '/Volumes/#{volumes_dir}' | grep '.#{new_resource.type}$') && sudo installer -pkg \"/Volumes/#{volumes_dir}/$installation_file\" -target /" - install_cmd += ' -allowUntrusted' if new_resource.allow_untrusted - - execute install_cmd do - # Prevent cfprefsd from holding up hdiutil detach for certain disk images - environment('__CFPREFERENCES_AVOID_DAEMON' => '1') - end - end - - execute "hdiutil detach '/Volumes/#{volumes_dir}' || hdiutil detach '/Volumes/#{volumes_dir}' -force" - end -end diff --git a/cookbooks/git/.foodcritic b/cookbooks/git/.foodcritic deleted file mode 100644 index b9f8767..0000000 --- a/cookbooks/git/.foodcritic +++ /dev/null @@ -1 +0,0 @@ -~FC016 diff --git a/cookbooks/git/CHANGELOG.md b/cookbooks/git/CHANGELOG.md index d2f2797..324797b 100644 --- a/cookbooks/git/CHANGELOG.md +++ b/cookbooks/git/CHANGELOG.md @@ -2,6 +2,63 @@ This file is used to list changes made in each version of the git cookbook. +## 10.0.0 (2019-10-16) + +- Add testing for CentOS 8, openSUSE 15, Ubuntu 18.04 in Travis +- Require Chef Infra Client 14 or later so we can drop the dependency on build-essential +- Resolve multiple cookstyle warnings + +## 9.0.1 (2018-06-02) + +- Update the platforms we test on +- Remove extra attr_accessor in config and requires +- Bump git version to 2.17.1 to resolve CVE + +## 9.0.0 (2018-03-08) + +- Remove the dependency on the homebrew cookbook by not automatically installing homebrew in the git resource on macOS systems. Homebrew needs to be setup before this resource runs and that should probably be the very first thing you do on a macOS system +- Use the build_essential resource instead of including the default recipe. This requires version 5.0 or later of the build-essential cookbook and allows us to use the build_essential resource that will be built into Chef 14 when that ships +- Remove extra includes in the resources that weren't necessary +- Updated testing to include Fedora 27, Ubuntu 18.04, Debian 9, macOS 10.12, and Windows 2016 + +## 8.0.1 (2018-02-10) + +- Resolve the new FC118 foodcritic warning +- Remove the ChefSpec matchers which are auto generated now +- Resolve FC104 warning + +## 8.0.0 (2017-09-01) + +### Breaking Changes + +- macOS resource now properly executes and uses homebrew to install git instead of dmg and packages posted to SourceForge +- Default to Git 2.9.5 now, which properly compiles on Fedora / Amazon Linux + +## Other Changes + +- Fixed support for Amazon Linux on Chef 13 +- Unified the package setup for source installs which fixes Amazon/Fedora +- Removed an entirely duplicate service provider +- Remove unused runit templates +- Properly fail when we're on an unsupported platform + +## 7.0.0 (2017-09-01) + +- Remove support for RHEL 5 which removes the need for the yum-epel cookbook +- Move templates out of the default directory now that we require Chef 12 +- Remove support for Ubuntu 10.04 +- Remove the version requirement on mac_os_x in the metadata +- Move maintainer information to the readme +- Expand Travis testing + +## 6.1.0 (2017-05-30) + +- Test with Local Delivery and not Rake +- Remove EOL platforms from the kitchen configs +- Use a SPDX standard license string +- Updated default versions documented in README to fix Issue #120. +- Remove class_eval and require chef 12.7+ + ## 6.0.0 (2017-02-14) - Fail on deprecations is now enabled so we're fully Chef 13 compatible diff --git a/cookbooks/git/MAINTAINERS.md b/cookbooks/git/MAINTAINERS.md deleted file mode 100644 index 645ed14..0000000 --- a/cookbooks/git/MAINTAINERS.md +++ /dev/null @@ -1,15 +0,0 @@ - - -# Maintainers - -This file lists how this cookbook project is maintained. When making changes to the system, this file tells you who needs to review your patch - you need a review from an existing maintainer for the cookbook to provide a :+1: on your pull request. Additionally, you need to not receive a veto from a Lieutenant or the Project Lead. - -Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) for details on the process and how to become a maintainer or the project lead. - -# Project Maintainer -* [Tim Smith](https://github.com/tas50) - -# Maintainers -* [Jennifer Davis](https://github.com/sigje) -* [Tim Smith](https://github.com/tas50) -* [Thom May](https://github.com/thommay) diff --git a/cookbooks/git/README.md b/cookbooks/git/README.md index 2196803..6619a1d 100644 --- a/cookbooks/git/README.md +++ b/cookbooks/git/README.md @@ -20,17 +20,17 @@ The following platforms have been tested with Test Kitchen: |---------------+-------| | centos-7 | X | |---------------+-------| +| centos-8 | X | +|---------------+-------| | fedora | X | |---------------+-------| -| debian-7 | X | +| debian-9 | X | |---------------+-------| -| debian-8 | X | -|---------------+-------| -| ubuntu-14.04 | X | +| debian-10 | X | |---------------+-------| | ubuntu-16.04 | X | |---------------+-------| -| openSUSE 13.2 | X | +| ubuntu-18.04 | X | |---------------+-------| | openSUSE Leap | X | |---------------+-------| @@ -38,13 +38,11 @@ The following platforms have been tested with Test Kitchen: ### Chef -- Chef 12.5+ +- Chef 14+ ### Cookbooks -- depends 'build-essential' - For compiling from source -- depends 'dmg' - For macOS Support -- depends 'yum-epel' - For older RHEL platform_family support +- none ## Usage @@ -60,6 +58,8 @@ Add `git::default`, `git::source` or `git::windows` to your run_list OR add `dep The `git_client` resource manages the installation of a Git client on a machine. +`Note`: on macOS systems homebrew must first be installed on the system before running this resource. Prior to version 9.0 of this cookbook homebrew was automatically installed. + #### Example ```ruby @@ -68,6 +68,17 @@ git_client 'default' do end ``` +#### Example of source install + +```ruby +git_client 'source' do + provider Chef::Provider::GitClient::Source + source_version '2.14.2' + source_checksum 'a03a12331d4f9b0f71733db9f47e1232d4ddce00e7f2a6e20f6ec9a19ce5ff61' + action :install +end +``` + ### git_config The `git_config` resource manages the configuration of Git client on a machine. @@ -96,23 +107,15 @@ Currently, there are distinct sets of resource properties, used by the providers - `source_prefix` - Defaults to '/usr/local' - `source_url` - Defaults to a calculated URL based on source_version -- `source_version` - Defaults to 2.7.4 +- `source_version` - Defaults to 2.8.1 - `source_use_pcre` - configure option for build. Defaults to false -- `source_checksum` - Defaults to a known value for the 2.7.4 source tarball - -# used by OSX package providers - -- `osx_dmg_app_name` - Defaults to 'git-2.7.1-intel-universal-mavericks' -- `osx_dmg_package_id` - Defaults to 'GitOSX.Installer.git271.git.pkg' -- `osx_dmg_volumes_dir` - Defaults to 'Git 2.7.1 Mavericks Intel Universal' -- `osx_dmg_url` - Defaults to Sourceforge -- `osx_dmg_checksum` - Defaults to the value for 2.7.1 +- `source_checksum` - Defaults to a known value for the 2.8.1 source tarball # used by the Windows package providers - `windows_display_name` - Windows display name - `windows_package_url` - Defaults to the Internet -- `windows_package_checksum` - Defaults to the value for 2.7.4 +- `windows_package_checksum` - Defaults to the value for 2.8.1 ## Recipes @@ -127,11 +130,6 @@ This cookbook ships with ready to use, attribute driven recipes that utilize the - `node['git']['checksum']` - package SHA256 checksum - `node['git']['display_name']` - `windows_package` resource Display Name (makes the package install idempotent) -### Mac OS X - -- `node['git']['osx_dmg']['url']` - URL to git package -- `node['git']['osx_dmg']['checksum']` - package SHA256 checksum - ### Linux - `node['git']['prefix']` - git install directory @@ -140,11 +138,13 @@ This cookbook ships with ready to use, attribute driven recipes that utilize the - `node['git']['checksum']` - tarball SHA256 checksum - `node['git']['use_pcre']` - if true, builds git with PCRE enabled -## License & Authors +## Maintainers -- Author:: Joshua Timberman ([joshua@chef.io](mailto:joshua@chef.io)) -- Author:: Sean OMeara ([sean@sean.io](mailto:sean@sean.io)) -- Copyright:: 2009-2017, Chef Software, Inc. +This cookbook is maintained by Chef's Community Cookbook Engineering team. Our goal is to improve cookbook quality and to aid the community in contributing to cookbooks. To learn more about our team, process, and design goals see our [team documentation](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/COOKBOOK_TEAM.MD). To learn more about contributing to cookbooks like this see our [contributing documentation](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD), or if you have general questions about this cookbook come chat with us in #cookbok-engineering on the [Chef Community Slack](http://community-slack.chef.io/) + +## License + +**Copyright:** 2009-2017, Chef Software, Inc. ``` Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/cookbooks/git/attributes/default.rb b/cookbooks/git/attributes/default.rb index a8b339e..7dc1b1a 100644 --- a/cookbooks/git/attributes/default.rb +++ b/cookbooks/git/attributes/default.rb @@ -3,7 +3,7 @@ # Cookbook:: git # Attributes:: default # -# Copyright:: 2008-2016, Chef Software, Inc. +# Copyright:: 2008-2019, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License. @@ -29,17 +29,11 @@ when 'windows' end default['git']['url'] = 'https://github.com/git-for-windows/git/releases/download/v%{version}.windows.1/Git-%{version}-%{architecture}-bit.exe' default['git']['display_name'] = "Git version #{node['git']['version']}" -when 'mac_os_x' - default['git']['osx_dmg']['app_name'] = 'git-2.8.1-intel-universal-mavericks' - default['git']['osx_dmg']['volumes_dir'] = 'Git 2.8.1 Mavericks Intel Universal' - default['git']['osx_dmg']['package_id'] = 'GitOSX.Installer.git281Universal.git.pkg' - default['git']['osx_dmg']['url'] = 'http://sourceforge.net/projects/git-osx-installer/files/git-2.8.1-intel-universal-mavericks.dmg/download' - default['git']['osx_dmg']['checksum'] = 'c2912895a1e2018d9be4c646765d511f7c82e0114275505dbd13d1ac70c62023' else default['git']['prefix'] = '/usr/local' - default['git']['version'] = '2.8.1' + default['git']['version'] = '2.17.1' default['git']['url'] = 'https://nodeload.github.com/git/git/tar.gz/v%{version}' - default['git']['checksum'] = 'e08503ecaf5d3ac10c40f22871c996a392256c8d038d16f52ebf974cba29ae42' + default['git']['checksum'] = '690f12cc5691e5adaf2dd390eae6f5acce68ae0d9bd9403814f8a1433833f02a' default['git']['use_pcre'] = false end diff --git a/cookbooks/git/libraries/helpers.rb b/cookbooks/git/libraries/helpers.rb index bedde84..7bf29b3 100644 --- a/cookbooks/git/libraries/helpers.rb +++ b/cookbooks/git/libraries/helpers.rb @@ -3,9 +3,8 @@ module GitCookbook # linux packages default to distro offering def parsed_package_name return new_resource.package_name if new_resource.package_name - return 'git-core' if node['platform'] == 'ubuntu' && node['platform_version'].to_f < 10.10 - return 'developer/versioning/git' if node['platform'] == 'omnios' - return 'scmgit' if node['platform'] == 'smartos' + return 'developer/versioning/git' if platform?('smartos') + return 'scmgit' if platform?('smartos') 'git' end @@ -21,7 +20,7 @@ module GitCookbook def parsed_source_checksum return new_resource.source_checksum if new_resource.source_checksum - '8d53703d75890c03e26a915c7af3b7b98d8cfb94382f685a9bcbee1eeaec47b4' # 2.7.4 tarball + '690f12cc5691e5adaf2dd390eae6f5acce68ae0d9bd9403814f8a1433833f02a' # 2.17.1 tarball end # windows diff --git a/cookbooks/git/libraries/matchers.rb b/cookbooks/git/libraries/matchers.rb deleted file mode 100644 index 25ed8df..0000000 --- a/cookbooks/git/libraries/matchers.rb +++ /dev/null @@ -1,16 +0,0 @@ -if defined?(ChefSpec) - ChefSpec.define_matcher(:git_client) - ChefSpec.define_matcher(:git_service) - - def set_git_config(resource_name) # rubocop:disable Style/AccessorMethodName - ChefSpec::Matchers::ResourceMatcher.new(:git_config, :set, resource_name) - end - - def install_git_client(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:git_client, :install, resource_name) - end - - def install_git_service(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:git_service, :install, resource_name) - end -end diff --git a/cookbooks/git/libraries/provider_git_client.rb b/cookbooks/git/libraries/provider_git_client.rb index 41d7cfd..84aaa45 100644 --- a/cookbooks/git/libraries/provider_git_client.rb +++ b/cookbooks/git/libraries/provider_git_client.rb @@ -1,12 +1,6 @@ class Chef class Provider class GitClient < Chef::Provider::LWRPBase - use_inline_resources - - def whyrun_supported? - true - end - include GitCookbook::Helpers end end diff --git a/cookbooks/git/libraries/provider_git_client_osx.rb b/cookbooks/git/libraries/provider_git_client_osx.rb index db604c9..cb3dea3 100644 --- a/cookbooks/git/libraries/provider_git_client_osx.rb +++ b/cookbooks/git/libraries/provider_git_client_osx.rb @@ -2,20 +2,10 @@ class Chef class Provider class GitClient class Osx < Chef::Provider::GitClient - include Chef::DSL::IncludeRecipe - - provides :git_client, os: 'mac_os_x' + provides :git_client, platform: 'mac_os_x' action :install do - dmg_package 'GitOSX-Installer' do - app new_resource.osx_dmg_app_name - package_id new_resource.osx_dmg_package_id - volumes_dir new_resource.osx_dmg_volumes_dir - source new_resource.osx_dmg_url - checksum new_resource.osx_dmg_checksum - type 'pkg' - action :install - end + package 'git' end action :delete do diff --git a/cookbooks/git/libraries/provider_git_client_package.rb b/cookbooks/git/libraries/provider_git_client_package.rb index 8c750e3..38db86d 100644 --- a/cookbooks/git/libraries/provider_git_client_package.rb +++ b/cookbooks/git/libraries/provider_git_client_package.rb @@ -2,14 +2,9 @@ class Chef class Provider class GitClient class Package < Chef::Provider::GitClient - include Chef::DSL::IncludeRecipe - provides :git_client, os: 'linux' action :install do - # FIXME: rhel 5 - include_recipe 'yum-epel' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 5 - # Software installation package "#{new_resource.name} :create #{parsed_package_name}" do package_name parsed_package_name diff --git a/cookbooks/git/libraries/provider_git_client_source.rb b/cookbooks/git/libraries/provider_git_client_source.rb index 6ab8bc7..7add0a9 100644 --- a/cookbooks/git/libraries/provider_git_client_source.rb +++ b/cookbooks/git/libraries/provider_git_client_source.rb @@ -2,30 +2,16 @@ class Chef class Provider class GitClient class Source < Chef::Provider::GitClient - include Chef::DSL::IncludeRecipe - action :install do - return "#{node['platform']} is not supported by the #{cookbook_name}::#{recipe_name} recipe" unless platform_family?('rhel', 'suse', 'fedora', 'debian') + raise "#{node['platform']} is not supported by the git_client source resource" unless platform_family?('rhel', 'suse', 'fedora', 'debian', 'amazon') - include_recipe 'build-essential' - include_recipe 'yum-epel' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 5 + build_essential 'install compilation tools for git' # move this to attributes. case node['platform_family'] - when 'fedora' - pkgs = %w(tar openssl-devel libcurl-devel expat-devel perl-ExtUtils-MakeMaker) - when 'rhel' - case node['platform_version'].to_i - when 5 - pkgs = %w(tar expat-devel gettext-devel curl-devel openssl-devel zlib-devel) - pkgs += %w( pcre-devel ) if new_resource.source_use_pcre - when 6, 7 - pkgs = %w(tar expat-devel gettext-devel libcurl-devel openssl-devel perl-ExtUtils-MakeMaker zlib-devel) - pkgs += %w( pcre-devel ) if new_resource.source_use_pcre - else - pkgs = %w(expat-devel gettext-devel curl-devel openssl-devel perl-ExtUtils-MakeMaker zlib-devel) if node['platform'] == 'amazon' - pkgs += %w( pcre-devel ) if new_resource.source_use_pcre - end + when 'rhel', 'fedora', 'amazon' + pkgs = %w(tar expat-devel gettext-devel libcurl-devel openssl-devel perl-ExtUtils-MakeMaker zlib-devel) + pkgs += %w( pcre-devel ) if new_resource.source_use_pcre when 'debian' pkgs = %w(libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev) pkgs += %w( libpcre3-dev ) if new_resource.source_use_pcre @@ -52,7 +38,7 @@ class Chef command <<-COMMAND (mkdir git-#{new_resource.source_version} && tar -zxf git-#{new_resource.source_version}.tar.gz -C git-#{new_resource.source_version} --strip-components 1) (cd git-#{new_resource.source_version} && make prefix=#{new_resource.source_prefix} #{additional_make_params} install) - COMMAND + COMMAND not_if "git --version | grep #{new_resource.source_version}" not_if "#{new_resource.source_prefix}/bin/git --version | grep #{new_resource.source_version}" end diff --git a/cookbooks/git/libraries/provider_git_client_windows.rb b/cookbooks/git/libraries/provider_git_client_windows.rb index 305cdd2..8b88e1a 100644 --- a/cookbooks/git/libraries/provider_git_client_windows.rb +++ b/cookbooks/git/libraries/provider_git_client_windows.rb @@ -3,8 +3,6 @@ class Chef class Provider class GitClient class Windows < Chef::Provider::GitClient - include Chef::DSL::IncludeRecipe - provides :git_client, os: 'windows' action :install do @@ -22,7 +20,7 @@ class Chef else ENV['ProgramW6432'] || ENV['ProgramFiles'] end - GIT_PATH = "#{PROGRAM_FILES}\\Git\\Cmd".freeze + GIT_PATH = "#{PROGRAM_FILES}\\Git\\Cmd" # COOK-3482 - windows_path resource doesn't change the current process # environment variables. Therefore, git won't actually be on the PATH @@ -36,7 +34,7 @@ class Chef end windows_path GIT_PATH do - notifies :create, 'ruby_block[Add Git Path]', :immediately + notifies :run, 'ruby_block[Add Git Path]', :immediately action :add end end diff --git a/cookbooks/git/libraries/provider_git_service.rb b/cookbooks/git/libraries/provider_git_service.rb index 7f74e90..b7b200a 100644 --- a/cookbooks/git/libraries/provider_git_service.rb +++ b/cookbooks/git/libraries/provider_git_service.rb @@ -1,19 +1,13 @@ class Chef class Provider class GitClient < Chef::Provider::LWRPBase - use_inline_resources - - def whyrun_supported? - true - end - include Chef::DSL::IncludeRecipe include GitCookbook::Helpers provides :git_service, os: 'linux' action :create do - return "#{node['platform']} is not supported by the #{cookbook_name}::#{recipe_name} recipe" if node['platform'] == 'windows' + return "#{node['platform']} is not supported by the #{cookbook_name}::#{recipe_name} recipe" if platform?('windows') include_recipe 'git' diff --git a/cookbooks/git/libraries/provider_git_service_xinetd.rb b/cookbooks/git/libraries/provider_git_service_xinetd.rb deleted file mode 100644 index 74b524e..0000000 --- a/cookbooks/git/libraries/provider_git_service_xinetd.rb +++ /dev/null @@ -1,55 +0,0 @@ -class Chef - class Provider - class GitClient < Chef::Provider::LWRPBase - use_inline_resources - - def whyrun_supported? - true - end - - include Chef::DSL::IncludeRecipe - include GitCookbook::Helpers - - action :create do - return "#{node['platform']} is not supported by the #{cookbook_name}::#{recipe_name} recipe" if node['platform'] == 'windows' - - include_recipe 'git' - - directory new_resource.service_base_path do - owner 'root' - group 'root' - mode '0755' - end - - case node['platform_family'] - when 'debian' - package 'xinetd' - when 'rhel' - package 'git-daemon' - else - log 'Platform requires setting up a git daemon service script.' - log "Hint: /usr/bin/git daemon --export-all --user=nobody --group=daemon --base-path=#{new_resource.service_base_path}" - return - end - - template '/etc/xinetd.d/git' do - backup false - source 'git-xinetd.d.erb' - owner 'root' - group 'root' - mode '0644' - variables( - git_daemon_binary: value_for_platform_family( - 'debian' => '/usr/lib/git-core/git-daemon', - 'rhel' => '/usr/libexec/git-core/git-daemon' - ) - ) - end - - service 'xinetd' do - action [:enable, :restart] - end - end - end - end -end diff --git a/cookbooks/git/metadata.json b/cookbooks/git/metadata.json index 28f80e7..e8249be 100644 --- a/cookbooks/git/metadata.json +++ b/cookbooks/git/metadata.json @@ -1 +1 @@ -{"name":"git","version":"6.0.0","description":"Installs git and/or sets up a Git server daemon","long_description":"# Git Cookbook\n\n[![Build Status](https://travis-ci.org/chef-cookbooks/git.svg?branch=master)](https://travis-ci.org/chef-cookbooks/git) [![Cookbook Version](https://img.shields.io/cookbook/v/git.svg)](https://supermarket.chef.io/cookbooks/git)\n\nInstalls git_client from package or source. Optionally sets up a git service under xinetd.\n\n## Scope\n\nThis cookbook is concerned with the Git SCM utility. It does not address ecosystem tooling or related projects.\n\n## Requirements\n\n### Platforms\n\nThe following platforms have been tested with Test Kitchen:\n\n```\n|---------------+-------|\n| centos-6 | X |\n|---------------+-------|\n| centos-7 | X |\n|---------------+-------|\n| fedora | X |\n|---------------+-------|\n| debian-7 | X |\n|---------------+-------|\n| debian-8 | X |\n|---------------+-------|\n| ubuntu-14.04 | X |\n|---------------+-------|\n| ubuntu-16.04 | X |\n|---------------+-------|\n| openSUSE 13.2 | X |\n|---------------+-------|\n| openSUSE Leap | X |\n|---------------+-------|\n```\n\n### Chef\n\n- Chef 12.5+\n\n### Cookbooks\n\n- depends 'build-essential' - For compiling from source\n- depends 'dmg' - For macOS Support\n- depends 'yum-epel' - For older RHEL platform_family support\n\n## Usage\n\nAdd `git::default`, `git::source` or `git::windows` to your run_list OR add `depends 'git', '~> 4.3'` to your cookbook's metadata.rb. include_recipe one of the recipes from your cookbook OR use the git_client resource directly, the same way you'd use core Chef resources (file, template, directory, package, etc).\n\n## Resources Overview\n\n- `git_client`: Manages a Git client installation on a machine. Acts as a singleton when using the (default) package provider. Source provider available as well.\n- `git_service`: Sets up a Git service via xinetd. WARNING: This is insecure and will probably be removed in the future\n- `git_config`: Sets up Git configuration on a node.\n\n### git_client\n\nThe `git_client` resource manages the installation of a Git client on a machine.\n\n#### Example\n\n```ruby\ngit_client 'default' do\n action :install\nend\n```\n\n### git_config\n\nThe `git_config` resource manages the configuration of Git client on a machine.\n\n#### Example\n\n```ruby\ngit_config 'url.https://github.com/.insteadOf' do\n value 'git://github.com/'\n scope 'system'\n options '--add'\nend\n```\n\n#### Properties\n\nCurrently, there are distinct sets of resource properties, used by the providers for source, package, macos, and windows.\n\n# used by linux package providers\n\n- `package_name` - Package name to install on Linux machines. Defaults to a calculated value based on platform.\n- `package_version` - Defaults to nil.\n- `package_action` - Defaults to `:install`\n\n# used by source providers\n\n- `source_prefix` - Defaults to '/usr/local'\n- `source_url` - Defaults to a calculated URL based on source_version\n- `source_version` - Defaults to 2.7.4\n- `source_use_pcre` - configure option for build. Defaults to false\n- `source_checksum` - Defaults to a known value for the 2.7.4 source tarball\n\n# used by OSX package providers\n\n- `osx_dmg_app_name` - Defaults to 'git-2.7.1-intel-universal-mavericks'\n- `osx_dmg_package_id` - Defaults to 'GitOSX.Installer.git271.git.pkg'\n- `osx_dmg_volumes_dir` - Defaults to 'Git 2.7.1 Mavericks Intel Universal'\n- `osx_dmg_url` - Defaults to Sourceforge\n- `osx_dmg_checksum` - Defaults to the value for 2.7.1\n\n# used by the Windows package providers\n\n- `windows_display_name` - Windows display name\n- `windows_package_url` - Defaults to the Internet\n- `windows_package_checksum` - Defaults to the value for 2.7.4\n\n## Recipes\n\nThis cookbook ships with ready to use, attribute driven recipes that utilize the `git_client` and `git_service` resources. As of cookbook 4.x, they utilize the same attributes layout scheme from the 3.x. Due to some overlap, it is currently impossible to simultaneously install the Git client as a package and from source by using the \"manipulate a the node attributes and run a recipe\" technique. If you need both, you'll need to utilize the git_client resource in a recipe.\n\n## Attributes\n\n### Windows\n\n- `node['git']['version']` - git version to install\n- `node['git']['url']` - URL to git package\n- `node['git']['checksum']` - package SHA256 checksum\n- `node['git']['display_name']` - `windows_package` resource Display Name (makes the package install idempotent)\n\n### Mac OS X\n\n- `node['git']['osx_dmg']['url']` - URL to git package\n- `node['git']['osx_dmg']['checksum']` - package SHA256 checksum\n\n### Linux\n\n- `node['git']['prefix']` - git install directory\n- `node['git']['version']` - git version to install\n- `node['git']['url']` - URL to git tarball\n- `node['git']['checksum']` - tarball SHA256 checksum\n- `node['git']['use_pcre']` - if true, builds git with PCRE enabled\n\n## License & Authors\n\n- Author:: Joshua Timberman ([joshua@chef.io](mailto:joshua@chef.io))\n- Author:: Sean OMeara ([sean@sean.io](mailto:sean@sean.io))\n- Copyright:: 2009-2017, Chef Software, Inc.\n\n```\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","centos":">= 0.0.0","debian":">= 0.0.0","fedora":">= 0.0.0","freebsd":">= 0.0.0","mac_os_x":">= 10.6.0","omnios":">= 0.0.0","oracle":">= 0.0.0","redhat":">= 0.0.0","smartos":">= 0.0.0","scientific":">= 0.0.0","suse":">= 0.0.0","opensuse":">= 0.0.0","opensuseleap":">= 0.0.0","ubuntu":">= 0.0.0","windows":">= 0.0.0"},"dependencies":{"build-essential":">= 0.0.0","dmg":">= 0.0.0","yum-epel":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{"git":"Installs git","git::server":"Sets up a runit_service for git daemon","git::source":"Installs git from source"}} \ No newline at end of file +{"name":"git","version":"10.0.0","description":"Installs git and/or sets up a Git server daemon","long_description":"","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache-2.0","platforms":{"amazon":">= 0.0.0","centos":">= 0.0.0","debian":">= 0.0.0","fedora":">= 0.0.0","freebsd":">= 0.0.0","mac_os_x":">= 0.0.0","omnios":">= 0.0.0","oracle":">= 0.0.0","redhat":">= 0.0.0","smartos":">= 0.0.0","scientific":">= 0.0.0","suse":">= 0.0.0","opensuseleap":">= 0.0.0","ubuntu":">= 0.0.0","windows":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chef-cookbooks/git","issues_url":"https://github.com/chef-cookbooks/git/issues","chef_version":[[">= 14"]],"ohai_version":[]} \ No newline at end of file diff --git a/cookbooks/git/metadata.rb b/cookbooks/git/metadata.rb new file mode 100644 index 0000000..f45a478 --- /dev/null +++ b/cookbooks/git/metadata.rb @@ -0,0 +1,26 @@ +name 'git' +maintainer 'Chef Software, Inc.' +maintainer_email 'cookbooks@chef.io' +license 'Apache-2.0' +description 'Installs git and/or sets up a Git server daemon' +version '10.0.0' + +supports 'amazon' +supports 'centos' +supports 'debian' +supports 'fedora' +supports 'freebsd' +supports 'mac_os_x' +supports 'omnios' +supports 'oracle' +supports 'redhat' +supports 'smartos' +supports 'scientific' +supports 'suse' +supports 'opensuseleap' +supports 'ubuntu' +supports 'windows' + +source_url 'https://github.com/chef-cookbooks/git' +issues_url 'https://github.com/chef-cookbooks/git/issues' +chef_version '>= 14' diff --git a/cookbooks/git/recipes/default.rb b/cookbooks/git/recipes/default.rb index bc7feed..da57fa5 100644 --- a/cookbooks/git/recipes/default.rb +++ b/cookbooks/git/recipes/default.rb @@ -2,7 +2,7 @@ # Cookbook:: git # Recipe:: default # -# Copyright:: 2008-2016, Chef Software, Inc. +# Copyright:: 2008-2019, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/cookbooks/git/recipes/package.rb b/cookbooks/git/recipes/package.rb index e8812f6..af90138 100644 --- a/cookbooks/git/recipes/package.rb +++ b/cookbooks/git/recipes/package.rb @@ -2,7 +2,7 @@ # Cookbook:: git # Recipe:: package # -# Copyright:: 2008-2016, Chef Software, Inc. +# Copyright:: 2008-2019, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,17 +17,6 @@ # limitations under the License. case node['platform'] -when 'mac_os_x' - # FIXME: The resource has three distinct groups of properties used in - # different providers... should we make multiple resource types instead? - git_client 'default' do - osx_dmg_app_name node['git']['osx_dmg']['app_name'] - osx_dmg_package_id node['git']['osx_dmg']['package_id'] - osx_dmg_volumes_dir node['git']['osx_dmg']['volumes_dir'] - osx_dmg_url node['git']['osx_dmg']['url'] - osx_dmg_checksum node['git']['osx_dmg']['checksum'] - action :install - end when 'windows' include_recipe 'git::windows' else diff --git a/cookbooks/git/recipes/server.rb b/cookbooks/git/recipes/server.rb index 1567cbb..05ecb42 100644 --- a/cookbooks/git/recipes/server.rb +++ b/cookbooks/git/recipes/server.rb @@ -2,7 +2,7 @@ # Cookbook:: git # Recipe:: server # -# Copyright:: 2009-2016, Chef Software, Inc. +# Copyright:: 2009-2019, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/cookbooks/git/recipes/windows.rb b/cookbooks/git/recipes/windows.rb index 7fd5882..13cd459 100644 --- a/cookbooks/git/recipes/windows.rb +++ b/cookbooks/git/recipes/windows.rb @@ -2,7 +2,7 @@ # Cookbook:: git # Recipe:: windows # -# Copyright:: 2008-2016, Chef Software, Inc. +# Copyright:: 2008-2019, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/cookbooks/git/resources/config.rb b/cookbooks/git/resources/config.rb index 2f3d88c..3554bf0 100644 --- a/cookbooks/git/resources/config.rb +++ b/cookbooks/git/resources/config.rb @@ -1,4 +1,4 @@ -property :key, String, name_attribute: true +property :key, String, name_property: true property :value, String property :scope, equal_to: %w(local global system), default: 'global', desired_state: false property :path, String, desired_state: false @@ -6,10 +6,6 @@ property :user, String, desired_state: false property :group, String, desired_state: false property :options, String, desired_state: false -attr_accessor :exists - -require 'mixlib/shellout' - def initialize(*args) super @@ -38,7 +34,7 @@ action :set do end end -action_class.class_eval do +action_class do def config_cmd "git config --#{new_resource.scope}" end diff --git a/cookbooks/git/templates/default/sv-git-daemon-log-run.erb b/cookbooks/git/templates/default/sv-git-daemon-log-run.erb deleted file mode 100644 index a79a518..0000000 --- a/cookbooks/git/templates/default/sv-git-daemon-log-run.erb +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec svlogd -tt ./main diff --git a/cookbooks/git/templates/default/sv-git-daemon-run.erb b/cookbooks/git/templates/default/sv-git-daemon-run.erb deleted file mode 100644 index f340a23..0000000 --- a/cookbooks/git/templates/default/sv-git-daemon-run.erb +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -exec 2>&1 -exec /usr/bin/git daemon <%= node['git']['server']['export_all'] ? '--export-all' : nil %> --user=nobody --group=daemon --syslog --base-path=<%= node["git"]["server"]["base_path"] %> <%= node["git"]["server"]["base_path"] %> diff --git a/cookbooks/git/templates/default/git-xinetd.d.erb b/cookbooks/git/templates/git-xinetd.d.erb similarity index 100% rename from cookbooks/git/templates/default/git-xinetd.d.erb rename to cookbooks/git/templates/git-xinetd.d.erb diff --git a/cookbooks/golang/CHANGELOG.md b/cookbooks/golang/CHANGELOG.md new file mode 100644 index 0000000..0313261 --- /dev/null +++ b/cookbooks/golang/CHANGELOG.md @@ -0,0 +1,98 @@ +# CHANGELOG for golang + +This file is used to list changes made in each version of golang. + +## 4.1.0 + +- Create a custom resource to install Go from source or by downloading a package + +## 4.0.0 + +- Update testing setup: + - Use Chef Workstation instead of Rubygems + - Includes dropping `foodcritic` in favor of current `cookstyle` + - Add more recent & current distro versions + - Add very basic unit tests + - Use GitHub Actions instead of Travis CI +- Refactor minitest to Inspec +- Refactor to use current style of Chef Custom Resource +- Update default version to Go v1.14.4 +- Use `build_essential` when building from source + - Requires Chef >= 14.0.0 +- Omit attempting to install `bzr` on CentOS 8, they do not have that package available +- Utilize default Chef order-of-operations instead of `notifies` +- Use `ark` resource to simplify download & installation of binary & source +- Clean up unnecessary env vars from source build +- Build from source per [official Go docs](https://golang.org/doc/install/source) +- Use native resources instead of shell commands when building from source +- Set `$PATH` in `golang.sh` so that the existing values are last, per general practice +- Tighten up `golang_package` so it does not perform actions at compile time, it uses `execute` in favor of `bash` resources, and in general is more Chef-y +- Update tests to validate that non-root users can install Go and Go packages +- Refactor attributes to add ability to install a version from source that differs from the packaged version (which is needed to build from source) + +## 3.0.0 + +- rename to `chef-golang` so that metadata name matches repositoriy name + +## 2.0.0 + +- change attribute namespace to `node['golang']` + +## 1.7.2 + +- Better chef12,13 support +- Ruby 2.3 +- Update gems, lint + +## 1.7.1 + +- Create a temporary directory + +## 1.7.0 + +- Golang 1.5 + +## 1.6.2 + +- Ability to install from source + +## 1.6.0 + +- Removed support for Ruby 1.9.3 + +## 1.5.1 + +- Fix testing with Vagrant, Test-Kitchen +- Golang 1.4 + +## 1.5.0 + +- Golang 1.3 + +## 1.4.0 + +- Add build action to LWRP +- Update default go version to 1.2.2 +- Add autodetection the platform architecture +- Change package location to `http://golang.org/dl/` + +## 1.3.0 + +## 1.2.0 + +## 1.1.0 + +- Added package LWRP +- Configurable `gopath` & `gobin` + +## 1.0.2 + +- Lets users easily specify another install dir + +## 1.0.1 + +- Avoid extra unpacked copy of Go + +## 1.0.0 + +- Initial release of golang diff --git a/cookbooks/golang/CONTRIBUTING.md b/cookbooks/golang/CONTRIBUTING.md new file mode 100644 index 0000000..a946aea --- /dev/null +++ b/cookbooks/golang/CONTRIBUTING.md @@ -0,0 +1,4 @@ +# Contributing + +Please refer to +[https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) diff --git a/cookbooks/golang/README.md b/cookbooks/golang/README.md new file mode 100644 index 0000000..4328d7d --- /dev/null +++ b/cookbooks/golang/README.md @@ -0,0 +1,77 @@ +# Golang (Go) Cookbook + +[![Cookbook Version](https://img.shields.io/cookbook/v/golang.svg?style=flat)](https://supermarket.chef.io/cookbooks/golang) +[![CI State](https://github.com/sous-chefs/golang/workflows/ci/badge.svg)](https://github.com/sous-chefs/golang/actions?query=workflow%3Aci) +[![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) +[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) +[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) + +## Description + +Chef cookbook for the [Go programming language](http://golang.org/). + +## Requirements + +### Platform + +* Ubuntu >= 18.04 +* Debian >= 8 +* CentOS >= 7 + +## Usage + +### golang::default + +Include `golang` in your node's `run_list`: + +```json +{ + "name":"my_node", + "run_list": [ + "recipe[golang]" + ] +} +``` + +### golang::packages + +To install Go packages using node attributes add the packages to the `['golang']['packages']` attribute: + +```json +{ + "name":"my_node", + "golang": { + "packages": [ + "github.com/go-check/check" + ] + }, + "run_list": [ + "recipe[golang]" + ] +} +``` + +## Contributors + +This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) + +### Backers + +Thank you to all our backers! + +![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) + +### Sponsors + +Support this project by becoming a sponsor. Your logo will show up here with a link to your website. + +![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) diff --git a/cookbooks/golang/attributes/default.rb b/cookbooks/golang/attributes/default.rb new file mode 100644 index 0000000..6f049f7 --- /dev/null +++ b/cookbooks/golang/attributes/default.rb @@ -0,0 +1,15 @@ +# +# Cookbook:: golang +# Attribute:: default +# + +default['golang']['scm'] = true +default['golang']['scm_packages'] = value_for_platform( + 'centos' => { '>= 8' => %w(git mercurial) }, + 'default' => %w(git mercurial bzr) +) + +default['golang']['install_dir'] = '/usr/local' +default['golang']['gopath'] = '/opt/go' +default['golang']['gobin'] = '/opt/go/bin' +default['golang']['packages'] = [] diff --git a/cookbooks/golang/metadata.json b/cookbooks/golang/metadata.json new file mode 100644 index 0000000..2c1c376 --- /dev/null +++ b/cookbooks/golang/metadata.json @@ -0,0 +1 @@ +{"name":"golang","version":"4.1.0","description":"Installs go programming language","long_description":"","maintainer":"Sous Chefs","maintainer_email":"help@sous-chefs.org","license":"Apache-2.0","platforms":{"debian":">= 0.0.0","ubuntu":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","fedora":">= 0.0.0","amazon":">= 0.0.0","scientific":">= 0.0.0","oracle":">= 0.0.0"},"dependencies":{"ark":"~> 5.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/sous-chefs/golang","issues_url":"https://github.com/sous-chefs/golang/issues","chef_version":[[">= 14.0"]],"ohai_version":[]} \ No newline at end of file diff --git a/cookbooks/golang/metadata.rb b/cookbooks/golang/metadata.rb new file mode 100644 index 0000000..81e6bbb --- /dev/null +++ b/cookbooks/golang/metadata.rb @@ -0,0 +1,20 @@ +name 'golang' +maintainer 'Sous Chefs' +maintainer_email 'help@sous-chefs.org' +license 'Apache-2.0' +description 'Installs go programming language' +source_url 'https://github.com/sous-chefs/golang' +issues_url 'https://github.com/sous-chefs/golang/issues' +chef_version '>= 14.0' +version '4.1.0' + +supports 'debian' +supports 'ubuntu' +supports 'redhat' +supports 'centos' +supports 'fedora' +supports 'amazon' +supports 'scientific' +supports 'oracle' + +depends 'ark', '~> 5.0' diff --git a/cookbooks/golang/recipes/default.rb b/cookbooks/golang/recipes/default.rb new file mode 100644 index 0000000..91cec2d --- /dev/null +++ b/cookbooks/golang/recipes/default.rb @@ -0,0 +1,30 @@ +# +# Cookbook:: golang +# Recipe:: default +# +# Copyright:: 2013, Alexander Rozhnov +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +golang 'Install go' do + from_source node['golang']['from_source'] + version node['golang']['version'] if node['golang']['version'] # go version + source_version node['golang']['source_version'] if node['golang']['source_version'] # go version from source + owner node['golang']['owner'] if node['golang']['owner'] + group node['golang']['group'] if node['golang']['group'] +end + +node['golang']['packages'].each do |package| + golang_package package +end diff --git a/cookbooks/golang/resources/default.rb b/cookbooks/golang/resources/default.rb new file mode 100644 index 0000000..64c4d77 --- /dev/null +++ b/cookbooks/golang/resources/default.rb @@ -0,0 +1,167 @@ +# +# Cookbook:: golang +# Resource:: default +# +# Copyright:: 2020, Sous-chefs +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +# Install golang by compiling from source +property :from_source, [true, false], default: false + +# Base directory for go +property :install_dir, String, default: '/usr/local' +property :gopath, String, default: '/opt/go' +property :gobin, String, default: '/opt/go/bin' + +# Directory and file attributes +property :owner, String, default: 'root' +property :group, String, default: 'root' +property :directory_mode, String, default: '0755' + +# version to install +# ark input binaries and stuff download +# e.g. https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz +# https://dl.google.com/go/go1.14.4/linux-amd64.tar.gz +# https://golang.org/dl/go1.14.6.darwin-amd64.tar.gz +# https://golang.org/dl/go1.14.6.linux-amd64.tar.gz +property :url, String, default: 'https://golang.org/dl/goVERSION.OS-PLATFORM.tar.gz' +property :version, String, default: '1.14.4' + +# ark input source +# e.g. https://dl.google.com/go/go1.14.4.src.tar.gz +property :source_url, String, default: 'https://golang.org/dl/goVERSION.src.tar.gz' +property :source_version, String, default: '1.14.4' + +# installation script from the source repository +property :source_method, String, default: 'all.bash' + +# install SCM packages +property :scm, [true, false], default: true +property :scm_packages, [String, Array], default: %w(git mercurial) + +action_class do + def bin_url + return new_resource.url if property_is_set?(:url) + new_resource.url.sub(/PLATFORM/, platform).sub(/OS/, os).sub(/VERSION/, new_resource.version) + end + + def source_url + return new_resource.source_url if property_is_set?(:source_url) + new_resource.source_url.sub(/VERSION/, new_resource.source_version) + end + + def os + node['os'] + end + + def platform + node['kernel']['machine'] =~ /i.86/ ? '386' : 'amd64' + end +end + +action :install do + directory new_resource.gopath do + recursive true + owner new_resource.owner + group new_resource.group + mode new_resource.directory_mode + end + + directory new_resource.gobin do + recursive true + owner new_resource.owner + group new_resource.group + mode new_resource.directory_mode + end + + directory new_resource.install_dir do + recursive true + mode new_resource.directory_mode + end + + directory ::File.join(Chef::Config[:file_cache_path], 'go') do + recursive true + end + + template '/etc/profile.d/golang.sh' do + source 'golang.sh.erb' + mode new_resource.directory_mode + variables gobin: new_resource.gobin, + gopath: new_resource.gobin, + install_dir: new_resource.install_dir + end + + if new_resource.scm + apt_update do + only_if { platform_family? 'debian' } + end + package new_resource.scm_packages + end + + # pgk to install go binaries, doc, base packages + # ark is not idempotent by itself. Check to see if the go binary is the correct version + url = bin_url + ark 'go' do + url url + version new_resource.version + not_if "/usr/local/go-#{new_resource.version}/bin/go version | grep #{new_resource.version}" + end + + ##### SOURCE BUILD + + if new_resource.from_source + + directory ::File.join(new_resource.install_dir, 'go', 'bin') do + recursive true + mode new_resource.directory_mode + end + + build_essential + + file "#{new_resource.install_dir}/go" do + manage_symlink_source true + action :delete + only_if do + # Create idempotency by not deleting symlink if it points to source build + ::File.exist?("#{new_resource.install_dir}/go") && + ::File.ftype("#{new_resource.install_dir}/go") == 'link' && + ::File.readlink("#{new_resource.install_dir}/go") != "#{new_resource.install_dir}/go-source" + end + end + + url = source_url + ark 'go' do # resource with the same name, that's an issue. Source install + url url + version 'source' + action :put + release_file '/tmp/ark_release_file' + not_if "test -x #{::File.join(new_resource.install_dir, 'go', 'bin', 'go')} && #{::File.join(new_resource.install_dir, 'go', 'bin', 'go')} version | grep #{new_resource.source_version}" + end + + # see if build already done + # converge_by if not done + execute 'build-golang' do + cwd "#{new_resource.install_dir}/go/src" + command "./#{new_resource.source_method}" + environment({ + # Use the package-installed Go as the bootstrap version b/c Go is built with Go + GOROOT_BOOTSTRAP: "#{new_resource.install_dir}/go-#{new_resource.version}", + GOROOT: "#{new_resource.install_dir}/go", + GOBIN: "#{new_resource.install_dir}/go/bin", + }) + not_if "test -x #{::File.join(new_resource.install_dir, 'go', 'bin', 'go')} && #{::File.join(new_resource.install_dir, 'go', 'bin', 'go')} version | grep #{new_resource.source_version}" + end + end +end diff --git a/cookbooks/golang/resources/package.rb b/cookbooks/golang/resources/package.rb new file mode 100644 index 0000000..4090444 --- /dev/null +++ b/cookbooks/golang/resources/package.rb @@ -0,0 +1,52 @@ +# +# Cookbook:: golang +# Resource:: default +# + +default_action :install + +gocache = '/tmp/go' + +action :install do + execute "go get #{new_resource.name}" do + user node['golang']['owner'] + group node['golang']['group'] + environment({ + PATH: "#{node['golang']['install_dir']}/go/bin:#{node['golang']['gobin']}:" \ + '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + GOPATH: node['golang']['gopath'], + GOBIN: node['golang']['gobin'], + GOCACHE: gocache, + }) + end +end + +action :update do + execute "go get -u #{new_resource.name}" do + user node['golang']['owner'] + group node['golang']['group'] + environment({ + PATH: "#{node['golang']['install_dir']}/go/bin:#{node['golang']['gobin']}:" \ + '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + GOPATH: node['golang']['gopath'], + GOBIN: node['golang']['gobin'], + GOCACHE: gocache, + }) + end +end + +action :build do + execute "go build -work -x #{new_resource.name}" do + user node['golang']['owner'] + group node['golang']['group'] + cwd gocache + environment({ + PATH: "#{node['golang']['install_dir']}/go/bin:#{node['golang']['gobin']}:" \ + '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + HOME: "/home/#{node['golang']['owner']}", + GOPATH: node['golang']['gopath'], + GOBIN: node['golang']['gobin'], + GOCACHE: gocache, + }) + end +end diff --git a/cookbooks/golang/templates/golang.sh.erb b/cookbooks/golang/templates/golang.sh.erb new file mode 100644 index 0000000..41db116 --- /dev/null +++ b/cookbooks/golang/templates/golang.sh.erb @@ -0,0 +1,3 @@ +export PATH="<%= ::File.join(@install_dir, 'go', 'bin') %>:<%= @gobin %>:$PATH" +export GOPATH=<%= @gopath %> +export GOBIN=<%= @gobin %> diff --git a/site-cookbooks/kosmos-bitcoin/metadata.rb b/site-cookbooks/kosmos-bitcoin/metadata.rb index 37f95f4..59b2b93 100644 --- a/site-cookbooks/kosmos-bitcoin/metadata.rb +++ b/site-cookbooks/kosmos-bitcoin/metadata.rb @@ -20,4 +20,4 @@ chef_version '>= 14.0' # source_url 'https://github.com//kosmos-bitcoin' depends "ark" -depends "kosmos_encfs" +depends "golang" From d5448e824026b4b26ab59c9878667fb4f2587c56 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 23 Aug 2020 12:37:53 +0200 Subject: [PATCH 111/327] Basic LND installation --- nodes/bitcoin-2.json | 9 +++- .../kosmos-bitcoin/attributes/default.rb | 4 ++ site-cookbooks/kosmos-bitcoin/metadata.rb | 5 +- site-cookbooks/kosmos-bitcoin/recipes/lnd.rb | 50 +++++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 site-cookbooks/kosmos-bitcoin/recipes/lnd.rb diff --git a/nodes/bitcoin-2.json b/nodes/bitcoin-2.json index 0d9d007..c888e0c 100644 --- a/nodes/bitcoin-2.json +++ b/nodes/bitcoin-2.json @@ -18,6 +18,7 @@ "kosmos-base", "kosmos-base::default", "kosmos-bitcoin::source", + "kosmos-bitcoin::lnd", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -32,7 +33,10 @@ "postfix::_attributes", "postfix::sasl_auth", "hostname::default", - "ark::default" + "ark::default", + "git::default", + "git::package", + "golang::default" ], "platform": "ubuntu", "platform_version": "20.04", @@ -50,6 +54,7 @@ }, "run_list": [ "recipe[kosmos-base]", - "recipe[kosmos-bitcoin::source]" + "recipe[kosmos-bitcoin::source]", + "recipe[kosmos-bitcoin::lnd]" ] } \ No newline at end of file diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 70dca3c..306c2c7 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -24,3 +24,7 @@ node.default['bitcoin']['conf'] = { zmqpubrawblock: 'tcp://127.0.0.1:8337', zmqpubrawtx: 'tcp://127.0.0.1:8338' } + +node.default['lnd']['repo'] = 'https://github.com/lightningnetwork/lnd' +node.default['lnd']['revision'] = 'v0.11.0-beta' +node.default['lnd']['source_dir'] = '/opt/lnd' diff --git a/site-cookbooks/kosmos-bitcoin/metadata.rb b/site-cookbooks/kosmos-bitcoin/metadata.rb index 59b2b93..a462885 100644 --- a/site-cookbooks/kosmos-bitcoin/metadata.rb +++ b/site-cookbooks/kosmos-bitcoin/metadata.rb @@ -19,5 +19,6 @@ chef_version '>= 14.0' # # source_url 'https://github.com//kosmos-bitcoin' -depends "ark" -depends "golang" +depends 'ark' +depends 'git' +depends 'golang' diff --git a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb new file mode 100644 index 0000000..4708447 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb @@ -0,0 +1,50 @@ +# +# Cookbook:: kosmos-bitcoin +# Recipe:: lnd +# +# 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 "git" +include_recipe "golang" + +# bitcoin_user = node['bitcoin']['username'] +# bitcoin_group = node['bitcoin']['usergroup'] +# bitcoin_datadir = node['bitcoin']['datadir'] +# bitcoin_conf_path = node['bitcoin']['conf_path'] + +git node['lnd']['source_dir'] do + repository node['lnd']['repo'] + revision node['lnd']['revision'] + action :sync + notifies :run, 'bash[compile_lnd]', :immediately +end + +bash "compile_lnd" do + cwd node['lnd']['source_dir'] + code <<-EOH + source /etc/profile.d/golang.sh + make clean && make && make install + EOH + action :nothing +end From d6ad68c50a8197b1fdd6f20f0b241b8453ec6415 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 30 Aug 2020 17:23:17 +0200 Subject: [PATCH 112/327] Add node config for new wiki VM --- clients/wiki-1.json | 4 +++ nodes/wiki-1.json | 76 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 clients/wiki-1.json create mode 100644 nodes/wiki-1.json diff --git a/clients/wiki-1.json b/clients/wiki-1.json new file mode 100644 index 0000000..f50d2b0 --- /dev/null +++ b/clients/wiki-1.json @@ -0,0 +1,4 @@ +{ + "name": "wiki-1", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3LprIvOWrnsywbvFGXtK\nsbd6xmILw/W/dSogLi0DQBXxPsOipH8pL4K6IeZmMeU3TXaW7faf/54KrMnh+4s1\nLEXpWSATvCaw1LzihzoXELpVLNvBLHZjAAO2TJ5ay1knTlA92hqN8qZOKzRtfHBX\n49dIgJgY95UIIJqSk4425llgQY/tntEWPjSduPIyST/PKkuW+RbUj4XyKm/qrASV\nXrbDK0dZAD0kJrOEjKspUyBQjyutFy+hkv0ldiGogcpCNPDaDsJqnw+Gp0gv6w7V\n92omCx8oJuXoqL1SIB6ayHV3q1pEWC9VbDRdcSYBjbRPFITEj6Er0m6OhJjlOyyR\nfwIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/wiki-1.json b/nodes/wiki-1.json new file mode 100644 index 0000000..a6f9be0 --- /dev/null +++ b/nodes/wiki-1.json @@ -0,0 +1,76 @@ +{ + "name": "wiki-1", + "normal": { + "knife_zero": { + "host": "10.147.20.206" + } + }, + "automatic": { + "fqdn": "wiki-1", + "os": "linux", + "os_version": "5.4.0-42-generic", + "hostname": "wiki-1", + "ipaddress": "192.168.122.26", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "kosmos-mediawiki", + "kosmos-mediawiki::default", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default", + "ark::default", + "composer::default", + "composer::install", + "php::default", + "php::package", + "php::ini", + "composer::global_configs", + "mediawiki::default", + "mediawiki::database", + "kosmos-nginx::default", + "nginx::default", + "nginx::package", + "nginx::ohai_plugin", + "nginx::repo", + "nginx::commons", + "nginx::commons_dir", + "nginx::commons_script", + "nginx::commons_conf", + "mediawiki::nginx", + "backup::default", + "logrotate::default" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "chef": { + "version": "15.13.8", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.13.8/lib" + }, + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + } + } + }, + "run_list": [ + "recipe[kosmos-base]", + "recipe[kosmos-mediawiki]" + ] +} \ No newline at end of file From c9440800df4e27dc709cf2b82bac885263472b71 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 30 Aug 2020 17:48:52 +0200 Subject: [PATCH 113/327] Update vendored cookbooks for mediawiki --- cookbooks/composer/LICENSE | 21 ++++++ cookbooks/mysql/metadata.rb | 20 ++++++ .../apparmor/ubuntu-14.04/usr.sbin.mysqld.erb | 47 +++++++++++++ .../apparmor/ubuntu-16.04/usr.sbin.mysqld.erb | 68 +++++++++++++++++++ .../apparmor/ubuntu-18.04/usr.sbin.mysqld.erb | 68 +++++++++++++++++++ cookbooks/php/metadata.rb | 19 ++++++ 6 files changed, 243 insertions(+) create mode 100644 cookbooks/composer/LICENSE create mode 100644 cookbooks/mysql/metadata.rb create mode 100644 cookbooks/mysql/templates/default/apparmor/ubuntu-14.04/usr.sbin.mysqld.erb create mode 100644 cookbooks/mysql/templates/default/apparmor/ubuntu-16.04/usr.sbin.mysqld.erb create mode 100644 cookbooks/mysql/templates/default/apparmor/ubuntu-18.04/usr.sbin.mysqld.erb create mode 100644 cookbooks/php/metadata.rb diff --git a/cookbooks/composer/LICENSE b/cookbooks/composer/LICENSE new file mode 100644 index 0000000..fb1d16c --- /dev/null +++ b/cookbooks/composer/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2012-2017 David Joos + +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. diff --git a/cookbooks/mysql/metadata.rb b/cookbooks/mysql/metadata.rb new file mode 100644 index 0000000..78a50fc --- /dev/null +++ b/cookbooks/mysql/metadata.rb @@ -0,0 +1,20 @@ +name 'mysql' +maintainer 'Sous Chefs' +maintainer_email 'help@sous-chefs.org' +license 'Apache-2.0' +description 'Provides mysql_service, mysql_config, and mysql_client resources' +source_url 'https://github.com/sous-chefs/mysql' +issues_url 'https://github.com/sous-chefs/mysql/issues' +chef_version '>= 12.7' +version '8.7.3' + +%w(redhat centos scientific oracle).each do |el| + supports el, '>= 6.0' +end + +supports 'amazon' +supports 'fedora' +supports 'debian', '>= 7.0' +supports 'ubuntu', '>= 14.04' +supports 'opensuseleap' +supports 'suse', '>= 12.0' diff --git a/cookbooks/mysql/templates/default/apparmor/ubuntu-14.04/usr.sbin.mysqld.erb b/cookbooks/mysql/templates/default/apparmor/ubuntu-14.04/usr.sbin.mysqld.erb new file mode 100644 index 0000000..19ddbf5 --- /dev/null +++ b/cookbooks/mysql/templates/default/apparmor/ubuntu-14.04/usr.sbin.mysqld.erb @@ -0,0 +1,47 @@ +# vim:syntax=apparmor +# Last Modified: Tue Jun 19 17:37:30 2007 +#include + +/usr/sbin/mysqld { + #include + #include + #include + #include + #include + + capability dac_override, + capability sys_resource, + capability setgid, + capability setuid, + + network tcp, + + /etc/hosts.allow r, + /etc/hosts.deny r, + + /etc/mysql/*.pem r, + /etc/mysql/conf.d/ r, + /etc/mysql/conf.d/* r, + /etc/mysql/*.cnf r, + /usr/lib/mysql/plugin/ r, + /usr/lib/mysql/plugin/*.so* mr, + /usr/sbin/mysqld mr, + /usr/share/mysql/** r, + /var/log/mysql.log rw, + /var/log/mysql.err rw, + /var/lib/mysql/ r, + /var/lib/mysql/** rwk, + /var/log/mysql/ r, + /var/log/mysql/* rw, + /var/run/mysqld/mysqld.pid rw, + /var/run/mysqld/mysqld.sock w, + /var/run/mysqld/mysqld.sock.lock rw, + /run/mysqld/mysqld.pid rw, + /run/mysqld/mysqld.sock w, + /run/mysqld/mysqld.sock.lock rw, + + /sys/devices/system/cpu/ r, + + # Site-specific additions and overrides. See local/README for details. + #include +} diff --git a/cookbooks/mysql/templates/default/apparmor/ubuntu-16.04/usr.sbin.mysqld.erb b/cookbooks/mysql/templates/default/apparmor/ubuntu-16.04/usr.sbin.mysqld.erb new file mode 100644 index 0000000..2619e7d --- /dev/null +++ b/cookbooks/mysql/templates/default/apparmor/ubuntu-16.04/usr.sbin.mysqld.erb @@ -0,0 +1,68 @@ +# vim:syntax=apparmor +# Last Modified: Tue Feb 09 15:28:30 2016 +#include + +/usr/sbin/mysqld { + #include + #include + #include + #include + #include + +# Allow system resource access + /sys/devices/system/cpu/ r, + capability sys_resource, + capability dac_override, + capability setuid, + capability setgid, + +# Allow network access + network tcp, + + /etc/hosts.allow r, + /etc/hosts.deny r, + +# Allow config access + /etc/mysql/** r, + +# Allow pid, socket, socket lock file access + /var/run/mysqld/mysqld.pid rw, + /var/run/mysqld/mysqld.sock rw, + /var/run/mysqld/mysqld.sock.lock rw, + /run/mysqld/mysqld.pid rw, + /run/mysqld/mysqld.sock rw, + /run/mysqld/mysqld.sock.lock rw, + +# Allow execution of server binary + /usr/sbin/mysqld mr, + /usr/sbin/mysqld-debug mr, + +# Allow plugin access + /usr/lib/mysql/plugin/ r, + /usr/lib/mysql/plugin/*.so* mr, + +# Allow error msg and charset access + /usr/share/mysql/ r, + /usr/share/mysql/** r, + +# Allow data dir access + /var/lib/mysql/ r, + /var/lib/mysql/** rwk, + +# Allow data files dir access + /var/lib/mysql-files/ r, + /var/lib/mysql-files/** rwk, + +# Allow keyring dir access + /var/lib/mysql-keyring/ r, + /var/lib/mysql-keyring/** rwk, + +# Allow log file access + /var/log/mysql.err rw, + /var/log/mysql.log rw, + /var/log/mysql/ r, + /var/log/mysql/** rw, + + # Site-specific additions and overrides. See local/README for details. + #include +} diff --git a/cookbooks/mysql/templates/default/apparmor/ubuntu-18.04/usr.sbin.mysqld.erb b/cookbooks/mysql/templates/default/apparmor/ubuntu-18.04/usr.sbin.mysqld.erb new file mode 100644 index 0000000..2619e7d --- /dev/null +++ b/cookbooks/mysql/templates/default/apparmor/ubuntu-18.04/usr.sbin.mysqld.erb @@ -0,0 +1,68 @@ +# vim:syntax=apparmor +# Last Modified: Tue Feb 09 15:28:30 2016 +#include + +/usr/sbin/mysqld { + #include + #include + #include + #include + #include + +# Allow system resource access + /sys/devices/system/cpu/ r, + capability sys_resource, + capability dac_override, + capability setuid, + capability setgid, + +# Allow network access + network tcp, + + /etc/hosts.allow r, + /etc/hosts.deny r, + +# Allow config access + /etc/mysql/** r, + +# Allow pid, socket, socket lock file access + /var/run/mysqld/mysqld.pid rw, + /var/run/mysqld/mysqld.sock rw, + /var/run/mysqld/mysqld.sock.lock rw, + /run/mysqld/mysqld.pid rw, + /run/mysqld/mysqld.sock rw, + /run/mysqld/mysqld.sock.lock rw, + +# Allow execution of server binary + /usr/sbin/mysqld mr, + /usr/sbin/mysqld-debug mr, + +# Allow plugin access + /usr/lib/mysql/plugin/ r, + /usr/lib/mysql/plugin/*.so* mr, + +# Allow error msg and charset access + /usr/share/mysql/ r, + /usr/share/mysql/** r, + +# Allow data dir access + /var/lib/mysql/ r, + /var/lib/mysql/** rwk, + +# Allow data files dir access + /var/lib/mysql-files/ r, + /var/lib/mysql-files/** rwk, + +# Allow keyring dir access + /var/lib/mysql-keyring/ r, + /var/lib/mysql-keyring/** rwk, + +# Allow log file access + /var/log/mysql.err rw, + /var/log/mysql.log rw, + /var/log/mysql/ r, + /var/log/mysql/** rw, + + # Site-specific additions and overrides. See local/README for details. + #include +} diff --git a/cookbooks/php/metadata.rb b/cookbooks/php/metadata.rb new file mode 100644 index 0000000..112a8c9 --- /dev/null +++ b/cookbooks/php/metadata.rb @@ -0,0 +1,19 @@ +name 'php' +maintainer 'Sous Chefs' +maintainer_email 'help@sous-chefs.org' +license 'Apache-2.0' +description 'Installs and maintains php and php modules' +source_url 'https://github.com/sous-chefs/php' +issues_url 'https://github.com/sous-chefs/php/issues' +chef_version '>= 14.0' +version '8.0.0' + +depends 'yum-epel' + +supports 'amazon', '>= 2.0' +supports 'centos', '>= 7.0' +supports 'debian', '>= 9.0' +supports 'oracle', '>= 7.0' +supports 'redhat', '>= 7.0' +supports 'scientific', '>= 7.0' +supports 'ubuntu', '>= 16.04' From 38c6a1ae152ed891315efcb3dcef28a13c014e03 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 30 Aug 2020 17:59:45 +0200 Subject: [PATCH 114/327] Update mediawiki, install extensions from git repos --- .../kosmos-mediawiki/recipes/default.rb | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/site-cookbooks/kosmos-mediawiki/recipes/default.rb b/site-cookbooks/kosmos-mediawiki/recipes/default.rb index a16bdfe..b459914 100644 --- a/site-cookbooks/kosmos-mediawiki/recipes/default.rb +++ b/site-cookbooks/kosmos-mediawiki/recipes/default.rb @@ -30,10 +30,10 @@ include_recipe 'composer' server_name = 'wiki.kosmos.org' -node.override['mediawiki']['version'] = "1.32.0" +node.override['mediawiki']['version'] = "1.34.2" node.override['mediawiki']['webdir'] = "#{node['mediawiki']['docroot_dir']}/mediawiki-#{node['mediawiki']['version']}" node.override['mediawiki']['tarball']['name'] = "mediawiki-#{node['mediawiki']['version']}.tar.gz" -node.override['mediawiki']['tarball']['url'] = "https://releases.wikimedia.org/mediawiki/1.32/#{node['mediawiki']['tarball']['name']}" +node.override['mediawiki']['tarball']['url'] = "https://releases.wikimedia.org/mediawiki/1.34/#{node['mediawiki']['tarball']['name']}" node.override['mediawiki']['language_code'] = 'en' node.override['mediawiki']['server_name'] = server_name node.override['mediawiki']['site_name'] = 'Kosmos Wiki' @@ -98,7 +98,8 @@ nginx_site server_name do action :enable end -nginx_certbot_site server_name +# TODO +# nginx_certbot_site server_name # # Extensions @@ -136,31 +137,28 @@ end if node["mediawiki"]["ldap_enabled"] # LDAP - ark "PluggableAuth" do - url "https://github.com/wikimedia/mediawiki-extensions-PluggableAuth/archive/REL1_32.zip" - path "#{node['mediawiki']['webdir']}/extensions" - owner node["nginx"]["user"] + git "#{node['mediawiki']['webdir']}/extensions/PluggableAuth" do + repository "https://github.com/wikimedia/mediawiki-extensions-PluggableAuth.git" + revision "5.7" + user node["nginx"]["user"] group node["nginx"]["group"] - mode 0750 - action :dump + action :sync end - ark "LDAPProvider" do - url "https://github.com/wikimedia/mediawiki-extensions-LDAPProvider/archive/REL1_31.zip" - path "#{node['mediawiki']['webdir']}/extensions" - owner node["nginx"]["user"] + git "#{node['mediawiki']['webdir']}/extensions/LDAPProvider" do + repository "https://github.com/wikimedia/mediawiki-extensions-LDAPProvider.git" + revision "1.0.3" + user node["nginx"]["user"] group node["nginx"]["group"] - mode 0750 - action :dump + action :sync end - ark "LDAPAuthentication2" do - url "https://github.com/wikimedia/mediawiki-extensions-LDAPAuthentication2/archive/REL1_31.zip" - path "#{node['mediawiki']['webdir']}/extensions" - owner node["nginx"]["user"] + git "#{node['mediawiki']['webdir']}/extensions/LDAPAuthentication2" do + repository "https://github.com/wikimedia/mediawiki-extensions-LDAPAuthentication2.git" + revision "1.0.1" + user node["nginx"]["user"] group node["nginx"]["group"] - mode 0750 - action :dump + action :sync end package "php-ldap" From c646c3d5b4772c061fda8b8d8abfac9c1974c033 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 30 Aug 2020 18:03:44 +0200 Subject: [PATCH 115/327] Update mediawiki cookbook (Kosmos fork) --- Berksfile | 13 ++++++------- Berksfile.lock | 7 ++----- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Berksfile b/Berksfile index 7ffb698..1db64f4 100644 --- a/Berksfile +++ b/Berksfile @@ -3,13 +3,12 @@ source 'https://supermarket.chef.io' cookbook 'mediawiki', - git: 'https://github.com/67P/mediawiki-cookbook.git', - ref: '55a4680ee298199fa5f7fa51b5c589fbfa52eed0' + git: 'https://github.com/67P/mediawiki-cookbook.git', + ref: 'nginx' cookbook 'redis', - git: 'https://github.com/phlipper/chef-redis.git', - ref: 'v0.5.6' + git: 'https://github.com/phlipper/chef-redis.git', + ref: 'v0.5.6' cookbook 'postfix', '= 5.0.2' -cookbook 'php-fpm', '~> 0.8.0' cookbook 'php', '~> 6.1.1' cookbook 'composer', '~> 2.6.1' cookbook 'poise-ruby-build', '~> 1.1.0' @@ -47,8 +46,8 @@ cookbook 'compat_resource', '= 12.19.0' cookbook 'homebrew', '= 3.0.0' cookbook 'mariadb', '= 0.3.1' cookbook 'ipfs', - git: 'https://gitea.kosmos.org/kosmos/ipfs-cookbook.git', - ref: 'v0.4.1' + git: 'https://gitea.kosmos.org/kosmos/ipfs-cookbook.git', + ref: 'v0.4.1' cookbook 'elasticsearch', '= 4.2.0' cookbook 'java', '~> 4.3.0' cookbook 'ulimit', '~> 1.0.0' diff --git a/Berksfile.lock b/Berksfile.lock index 1e3996b..cfefcac 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -25,8 +25,8 @@ DEPENDENCIES mariadb (= 0.3.1) mediawiki git: https://github.com/67P/mediawiki-cookbook.git - revision: 55a4680ee298199fa5f7fa51b5c589fbfa52eed0 - ref: 55a4680 + revision: 78641e53635ba6cbd4a2a51fd597adb8fef1e8ad + ref: nginx mysql (~> 8.5.1) nginx (= 9.0.0) nodejs (~> 5.0.0) @@ -34,7 +34,6 @@ DEPENDENCIES ohai (~> 5.2.5) openssl (~> 8.5.5) php (~> 6.1.1) - php-fpm (~> 0.8.0) poise (~> 2.8.2) poise-archive (~> 1.5.0) poise-javascript @@ -107,7 +106,6 @@ GRAPH apache2 (>= 0.0.0) nginx (>= 0.0.0) php (>= 0.0.0) - php-fpm (>= 0.0.0) mingw (2.1.0) seven_zip (>= 0.0.0) mysql (8.5.1) @@ -124,7 +122,6 @@ GRAPH php (6.1.1) build-essential (>= 5.0) yum-epel (>= 0.0.0) - php-fpm (0.8.0) poise (2.8.2) poise-archive (1.5.0) poise (~> 2.6) From 7af26d6ad313cb4f469ff4be17a3f8fc565e9829 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 5 Sep 2020 20:59:07 +0200 Subject: [PATCH 116/327] Remove wiki role from andromeda --- nodes/andromeda.kosmos.org.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nodes/andromeda.kosmos.org.json b/nodes/andromeda.kosmos.org.json index dea7894..338bb9c 100644 --- a/nodes/andromeda.kosmos.org.json +++ b/nodes/andromeda.kosmos.org.json @@ -131,10 +131,9 @@ "recipe[kosmos-ipfs]", "recipe[kosmos-ipfs::public_gateway]", "role[postgresql_primary]", - "recipe[kosmos-mediawiki]", "recipe[kosmos-btcpayserver::proxy]", "role[mastodon]", "role[ejabberd]", "recipe[kosmos_gitea::pg_db]" ] -} \ No newline at end of file +} From b7e2a723691bc92c701bc5c55a19d1ab874d7647 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 5 Sep 2020 23:43:28 +0200 Subject: [PATCH 117/327] Add missing changes for mediawiki upgrades --- Berksfile | 10 +- Berksfile.lock | 17 +- cookbooks/composer/README.md | 2 +- cookbooks/composer/attributes/default.rb | 3 +- cookbooks/composer/metadata.json | 23 +- cookbooks/composer/metadata.rb | 5 +- .../composer/providers/install_global.rb | 3 - cookbooks/composer/providers/project.rb | 3 - cookbooks/composer/recipes/install.rb | 4 +- cookbooks/composer/recipes/self_update.rb | 8 +- .../composer/resources/install_global.rb | 5 - cookbooks/composer/resources/project.rb | 5 - cookbooks/mediawiki/metadata.json | 3 +- cookbooks/mediawiki/metadata.rb | 1 - cookbooks/mediawiki/recipes/nginx.rb | 21 +- cookbooks/mysql/.foodcritic | 1 - cookbooks/mysql/CHANGELOG.md | 318 +++-- cookbooks/mysql/CONTRIBUTING.md | 4 +- cookbooks/mysql/README.md | 83 +- cookbooks/mysql/libraries/helpers.rb | 73 +- cookbooks/mysql/libraries/matchers.rb | 71 -- cookbooks/mysql/libraries/mysql_base.rb | 3 - .../mysql_client_installation_package.rb | 5 +- cookbooks/mysql/libraries/mysql_config.rb | 3 +- .../mysql_server_installation_package.rb | 5 +- cookbooks/mysql/libraries/mysql_service.rb | 5 +- .../mysql/libraries/mysql_service_base.rb | 41 +- .../mysql_service_manager_systemd.rb | 5 +- .../mysql_service_manager_sysvinit.rb | 1 + .../mysql_service_manager_upstart.rb | 1 + cookbooks/mysql/metadata.json | 2 +- .../apparmor/usr.sbin.mysqld-instance.erb | 1 + .../default/apparmor/usr.sbin.mysqld.erb | 47 - .../default/systemd/mysqld.service.erb | 9 +- cookbooks/php-fpm/.foodcritic | 1 - cookbooks/php-fpm/README.md | 142 --- cookbooks/php-fpm/attributes/default.rb | 71 -- cookbooks/php-fpm/definitions/php_fpm_pool.rb | 65 - cookbooks/php-fpm/metadata.json | 1 - cookbooks/php-fpm/recipes/configure.rb | 43 - cookbooks/php-fpm/recipes/default.rb | 22 - cookbooks/php-fpm/recipes/install.rb | 59 - cookbooks/php-fpm/recipes/repository.rb | 54 - cookbooks/php-fpm/recipes/test.rb | 3 - cookbooks/php-fpm/templates/php-fpm.conf.erb | 60 - cookbooks/php-fpm/templates/pool.conf.erb | 424 ------- cookbooks/php/CHANGELOG.md | 38 +- cookbooks/php/CONTRIBUTING.md | 4 +- cookbooks/php/README.md | 228 +--- cookbooks/php/attributes/default.rb | 156 ++- cookbooks/php/metadata.json | 2 +- cookbooks/php/recipes/ini.rb | 20 + cookbooks/php/recipes/package.rb | 12 +- cookbooks/php/recipes/recompile.rb | 32 +- cookbooks/php/recipes/source.rb | 68 +- cookbooks/php/resources/pear.rb | 28 +- cookbooks/php/resources/pear_channel.rb | 3 - .../php/templates/default/extension.ini.erb | 3 + cookbooks/php/templates/default/php.ini.erb | 1077 +++++++++-------- nodes/wiki-1.json | 16 +- .../kosmos-mediawiki/recipes/default.rb | 8 +- 61 files changed, 1179 insertions(+), 2252 deletions(-) delete mode 100644 cookbooks/mysql/.foodcritic delete mode 100644 cookbooks/mysql/libraries/matchers.rb delete mode 100644 cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld.erb delete mode 100644 cookbooks/php-fpm/.foodcritic delete mode 100644 cookbooks/php-fpm/README.md delete mode 100644 cookbooks/php-fpm/attributes/default.rb delete mode 100644 cookbooks/php-fpm/definitions/php_fpm_pool.rb delete mode 100644 cookbooks/php-fpm/metadata.json delete mode 100644 cookbooks/php-fpm/recipes/configure.rb delete mode 100644 cookbooks/php-fpm/recipes/default.rb delete mode 100644 cookbooks/php-fpm/recipes/install.rb delete mode 100644 cookbooks/php-fpm/recipes/repository.rb delete mode 100644 cookbooks/php-fpm/recipes/test.rb delete mode 100644 cookbooks/php-fpm/templates/php-fpm.conf.erb delete mode 100644 cookbooks/php-fpm/templates/pool.conf.erb diff --git a/Berksfile b/Berksfile index 1db64f4..5420a3a 100644 --- a/Berksfile +++ b/Berksfile @@ -9,8 +9,8 @@ cookbook 'redis', git: 'https://github.com/phlipper/chef-redis.git', ref: 'v0.5.6' cookbook 'postfix', '= 5.0.2' -cookbook 'php', '~> 6.1.1' -cookbook 'composer', '~> 2.6.1' +cookbook 'php', '~> 8.0.0' +cookbook 'composer', '~> 2.7.0' cookbook 'poise-ruby-build', '~> 1.1.0' cookbook 'application', '~> 5.2.0' cookbook 'application_javascript', '~> 1.0.0' @@ -28,15 +28,15 @@ cookbook 'nginx', '= 9.0.0' # Remove when cookbooks stop depending on it, the build_essential resource is # part of Chef 14 (https://docs.chef.io/resource_build_essential.html) cookbook 'build-essential', '~> 8.2.1' -cookbook 'mysql', '~> 8.5.1' +cookbook 'mysql', '~> 8.7.3' # cookbook 'postgresql', '= 7.1.8' cookbook 'apt', '~> 7.3.0' -cookbook 'git', '>= 6.0.0' +cookbook 'git', '~> 10.0.0' cookbook 'hostsfile', '= 2.4.5' cookbook 'ohai', '~> 5.2.5' cookbook 'nodejs', '~> 5.0.0' cookbook 'timezone_iii', '= 1.0.4' -cookbook 'ark', '>= 3.1.0' +cookbook 'ark', '>= 5.0.0' cookbook 'logrotate', '= 2.2.0' cookbook 'openssl', '~> 8.5.5' cookbook 'ntp', '= 3.4.0' diff --git a/Berksfile.lock b/Berksfile.lock index cfefcac..590945a 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -4,14 +4,14 @@ DEPENDENCIES application_git (= 1.1.0) application_javascript (~> 1.0.0) apt (~> 7.3.0) - ark (>= 3.1.0) + ark (>= 5.0.0) build-essential (~> 8.2.1) chef-sugar (= 3.3.0) compat_resource (= 12.19.0) - composer (~> 2.6.1) + composer (~> 2.7.0) elasticsearch (= 4.2.0) firewall (~> 2.6.3) - git (>= 6.0.0) + git (~> 10.0.0) golang (~> 4.1.0) homebrew (= 3.0.0) hostname (= 0.4.2) @@ -27,13 +27,13 @@ DEPENDENCIES git: https://github.com/67P/mediawiki-cookbook.git revision: 78641e53635ba6cbd4a2a51fd597adb8fef1e8ad ref: nginx - mysql (~> 8.5.1) + mysql (~> 8.7.3) nginx (= 9.0.0) nodejs (~> 5.0.0) ntp (= 3.4.0) ohai (~> 5.2.5) openssl (~> 8.5.5) - php (~> 6.1.1) + php (~> 8.0.0) poise (~> 2.8.2) poise-archive (~> 1.5.0) poise-javascript @@ -74,7 +74,7 @@ GRAPH seven_zip (>= 0.0.0) chef-sugar (3.3.0) compat_resource (12.19.0) - composer (2.6.1) + composer (2.7.0) apt (>= 0.0.0) php (>= 0.0.0) windows (>= 0.0.0) @@ -108,7 +108,7 @@ GRAPH php (>= 0.0.0) mingw (2.1.0) seven_zip (>= 0.0.0) - mysql (8.5.1) + mysql (8.7.3) nginx (9.0.0) build-essential (>= 5.0) ohai (>= 4.1.0) @@ -119,8 +119,7 @@ GRAPH ntp (3.4.0) ohai (5.2.5) openssl (8.5.5) - php (6.1.1) - build-essential (>= 5.0) + php (8.0.0) yum-epel (>= 0.0.0) poise (2.8.2) poise-archive (1.5.0) diff --git a/cookbooks/composer/README.md b/cookbooks/composer/README.md index d41686e..97c9268 100644 --- a/cookbooks/composer/README.md +++ b/cookbooks/composer/README.md @@ -159,7 +159,7 @@ end ## License and Authors Author: David Joos -Copyright: 2016, David Joos +Copyright: 2016-2017, David Joos Author: David Joos Author: Escape Studios Development diff --git a/cookbooks/composer/attributes/default.rb b/cookbooks/composer/attributes/default.rb index bb99dca..9465e01 100644 --- a/cookbooks/composer/attributes/default.rb +++ b/cookbooks/composer/attributes/default.rb @@ -14,7 +14,7 @@ if node['platform'] == 'windows' default['composer']['global_install']['install_dir'] = 'C:\\Program\ Files\\Composer' default['composer']['global_install']['bin_dir'] = 'C:\\ProgramData\\Composer' else - default['composer']['url'] = 'http://getcomposer.org/composer.phar' + default['composer']['url'] = 'http://getcomposer.org/composer-stable.phar' default['composer']['install_dir'] = '/usr/local/bin' default['composer']['bin'] = "#{node['composer']['install_dir']}/composer" default['composer']['install_globally'] = true @@ -27,3 +27,4 @@ end default['composer']['global_configs'] = {} default['composer']['home_dir'] = nil default['composer']['php_recipe'] = 'php::default' +default['composer']['self_update_channel'] = nil diff --git a/cookbooks/composer/metadata.json b/cookbooks/composer/metadata.json index d86a891..c552bd0 100644 --- a/cookbooks/composer/metadata.json +++ b/cookbooks/composer/metadata.json @@ -1,7 +1,7 @@ { "name": "composer", "description": "Installs/Configures Composer", - "long_description": "[![Build Status](https://travis-ci.org/djoos-cookbooks/composer.png)](https://travis-ci.org/djoos-cookbooks/composer)\n\n# composer cookbook\n\n## Description\n\nThis cookbook provides an easy way to install Composer, a dependency manager for PHP.\n\nMore information?\nhttp://getcomposer.org/\n\n## Requirements\n\n### Cookbooks:\n\n* php\n* windows\n\n### Platforms:\n\n* Ubuntu\n* Debian\n* RHEL\n* CentOS\n* Fedora\n* Windows\n\n## Attributes\n\n* `node['composer']['url']` - Location of the source\n* `node['composer']['install_dir']` - Installation target directory (absolute or relative path) if installing locally\n* `node['composer']['bin']` - bin directory\n* `node['composer']['install_globally']` - Installation method, ':source' or ':package' - default true\n* `node['composer']['mask']` - Mask for composer.phar - 0755\n* `node['composer']['link_type']` - link type for composer.phar link - default :symbolic\n* `node['composer']['global_configs']` - Hash with global config options for users, eg. { \"userX\" => { \"github-oauth\" => { \"github.com\" => \"userX_oauth_token\" }, \"vendor-dir\" => \"myvendordir\" } } - default {}\n* `node['composer']['home_dir']` - COMPOSER_HOME, defaults to nil (in which case install_dir will be used), please do read the [Composer documentation on COMPOSER_HOME](https://getcomposer.org/doc/03-cli.md#composer-home) when setting a custom home_dir\n* `node['composer']['php_recipe']` - The php recipe to include, defaults to \"php::default\"\n* `node['composer']['global_install']['install_dir']` - The default location to install the packages in for composer_install_global\n* `node['composer']['global_install']['bin_dir']` - The default location to symlink the binaries when using composer_install_global\n\n## Resources / Providers\nThis cookbook includes an LWRP for managing a Composer project and one for a global installation of composer packages\n\n### `composer_project`\n\n#### Actions\n- :install: Reads the composer.json file from the current directory, resolves the dependencies, and installs them into project directory - this is the default action\n- :require Create composer.json file using specified package and version and installs it with the dependencies.\n- :update: Gets the latest versions of the dependencies and updates the composer.lock file\n- :dump_autoload: Updates the autoloader without having to go through an install or update (eg. because of new classes in a classmap package)\n- :remove Removes package from composer.json and uninstalls it\n\n#### Attribute parameters\n- project_dir: The directory where your project's composer.json can be found (name attribute)\n- package: The package to require or remove when using those actions\n- version: The version of the package to require or remove when using those actions, default *.*.* Be careful when uninstalling, the version has to match the installed package!\n- vendor: Can be used to combine package and version, deprecated!\n- dev: Install packages listed in require-dev, default false\n- quiet: Do not output any message, default true\n- optimize_autoloader: Optimize PSR0 packages to use classmaps, default false\n- prefer_dist: use the dist installation method\n- prefer_source: use the source installation method\n- bin_dir, overwrites the composer bin dir\n- user: the user to use when executing the composer commands\n- group: the group to use when executing the composer commands\n- umask: the umask to use when executing the composer commands\n- environment: A hash of environment variables that will be available when running composer\n\n#### Examples\n```\n# Install the project dependencies\ncomposer_project \"/path/to/project\" do\n dev false\n quiet true\n prefer_dist false\n action :install\nend\n\n# Require the package in the project dir\ncomposer_project \"/path/to/project\" do\n package 'vendor/package'\n version '*.*.*'\n dev false\n quiet true\n prefer_dist false\n action :require\nend\n\n# Update the project dependencies\ncomposer_project \"/path/to/project\" do\n dev false\n quiet true\n action :update\nend\n\n# Dump-autoload in the project dir\ncomposer_project \"/path/to/project\" do\n dev false\n quiet true\n action :dump_autoload\nend\n\n# Remove the package in the project dir\ncomposer_project \"/path/to/project\" do\n package 'vendor/package'\n action :remove\nend\n```\n\n### `composer_install_global`\n\n#### Actions\n- :install: Installs the package in the preferred global composer directory, putting binary symlinks in the preferred global binary directory (see attributes)\n- :update: Gets the latest versions of the dependencies and updates the composer.lock file for the globally installed composer packages\n- :remove Removes package from the global composer.json and uninstalls it\n\n#### Attribute parameters\n- package: The package to install or remove, name_attribute\n- version: The version of the package to install or remove when using those actions, default *.*.* Be careful when uninstalling, the version has to match the installed package!\n- install_dir: the directory in which to make the global installation, default: see the attributes\n- bin_dir: the directory in which to make the symlinks to the binaries, default: see the attributes\n- dev: Install packages listed in require-dev, default false\n- quiet: Do not output any message, default true\n- optimize_autoloader: Optimize PSR0 packages to use classmaps, default false\n- prefer_dist: use the dist installation method\n- prefer_source: use the source installation method\n\n#### Examples\n```\n# Install a package globally\ncomposer_install_global \"package\" do\n version '~4.1'\n action :install\nend\n\n# Update the package\ncomposer_install_global \"package\" do\n action :update\nend\n\n# Remove the package from the global installation\ncomposer_install_global \"package\" do\n action :remove\nend\n```\n\n## Usage\n\n1. include `recipe[composer]` in a run list\n2. tweak the attributes via attributes/default.rb\n--- OR ---\n[override the attribute on a higher level](http://wiki.opscode.com/display/chef/Attributes#Attributes-AttributesPrecedence)\n\n## References\n\n* [Composer home page] (http://getcomposer.org/)\n\n## License and Authors\n\nAuthor: David Joos \nCopyright: 2016, David Joos\n\nAuthor: David Joos \nAuthor: Escape Studios Development \nCopyright: 2012-2015, Escape Studios\n\nUnless otherwise noted, all files are released under the MIT license,\npossible exceptions will contain licensing information in them.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n", + "long_description": "[![Build Status](https://travis-ci.org/djoos-cookbooks/composer.png)](https://travis-ci.org/djoos-cookbooks/composer)\n\n# composer cookbook\n\n## Description\n\nThis cookbook provides an easy way to install Composer, a dependency manager for PHP.\n\nMore information?\nhttp://getcomposer.org/\n\n## Requirements\n\n### Cookbooks:\n\n* php\n* windows\n\n### Platforms:\n\n* Ubuntu\n* Debian\n* RHEL\n* CentOS\n* Fedora\n* Windows\n\n## Attributes\n\n* `node['composer']['url']` - Location of the source\n* `node['composer']['install_dir']` - Installation target directory (absolute or relative path) if installing locally\n* `node['composer']['bin']` - bin directory\n* `node['composer']['install_globally']` - Installation method, ':source' or ':package' - default true\n* `node['composer']['mask']` - Mask for composer.phar - 0755\n* `node['composer']['link_type']` - link type for composer.phar link - default :symbolic\n* `node['composer']['global_configs']` - Hash with global config options for users, eg. { \"userX\" => { \"github-oauth\" => { \"github.com\" => \"userX_oauth_token\" }, \"vendor-dir\" => \"myvendordir\" } } - default {}\n* `node['composer']['home_dir']` - COMPOSER_HOME, defaults to nil (in which case install_dir will be used), please do read the [Composer documentation on COMPOSER_HOME](https://getcomposer.org/doc/03-cli.md#composer-home) when setting a custom home_dir\n* `node['composer']['php_recipe']` - The php recipe to include, defaults to \"php::default\"\n* `node['composer']['global_install']['install_dir']` - The default location to install the packages in for composer_install_global\n* `node['composer']['global_install']['bin_dir']` - The default location to symlink the binaries when using composer_install_global\n\n## Resources / Providers\nThis cookbook includes an LWRP for managing a Composer project and one for a global installation of composer packages\n\n### `composer_project`\n\n#### Actions\n- :install: Reads the composer.json file from the current directory, resolves the dependencies, and installs them into project directory - this is the default action\n- :require Create composer.json file using specified package and version and installs it with the dependencies.\n- :update: Gets the latest versions of the dependencies and updates the composer.lock file\n- :dump_autoload: Updates the autoloader without having to go through an install or update (eg. because of new classes in a classmap package)\n- :remove Removes package from composer.json and uninstalls it\n\n#### Attribute parameters\n- project_dir: The directory where your project's composer.json can be found (name attribute)\n- package: The package to require or remove when using those actions\n- version: The version of the package to require or remove when using those actions, default *.*.* Be careful when uninstalling, the version has to match the installed package!\n- vendor: Can be used to combine package and version, deprecated!\n- dev: Install packages listed in require-dev, default false\n- quiet: Do not output any message, default true\n- optimize_autoloader: Optimize PSR0 packages to use classmaps, default false\n- prefer_dist: use the dist installation method\n- prefer_source: use the source installation method\n- bin_dir, overwrites the composer bin dir\n- user: the user to use when executing the composer commands\n- group: the group to use when executing the composer commands\n- umask: the umask to use when executing the composer commands\n- environment: A hash of environment variables that will be available when running composer\n\n#### Examples\n```\n# Install the project dependencies\ncomposer_project \"/path/to/project\" do\n dev false\n quiet true\n prefer_dist false\n action :install\nend\n\n# Require the package in the project dir\ncomposer_project \"/path/to/project\" do\n package 'vendor/package'\n version '*.*.*'\n dev false\n quiet true\n prefer_dist false\n action :require\nend\n\n# Update the project dependencies\ncomposer_project \"/path/to/project\" do\n dev false\n quiet true\n action :update\nend\n\n# Dump-autoload in the project dir\ncomposer_project \"/path/to/project\" do\n dev false\n quiet true\n action :dump_autoload\nend\n\n# Remove the package in the project dir\ncomposer_project \"/path/to/project\" do\n package 'vendor/package'\n action :remove\nend\n```\n\n### `composer_install_global`\n\n#### Actions\n- :install: Installs the package in the preferred global composer directory, putting binary symlinks in the preferred global binary directory (see attributes)\n- :update: Gets the latest versions of the dependencies and updates the composer.lock file for the globally installed composer packages\n- :remove Removes package from the global composer.json and uninstalls it\n\n#### Attribute parameters\n- package: The package to install or remove, name_attribute\n- version: The version of the package to install or remove when using those actions, default *.*.* Be careful when uninstalling, the version has to match the installed package!\n- install_dir: the directory in which to make the global installation, default: see the attributes\n- bin_dir: the directory in which to make the symlinks to the binaries, default: see the attributes\n- dev: Install packages listed in require-dev, default false\n- quiet: Do not output any message, default true\n- optimize_autoloader: Optimize PSR0 packages to use classmaps, default false\n- prefer_dist: use the dist installation method\n- prefer_source: use the source installation method\n\n#### Examples\n```\n# Install a package globally\ncomposer_install_global \"package\" do\n version '~4.1'\n action :install\nend\n\n# Update the package\ncomposer_install_global \"package\" do\n action :update\nend\n\n# Remove the package from the global installation\ncomposer_install_global \"package\" do\n action :remove\nend\n```\n\n## Usage\n\n1. include `recipe[composer]` in a run list\n2. tweak the attributes via attributes/default.rb\n--- OR ---\n[override the attribute on a higher level](http://wiki.opscode.com/display/chef/Attributes#Attributes-AttributesPrecedence)\n\n## References\n\n* [Composer home page] (http://getcomposer.org/)\n\n## License and Authors\n\nAuthor: David Joos \nCopyright: 2016-2017, David Joos\n\nAuthor: David Joos \nAuthor: Escape Studios Development \nCopyright: 2012-2015, Escape Studios\n\nUnless otherwise noted, all files are released under the MIT license,\npossible exceptions will contain licensing information in them.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n", "maintainer": "David Joos", "maintainer_email": "development@davidjoos.com", "license": "MIT", @@ -19,27 +19,12 @@ "apt": ">= 0.0.0", "php": ">= 0.0.0", "windows": ">= 0.0.0" - }, - "recommendations": { - - }, - "suggestions": { - - }, - "conflicting": { - }, "providing": { - }, - "replacing": { - }, "attributes": { - }, - "groupings": { - }, "recipes": { "composer": "Installs (if applicable) and self-updates composer.", @@ -47,12 +32,14 @@ "composer::self_update": "Installs (if applicable) and self-updates composer.", "composer::global_configs": "Sets up global config options via `composer config --global`" }, - "version": "2.6.1", + "version": "2.7.0", "source_url": "https://github.com/djoos-cookbooks/composer", "issues_url": "https://github.com/djoos-cookbooks/composer/issues", "privacy": false, "chef_versions": [ - + [ + ">= 0.10.0" + ] ], "ohai_versions": [ diff --git a/cookbooks/composer/metadata.rb b/cookbooks/composer/metadata.rb index 4cc7da0..aae5776 100644 --- a/cookbooks/composer/metadata.rb +++ b/cookbooks/composer/metadata.rb @@ -4,9 +4,10 @@ maintainer_email 'development@davidjoos.com' license 'MIT' description 'Installs/Configures Composer' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '2.6.1' +version '2.7.0' +chef_version '>= 0.10.0' if respond_to?(:chef_version) -%w(debian ubuntu redhat centos fedora scientific amazon windows).each do |os| +%w[debian ubuntu redhat centos fedora scientific amazon windows].each do |os| supports os end diff --git a/cookbooks/composer/providers/install_global.rb b/cookbooks/composer/providers/install_global.rb index 8022a64..99dfbfb 100644 --- a/cookbooks/composer/providers/install_global.rb +++ b/cookbooks/composer/providers/install_global.rb @@ -13,17 +13,14 @@ end action :install do install_global_install - new_resource.updated_by_last_action(true) end action :remove do install_global_remove - new_resource.updated_by_last_action(true) end action :update do install_global_update - new_resource.updated_by_last_action(true) end def install_global_install diff --git a/cookbooks/composer/providers/project.rb b/cookbooks/composer/providers/project.rb index 11064ad..35b421d 100644 --- a/cookbooks/composer/providers/project.rb +++ b/cookbooks/composer/providers/project.rb @@ -13,7 +13,6 @@ end action :install do make_execute 'install' - new_resource.updated_by_last_action(true) end action :require do @@ -22,12 +21,10 @@ end action :update do make_execute 'update' - new_resource.updated_by_last_action(true) end action :dump_autoload do make_execute 'dump-autoload' - new_resource.updated_by_last_action(true) end action :remove do diff --git a/cookbooks/composer/recipes/install.rb b/cookbooks/composer/recipes/install.rb index 477b418..3a2f9e2 100755 --- a/cookbooks/composer/recipes/install.rb +++ b/cookbooks/composer/recipes/install.rb @@ -10,9 +10,9 @@ include_recipe node['composer']['php_recipe'] if node['platform'] == 'windows' windows_package 'Composer - PHP Dependency Manager' do source node['composer']['url'] - options %w( + options %w[ /VERYSILENT - ).join(' ') + ].join(' ') end install_dir = "#{node['composer']['install_dir'].tr('/', '\\')}\\bin" diff --git a/cookbooks/composer/recipes/self_update.rb b/cookbooks/composer/recipes/self_update.rb index 25d1bc1..6cf1058 100644 --- a/cookbooks/composer/recipes/self_update.rb +++ b/cookbooks/composer/recipes/self_update.rb @@ -7,9 +7,15 @@ include_recipe 'composer::install' +channel = if node['composer']['self_update_channel'].nil? + '' + else + " --#{node['composer']['self_update_channel']}" + end + execute 'composer-self_update' do cwd node['composer']['install_dir'] - command 'composer self-update' + command 'composer self-update' + channel environment 'COMPOSER_HOME' => Composer.home_dir(node) action :run ignore_failure true diff --git a/cookbooks/composer/resources/install_global.rb b/cookbooks/composer/resources/install_global.rb index 93f259d..a595251 100644 --- a/cookbooks/composer/resources/install_global.rb +++ b/cookbooks/composer/resources/install_global.rb @@ -17,8 +17,3 @@ attribute :quiet, :kind_of => [TrueClass, FalseClass], :default => true attribute :optimize_autoloader, :kind_of => [TrueClass, FalseClass], :default => false attribute :prefer_dist, :kind_of => [TrueClass, FalseClass], :default => false attribute :prefer_source, :kind_of => [TrueClass, FalseClass], :default => false - -def initialize(*args) - super - @action = :install -end diff --git a/cookbooks/composer/resources/project.rb b/cookbooks/composer/resources/project.rb index 1780ef2..93ebca5 100644 --- a/cookbooks/composer/resources/project.rb +++ b/cookbooks/composer/resources/project.rb @@ -22,8 +22,3 @@ attribute :user, :kind_of => String, :default => 'root' attribute :group, :kind_of => String, :default => 'root' attribute :umask, :kind_of => [String, Integer], :default => '0002' attribute :environment, :kind_of => Hash, :default => {} - -def initialize(*args) - super - @action = :install -end diff --git a/cookbooks/mediawiki/metadata.json b/cookbooks/mediawiki/metadata.json index 6e73805..9998b8b 100644 --- a/cookbooks/mediawiki/metadata.json +++ b/cookbooks/mediawiki/metadata.json @@ -12,8 +12,7 @@ "dependencies": { "apache2": ">= 0.0.0", "php": ">= 0.0.0", - "nginx": ">= 0.0.0", - "php-fpm": ">= 0.0.0" + "nginx": ">= 0.0.0" }, "providing": { diff --git a/cookbooks/mediawiki/metadata.rb b/cookbooks/mediawiki/metadata.rb index 4dbc567..2861c3c 100644 --- a/cookbooks/mediawiki/metadata.rb +++ b/cookbooks/mediawiki/metadata.rb @@ -8,7 +8,6 @@ version '0.5.0' depends 'apache2' depends 'php' depends 'nginx' -depends 'php-fpm' attribute 'mediawiki/version', :display_name => "Mediawiki version", diff --git a/cookbooks/mediawiki/recipes/nginx.rb b/cookbooks/mediawiki/recipes/nginx.rb index 30c1fb8..6fe3eaa 100644 --- a/cookbooks/mediawiki/recipes/nginx.rb +++ b/cookbooks/mediawiki/recipes/nginx.rb @@ -3,30 +3,11 @@ # Recipe:: nginx # -node.default['php-fpm']['pools'] = [] -node.override['php-fpm']['package_name'] = "php-fpm" -node.override['php-fpm']['service_name'] = "php7.2-fpm" -node.override['php-fpm']['conf_dir'] = "/etc/php/7.2/fpm/conf.d" -node.override['php-fpm']['pool_conf_dir'] = "/etc/php/7.2/fpm/pool.d" -node.override['php-fpm']['conf_file'] = "/etc/php/7.2/fpm/php-fpm.conf" - -include_recipe "php-fpm" -include_recipe 'php-fpm::repository' unless node['php-fpm']['skip_repository_install'] -include_recipe "php-fpm::install" - -php_fpm_pool "www" do - enable false -end - php_fpm_pool "mediawiki" do listen "127.0.0.1:9002" user node['nginx']['user'] group node['nginx']['group'] - listen_owner node['nginx']['user'] - listen_group node['nginx']['group'] - php_options node['mediawiki']['php_options'] - start_servers 5 - enable true + additional_config node['mediawiki']['php_options'] end include_recipe "nginx" diff --git a/cookbooks/mysql/.foodcritic b/cookbooks/mysql/.foodcritic deleted file mode 100644 index 913f038..0000000 --- a/cookbooks/mysql/.foodcritic +++ /dev/null @@ -1 +0,0 @@ -~FC005 diff --git a/cookbooks/mysql/CHANGELOG.md b/cookbooks/mysql/CHANGELOG.md index 92291b9..2296313 100644 --- a/cookbooks/mysql/CHANGELOG.md +++ b/cookbooks/mysql/CHANGELOG.md @@ -1,24 +1,84 @@ -# mysql Cookbook CHANGELOG +# Changelog -This file is used to list changes made in each version of the mysql cookbook. +All notable changes to this project will be documented in this file. -## 8.5.1 (2017-08-23) +## 8.7.3 - 2020-07-22 + +- restore resource_name in mysql_service for Chef Infra Client < 16 +- resolved cookstyle error: libraries/mysql_client_installation_package.rb:8:5 warning: `ChefDeprecations/ResourceUsesOnlyResourceName` +- resolved cookstyle error: libraries/mysql_client_installation_package.rb:9:1 convention: `Layout/IndentationConsistency` +- resolved cookstyle error: libraries/mysql_client_installation_package.rb:9:1 convention: `Layout/IndentationWidth` +- resolved cookstyle error: libraries/mysql_client_installation_package.rb:9:3 convention: `Layout/IndentationWidth` +- resolved cookstyle error: libraries/mysql_client_installation_package.rb:9:9 convention: `Layout/IndentationConsistency` +- resolved cookstyle error: libraries/mysql_server_installation_package.rb:4:5 warning: `ChefDeprecations/ResourceUsesOnlyResourceName` +- resolved cookstyle error: libraries/mysql_server_installation_package.rb:5:1 convention: `Layout/IndentationConsistency` +- resolved cookstyle error: libraries/mysql_server_installation_package.rb:5:1 convention: `Layout/IndentationWidth` +- resolved cookstyle error: libraries/mysql_server_installation_package.rb:5:3 convention: `Layout/IndentationWidth` +- resolved cookstyle error: libraries/mysql_server_installation_package.rb:5:9 convention: `Layout/IndentationConsistency` +- resolved cookstyle error: libraries/mysql_service_manager_systemd.rb:3:5 warning: `ChefDeprecations/ResourceUsesOnlyResourceName` +- resolved cookstyle error: libraries/mysql_service_manager_systemd.rb:4:1 convention: `Layout/IndentationConsistency` +- resolved cookstyle error: libraries/mysql_service_manager_systemd.rb:4:1 convention: `Layout/IndentationWidth` +- resolved cookstyle error: libraries/mysql_service_manager_systemd.rb:4:3 convention: `Layout/IndentationWidth` +- resolved cookstyle error: libraries/mysql_service_manager_systemd.rb:4:9 convention: `Layout/IndentationConsistency` +- resolved cookstyle error: libraries/mysql_service_manager_sysvinit.rb:3:5 warning: `ChefDeprecations/ResourceUsesOnlyResourceName` +- resolved cookstyle error: libraries/mysql_service_manager_sysvinit.rb:4:1 convention: `Layout/IndentationConsistency` +- resolved cookstyle error: libraries/mysql_service_manager_sysvinit.rb:4:1 convention: `Layout/IndentationWidth` +- resolved cookstyle error: libraries/mysql_service_manager_sysvinit.rb:4:3 convention: `Layout/IndentationWidth` +- resolved cookstyle error: libraries/mysql_service_manager_sysvinit.rb:4:9 convention: `Layout/IndentationConsistency` +- resolved cookstyle error: libraries/mysql_service_manager_upstart.rb:3:5 warning: `ChefDeprecations/ResourceUsesOnlyResourceName` +- resolved cookstyle error: libraries/mysql_service_manager_upstart.rb:4:1 convention: `Layout/IndentationConsistency` +- resolved cookstyle error: libraries/mysql_service_manager_upstart.rb:4:1 convention: `Layout/IndentationWidth` +- resolved cookstyle error: libraries/mysql_service_manager_upstart.rb:4:3 convention: `Layout/IndentationWidth` +- resolved cookstyle error: libraries/mysql_service_manager_upstart.rb:4:9 convention: `Layout/IndentationConsistency` + +## 8.7.2 - 2020-06-02 + +- resolved cookstyle error: libraries/mysql_service.rb:4:5 warning: `ChefDeprecations/ResourceUsesOnlyResourceName` + +## 8.7.1 - 2020-05-20 + +- resolved cookstyle error: spec/mysql_client_installation_package_spec.rb:7:46 warning: `ChefDeprecations/DeprecatedChefSpecPlatform` +- resolved cookstyle error: spec/mysql_server_installation_package_spec.rb:7:46 warning: `ChefDeprecations/DeprecatedChefSpecPlatform` + +## 8.7.0 - 2020-05-05 + +- migration to Github Actions +- Ability to include "none" as an installation method in mysql_service +- resolved cookstyle error: libraries/helpers.rb:57:48 refactor: `ChefStyle/UnnecessaryOSCheck` +- resolved cookstyle error: libraries/helpers.rb:58:41 refactor: `ChefStyle/UnnecessaryOSCheck` + +## [8.6.0] - 2019-12-03 + +- Fix the failing linting tests +- Add mysql57 support for Amazon Linux AMI +- Fix installation and testing on Ubuntu 18.04 bionic, EL7, Fedora and Opensuse +- Ensure compatibility with mysql 5.7 on Ubtuntu 16.04 +- Add apparmor profile for ubuntu 16.04 +- Allow instance with 'mysql' as name +- Add a helper for Ubuntu 18.04 +- Remove support for Debian 7 +- Remove ChefSpec matchers +- Set apparmor tmp_dir permissions on directory itself +- Run latest cookstyle +- Circleci, Yaml and markdown lint updates + +## [8.5.1] - 2017-08-23 - Fix the remainder of the namespace collision deprecation warnings - Remove the class_eval in the action class as this causes issues with some releases of Chef 12 -## 8.5.0 (2017-08-23) +## [8.5.0] - 2017-08-23 - Require Chef 12.7+ since 12.5/12.6 has custom resource action_class issues - Resolve several Chef 14 deprecation warnings -## 8.4.0 (2017-05-30) +## [8.4.0] - 2017-05-30 - Fix client/server install on Amazon Linux and add testing - Remove support for Ubuntu Precise since it's EOL - Add Amazon Linux testing -## 8.3.1 (2017-04-04) +## [8.3.1] - 2017-04-04 - Fix an ignoring of 'cookbook' attribute by 'mysql_config' resource - Remove unused helper method @@ -26,21 +86,24 @@ This file is used to list changes made in each version of the mysql cookbook. - Switch to Delivery Local and rename the docked config - Remove mention of the EOL opensuse 13.x in the readme -## 8.3.0 (2017-03-20) +## [8.3.0] - 2017-03-20 + - Refactor mysql_service_manager_upstart.rb to eliminate use of cloned resource -## 8.2.0 (2016-12-03) +## [8.2.0] - 2016-12-03 - Include client development packages on RHEL/SUSE platforms -## 8.1.1 (2016-10-31) +## [8.1.1] - 2016-10-31 + - Fixing CVE-2016-6662 - Reverting execure bit on mysql config -## 8.1.0 (2016-10-29) +## [8.1.0] - 2016-10-29 - Drop hardcoded, specific package version logic that broke many users -## 8.0.4 (2016-09-26) +## [8.0.4] - 2016-09-26 + - Bump debian version - Updated packages for 12.04 and 14.04 too - Add chef_version metadata @@ -48,19 +111,22 @@ This file is used to list changes made in each version of the mysql cookbook. - Add selinux to the Berksfile for testing - Make sure yum repos are setup in local Test Kitchen -## 8.0.3 (2016-09-14) +## [8.0.3] - 2016-09-14 + - [GH-390] Fix #390 incorrect escaping of initial_root_password - Updated package versions for Ubuntu 16.04 - Testing updates -# v8.0.2 (2016-08-25) +## [8.0.2] - 2016-08-25 + - Various bug fixed and updates to package version strings -# v8.0.1 (2016-07-20) +## [8.0.1] - 2016-07-20 + - Fixed a regression in the mysql_client resource where the action was changed from create to install in the 8.0 release - Added oracle, opensuse, and opensuseleap as supported platforms in the metadata -# v8.0.0 (2016-07-11) +## [8.0.0] - 2016-07-11 - Converting from LWRP to custom resources - Removing yum-mysql and other dependencies. @@ -71,26 +137,26 @@ This file is used to list changes made in each version of the mysql cookbook. - Renaming "replication" test suite to "smoke" - Moving to Inspec -## v7.2.0 (2016-06-30) +## [7.2.0] - 2016-06-30 - Support openeSUSE leap - Support Fedora 24 -## v7.1.2 (2016-06-30) +## [7.1.2] - 2016-06-30 - Avoid deprecation warnings on the upcoming Chef 12.12 release -## v7.1.1 (2016-06-03) +## [7.1.1] - 2016-06-03 - Fix apparmor blocking writes to non-default tmp_dirs - Updated apparmor config to allow read & write to sock.lock file - Use cookstyle instead of Rubocop directly -## v7.1.0 (2016-05-11) +## [7.1.0] - 2016-05-11 - Added support for Ubuntu 16.04 -## v7.0.0 (2016-04-19) +## [7.0.0] - 2016-04-19 - Removed support for legacy distros: Ubuntu 10.04/13.04/14.10/15.04, Fedora 20/21, OmniOS r151006, opensuse 11.3/12.0 - Added support for Fedora 23, suse 13.X, and Ubuntu 16.04 @@ -100,161 +166,161 @@ This file is used to list changes made in each version of the mysql cookbook. - Added Travis CI Test Kitchen testing on Fedora 22/23 and removed Fedora 21 - Updated the platforms used in the specs -## v6.1.3 (2016-03-14) +## [6.1.3] - 2016-03-14 - Added support for Ubuntu 15.10 - Added support for Amazon Linux 2016-03 - Updated Kitchen testing configs -## v6.1.2 (2015-10-05) +## [6.1.2] - 2015-10-05 - Added support for Amazon Linux 2015.09 -## v6.1.1 (2015-09-24) +## [6.1.1] - 2015-09-24 - Completing ChefSpec matchers -## v6.1.0 (2015-07-17) +## [6.1.0] - 2015-07-17 - Adding tunables for tmp_dir, error_log, and pid_file - Adding mysqld_options hash interface for main my.cnf template -## v6.0.31 (2015-07-13) +## [6.0.31] - 2015-07-13 - Reverting create_stop_system_service checks -## v6.0.30 (2015-07-13) +## [6.0.30] - 2015-07-13 - Ubuntu 15.04 support - Check for scripts and unit files during create_stop_system_service -## v6.0.29 (2015-07-12) +## [6.0.29] - 2015-07-12 - Patch to allow blank root password - Adding package information for Suse 12.0 -## v6.0.28 (2015-07-10) +## [6.0.28] - 2015-07-10 - Fixes for 12.4.x -## v6.0.27 (2015-07-09) +## [6.0.27] - 2015-07-09 - Allowing integer value for port number -## v6.0.26 (2015-07-07) +## [6.0.26] - 2015-07-07 - Reverting breaking changes introduced in 6.0.25 -## v6.0.25 (2015-07-06) +## [6.0.25] - 2015-07-06 - Fixes for 12.4.1 -## v6.0.24 (2015-06-27) +## [6.0.24] - 2015-06-27 - 341 - Changing default GRANT for root from '%' to 'localhost' and '127.0.0.1' -## v6.0.23 (2015-06-21) +## [6.0.23] - 2015-06-21 - 354 Better handling of long MySQL startup times -## v6.0.22 (2015-05-07) +## [6.0.22] - 2015-05-07 - Debian 8 (Jessie) support -## v6.0.21 (2015-04-08) +## [6.0.21] - 2015-04-08 - Fix to Upstart prestart script when using custom socket - Adding --explicit_defaults_for_timestamp mysql_install_db_cmd for - 5.6 and above -## v6.0.20 (2015-03-27) +## [6.0.20] - 2015-03-27 - 318 - Fixing Upstart pre-start script to handle custom socket paths -## v6.0.19 (2015-03-25) +## [6.0.19] - 2015-03-25 - Adding support for Amazon Linux 2015.03 -## v6.0.18 (2015-03-24) +## [6.0.18] - 2015-03-24 - Adding support for 5.6 and 5.7 packages from dotdeb repos on Debian 7 -## v6.0.17 (2015-03-13) +## [6.0.17] - 2015-03-13 - Updated for MySQL 5.7.6. - Handing removal of mysql_install_db and mysqld_safe -## v6.0.16 (2015-03-10) +## [6.0.16] - 2015-03-10 - Moved --defaults-file as first option to mysql_install_db_script -## v6.0.15 (2015-02-26) +## [6.0.15] - 2015-02-26 - Updating docker detection fix to pass specs -## v6.0.14 (2015-02-26) +## [6.0.14] - 2015-02-26 - Fixed debian system service :disable action. Now survives reboot - Fixing centos-7 instance :enable action. Now survives - Not applying Apparmor policy if running in a Docker container -## v6.0.13 (2015-02-15) +## [6.0.13] - 2015-02-15 - Adding support for special characters in initial_root_password - Fixing failure status bug in sysvinit script -## v6.0.12 (2015-02-30) +## [6.0.12] - 2015-02-30 - No changes. Released a 6.0.11 that was identical to 6.0.10. - Git before coffee. -## v6.0.11 (2015-02-30) +## [6.0.11] - 2015-02-30 - Adding support for configurable socket files -## v6.0.10 (2015-01-19) +## [6.0.10] - 2015-01-19 - Fix #282 - Fixing up data_dir template variable -## v6.0.9 (2015-01-19) +## [6.0.9] - 2015-01-19 - Fix #282 - undefined method `parsed_data_dir' bug -## v6.0.8 (2015-01-19) +## [6.0.8] - 2015-01-19 - Refactoring helper methods out of resource classes -## v6.0.7 (2015-01-14) +## [6.0.7] - 2015-01-14 - Fixing timing issue with Upstart provider :restart and :reload - actions where service returns before being available -## v6.0.6 (2014-12-26) +## [6.0.6] - 2014-12-26 - Fixing subtle bug where MysqlCookbook::Helper methods were polluting Chef::Resource -## v6.0.5 (2014-12-25) +## [6.0.5] - 2014-12-25 - Using 'include_recipe' instead of 'recipe_eval' in LWRP - Fixing type checking on package_name attribute in mysql_client resource. -## v6.0.4 (2014-12-21) +## [6.0.4] - 2014-12-21 - Suggest available versions if current is not available for current platform. -## v6.0.3 (2014-12-17) +## [6.0.3] - 2014-12-17 - Adding bind_address parameter to mysql_service resource -## v6.0.2 (2014-12-17) +## [6.0.2] - 2014-12-17 - Fixing sysvinit provider to survive reboots -## v6.0.1 (2014-12-16) +## [6.0.1] - 2014-12-16 - Fixing Upstart template to survive reboots -## v6.0.0 (2014-12-15) +## [6.0.0] - 2014-12-15 - Major version update - Cookbook now provides LWRPs instead of recipes @@ -269,11 +335,11 @@ This file is used to list changes made in each version of the mysql cookbook. - Refactored acceptance tests - Temporarily dropped FreeBSD support -## v5.6.1 (2014-10-29) +## [5.6.1] - 2014-10-29 - Use Gem::Version instead of Chef::Version -## v5.6.0 (2014-10-29) +## [5.6.0] - 2014-10-29 - Changing default charset to utf8 - Quoting passwords in debian.cnf.erb @@ -282,45 +348,45 @@ This file is used to list changes made in each version of the mysql cookbook. - Only hide passwords from STDOUT via "sensitive true" in chef-client higher than 11.14 - Updating test harness -## v5.5.4 (2014-10-07) +## [5.5.4] - 2014-10-07 - Adding sensitive flag to execute resources to protect passwords from logs -## v5.5.3 (2014-09-24) +## [5.5.3] - 2014-09-24 - Reverting back to Upstart on Ubuntu 14.04 -## v5.5.2 (2014-09-8) +## [5.5.2] - 2014-09-8 - Reverting commit that broke Debian pass_string -## v5.5.1 (2014-09-2) +## [5.5.1] - 2014-09-2 - Switching Ubuntu service provider to use SysVinit instead of Upstart -## v5.5.0 (2014-08-27) +## [5.5.0] - 2014-08-27 - Adding package version and action parameters to mysql_service resource - Fixing Debian pass_string -## v5.4.4 (2014-08-27) +## [5.4.4] - 2014-08-27 - Changing module namespace to MysqlCookbook -## v5.4.3 (2014-08-25) +## [5.4.3] - 2014-08-25 - More refactoring. Moving helper function bits into resource parsed_parameters -## v5.4.2 (2014-08-25) +## [5.4.2] - 2014-08-25 - Moving provider local variables into definitions for RHEL provider -## v5.4.1 (2014-08-25) +## [5.4.1] - 2014-08-25 - Refactoring resources into the LWRP style with parsed parameters - Moving provider local variables into definitions -## v5.4.0 (2014-08-25) +## [5.4.0] - 2014-08-25 - 212 - support for centos-7 (mysql55 and mysql56) - Adding (untested) Debian-6 support @@ -330,119 +396,119 @@ This file is used to list changes made in each version of the mysql cookbook. - Appeasing AppArmor - Reducing duplication in client provider -## v5.3.6 (2014-06-18) +## [5.3.6] - 2014-06-18 - Fixing pid path location. Updating tests to include real RHEL -## v5.3.4 (2014-06-16) +## [5.3.4] - 2014-06-16 - Fixing specs for Amazon Linux server package names -## v5.3.2 (2014-06-16) +## [5.3.2] - 2014-06-16 - Fixing Amazon Linux support -## v5.3.0 (2014-06-11) +## [5.3.0] - 2014-06-11 - 189 - Fix server_repl_password description - 191 - Adding support for server55 and server56 on el-6 - 193 - Fix syntax in mysql_service example - 199 - Adding Suse support -## v5.2.12 (2014-05-19) +## [5.2.12] - 2014-05-19 PR #192 - recipes/server.rb should honor parameter node['mysql']['version'] -## v5.2.10 (2014-05-15) +## [5.2.10] - 2014-05-15 - COOK-4394 - restore freebsd support -## v5.2.8 (2014-05-15) +## [5.2.8] - 2014-05-15 - [COOK-4653] - Missing mySQL 5.6 support for Ubuntu 14.04 -## v5.2.6 (2014-05-07) +## [5.2.6] - 2014-05-07 - [COOK-4625] - Fix password resource parameter consumption on Debian and Ubuntu - Fix up typos and version numbers in PLATFORMS.md - Fix up specs from COOK-4613 changes -## v5.2.4 (2014-05-02) +## [5.2.4] - 2014-05-02 - [COOK-4613] - Fix permissions on mysql data_dir to allow global access to mysql.sock -## v5.2.2 (2014-04-24) +## [5.2.2] - 2014-04-24 - [COOK-4564] - Using positive tests for datadir move -## v5.2.0 (2014-04-22) +## [5.2.0] - 2014-04-22 - [COOK-4551] - power grants.sql from resource parameters -## v5.1.12 (2014-04-21) +## [5.1.12] - 2014-04-21 - [COOK-4554] - Support for Debian Sid -## v5.1.10 (2014-04-21) +## [5.1.10] - 2014-04-21 - [COOK-4565] Support for Ubuntu 14.04 - [COOK-4565] Adding Specs and TK platform - Removing non-LTS 13.10 specs and TK platform -## v5.1.8 (2014-04-12) +## [5.1.8] - 2014-04-12 Adding Ubuntu 13.04 to Platforminfo -## v5.1.6 (2014-04-11) +## [5.1.6] - 2014-04-11 - [COOK-4548] - Add template[/etc/mysql/debian.cnf] to Ubuntu provider -## v5.1.4 (2014-04-11) +## [5.1.4] - 2014-04-11 - [COOK-4547] - Shellescape server_root_password -## v5.1.2 (2014-04-09) +## [5.1.2] - 2014-04-09 - [COOK-4519] - Fix error in run_dir for Ubuntu - [COOK-4531] - Fix pid and run_dir for Debian -## v5.1.0 (2014-04-08) +## [5.1.0] - 2014-04-08 [COOK-4523] - Allow for both :restart and :reload -## v5.0.6 (2014-04-07) +## [5.0.6] - 2014-04-07 - [COOK-4519] - Updating specs to reflect pid file change on Ubuntu -## v5.0.4 (2014-04-07) +## [5.0.4] - 2014-04-07 - [COOK-4519] - Fix path to pid file on Ubuntu -## v5.0.2 (2014-04-01) +## [5.0.2] - 2014-04-01 - Moving server_deprecated into recipes directory -## v5.0.0 (2014-03-31) +## [5.0.0] - 2014-03-31 - Rewriting as a library cookbook - Exposing mysql_service and mysql_client resources - User now needs to supply configuration - Moving attribute driven recipe to server-deprecated -## v4.1.2 (2014-02-28) +## [4.1.2] - 2014-02-28 - [COOK-4349] - Fix invalid platform check - [COOK-4184] - Better handling of Ubuntu upstart service - [COOK-2100] - Changing innodb_log_file_size tunable results in inability to start MySQL -## v4.1.1 (2014-02-25) +## [4.1.1] - 2014-02-25 - **[COOK-2966] - Address foodcritic failures' - **[COOK-4182] - Template parse failure in /etc/init/mysql.conf (data_dir)' - **[COOK-4198] - Added missing tunable' - **[COOK-4206] - create root@127.0.0.1, as well as root@localhost' -## v4.0.20 (2014-01-18) +## [4.0.20] - 2014-01-18 - [COOK-3931] - MySQL Server Recipe Regression for Non-LTS Ubuntu Versions - [COOK-3945] - MySQL cookbook fails on Ubuntu 13.04/13.10 @@ -452,11 +518,11 @@ Adding Ubuntu 13.04 to Platforminfo - [COOK-4001] - Pull request: Fixes for broken mysql::server on Debian - [COOK-4071] - Mysql cookbook doesn't work on debian 7.2 -## v4.0.14 +## [4.0.14] Fixing style cops -## v4.0.12 +## [4.0.12] ### Bug @@ -466,25 +532,25 @@ Fixing style cops - **[COOK-3801](https://tickets.chef.io/browse/COOK-3801)** - Add innodb_adaptive_flushing_method and innodb_adaptive_checkpoint -## v4.0.10 +## [4.0.10] fixing metadata version error. locking to 3.0 -## v4.0.8 +## [4.0.8] Locking yum dependency to '< 3' -## v4.0.6 +## [4.0.6] -# Bug +### Bug - [COOK-3943] Notifying service restart on grants update -## v4.0.4 +## [4.0.4] [COOK-3952] - Adding 'recursive true' to directory resources -## v4.0.2 +## [4.0.2] ### BUGS @@ -492,7 +558,7 @@ Locking yum dependency to '< 3' - Fixing bug where unprivileged users cannot connect over a local socket. Adding integration test. - Fixing bug in mysql_grants_cmd generation -## v4.0.0 +## [4.0.0] - [COOK-3928] Heavily refactoring for readability. Moving platform implementation into separate recipes - Moving integration tests from minitest to serverspec, removing "improper" tests @@ -503,23 +569,23 @@ Locking yum dependency to '< 3' - [COOK-3807] - Don't use execute[assign-root-password] on Debian and Ubuntu - [COOK-3881] - Fixing /etc being owned by mysql user -## v3.0.12 +## [3.0.12] ### Bug - **[COOK-3752](https://tickets.chef.io/browse/COOK-3752)** - mysql service fails to start in mysql::server recipe -## v3.0.10 +## [3.0.10] - Fix a failed release attempt for v3.0.8 -## v3.0.8 +## [3.0.8] ### Bug - **[COOK-3749](https://tickets.chef.io/browse/COOK-3749)** - Fix a regression with Chef 11-specific features -## v3.0.6 +## [3.0.6] ### Bug @@ -536,7 +602,7 @@ Locking yum dependency to '< 3' - **[COOK-3498](https://tickets.chef.io/browse/COOK-3498)** - Add support for replicate_* variables in my.cnf -## v3.0.4 +## [3.0.4] ### Bug @@ -546,7 +612,7 @@ Locking yum dependency to '< 3' - **[COOK-3134](https://tickets.chef.io/browse/COOK-3134)** - Fix Chef 11 support - **[COOK-2318](https://tickets.chef.io/browse/COOK-2318)** - Remove redundant `if` block around `node.mysql.tunable.log_bin` -## v3.0.2 +## [3.0.2] ### Bug @@ -558,7 +624,7 @@ Locking yum dependency to '< 3' - [COOK-2102]: `innodb_flush_log_at_trx_commit` value is incorrectly set based on CPU count -## v3.0.0 +## [3.0.0] **Note** This is a backwards incompatible version with previous versions of the cookbook. Tickets that introduce incompatibility are COOK-2615 and COOK-2617. @@ -580,11 +646,11 @@ Locking yum dependency to '< 3' - [COOK-2618] - myisam-recover not using attribute value - [COOK-2617] - open-files is a duplicate of open-files-limit -## v2.1.2 +## [2.1.2] - [COOK-2172] - Mysql cookbook duplicates `binlog_format` configuration -## v2.1.0 +## [2.1.0] - [COOK-1669] - Using platform("ubuntu") in default attributes always returns true - [COOK-1694] - Added additional my.cnf fields and reorganized cookbook to avoid race conditions with mysql startup and sql script execution @@ -592,13 +658,13 @@ Locking yum dependency to '< 3' - [COOK-1929] - Update msyql server attributes file because setting attributes without specifying a precedence is deprecated - [COOK-1999] - Add read_only tunable useful for replication slave servers -## v2.0.2 +## [2.0.2] - [COOK-1967] - mysql: trailing comma in server.rb platform family -## v2.0.0 +## [2.0.0] -**Important note for this release** +### Important note for this release Under Chef Solo, you must set the node attributes for the root, debian and repl passwords or the run will completely fail. See COOK-1737 for background on this. @@ -613,9 +679,9 @@ Under Chef Solo, you must set the node attributes for the root, debian and repl - [COOK-1769] - link to database recipe in mysql README goes to old chef/cookbooks repo instead of chef-cookbook organization - [COOK-1963] - use `platform_family` -## v1.3.0 +## [1.3.0] -**Important note for this release** +### Important note for this release This version no longer installs Ruby bindings in the client recipe by default. Use the ruby recipe if you'd like the RubyGem. If you'd like packages from your distribution, use them in your application's specific cookbook/recipe, or modify the client packages attribute. This resolves the following tickets: @@ -637,7 +703,7 @@ The following issues are also addressed in this release. - [COOK-934] - remove deprecated mysql/libraries/database.rb, use the database cookbook instead. - [COOK-1475] - fix restart on config change -## v1.2.6 +## [1.2.6] - [COOK-1113] - Use an attribute to determine if upstart is used - [COOK-1121] - Add support for Windows @@ -645,47 +711,47 @@ The following issues are also addressed in this release. - [COOK-1151] - Fix server_ec2 handling /var/lib/mysql bind mount - [COOK-1321] - Document setting password attributes for solo -## v1.2.4 +## [1.2.4] - [COOK-992] - fix FATAL nameerror - [COOK-827] - `mysql:server_ec2` recipe can't mount `data_dir` - [COOK-945] - FreeBSD support -## v1.2.2 +## [1.2.2] - [COOK-826] mysql::server recipe doesn't quote password string - [COOK-834] Add 'scientific' and 'amazon' platforms to mysql cookbook -## v1.2.1 +## [1.2.1] - [COOK-644] Mysql client cookbook 'package missing' error message is confusing - [COOK-645] RHEL6/CentOS6 - mysql cookbook contains 'skip-federated' directive which is unsupported on MySQL 5.1 -## v1.2.0 +## [1.2.0] - [COOK-684] remove mysql_database LWRP -## v1.0.8 +## [1.0.8] - [COOK-633] ensure "cloud" attribute is available -## v1.0.7 +## [1.0.7] - [COOK-614] expose all mysql tunable settings in config - [COOK-617] bind to private IP if available -## v1.0.6 +## [1.0.6] - [COOK-605] install mysql-client package on ubuntu/debian -## v1.0.5 +## [1.0.5] - [COOK-465] allow optional remote root connections to mysql - [COOK-455] improve platform version handling - externalize conf_dir attribute for easier cross platform support - change datadir attribute to data_dir for consistency -## v1.0.4 +## [1.0.4] - fix regressions on debian platform - [COOK-578] wrap root password in quotes diff --git a/cookbooks/mysql/CONTRIBUTING.md b/cookbooks/mysql/CONTRIBUTING.md index ef2f2b8..a946aea 100644 --- a/cookbooks/mysql/CONTRIBUTING.md +++ b/cookbooks/mysql/CONTRIBUTING.md @@ -1,2 +1,4 @@ +# Contributing + Please refer to -https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD +[https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) diff --git a/cookbooks/mysql/README.md b/cookbooks/mysql/README.md index 63dba0f..adf14cc 100644 --- a/cookbooks/mysql/README.md +++ b/cookbooks/mysql/README.md @@ -1,6 +1,10 @@ # MySQL Cookbook -[![Build Status](https://travis-ci.org/chef-cookbooks/mysql.svg?branch=master)](https://travis-ci.org/chef-cookbooks/mysql) [![Cookbook Version](https://img.shields.io/cookbook/v/mysql.svg)](https://supermarket.chef.io/cookbooks/mysql) +[![Cookbook Version](https://img.shields.io/cookbook/v/mysql.svg)](https://supermarket.chef.io/cookbooks/mysql) +[![Build Status](https://img.shields.io/circleci/project/github/sous-chefs/mysql/master.svg)](https://circleci.com/gh/sous-chefs/mysql) +[![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) +[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) +[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) The MySQL Cookbook is a library cookbook that provides resource primitives (LWRPs) for use in recipes. It is designed to be a reference example for creating highly reusable cross-platform cookbooks. @@ -8,6 +12,10 @@ The MySQL Cookbook is a library cookbook that provides resource primitives (LWRP This cookbook is concerned with the "MySQL Community Server", particularly those shipped with F/OSS Unix and Linux distributions. It does not address forks or value-added repackaged MySQL distributions like MariaDB or Percona. +## Maintainers + +This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF). + ## Requirements - Chef 12.7 or higher @@ -18,27 +26,15 @@ This cookbook is concerned with the "MySQL Community Server", particularly those The following platforms have been tested with Test Kitchen: -``` -|----------------+-----+-----+-----+-----| -| | 5.1 | 5.5 | 5.6 | 5.7 | -|----------------+-----+-----+-----+-----| -| debian-7 | | X | | | -|----------------+-----+-----+-----+-----| +| OS | 5.1 | 5.5 | 5.6 | 5.7 | +|----------------|-----|-----|-----|-----| | debian-8 | | X | | | -|----------------+-----+-----+-----+-----| | ubuntu-14.04 | | X | X | | -|----------------+-----+-----+-----+-----| | ubuntu-16.04 | | | | X | -|----------------+-----+-----+-----+-----| | centos-6 | X | X | X | X | -|----------------+-----+-----+-----+-----| | centos-7 | | X | X | X | -|----------------+-----+-----+-----+-----| | fedora | | | X | X | -|----------------+-----+-----+-----+-----| | openSUSE Leap | | | X | | -|----------------+-----+-----+-----+-----| -``` ## Cookbook Dependencies @@ -65,9 +61,11 @@ end The service name on the OS is `mysql-foo`. You can manually start and stop it with `service mysql-foo start` and `service mysql-foo stop`. +If you use `default` as the name the service name will be `mysql` instead of `mysql-default`. + The configuration file is at `/etc/mysql-foo/my.cnf`. It contains the minimum options to get the service running. It looks like this. -``` +```toml # Chef generated my.cnf for instance mysql-foo [client] @@ -104,12 +102,13 @@ end mysql_config 'foo' do source 'my_extra_settings.erb' + instance 'foo' notifies :restart, 'mysql_service[foo]' action :create end ``` -You are responsible for providing `my_extra_settings.erb` in your own cookbook's templates folder. +You are responsible for providing `my_extra_settings.erb` in your own cookbook's templates folder. The name of the mysql service instance must be provided in mysql config as this defaults to 'default'. ## Connecting with the mysql CLI command @@ -156,7 +155,6 @@ Please note that when using `notifies` or `subscribes`, the resource to referenc - `error_log` - Tunable location of the error_log - `initial_root_password` - allows the user to specify the initial root password for mysql when initializing new databases. This can be set explicitly in a recipe, driven from a node attribute, or from data_bags. When omitted, it defaults to `ilikerandompasswords`. Please be sure to change it. - `instance` - A string to identify the MySQL service. By convention, to allow for multiple instances of the `mysql_service`, directories and files on disk are named `mysql-`. Defaults to the resource name. -- `package_action` - Defaults to `:install`. - `package_name` - Defaults to a value looked up in an internal map. - `package_version` - Specific version of the package to install,passed onto the underlying package manager. Defaults to `nil`. - `bind_address` - determines the listen IP address for the mysqld service. When omitted, it will be determined by MySQL. If the address is "regular" IPv4/IPv6address (e.g 127.0.0.1 or ::1), the server accepts TCP/IP connections only for that particular address. If the address is "0.0.0.0" (IPv4) or "::" (IPv6), the server accepts TCP/IP connections on all IPv4 or IPv6 interfaces. @@ -166,17 +164,17 @@ Please note that when using `notifies` or `subscribes`, the resource to referenc - `run_user` - The name of the system user the `mysql_service` should run as. Defaults to 'mysql'. - `pid_file` - Tunable location of the pid file. - `socket` - determines where to write the socket file for the `mysql_service` instance. Useful when configuring clients on the same machine to talk over socket and skip the networking stack. Defaults to a calculated value based on platform and instance name. -- `tmp_dir` - Tunable location of the tmp_dir +- `tmp_dir` - Tunable location of the tmp_dir. - `version` - allows the user to select from the versions available for the platform, where applicable. When omitted, it will install the default MySQL version for the target platform. Available version numbers are `5.0`, `5.1`, `5.5`, `5.6`, and `5.7`, depending on platform. #### Actions - `:create` - Configures everything but the underlying operating system service. - `:delete` - Removes everything but the package and data_dir. -- `:start` - Starts the underlying operating system service -- `:stop`- Stops the underlying operating system service -- `:restart` - Restarts the underlying operating system service -- `:reload` - Reloads the underlying operating system service +- `:start` - Starts the underlying operating system service. +- `:stop`- Stops the underlying operating system service. +- `:restart` - Restarts the underlying operating system service. +- `:reload` - Reloads the underlying operating system service. #### Providers @@ -353,7 +351,7 @@ Use multiple `mysql_service` instances to test a replication setup. This particu ## Frequently Asked Questions -### How do I run this behind my firewall? +### How do I run this behind my firewall On Linux, the `mysql_service` resource uses the platform's underlying package manager to install software. For this to work behind firewalls, you'll need to either: @@ -395,30 +393,35 @@ Or to connect over the network, use something like this: connect over the networ These network or socket ssettings can also be put in you $HOME/.my.cnf, if preferred. -### What about MariaDB, Percona, etc. +### What about MariaDB, Percona, etc MySQL forks are purposefully out of scope for this cookbook. This is mostly to reduce the testing matrix to a manageable size. Cookbooks for these technologies can easily be created by copying and adapting this cookbook. However, there will be differences. Package repository locations, package version names, software major version numbers, supported platform matrices, and the availability of software such as XtraDB and Galera are the main reasons that creating multiple cookbooks to make sense. -## Maintainers +There are existing cookbooks to carter for these forks, check them out on the supermarket -This cookbook is maintained by Chef's Community Cookbook Engineering team. Our goal is to improve cookbook quality and to aid the community in contributing to cookbooks. To learn more about our team, process, and design goals see our [team documentation](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/COOKBOOK_TEAM.MD). To learn more about contributing to cookbooks like this see our [contributing documentation](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD), or if you have general questions about this cookbook come chat with us in #cookbok-engineering on the [Chef Community Slack](http://community-slack.chef.io/) +## Contributors -## License +This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) -```text -Copyright:: 2009-2017 Chef Software, Inc +### Backers -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at +Thank you to all our backers! - http://www.apache.org/licenses/LICENSE-2.0 +![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -``` +### Sponsors + +Support this project by becoming a sponsor. Your logo will show up here with a link to your website. + +![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) diff --git a/cookbooks/mysql/libraries/helpers.rb b/cookbooks/mysql/libraries/helpers.rb index e60d21d..ac2340b 100644 --- a/cookbooks/mysql/libraries/helpers.rb +++ b/cookbooks/mysql/libraries/helpers.rb @@ -12,8 +12,13 @@ module MysqlCookbook false end - def wheezy? - return true if node['platform'] == 'debian' && node['platform_version'].to_i == 7 + def fedora? + return true if node['platform_family'] == 'fedora' + false + end + + def suse? + return true if node['platform_family'] == 'suse' false end @@ -38,14 +43,19 @@ module MysqlCookbook false end + def bionic? + return true if node['platform'] == 'ubuntu' && node['platform_version'] == '18.04' + false + end + def defaults_file "#{etc_dir}/my.cnf" end def default_data_dir return "/var/lib/#{mysql_name}" if node['os'] == 'linux' - return "/opt/local/lib/#{mysql_name}" if node['os'] == 'solaris2' - return "/var/db/#{mysql_name}" if node['os'] == 'freebsd' + return "/opt/local/lib/#{mysql_name}" if platform_family?('solaris2') + return "/var/db/#{mysql_name}" if platform_family?('freebsd') end def default_error_log @@ -58,22 +68,22 @@ module MysqlCookbook def default_major_version # rhelish - return '5.1' if el6? + return '5.6' if el6? return '5.6' if el7? return '5.6' if node['platform'] == 'amazon' # debian - return '5.5' if wheezy? return '5.5' if jessie? # ubuntu return '5.5' if trusty? return '5.7' if xenial? + return '5.7' if bionic? # misc return '5.6' if node['platform'] == 'freebsd' - return '5.6' if node['platform'] == 'fedora' - return '5.6' if node['platform_family'] == 'suse' + return '5.7' if fedora? + return '5.6' if suse? end def major_from_full(v) @@ -81,7 +91,11 @@ module MysqlCookbook end def mysql_name - "mysql-#{instance}" + if instance == 'default' + 'mysql' + else + "mysql-#{instance}" + end end def default_socket_file @@ -89,20 +103,23 @@ module MysqlCookbook end def default_client_package_name - return ['mysql', 'mysql-devel'] if major_version == '5.1' && el6? + return %w(mysql mysql-devel) if major_version == '5.1' && el6? + return %w(mysql mysql-devel) if el7? return ['mysql55', 'mysql55-devel.x86_64'] if major_version == '5.5' && node['platform'] == 'amazon' return ['mysql56', 'mysql56-devel.x86_64'] if major_version == '5.6' && node['platform'] == 'amazon' + return ['mysql57', 'mysql57-devel.x86_64'] if major_version == '5.7' && node['platform'] == 'amazon' return ['mysql-client-5.5', 'libmysqlclient-dev'] if major_version == '5.5' && node['platform_family'] == 'debian' return ['mysql-client-5.6', 'libmysqlclient-dev'] if major_version == '5.6' && node['platform_family'] == 'debian' return ['mysql-client-5.7', 'libmysqlclient-dev'] if major_version == '5.7' && node['platform_family'] == 'debian' return 'mysql-community-server-client' if major_version == '5.6' && node['platform_family'] == 'suse' - ['mysql-community-client', 'mysql-community-devel'] + %w(mysql-community-client mysql-community-devel) end def default_server_package_name return 'mysql-server' if major_version == '5.1' && el6? return 'mysql55-server' if major_version == '5.5' && node['platform'] == 'amazon' return 'mysql56-server' if major_version == '5.6' && node['platform'] == 'amazon' + return 'mysql57-server' if major_version == '5.7' && node['platform'] == 'amazon' return 'mysql-server-5.5' if major_version == '5.5' && node['platform_family'] == 'debian' return 'mysql-server-5.6' if major_version == '5.6' && node['platform_family'] == 'debian' return 'mysql-server-5.7' if major_version == '5.7' && node['platform_family'] == 'debian' @@ -189,7 +206,6 @@ module MysqlCookbook set -e rm -rf /tmp/#{mysql_name} mkdir /tmp/#{mysql_name} - cat > /tmp/#{mysql_name}/my.sql <<-'EOSQL' UPDATE mysql.user SET #{password_column_name}=PASSWORD('#{sql_escaped_password}')#{password_expired} WHERE user = 'root'; DELETE FROM mysql.user WHERE USER LIKE ''; @@ -198,15 +214,24 @@ FLUSH PRIVILEGES; DELETE FROM mysql.db WHERE db LIKE 'test%'; DROP DATABASE IF EXISTS test ; EOSQL - #{db_init} #{record_init} - while [ ! -f #{pid_file} ] ; do sleep 1 ; done kill `cat #{pid_file}` while [ -f #{pid_file} ] ; do sleep 1 ; done rm -rf /tmp/#{mysql_name} - EOS + EOS + end + + def wait_for_init + cmd = <<-EOS + while [ ! -f #{pid_file} ] ; do sleep 1 ; done + kill `cat #{pid_file}` + while [ -f #{pid_file} ] ; do sleep 1 ; done + rm -rf /tmp/#{mysql_name} + EOS + cmd = '' if v57plus + cmd end def password_column_name @@ -256,12 +281,26 @@ EOSQL def mysqld_bin return "#{prefix_dir}/libexec/mysqld" if node['platform_family'] == 'smartos' return "#{base_dir}/bin/mysqld" if node['platform_family'] == 'omnios' - return '/usr/sbin/mysqld' if node['platform_family'] == 'fedora' && v56plus - return '/usr/libexec/mysqld' if node['platform_family'] == 'fedora' + return '/usr/sbin/mysqld' if fedora? && v56plus + return '/usr/libexec/mysqld' if fedora? return 'mysqld' if scl_package? "#{prefix_dir}/usr/sbin/mysqld" end + def mysql_systemd_start_pre + return '/usr/bin/mysqld_pre_systemd' if v57plus && (el7? || fedora?) + return '/usr/bin/mysql-systemd-start pre' if node['platform_family'] == 'rhel' + return '/usr/lib/mysql/mysql-systemd-helper install' if suse? + '/usr/share/mysql/mysql-systemd-start pre' + end + + def mysql_systemd + return "/usr/libexec/#{mysql_name}-wait-ready $MAINPID" if v57plus && (el7? || fedora?) + return '/usr/bin/mysql-systemd-start' if node['platform_family'] == 'rhel' + return '/usr/share/mysql/mysql-systemd-start' if v57plus + "/usr/libexec/#{mysql_name}-wait-ready $MAINPID" + end + def mysqld_initialize_cmd cmd = mysqld_bin cmd << " --defaults-file=#{etc_dir}/my.cnf" diff --git a/cookbooks/mysql/libraries/matchers.rb b/cookbooks/mysql/libraries/matchers.rb deleted file mode 100644 index adf5e73..0000000 --- a/cookbooks/mysql/libraries/matchers.rb +++ /dev/null @@ -1,71 +0,0 @@ -if defined?(ChefSpec) - ChefSpec.define_matcher :mysql_config - ChefSpec.define_matcher :mysql_service - ChefSpec.define_matcher :mysql_client - - # mysql_client_client_installation_package - def install_mysql_client_installation_package(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_client_installation_package, :create, resource_name) - end - - def remove_mysql_client_installation_package(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_client_installation_package, :remove, resource_name) - end - - # mysql_server_server_installation_package - def install_mysql_server_installation_package(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_server_installation_package, :install, resource_name) - end - - def remove_mysql_server_installation_package(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_server_installation_package, :remove, resource_name) - end - - ##### - # old - ##### - - # client - def create_mysql_client(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_client, :create, resource_name) - end - - def delete_mysql_client(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_client, :delete, resource_name) - end - - # mysql_config - def create_mysql_config(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_config, :create, resource_name) - end - - def delete_mysql_config(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_config, :delete, resource_name) - end - - # service - def create_mysql_service(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :create, resource_name) - end - - def delete_mysql_service(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :delete, resource_name) - end - - def start_mysql_service(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :start, resource_name) - end - - def stop_mysql_service(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :stop, resource_name) - end - - def restart_mysql_service(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :restart, resource_name) - end - - def reload_mysql_service(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :reload, resource_name) - end - -end diff --git a/cookbooks/mysql/libraries/mysql_base.rb b/cookbooks/mysql/libraries/mysql_base.rb index 2db0c16..0e1d675 100644 --- a/cookbooks/mysql/libraries/mysql_base.rb +++ b/cookbooks/mysql/libraries/mysql_base.rb @@ -3,9 +3,6 @@ module MysqlCookbook require_relative 'helpers' # All resources are composites - def whyrun_supported? - true - end ################ # Type Constants diff --git a/cookbooks/mysql/libraries/mysql_client_installation_package.rb b/cookbooks/mysql/libraries/mysql_client_installation_package.rb index 1dc87f5..9da3cfa 100644 --- a/cookbooks/mysql/libraries/mysql_client_installation_package.rb +++ b/cookbooks/mysql/libraries/mysql_client_installation_package.rb @@ -4,14 +4,15 @@ module MysqlCookbook require_relative 'helpers' include MysqlCookbook::HelpersBase - # Resource properties + # Resource:: properties resource_name :mysql_client_installation_package + provides :mysql_client_installation_package provides :mysql_client_installation, os: 'linux' provides :mysql_client, os: 'linux' property :package_name, [String, Array], default: lazy { default_client_package_name }, desired_state: false property :package_options, [String, nil], desired_state: false - property :package_version, [String, nil], default: nil, desired_state: false + property :package_version, [String, nil], desired_state: false # Actions action :create do diff --git a/cookbooks/mysql/libraries/mysql_config.rb b/cookbooks/mysql/libraries/mysql_config.rb index d4a52c9..27409fe 100644 --- a/cookbooks/mysql/libraries/mysql_config.rb +++ b/cookbooks/mysql/libraries/mysql_config.rb @@ -1,6 +1,7 @@ module MysqlCookbook class MysqlConfig < MysqlBase resource_name :mysql_config + provides :mysql_config property :config_name, String, name_property: true, desired_state: false property :cookbook, String, desired_state: false @@ -14,8 +15,6 @@ module MysqlCookbook require_relative 'helpers' include MysqlCookbook::HelpersBase - provides :mysql_config - action :create do # hax because group property g = Chef::Resource::Group.new(new_resource.group, run_context) diff --git a/cookbooks/mysql/libraries/mysql_server_installation_package.rb b/cookbooks/mysql/libraries/mysql_server_installation_package.rb index bf46c8d..86791cf 100644 --- a/cookbooks/mysql/libraries/mysql_server_installation_package.rb +++ b/cookbooks/mysql/libraries/mysql_server_installation_package.rb @@ -1,12 +1,13 @@ module MysqlCookbook class MysqlServerInstallationPackage < MysqlBase - # Resource properties + # Resource:: properties resource_name :mysql_server_installation_package + provides :mysql_server_installation_package provides :mysql_server_installation, os: 'linux' property :package_name, String, default: lazy { default_server_package_name }, desired_state: false property :package_options, [String, nil], desired_state: false - property :package_version, [String, nil], default: nil, desired_state: false + property :package_version, [String, nil], desired_state: false # helper methods require_relative 'helpers' diff --git a/cookbooks/mysql/libraries/mysql_service.rb b/cookbooks/mysql/libraries/mysql_service.rb index aa969bd..2880ab3 100644 --- a/cookbooks/mysql/libraries/mysql_service.rb +++ b/cookbooks/mysql/libraries/mysql_service.rb @@ -2,9 +2,10 @@ module MysqlCookbook require_relative 'mysql_service_base' class MysqlService < MysqlServiceBase resource_name :mysql_service + provides :mysql_service # installation type and service_manager - property :install_method, %w(package auto), default: 'auto', desired_state: false + property :install_method, %w(package auto none), default: 'auto', desired_state: false property :service_manager, %w(sysvinit upstart systemd auto), default: 'auto', desired_state: false # mysql_server_installation @@ -12,7 +13,7 @@ module MysqlCookbook property :major_version, String, default: lazy { major_from_full(version) }, desired_state: false property :package_name, String, default: lazy { default_package_name }, desired_state: false property :package_options, [String, nil], desired_state: false - property :package_version, [String, nil], default: nil, desired_state: false + property :package_version, [String, nil], desired_state: false ################ # Helper Methods diff --git a/cookbooks/mysql/libraries/mysql_service_base.rb b/cookbooks/mysql/libraries/mysql_service_base.rb index a03b5aa..1e22d7e 100644 --- a/cookbooks/mysql/libraries/mysql_service_base.rb +++ b/cookbooks/mysql/libraries/mysql_service_base.rb @@ -41,6 +41,7 @@ module MysqlCookbook # setting up multiple services. file "#{prefix_dir}/etc/mysql/my.cnf" do action :delete + not_if { node['init_package'] == 'systemd' } end file "#{prefix_dir}/etc/my.cnf" do @@ -55,20 +56,14 @@ module MysqlCookbook end # Support directories - directory etc_dir do - owner new_resource.run_user - group new_resource.run_group - mode '0750' - recursive true - action :create - end - - directory new_resource.include_dir do - owner new_resource.run_user - group new_resource.run_group - mode '0750' - recursive true - action :create + [etc_dir, new_resource.include_dir, log_dir, new_resource.data_dir].each do |dir| + directory dir do + owner new_resource.run_user + group new_resource.run_group + mode '0750' + recursive true + action :create + end end directory run_dir do @@ -79,22 +74,6 @@ module MysqlCookbook action :create end - directory log_dir do - owner new_resource.run_user - group new_resource.run_group - mode '0750' - recursive true - action :create - end - - directory new_resource.data_dir do - owner new_resource.run_user - group new_resource.run_group - mode '0750' - recursive true - action :create - end - # Main configuration file template "#{etc_dir}/my.cnf" do source 'my.cnf.erb' @@ -171,7 +150,7 @@ module MysqlCookbook template '/etc/apparmor.d/usr.sbin.mysqld' do cookbook 'mysql' - source 'apparmor/usr.sbin.mysqld.erb' + source "apparmor/#{node['platform']}-#{node['platform_version']}/usr.sbin.mysqld.erb" owner 'root' group 'root' mode '0644' diff --git a/cookbooks/mysql/libraries/mysql_service_manager_systemd.rb b/cookbooks/mysql/libraries/mysql_service_manager_systemd.rb index 5c6880a..acf46f1 100644 --- a/cookbooks/mysql/libraries/mysql_service_manager_systemd.rb +++ b/cookbooks/mysql/libraries/mysql_service_manager_systemd.rb @@ -1,6 +1,7 @@ module MysqlCookbook class MysqlServiceManagerSystemd < MysqlServiceBase resource_name :mysql_service_manager_systemd + provides :mysql_service_manager_systemd provides :mysql_service_manager, os: 'linux' do |_node| Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) @@ -48,7 +49,9 @@ module MysqlCookbook config: new_resource, etc_dir: etc_dir, base_dir: base_dir, - mysqld_bin: mysqld_bin + mysqld_bin: mysqld_bin, + mysql_systemd_start_pre: mysql_systemd_start_pre, + mysql_systemd: mysql_systemd ) cookbook 'mysql' notifies :run, "execute[#{new_resource.instance} systemctl daemon-reload]", :immediately diff --git a/cookbooks/mysql/libraries/mysql_service_manager_sysvinit.rb b/cookbooks/mysql/libraries/mysql_service_manager_sysvinit.rb index 5608dec..563ab77 100644 --- a/cookbooks/mysql/libraries/mysql_service_manager_sysvinit.rb +++ b/cookbooks/mysql/libraries/mysql_service_manager_sysvinit.rb @@ -1,6 +1,7 @@ module MysqlCookbook class MysqlServiceManagerSysvinit < MysqlServiceBase resource_name :mysql_service_manager_sysvinit + provides :mysql_service_manager_sysvinit provides :mysql_service_manager, os: 'linux' diff --git a/cookbooks/mysql/libraries/mysql_service_manager_upstart.rb b/cookbooks/mysql/libraries/mysql_service_manager_upstart.rb index f8f28c2..f547e35 100644 --- a/cookbooks/mysql/libraries/mysql_service_manager_upstart.rb +++ b/cookbooks/mysql/libraries/mysql_service_manager_upstart.rb @@ -1,6 +1,7 @@ module MysqlCookbook class MysqlServiceManagerUpstart < MysqlServiceBase resource_name :mysql_service_manager_upstart + provides :mysql_service_manager_upstart provides :mysql_service_manager, platform_family: 'debian' do |_node| Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) && diff --git a/cookbooks/mysql/metadata.json b/cookbooks/mysql/metadata.json index f847f3b..e78d557 100644 --- a/cookbooks/mysql/metadata.json +++ b/cookbooks/mysql/metadata.json @@ -1 +1 @@ -{"name":"mysql","version":"8.5.1","description":"Provides mysql_service, mysql_config, and mysql_client resources","long_description":"","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache-2.0","platforms":{"redhat":">= 6.0","centos":">= 6.0","scientific":">= 6.0","oracle":">= 6.0","amazon":">= 0.0.0","fedora":">= 0.0.0","debian":">= 7.0","ubuntu":">= 12.04","opensuse":">= 13.0","opensuseleap":">= 0.0.0","suse":">= 12.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chef-cookbooks/mysql","issues_url":"https://github.com/chef-cookbooks/mysql/issues","chef_version":[[">= 12.7"]],"ohai_version":[]} \ No newline at end of file +{"name":"mysql","version":"8.7.3","description":"Provides mysql_service, mysql_config, and mysql_client resources","long_description":"","maintainer":"Sous Chefs","maintainer_email":"help@sous-chefs.org","license":"Apache-2.0","platforms":{"redhat":">= 6.0","centos":">= 6.0","scientific":">= 6.0","oracle":">= 6.0","amazon":">= 0.0.0","fedora":">= 0.0.0","debian":">= 7.0","ubuntu":">= 14.04","opensuseleap":">= 0.0.0","suse":">= 12.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/sous-chefs/mysql","issues_url":"https://github.com/sous-chefs/mysql/issues","chef_version":[[">= 12.7"]],"ohai_version":[]} \ No newline at end of file diff --git a/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld-instance.erb b/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld-instance.erb index 130beb7..e3bbb05 100644 --- a/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld-instance.erb +++ b/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld-instance.erb @@ -11,4 +11,5 @@ <%= @config.socket_file %> rw, /tmp/<%= @mysql_name %>/ r, /tmp/<%= @mysql_name %>/my.sql r, +<%= @config.tmp_dir %>/ rw, <%= @config.tmp_dir %>/* rw, diff --git a/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld.erb b/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld.erb deleted file mode 100644 index 19ddbf5..0000000 --- a/cookbooks/mysql/templates/default/apparmor/usr.sbin.mysqld.erb +++ /dev/null @@ -1,47 +0,0 @@ -# vim:syntax=apparmor -# Last Modified: Tue Jun 19 17:37:30 2007 -#include - -/usr/sbin/mysqld { - #include - #include - #include - #include - #include - - capability dac_override, - capability sys_resource, - capability setgid, - capability setuid, - - network tcp, - - /etc/hosts.allow r, - /etc/hosts.deny r, - - /etc/mysql/*.pem r, - /etc/mysql/conf.d/ r, - /etc/mysql/conf.d/* r, - /etc/mysql/*.cnf r, - /usr/lib/mysql/plugin/ r, - /usr/lib/mysql/plugin/*.so* mr, - /usr/sbin/mysqld mr, - /usr/share/mysql/** r, - /var/log/mysql.log rw, - /var/log/mysql.err rw, - /var/lib/mysql/ r, - /var/lib/mysql/** rwk, - /var/log/mysql/ r, - /var/log/mysql/* rw, - /var/run/mysqld/mysqld.pid rw, - /var/run/mysqld/mysqld.sock w, - /var/run/mysqld/mysqld.sock.lock rw, - /run/mysqld/mysqld.pid rw, - /run/mysqld/mysqld.sock w, - /run/mysqld/mysqld.sock.lock rw, - - /sys/devices/system/cpu/ r, - - # Site-specific additions and overrides. See local/README for details. - #include -} diff --git a/cookbooks/mysql/templates/default/systemd/mysqld.service.erb b/cookbooks/mysql/templates/default/systemd/mysqld.service.erb index f1fb6c1..1a5cd41 100644 --- a/cookbooks/mysql/templates/default/systemd/mysqld.service.erb +++ b/cookbooks/mysql/templates/default/systemd/mysqld.service.erb @@ -7,10 +7,15 @@ After=network.target Type=simple User=<%= @config.run_user %> Group=<%= @config.run_group %> +PermissionsStartOnly=true +ExecStartPre=<%= @mysql_systemd_start_pre %> + ExecStart=<%= @mysqld_bin %> --defaults-file=<%= @etc_dir %>/my.cnf --basedir=<%= @base_dir %> -ExecStartPost=/usr/libexec/mysql-<%= @config.instance %>-wait-ready $MAINPID +ExecStartPost=<%= @mysql_systemd %> TimeoutSec=300 -PrivateTmp=true +Restart=on-failure +RuntimeDirectory=mysqld +RuntimeDirectoryMode=755 [Install] WantedBy=multi-user.target diff --git a/cookbooks/php-fpm/.foodcritic b/cookbooks/php-fpm/.foodcritic deleted file mode 100644 index 55a27da..0000000 --- a/cookbooks/php-fpm/.foodcritic +++ /dev/null @@ -1 +0,0 @@ -~FC015 diff --git a/cookbooks/php-fpm/README.md b/cookbooks/php-fpm/README.md deleted file mode 100644 index a503473..0000000 --- a/cookbooks/php-fpm/README.md +++ /dev/null @@ -1,142 +0,0 @@ -[![Build Status](https://travis-ci.org/yevgenko/cookbook-php-fpm.svg?branch=master)](https://travis-ci.org/yevgenko/cookbook-php-fpm) - -# Description - -Installs and configures PHP-FPM (FastCGI Process Manager), an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. It's like the `unicorn` of the PHP world dawg. - -# Requirements - -## Platform - -- Debian, Ubuntu -- CentOS, Red Hat, Fedora -- Amazon Linux - -## Cookbooks - -- none - -## Chef - -- 12.14 or later - -# Description - -Creates a PHP-FPM configuration file at the path specified. Meant to be deployed with a service init scheme/supervisor such as runit. Please see the `application::php-fpm` recipe for a complete working example. In depth information about PHP-FPM's configuration values can be [found in the PHP-FPM documentation](http://php.net/manual/en/install.fpm.configuration.php). - -# Usage - -Simply include the recipe where you want PHP-FPM installed. Default pool **www** will be created. To disable pool creation set default['php-fpm']['pools'] to false. - -To customize settings and pools you can override default attributes. - -## Usage in roles: - -```ruby -name "php-fpm" -description "php fpm role" -run_list "recipe[php-fpm]" -override_attributes "php-fpm" => { - "pools" => { - "default" => { - :enable => true - }, - "www" => { - :enable => "true", - :cookbook => "another-cookbook", - :process_manager => "dynamic", - :max_requests => 5000, - :php_options => { 'php_admin_flag[log_errors]' => 'on', 'php_admin_value[memory_limit]' => '32M' } - } - } -} -``` - -# Creating pools in recipes - -## Create PHP-FPM pool named 'www' with default settings: - -```ruby -php_fpm_pool "www" -``` - -## Create PHP-FPM pool named 'www' with custom settings: - -```ruby -php_fpm_pool "www" do - cookbook "another-cookbook" # get template from another cookbook - process_manager "dynamic" - max_requests 5000 - php_options 'php_admin_flag[log_errors]' => 'on', 'php_admin_value[memory_limit]' => '32M' -end -``` - -## Delete PHP-FPM pool named 'www': - -```ruby -php_fpm_pool "www" do - enable false -end -``` - -# Development - -## Requirements - -- [Docker](https://www.docker.com/) - -## Setup - -To get all dependencies: - -``` -bundle install -``` - -## Test - -To see available platforms: - -``` -bundle exec rake -T -``` - -To test particular platform: - -``` -bundle exec rake kitchen:default-ubuntu-1604 -``` - -To test all platforms: - -``` -bundle exec rake kitchen:all -``` - -## Publishing (maintainers only!) - -Bump version in metadata.rb, commit and push to master! - -``` -bundle exec rake publish -``` - -as a result new tag will be created and pushed to github as well as new version will be published on - -# Contributing - -Please do not bump version when proposing a change, no other rules ;) - -# License and Author - -Author:: Seth Chisamore ([schisamo@chef.io](mailto:schisamo@chef.io)) - -Copyright:: 2011-2017, Chef Software, Inc - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - -``` -http://www.apache.org/licenses/LICENSE-2.0 -``` - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/cookbooks/php-fpm/attributes/default.rb b/cookbooks/php-fpm/attributes/default.rb deleted file mode 100644 index e77c7ed..0000000 --- a/cookbooks/php-fpm/attributes/default.rb +++ /dev/null @@ -1,71 +0,0 @@ -case node['platform_family'] -when 'rhel', 'fedora' - user = 'apache' - group = 'apache' - conf_dir = '/etc/php.d' - pool_conf_dir = '/etc/php-fpm.d' - conf_file = '/etc/php-fpm.conf' - error_log = '/var/log/php-fpm/error.log' - pid = '/var/run/php-fpm/php-fpm.pid' -else - user = 'www-data' - group = 'www-data' - if platform?('ubuntu') && node['platform_version'].to_f >= 16.04 - php_conf_dir = '/etc/php/7.0' - php_fpm_name = 'php7.0-fpm' - else - php_conf_dir = '/etc/php5' - php_fpm_name = 'php5-fpm' - end - conf_dir = "#{php_conf_dir}/fpm/conf.d" - pool_conf_dir = "#{php_conf_dir}/fpm/pool.d" - conf_file = "#{php_conf_dir}/fpm/php-fpm.conf" - error_log = "/var/log/#{php_fpm_name}.log" - pid = "/var/run/#{php_fpm_name}.pid" -end - -default['php-fpm']['user'] = user -default['php-fpm']['group'] = group -default['php-fpm']['conf_dir'] = conf_dir -default['php-fpm']['pool_conf_dir'] = pool_conf_dir -default['php-fpm']['conf_file'] = conf_file -default['php-fpm']['pid'] = pid -default['php-fpm']['log_dir'] = '/var/log/php-fpm' -default['php-fpm']['error_log'] = error_log -default['php-fpm']['log_level'] = 'notice' -default['php-fpm']['emergency_restart_threshold'] = 0 -default['php-fpm']['emergency_restart_interval'] = 0 -default['php-fpm']['process_control_timeout'] = 0 -default['php-fpm']['process_manager'] = 'ondemand' -default['php-fpm']['max_children'] = 50 -default['php-fpm']['start_servers'] = 5 -default['php-fpm']['min_spare_servers'] = 5 -default['php-fpm']['max_spare_servers'] = 35 -default['php-fpm']['max_requests'] = 0 -default['php-fpm']['request_terminate_timeout'] = 0 -default['php-fpm']['catch_workers_output'] = 'no' -default['php-fpm']['security_limit_extensions'] = '.php' -default['php-fpm']['listen_mode'] = '0660' -default['php-fpm']['listen'] = '/var/run/php-fpm-%{pool_name}.sock' - -default['php-fpm']['pools'] = { - 'www' => { - enable: true, - }, -} - -default['php-fpm']['skip_repository_install'] = false -default['php-fpm']['installation_action'] = :install -default['php-fpm']['version'] = nil - -case node['platform_family'] -when 'rhel' - default['php-fpm']['yum_url'] = 'http://rpms.famillecollet.com/enterprise/$releasever/remi/$basearch/' - default['php-fpm']['yum_mirrorlist'] = 'http://rpms.famillecollet.com/enterprise/$releasever/remi/mirror' -when 'fedora' - default['php-fpm']['skip_repository_install'] = true -end - -default['php-fpm']['dotdeb_repository']['uri'] = 'http://packages.dotdeb.org' -default['php-fpm']['dotdeb_repository']['key'] = 'http://www.dotdeb.org/dotdeb.gpg' -default['php-fpm']['dotdeb-php53_repository']['uri'] = 'http://php53.dotdeb.org' diff --git a/cookbooks/php-fpm/definitions/php_fpm_pool.rb b/cookbooks/php-fpm/definitions/php_fpm_pool.rb deleted file mode 100644 index 12fc383..0000000 --- a/cookbooks/php-fpm/definitions/php_fpm_pool.rb +++ /dev/null @@ -1,65 +0,0 @@ -# -# Cookbook Name:: php-fpm -# Definition:: php_fpm_pool -# -# Copyright 2008-2017, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -define :php_fpm_pool, template: 'pool.conf.erb', enable: true do - pool_name = params[:name] - - conf_file = "#{node['php-fpm']['pool_conf_dir']}/#{pool_name}.conf" - - if params[:enable] - template conf_file do - only_if "test -d #{node['php-fpm']['pool_conf_dir']} || mkdir -p #{node['php-fpm']['pool_conf_dir']}" - source params[:template] - owner 'root' - group 'root' - mode '0644' - cookbook params[:cookbook] || 'php-fpm' - variables( - pool_name: pool_name, - listen: params[:listen] || node['php-fpm']['listen'].gsub(/%{pool_name}/, pool_name), - listen_owner: params[:listen_owner] || node['php-fpm']['listen_owner'] || node['php-fpm']['user'], - listen_group: params[:listen_group] || node['php-fpm']['listen_group'] || node['php-fpm']['group'], - listen_mode: params[:listen_mode] || node['php-fpm']['listen_mode'], - allowed_clients: params[:allowed_clients], - user: params[:user] || node['php-fpm']['user'], - group: params[:group] || node['php-fpm']['group'], - process_manager: params[:process_manager] || node['php-fpm']['process_manager'], - max_children: params[:max_children] || node['php-fpm']['max_children'], - start_servers: params[:start_servers] || node['php-fpm']['start_servers'], - min_spare_servers: params[:min_spare_servers] || node['php-fpm']['min_spare_servers'], - max_spare_servers: params[:max_spare_servers] || node['php-fpm']['max_spare_servers'], - max_requests: params[:max_requests] || node['php-fpm']['max_requests'], - catch_workers_output: params[:catch_workers_output] || node['php-fpm']['catch_workers_output'], - security_limit_extensions: params[:security_limit_extensions] || node['php-fpm']['security_limit_extensions'], - access_log: params[:access_log] || false, - slowlog: params[:slowlog] || false, - request_slowlog_timeout: params[:request_slowlog_timeout] || false, - php_options: params[:php_options] || {}, - request_terminate_timeout: params[:request_terminate_timeout] || node['php-fpm']['request_terminate_timeout'], - params: params - ) - notifies :restart, 'service[php-fpm]' - end - else - cookbook_file conf_file do - action :delete - notifies :restart, 'service[php-fpm]' - end - end -end diff --git a/cookbooks/php-fpm/metadata.json b/cookbooks/php-fpm/metadata.json deleted file mode 100644 index 5fc4dbe..0000000 --- a/cookbooks/php-fpm/metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"php-fpm","version":"0.8.0","description":"Installs/Configures php-fpm","long_description":"[![Build Status](https://travis-ci.org/yevgenko/cookbook-php-fpm.svg?branch=master)](https://travis-ci.org/yevgenko/cookbook-php-fpm)\n\n# Description\n\nInstalls and configures PHP-FPM (FastCGI Process Manager), an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. It's like the `unicorn` of the PHP world dawg.\n\n# Requirements\n\n## Platform\n\n- Debian, Ubuntu\n- CentOS, Red Hat, Fedora\n- Amazon Linux\n\n## Cookbooks\n\n- none\n\n## Chef\n\n- 12.14 or later\n\n# Description\n\nCreates a PHP-FPM configuration file at the path specified. Meant to be deployed with a service init scheme/supervisor such as runit. Please see the `application::php-fpm` recipe for a complete working example. In depth information about PHP-FPM's configuration values can be [found in the PHP-FPM documentation](http://php.net/manual/en/install.fpm.configuration.php).\n\n# Usage\n\nSimply include the recipe where you want PHP-FPM installed. Default pool **www** will be created. To disable pool creation set default['php-fpm']['pools'] to false.\n\nTo customize settings and pools you can override default attributes.\n\n## Usage in roles:\n\n```ruby\nname \"php-fpm\"\ndescription \"php fpm role\"\nrun_list \"recipe[php-fpm]\"\noverride_attributes \"php-fpm\" => {\n \"pools\" => {\n \"default\" => {\n :enable => true\n },\n \"www\" => {\n :enable => \"true\",\n :cookbook => \"another-cookbook\",\n :process_manager => \"dynamic\",\n :max_requests => 5000,\n :php_options => { 'php_admin_flag[log_errors]' => 'on', 'php_admin_value[memory_limit]' => '32M' }\n }\n }\n}\n```\n\n# Creating pools in recipes\n\n## Create PHP-FPM pool named 'www' with default settings:\n\n```ruby\nphp_fpm_pool \"www\"\n```\n\n## Create PHP-FPM pool named 'www' with custom settings:\n\n```ruby\nphp_fpm_pool \"www\" do\n cookbook \"another-cookbook\" # get template from another cookbook\n process_manager \"dynamic\"\n max_requests 5000\n php_options 'php_admin_flag[log_errors]' => 'on', 'php_admin_value[memory_limit]' => '32M'\nend\n```\n\n## Delete PHP-FPM pool named 'www':\n\n```ruby\nphp_fpm_pool \"www\" do\n enable false\nend\n```\n\n# Development\n\n## Requirements\n\n- [Docker](https://www.docker.com/)\n\n## Setup\n\nTo get all dependencies:\n\n```\nbundle install\n```\n\n## Test\n\nTo see available platforms:\n\n```\nbundle exec rake -T\n```\n\nTo test particular platform:\n\n```\nbundle exec rake kitchen:default-ubuntu-1604\n```\n\nTo test all platforms:\n\n```\nbundle exec rake kitchen:all\n```\n\n## Publishing (maintainers only!)\n\nBump version in metadata.rb, commit and push to master!\n\n```\nbundle exec rake publish\n```\n\nas a result new tag will be created and pushed to github as well as new version will be published on \n\n# Contributing\n\nPlease do not bump version when proposing a change, no other rules ;)\n\n# License and Author\n\nAuthor:: Seth Chisamore ([schisamo@chef.io](mailto:schisamo@chef.io))\n\nCopyright:: 2011-2017, Chef Software, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n```\nhttp://www.apache.org/licenses/LICENSE-2.0\n```\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache-2.0","platforms":{"debian":">= 0.0.0","ubuntu":">= 0.0.0","centos":">= 0.0.0","redhat":">= 0.0.0","fedora":">= 0.0.0","amazon":">= 0.0.0","oracle":">= 0.0.0","scientific":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/yevgenko/cookbook-php-fpm","issues_url":"https://github.com/yevgenko/cookbook-php-fpm/issues","chef_version":[[">= 12.14"]],"ohai_version":[]} \ No newline at end of file diff --git a/cookbooks/php-fpm/recipes/configure.rb b/cookbooks/php-fpm/recipes/configure.rb deleted file mode 100644 index 26bfb8d..0000000 --- a/cookbooks/php-fpm/recipes/configure.rb +++ /dev/null @@ -1,43 +0,0 @@ -# -# Author:: Seth Chisamore () -# Cookbook Name:: php-fpm -# Recipe:: package -# -# Copyright 2011-2017, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -template node['php-fpm']['conf_file'] do - source 'php-fpm.conf.erb' - mode 00644 - owner 'root' - group 'root' - notifies :restart, 'service[php-fpm]' -end - -if node['php-fpm']['pools'] - node['php-fpm']['pools'].each do |pool| - if pool.is_a?(Array) - pool_name = pool[0] - pool = pool[1] - else - pool_name = pool[:name] - end - php_fpm_pool pool_name do - pool.each do |k, v| - params[k.to_sym] = v - end - end - end -end diff --git a/cookbooks/php-fpm/recipes/default.rb b/cookbooks/php-fpm/recipes/default.rb deleted file mode 100644 index 652298a..0000000 --- a/cookbooks/php-fpm/recipes/default.rb +++ /dev/null @@ -1,22 +0,0 @@ -# -# Author:: Seth Chisamore () -# Cookbook Name:: php-fpm -# Recipe:: default -# -# Copyright 2011-2017, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -include_recipe 'php-fpm::install' -include_recipe 'php-fpm::configure' diff --git a/cookbooks/php-fpm/recipes/install.rb b/cookbooks/php-fpm/recipes/install.rb deleted file mode 100644 index 5249919..0000000 --- a/cookbooks/php-fpm/recipes/install.rb +++ /dev/null @@ -1,59 +0,0 @@ -# -# Author:: Seth Chisamore () -# Cookbook Name:: php-fpm -# Recipe:: package -# -# Copyright 2011-2017, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -include_recipe 'php-fpm::repository' unless node['php-fpm']['skip_repository_install'] - -php_fpm_package_name = if node['php-fpm']['package_name'].nil? - if platform_family?('rhel', 'fedora') - 'php-fpm' - elsif platform?('ubuntu') && node['platform_version'].to_f >= 16.04 - 'php7.0-fpm' - else - 'php5-fpm' - end - else - node['php-fpm']['package_name'] - end - -package php_fpm_package_name do - action node['php-fpm']['installation_action'] - version node['php-fpm']['version'] if node['php-fpm']['version'] -end - -php_fpm_service_name = if node['php-fpm']['service_name'].nil? - php_fpm_package_name - else - node['php-fpm']['service_name'] - end - -service_provider = nil -# this is actually already done in chef, but is kept here for older chef releases -if platform?('ubuntu') && node['platform_version'].to_f.between?(13.10, 14.10) - service_provider = ::Chef::Provider::Service::Upstart -end - -directory node['php-fpm']['log_dir'] - -service 'php-fpm' do - provider service_provider if service_provider - service_name php_fpm_service_name - supports start: true, stop: true, restart: true, reload: true - action [:enable, :start] -end diff --git a/cookbooks/php-fpm/recipes/repository.rb b/cookbooks/php-fpm/recipes/repository.rb deleted file mode 100644 index a0a6c0c..0000000 --- a/cookbooks/php-fpm/recipes/repository.rb +++ /dev/null @@ -1,54 +0,0 @@ -# -# Author:: Seth Chisamore () -# Cookbook Name:: php-fpm -# Recipe:: package -# -# Copyright 2011-2017, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -case node['platform'] -when 'debian' - # Configure Dotdeb repos - # TODO: move this to it's own 'dotdeb' cookbook? - # http://www.dotdeb.org/instructions/ - if node['platform_version'].to_f >= 8.0 - apt_repository 'dotdeb' do - uri node['php-fpm']['dotdeb_repository']['uri'] - distribution 'jessie' - components ['all'] - key node['php-fpm']['dotdeb_repository']['key'] - action :add - end - elsif node['platform_version'].to_f >= 7.0 - apt_repository 'dotdeb' do - uri node['php-fpm']['dotdeb_repository']['uri'] - distribution 'wheezy' - components ['all'] - key node['php-fpm']['dotdeb_repository']['key'] - action :add - end - end - -when 'amazon', 'fedora', 'centos', 'redhat', 'scientific', 'oracle' - unless platform?('centos', 'redhat') && node['platform_version'].to_f >= 6.4 # ~FC024 - yum_repository 'remi' do - description 'Remi' - url node['php-fpm']['yum_url'] - mirrorlist node['php-fpm']['yum_mirrorlist'] - gpgkey 'http://rpms.famillecollet.com/RPM-GPG-KEY-remi' - action :add - end - end -end diff --git a/cookbooks/php-fpm/recipes/test.rb b/cookbooks/php-fpm/recipes/test.rb deleted file mode 100644 index eff3d5f..0000000 --- a/cookbooks/php-fpm/recipes/test.rb +++ /dev/null @@ -1,3 +0,0 @@ -include_recipe 'php-fpm::default' - -package 'net-tools' diff --git a/cookbooks/php-fpm/templates/php-fpm.conf.erb b/cookbooks/php-fpm/templates/php-fpm.conf.erb deleted file mode 100644 index 900eb7c..0000000 --- a/cookbooks/php-fpm/templates/php-fpm.conf.erb +++ /dev/null @@ -1,60 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;; -; FPM Configuration ; -;;;;;;;;;;;;;;;;;;;;; - -; All relative paths in this configuration file are relative to PHP's install -; prefix. - -; Include one or more files. If glob(3) exists, it is used to include a bunch of -; files from a glob(3) pattern. This directive can be used everywhere in the -; file. -include = <%= "#{node['php-fpm']['pool_conf_dir']}/*.conf" %> - -;;;;;;;;;;;;;;;;;; -; Global Options ; -;;;;;;;;;;;;;;;;;; - -[global] -; Pid file -; Default Value: none -pid = <%= node['php-fpm']['pid'] %> - -; Error log file -; Default Value: /var/log/php-fpm.log -error_log = <%= node['php-fpm']['error_log'] %> - -; Log level -; Possible Values: alert, error, warning, notice, debug -; Default Value: notice -log_level = <%= node['php-fpm']['log_level'] %> - -; If this number of child processes exit with SIGSEGV or SIGBUS within the time -; interval set by emergency_restart_interval then FPM will restart. A value -; of '0' means 'Off'. -; Default Value: 0 -emergency_restart_threshold = <%= node['php-fpm']['emergency_restart_threshold'] %> - -; Interval of time used by emergency_restart_interval to determine when -; a graceful restart will be initiated. This can be useful to work around -; accidental corruptions in an accelerator's shared memory. -; Available Units: s(econds), m(inutes), h(ours), or d(ays) -; Default Unit: seconds -; Default Value: 0 -emergency_restart_interval = <%= node['php-fpm']['emergency_restart_interval'] %> - -; Time limit for child processes to wait for a reaction on signals from master. -; Available units: s(econds), m(inutes), h(ours), or d(ays) -; Default Unit: seconds -; Default Value: 0 -process_control_timeout = <%= node['php-fpm']['process_control_timeout'] %> - -; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging. -; Default Value: yes -daemonize = yes - -;;;;;;;;;;;;;;;;;;;; -; Pool Definitions ; -;;;;;;;;;;;;;;;;;;;; - -; See <%= "#{node['php-fpm']['pool_conf_dir']}/*.conf" %> - diff --git a/cookbooks/php-fpm/templates/pool.conf.erb b/cookbooks/php-fpm/templates/pool.conf.erb deleted file mode 100644 index ec4fbf3..0000000 --- a/cookbooks/php-fpm/templates/pool.conf.erb +++ /dev/null @@ -1,424 +0,0 @@ -; Start a new pool named '<%= @pool_name %>'. -; the variable $pool can we used in any directive and will be replaced by the -; pool name ('<%= @pool_name %>' here) -[<%= @pool_name %>] - -; Per pool prefix -; It only applies on the following directives: -; - 'slowlog' -; - 'listen' (unixsocket) -; - 'chroot' -; - 'chdir' -; - 'php_values' -; - 'php_admin_values' -; When not set, the global prefix (or /usr) applies instead. -; Note: This directive can also be relative to the global prefix. -; Default Value: none -;prefix = /path/to/pools/$pool - -; Unix user/group of processes -; Note: The user is mandatory. If the group is not set, the default user's group -; will be used. -user = <%= @user %> -group = <%= @group %> - -; The address on which to accept FastCGI requests. -; Valid syntaxes are: -; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on -; a specific port; -; 'port' - to listen on a TCP socket to all addresses on a -; specific port; -; '/path/to/unix/socket' - to listen on a unix socket. -; Note: This value is mandatory. -listen = <%= @listen %> - -; Set listen(2) backlog. -; Default Value: 128 (-1 on FreeBSD and OpenBSD) -;listen.backlog = 128 - -; Set permissions for unix socket, if one is used. In Linux, read/write -; permissions must be set in order to allow connections from a web server. Many -; BSD-derived systems allow connections regardless of permissions. -; Default Values: user and group are set as the running user -; mode is set to 0666 - -;listen.owner = nobody -<% unless @listen_owner.nil? %> -listen.owner = <%= @listen_owner %> -<% end %> - -;listen.group = nobody -<% unless @listen_group.nil? %> -listen.group = <%= @listen_group %> -<% end %> - -listen.mode = <%= @listen_mode %> - -; List of ipv4 addresses of FastCGI clients which are allowed to connect. -; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original -; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address -; must be separated by a comma. If this value is left blank, connections will be -; accepted from any ip address. -; Default Value: any -listen.allowed_clients = <%= @allowed_clients ? ([@allowed_clients].flatten.join(',')) : "127.0.0.1" %> - -; Specify the nice(2) priority to apply to the pool processes (only if set) -; The value can vary from -19 (highest priority) to 20 (lower priority) -; Note: - It will only work if the FPM master process is launched as root -; - The pool processes will inherit the master process priority -; unless it specified otherwise -; Default Value: no set -; priority = -19 - -; Choose how the process manager will control the number of child processes. -; Possible Values: -; static - a fixed number (pm.max_children) of child processes; -; dynamic - the number of child processes are set dynamically based on the -; following directives. With this process management, there will be -; always at least 1 children. -; pm.max_children - the maximum number of children that can -; be alive at the same time. -; pm.start_servers - the number of children created on startup. -; pm.min_spare_servers - the minimum number of children in 'idle' -; state (waiting to process). If the number -; of 'idle' processes is less than this -; number then some children will be created. -; pm.max_spare_servers - the maximum number of children in 'idle' -; state (waiting to process). If the number -; of 'idle' processes is greater than this -; number then some children will be killed. -; ondemand - no children are created at startup. Children will be forked when -; new requests will connect. The following parameter are used: -; pm.max_children - the maximum number of children that -; can be alive at the same time. -; pm.process_idle_timeout - The number of seconds after which -; an idle process will be killed. -; Note: This value is mandatory. -pm = <%= @process_manager %> - -; The number of child processes to be created when pm is set to 'static' and the -; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. -; This value sets the limit on the number of simultaneous requests that will be -; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. -; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP -; CGI. The below defaults are based on a server without much resources. Don't -; forget to tweak pm.* to fit your needs. -; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' -; Note: This value is mandatory. -pm.max_children = <%= @max_children %> - -<% if @process_manager == "dynamic" %> -; The number of child processes created on startup. -; Note: Used only when pm is set to 'dynamic' -; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 -<% if @start_servers %> -pm.start_servers = <%= @start_servers %> -<% end %> - -; The desired minimum number of idle server processes. -; Note: Used only when pm is set to 'dynamic' -; Note: Mandatory when pm is set to 'dynamic' -pm.min_spare_servers = <%= @min_spare_servers %> - -; The desired maximum number of idle server processes. -; Note: Used only when pm is set to 'dynamic' -; Note: Mandatory when pm is set to 'dynamic' -pm.max_spare_servers = <%= @max_spare_servers %> -<% end %> - -<% if @process_manager == "ondemand" %> -; The number of seconds after which an idle process will be killed. -; Note: Used only when pm is set to 'ondemand' -; Default Value: 10s -;pm.process_idle_timeout = 10s; -<% end %> - -; The number of requests each child process should execute before respawning. -; This can be useful to work around memory leaks in 3rd party libraries. For -; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. -; Default Value: 0 -pm.max_requests = <%= @max_requests %> - -; The URI to view the FPM status page. If this value is not set, no URI will be -; recognized as a status page. It shows the following informations: -; pool - the name of the pool; -; process manager - static, dynamic or ondemand; -; start time - the date and time FPM has started; -; start since - number of seconds since FPM has started; -; accepted conn - the number of request accepted by the pool; -; listen queue - the number of request in the queue of pending -; connections (see backlog in listen(2)); -; max listen queue - the maximum number of requests in the queue -; of pending connections since FPM has started; -; listen queue len - the size of the socket queue of pending connections; -; idle processes - the number of idle processes; -; active processes - the number of active processes; -; total processes - the number of idle + active processes; -; max active processes - the maximum number of active processes since FPM -; has started; -; max children reached - number of times, the process limit has been reached, -; when pm tries to start more children (works only for -; pm 'dynamic' and 'ondemand'); -; Value are updated in real time. -; Example output: -; pool: www -; process manager: static -; start time: 01/Jul/2011:17:53:49 +0200 -; start since: 62636 -; accepted conn: 190460 -; listen queue: 0 -; max listen queue: 1 -; listen queue len: 42 -; idle processes: 4 -; active processes: 11 -; total processes: 15 -; max active processes: 12 -; max children reached: 0 -; -; By default the status page output is formatted as text/plain. Passing either -; 'html', 'xml' or 'json' in the query string will return the corresponding -; output syntax. Example: -; http://www.foo.bar/status -; http://www.foo.bar/status?json -; http://www.foo.bar/status?html -; http://www.foo.bar/status?xml -; -; By default the status page only outputs short status. Passing 'full' in the -; query string will also return status for each pool process. -; Example: -; http://www.foo.bar/status?full -; http://www.foo.bar/status?json&full -; http://www.foo.bar/status?html&full -; http://www.foo.bar/status?xml&full -; The Full status returns for each process: -; pid - the PID of the process; -; state - the state of the process (Idle, Running, ...); -; start time - the date and time the process has started; -; start since - the number of seconds since the process has started; -; requests - the number of requests the process has served; -; request duration - the duration in ms of the requests; -; request method - the request method (GET, POST, ...); -; request URI - the request URI with the query string; -; content length - the content length of the request (only with POST); -; user - the user (PHP_AUTH_USER) (or '-' if not set); -; script - the main script called (or '-' if not set); -; last request cpu - the %cpu the last request consumed -; it's always 0 if the process is not in Idle state -; because CPU calculation is done when the request -; processing has terminated; -; last request memory - the max amount of memory the last request consumed -; it's always 0 if the process is not in Idle state -; because memory calculation is done when the request -; processing has terminated; -; If the process is in Idle state, then informations are related to the -; last request the process has served. Otherwise informations are related to -; the current request being served. -; Example output: -; ************************ -; pid: 31330 -; state: Running -; start time: 01/Jul/2011:17:53:49 +0200 -; start since: 63087 -; requests: 12808 -; request duration: 1250261 -; request method: GET -; request URI: /test_mem.php?N=10000 -; content length: 0 -; user: - -; script: /home/fat/web/docs/php/test_mem.php -; last request cpu: 0.00 -; last request memory: 0 -; -; Note: There is a real-time FPM status monitoring sample web page available -; It's available in: ${prefix}/share/fpm/status.html -; -; Note: The value must start with a leading slash (/). The value can be -; anything, but it may not be a good idea to use the .php extension or it -; may conflict with a real PHP file. -; Default Value: not set -;pm.status_path = /status - -; The ping URI to call the monitoring page of FPM. If this value is not set, no -; URI will be recognized as a ping page. This could be used to test from outside -; that FPM is alive and responding, or to -; - create a graph of FPM availability (rrd or such); -; - remove a server from a group if it is not responding (load balancing); -; - trigger alerts for the operating team (24/7). -; Note: The value must start with a leading slash (/). The value can be -; anything, but it may not be a good idea to use the .php extension or it -; may conflict with a real PHP file. -; Default Value: not set -;ping.path = /ping - -; This directive may be used to customize the response of a ping request. The -; response is formatted as text/plain with a 200 response code. -; Default Value: pong -;ping.response = pong - -; The access log file -; Default: not set -<% if @access_log %> -access.log = <%= node['php-fpm']['log_dir'] %>/$pool.access.log -<% end %> - -; The access log format. -; The following syntax is allowed -; %%: the '%' character -; %C: %CPU used by the request -; it can accept the following format: -; - %{user}C for user CPU only -; - %{system}C for system CPU only -; - %{total}C for user + system CPU (default) -; %d: time taken to serve the request -; it can accept the following format: -; - %{seconds}d (default) -; - %{miliseconds}d -; - %{mili}d -; - %{microseconds}d -; - %{micro}d -; %e: an environment variable (same as $_ENV or $_SERVER) -; it must be associated with embraces to specify the name of the env -; variable. Some exemples: -; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e -; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e -; %f: script filename -; %l: content-length of the request (for POST request only) -; %m: request method -; %M: peak of memory allocated by PHP -; it can accept the following format: -; - %{bytes}M (default) -; - %{kilobytes}M -; - %{kilo}M -; - %{megabytes}M -; - %{mega}M -; %n: pool name -; %o: output header -; it must be associated with embraces to specify the name of the header: -; - %{Content-Type}o -; - %{X-Powered-By}o -; - %{Transfert-Encoding}o -; - .... -; %p: PID of the child that serviced the request -; %P: PID of the parent of the child that serviced the request -; %q: the query string -; %Q: the '?' character if query string exists -; %r: the request URI (without the query string, see %q and %Q) -; %R: remote IP address -; %s: status (response code) -; %t: server time the request was received -; it can accept a strftime(3) format: -; %d/%b/%Y:%H:%M:%S %z (default) -; %T: time the log has been written (the request has finished) -; it can accept a strftime(3) format: -; %d/%b/%Y:%H:%M:%S %z (default) -; %u: remote user -; -; Default: "%R - %u %t \"%m %r\" %s" -;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%" - -; The log file for slow requests -; Default Value: not set -; Note: slowlog is mandatory if request_slowlog_timeout is set -<% if @slowlog %> -slowlog = <%= @slowlog %> -<% else %> -;slowlog = log/$pool.log.slow -<% end %> - -; The timeout for serving a single request after which a PHP backtrace will be -; dumped to the 'slowlog' file. A value of '0s' means 'off'. -; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) -; Default Value: 0 -<% if @request_slowlog_timeout %> -request_slowlog_timeout = <%=@request_slowlog_timeout %> -<% else %> -;request_slowlog_timeout = 0 -<% end %> - -; The timeout for serving a single request after which the worker process will -; be killed. This option should be used when the 'max_execution_time' ini option -; does not stop script execution for some reason. A value of '0' means 'off'. -; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) -; Default Value: 0 -request_terminate_timeout = <%=@request_terminate_timeout %> - -; Set open file descriptor rlimit. -; Default Value: system defined value -;rlimit_files = 1024 - -; Set max core size rlimit. -; Possible Values: 'unlimited' or an integer greater or equal to 0 -; Default Value: system defined value -;rlimit_core = 0 - -; Chroot to this directory at the start. This value must be defined as an -; absolute path. When this value is not set, chroot is not used. -; Note: you can prefix with '$prefix' to chroot to the pool prefix or one -; of its subdirectories. If the pool prefix is not set, the global prefix -; will be used instead. -; Note: chrooting is a great security feature and should be used whenever -; possible. However, all PHP paths will be relative to the chroot -; (error_log, sessions.save_path, ...). -; Default Value: not set -;chroot = - -; Chdir to this directory at the start. -; Note: relative path can be used. -; Default Value: current directory or / when chroot -;chdir = / - -; Redirect worker stdout and stderr into main error log. If not set, stdout and -; stderr will be redirected to /dev/null according to FastCGI specs. -; Note: on highloaded environement, this can cause some delay in the page -; process time (several ms). -; Default Value: no -catch_workers_output = <%= @catch_workers_output %> - -<% if node['platform'] != 'ubuntu' && node['platform_version'] != '10.04' %> -; Limits the extensions of the main script FPM will allow to parse. This can -; prevent configuration mistakes on the web server side. You should only limit -; FPM to .php extensions to prevent malicious users to use other extensions to -; exectute php code. -; Note: set an empty value to allow all extensions. -; Default Value: .php -;security.limit_extensions = .php .php3 .php4 .php5 -security.limit_extensions = <%=@security_limit_extensions %> -<% end %> - -; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from -; the current environment. -; Default Value: clean env -;env[HOSTNAME] = $HOSTNAME -;env[PATH] = /usr/local/bin:/usr/bin:/bin -;env[TMP] = /tmp -;env[TMPDIR] = /tmp -;env[TEMP] = /tmp - -; Additional php.ini defines, specific to this pool of workers. These settings -; overwrite the values previously defined in the php.ini. The directives are the -; same as the PHP SAPI: -; php_value/php_flag - you can set classic ini defines which can -; be overwritten from PHP call 'ini_set'. -; php_admin_value/php_admin_flag - these directives won't be overwritten by -; PHP call 'ini_set' -; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no. - -; Defining 'extension' will load the corresponding shared extension from -; extension_dir. Defining 'disable_functions' or 'disable_classes' will not -; overwrite previously defined php.ini values, but will append the new value -; instead. - -; Note: path INI options can be relative and will be expanded with the prefix -; (pool, global or /usr) - -; Default Value: nothing is defined by default except the values in php.ini and -; specified at startup with the -d argument -;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com -;php_flag[display_errors] = off -;php_admin_value[error_log] = /var/log/fpm-php.www.log -;php_admin_flag[log_errors] = on -;php_admin_value[memory_limit] = 32M - -<% @php_options.each do |name,value| %> -<%= "#{name} = #{value}" %> -<% end %> diff --git a/cookbooks/php/CHANGELOG.md b/cookbooks/php/CHANGELOG.md index ae0c697..ddc51ab 100644 --- a/cookbooks/php/CHANGELOG.md +++ b/cookbooks/php/CHANGELOG.md @@ -1,6 +1,38 @@ -# php Cookbook CHANGELOG +# PHP Cookbook CHANGELOG -This file is used to list changes made in each version of the php cookbook. +This file is used to list changes made in each version of the PHP cookbook. + +## 8.0.0 (2020-07-09) + +- Drop support for: + - Debian 8 + - Ubuntu < 16.04 + - Amazon Linux 1 +- Set default PHP version to 7.2.x +- Update Ubuntu 18.04 support to source build PHP 7.2 +- Update attributes for Debian 10 +- Add support for Ubuntu 20.04 +- Only symlink GMP on Ubuntu 16.04 to aid source builds +- Drop support for installing from source on Debian 9 + +## 7.2.0 (2020-06-19) + +- Include extension priority on the specified format to the extension file + +## 7.1.0 (2020-05-05) + +- Split out resource documentation into the documentation folder +- Run cookstyle 0.75.1 +- Fix dependency problem with installing php from source on ubuntu 18.04 +- Simplify platform checks +- Remove unused long_description metadata from metadata.rb +- Migrated to Github Actions for testing +- Adding control of php-fpm php.ini with specific attribute + +## 7.0.0 (2019-08-07) + +- *Drop support for Chef 13* so we don't need to require build essentials +- Sync php.ini template with php.ini-production from php-7.2.18 ## 6.1.1 (2018-08-07) @@ -42,7 +74,7 @@ This release removes the previous recipes in this cookbook for setting up variou - Converted the php_pear resource to a custom resource - Moved all helper logic out of the resource and into its own helper library file -- Fix source install on Ubuntu by making sure we have xml2-config package +- Fix source install on Ubuntu by making sure we have xml2-config package - Remove options that are no longer recognised by the php installer when installing from source - Remove matchers as we no longer require them with a modern ChefDK diff --git a/cookbooks/php/CONTRIBUTING.md b/cookbooks/php/CONTRIBUTING.md index ef2f2b8..a946aea 100644 --- a/cookbooks/php/CONTRIBUTING.md +++ b/cookbooks/php/CONTRIBUTING.md @@ -1,2 +1,4 @@ +# Contributing + Please refer to -https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD +[https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) diff --git a/cookbooks/php/README.md b/cookbooks/php/README.md index 6bd2873..ae26ef1 100644 --- a/cookbooks/php/README.md +++ b/cookbooks/php/README.md @@ -1,9 +1,17 @@ # php Cookbook -[![Build Status](https://travis-ci.org/chef-cookbooks/php.svg?branch=master)](http://travis-ci.org/chef-cookbooks/php) [![Cookbook Version](https://img.shields.io/cookbook/v/php.svg)](https://supermarket.chef.io/cookbooks/php) +[![Cookbook Version](https://img.shields.io/cookbook/v/php.svg)](https://supermarket.chef.io/cookbooks/php) +[![Build Status](https://img.shields.io/circleci/project/github/sous-chefs/php/master.svg)](https://circleci.com/gh/sous-chefs/php) +[![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) +[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) +[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) It installs and configures PHP and the PEAR package management system. Also includes resources for managing PEAR (and PECL) packages, PECL channels, and PHP-FPM pools. +## Maintainers + +This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF). + ## Requirements ### Platforms @@ -14,18 +22,14 @@ It installs and configures PHP and the PEAR package management system. Also incl ### Chef -- Chef 12.7+ - -### Cookbooks - -- build-essential +- Chef 14+ ## Attributes - `node['php']['install_method']` = method to install php with, default `package`. - `node['php']['directives']` = Hash of directives and values to append to `php.ini`, default `{}`. - `node['php']['pear_setup']` = Boolean value to determine whether to set up pear repositories. Default: `true` -- `node['php']['pear_channels']` = List of external pear channels to add if `node['php']['pear_setup]` is true. Default: `['pear.php.net', 'pecl.php.net']` +- `node['php']['pear_channels']` = List of external pear channels to add if `node['php']['pear_setup']` is true. Default: `['pear.php.net', 'pecl.php.net']` The file also contains the following attribute types: @@ -36,175 +40,9 @@ The file also contains the following attribute types: This cookbook includes resources for managing: -- PEAR channels -- PEAR/PECL packages - -### `php_pear_channel` - -[PEAR Channels](http://pear.php.net/manual/en/guide.users.commandline.channels.php) are alternative sources for PEAR packages. This resource provides and easy way to manage these channels. - -#### Actions - -- `:discover`: Initialize a channel from its server. -- `:add`: Add a channel to the channel list, usually only used to add private channels. Public channels are usually added using the `:discover` action -- `:update`: Update an existing channel -- `:remove`: Remove a channel from the List - -#### Properties - -- `channel_name`: name attribute. The name of the channel to discover -- `channel_xml`: the channel.xml file of the channel you are adding -- `binary`: pear binary, default: pear - -#### Examples - -```ruby -# discover the horde channel -php_pear_channel "pear.horde.org" do - action :discover -end - -# download xml then add the symfony channel -remote_file "#{Chef::Config[:file_cache_path]}/symfony-channel.xml" do - source 'http://pear.symfony-project.com/channel.xml' - mode '0644' -end -php_pear_channel 'symfony' do - channel_xml "#{Chef::Config[:file_cache_path]}/symfony-channel.xml" - action :add -end - -# update the main pear channel -php_pear_channel 'pear.php.net' do - action :update -end - -# update the main pecl channel -php_pear_channel 'pecl.php.net' do - action :update -end -``` - -### `php_pear` - -[PEAR](http://pear.php.net/) is a framework and distribution system for reusable PHP components. [PECL](http://pecl.php.net/) is a repository for PHP Extensions. PECL contains C extensions for compiling into PHP. As C programs, PECL extensions run more efficiently than PEAR packages. PEARs and PECLs use the same packaging and distribution system. As such this resource is clever enough to abstract away the small differences and can be used for managing either. This resource also creates the proper module .ini file for each PECL extension at the correct location for each supported platform. - -#### Actions - -- `:install`: Install a pear package - if version is provided, install that specific version -- `:upgrade`: Upgrade a pear package - if version is provided, upgrade to that specific version -- `:remove`: Remove a pear package -- `:reinstall`: Force install of the package even if the same version is already installed. Note: This will converge on every Chef run and is probably not what you want. -- `:purge`: An alias for remove as the two behave the same in pear - -#### Properties - -- `package_name`: name attribute. The name of the pear package to install -- `version`: the version of the pear package to install/upgrade. If no version is given latest is assumed. -- `channel`: -- `options`: Add additional options to the underlying pear package command -- `directives`: extra extension directives (settings) for a pecl. on most platforms these usually get rendered into the extension's .ini file -- `zend_extensions`: extension filenames which should be loaded with zend_extension. -- `preferred_state`: PEAR by default installs stable packages only, this allows you to install pear packages in a devel, alpha or beta state -- `binary`: The pear binary to use, by default pear, can be overridden if the binary is not called pear, e.g. pear7 - -#### Examples - -```ruby -# upgrade a pear -php_pear 'XML_RPC' do - action :upgrade -end - -# install a specific version -php_pear 'XML_RPC' do - version '1.5.4' - action :install -end - -# install the mongodb pecl -php_pear 'Install mongo but use a different resource name' do - package_name 'mongo' - action :install -end - -# install the xdebug pecl -php_pear 'xdebug' do - # Specify that xdebug.so must be loaded as a zend extension - zend_extensions ['xdebug.so'] - action :install -end - -# install apc pecl with directives -php_pear 'apc' do - action :install - directives(shm_size: 128, enable_cli: 1) -end - -# install using the pear-7 binary -php_pear 'apc' do - action :install - binary 'pear7' -end - -# install the beta version of Horde_Url -# from the horde channel -hc = php_pear_channel 'pear.horde.org' do - action :discover -end - -php_pear 'Horde_Url' do - preferred_state 'beta' - channel hc.channel_name - action :install -end - -# install the YAML pear from the symfony project -sc = php_pear_channel 'pear.symfony-project.com' do - action :discover -end - -php_pear 'YAML' do - channel sc.channel_name - action :install -end -``` - -### `php_fpm_pool` - -Installs the `php-fpm` package appropriate for your distro (if using packages) and configures a FPM pool for you. Currently only supported in Debian-family operating systems and CentOS 7 (or at least tested with such, YMMV if you are using source). - -Please consider FPM functionally pre-release, and test it thoroughly in your environment before using it in production - -More info: - -#### Actions - -- `:install`: Installs the FPM pool (default). -- `:uninstall`: Removes the FPM pool. - -#### Attribute Parameters - -- `pool_name`: name attribute. The name of the FPM pool. -- `listen`: The listen address. Default: `/var/run/php5-fpm.sock` -- `user`: The user to run the FPM under. Default should be the webserver user for your distro. -- `group`: The group to run the FPM under. Default should be the webserver group for your distro. -- `process_manager`: Process manager to use - see . Default: `dynamic` -- `max_children`: Max children to scale to. Default: 5 -- `start_servers`: Number of servers to start the pool with. Default: 2 -- `min_spare_servers`: Minimum number of servers to have as spares. Default: 1 -- `max_spare_servers`: Maximum number of servers to have as spares. Default: 3 -- `chdir`: The startup working directory of the pool. Default: `/` -- `additional_config`: Additional parameters in JSON. Default: {} - -#### Examples - -```ruby -# Install a FPM pool named "default" -php_fpm_pool 'default' do - action :install -end -``` +- [php_pear](https://github.com/sous-chefs/php/tree/master/documentation/php_pear.md) +- [php_pear_channel](https://github.com/sous-chefs/php/tree/master/documentation/php_pear_channel.md) +- [php_fpm_pool](https://github.com/sous-chefs/php/tree/master/documentation/php_fpm_pool.md) ## Recipes @@ -220,11 +58,13 @@ This recipe installs PHP from packages. This recipe installs PHP from source. +*Note:* Debian 9 is not supported for building from source. + ## Usage Simply include the `php` recipe where ever you would like php installed. To install from source override the `node['php']['install_method']` attribute with in a role or wrapper cookbook: -### Role example: +### Role example ```ruby name 'php' @@ -239,25 +79,27 @@ run_list( ) ``` -## Maintainers +## Contributors -This cookbook is maintained by Chef's Community Cookbook Engineering team. Our goal is to improve cookbook quality and to aid the community in contributing to cookbooks. To learn more about our team, process, and design goals see our [team documentation](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/COOKBOOK_TEAM.MD). To learn more about contributing to cookbooks like this see our [contributing documentation](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD), or if you have general questions about this cookbook come chat with us in #cookbok-engineering on the [Chef Community Slack](http://community-slack.chef.io/) +This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) -## License +### Backers -**Copyright:** 2011-2018, Chef Software, Inc. -**Copyright:** 2018, Oracle and/or its affiliates. All rights reserved +Thank you to all our backers! -``` -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at +![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) - http://www.apache.org/licenses/LICENSE-2.0 +### Sponsors -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -``` +Support this project by becoming a sponsor. Your logo will show up here with a link to your website. + +![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) +![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) diff --git a/cookbooks/php/attributes/default.rb b/cookbooks/php/attributes/default.rb index f12383d..3528620 100644 --- a/cookbooks/php/attributes/default.rb +++ b/cookbooks/php/attributes/default.rb @@ -18,13 +18,14 @@ # lib_dir = 'lib' + default['php']['install_method'] = 'package' default['php']['directives'] = {} default['php']['bin'] = 'php' default['php']['pecl'] = 'pecl' -default['php']['version'] = '5.6.30' +default['php']['version'] = '7.2.31' default['php']['pear'] = '/usr/bin/pear' default['php']['pear_setup'] = true @@ -33,20 +34,23 @@ default['php']['pear_channels'] = [ 'pecl.php.net', ] -default['php']['url'] = 'http://us1.php.net/get' -default['php']['checksum'] = '8bc7d93e4c840df11e3d9855dcad15c1b7134e8acf0cf3b90b932baea2d0bde2' +default['php']['url'] = 'https://www.php.net/distributions' +default['php']['checksum'] = '796837831ccebf00dc15921ed327cfbac59177da41b33044d9a6c7134cdd250c' # checksum of the .tar.gz files default['php']['prefix_dir'] = '/usr/local' -default['php']['enable_mod'] = '/usr/sbin/php5enmod' -default['php']['disable_mod'] = '/usr/sbin/php5dismod' +default['php']['enable_mod'] = '/usr/sbin/phpenmod' +default['php']['disable_mod'] = '/usr/sbin/phpdismod' default['php']['ini']['template'] = 'php.ini.erb' default['php']['ini']['cookbook'] = 'php' -default['php']['fpm_socket'] = '/var/run/php5-fpm.sock' +default['php']['fpm_socket'] = '/var/run/php7.2-fpm.sock' +default['php']['fpm_conf_dir'] = nil +default['php']['fpm_ini_control'] = false case node['platform_family'] -when 'rhel', 'fedora', 'amazon' +when 'rhel', 'amazon' lib_dir = node['kernel']['machine'] =~ /x86_64/ ? 'lib64' : 'lib' + default['php']['conf_dir'] = '/etc' default['php']['ext_conf_dir'] = '/etc/php.d' default['php']['fpm_user'] = 'nobody' @@ -54,21 +58,14 @@ when 'rhel', 'fedora', 'amazon' default['php']['fpm_listen_user'] = 'nobody' default['php']['fpm_listen_group'] = 'nobody' default['php']['ext_dir'] = "/usr/#{lib_dir}/php/modules" - if node['platform'] == 'amazon' # amazon names their packages with versions on 201X amazon - default['php']['src_deps'] = %w(bzip2-devel libc-client-devel curl-devel freetype-devel gmp-devel libjpeg-devel krb5-devel libmcrypt-devel libpng-devel openssl-devel t1lib-devel libxml2-devel libxslt-devel zlib-devel) + default['php']['fpm_package'] = 'php-fpm' - if node['platform_version'].to_i == 2 - default['php']['packages'] = %w(php php-devel php-pear) - default['php']['fpm_package'] = 'php-fpm' - else - default['php']['packages'] = %w(php56 php56-devel php-pear) - default['php']['fpm_package'] = 'php56-fpm' - end - else # redhat does not name their packages with version on RHEL 6+ - default['php']['src_deps'] = %w(bzip2-devel libc-client-devel curl-devel freetype-devel gmp-devel libjpeg-devel krb5-devel libmcrypt-devel libpng-devel openssl-devel t1lib-devel libxml2-devel libxslt-devel zlib-devel mhash-devel) - default['php']['packages'] = %w(php php-devel php-cli php-pear) - default['php']['fpm_package'] = 'php-fpm' - end + default['php']['src_deps'] = if platform?('amazon') || node['platform_version'].to_i < 8 + %w(bzip2-devel libc-client-devel curl-devel freetype-devel gmp-devel libjpeg-devel krb5-devel libmcrypt-devel libpng-devel openssl-devel t1lib-devel libxml2-devel libxslt-devel zlib-devel mhash-devel) + else # redhat does not name their packages with version on RHEL 6+ + %w(bzip2-devel libc-client-devel curl-devel freetype-devel gmp-devel libjpeg-devel krb5-devel libmcrypt-devel libpng-devel openssl-devel libxml2-devel libxslt-devel zlib-devel mhash-devel) + end + default['php']['packages'] = %w(php php-devel php-cli php-pear) default['php']['fpm_pooldir'] = '/etc/php-fpm.d' default['php']['fpm_default_conf'] = '/etc/php-fpm.d/www.conf' default['php']['fpm_service'] = 'php-fpm' @@ -79,86 +76,73 @@ when 'rhel', 'fedora', 'amazon' default['php']['fpm_listen_group'] = 'apache' end when 'debian' - default['php']['conf_dir'] = '/etc/php5/cli' - default['php']['ext_conf_dir'] = '/etc/php5/conf.d' - default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng12-dev libssl-dev libt1-dev libxml2-dev libxslt-dev zlib1g-dev) - default['php']['packages'] = %w(php5-cgi php5 php5-dev php5-cli php-pear) - default['php']['fpm_package'] = 'php5-fpm' - default['php']['fpm_pooldir'] = '/etc/php5/fpm/pool.d' - default['php']['fpm_user'] = 'www-data' - default['php']['fpm_group'] = 'www-data' + default['php']['version'] = '7.0.4' + default['php']['checksum'] = 'f6cdac2fd37da0ac0bbcee0187d74b3719c2f83973dfe883d5cde81c356fe0a8' + default['php']['conf_dir'] = '/etc/php/7.0/cli' + default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg-dev libkrb5-dev libmcrypt-dev libpng-dev libssl-dev pkg-config libxml2-dev) + default['php']['packages'] = %w(php7.0-cgi php7.0 php7.0-dev php7.0-cli php-pear) + default['php']['disable_mod'] = '/usr/sbin/phpdismod' + default['php']['enable_mod'] = '/usr/sbin/phpenmod' + default['php']['fpm_default_conf'] = '/etc/php/7.0/fpm/pool.d/www.conf' + default['php']['fpm_conf_dir'] = '/etc/php/7.0/fpm' + default['php']['ext_conf_dir'] = '/etc/php/7.0/mods-available' + default['php']['fpm_package'] = 'php7.0-fpm' + default['php']['fpm_pooldir'] = '/etc/php/7.0/fpm/pool.d' + default['php']['fpm_service'] = 'php7.0-fpm' + default['php']['fpm_socket'] = '/var/run/php/php7.0-fpm.sock' + default['php']['fpm_user'] = 'www-data' + default['php']['fpm_group'] = 'www-data' default['php']['fpm_listen_user'] = 'www-data' default['php']['fpm_listen_group'] = 'www-data' - default['php']['fpm_service'] = 'php5-fpm' - default['php']['fpm_default_conf'] = '/etc/php5/fpm/pool.d/www.conf' - if (platform?('debian') && node['platform_version'].to_i >= 9) || - (platform?('ubuntu') && node['platform_version'].to_f == 16.04) - default['php']['version'] = '7.0.4' - default['php']['checksum'] = 'f6cdac2fd37da0ac0bbcee0187d74b3719c2f83973dfe883d5cde81c356fe0a8' - default['php']['conf_dir'] = '/etc/php/7.0/cli' - default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng12-dev libssl-dev pkg-config libxml2-dev) - default['php']['packages'] = %w(php7.0-cgi php7.0 php7.0-dev php7.0-cli php-pear) - default['php']['fpm_package'] = 'php7.0-fpm' - default['php']['fpm_pooldir'] = '/etc/php/7.0/fpm/pool.d' - default['php']['fpm_service'] = 'php7.0-fpm' - default['php']['fpm_socket'] = '/var/run/php/php7.0-fpm.sock' - default['php']['fpm_default_conf'] = '/etc/php/7.0/fpm/pool.d/www.conf' - default['php']['enable_mod'] = '/usr/sbin/phpenmod' - default['php']['disable_mod'] = '/usr/sbin/phpdismod' - default['php']['ext_conf_dir'] = '/etc/php/7.0/mods-available' - elsif platform?('ubuntu') && node['platform_version'].to_f >= 18.04 - default['php']['version'] = '7.0.4' - default['php']['checksum'] = 'f6cdac2fd37da0ac0bbcee0187d74b3719c2f83973dfe883d5cde81c356fe0a8' + if platform?('debian') && node['platform_version'].to_i >= 10 + default['php']['version'] = '7.3.19' + default['php']['checksum'] = '809126b46d62a1a06c2d5a0f9d7ba61aba40e165f24d2d185396d0f9646d3280' + default['php']['conf_dir'] = '/etc/php/7.3/cli' + default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-turbo-dev libkrb5-dev libmcrypt-dev libpng-dev libssl-dev pkg-config libxml2-dev file re2c libzip-dev) + # Debian >= 10 drops versions from the package names + default['php']['packages'] = %w(php-cgi php php-dev php-cli php-pear) + default['php']['fpm_package'] = 'php7.3-fpm' + default['php']['fpm_pooldir'] = '/etc/php/7.3/fpm/pool.d' + default['php']['fpm_service'] = 'php7.3-fpm' + default['php']['fpm_socket'] = '/var/run/php/php7.3-fpm.sock' + default['php']['fpm_default_conf'] = '/etc/php/7.3/fpm/pool.d/www.conf' + default['php']['fpm_conf_dir'] = '/etc/php/7.3/fpm' + default['php']['ext_conf_dir'] = '/etc/php/7.3/mods-available' + elsif platform?('ubuntu') && node['platform_version'].to_f == 18.04 + default['php']['version'] = '7.2.31' + default['php']['checksum'] = '796837831ccebf00dc15921ed327cfbac59177da41b33044d9a6c7134cdd250c' default['php']['conf_dir'] = '/etc/php/7.2/cli' - default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng12-dev libssl-dev pkg-config libxml2-dev) + default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng-dev libssl-dev pkg-config libxml2-dev) default['php']['packages'] = %w(php7.2-cgi php7.2 php7.2-dev php7.2-cli php-pear) default['php']['fpm_package'] = 'php7.2-fpm' default['php']['fpm_pooldir'] = '/etc/php/7.2/fpm/pool.d' default['php']['fpm_service'] = 'php7.2-fpm' default['php']['fpm_socket'] = '/var/run/php/php7.2-fpm.sock' default['php']['fpm_default_conf'] = '/etc/php/7.2/fpm/pool.d/www.conf' + default['php']['fpm_conf_dir'] = '/etc/php/7.2/fpm' + default['php']['ext_conf_dir'] = '/etc/php/7.2/mods-available' + elsif platform?('ubuntu') && node['platform_version'].to_f >= 20.04 + default['php']['version'] = '7.4.7' + default['php']['checksum'] = 'a554a510190e726ebe7157fb00b4aceabdb50c679430510a3b93cbf5d7546e44' + default['php']['conf_dir'] = '/etc/php/7.4/cli' + default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng-dev libssl-dev pkg-config libxml2-dev libsqlite3-dev libonig-dev) + # Ubuntu >= 20.04 drops versions from the package names + default['php']['packages'] = %w(php-cgi php php-dev php-cli php-pear) + default['php']['fpm_package'] = 'php7.4-fpm' + default['php']['fpm_pooldir'] = '/etc/php/7.4/fpm/pool.d' + default['php']['fpm_service'] = 'php7.4-fpm' + default['php']['fpm_socket'] = '/var/run/php/php7.4-fpm.sock' + default['php']['fpm_default_conf'] = '/etc/php/7.4/fpm/pool.d/www.conf' + default['php']['fpm_conf_dir'] = '/etc/php/7.4/fpm' default['php']['enable_mod'] = '/usr/sbin/phpenmod' default['php']['disable_mod'] = '/usr/sbin/phpdismod' - default['php']['ext_conf_dir'] = '/etc/php/7.2/mods-available' + default['php']['ext_conf_dir'] = '/etc/php/7.4/mods-available' end - - case node['platform'] - when 'ubuntu' - case node['platform_version'].to_f - when 13.04..15.10 - default['php']['ext_conf_dir'] = '/etc/php5/mods-available' - end - when 'debian' - if node['platform_version'].to_i == 8 - default['php']['ext_conf_dir'] = '/etc/php5/mods-available' - end - end -when 'suse' - default['php']['conf_dir'] = '/etc/php5/cli' - default['php']['ext_conf_dir'] = '/etc/php5/conf.d' - default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng12-dev libssl-dev libt1-dev libxml2-devel libxslt-devel zlib-devel) - default['php']['fpm_default_conf'] = '/etc/php-fpm.d/www.conf' - default['php']['fpm_pooldir'] = '/etc/php5/fpm' - default['php']['fpm_service'] = 'php-fpm' - default['php']['fpm_package'] = 'php5-fpm' - default['php']['fpm_user'] = 'wwwrun' - default['php']['fpm_group'] = 'www' - default['php']['fpm_listen_user'] = 'wwwrun' - default['php']['fpm_listen_group'] = 'www' - default['php']['packages'] = %w(apache2-mod_php5 php5-pear) - lib_dir = node['kernel']['machine'] =~ /x86_64/ ? 'lib64' : 'lib' -when 'freebsd' - default['php']['conf_dir'] = '/usr/local/etc' - default['php']['ext_conf_dir'] = '/usr/local/etc/php' - default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng12-dev libssl-dev libt1-dev) - default['php']['fpm_user'] = 'www' - default['php']['fpm_group'] = 'www' - default['php']['fpm_listen_user'] = 'www' - default['php']['fpm_listen_group'] = 'www' - default['php']['packages'] = %w( php56 pear ) end +default['php']['src_recompile'] = false + default['php']['configure_options'] = %W(--prefix=#{node['php']['prefix_dir']} --with-libdir=#{lib_dir} --with-config-file-path=#{node['php']['conf_dir']} diff --git a/cookbooks/php/metadata.json b/cookbooks/php/metadata.json index 5f11b3d..5fa1158 100644 --- a/cookbooks/php/metadata.json +++ b/cookbooks/php/metadata.json @@ -1 +1 @@ -{"name":"php","version":"6.1.1","description":"Installs and maintains php and php modules","long_description":"# php Cookbook\n\n[![Build Status](https://travis-ci.org/chef-cookbooks/php.svg?branch=master)](http://travis-ci.org/chef-cookbooks/php) [![Cookbook Version](https://img.shields.io/cookbook/v/php.svg)](https://supermarket.chef.io/cookbooks/php)\n\nIt installs and configures PHP and the PEAR package management system. Also includes resources for managing PEAR (and PECL) packages, PECL channels, and PHP-FPM pools.\n\n## Requirements\n\n### Platforms\n\n- Debian, Ubuntu\n- CentOS, Red Hat, Oracle, Scientific, Amazon Linux\n- Fedora\n\n### Chef\n\n- Chef 12.7+\n\n### Cookbooks\n\n- build-essential\n\n## Attributes\n\n- `node['php']['install_method']` = method to install php with, default `package`.\n- `node['php']['directives']` = Hash of directives and values to append to `php.ini`, default `{}`.\n- `node['php']['pear_setup']` = Boolean value to determine whether to set up pear repositories. Default: `true`\n- `node['php']['pear_channels']` = List of external pear channels to add if `node['php']['pear_setup]` is true. Default: `['pear.php.net', 'pecl.php.net']`\n\nThe file also contains the following attribute types:\n\n- platform specific locations and settings.\n- source installation settings\n\n## Resources\n\nThis cookbook includes resources for managing:\n\n- PEAR channels\n- PEAR/PECL packages\n\n### `php_pear_channel`\n\n[PEAR Channels](http://pear.php.net/manual/en/guide.users.commandline.channels.php) are alternative sources for PEAR packages. This resource provides and easy way to manage these channels.\n\n#### Actions\n\n- `:discover`: Initialize a channel from its server.\n- `:add`: Add a channel to the channel list, usually only used to add private channels. Public channels are usually added using the `:discover` action\n- `:update`: Update an existing channel\n- `:remove`: Remove a channel from the List\n\n#### Properties\n\n- `channel_name`: name attribute. The name of the channel to discover\n- `channel_xml`: the channel.xml file of the channel you are adding\n- `binary`: pear binary, default: pear\n\n#### Examples\n\n```ruby\n# discover the horde channel\nphp_pear_channel \"pear.horde.org\" do\n action :discover\nend\n\n# download xml then add the symfony channel\nremote_file \"#{Chef::Config[:file_cache_path]}/symfony-channel.xml\" do\n source 'http://pear.symfony-project.com/channel.xml'\n mode '0644'\nend\nphp_pear_channel 'symfony' do\n channel_xml \"#{Chef::Config[:file_cache_path]}/symfony-channel.xml\"\n action :add\nend\n\n# update the main pear channel\nphp_pear_channel 'pear.php.net' do\n action :update\nend\n\n# update the main pecl channel\nphp_pear_channel 'pecl.php.net' do\n action :update\nend\n```\n\n### `php_pear`\n\n[PEAR](http://pear.php.net/) is a framework and distribution system for reusable PHP components. [PECL](http://pecl.php.net/) is a repository for PHP Extensions. PECL contains C extensions for compiling into PHP. As C programs, PECL extensions run more efficiently than PEAR packages. PEARs and PECLs use the same packaging and distribution system. As such this resource is clever enough to abstract away the small differences and can be used for managing either. This resource also creates the proper module .ini file for each PECL extension at the correct location for each supported platform.\n\n#### Actions\n\n- `:install`: Install a pear package - if version is provided, install that specific version\n- `:upgrade`: Upgrade a pear package - if version is provided, upgrade to that specific version\n- `:remove`: Remove a pear package\n- `:reinstall`: Force install of the package even if the same version is already installed. Note: This will converge on every Chef run and is probably not what you want.\n- `:purge`: An alias for remove as the two behave the same in pear\n\n#### Properties\n\n- `package_name`: name attribute. The name of the pear package to install\n- `version`: the version of the pear package to install/upgrade. If no version is given latest is assumed.\n- `channel`:\n- `options`: Add additional options to the underlying pear package command\n- `directives`: extra extension directives (settings) for a pecl. on most platforms these usually get rendered into the extension's .ini file\n- `zend_extensions`: extension filenames which should be loaded with zend_extension.\n- `preferred_state`: PEAR by default installs stable packages only, this allows you to install pear packages in a devel, alpha or beta state\n- `binary`: The pear binary to use, by default pear, can be overridden if the binary is not called pear, e.g. pear7\n\n#### Examples\n\n```ruby\n# upgrade a pear\nphp_pear 'XML_RPC' do\n action :upgrade\nend\n\n# install a specific version\nphp_pear 'XML_RPC' do\n version '1.5.4'\n action :install\nend\n\n# install the mongodb pecl\nphp_pear 'Install mongo but use a different resource name' do\n package_name 'mongo'\n action :install\nend\n\n# install the xdebug pecl\nphp_pear 'xdebug' do\n # Specify that xdebug.so must be loaded as a zend extension\n zend_extensions ['xdebug.so']\n action :install\nend\n\n# install apc pecl with directives\nphp_pear 'apc' do\n action :install\n directives(shm_size: 128, enable_cli: 1)\nend\n\n# install using the pear-7 binary\nphp_pear 'apc' do\n action :install\n binary 'pear7'\nend\n\n# install the beta version of Horde_Url\n# from the horde channel\nhc = php_pear_channel 'pear.horde.org' do\n action :discover\nend\n\nphp_pear 'Horde_Url' do\n preferred_state 'beta'\n channel hc.channel_name\n action :install\nend\n\n# install the YAML pear from the symfony project\nsc = php_pear_channel 'pear.symfony-project.com' do\n action :discover\nend\n\nphp_pear 'YAML' do\n channel sc.channel_name\n action :install\nend\n```\n\n### `php_fpm_pool`\n\nInstalls the `php-fpm` package appropriate for your distro (if using packages) and configures a FPM pool for you. Currently only supported in Debian-family operating systems and CentOS 7 (or at least tested with such, YMMV if you are using source).\n\nPlease consider FPM functionally pre-release, and test it thoroughly in your environment before using it in production\n\nMore info: \n\n#### Actions\n\n- `:install`: Installs the FPM pool (default).\n- `:uninstall`: Removes the FPM pool.\n\n#### Attribute Parameters\n\n- `pool_name`: name attribute. The name of the FPM pool.\n- `listen`: The listen address. Default: `/var/run/php5-fpm.sock`\n- `user`: The user to run the FPM under. Default should be the webserver user for your distro.\n- `group`: The group to run the FPM under. Default should be the webserver group for your distro.\n- `process_manager`: Process manager to use - see . Default: `dynamic`\n- `max_children`: Max children to scale to. Default: 5\n- `start_servers`: Number of servers to start the pool with. Default: 2\n- `min_spare_servers`: Minimum number of servers to have as spares. Default: 1\n- `max_spare_servers`: Maximum number of servers to have as spares. Default: 3\n- `chdir`: The startup working directory of the pool. Default: `/`\n- `additional_config`: Additional parameters in JSON. Default: {}\n\n#### Examples\n\n```ruby\n# Install a FPM pool named \"default\"\nphp_fpm_pool 'default' do\n action :install\nend\n```\n\n## Recipes\n\n### default\n\nInclude the default recipe in a run list, to get `php`. By default `php` is installed from packages but this can be changed by using the `install_method` attribute.\n\n### package\n\nThis recipe installs PHP from packages.\n\n### source\n\nThis recipe installs PHP from source.\n\n## Usage\n\nSimply include the `php` recipe where ever you would like php installed. To install from source override the `node['php']['install_method']` attribute with in a role or wrapper cookbook:\n\n### Role example:\n\n```ruby\nname 'php'\ndescription 'Install php from source'\noverride_attributes(\n 'php' => {\n 'install_method' => 'source',\n }\n)\nrun_list(\n 'recipe[php]'\n)\n```\n\n## Maintainers\n\nThis cookbook is maintained by Chef's Community Cookbook Engineering team. Our goal is to improve cookbook quality and to aid the community in contributing to cookbooks. To learn more about our team, process, and design goals see our [team documentation](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/COOKBOOK_TEAM.MD). To learn more about contributing to cookbooks like this see our [contributing documentation](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD), or if you have general questions about this cookbook come chat with us in #cookbok-engineering on the [Chef Community Slack](http://community-slack.chef.io/)\n\n## License\n\n**Copyright:** 2011-2018, Chef Software, Inc.\n**Copyright:** 2018, Oracle and/or its affiliates. All rights reserved\n\n```\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache-2.0","platforms":{"amazon":">= 0.0.0","centos":">= 0.0.0","debian":">= 0.0.0","fedora":">= 0.0.0","oracle":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0","suse":">= 0.0.0","opensuse":">= 0.0.0","opensuseleap":">= 0.0.0","ubuntu":">= 0.0.0"},"dependencies":{"build-essential":">= 5.0","yum-epel":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{"php":"Installs php","php::package":"Installs php using packages.","php::source":"Installs php from source."},"source_url":"https://github.com/chef-cookbooks/php","issues_url":"https://github.com/chef-cookbooks/php/issues","chef_version":[[">= 12.7"]],"ohai_version":[]} \ No newline at end of file +{"name":"php","version":"8.0.0","description":"Installs and maintains php and php modules","long_description":"","maintainer":"Sous Chefs","maintainer_email":"help@sous-chefs.org","license":"Apache-2.0","platforms":{"amazon":">= 2.0","centos":">= 7.0","debian":">= 9.0","oracle":">= 7.0","redhat":">= 7.0","scientific":">= 7.0","ubuntu":">= 16.04"},"dependencies":{"yum-epel":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/sous-chefs/php","issues_url":"https://github.com/sous-chefs/php/issues","chef_version":[[">= 14.0"]],"ohai_version":[]} \ No newline at end of file diff --git a/cookbooks/php/recipes/ini.rb b/cookbooks/php/recipes/ini.rb index df348d7..6a92f05 100644 --- a/cookbooks/php/recipes/ini.rb +++ b/cookbooks/php/recipes/ini.rb @@ -18,6 +18,26 @@ # limitations under the License. # +if node['php']['fpm_ini_control'] + + service node['php']['fpm_service'] do + action :enable + end + + template "#{node['php']['fpm_conf_dir']}/php.ini" do + source node['php']['ini']['template'] + cookbook node['php']['ini']['cookbook'] + owner 'root' + group node['root_group'] + mode '0644' + manage_symlink_source true + variables(directives: node['php']['directives']) + notifies :restart, "service[#{node['php']['fpm_service']}]" + not_if { node['php']['fpm_conf_dir'].nil? } + end + +end + template "#{node['php']['conf_dir']}/php.ini" do source node['php']['ini']['template'] cookbook node['php']['ini']['cookbook'] diff --git a/cookbooks/php/recipes/package.rb b/cookbooks/php/recipes/package.rb index b361ff2..c77b0ee 100644 --- a/cookbooks/php/recipes/package.rb +++ b/cookbooks/php/recipes/package.rb @@ -19,16 +19,8 @@ # limitations under the License. # -if platform_family?('rhel', 'debian', 'amazon', 'suse') - package node['php']['packages'] do - options node['php']['package_options'] - end -else - node['php']['packages'].each do |pkg| - package pkg do - options node['php']['package_options'] - end - end +package node['php']['packages'] do + options node['php']['package_options'] end include_recipe 'php::ini' diff --git a/cookbooks/php/recipes/recompile.rb b/cookbooks/php/recipes/recompile.rb index 46398cb..fce1ad9 100644 --- a/cookbooks/php/recipes/recompile.rb +++ b/cookbooks/php/recipes/recompile.rb @@ -18,34 +18,6 @@ # limitations under the License. # -version = node['php']['version'] -configure_options = node['php']['configure_options'].join(' ') -ext_dir_prefix = node['php']['ext_dir'] ? "EXTENSION_DIR=#{node['php']['ext_dir']}" : '' +node.default['php']['src_recompile'] = true -node['php']['src_deps'].each do |pkg| - package pkg do - action 'install' - end -end - -remote_file "#{Chef::Config[:file_cache_path]}/php-#{version}.tar.gz" do - source "#{node['php']['url']}/php-#{version}.tar.gz/from/this/mirror" - checksum node['php']['checksum'] - mode '0644' - action 'create_if_missing' -end - -bash 'un-pack php' do - cwd Chef::Config[:file_cache_path] - code "tar -zxf php-#{version}.tar.gz" - creates "#{Chef::Config[:file_cache_path]}/php-#{version}" -end - -bash 're-build php' do - cwd "#{Chef::Config[:file_cache_path]}/php-#{version}" - code <<-EOF - (make clean) - (#{ext_dir_prefix} ./configure #{configure_options}) - (make -j #{node['cpu']['total']} && make install) - EOF -end +include_recipe 'php::source' diff --git a/cookbooks/php/recipes/source.rb b/cookbooks/php/recipes/source.rb index 407fab9..731440f 100644 --- a/cookbooks/php/recipes/source.rb +++ b/cookbooks/php/recipes/source.rb @@ -18,20 +18,41 @@ # limitations under the License. # -configure_options = node['php']['configure_options'].join(' ') +if platform?('debian') && node['platform_version'].to_i == 9 + Chef::Log.fatal 'Debian 9 is not supported when building from source' +end -build_essential 'install compilation tools' -include_recipe 'yum-epel' if node['platform_family'] == 'rhel' +version = node['php']['version'] +configure_options = node['php']['configure_options'].join(' ') +ext_dir_prefix = node['php']['ext_dir'] ? "EXTENSION_DIR=#{node['php']['ext_dir']}" : '' + +php_exists = if node['php']['src_recompile'] + false + else + "$(which #{node['php']['bin']}) --version | grep #{version}" + end + +build_essential + +include_recipe 'yum-epel' if platform_family?('rhel', 'amazon') package node['php']['src_deps'] -version = node['php']['version'] +log "php_exists == #{php_exists}" remote_file "#{Chef::Config[:file_cache_path]}/php-#{version}.tar.gz" do - source "#{node['php']['url']}/php-#{version}.tar.gz/from/this/mirror" + source "#{node['php']['url']}/php-#{version}.tar.gz" checksum node['php']['checksum'] - mode '0644' - not_if "$(which #{node['php']['bin']}) --version | grep #{version}" + action :create_if_missing + not_if php_exists + notifies :run, 'execute[un-pack php]', :immediately +end + +execute 'un-pack php' do + cwd Chef::Config[:file_cache_path] + command "tar -zxf php-#{version}.tar.gz" + creates "#{Chef::Config[:file_cache_path]}/php-#{version}" + action :nothing end if node['php']['ext_dir'] @@ -41,26 +62,31 @@ if node['php']['ext_dir'] mode '0755' recursive true end - ext_dir_prefix = "EXTENSION_DIR=#{node['php']['ext_dir']}" -else - ext_dir_prefix = '' end -# PHP is unable to find the GMP library in 16.04. The symlink brings the file -# inside of the include libraries. +# PHP is unable to find the GMP library on Ubuntu 16.04 +# This symlink brings the file inside of the included libraries link '/usr/include/gmp.h' do to '/usr/include/x86_64-linux-gnu/gmp.h' - only_if { node['platform_family'] == 'debian' && node['platform_version'].to_f >= 14.04 } + only_if { platform?('ubuntu') && node['platform_version'].to_f == 16.04 } end -bash 'build php' do - cwd Chef::Config[:file_cache_path] - code <<-EOF - tar -zxf php-#{version}.tar.gz - (cd php-#{version} && #{ext_dir_prefix} ./configure #{configure_options}) - (cd php-#{version} && make -j #{node['cpu']['total']} && make install) - EOF - not_if "$(which #{node['php']['bin']}) --version | grep #{version}" +execute 'clean build' do + cwd "#{Chef::Config[:file_cache_path]}/php-#{version}" + command 'make clean' + only_if { node['php']['src_recompile'] } +end + +execute 'configure php' do + cwd "#{Chef::Config[:file_cache_path]}/php-#{version}" + command "#{ext_dir_prefix} ./configure #{configure_options}" + not_if php_exists +end + +execute 'build and install php' do + cwd "#{Chef::Config[:file_cache_path]}/php-#{version}" + command "make -j #{node['cpu']['total']} && make install" + not_if php_exists end directory node['php']['conf_dir'] do diff --git a/cookbooks/php/resources/pear.rb b/cookbooks/php/resources/pear.rb index c4aea46..2d7de7f 100644 --- a/cookbooks/php/resources/pear.rb +++ b/cookbooks/php/resources/pear.rb @@ -19,14 +19,14 @@ # property :package_name, String, name_property: true -property :version, [String, nil], default: nil +property :version, [String, nil] property :channel, String property :options, String property :directives, Hash, default: {} property :zend_extensions, Array, default: [] property :preferred_state, String, default: 'stable' property :binary, String, default: 'pear' -property :priority, [String, nil], default: nil +property :priority, [String, nil] def current_installed_version(new_resource) version_check_cmd = "#{new_resource.binary} -d" @@ -69,6 +69,8 @@ load_current_value do |new_resource| end action :install do + build_essential + # If we specified a version, and it's not the current version, move to the specified version install_version = new_resource.version unless new_resource.version.nil? || new_resource.version == current_resource.version # Check if the version we want is already installed @@ -87,6 +89,8 @@ end # reinstall is just an install that always fires action :reinstall do + build_essential + install_version = new_resource.version unless new_resource.version.nil? converge_by("reinstall package #{new_resource.package_name} #{install_version}") do info_output = "Installing #{new_resource.package_name}" @@ -214,7 +218,14 @@ action_class do def get_extension_files(name) files = [] - p = shell_out("#{new_resource.binary} list-files #{name}") + # use appropriate binary when listing pecl packages + list_binary = if new_resource.channel == 'pecl.php.net' + node['php']['pecl'] + else + new_resource.binary + end + + p = shell_out("#{list_binary} list-files #{name}") p.stdout.each_line.grep(/^src\s+.*\.so$/i).each do |line| files << line.split[1] end @@ -231,7 +242,11 @@ action_class do search_args << " search#{expand_channel(new_resource.channel)} #{new_resource.package_name}" if grep_for_version(shell_out(new_resource.binary + search_args).stdout, new_resource.package_name) - false + if (new_resource.binary.include? 'pecl') || (new_resource.channel == 'pecl.php.net') + true + else + false + end elsif grep_for_version(shell_out(node['php']['pecl'] + search_args).stdout, new_resource.package_name) true else @@ -276,5 +291,10 @@ action_class do ) action action end + + execute "#{node['php']['enable_mod']} #{name}" do + creates "#{node['php']['conf_dir']}/conf.d/#{name}" + only_if { platform_family? 'debian' } + end end end diff --git a/cookbooks/php/resources/pear_channel.rb b/cookbooks/php/resources/pear_channel.rb index 96a244e..40db5d3 100644 --- a/cookbooks/php/resources/pear_channel.rb +++ b/cookbooks/php/resources/pear_channel.rb @@ -22,9 +22,6 @@ property :channel_xml, String property :channel_name, String, name_property: true property :binary, String, default: 'pear' -# TODO: add authenticated channel support! -# property :username, :kind_of => String -# property :password, :kind_of => String action :discover do unless exists? diff --git a/cookbooks/php/templates/default/extension.ini.erb b/cookbooks/php/templates/default/extension.ini.erb index 13c5122..4cc47a0 100644 --- a/cookbooks/php/templates/default/extension.ini.erb +++ b/cookbooks/php/templates/default/extension.ini.erb @@ -1,4 +1,7 @@ ; configuration for php <%= @name %> module +<% if @priority %> +; priority=<%= @priority %> +<% end -%> <% @extensions.each do |filepath, zend| -%> <%= 'zend_' if zend %>extension=<%= filepath %> <% end -%> diff --git a/cookbooks/php/templates/default/php.ini.erb b/cookbooks/php/templates/default/php.ini.erb index 6c3f990..3d0fe7f 100644 --- a/cookbooks/php/templates/default/php.ini.erb +++ b/cookbooks/php/templates/default/php.ini.erb @@ -19,7 +19,7 @@ ; See the PHP docs for more specific information. ; http://php.net/configuration.file -; The syntax of the file is extremely simple. Whitespace and Lines +; The syntax of the file is extremely simple. Whitespace and lines ; beginning with a semicolon are silently ignored (as you probably guessed). ; Section headers (e.g. [Foo]) are also silently ignored, even though ; they might mean something in the future. @@ -78,9 +78,9 @@ ; compatibility with older or less security conscience applications. We ; recommending using the production ini in production and testing environments. -; php.ini-development is very similar to its production variant, except it's -; much more verbose when it comes to errors. We recommending using the -; development version only in development environments as errors shown to +; php.ini-development is very similar to its production variant, except it is +; much more verbose when it comes to errors. We recommend using the +; development version only in development environments, as errors shown to ; application users can inadvertently leak otherwise secure information. ;;;;;;;;;;;;;;;;;;; @@ -102,25 +102,20 @@ ; Production Value: Off ; error_reporting -; Default Value: E_ALL & ~E_NOTICE -; Development Value: E_ALL | E_STRICT -; Production Value: E_ALL & ~E_DEPRECATED +; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED +; Development Value: E_ALL +; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT ; html_errors ; Default Value: On ; Development Value: On -; Production value: Off +; Production value: On ; log_errors ; Default Value: Off ; Development Value: On ; Production Value: On -; magic_quotes_gpc -; Default Value: On -; Development Value: Off -; Production Value: Off - ; max_input_time ; Default Value: -1 (Unlimited) ; Development Value: 60 (60 seconds) @@ -136,32 +131,17 @@ ; Development Value: Off ; Production Value: Off -; register_long_arrays -; Default Value: On -; Development Value: Off -; Production Value: Off - ; request_order ; Default Value: None ; Development Value: "GP" ; Production Value: "GP" -; session.bug_compat_42 -; Default Value: On -; Development Value: On -; Production Value: Off - -; session.bug_compat_warn -; Default Value: On -; Development Value: On -; Production Value: Off - ; session.gc_divisor ; Default Value: 100 ; Development Value: 1000 ; Production Value: 1000 -; session.hash_bits_per_character +; session.sid_bits_per_character ; Default Value: 4 ; Development Value: 5 ; Production Value: 5 @@ -176,11 +156,6 @@ ; Development Value: On ; Production Value: Off -; url_rewriter.tags -; Default Value: "a=href,area=href,frame=src,form=,fieldset=" -; Development Value: "a=href,area=href,frame=src,input=src,form=fakeentry" -; Production Value: "a=href,area=href,frame=src,input=src,form=fakeentry" - ; variables_order ; Default Value: "EGPCS" ; Development Value: "GPCS" @@ -207,23 +182,18 @@ engine = On ; This directive determines whether or not PHP will recognize code between -; tags as PHP source which should be processed as such. It's been -; recommended for several years that you not use the short tag "short cut" and -; instead to use the full tag combination. With the wide spread use -; of XML and use of these tags by other languages, the server can become easily -; confused and end up parsing the wrong code in the wrong context. But because -; this short cut has been a feature for such a long time, it's currently still -; supported for backwards compatibility, but we recommend you don't use them. +; tags as PHP source which should be processed as such. It is +; generally recommended that should be used and that this feature +; should be disabled, as enabling it may result in issues when generating XML +; documents, however this remains supported for backward compatibility reasons. +; Note that this directive does not control the tags. -; http://php.net/asp-tags -asp_tags = Off - ; The number of significant digits displayed in floating point numbers. ; http://php.net/precision precision = 14 @@ -267,6 +237,23 @@ output_buffering = 4096 ; http://php.net/output-handler ;output_handler = +; URL rewriter function rewrites URL on the fly by using +; output buffer. You can set target tags by this configuration. +; "form" tag is special tag. It will add hidden input tag to pass values. +; Refer to session.trans_sid_tags for usage. +; Default Value: "form=" +; Development Value: "form=" +; Production Value: "form=" +;url_rewriter.tags + +; URL rewriter will not rewrites absolute URL nor form by default. To enable +; absolute URL rewrite, allowed hosts must be defined at RUNTIME. +; Refer to session.trans_sid_hosts for more details. +; Default Value: "" +; Development Value: "" +; Production Value: "" +;url_rewriter.hosts + ; Transparent output compression using the zlib library ; Valid values for this option are 'off', 'on', or a specific buffer size ; to be used for compression (default is 4KB) @@ -305,65 +292,28 @@ implicit_flush = Off ; callback-function. unserialize_callback_func = -; When floats & doubles are serialized store serialize_precision significant +; When floats & doubles are serialized, store serialize_precision significant ; digits after the floating point. The default value ensures that when floats ; are decoded with unserialize, the data will remain the same. -serialize_precision = 100 - -; Safe Mode -; http://php.net/safe-mode -safe_mode = Off - -; By default, Safe Mode does a UID compare check when -; opening files. If you want to relax this to a GID compare, -; then turn on safe_mode_gid. -; http://php.net/safe-mode-gid -safe_mode_gid = Off - -; When safe_mode is on, UID/GID checks are bypassed when -; including files from this directory and its subdirectories. -; (directory must also be in include_path or full path must -; be used when including) -; http://php.net/safe-mode-include-dir -safe_mode_include_dir = - -; When safe_mode is on, only executables located in the safe_mode_exec_dir -; will be allowed to be executed via the exec family of functions. -; http://php.net/safe-mode-exec-dir -safe_mode_exec_dir = - -; Setting certain environment variables may be a potential security breach. -; This directive contains a comma-delimited list of prefixes. In Safe Mode, -; the user may only alter environment variables whose names begin with the -; prefixes supplied here. By default, users will only be able to set -; environment variables that begin with PHP_ (e.g. PHP_FOO=BAR). -; Note: If this directive is empty, PHP will let the user modify ANY -; environment variable! -; http://php.net/safe-mode-allowed-env-vars -safe_mode_allowed_env_vars = PHP_ - -; This directive contains a comma-delimited list of environment variables that -; the end user won't be able to change using putenv(). These variables will be -; protected even if safe_mode_allowed_env_vars is set to allow to change them. -; http://php.net/safe-mode-protected-env-vars -safe_mode_protected_env_vars = LD_LIBRARY_PATH +; The value is also used for json_encode when encoding double values. +; If -1 is used, then dtoa mode 0 is used which automatically select the best +; precision. +serialize_precision = -1 ; open_basedir, if set, limits all file operations to the defined directory ; and below. This directive makes most sense if used in a per-directory -; or per-virtualhost web server configuration file. This directive is -; *NOT* affected by whether Safe Mode is turned On or Off. +; or per-virtualhost web server configuration file. +; Note: disables the realpath cache ; http://php.net/open-basedir ;open_basedir = ; This directive allows you to disable certain functions for security reasons. -; It receives a comma-delimited list of function names. This directive is -; *NOT* affected by whether Safe Mode is turned On or Off. +; It receives a comma-delimited list of function names. ; http://php.net/disable-functions disable_functions = ; This directive allows you to disable certain classes for security reasons. -; It receives a comma-delimited list of class names. This directive is -; *NOT* affected by whether Safe Mode is turned On or Off. +; It receives a comma-delimited list of class names. ; http://php.net/disable-classes disable_classes = @@ -373,7 +323,6 @@ disable_classes = ;highlight.string = #DD0000 ;highlight.comment = #FF9900 ;highlight.keyword = #007700 -;highlight.bg = #FFFFFF ;highlight.default = #0000BB ;highlight.html = #000000 @@ -387,8 +336,9 @@ disable_classes = ; Determines the size of the realpath cache to be used by PHP. This value should ; be increased on systems where PHP opens many files to reflect the quantity of ; the file operations performed. +; Note: if open_basedir is set, the cache is disabled ; http://php.net/realpath-cache-size -;realpath_cache_size = 16k +;realpath_cache_size = 4096k ; Duration of time, in seconds for which to cache realpath information for a given ; file or directory. For systems with rarely changing files, consider increasing this @@ -396,6 +346,22 @@ disable_classes = ; http://php.net/realpath-cache-ttl ;realpath_cache_ttl = 120 +; Enables or disables the circular reference collector. +; http://php.net/zend.enable-gc +zend.enable_gc = On + +; If enabled, scripts may be written in encodings that are incompatible with +; the scanner. CP936, Big5, CP949 and Shift_JIS are the examples of such +; encodings. To use this feature, mbstring extension must be enabled. +; Default: Off +;zend.multibyte = Off + +; Allows to set the default encoding for the scripts. This value will be used +; unless "declare(encoding=...)" directive appears at the top of the script. +; Only affects if zend.multibyte is set. +; Default: "" +;zend.script_encoding = + ;;;;;;;;;;;;;;;;; ; Miscellaneous ; ;;;;;;;;;;;;;;;;; @@ -430,6 +396,9 @@ max_input_time = 60 ; http://php.net/max-input-nesting-level ;max_input_nesting_level = 64 +; How many GET/POST/COOKIE input variables may be accepted +; max_input_vars = 1000 + ; Maximum amount of memory a script may consume (128MB) ; http://php.net/memory-limit memory_limit = 128M @@ -449,12 +418,12 @@ memory_limit = 128M ; recommend error reporting setting. Your production server shouldn't be wasting ; resources complaining about best practices and coding standards. That's what ; development servers and development settings are for. -; Note: The php.ini-development file has this setting as E_ALL | E_STRICT. This +; Note: The php.ini-development file has this setting as E_ALL. This ; means it pretty much reports everything which is exactly what you want during ; development and early testing. ; ; Error Level Constants: -; E_ALL - All errors and warnings (includes E_STRICT as of PHP 6.0.0) +; E_ALL - All errors and warnings (includes E_STRICT as of PHP 5.4.0) ; E_ERROR - fatal run-time errors ; E_RECOVERABLE_ERROR - almost fatal run-time errors ; E_WARNING - run-time warnings (non-fatal errors) @@ -462,7 +431,7 @@ memory_limit = 128M ; E_NOTICE - run-time notices (these are warnings which often result ; from a bug in your code, but it's possible that it was ; intentional (e.g., using an uninitialized variable and -; relying on the fact it's automatically initialized to an +; relying on the fact it is automatically initialized to an ; empty string) ; E_STRICT - run-time notices, enable to have PHP suggest changes ; to your code which will ensure the best interoperability @@ -480,23 +449,23 @@ memory_limit = 128M ; E_USER_DEPRECATED - user-generated deprecation warnings ; ; Common Values: -; E_ALL & ~E_NOTICE (Show all errors, except for notices and coding standards warnings.) -; E_ALL & ~E_NOTICE | E_STRICT (Show all errors, except for notices) +; E_ALL (Show all errors, warnings and notices including coding standards.) +; E_ALL & ~E_NOTICE (Show all errors, except for notices) +; E_ALL & ~E_NOTICE & ~E_STRICT (Show all errors, except for notices and coding standards warnings.) ; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors) -; E_ALL | E_STRICT (Show all errors, warnings and notices including coding standards.) -; Default Value: E_ALL & ~E_NOTICE -; Development Value: E_ALL | E_STRICT -; Production Value: E_ALL & ~E_DEPRECATED +; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED +; Development Value: E_ALL +; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT ; http://php.net/error-reporting -error_reporting = E_ALL & ~E_DEPRECATED +error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT ; This directive controls whether or not and where PHP will output errors, ; notices and warnings too. Error output is very useful during development, but ; it could be very dangerous in production environments. Depending on the code ; which is triggering the error, sensitive information could potentially leak ; out of your application such as database usernames and passwords or worse. -; It's recommended that errors be logged on production servers rather than -; having the errors sent to STDOUT. +; For production environments, we recommend logging errors rather than +; sending them to STDOUT. ; Possible Values: ; Off = Do not display any errors ; stderr = Display errors to STDERR (affects only CGI/CLI binaries!) @@ -510,8 +479,8 @@ display_errors = Off ; The display of errors which occur during PHP's startup sequence are handled ; separately from display_errors. PHP's default behavior is to suppress those ; errors from clients. Turning the display of startup errors on can be useful in -; debugging configuration problems. But, it's strongly recommended that you -; leave this setting off on production servers. +; debugging configuration problems. We strongly recommend you +; set this to 'off' for production servers. ; Default Value: Off ; Development Value: On ; Production Value: Off @@ -556,11 +525,12 @@ report_memleaks = On ; Store the last error/warning message in $php_errormsg (boolean). Setting this value ; to On can assist in debugging and is appropriate for development servers. It should ; however be disabled on production servers. +; This directive is DEPRECATED. ; Default Value: Off -; Development Value: On +; Development Value: Off ; Production Value: Off ; http://php.net/track-errors -track_errors = Off +;track_errors = Off ; Turn off normal error reporting and emit XML-RPC error XML ; http://php.net/xmlrpc-errors @@ -569,23 +539,24 @@ track_errors = Off ; An XML-RPC faultCode ;xmlrpc_error_number = 0 -; When PHP displays or logs an error, it has the capability of inserting html -; links to documentation related to that error. This directive controls whether -; those HTML links appear in error messages or not. For performance and security -; reasons, it's recommended you disable this on production servers. +; When PHP displays or logs an error, it has the capability of formatting the +; error message as HTML for easier reading. This directive controls whether +; the error message is formatted as HTML or not. ; Note: This directive is hardcoded to Off for the CLI SAPI ; Default Value: On ; Development Value: On -; Production value: Off +; Production value: On ; http://php.net/html-errors -html_errors = Off +html_errors = On -; If html_errors is set On PHP produces clickable error messages that direct -; to a page describing the error or function causing the error in detail. +; If html_errors is set to On *and* docref_root is not empty, then PHP +; produces clickable error messages that direct to a page describing the error +; or function causing the error in detail. ; You can download a copy of the PHP manual from http://php.net/docs ; and change docref_root to the base URL of your local copy including the ; leading '/'. You must also specify the file extension being used including -; the dot. PHP's default behavior is to leave these settings empty. +; the dot. PHP's default behavior is to leave these settings empty, in which +; case no links to documentation are generated. ; Note: Never use this feature for production boxes. ; http://php.net/docref-root ; Examples @@ -598,22 +569,27 @@ html_errors = Off ; this setting blank. ; http://php.net/error-prepend-string ; Example: -;error_prepend_string = "" +;error_prepend_string = "" ; String to output after an error message. PHP's default behavior is to leave ; this setting blank. ; http://php.net/error-append-string ; Example: -;error_append_string = "" +;error_append_string = "" ; Log errors to specified file. PHP's default behavior is to leave this value ; empty. ; http://php.net/error-log ; Example: ;error_log = php_errors.log -; Log errors to syslog (Event Log on NT, not valid in Windows 95). +; Log errors to syslog (Event Log on Windows). ;error_log = syslog +;windows.show_crt_warning +; Default value: 0 +; Development value: 0 +; Production value: 0 + ;;;;;;;;;;;;;;;;; ; Data Handling ; ;;;;;;;;;;;;;;;;; @@ -632,51 +608,31 @@ html_errors = Off ;arg_separator.input = ";&" ; This directive determines which super global arrays are registered when PHP -; starts up. If the register_globals directive is enabled, it also determines -; what order variables are populated into the global space. G,P,C,E & S are -; abbreviations for the following respective super globals: GET, POST, COOKIE, -; ENV and SERVER. There is a performance penalty paid for the registration of -; these arrays and because ENV is not as commonly used as the others, ENV is -; is not recommended on productions servers. You can still get access to -; the environment variables through getenv() should you need to. +; starts up. G,P,C,E & S are abbreviations for the following respective super +; globals: GET, POST, COOKIE, ENV and SERVER. There is a performance penalty +; paid for the registration of these arrays and because ENV is not as commonly +; used as the others, ENV is not recommended on productions servers. You +; can still get access to the environment variables through getenv() should you +; need to. ; Default Value: "EGPCS" ; Development Value: "GPCS" ; Production Value: "GPCS"; ; http://php.net/variables-order variables_order = "GPCS" -; This directive determines which super global data (G,P,C,E & S) should -; be registered into the super global array REQUEST. If so, it also determines -; the order in which that data is registered. The values for this directive are -; specified in the same manner as the variables_order directive, EXCEPT one. -; Leaving this value empty will cause PHP to use the value set in the -; variables_order directive. It does not mean it will leave the super globals -; array REQUEST empty. +; This directive determines which super global data (G,P & C) should be +; registered into the super global array REQUEST. If so, it also determines +; the order in which that data is registered. The values for this directive +; are specified in the same manner as the variables_order directive, +; EXCEPT one. Leaving this value empty will cause PHP to use the value set +; in the variables_order directive. It does not mean it will leave the super +; globals array REQUEST empty. ; Default Value: None ; Development Value: "GP" ; Production Value: "GP" ; http://php.net/request-order request_order = "GP" -; Whether or not to register the EGPCS variables as global variables. You may -; want to turn this off if you don't want to clutter your scripts' global scope -; with user data. -; You should do your best to write your scripts so that they do not require -; register_globals to be on; Using form variables as globals can easily lead -; to possible security problems, if the code is not very well thought of. -; http://php.net/register-globals -register_globals = Off - -; Determines whether the deprecated long $HTTP_*_VARS type predefined variables -; are registered by PHP or not. As they are deprecated, we obviously don't -; recommend you use them. They are on by default for compatibility reasons but -; they are not recommended on production servers. -; Default Value: On -; Development Value: Off -; Production Value: Off -; http://php.net/register-long-arrays -register_long_arrays = Off - ; This directive determines whether PHP registers $argv & $argc each time it ; runs. $argv contains an array of all the arguments passed to PHP when a script ; is invoked. $argc contains an integer representing the number of arguments @@ -692,42 +648,29 @@ register_long_arrays = Off ; http://php.net/register-argc-argv register_argc_argv = Off -; When enabled, the SERVER and ENV variables are created when they're first -; used (Just In Time) instead of when the script starts. If these variables -; are not used within a script, having this directive on will result in a -; performance gain. The PHP directives register_globals, register_long_arrays, -; and register_argc_argv must be disabled for this directive to have any affect. +; When enabled, the ENV, REQUEST and SERVER variables are created when they're +; first used (Just In Time) instead of when the script starts. If these +; variables are not used within a script, having this directive on will result +; in a performance gain. The PHP directive register_argc_argv must be disabled +; for this directive to have any affect. ; http://php.net/auto-globals-jit auto_globals_jit = On +; Whether PHP will read the POST data. +; This option is enabled by default. +; Most likely, you won't want to disable this option globally. It causes $_POST +; and $_FILES to always be empty; the only way you will be able to read the +; POST data will be through the php://input stream wrapper. This can be useful +; to proxy requests or to process the POST data in a memory efficient fashion. +; http://php.net/enable-post-data-reading +;enable_post_data_reading = Off + ; Maximum size of POST data that PHP will accept. +; Its value may be 0 to disable the limit. It is ignored if POST data reading +; is disabled through enable_post_data_reading. ; http://php.net/post-max-size post_max_size = 8M -; Magic quotes are a preprocessing feature of PHP where PHP will attempt to -; escape any character sequences in GET, POST, COOKIE and ENV data which might -; otherwise corrupt data being placed in resources such as databases before -; making that data available to you. Because of character encoding issues and -; non-standard SQL implementations across many databases, it's not currently -; possible for this feature to be 100% accurate. PHP's default behavior is to -; enable the feature. We strongly recommend you use the escaping mechanisms -; designed specifically for the database your using instead of relying on this -; feature. Also note, this feature has been deprecated as of PHP 5.3.0 and is -; scheduled for removal in PHP 6. -; Default Value: On -; Development Value: Off -; Production Value: Off -; http://php.net/magic-quotes-gpc -magic_quotes_gpc = Off - -; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc. -; http://php.net/magic-quotes-runtime -magic_quotes_runtime = Off - -; Use Sybase-style magic quotes (escape ' with '' instead of \'). -; http://php.net/magic-quotes-sybase -magic_quotes_sybase = Off - ; Automatically add files before PHP document. ; http://php.net/auto-prepend-file auto_prepend_file = @@ -736,22 +679,32 @@ auto_prepend_file = ; http://php.net/auto-append-file auto_append_file = -; By default, PHP will output a character encoding using -; the Content-type: header. To disable sending of the charset, simply -; set it to be empty. +; By default, PHP will output a media type using the Content-Type header. To +; disable this, simply set it to be empty. ; -; PHP's built-in default is text/html +; PHP's built-in default media type is set to text/html. ; http://php.net/default-mimetype default_mimetype = "text/html" -; PHP's default character set is set to empty. +; PHP's default character set is set to UTF-8. ; http://php.net/default-charset -;default_charset = "iso-8859-1" +default_charset = "UTF-8" -; Always populate the $HTTP_RAW_POST_DATA variable. PHP's default behavior is -; to disable this feature. -; http://php.net/always-populate-raw-post-data -;always_populate_raw_post_data = On +; PHP internal character encoding is set to empty. +; If empty, default_charset is used. +; http://php.net/internal-encoding +;internal_encoding = + +; PHP input character encoding is set to empty. +; If empty, default_charset is used. +; http://php.net/input-encoding +;input_encoding = + +; PHP output character encoding is set to empty. +; If empty, default_charset is used. +; See also output_buffer. +; http://php.net/output-encoding +;output_encoding = ;;;;;;;;;;;;;;;;;;;;;;;;; ; Paths and Directories ; @@ -785,6 +738,10 @@ user_dir = ; On windows: ; extension_dir = "ext" +; Directory where the temporary files should be placed. +; Defaults to the system default (see sys_get_temp_dir) +; sys_temp_dir = "/tmp" + ; Whether or not to enable the dl() function. The dl() function does NOT work ; properly in multithreaded servers, such as IIS or Zeus, and is automatically ; disabled on them. @@ -807,7 +764,7 @@ enable_dl = Off ; will look for to know it is OK to continue execution. Setting this variable MAY ; cause security issues, KNOW WHAT YOU ARE DOING FIRST. ; http://php.net/cgi.redirect-status-env -;cgi.redirect_status_env = ; +;cgi.redirect_status_env = ; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's ; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok @@ -818,26 +775,38 @@ enable_dl = Off ; http://php.net/cgi.fix-pathinfo ;cgi.fix_pathinfo=1 +; if cgi.discard_path is enabled, the PHP CGI binary can safely be placed outside +; of the web tree and people will not be able to circumvent .htaccess security. +; http://php.net/cgi.dicard-path +;cgi.discard_path=1 + ; FastCGI under IIS (on WINNT based OS) supports the ability to impersonate ; security tokens of the calling client. This allows IIS to define the ; security context that the request runs under. mod_fastcgi under Apache ; does not currently support this feature (03/17/2002) ; Set to 1 if running under IIS. Default is zero. ; http://php.net/fastcgi.impersonate -;fastcgi.impersonate = 1; +;fastcgi.impersonate = 1 ; Disable logging through FastCGI connection. PHP's default behavior is to enable ; this feature. ;fastcgi.logging = 0 ; cgi.rfc2616_headers configuration option tells PHP what type of headers to -; use when sending HTTP response code. If it's set 0 PHP sends Status: header that -; is supported by Apache. When this option is set to 1 PHP will send +; use when sending HTTP response code. If set to 0, PHP sends Status: header that +; is supported by Apache. When this option is set to 1, PHP will send ; RFC2616 compliant header. ; Default is zero. ; http://php.net/cgi.rfc2616-headers ;cgi.rfc2616_headers = 0 +; cgi.check_shebang_line controls whether CGI PHP checks for line starting with #! +; (shebang) at the top of the running script. This line might be needed if the +; script support running both as stand-alone script and via PHP CGI<. PHP in CGI +; mode skips this line and ignores its content if this directive is turned on. +; http://php.net/cgi.check-shebang-line +;cgi.check_shebang_line=1 + ;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;; @@ -898,71 +867,72 @@ default_socket_timeout = 60 ; If you wish to have an extension loaded automatically, use the following ; syntax: ; -; extension=modulename.extension +; extension=modulename ; -; For example, on Windows: +; For example: ; -; extension=msql.dll +; extension=mysqli ; -; ... or under UNIX: +; When the extension library to load is not located in the default extension +; directory, You may specify an absolute path to the library file: ; -; extension=msql.so +; extension=/path/to/extension/mysqli.so ; -; ... or with a path: +; Note : The syntax used in previous PHP versions ('extension=.so' and +; 'extension='php_.dll') is supported for legacy reasons and may be +; deprecated in a future PHP major version. So, when it is possible, please +; move to the new ('extension=) syntax. ; -; extension=/path/to/extension/msql.so +; Notes for Windows environments : ; -; If you only provide the name of the extension, PHP will look for it in its -; default extension directory. +; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+) +; extension folders as well as the separate PECL DLL download (PHP 5+). +; Be sure to appropriately set the extension_dir directive. ; -; Windows Extensions -; Note that ODBC support is built in, so no dll is needed for it. -; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5) -; extension folders as well as the separate PECL DLL download (PHP 5). -; Be sure to appropriately set the extension_dir directive. -; -;extension=php_bz2.dll -;extension=php_curl.dll -;extension=php_fileinfo.dll -;extension=php_gd2.dll -;extension=php_gettext.dll -;extension=php_gmp.dll -;extension=php_intl.dll -;extension=php_imap.dll -;extension=php_interbase.dll -;extension=php_ldap.dll -;extension=php_mbstring.dll -;extension=php_exif.dll ; Must be after mbstring as it depends on it -;extension=php_mysql.dll -;extension=php_mysqli.dll -;extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client -;extension=php_oci8_11g.dll ; Use with Oracle 11g Instant Client -;extension=php_openssl.dll -;extension=php_pdo_firebird.dll -;extension=php_pdo_mssql.dll -;extension=php_pdo_mysql.dll -;extension=php_pdo_oci.dll -;extension=php_pdo_odbc.dll -;extension=php_pdo_pgsql.dll -;extension=php_pdo_sqlite.dll -;extension=php_pgsql.dll -;extension=php_pspell.dll -;extension=php_shmop.dll -;extension=php_snmp.dll -;extension=php_soap.dll -;extension=php_sockets.dll -;extension=php_sqlite.dll -;extension=php_sqlite3.dll -;extension=php_sybase_ct.dll -;extension=php_tidy.dll -;extension=php_xmlrpc.dll -;extension=php_xsl.dll -;extension=php_zip.dll +;extension=bz2 +;extension=curl +;extension=fileinfo +;extension=gd2 +;extension=gettext +;extension=gmp +;extension=intl +;extension=imap +;extension=interbase +;extension=ldap +;extension=mbstring +;extension=exif ; Must be after mbstring as it depends on it +;extension=mysqli +;extension=oci8_12c ; Use with Oracle Database 12c Instant Client +;extension=odbc +;extension=openssl +;extension=pdo_firebird +;extension=pdo_mysql +;extension=pdo_oci +;extension=pdo_odbc +;extension=pdo_pgsql +;extension=pdo_sqlite +;extension=pgsql +;extension=shmop + +; The MIBS data available in the PHP distribution must be installed. +; See http://www.php.net/manual/en/snmp.installation.php +;extension=snmp + +;extension=soap +;extension=sockets +;extension=sqlite3 +;extension=tidy +;extension=xmlrpc +;extension=xsl ;;;;;;;;;;;;;;;;;;; ; Module Settings ; ;;;;;;;;;;;;;;;;;;; +[CLI Server] +; Whether the CLI web server uses ANSI color coding in its terminal output. +cli_server.color = On + [Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone @@ -988,9 +958,29 @@ default_socket_timeout = 60 ;filter.default_flags = [iconv] -;iconv.input_encoding = ISO-8859-1 -;iconv.internal_encoding = ISO-8859-1 -;iconv.output_encoding = ISO-8859-1 +; Use of this INI entry is deprecated, use global input_encoding instead. +; If empty, default_charset or input_encoding or iconv.input_encoding is used. +; The precedence is: default_charset < intput_encoding < iconv.input_encoding +;iconv.input_encoding = + +; Use of this INI entry is deprecated, use global internal_encoding instead. +; If empty, default_charset or internal_encoding or iconv.internal_encoding is used. +; The precedence is: default_charset < internal_encoding < iconv.internal_encoding +;iconv.internal_encoding = + +; Use of this INI entry is deprecated, use global output_encoding instead. +; If empty, default_charset or output_encoding or iconv.output_encoding is used. +; The precedence is: default_charset < output_encoding < iconv.output_encoding +; To use an output encoding conversion, iconv's output handler must be set +; otherwise output encoding conversion cannot be performed. +;iconv.output_encoding = + +[imap] +; rsh/ssh logins are disabled by default. Use this INI entry if you want to +; enable them. Note that the IMAP library does not filter mailbox names before +; passing them to rsh/ssh command, thus passing untrusted data to this function +; with rsh/ssh enabled is insecure. +;imap.enable_insecure_rsh=0 [intl] ;intl.default_locale = @@ -998,14 +988,22 @@ default_socket_timeout = 60 ; happens within intl functions. The value is the level of the error produced. ; Default is 0, which does not produce any errors. ;intl.error_level = E_WARNING - -[sqlite] -; http://php.net/sqlite.assoc-case -;sqlite.assoc_case = 0 +;intl.use_exceptions = 0 [sqlite3] +; Directory pointing to SQLite3 extensions +; http://php.net/sqlite3.extension-dir ;sqlite3.extension_dir = +; SQLite defensive mode flag (only available from SQLite 3.26+) +; When the defensive flag is enabled, language features that allow ordinary +; SQL to deliberately corrupt the database file are disabled. This forbids +; writing directly to the schema, shadow tables (eg. FTS data tables), or +; the sqlite_dbpage virtual table. +; https://www.sqlite.org/c3ref/c_dbconfig_defensive.html +; (for older SQLite versions, this flag has no use) +;sqlite3.defensive = 1 + [Pcre] ;PCRE library backtracking limit. ; http://php.net/pcre.backtrack-limit @@ -1018,6 +1016,10 @@ default_socket_timeout = 60 ; http://php.net/pcre.recursion-limit ;pcre.recursion_limit=100000 +;Enables or disables JIT compilation of patterns. This requires the PCRE +;library to be compiled with JIT support. +;pcre.jit=1 + [Pdo] ; Whether to pool ODBC connections. Can be one of "strict", "relaxed" or "off" ; http://php.net/pdo-odbc.connection-pooling @@ -1044,13 +1046,6 @@ pdo_mysql.default_socket= ;phar.cache_list = -[Syslog] -; Whether or not to define the various syslog variables (e.g. $LOG_PID, -; $LOG_CRON, etc.). Turning it off is a good idea performance-wise. In -; runtime, you can define these variables by calling define_syslog_variables(). -; http://php.net/define-syslog-variables -define_syslog_variables = Off - [mail function] ; For Win32 only. ; http://php.net/smtp @@ -1068,19 +1063,17 @@ smtp_port = 25 ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of -; the 5th parameter to mail(), even in safe mode. +; the 5th parameter to mail(). ;mail.force_extra_parameters = ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename -mail.add_x_header = On +mail.add_x_header = Off ; The path to a log file that will log all mail() calls. Log entries include ; the full path of the script, line number, To address and headers. ;mail.log = - -[SQL] -; http://php.net/sql.safe-mode -sql.safe_mode = Off +; Log mail to syslog (Event Log on Windows). +;mail.log = syslog [ODBC] ; http://php.net/odbc.default-db @@ -1156,64 +1149,6 @@ ibase.dateformat = "%Y-%m-%d" ; Default time format. ibase.timeformat = "%H:%M:%S" -[MySQL] -; Allow accessing, from PHP's perspective, local files with LOAD DATA statements -; http://php.net/mysql.allow_local_infile -mysql.allow_local_infile = On - -; Allow or prevent persistent links. -; http://php.net/mysql.allow-persistent -mysql.allow_persistent = On - -; If mysqlnd is used: Number of cache slots for the internal result set cache -; http://php.net/mysql.cache_size -mysql.cache_size = 2000 - -; Maximum number of persistent links. -1 means no limit. -; http://php.net/mysql.max-persistent -mysql.max_persistent = -1 - -; Maximum number of links (persistent + non-persistent). -1 means no limit. -; http://php.net/mysql.max-links -mysql.max_links = -1 - -; Default port number for mysql_connect(). If unset, mysql_connect() will use -; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the -; compile-time value defined MYSQL_PORT (in that order). Win32 will only look -; at MYSQL_PORT. -; http://php.net/mysql.default-port -mysql.default_port = - -; Default socket name for local MySQL connects. If empty, uses the built-in -; MySQL defaults. -; http://php.net/mysql.default-socket -mysql.default_socket = - -; Default host for mysql_connect() (doesn't apply in safe mode). -; http://php.net/mysql.default-host -mysql.default_host = - -; Default user for mysql_connect() (doesn't apply in safe mode). -; http://php.net/mysql.default-user -mysql.default_user = - -; Default password for mysql_connect() (doesn't apply in safe mode). -; Note that this is generally a *bad* idea to store passwords in this file. -; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password") -; and reveal this password! And of course, any users with read access to this -; file will be able to reveal the password as well. -; http://php.net/mysql.default-password -mysql.default_password = - -; Maximum time (in seconds) for connect timeout. -1 means no limit -; http://php.net/mysql.connect-timeout -mysql.connect_timeout = 60 - -; Trace mode. When trace_mode is active (=On), warnings for table/index scans and -; SQL-Errors will be displayed. -; http://php.net/mysql.trace-mode -mysql.trace_mode = Off - [MySQLi] ; Maximum number of persistent links. -1 means no limit. @@ -1268,16 +1203,29 @@ mysqli.default_pw = mysqli.reconnect = Off [mysqlnd] -; Enable / Disable collection of general statstics by mysqlnd which can be +; Enable / Disable collection of general statistics by mysqlnd which can be ; used to tune and monitor MySQL operations. ; http://php.net/mysqlnd.collect_statistics mysqlnd.collect_statistics = On -; Enable / Disable collection of memory usage statstics by mysqlnd which can be +; Enable / Disable collection of memory usage statistics by mysqlnd which can be ; used to tune and monitor MySQL operations. ; http://php.net/mysqlnd.collect_memory_statistics mysqlnd.collect_memory_statistics = Off +; Records communication from all extensions using mysqlnd to the specified log +; file. +; http://php.net/mysqlnd.debug +;mysqlnd.debug = + +; Defines which queries will be logged. +; http://php.net/mysqlnd.log_mask +;mysqlnd.log_mask = 0 + +; Default size of the mysqlnd memory pool, which is used by result sets. +; http://php.net/mysqlnd.mempool_default_size +;mysqlnd.mempool_default_size = 16000 + ; Size of a pre-allocated buffer used when sending commands to MySQL in bytes. ; http://php.net/mysqlnd.net_cmd_buffer_size ;mysqlnd.net_cmd_buffer_size = 2048 @@ -1287,6 +1235,15 @@ mysqlnd.collect_memory_statistics = Off ; http://php.net/mysqlnd.net_read_buffer_size ;mysqlnd.net_read_buffer_size = 32768 +; Timeout for network requests in seconds. +; http://php.net/mysqlnd.net_read_timeout +;mysqlnd.net_read_timeout = 31536000 + +; SHA-256 Authentication Plugin related. File with the MySQL server public RSA +; key. +; http://php.net/mysqlnd.sha256_server_public_key +;mysqlnd.sha256_server_public_key = + [OCI8] ; Connection: Enables privileged connections using external @@ -1340,7 +1297,7 @@ mysqlnd.collect_memory_statistics = Off ; http://php.net/oci8.old-oci-close-semantics ;oci8.old_oci_close_semantics = Off -[PostgresSQL] +[PostgreSQL] ; Allow or prevent persistent links. ; http://php.net/pgsql.allow-persistent pgsql.allow_persistent = On @@ -1368,45 +1325,6 @@ pgsql.ignore_notice = 0 ; http://php.net/pgsql.log-notice pgsql.log_notice = 0 -[Sybase-CT] -; Allow or prevent persistent links. -; http://php.net/sybct.allow-persistent -sybct.allow_persistent = On - -; Maximum number of persistent links. -1 means no limit. -; http://php.net/sybct.max-persistent -sybct.max_persistent = -1 - -; Maximum number of links (persistent + non-persistent). -1 means no limit. -; http://php.net/sybct.max-links -sybct.max_links = -1 - -; Minimum server message severity to display. -; http://php.net/sybct.min-server-severity -sybct.min_server_severity = 10 - -; Minimum client message severity to display. -; http://php.net/sybct.min-client-severity -sybct.min_client_severity = 10 - -; Set per-context timeout -; http://php.net/sybct.timeout -;sybct.timeout= - -;sybct.packet_size - -; The maximum time in seconds to wait for a connection attempt to succeed before returning failure. -; Default: one minute -;sybct.login_timeout= - -; The name of the host you claim to be connecting from, for display by sp_who. -; Default: none -;sybct.hostname= - -; Allows you to define how often deadlocks are to be retried. -1 means "forever". -; Default: 0 -;sybct.deadlock_retry_count= - [bcmath] ; Number of decimal digits for all bcmath functions. ; http://php.net/bcmath.scale @@ -1431,9 +1349,9 @@ session.save_handler = files ; ; where N is an integer. Instead of storing all the session files in ; /path, what this will do is use subdirectories N-levels deep, and -; store the session data in those directories. This is useful if you -; or your OS have problems with lots of files in one directory, and is -; a more efficient layout for servers that handle lots of sessions. +; store the session data in those directories. This is useful if +; your OS has problems with many files in one directory, and is +; a more efficient layout for servers that handle many sessions. ; ; NOTE 1: PHP will not create this directory structure automatically. ; You can use the script in the ext/session dir for that purpose. @@ -1450,6 +1368,14 @@ session.save_handler = files ; http://php.net/session.save-path ;session.save_path = "/tmp" +; Whether to use strict session mode. +; Strict session mode does not accept uninitialized session ID and regenerate +; session ID if browser sends uninitialized session ID. Strict mode protects +; applications from session fixation via session adoption vulnerability. It is +; disabled by default for maximum compatibility, but enabling it is encouraged. +; https://wiki.php.net/rfc/strict_sessions +session.use_strict_mode = 0 + ; Whether to use cookies. ; http://php.net/session.use-cookies session.use_cookies = 1 @@ -1458,9 +1384,9 @@ session.use_cookies = 1 ;session.cookie_secure = ; This option forces PHP to fetch and use a cookie for storing and maintaining -; the session id. We encourage this operation as it's very helpful in combatting +; the session id. We encourage this operation as it's very helpful in combating ; session hijacking when not specifying and managing your own session id. It is -; not the end all be all of session hijacking defense, but it's a good start. +; not the be-all and end-all of session hijacking defense, but it's a good start. ; http://php.net/session.use-only-cookies session.use_only_cookies = 1 @@ -1529,32 +1455,7 @@ session.gc_maxlifetime = 1440 ; collection through a shell script, cron entry, or some other method. ; For example, the following script would is the equivalent of ; setting session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes): -; find /path/to/sessions -cmin +24 | xargs rm - -; PHP 4.2 and less have an undocumented feature/bug that allows you to -; to initialize a session variable in the global scope, even when register_globals -; is disabled. PHP 4.3 and later will warn you, if this feature is used. -; You can disable the feature and the warning separately. At this time, -; the warning is only displayed, if bug_compat_42 is enabled. This feature -; introduces some serious security problems if not handled correctly. It's -; recommended that you do not use this feature on production servers. But you -; should enable this on development servers and enable the warning as well. If you -; do not enable the feature on development servers, you won't be warned when it's -; used and debugging errors caused by this can be difficult to track down. -; Default Value: On -; Development Value: On -; Production Value: Off -; http://php.net/session.bug-compat-42 -session.bug_compat_42 = Off - -; This setting controls whether or not you are warned by PHP when initializing a -; session value into the global space. session.bug_compat_42 must be enabled before -; these warnings can be issued by PHP. See the directive above for more information. -; Default Value: On -; Development Value: On -; Production Value: Off -; http://php.net/session.bug-compat-warn -session.bug_compat_warn = Off +; find /path/to/sessions -cmin +24 -type f | xargs rm ; Check HTTP Referer to invalidate externally stored URLs containing ids. ; HTTP_REFERER has to contain this substring for the session to be @@ -1562,17 +1463,6 @@ session.bug_compat_warn = Off ; http://php.net/session.referer-check session.referer_check = -; How many bytes to read from the file. -; http://php.net/session.entropy-length -session.entropy_length = 0 - -; Specified here to create the session id. -; http://php.net/session.entropy-file -; On systems that don't have /dev/urandom /dev/arandom can be used -; On windows, setting the entropy_length setting will activate the -; Windows random source (using the CryptoAPI) -;session.entropy_file = /dev/urandom - ; Set to {nocache,private,public,} to determine HTTP caching aspects ; or leave this empty to avoid sending anti-caching headers. ; http://php.net/session.cache-limiter @@ -1583,26 +1473,50 @@ session.cache_limiter = nocache session.cache_expire = 180 ; trans sid support is disabled by default. -; Use of trans sid may risk your users security. +; Use of trans sid may risk your users' security. ; Use this option with caution. ; - User may send URL contains active session ID ; to other person via. email/irc/etc. ; - URL that contains active session ID may be stored -; in publically accessible computer. +; in publicly accessible computer. ; - User may access your site with the same session ID ; always using URL stored in browser's history or bookmarks. ; http://php.net/session.use-trans-sid session.use_trans_sid = 0 -; Select a hash function for use in generating session ids. -; Possible Values -; 0 (MD5 128 bits) -; 1 (SHA-1 160 bits) -; This option may also be set to the name of any hash function supported by -; the hash extension. A list of available hashes is returned by the hash_algos() -; function. -; http://php.net/session.hash-function -session.hash_function = 0 +; Set session ID character length. This value could be between 22 to 256. +; Shorter length than default is supported only for compatibility reason. +; Users should use 32 or more chars. +; http://php.net/session.sid-length +; Default Value: 32 +; Development Value: 26 +; Production Value: 26 +session.sid_length = 26 + +; The URL rewriter will look for URLs in a defined set of HTML tags. +;

is special; if you include them here, the rewriter will +; add a hidden field with the info which is otherwise appended +; to URLs. tag's action attribute URL will not be modified +; unless it is specified. +; Note that all valid entries require a "=", even if no value follows. +; Default Value: "a=href,area=href,frame=src,form=" +; Development Value: "a=href,area=href,frame=src,form=" +; Production Value: "a=href,area=href,frame=src,form=" +; http://php.net/url-rewriter.tags +session.trans_sid_tags = "a=href,area=href,frame=src,form=" + +; URL rewriter does not rewrite absolute URLs by default. +; To enable rewrites for absolute pathes, target hosts must be specified +; at RUNTIME. i.e. use ini_set() +; tags is special. PHP will check action attribute's URL regardless +; of session.trans_sid_tags setting. +; If no host is defined, HTTP_HOST will be used for allowed host. +; Example value: php.net,www.php.net,wiki.php.net +; Use "," for multiple hosts. No spaces are allowed. +; Default Value: "" +; Development Value: "" +; Production Value: "" +;session.trans_sid_hosts="" ; Define how many bits are stored in each character when converting ; the binary hash data to something readable. @@ -1614,77 +1528,78 @@ session.hash_function = 0 ; Development Value: 5 ; Production Value: 5 ; http://php.net/session.hash-bits-per-character -session.hash_bits_per_character = 5 +session.sid_bits_per_character = 5 -; The URL rewriter will look for URLs in a defined set of HTML tags. -; form/fieldset are special; if you include them here, the rewriter will -; add a hidden field with the info which is otherwise appended -; to URLs. If you want XHTML conformity, remove the form entry. -; Note that all valid entries require a "=", even if no value follows. -; Default Value: "a=href,area=href,frame=src,form=,fieldset=" -; Development Value: "a=href,area=href,frame=src,input=src,form=fakeentry" -; Production Value: "a=href,area=href,frame=src,input=src,form=fakeentry" -; http://php.net/url-rewriter.tags -url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry" +; Enable upload progress tracking in $_SESSION +; Default Value: On +; Development Value: On +; Production Value: On +; http://php.net/session.upload-progress.enabled +;session.upload_progress.enabled = On -[MSSQL] -; Allow or prevent persistent links. -mssql.allow_persistent = On +; Cleanup the progress information as soon as all POST data has been read +; (i.e. upload completed). +; Default Value: On +; Development Value: On +; Production Value: On +; http://php.net/session.upload-progress.cleanup +;session.upload_progress.cleanup = On -; Maximum number of persistent links. -1 means no limit. -mssql.max_persistent = -1 +; A prefix used for the upload progress key in $_SESSION +; Default Value: "upload_progress_" +; Development Value: "upload_progress_" +; Production Value: "upload_progress_" +; http://php.net/session.upload-progress.prefix +;session.upload_progress.prefix = "upload_progress_" -; Maximum number of links (persistent+non persistent). -1 means no limit. -mssql.max_links = -1 +; The index name (concatenated with the prefix) in $_SESSION +; containing the upload progress information +; Default Value: "PHP_SESSION_UPLOAD_PROGRESS" +; Development Value: "PHP_SESSION_UPLOAD_PROGRESS" +; Production Value: "PHP_SESSION_UPLOAD_PROGRESS" +; http://php.net/session.upload-progress.name +;session.upload_progress.name = "PHP_SESSION_UPLOAD_PROGRESS" -; Minimum error severity to display. -mssql.min_error_severity = 10 +; How frequently the upload progress should be updated. +; Given either in percentages (per-file), or in bytes +; Default Value: "1%" +; Development Value: "1%" +; Production Value: "1%" +; http://php.net/session.upload-progress.freq +;session.upload_progress.freq = "1%" -; Minimum message severity to display. -mssql.min_message_severity = 10 +; The minimum delay between updates, in seconds +; Default Value: 1 +; Development Value: 1 +; Production Value: 1 +; http://php.net/session.upload-progress.min-freq +;session.upload_progress.min_freq = "1" -; Compatibility mode with old versions of PHP 3.0. -mssql.compatability_mode = Off - -; Connect timeout -;mssql.connect_timeout = 5 - -; Query timeout -;mssql.timeout = 60 - -; Valid range 0 - 2147483647. Default = 4096. -;mssql.textlimit = 4096 - -; Valid range 0 - 2147483647. Default = 4096. -;mssql.textsize = 4096 - -; Limits the number of records in each batch. 0 = all records in one batch. -;mssql.batchsize = 0 - -; Specify how datetime and datetim4 columns are returned -; On => Returns data converted to SQL server settings -; Off => Returns values as YYYY-MM-DD hh:mm:ss -;mssql.datetimeconvert = On - -; Use NT authentication when connecting to the server -mssql.secure_connection = Off - -; Specify max number of processes. -1 = library default -; msdlib defaults to 25 -; FreeTDS defaults to 4096 -;mssql.max_procs = -1 - -; Specify client character set. -; If empty or not set the client charset from freetds.comf is used -; This is only used when compiled with FreeTDS -;mssql.charset = "ISO-8859-1" +; Only write session data when session data is changed. Enabled by default. +; http://php.net/session.lazy-write +;session.lazy_write = On [Assertion] +; Switch whether to compile assertions at all (to have no overhead at run-time) +; -1: Do not compile at all +; 0: Jump over assertion at run-time +; 1: Execute assertions +; Changing from or to a negative value is only possible in php.ini! (For turning assertions on and off at run-time, see assert.active, when zend.assertions = 1) +; Default Value: 1 +; Development Value: 1 +; Production Value: -1 +; http://php.net/zend.assertions +zend.assertions = -1 + ; Assert(expr); active by default. ; http://php.net/assert.active ;assert.active = On -; Issue a PHP warning for each failed assertion. +; Throw an AssertationException on failed assertions +; http://php.net/assert.exception +;assert.exception = On + +; Issue a PHP warning for each failed assertion. (Overridden by assert.exception if active) ; http://php.net/assert.warning ;assert.warning = On @@ -1728,23 +1643,34 @@ mssql.secure_connection = Off [mbstring] ; language for internal character representation. +; This affects mb_send_mail() and mbstring.detect_order. ; http://php.net/mbstring.language ;mbstring.language = Japanese +; Use of this INI entry is deprecated, use global internal_encoding instead. ; internal/script encoding. -; Some encoding cannot work as internal encoding. -; (e.g. SJIS, BIG5, ISO-2022-*) -; http://php.net/mbstring.internal-encoding -;mbstring.internal_encoding = EUC-JP +; Some encoding cannot work as internal encoding. (e.g. SJIS, BIG5, ISO-2022-*) +; If empty, default_charset or internal_encoding or iconv.internal_encoding is used. +; The precedence is: default_charset < internal_encoding < iconv.internal_encoding +;mbstring.internal_encoding = +; Use of this INI entry is deprecated, use global input_encoding instead. ; http input encoding. +; mbstring.encoding_traslation = On is needed to use this setting. +; If empty, default_charset or input_encoding or mbstring.input is used. +; The precedence is: default_charset < intput_encoding < mbsting.http_input ; http://php.net/mbstring.http-input -;mbstring.http_input = auto +;mbstring.http_input = -; http output encoding. mb_output_handler must be -; registered as output buffer to function +; Use of this INI entry is deprecated, use global output_encoding instead. +; http output encoding. +; mb_output_handler must be registered as output buffer to function. +; If empty, default_charset or output_encoding or mbstring.http_output is used. +; The precedence is: default_charset < output_encoding < mbstring.http_output +; To use an output encoding conversion, mbstring's output handler must be set +; otherwise output encoding conversion cannot be performed. ; http://php.net/mbstring.http-output -;mbstring.http_output = SJIS +;mbstring.http_output = ; enable automatic encoding translation according to ; mbstring.internal_encoding setting. Input chars are @@ -1755,14 +1681,14 @@ mssql.secure_connection = Off ;mbstring.encoding_translation = Off ; automatic encoding detection order. -; auto means +; "auto" detect order is changed according to mbstring.language ; http://php.net/mbstring.detect-order ;mbstring.detect_order = auto ; substitute_character used when character cannot be converted ; one from another ; http://php.net/mbstring.substitute-character -;mbstring.substitute_character = none; +;mbstring.substitute_character = none ; overload(replace) single byte functions by mbstring functions. ; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(), @@ -1776,23 +1702,20 @@ mssql.secure_connection = Off ;mbstring.func_overload = 0 ; enable strict encoding detection. -;mbstring.strict_detection = Off +; Default: Off +;mbstring.strict_detection = On ; This directive specifies the regex pattern of content types for which mb_output_handler() ; is activated. ; Default: mbstring.http_output_conv_mimetype=^(text/|application/xhtml\+xml) ;mbstring.http_output_conv_mimetype= -; Allows to set script encoding. Only affects if PHP is compiled with --enable-zend-multibyte -; Default: "" -;mbstring.script_encoding= - [gd] ; Tell the jpeg decode to ignore warnings and try to create ; a gd image. The warning will then be displayed as notices ; disabled by default ; http://php.net/gd.jpeg-ignore-warning -;gd.jpeg_ignore_warning = 0 +;gd.jpeg_ignore_warning = 1 [exif] ; Exif UNICODE user comments are handled as UCS-2BE/UCS-2LE and JIS as JIS. @@ -1854,20 +1777,160 @@ soap.wsdl_cache_limit = 5 ; Sets the maximum number of open links or -1 for unlimited. ldap.max_links = -1 -[mcrypt] -; For more information about mcrypt settings see http://php.net/mcrypt-module-open - -; Directory where to load mcrypt algorithms -; Default: Compiled in into libmcrypt (usually /usr/local/lib/libmcrypt) -;mcrypt.algorithms_dir= - -; Directory where to load mcrypt modes -; Default: Compiled in into libmcrypt (usually /usr/local/lib/libmcrypt) -;mcrypt.modes_dir= - [dba] ;dba.default_handler= +[opcache] +; Determines if Zend OPCache is enabled +;opcache.enable=1 + +; Determines if Zend OPCache is enabled for the CLI version of PHP +;opcache.enable_cli=0 + +; The OPcache shared memory storage size. +;opcache.memory_consumption=128 + +; The amount of memory for interned strings in Mbytes. +;opcache.interned_strings_buffer=8 + +; The maximum number of keys (scripts) in the OPcache hash table. +; Only numbers between 200 and 1000000 are allowed. +;opcache.max_accelerated_files=10000 + +; The maximum percentage of "wasted" memory until a restart is scheduled. +;opcache.max_wasted_percentage=5 + +; When this directive is enabled, the OPcache appends the current working +; directory to the script key, thus eliminating possible collisions between +; files with the same name (basename). Disabling the directive improves +; performance, but may break existing applications. +;opcache.use_cwd=1 + +; When disabled, you must reset the OPcache manually or restart the +; webserver for changes to the filesystem to take effect. +;opcache.validate_timestamps=1 + +; How often (in seconds) to check file timestamps for changes to the shared +; memory storage allocation. ("1" means validate once per second, but only +; once per request. "0" means always validate) +;opcache.revalidate_freq=2 + +; Enables or disables file search in include_path optimization +;opcache.revalidate_path=0 + +; If disabled, all PHPDoc comments are dropped from the code to reduce the +; size of the optimized code. +;opcache.save_comments=1 + +; Allow file existence override (file_exists, etc.) performance feature. +;opcache.enable_file_override=0 + +; A bitmask, where each bit enables or disables the appropriate OPcache +; passes +;opcache.optimization_level=0xffffffff + +;opcache.inherited_hack=1 +;opcache.dups_fix=0 + +; The location of the OPcache blacklist file (wildcards allowed). +; Each OPcache blacklist file is a text file that holds the names of files +; that should not be accelerated. The file format is to add each filename +; to a new line. The filename may be a full path or just a file prefix +; (i.e., /var/www/x blacklists all the files and directories in /var/www +; that start with 'x'). Line starting with a ; are ignored (comments). +;opcache.blacklist_filename= + +; Allows exclusion of large files from being cached. By default all files +; are cached. +;opcache.max_file_size=0 + +; Check the cache checksum each N requests. +; The default value of "0" means that the checks are disabled. +;opcache.consistency_checks=0 + +; How long to wait (in seconds) for a scheduled restart to begin if the cache +; is not being accessed. +;opcache.force_restart_timeout=180 + +; OPcache error_log file name. Empty string assumes "stderr". +;opcache.error_log= + +; All OPcache errors go to the Web server log. +; By default, only fatal errors (level 0) or errors (level 1) are logged. +; You can also enable warnings (level 2), info messages (level 3) or +; debug messages (level 4). +;opcache.log_verbosity_level=1 + +; Preferred Shared Memory back-end. Leave empty and let the system decide. +;opcache.preferred_memory_model= + +; Protect the shared memory from unexpected writing during script execution. +; Useful for internal debugging only. +;opcache.protect_memory=0 + +; Allows calling OPcache API functions only from PHP scripts which path is +; started from specified string. The default "" means no restriction +;opcache.restrict_api= + +; Mapping base of shared memory segments (for Windows only). All the PHP +; processes have to map shared memory into the same address space. This +; directive allows to manually fix the "Unable to reattach to base address" +; errors. +;opcache.mmap_base= + +; Enables and sets the second level cache directory. +; It should improve performance when SHM memory is full, at server restart or +; SHM reset. The default "" disables file based caching. +;opcache.file_cache= + +; Enables or disables opcode caching in shared memory. +;opcache.file_cache_only=0 + +; Enables or disables checksum validation when script loaded from file cache. +;opcache.file_cache_consistency_checks=1 + +; Implies opcache.file_cache_only=1 for a certain process that failed to +; reattach to the shared memory (for Windows only). Explicitly enabled file +; cache is required. +;opcache.file_cache_fallback=1 + +; Enables or disables copying of PHP code (text segment) into HUGE PAGES. +; This should improve performance, but requires appropriate OS configuration. +;opcache.huge_code_pages=1 + +; Validate cached file permissions. +;opcache.validate_permission=0 + +; Prevent name collisions in chroot'ed environment. +;opcache.validate_root=0 + +; If specified, it produces opcode dumps for debugging different stages of +; optimizations. +;opcache.opt_debug_level=0 + +[curl] +; A default value for the CURLOPT_CAINFO option. This is required to be an +; absolute path. +;curl.cainfo = + +[openssl] +; The location of a Certificate Authority (CA) file on the local filesystem +; to use when verifying the identity of SSL/TLS peers. Most users should +; not specify a value for this directive as PHP will attempt to use the +; OS-managed cert stores in its absence. If specified, this value may still +; be overridden on a per-stream basis via the "cafile" SSL stream context +; option. +;openssl.cafile= + +; If openssl.cafile is not specified or if the CA file is not found, the +; directory pointed to by openssl.capath is searched for a suitable +; certificate. This value must be a correctly hashed certificate directory. +; Most users should not specify a value for this directive as PHP will +; attempt to use the OS-managed cert stores in its absence. If specified, +; this value may still be overridden on a per-stream basis via the "capath" +; SSL stream context option. +;openssl.capath= + ; Local Variables: ; tab-width: 4 ; End: diff --git a/nodes/wiki-1.json b/nodes/wiki-1.json index a6f9be0..efd9083 100644 --- a/nodes/wiki-1.json +++ b/nodes/wiki-1.json @@ -8,7 +8,7 @@ "automatic": { "fqdn": "wiki-1", "os": "linux", - "os_version": "5.4.0-42-generic", + "os_version": "5.4.0-45-generic", "hostname": "wiki-1", "ipaddress": "192.168.122.26", "roles": [ @@ -41,19 +41,7 @@ "php::ini", "composer::global_configs", "mediawiki::default", - "mediawiki::database", - "kosmos-nginx::default", - "nginx::default", - "nginx::package", - "nginx::ohai_plugin", - "nginx::repo", - "nginx::commons", - "nginx::commons_dir", - "nginx::commons_script", - "nginx::commons_conf", - "mediawiki::nginx", - "backup::default", - "logrotate::default" + "mediawiki::database" ], "platform": "ubuntu", "platform_version": "20.04", diff --git a/site-cookbooks/kosmos-mediawiki/recipes/default.rb b/site-cookbooks/kosmos-mediawiki/recipes/default.rb index b459914..deb263b 100644 --- a/site-cookbooks/kosmos-mediawiki/recipes/default.rb +++ b/site-cookbooks/kosmos-mediawiki/recipes/default.rb @@ -45,11 +45,6 @@ mediawiki_credentials = data_bag_item('credentials', 'mediawiki') node.override['mediawiki']['db']['root_password'] = mysql_credentials["root_password"] node.override['mediawiki']['db']['pass'] = mediawiki_credentials["db_pass"] -# Fix bug in php cookbook -if platform?('ubuntu') && node[:platform_version].to_f == 14.04 - node.override['php']['ext_conf_dir'] = '/etc/php5/mods-available' -end - directory "#{node['mediawiki']['webdir']}/skins/common/images" do owner node['nginx']['user'] group node['nginx']['group'] @@ -98,8 +93,7 @@ nginx_site server_name do action :enable end -# TODO -# nginx_certbot_site server_name +nginx_certbot_site server_name # # Extensions From 8dd146e95ca5de2580f5588773ce114809f314af Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 6 Sep 2020 13:42:34 +0200 Subject: [PATCH 118/327] Remove obsolete mysql client install This fails nowadays,and the client is already installed via the mysql package in the first place. --- site-cookbooks/backup/recipes/default.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/site-cookbooks/backup/recipes/default.rb b/site-cookbooks/backup/recipes/default.rb index a7f215b..a0aa1f7 100644 --- a/site-cookbooks/backup/recipes/default.rb +++ b/site-cookbooks/backup/recipes/default.rb @@ -62,12 +62,6 @@ cron "default backup model" do end include_recipe 'logrotate' -# Install MySQL client (includes mysqldump) -mysql_client 'default' do - action :create - version '5.7' if node[:platform_version].to_f == 18.04 - not_if { node["backup"]["mysql"]["databases"].empty? } -end # Write the credentials file to allow dumps without password for the root # user (https://dev.mysql.com/doc/refman/5.7/en/option-files.html) From 2d559ebd918400e20b6fc5cc481586eb588da386 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 6 Sep 2020 13:43:07 +0200 Subject: [PATCH 119/327] Update wiki node config Just committing the changes after a successful run with letsencrypt also working. --- nodes/wiki-1.json | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/nodes/wiki-1.json b/nodes/wiki-1.json index efd9083..b69ecff 100644 --- a/nodes/wiki-1.json +++ b/nodes/wiki-1.json @@ -41,7 +41,20 @@ "php::ini", "composer::global_configs", "mediawiki::default", - "mediawiki::database" + "mediawiki::database", + "kosmos-nginx::default", + "nginx::default", + "nginx::package", + "nginx::ohai_plugin", + "nginx::repo", + "nginx::commons", + "nginx::commons_dir", + "nginx::commons_script", + "nginx::commons_conf", + "mediawiki::nginx", + "backup::default", + "logrotate::default", + "kosmos-base::letsencrypt" ], "platform": "ubuntu", "platform_version": "20.04", From a1a0d7e4c114c087596088d42f64f2a9fcdfe418 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 6 Sep 2020 13:46:06 +0200 Subject: [PATCH 120/327] Switch Certbot to snap package on Ubuntu 20.04+ Needs only minor changes. Tested and running on wiki.kosmos.org already. --- .../kosmos-base/files/default/certbot.service | 3 +- .../kosmos-base/recipes/letsencrypt.rb | 52 ++++++++++++------- .../resources/nginx_certbot_site.rb | 4 +- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/site-cookbooks/kosmos-base/files/default/certbot.service b/site-cookbooks/kosmos-base/files/default/certbot.service index 39274c3..20c9b88 100644 --- a/site-cookbooks/kosmos-base/files/default/certbot.service +++ b/site-cookbooks/kosmos-base/files/default/certbot.service @@ -1,7 +1,6 @@ [Unit] Description=Certbot -Documentation=file:///usr/share/doc/python-certbot-doc/html/index.html -Documentation=https://letsencrypt.readthedocs.io/en/latest/ +Documentation=https://certbot.eff.org/docs/ OnFailure=status-email-ops@%n.service [Service] Type=oneshot diff --git a/site-cookbooks/kosmos-base/recipes/letsencrypt.rb b/site-cookbooks/kosmos-base/recipes/letsencrypt.rb index d477588..ac5016e 100644 --- a/site-cookbooks/kosmos-base/recipes/letsencrypt.rb +++ b/site-cookbooks/kosmos-base/recipes/letsencrypt.rb @@ -24,13 +24,24 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Install certbot and set up hooks - -apt_repository "certbot" do - uri "ppa:certbot/certbot" +unless platform?('ubuntu') + raise "This recipe only supports Ubuntu installs" end -package "certbot" +if node[:platform_version].to_f < 20.04 + apt_repository "certbot" do + uri "ppa:certbot/certbot" + end + package "certbot" +else + bash "install_certbot_snap" do + code "snap install --classic certbot" + end + # TODO switch to snap_package resource when they fix it + # snap_package "certbot" do + # options "--classic" + # end +end %w(deploy post pre).each do |subdir| directory "/etc/letsencrypt/renewal-hooks/#{subdir}" do @@ -52,22 +63,23 @@ systemctl reload nginx group "root" end -gandi_api_data_bag_item = data_bag_item('credentials', 'gandi_api_5apps') +# gandi_api_data_bag_item = data_bag_item('credentials', 'gandi_api_5apps') -template "/root/gandi_dns_certbot_hook.sh" do - variables gandi_api_key: gandi_api_data_bag_item["key"] - mode 0770 -end +# TODO only write to machines that actually need it (e.g. via role) +# template "/root/gandi_dns_certbot_hook.sh" do +# variables gandi_api_key: gandi_api_data_bag_item["key"] +# mode 0770 +# end -include_recipe 'kosmos-base::systemd_emails' +# include_recipe 'kosmos-base::systemd_emails' +# TODO Check the deployed certs expiration dates instead of overwriting supplied systemd services # Overwrite the systemd service to add email notifications on failures -cookbook_file "/lib/systemd/system/certbot.service" do - source "certbot.service" - notifies :run, "execute[systemctl daemon-reload]", :delayed -end - -execute "systemctl daemon-reload" do - command "systemctl daemon-reload" - action :nothing -end +# cookbook_file "/lib/systemd/system/certbot.service" do +# source "certbot.service" +# notifies :run, "execute[systemctl daemon-reload]", :delayed +# end +# execute "systemctl daemon-reload" do +# command "systemctl daemon-reload" +# action :nothing +# end diff --git a/site-cookbooks/kosmos-nginx/resources/nginx_certbot_site.rb b/site-cookbooks/kosmos-nginx/resources/nginx_certbot_site.rb index 97a13af..a3aecc2 100644 --- a/site-cookbooks/kosmos-nginx/resources/nginx_certbot_site.rb +++ b/site-cookbooks/kosmos-nginx/resources/nginx_certbot_site.rb @@ -39,10 +39,12 @@ action :create do include_recipe "kosmos-base::letsencrypt" + certbot_bin = node[:platform_version].to_f < 20.04 ? "/usr/bin/certbot" : "/snap/bin/certbot" + # Generate a Let's Encrypt cert (only if the nginx vhost exists and no cert # has been generated before. The renew cron will take care of renewing execute "letsencrypt cert for #{domain}" do - command "/usr/bin/certbot certonly --webroot --agree-tos --email ops@kosmos.org --webroot-path #{root_directory} -d #{domain} -n" + command "#{certbot_bin} certonly --webroot --agree-tos --email ops@kosmos.org --webroot-path #{root_directory} -d #{domain} -n" only_if do ::File.exist?("#{node['nginx']['dir']}/sites-enabled/#{domain}_certbot") && !::File.exist?("/etc/letsencrypt/live/#{domain}/fullchain.pem") From ee7a853b5c816df056c44a6175372d7fdc25b4aa Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 6 Sep 2020 14:00:35 +0200 Subject: [PATCH 121/327] Set up a testing VM on draco Currently only has base recipe and nginx with certbot running. https://test-2.kosmos.org/ --- clients/test-2.json | 4 ++++ nodes/test-2.json | 52 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 clients/test-2.json create mode 100644 nodes/test-2.json diff --git a/clients/test-2.json b/clients/test-2.json new file mode 100644 index 0000000..12c109c --- /dev/null +++ b/clients/test-2.json @@ -0,0 +1,4 @@ +{ + "name": "test-2", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyU+Pg4svFeiLc4/OogiZ\n45MgXWMT7/S28R5lDQ3QwCc4c3mGEfkoiOzBmPpf/JuTIRO6W8hsXQNm5Wr3jGYa\nIKHtfSqNufLievLxymR781Grkzxsy8GefeUajNn0Nypjs4ACso2rdX3KmQ/xJr4n\nFKk6Jj08Fp/7i7kzgC8WA6ZeuVPRw9PODTof7x1BMoTfUXaGPPEIVxtv7cZBdkp1\nQK3F2A8nokqDo3630iOq/P29h80STGmeH8hjpICTGxYDOR/vvp7Zs7z8aueZ6iUT\n3oit8w+gAI4RTgu4bgPbwsh5nfIXZaJeSVrV6zpPO5usMbWWDJgdbhwbAGGYVSFp\nEQIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/test-2.json b/nodes/test-2.json new file mode 100644 index 0000000..aac9607 --- /dev/null +++ b/nodes/test-2.json @@ -0,0 +1,52 @@ +{ + "name": "test-2", + "normal": { + "knife_zero": { + "host": "10.147.20.109" + } + }, + "automatic": { + "fqdn": "test-2", + "os": "linux", + "os_version": "5.4.0-45-generic", + "hostname": "test-2", + "ipaddress": "192.168.122.166", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + }, + "chef": { + "version": "15.13.8", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.13.8/lib" + } + } + }, + "run_list": [ + "recipe[kosmos-base]" + ] +} \ No newline at end of file From 41319fc5bcbb3a03b429d0a3aa119040982a9830 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 15 Sep 2020 13:04:54 +0200 Subject: [PATCH 122/327] Add shell script for creating LDAP user accounts --- doc/ldap.md | 6 ++++++ scripts/ldap/add_user.sh | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 scripts/ldap/add_user.sh diff --git a/doc/ldap.md b/doc/ldap.md index 7ebe26f..5ebcf8f 100644 --- a/doc/ldap.md +++ b/doc/ldap.md @@ -14,3 +14,9 @@ $ knife data bag show credentials dirsrv --secret-file .chef/encrypted_data_bag_ ``` $ ldapsearch -x -W -D 'cn=Directory Manager' -b "ou=users,dc=kosmos,dc=org" -H "ldaps://ldap.kosmos.org" -v ``` + +## Shell scripts + +Adding a new user account (requires username, email, password): + + ./scripts/ldap/add_user.sh username user@example.com changeme diff --git a/scripts/ldap/add_user.sh b/scripts/ldap/add_user.sh new file mode 100755 index 0000000..d6098a9 --- /dev/null +++ b/scripts/ldap/add_user.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -xe; + +password=$(ruby -r base64 -r digest -r securerandom -e "salt = SecureRandom.hex(32); password = '$3'; puts '{SSHA512}' + Base64.strict_encode64(Digest::SHA512.digest(password + salt) + salt)"); + +ldapadd -x -W -D 'cn=Directory Manager' -H "ldaps://ldap.kosmos.org" << EOF +dn: cn=$1,ou=kosmos.org,cn=users,dc=kosmos,dc=org +objectClass: top +objectClass: account +objectClass: person +objectClass: extensibleObject +cn: $1 +sn: $1 +uid: $1 +mail: $2 +userPassword: $password +EOF From a8b303af4a2d02211cbab24fc3b7b722196e42d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 16 Sep 2020 11:36:29 +0200 Subject: [PATCH 123/327] Fix the search command for Kosmos LDAP users --- doc/ldap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ldap.md b/doc/ldap.md index 5ebcf8f..846bf2d 100644 --- a/doc/ldap.md +++ b/doc/ldap.md @@ -12,7 +12,7 @@ $ knife data bag show credentials dirsrv --secret-file .chef/encrypted_data_bag_ ## Example search (will prompt for password): ``` -$ ldapsearch -x -W -D 'cn=Directory Manager' -b "ou=users,dc=kosmos,dc=org" -H "ldaps://ldap.kosmos.org" -v +$ ldapsearch -x -W -D 'cn=Directory Manager' -b "ou=kosmos.org,cn=users,dc=kosmos,dc=org" -H "ldaps://ldap.kosmos.org" -v ``` ## Shell scripts From 3d8d31c32f47f9d162aa2e7f14b95f5d207c3592 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 24 Sep 2020 17:39:28 +0200 Subject: [PATCH 124/327] Fix kosmos-ipfs not requiring nodejs/npm If node isn't installed on a machine by something else before running the kosmos-ipfs recipe, then it fails. --- site-cookbooks/kosmos-ipfs/metadata.rb | 1 + site-cookbooks/kosmos-ipfs/recipes/kredits_pinner.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/site-cookbooks/kosmos-ipfs/metadata.rb b/site-cookbooks/kosmos-ipfs/metadata.rb index cda9ca4..8b89975 100644 --- a/site-cookbooks/kosmos-ipfs/metadata.rb +++ b/site-cookbooks/kosmos-ipfs/metadata.rb @@ -9,5 +9,6 @@ version '0.3.0' depends 'ipfs' depends 'kosmos-base' depends 'kosmos-nginx' +depends 'kosmos-nodejs' depends 'firewall' depends 'application_javascript' diff --git a/site-cookbooks/kosmos-ipfs/recipes/kredits_pinner.rb b/site-cookbooks/kosmos-ipfs/recipes/kredits_pinner.rb index 8ae29fe..8fc479c 100644 --- a/site-cookbooks/kosmos-ipfs/recipes/kredits_pinner.rb +++ b/site-cookbooks/kosmos-ipfs/recipes/kredits_pinner.rb @@ -24,6 +24,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +include_recipe 'kosmos-nodejs' + app_name = "kredits-ipfs-pinner" deploy_user = "ipfs" deploy_group = "ipfs" From 7c4af862b70ffe5879144764087fcc3c0c07245d Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 24 Sep 2020 17:41:24 +0200 Subject: [PATCH 125/327] Add node config for new IPFS (gateway) VM --- nodes/ipfs-1.json | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 nodes/ipfs-1.json diff --git a/nodes/ipfs-1.json b/nodes/ipfs-1.json new file mode 100644 index 0000000..85d0e6a --- /dev/null +++ b/nodes/ipfs-1.json @@ -0,0 +1,75 @@ +{ + "name": "ipfs-1", + "normal": { + "knife_zero": { + "host": "10.147.20.198" + } + }, + "automatic": { + "fqdn": "ipfs-1", + "os": "linux", + "os_version": "5.4.0-48-generic", + "hostname": "ipfs-1", + "ipaddress": "192.168.122.195", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "kosmos-ipfs", + "kosmos-ipfs::default", + "kosmos-ipfs::public_gateway", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default", + "ipfs::default", + "ipfs::_user", + "kosmos-ipfs::kredits_pinner", + "kosmos-nodejs::default", + "nodejs::nodejs_from_package", + "nodejs::repo", + "firewall::default", + "chef-sugar::default", + "kosmos-nginx::default", + "nginx::default", + "nginx::package", + "nginx::ohai_plugin", + "nginx::repo", + "nginx::commons", + "nginx::commons_dir", + "nginx::commons_script", + "nginx::commons_conf", + "kosmos-base::letsencrypt" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "chef": { + "version": "15.14.0", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib" + }, + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + } + } + }, + "run_list": [ + "recipe[kosmos-base]", + "recipe[kosmos-ipfs]", + "recipe[kosmos-ipfs::public_gateway]" + ] +} \ No newline at end of file From 2119c112437e70be6d8d0fd9d3ead1a2d8cd9a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 25 Sep 2020 16:29:01 +0200 Subject: [PATCH 126/327] Do not include kosmos-postgresql in kosmos-ejabberd default recipe It will install PostgreSQL, and we do not want that on the ejabberd server --- site-cookbooks/kosmos-ejabberd/recipes/default.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index 6e60685..2a73cdb 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -24,8 +24,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -include_recipe "kosmos-postgresql" - ejabberd_credentials = data_bag_item("credentials", "ejabberd") ejabberd_version = node["kosmos-ejabberd"]["version"] From 7eaf177bb2cb7a91fd79bb46cb3edb20963a8eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 6 Oct 2020 15:51:01 +0200 Subject: [PATCH 127/327] Set the autocreate permission for Mediawiki users This allows LDAP sign ins to create an account automatically Fixes #219 --- site-cookbooks/kosmos-mediawiki/recipes/default.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/site-cookbooks/kosmos-mediawiki/recipes/default.rb b/site-cookbooks/kosmos-mediawiki/recipes/default.rb index deb263b..1f1ce8d 100644 --- a/site-cookbooks/kosmos-mediawiki/recipes/default.rb +++ b/site-cookbooks/kosmos-mediawiki/recipes/default.rb @@ -250,6 +250,7 @@ wfLoadExtension( 'LDAPAuthentication2' ); # Disable account creation page, since this is not possible to create an account # when only LDAP login is enabled $wgGroupPermissions['*']['createaccount'] = false; +$wgGroupPermissions['*']['autocreateaccount'] = true; EOF ) From 429b609ac2b4899b2e70977cdd345298048a2615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 20 Oct 2020 12:20:05 +0200 Subject: [PATCH 128/327] Initial kosmos_discourse cookbook The systemd unit does not work Refs #222 --- site-cookbooks/kosmos_discourse/.gitignore | 22 ++++ site-cookbooks/kosmos_discourse/CHANGELOG.md | 7 ++ site-cookbooks/kosmos_discourse/LICENSE | 21 ++++ site-cookbooks/kosmos_discourse/README.md | 4 + site-cookbooks/kosmos_discourse/chefignore | 110 ++++++++++++++++++ site-cookbooks/kosmos_discourse/metadata.rb | 10 ++ .../kosmos_discourse/recipes/default.rb | 69 +++++++++++ .../templates/discourse.service.erb | 23 ++++ .../kosmos_discourse/templates/nginx_conf.erb | 34 ++++++ 9 files changed, 300 insertions(+) create mode 100644 site-cookbooks/kosmos_discourse/.gitignore create mode 100644 site-cookbooks/kosmos_discourse/CHANGELOG.md create mode 100644 site-cookbooks/kosmos_discourse/LICENSE create mode 100644 site-cookbooks/kosmos_discourse/README.md create mode 100644 site-cookbooks/kosmos_discourse/chefignore create mode 100644 site-cookbooks/kosmos_discourse/metadata.rb create mode 100644 site-cookbooks/kosmos_discourse/recipes/default.rb create mode 100644 site-cookbooks/kosmos_discourse/templates/discourse.service.erb create mode 100644 site-cookbooks/kosmos_discourse/templates/nginx_conf.erb diff --git a/site-cookbooks/kosmos_discourse/.gitignore b/site-cookbooks/kosmos_discourse/.gitignore new file mode 100644 index 0000000..9abf29f --- /dev/null +++ b/site-cookbooks/kosmos_discourse/.gitignore @@ -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 diff --git a/site-cookbooks/kosmos_discourse/CHANGELOG.md b/site-cookbooks/kosmos_discourse/CHANGELOG.md new file mode 100644 index 0000000..99ae433 --- /dev/null +++ b/site-cookbooks/kosmos_discourse/CHANGELOG.md @@ -0,0 +1,7 @@ +# kosmos_discourse CHANGELOG + +This file is used to list changes made in each version of the kosmos_discourse cookbook. + +# 0.1.0 + +Initial release. diff --git a/site-cookbooks/kosmos_discourse/LICENSE b/site-cookbooks/kosmos_discourse/LICENSE new file mode 100644 index 0000000..dd321fd --- /dev/null +++ b/site-cookbooks/kosmos_discourse/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +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. diff --git a/site-cookbooks/kosmos_discourse/README.md b/site-cookbooks/kosmos_discourse/README.md new file mode 100644 index 0000000..cce437d --- /dev/null +++ b/site-cookbooks/kosmos_discourse/README.md @@ -0,0 +1,4 @@ +# kosmos_discourse + +TODO: Enter the cookbook description here. + diff --git a/site-cookbooks/kosmos_discourse/chefignore b/site-cookbooks/kosmos_discourse/chefignore new file mode 100644 index 0000000..5039e1c --- /dev/null +++ b/site-cookbooks/kosmos_discourse/chefignore @@ -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 diff --git a/site-cookbooks/kosmos_discourse/metadata.rb b/site-cookbooks/kosmos_discourse/metadata.rb new file mode 100644 index 0000000..76a2e83 --- /dev/null +++ b/site-cookbooks/kosmos_discourse/metadata.rb @@ -0,0 +1,10 @@ +name 'kosmos_discourse' +maintainer 'Kosmos Developers' +maintainer_email 'you@example.com' +license 'MIT' +description 'Installs/Configures kosmos_discourse' +long_description 'Installs/Configures kosmos_discourse' +version '0.1.0' +chef_version '>= 14.0' + +depends "kosmos-nginx" diff --git a/site-cookbooks/kosmos_discourse/recipes/default.rb b/site-cookbooks/kosmos_discourse/recipes/default.rb new file mode 100644 index 0000000..a2ed224 --- /dev/null +++ b/site-cookbooks/kosmos_discourse/recipes/default.rb @@ -0,0 +1,69 @@ +# +# Cookbook:: kosmos_discourse +# 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. + +package "docker-compose" +domain = "community.kosmos.org" +deploy_path = "/opt/discourse" + +repo = "https://github.com/discourse/discourse_docker" + +git deploy_path do + repository repo + revision "master" +end + +# FIXME: The systemd unit does not work +template "/etc/systemd/system/discourse.service" do + source "discourse.service.erb" + variables deploy_path: deploy_path + notifies :run, "execute[systemctl daemon-reload]", :immediately +end + +execute "systemctl daemon-reload" do + action :nothing +end + +service "discourse" do + action [:enable] +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: 3001 + + notifies :reload, 'service[nginx]', :delayed +end + +nginx_site domain do + action :enable +end + +nginx_certbot_site domain diff --git a/site-cookbooks/kosmos_discourse/templates/discourse.service.erb b/site-cookbooks/kosmos_discourse/templates/discourse.service.erb new file mode 100644 index 0000000..f85253d --- /dev/null +++ b/site-cookbooks/kosmos_discourse/templates/discourse.service.erb @@ -0,0 +1,23 @@ +[Unit] +Description=discourse service with docker compose +Requires=docker.service +After=docker.service + +[Service] +Restart=always + +WorkingDirectory=<%= @deploy_path %> + +Environment="SUPERVISED=true" + +ExecStartPre=<%= @deploy_path %>/launcher stop app +# Remove all containers that have stopped for > 24 hours +ExecStartPre=<%= @deploy_path %>/launcher cleanup + +ExecStart=<%= @deploy_path %>/launcher start app + +ExecStop=<%= @deploy_path %>/launcher stop app + +[Install] +WantedBy=multi-user.target + diff --git a/site-cookbooks/kosmos_discourse/templates/nginx_conf.erb b/site-cookbooks/kosmos_discourse/templates/nginx_conf.erb new file mode 100644 index 0000000..a1d639c --- /dev/null +++ b/site-cookbooks/kosmos_discourse/templates/nginx_conf.erb @@ -0,0 +1,34 @@ +# Generated by Chef +upstream _discourse { + server localhost:<%= @upstream_port %>; +} + +<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%> +server { + server_name <%= @server_name %>; + listen 443 ssl http2; + listen [::]:443 ssl http2; + + ssl_certificate <%= @ssl_cert %>; + ssl_certificate_key <%= @ssl_key %>; + + add_header Strict-Transport-Security "max-age=31536000"; + + # Send real IP to the Docker container + set_real_ip_from 127.0.0.1; + set_real_ip_from 172.17.0.1; + real_ip_header X-Forwarded-For; + + client_max_body_size 20M; + + location / { + # Increase number of buffers. Default is 8 + proxy_buffers 1024 8k; + + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_pass http://_discourse; + proxy_http_version 1.1; + } +} +<% end -%> From 07e6da4d33fc3298bf9eb5d64ae96d94ee0d2148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 20 Oct 2020 12:21:16 +0200 Subject: [PATCH 129/327] Add a role for discourse --- roles/discourse.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 roles/discourse.rb diff --git a/roles/discourse.rb b/roles/discourse.rb new file mode 100644 index 0000000..53a1ad2 --- /dev/null +++ b/roles/discourse.rb @@ -0,0 +1,5 @@ +name "discourse" + +run_list %w( + kosmos_discourse::default +) From dc2fe38e101769870c4cc54b01cd406fc9455dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 20 Oct 2020 12:21:30 +0200 Subject: [PATCH 130/327] Add the discourse role to centaurus --- nodes/centaurus.kosmos.org.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nodes/centaurus.kosmos.org.json b/nodes/centaurus.kosmos.org.json index 3fd6a8b..9819521 100644 --- a/nodes/centaurus.kosmos.org.json +++ b/nodes/centaurus.kosmos.org.json @@ -14,7 +14,8 @@ "roles": [ "gitea", "postgresql_client", - "postgresql_replica" + "postgresql_replica", + "discourse" ], "recipes": [ "kosmos-base", @@ -25,6 +26,8 @@ "kosmos_gitea::default", "kosmos_gitea::backup", "kosmos-postgresql::replica", + "kosmos_discourse", + "kosmos_discourse::default", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -73,6 +76,7 @@ "recipe[kosmos-base]", "recipe[kosmos_encfs]", "role[gitea]", - "role[postgresql_replica]" + "role[postgresql_replica]", + "role[discourse]" ] } \ No newline at end of file From 69383a666b208d7e574e9d3af1131e93c004383e Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 20 Oct 2020 15:42:42 +0200 Subject: [PATCH 131/327] Let hal8000 join new info@kosmos.chat room --- site-cookbooks/kosmos-hubot/attributes/default.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/site-cookbooks/kosmos-hubot/attributes/default.rb b/site-cookbooks/kosmos-hubot/attributes/default.rb index 0acddb3..0cb51cf 100644 --- a/site-cookbooks/kosmos-hubot/attributes/default.rb +++ b/site-cookbooks/kosmos-hubot/attributes/default.rb @@ -18,6 +18,7 @@ node.default['hal8000_xmpp']['rooms'] = [ 'kosmos@kosmos.chat', 'kosmos-dev@kosmos.chat', 'kredits@kosmos.chat', + 'info@kosmos.chat' ] node.default['hal8000_xmpp']['auth_admins'] = [] From 4f5b005087af3a6d968fc4ca3348a24c448d3f75 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 20 Oct 2020 15:44:53 +0200 Subject: [PATCH 132/327] Send wiki notifications to new info XMPP room --- site-cookbooks/kosmos-mediawiki/attributes/default.rb | 4 ++-- site-cookbooks/kosmos-mediawiki/recipes/default.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/site-cookbooks/kosmos-mediawiki/attributes/default.rb b/site-cookbooks/kosmos-mediawiki/attributes/default.rb index 4f58ee5..392f9dd 100644 --- a/site-cookbooks/kosmos-mediawiki/attributes/default.rb +++ b/site-cookbooks/kosmos-mediawiki/attributes/default.rb @@ -1,4 +1,4 @@ node.default["mediawiki"]["url"] = "https://wiki.kosmos.org/" -node.default["mediawiki"]["hubot_base_url"] = "http://barnard.kosmos.org:8080" -node.default["mediawiki"]["hubot_room"] = "#kosmos" +node.default["mediawiki"]["hubot_base_url"] = "https://hal8000.chat.kosmos.org" +node.default["mediawiki"]["hubot_room"] = "info@kosmos.chat" node.default["mediawiki"]["ldap_enabled"] = true diff --git a/site-cookbooks/kosmos-mediawiki/recipes/default.rb b/site-cookbooks/kosmos-mediawiki/recipes/default.rb index 1f1ce8d..1024296 100644 --- a/site-cookbooks/kosmos-mediawiki/recipes/default.rb +++ b/site-cookbooks/kosmos-mediawiki/recipes/default.rb @@ -119,7 +119,7 @@ ark "MediawikiHubot" do action :cherry_pick end -hubot_credentials = Chef::EncryptedDataBagItem.load('credentials', 'hal8000_freenode') +hubot_credentials = Chef::EncryptedDataBagItem.load('credentials', 'hal8000_xmpp') webhook_token = hubot_credentials['webhook_token'] template "#{node['mediawiki']['webdir']}/extensions/MediawikiHubot/DefaultConfig.php" do From 5062392c715cea52df569dd20f512f0a8f4494df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 20 Oct 2020 19:53:11 +0200 Subject: [PATCH 133/327] Fix the undefined variable in the instance resource --- site-cookbooks/kosmos-dirsrv/resources/instance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-dirsrv/resources/instance.rb b/site-cookbooks/kosmos-dirsrv/resources/instance.rb index 79c5b5d..3f0d37b 100644 --- a/site-cookbooks/kosmos-dirsrv/resources/instance.rb +++ b/site-cookbooks/kosmos-dirsrv/resources/instance.rb @@ -163,7 +163,7 @@ done # Generate a Let's Encrypt cert (only if the nginx vhost exists and no cert # has been generated before. The renew cron will take care of renewing execute "letsencrypt cert for #{new_resource.hostname}" do - command "/usr/bin/certbot certonly --webroot --agree-tos --email ops@kosmos.org --webroot-path #{root_directory} --deploy-hook /etc/letsencrypt/renewal-hooks/deploy/dirsrv -d #{new_resource.hostname} -n" + command "/usr/bin/certbot certonly --webroot --agree-tos --email ops@kosmos.org --webroot-path /var/www/#{new_resource.hostname} --deploy-hook /etc/letsencrypt/renewal-hooks/deploy/dirsrv -d #{new_resource.hostname} -n" only_if do ::File.exist?("#{node['nginx']['dir']}/sites-enabled/#{new_resource.hostname}_certbot") && !::File.exist?("/etc/letsencrypt/live/#{new_resource.hostname}/fullchain.pem") From 255e43c680172f8b406d2755e679cff04695817b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 22 Oct 2020 15:07:16 +0200 Subject: [PATCH 134/327] Fix the Systemd unit for discourse Switch the systemd unit to a oneshot type --- .../kosmos_discourse/recipes/default.rb | 31 +++++++++++-------- .../templates/discourse.service.erb | 23 -------------- 2 files changed, 18 insertions(+), 36 deletions(-) delete mode 100644 site-cookbooks/kosmos_discourse/templates/discourse.service.erb diff --git a/site-cookbooks/kosmos_discourse/recipes/default.rb b/site-cookbooks/kosmos_discourse/recipes/default.rb index a2ed224..5e65960 100644 --- a/site-cookbooks/kosmos_discourse/recipes/default.rb +++ b/site-cookbooks/kosmos_discourse/recipes/default.rb @@ -35,19 +35,24 @@ git deploy_path do revision "master" end -# FIXME: The systemd unit does not work -template "/etc/systemd/system/discourse.service" do - source "discourse.service.erb" - variables deploy_path: deploy_path - notifies :run, "execute[systemctl daemon-reload]", :immediately -end - -execute "systemctl daemon-reload" do - action :nothing -end - -service "discourse" do - action [:enable] +systemd_unit "discourse.service" do + content({Unit: { + Description: "discourse service with docker compose", + Requires: "docker.service", + After: "docker.service", + }, + Service: { + Type: "oneshot", + RemainAfterExit: "true", + WorkingDirectory: deploy_path, + Environment: "SUPERVISED=true", + ExecStart: "#{deploy_path}/launcher start app", + ExecStop: "#{deploy_path}/launcher stop app", + }, + Install: { + WantedBy: "multi-user.target" + }}) + action [:create, :enable] end template "#{node['nginx']['dir']}/sites-available/#{domain}" do diff --git a/site-cookbooks/kosmos_discourse/templates/discourse.service.erb b/site-cookbooks/kosmos_discourse/templates/discourse.service.erb deleted file mode 100644 index f85253d..0000000 --- a/site-cookbooks/kosmos_discourse/templates/discourse.service.erb +++ /dev/null @@ -1,23 +0,0 @@ -[Unit] -Description=discourse service with docker compose -Requires=docker.service -After=docker.service - -[Service] -Restart=always - -WorkingDirectory=<%= @deploy_path %> - -Environment="SUPERVISED=true" - -ExecStartPre=<%= @deploy_path %>/launcher stop app -# Remove all containers that have stopped for > 24 hours -ExecStartPre=<%= @deploy_path %>/launcher cleanup - -ExecStart=<%= @deploy_path %>/launcher start app - -ExecStop=<%= @deploy_path %>/launcher stop app - -[Install] -WantedBy=multi-user.target - From 2c368f0f104d69f4454a146ccbed7b12ee333474 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 25 Oct 2020 12:09:01 +0100 Subject: [PATCH 135/327] Update IPFS cookbook --- Berksfile | 2 +- Berksfile.lock | 6 +++--- cookbooks/ipfs/.kitchen.dokken.yml | 11 ++--------- cookbooks/ipfs/.kitchen.yml | 9 +++------ cookbooks/ipfs/.travis.yml | 3 +-- cookbooks/ipfs/Berksfile.lock | 2 +- cookbooks/ipfs/attributes/default.rb | 4 ++-- cookbooks/ipfs/metadata.json | 4 ++-- cookbooks/ipfs/metadata.rb | 4 ++-- cookbooks/ipfs/recipes/default.rb | 1 + .../test/integration/default/serverspec/ipfs_spec.rb | 5 +---- 11 files changed, 19 insertions(+), 32 deletions(-) diff --git a/Berksfile b/Berksfile index 5420a3a..2a32b61 100644 --- a/Berksfile +++ b/Berksfile @@ -47,7 +47,7 @@ cookbook 'homebrew', '= 3.0.0' cookbook 'mariadb', '= 0.3.1' cookbook 'ipfs', git: 'https://gitea.kosmos.org/kosmos/ipfs-cookbook.git', - ref: 'v0.4.1' + ref: 'v0.7.0' cookbook 'elasticsearch', '= 4.2.0' cookbook 'java', '~> 4.3.0' cookbook 'ulimit', '~> 1.0.0' diff --git a/Berksfile.lock b/Berksfile.lock index 590945a..ce0f7d4 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -18,8 +18,8 @@ DEPENDENCIES hostsfile (= 2.4.5) ipfs git: https://gitea.kosmos.org/kosmos/ipfs-cookbook.git - revision: 5c31191ff8571bc8425375fbf938913ac64aa2ee - ref: v0.4.1 + revision: d7c25b6ce5fa490b6de3529fdc163fb64f1ece8a + ref: v0.7.0 java (~> 4.3.0) logrotate (= 2.2.0) mariadb (= 0.3.1) @@ -92,7 +92,7 @@ GRAPH hostname (0.4.2) hostsfile (>= 0.0.0) hostsfile (2.4.5) - ipfs (0.4.1) + ipfs (0.7.0) ark (>= 0.0.0) java (4.3.0) homebrew (>= 0.0.0) diff --git a/cookbooks/ipfs/.kitchen.dokken.yml b/cookbooks/ipfs/.kitchen.dokken.yml index 856fa9a..436ce57 100644 --- a/cookbooks/ipfs/.kitchen.dokken.yml +++ b/cookbooks/ipfs/.kitchen.dokken.yml @@ -13,12 +13,10 @@ provisioner: verifier: name: inspec + root_path: '/opt/verifier' # Needed for the specs to be detected in Docker + chef_license: accept platforms: - - name: ubuntu-16.04 - driver: - image: dokken/ubuntu-16.04 - pid_one_command: /bin/systemd - name: ubuntu-18.04 driver: image: dokken/ubuntu-18.04 @@ -33,8 +31,3 @@ suites: run_list: - recipe[ipfs::default] attributes: - - name: cluster - run_list: - - recipe[ipfs::cluster] - - recipe[ipfs::cluster_service] - attributes: diff --git a/cookbooks/ipfs/.kitchen.yml b/cookbooks/ipfs/.kitchen.yml index 5c9425c..a14a206 100644 --- a/cookbooks/ipfs/.kitchen.yml +++ b/cookbooks/ipfs/.kitchen.yml @@ -6,17 +6,14 @@ provisioner: name: chef_zero platforms: - - name: ubuntu-16.04 - name: ubuntu-18.04 - name: debian-9 +verifier: + chef_license: accept + suites: - name: default run_list: - recipe[ipfs::default] attributes: - - name: cluster - run_list: - - recipe[ipfs::cluster] - - recipe[ipfs::cluster_service] - attributes: diff --git a/cookbooks/ipfs/.travis.yml b/cookbooks/ipfs/.travis.yml index c581c93..10fb3d6 100644 --- a/cookbooks/ipfs/.travis.yml +++ b/cookbooks/ipfs/.travis.yml @@ -20,7 +20,6 @@ services: docker env: matrix: - INSTANCE=default-debian-9 - - INSTANCE=default-ubuntu-1604 - INSTANCE=default-ubuntu-1804 before_script: @@ -30,7 +29,7 @@ before_script: - cookstyle --version - foodcritic --version -script: CHEF_LICENSE=accept-no-persist KITCHEN_LOCAL_YAML=.kitchen.dokken.yml CHEF_VERSION=13.10.4 kitchen verify ${INSTANCE} +script: CHEF_LICENSE=accept-no-persist KITCHEN_LOCAL_YAML=.kitchen.dokken.yml kitchen test ${INSTANCE} matrix: include: diff --git a/cookbooks/ipfs/Berksfile.lock b/cookbooks/ipfs/Berksfile.lock index 1167417..9034595 100644 --- a/cookbooks/ipfs/Berksfile.lock +++ b/cookbooks/ipfs/Berksfile.lock @@ -10,7 +10,7 @@ GRAPH build-essential (8.1.1) mingw (>= 1.1) seven_zip (>= 0.0.0) - ipfs (0.4.0) + ipfs (0.4.2) ark (>= 0.0.0) mingw (2.1.0) seven_zip (>= 0.0.0) diff --git a/cookbooks/ipfs/attributes/default.rb b/cookbooks/ipfs/attributes/default.rb index ec65268..82a45e7 100644 --- a/cookbooks/ipfs/attributes/default.rb +++ b/cookbooks/ipfs/attributes/default.rb @@ -1,5 +1,5 @@ -node.default['ipfs']['version'] = '0.4.22' -node.default['ipfs']['checksum'] = '43431bbef105b1c8d0679350d6f496b934d005df28c13280a67f0c88054976aa' +node.default['ipfs']['version'] = '0.7.0' +node.default['ipfs']['checksum'] = 'ef7c3f1bcae94c13c6e1033855ff99bb8e19089e01ea5018437847854c8c811f' node.default['ipfs']['ulimit'] = 64000 node.default['ipfs']['memory_max'] = '512M' diff --git a/cookbooks/ipfs/metadata.json b/cookbooks/ipfs/metadata.json index 7f1ec90..a8fe82e 100644 --- a/cookbooks/ipfs/metadata.json +++ b/cookbooks/ipfs/metadata.json @@ -1,6 +1,6 @@ { "name": "ipfs", - "description": "Installs/Configures ipfs", + "description": "Installs/Configures go-ipfs", "long_description": "# IPFS Cookbook\n\nThis cookbook installs go-ipfs and starts it as a daemon\n\n## Requirements\n\n### Platforms\n\nThis cookbook is tested on Ubuntu 18.06, 16.04 and Debian 9 using Test Kitchen.\nIt currently only supports 64bit platforms\n\n### Chef\n\n- Chef 12.5 or later (the cookbook provides a\n [Custom Resource](https://docs.chef.io/custom_resources.html) to configure\n go-ipfs)\n\n### Cookbook dependencies\n\n- `ark` to download and uncompress the go-ipfs package\n\n## Usage\n\n### ipfs::default\n\nJust include `ipfs` in your node's `run_list`:\n\n```json\n{\n \"name\":\"my_node\",\n \"run_list\": [\n \"recipe[ipfs]\"\n ]\n}\n```\n\n## Attributes\n\n- `node['ipfs']['version']` - the go-ipfs version to download from the official\nsite (64bit)\n- `node['ipfs']['checksum']` - the SHA256 checksum for the package\n- `node['ipfs']['config']` - a hash of config options\n\n## Resources\n\n`ipfs_config` sets the config. Supports hashes, arrays, booleans and strings.\nDoes not change anything if the config already has that value, and restarts\nthe server automatically\n\n```ruby\nipfs_config \"Gateway.Writable\" do\n value \"true\"\n end\n```\n\n## Running the specs and integrations tests\n\nInstall the latest [Chef DK](https://downloads.chef.io/chefdk).\n\n```\nchef exec delivery local all # Run the linting check, syntax check and unit tests\nkitchen verify # Run the integration tests for Ubuntu 16.04, 18.06 and Debian 9\n```\n\n## License and Authors\n\nAuthors: Kosmos Developers mail@kosmos.org \nCopyright: 2018-2019, [Kosmos Developers](https://kredits.kosmos.org/)\n\n```\nUnless otherwise noted, all files are released under the MIT license, possible\nexceptions will contain licensing information in them.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n", "maintainer": "Kosmos Developers", "maintainer_email": "mail@kosmos.org", @@ -17,7 +17,7 @@ "recipes": { }, - "version": "0.4.1", + "version": "0.7.0", "source_url": "https://github.com/67P/ipfs-cookbook", "issues_url": "https://github.com/67P/ipfs-cookbook/issues", "privacy": false, diff --git a/cookbooks/ipfs/metadata.rb b/cookbooks/ipfs/metadata.rb index 42758b4..1e8e777 100644 --- a/cookbooks/ipfs/metadata.rb +++ b/cookbooks/ipfs/metadata.rb @@ -2,9 +2,9 @@ name 'ipfs' maintainer 'Kosmos Developers' maintainer_email 'mail@kosmos.org' license 'MIT' -description 'Installs/Configures ipfs' +description 'Installs/Configures go-ipfs' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '0.4.1' +version '0.7.0' supports %w(ubuntu debian) diff --git a/cookbooks/ipfs/recipes/default.rb b/cookbooks/ipfs/recipes/default.rb index 73799a6..ab623b6 100644 --- a/cookbooks/ipfs/recipes/default.rb +++ b/cookbooks/ipfs/recipes/default.rb @@ -32,6 +32,7 @@ ark 'ipfs' do url "https://dist.ipfs.io/go-ipfs/v#{version}/go-ipfs_v#{version}_linux-amd64.tar.gz" checksum node['ipfs']['checksum'] has_binaries ['ipfs'] + notifies :restart, 'service[ipfs]', :delayed end execute 'ipfs init --empty-repo' do diff --git a/cookbooks/ipfs/test/integration/default/serverspec/ipfs_spec.rb b/cookbooks/ipfs/test/integration/default/serverspec/ipfs_spec.rb index 48cb2b4..2c6b9c5 100644 --- a/cookbooks/ipfs/test/integration/default/serverspec/ipfs_spec.rb +++ b/cookbooks/ipfs/test/integration/default/serverspec/ipfs_spec.rb @@ -45,10 +45,7 @@ describe 'IPFS' do { 'Swarm.AddrFilters' => addr_filters.rstrip, - 'Swarm.DisableBandwidthMetrics' => true, - 'Swarm.DisableRelay' => true, - 'Swarm.ConnMgr.HighWater' => 10, - 'Swarm.ConnMgr.LowWater' => 1, + 'Gateway.Writable' => true, }.each do |k, v| describe command("IPFS_PATH=/home/ipfs/.ipfs ipfs config '#{k}'") do let(:sudo_options) { '-u ipfs -i' } From c06d530f622fd1434050bfa22d37c7d949263190 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 25 Oct 2020 12:09:22 +0100 Subject: [PATCH 136/327] Update ipfs-1 kernel version --- nodes/ipfs-1.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodes/ipfs-1.json b/nodes/ipfs-1.json index 85d0e6a..5428880 100644 --- a/nodes/ipfs-1.json +++ b/nodes/ipfs-1.json @@ -8,7 +8,7 @@ "automatic": { "fqdn": "ipfs-1", "os": "linux", - "os_version": "5.4.0-48-generic", + "os_version": "5.4.0-52-generic", "hostname": "ipfs-1", "ipaddress": "192.168.122.195", "roles": [ From f874d7f9795b9eb82670584d53575a3355f7c8ac Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 29 Oct 2020 16:19:24 +0100 Subject: [PATCH 137/327] Remove hubot-rss-reader from hubots Not available in latest hal8000 source anymore --- site-cookbooks/kosmos-hubot/attributes/default.rb | 8 +++----- site-cookbooks/kosmos-hubot/recipes/hal8000.rb | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/site-cookbooks/kosmos-hubot/attributes/default.rb b/site-cookbooks/kosmos-hubot/attributes/default.rb index 0cb51cf..49c7a2e 100644 --- a/site-cookbooks/kosmos-hubot/attributes/default.rb +++ b/site-cookbooks/kosmos-hubot/attributes/default.rb @@ -7,11 +7,9 @@ node.default['hal8000_xmpp']['http_port'] = 8082 node.default['hal8000_xmpp']['domain'] = "hal8000.chat.kosmos.org" node.default['hal8000_xmpp']['hubot_scripts'] = [ - "hubot-help", "hubot-redis-brain", - "hubot-rules", "hubot-shipit", "hubot-plusplus", - "hubot-tell", "hubot-seen", "hubot-rss-reader", - "hubot-incoming-webhook", "hubot-auth", - "hubot-kredits", "hubot-schedule" + "hubot-help", "hubot-redis-brain", "hubot-rules", "hubot-shipit", + "hubot-plusplus", "hubot-tell", "hubot-seen", "hubot-incoming-webhook", + "hubot-auth", "hubot-kredits", "hubot-schedule" ] node.default['hal8000_xmpp']['rooms'] = [ diff --git a/site-cookbooks/kosmos-hubot/recipes/hal8000.rb b/site-cookbooks/kosmos-hubot/recipes/hal8000.rb index 87e92c6..b3c787e 100644 --- a/site-cookbooks/kosmos-hubot/recipes/hal8000.rb +++ b/site-cookbooks/kosmos-hubot/recipes/hal8000.rb @@ -67,7 +67,6 @@ application hal8000_path do "hubot-plusplus", "hubot-tell", "hubot-seen", - "hubot-rss-reader", "hubot-incoming-webhook", "hubot-auth", "hubot-schedule" From 4c17d9ad53abfbbc9930fe522fd402afa1539686 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 30 Oct 2020 10:00:23 +0100 Subject: [PATCH 138/327] Update barnard.kosmos.org node data --- nodes/barnard.kosmos.org.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nodes/barnard.kosmos.org.json b/nodes/barnard.kosmos.org.json index 3dd4a4c..db6fdf3 100644 --- a/nodes/barnard.kosmos.org.json +++ b/nodes/barnard.kosmos.org.json @@ -11,7 +11,7 @@ "automatic": { "fqdn": "barnard.kosmos.org", "os": "linux", - "os_version": "4.15.0-54-generic", + "os_version": "4.15.0-122-generic", "hostname": "barnard", "ipaddress": "104.248.95.16", "roles": [ @@ -43,6 +43,7 @@ "ntp::default", "ntp::apparmor", "kosmos-base::systemd_emails", + "apt::unattended-upgrades", "kosmos-base::firewall", "kosmos-postfix::default", "postfix::default", From ac49430521d7b0fd145be63772cfe3f4296e9621 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 8 Nov 2020 17:23:24 +0100 Subject: [PATCH 139/327] Install lib389 Fixes 389 CLIs not working (e.g. `dsctl`). --- site-cookbooks/kosmos-dirsrv/resources/instance.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/site-cookbooks/kosmos-dirsrv/resources/instance.rb b/site-cookbooks/kosmos-dirsrv/resources/instance.rb index 3f0d37b..7b99f9e 100644 --- a/site-cookbooks/kosmos-dirsrv/resources/instance.rb +++ b/site-cookbooks/kosmos-dirsrv/resources/instance.rb @@ -11,6 +11,7 @@ property :port, Integer, default: 389 action :create do include_recipe "apt" package "389-ds-base" + package "python3-lib389" include_recipe "ulimit" user_ulimit "dirsrv" do From ebf5f405f56f90b396c6ccb3492635a57a2ff149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 19 Nov 2020 12:57:58 +0100 Subject: [PATCH 140/327] Initial kosmos_drone cookbook Closes #235 --- data_bags/credentials/drone.json | 24 ++++ site-cookbooks/kosmos_drone/.gitignore | 22 ++++ site-cookbooks/kosmos_drone/CHANGELOG.md | 7 ++ site-cookbooks/kosmos_drone/LICENSE | 21 ++++ site-cookbooks/kosmos_drone/README.md | 3 + site-cookbooks/kosmos_drone/chefignore | 110 ++++++++++++++++++ site-cookbooks/kosmos_drone/metadata.rb | 11 ++ .../kosmos_drone/recipes/default.rb | 85 ++++++++++++++ .../templates/docker-compose.yml.erb | 36 ++++++ .../kosmos_drone/templates/nginx_conf.erb | 34 ++++++ 10 files changed, 353 insertions(+) create mode 100644 data_bags/credentials/drone.json create mode 100644 site-cookbooks/kosmos_drone/.gitignore create mode 100644 site-cookbooks/kosmos_drone/CHANGELOG.md create mode 100644 site-cookbooks/kosmos_drone/LICENSE create mode 100644 site-cookbooks/kosmos_drone/README.md create mode 100644 site-cookbooks/kosmos_drone/chefignore create mode 100644 site-cookbooks/kosmos_drone/metadata.rb create mode 100644 site-cookbooks/kosmos_drone/recipes/default.rb create mode 100644 site-cookbooks/kosmos_drone/templates/docker-compose.yml.erb create mode 100644 site-cookbooks/kosmos_drone/templates/nginx_conf.erb diff --git a/data_bags/credentials/drone.json b/data_bags/credentials/drone.json new file mode 100644 index 0000000..d499634 --- /dev/null +++ b/data_bags/credentials/drone.json @@ -0,0 +1,24 @@ +{ + "id": "drone", + "client_id": { + "encrypted_data": "PHC6f0UJwuaxnhMhxUVhHMqauCu9aYDp3IFqVzsxEoEodKhg8pgTWS14T5E7\nVm4xlcR/CuLcOA==\n", + "iv": "on4hNp3g6pLsvfTE\n", + "auth_tag": "ytx40h2fsBHhDpyhwKbHog==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "client_secret": { + "encrypted_data": "HAKFqsrbL447wgropHz2rgHmyRl3G2d24svTT+TYMI0jtQFTQPZLxNZkl3ki\n42n7baNrfXN3IJeQRyxyihw0\n", + "iv": "pmdiLiFgSPNNP7dl\n", + "auth_tag": "4j98l+lZ0k4mLioJHS5VJw==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "rpc_secret": { + "encrypted_data": "ll4f3ECLQTgJj47aeqnP0Ci1ncMYTwwFw1J46Qx3gPloA2YGPwlfa82Uck1k\neSHCTSNW\n", + "iv": "hP5Iq9zOjELUb9d8\n", + "auth_tag": "WJlme717tpgbWPcXwFzyvQ==\n", + "version": 3, + "cipher": "aes-256-gcm" + } +} \ No newline at end of file diff --git a/site-cookbooks/kosmos_drone/.gitignore b/site-cookbooks/kosmos_drone/.gitignore new file mode 100644 index 0000000..9abf29f --- /dev/null +++ b/site-cookbooks/kosmos_drone/.gitignore @@ -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 diff --git a/site-cookbooks/kosmos_drone/CHANGELOG.md b/site-cookbooks/kosmos_drone/CHANGELOG.md new file mode 100644 index 0000000..e781d99 --- /dev/null +++ b/site-cookbooks/kosmos_drone/CHANGELOG.md @@ -0,0 +1,7 @@ +# kosmos_drone CHANGELOG + +This file is used to list changes made in each version of the kosmos_drone cookbook. + +# 0.1.0 + +Initial release. diff --git a/site-cookbooks/kosmos_drone/LICENSE b/site-cookbooks/kosmos_drone/LICENSE new file mode 100644 index 0000000..dd321fd --- /dev/null +++ b/site-cookbooks/kosmos_drone/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +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. diff --git a/site-cookbooks/kosmos_drone/README.md b/site-cookbooks/kosmos_drone/README.md new file mode 100644 index 0000000..f2ccd1d --- /dev/null +++ b/site-cookbooks/kosmos_drone/README.md @@ -0,0 +1,3 @@ +# kosmos_drone + +Sets up [Drone](https://www.drone.io/) using Docker Compose diff --git a/site-cookbooks/kosmos_drone/chefignore b/site-cookbooks/kosmos_drone/chefignore new file mode 100644 index 0000000..5039e1c --- /dev/null +++ b/site-cookbooks/kosmos_drone/chefignore @@ -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 diff --git a/site-cookbooks/kosmos_drone/metadata.rb b/site-cookbooks/kosmos_drone/metadata.rb new file mode 100644 index 0000000..5c14444 --- /dev/null +++ b/site-cookbooks/kosmos_drone/metadata.rb @@ -0,0 +1,11 @@ +name 'kosmos_drone' +maintainer 'Kosmos Developers' +maintainer_email 'mail@kosmos.org' +license 'MIT' +description 'Installs/Configures kosmos_drone' +long_description 'Installs/Configures kosmos_drone' +version '0.1.0' +chef_version '>= 14.0' + +depends "kosmos-nginx" +depends "kosmos_gitea" diff --git a/site-cookbooks/kosmos_drone/recipes/default.rb b/site-cookbooks/kosmos_drone/recipes/default.rb new file mode 100644 index 0000000..f8629fc --- /dev/null +++ b/site-cookbooks/kosmos_drone/recipes/default.rb @@ -0,0 +1,85 @@ +# +# Cookbook:: kosmos_drone +# 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. + +package "docker-compose" +domain = "drone.kosmos.org" +deploy_path = "/opt/drone" +upstream_port = 3002 +credentials = data_bag_item("credentials", "drone") + +directory deploy_path do + action :create +end + +template "#{deploy_path}/docker-compose.yml" do + source "docker-compose.yml.erb" + sensitive true + mode 0640 + variables upstream_port: upstream_port, + domain: domain, + gitea_server: "https://#{node["kosmos_gitea"]["nginx"]["domain"]}", + client_id: credentials['client_id'], + client_secret: credentials['client_secret'], + rpc_secret: credentials['rpc_secret'], + max_procs: 4 +end + +systemd_unit "drone.service" do + content({Unit: { + Description: "drone service with docker compose", + Requires: "docker.service", + After: "docker.service", + }, + Service: { + Restart: "always", + WorkingDirectory: deploy_path, + ExecStart: "/usr/bin/docker-compose up", + ExecStartPre: "/usr/bin/docker-compose rm -f", + ExecStop: "/usr/bin/docker-compose down", + }, + Install: { + WantedBy: "multi-user.target", + }}) + action [:create, :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: upstream_port + + notifies :reload, 'service[nginx]', :delayed +end + +nginx_site domain do + action :enable +end + +nginx_certbot_site domain diff --git a/site-cookbooks/kosmos_drone/templates/docker-compose.yml.erb b/site-cookbooks/kosmos_drone/templates/docker-compose.yml.erb new file mode 100644 index 0000000..7854ce8 --- /dev/null +++ b/site-cookbooks/kosmos_drone/templates/docker-compose.yml.erb @@ -0,0 +1,36 @@ +version: '3' + +services: + drone-server: + image: drone/drone:1 + + ports: + - "<%= @upstream_port %>:80" + volumes: + - drone-server-data:/data + restart: always + environment: + - DRONE_USER_CREATE=username:greg,admin:true + - DRONE_GITEA_SERVER=<%= @gitea_server %> + - DRONE_GITEA_CLIENT_ID=<%= @client_id %> + - DRONE_GITEA_CLIENT_SECRET=<%= @client_secret %> + - DRONE_SERVER_HOST=<%= @domain %> + - DRONE_SERVER_PROTO=https # required for the Redirect URI to be built correctly + - DRONE_RPC_SECRET=<%= @rpc_secret %> + + drone-runner: + image: drone/drone-runner-docker:1 + + command: agent + restart: always + depends_on: + - drone-server + volumes: + - /var/run/docker.sock:/var/run/docker.sock + environment: + - DRONE_RPC_HOST=drone-server:80 + - DRONE_RPC_SECRET=<%= @rpc_secret %> + - DRONE_RUNNER_MAX_PROCS=<%= @max_procs %> + +volumes: + drone-server-data: diff --git a/site-cookbooks/kosmos_drone/templates/nginx_conf.erb b/site-cookbooks/kosmos_drone/templates/nginx_conf.erb new file mode 100644 index 0000000..4226de7 --- /dev/null +++ b/site-cookbooks/kosmos_drone/templates/nginx_conf.erb @@ -0,0 +1,34 @@ +<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%> +# Generated by Chef +upstream _drone { + server localhost:<%= @upstream_port %>; +} + +server { + server_name <%= @server_name %>; + listen 443 ssl http2; + listen [::]:443 ssl http2; + + ssl_certificate <%= @ssl_cert %>; + ssl_certificate_key <%= @ssl_key %>; + + add_header Strict-Transport-Security "max-age=31536000"; + + # Send real IP to the Docker container + set_real_ip_from 127.0.0.1; + set_real_ip_from 172.17.0.1; + real_ip_header X-Forwarded-For; + + client_max_body_size 20M; + + location / { + # Increase number of buffers. Default is 8 + proxy_buffers 1024 8k; + + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_pass http://_drone; + proxy_http_version 1.1; + } +} +<% end -%> From d7e54bf7ce0bbeb332c23226b38b533da9bd1973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 19 Nov 2020 12:58:22 +0100 Subject: [PATCH 141/327] Add drone role --- roles/drone.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 roles/drone.rb diff --git a/roles/drone.rb b/roles/drone.rb new file mode 100644 index 0000000..4ee08ac --- /dev/null +++ b/roles/drone.rb @@ -0,0 +1,5 @@ +name "drone" + +run_list %w( + kosmos_drone::default +) From df4c92b64eb28ef0116924d93cd718227f8952a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 19 Nov 2020 12:58:31 +0100 Subject: [PATCH 142/327] Update the centaurus node after adding drone to it --- nodes/centaurus.kosmos.org.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nodes/centaurus.kosmos.org.json b/nodes/centaurus.kosmos.org.json index 9819521..dd3d075 100644 --- a/nodes/centaurus.kosmos.org.json +++ b/nodes/centaurus.kosmos.org.json @@ -15,7 +15,8 @@ "gitea", "postgresql_client", "postgresql_replica", - "discourse" + "discourse", + "drone" ], "recipes": [ "kosmos-base", @@ -28,6 +29,8 @@ "kosmos-postgresql::replica", "kosmos_discourse", "kosmos_discourse::default", + "kosmos_drone", + "kosmos_drone::default", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -77,6 +80,7 @@ "recipe[kosmos_encfs]", "role[gitea]", "role[postgresql_replica]", - "role[discourse]" + "role[discourse]", + "role[drone]" ] } \ No newline at end of file From b63c86b37f5fcb274dad55221406ffe974743223 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 20 Nov 2020 14:36:25 +0100 Subject: [PATCH 143/327] Add CLI script for hashing LDAP passwords Only takes a cleartext password and outputs a salted, hashed password string for LDAP documents. --- scripts/ldap/hash_pw.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100755 scripts/ldap/hash_pw.sh diff --git a/scripts/ldap/hash_pw.sh b/scripts/ldap/hash_pw.sh new file mode 100755 index 0000000..327f16d --- /dev/null +++ b/scripts/ldap/hash_pw.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +password=$(ruby -r base64 -r digest -r securerandom -e "salt = SecureRandom.hex(32); password = '$1'; puts '{SSHA512}' + Base64.strict_encode64(Digest::SHA512.digest(password + salt) + salt)"); + +echo $password; From d384f691393ce8588230c209c8c70450eef01e8d Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 20 Nov 2020 23:22:42 +0100 Subject: [PATCH 144/327] Configure/deploy new akkounts app --- data_bags/credentials/akkounts.json | 17 ++ .../kosmos-akkounts/attributes/default.rb | 7 +- site-cookbooks/kosmos-akkounts/metadata.rb | 17 +- .../kosmos-akkounts/recipes/default.rb | 152 +++++++++++------- .../kosmos-akkounts/recipes/nginx.rb | 21 +-- .../kosmos-akkounts/templates/dotenv.erb | 13 -- .../templates/nginx_conf_akkounts-api.erb | 28 ---- .../templates/nginx_conf_akkounts.erb | 54 +++++++ .../templates/nodejs.systemd.service.erb | 15 -- 9 files changed, 191 insertions(+), 133 deletions(-) create mode 100644 data_bags/credentials/akkounts.json delete mode 100644 site-cookbooks/kosmos-akkounts/templates/dotenv.erb delete mode 100644 site-cookbooks/kosmos-akkounts/templates/nginx_conf_akkounts-api.erb create mode 100644 site-cookbooks/kosmos-akkounts/templates/nginx_conf_akkounts.erb delete mode 100644 site-cookbooks/kosmos-akkounts/templates/nodejs.systemd.service.erb diff --git a/data_bags/credentials/akkounts.json b/data_bags/credentials/akkounts.json new file mode 100644 index 0000000..1c4ab41 --- /dev/null +++ b/data_bags/credentials/akkounts.json @@ -0,0 +1,17 @@ +{ + "id": "akkounts", + "postgresql_password": { + "encrypted_data": "Vt/jXxrJPbJbEl8Nw9EdVymoId21hdzHxA0zwEfAkA==\n", + "iv": "rV3dOjUhPsrdhF59\n", + "auth_tag": "GwuMLjf5zqTxLUIKb7ZKjA==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "rails_master_key": { + "encrypted_data": "GjtdLy59dThzWYbEUD9Ss4G9vC3tcVgWDWLz3AoUl/jjJfSP2ym7ErjYwJhl\nE+1J2T3+\n", + "iv": "7PJXyCr2ozJHsMWZ\n", + "auth_tag": "nuW914Rh3Cn+ldGMc1JdGw==\n", + "version": 3, + "cipher": "aes-256-gcm" + } +} \ No newline at end of file diff --git a/site-cookbooks/kosmos-akkounts/attributes/default.rb b/site-cookbooks/kosmos-akkounts/attributes/default.rb index 692c1ee..ad6f4ea 100644 --- a/site-cookbooks/kosmos-akkounts/attributes/default.rb +++ b/site-cookbooks/kosmos-akkounts/attributes/default.rb @@ -1,3 +1,4 @@ -node.default['akkounts-api']['revision'] = 'master' -node.default['akkounts-api']['port'] = 3200 -node.default['akkounts-api']['server_name'] = 'api.accounts.kosmos.org' +node.default['akkounts']['repo'] = 'https://gitea.kosmos.org/kosmos/akkounts.git' +node.default['akkounts']['revision'] = 'master' +node.default['akkounts']['port'] = 3000 +node.default['akkounts']['domain'] = 'accounts.kosmos.org' diff --git a/site-cookbooks/kosmos-akkounts/metadata.rb b/site-cookbooks/kosmos-akkounts/metadata.rb index c487b0c..04b9892 100644 --- a/site-cookbooks/kosmos-akkounts/metadata.rb +++ b/site-cookbooks/kosmos-akkounts/metadata.rb @@ -2,13 +2,16 @@ name 'kosmos-akkounts' maintainer 'Kosmos Developers' maintainer_email 'mail@kosmos.org' license 'MIT' -description 'Installs/Configures kosmos-akkounts' -long_description 'Installs/Configures kosmos-akkounts' -version '0.1.0' +description 'Installs/configures kosmos-akkounts' +long_description 'Installs/configures kosmos-akkounts' +version '0.2.0' chef_version '>= 14.0' -depends 'application_javascript' -depends 'application_git' -depends 'kosmos-nodejs' -depends 'kosmos-mastodon' depends 'kosmos-nginx' +depends "kosmos-nodejs" +depends "poise-ruby-build" +depends "application" +depends 'application_git' +depends "postgresql" +depends "kosmos-postgresql" +depends "backup" diff --git a/site-cookbooks/kosmos-akkounts/recipes/default.rb b/site-cookbooks/kosmos-akkounts/recipes/default.rb index 2c874eb..aa00689 100644 --- a/site-cookbooks/kosmos-akkounts/recipes/default.rb +++ b/site-cookbooks/kosmos-akkounts/recipes/default.rb @@ -3,8 +3,7 @@ # Recipe:: default # # The MIT License (MIT) -# -# Copyright:: 2019, Kosmos Developers +# 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 @@ -23,12 +22,11 @@ # 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-nodejs' - -app_name = "akkounts-api" +# +app_name = "akkounts" deploy_user = "deploy" deploy_group = "deploy" +deploy_path = "/opt/#{app_name}" credentials = Chef::EncryptedDataBagItem.load('credentials', app_name) group deploy_group @@ -37,75 +35,115 @@ user deploy_user do group deploy_group manage_home true shell "/bin/bash" - comment "deploy user" end -path_to_deploy = "/opt/#{app_name}" -application path_to_deploy do +package "libpq-dev" + +include_recipe 'kosmos-nodejs' + +npm_package "yarn" do + version "1.22.4" +end + +ruby_version = "2.6.6" +bundle_path = "/opt/ruby_build/builds/#{ruby_version}/bin/bundle" +rails_env = node.chef_environment == "development" ? "development" : "production" + +execute "systemctl daemon-reload" do + command "systemctl daemon-reload" + action :nothing +end + +systemd_unit "akkounts.service" do + content({ + Unit: { + Description: "Kosmos account management", + Documentation: ["https://gitea.kosmos.org/kosmos/akkounts"], + After: "network.target" + }, + Service: { + Type: "simple", + User: deploy_user, + WorkingDirectory: deploy_path, + Environment: "RAILS_ENV=#{rails_env}", + ExecStart: "#{bundle_path} exec puma -C config/puma.rb --pidfile #{deploy_path}/tmp/puma.pid", + ExecStop: "#{bundle_path} exec puma -C config/puma.rb --pidfile #{deploy_path}/tmp/puma.pid stop", + ExecReload: "#{bundle_path} exec pumactl -F config/puma.rb --pidfile #{deploy_path}/tmp/puma.pid phased-restart", + PIDFile: "#{deploy_path}/tmp/puma.pid", + TimeoutSec: "10", + Restart: "always", + }, + Install: { + WantedBy: "multi-user.target" + } + }) + verify false + triggers_reload true + action [:create, :enable] +end + +application deploy_path do owner deploy_user group deploy_group # Take care of application restarts manually, in the git resource action_on_update false + environment "HOME" => deploy_path, + "PATH" => "/opt/ruby_build/builds/#{ruby_version}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" + + ruby_runtime ruby_version do + provider :ruby_build + version ruby_version + end + git do - user deploy_user - group deploy_group - repository "https://github.com/67P/#{app_name}.git" - revision node[app_name]['revision'] - # Restart service on deployments - notifies :restart, "application[#{path_to_deploy}]", :delayed - end - - npm_install do user deploy_user + group deploy_group + repository node[app_name]["repo"] + revision node[app_name]["revision"] + # Restart services on deployments + notifies :restart, "application[#{deploy_path}]", :delayed end - execute "systemctl daemon-reload" do - command "systemctl daemon-reload" - action :nothing - end - - smtp_credentials = Chef::EncryptedDataBagItem.load('credentials', 'smtp') - - template "#{path_to_deploy}/.env" do - source "dotenv.erb" - sensitive true + file "#{deploy_path}/config/master.key" do + content credentials['rails_master_key'] + mode '0400' owner deploy_user group deploy_group - variables btcpay_url: "https://btcpay.kosmos.org", - btcpay_privkey: credentials["btcpay_privkey"], - btcpay_merchant: credentials["btcpay_merchant"], - btcpay_store_id: credentials["btcpay_store_id"], - btcpay_webhook_host: "https://#{node[app_name]["server_name"]}", - btcpay_webhook_token: credentials["btcpay_webhook_token"], - smtp_host: "smtp.mailgun.org", - smtp_use_tls: true, - smtp_username: smtp_credentials['user_name'], - smtp_password: smtp_credentials['password'], - mastodon_host: "https://#{node["kosmos-mastodon"]["server_name"]}", - mastodon_auth_token: credentials["mastodon_auth_token"] - mode '0440' - # Restart service when the config changes - notifies :restart, "application[#{path_to_deploy}]", :delayed end - template "/lib/systemd/system/#{app_name}.service" do - source 'nodejs.systemd.service.erb' - owner 'root' - group 'root' - mode '0640' - variables( - user: deploy_user, - group: deploy_group, - app_dir: path_to_deploy, - entry: "/usr/bin/env node release/index.js" - ) - notifies :run, "execute[systemctl daemon-reload]", :delayed - notifies :restart, "service[#{app_name}]", :delayed + execute "bundle install" do + environment "HOME" => deploy_path + user deploy_user + cwd deploy_path + command "/opt/ruby_build/builds/#{ruby_version}/bin/bundle install --without development,test --deployment" end - service app_name do + execute "yarn install" do + environment "HOME" => deploy_path, "NODE_ENV" => "production" + user deploy_user + cwd deploy_path + command "yarn install --pure-lockfile" + end + + execute 'rake db:migrate' do + environment "RAILS_ENV" => rails_env, "HOME" => deploy_path + user deploy_user + group deploy_group + cwd deploy_path + command "PATH=\"/opt/ruby_build/builds/#{ruby_version}/bin:$PATH\" bundle exec rake db:migrate" + end + + execute 'rake assets:precompile' do + environment "RAILS_ENV" => rails_env, "HOME" => deploy_path + user deploy_user + group deploy_group + cwd deploy_path + command "PATH=\"/opt/ruby_build/builds/#{ruby_version}/bin:$PATH\" bundle exec rake assets:precompile" + end + + service "akkounts" do action [:enable, :start] end end diff --git a/site-cookbooks/kosmos-akkounts/recipes/nginx.rb b/site-cookbooks/kosmos-akkounts/recipes/nginx.rb index 9a2b6a4..e9afb74 100644 --- a/site-cookbooks/kosmos-akkounts/recipes/nginx.rb +++ b/site-cookbooks/kosmos-akkounts/recipes/nginx.rb @@ -4,7 +4,7 @@ # # The MIT License (MIT) # -# Copyright:: 2019, Kosmos Developers +# 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 @@ -25,22 +25,23 @@ # THE SOFTWARE. include_recipe "kosmos-nginx" -app_name = "akkounts-api" -server_name = node[app_name]["server_name"] +app_name = "akkounts" +domain = node[app_name]["domain"] -template "#{node['nginx']['dir']}/sites-available/#{server_name}" do +template "#{node['nginx']['dir']}/sites-available/#{domain}" do source "nginx_conf_#{app_name}.erb" owner 'www-data' mode 0640 - variables port: node[app_name]['port'], - server_name: server_name, - ssl_cert: "/etc/letsencrypt/live/#{server_name}/fullchain.pem", - ssl_key: "/etc/letsencrypt/live/#{server_name}/privkey.pem" + variables port: node[app_name]['port'], + domain: domain, + root_dir: "/opt/#{app_name}/public", + ssl_cert: "/etc/letsencrypt/live/#{domain}/fullchain.pem", + ssl_key: "/etc/letsencrypt/live/#{domain}/privkey.pem" notifies :reload, 'service[nginx]', :delayed end -nginx_site server_name do +nginx_site domain do action :enable end -nginx_certbot_site server_name +nginx_certbot_site domain diff --git a/site-cookbooks/kosmos-akkounts/templates/dotenv.erb b/site-cookbooks/kosmos-akkounts/templates/dotenv.erb deleted file mode 100644 index 15ae3b2..0000000 --- a/site-cookbooks/kosmos-akkounts/templates/dotenv.erb +++ /dev/null @@ -1,13 +0,0 @@ -BTCPAY_URL=<%= @btcpay_url %> -BTCPAY_PRIVKEY=<%= @btcpay_privkey %> -BTCPAY_MERCHANT=<%= @btcpay_merchant %> -BTCPAY_STORE_ID=<%= @btcpay_store_id %> -BTCPAY_WEBHOOK_HOST=<%= @btcpay_webhook_host %> -BTCPAY_WEBHOOK_TOKEN=<%= @btcpay_webhook_token %> -SMTP_HOST=<%= @smtp_host %> -SMTP_USE_TLS=true -SMTP_USERNAME=<%= @smtp_username %> -SMTP_PASSWORD=<%= @smtp_password %> -MASTODON_HOST=<%= @mastodon_host %> -MASTODON_AUTH_TOKEN=<%= @mastodon_auth_token %> -PORT=<%= node['akkounts-api']['port'] %> diff --git a/site-cookbooks/kosmos-akkounts/templates/nginx_conf_akkounts-api.erb b/site-cookbooks/kosmos-akkounts/templates/nginx_conf_akkounts-api.erb deleted file mode 100644 index 58b7eeb..0000000 --- a/site-cookbooks/kosmos-akkounts/templates/nginx_conf_akkounts-api.erb +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Chef -<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%> -upstream _akkounts { - server localhost:<%= @port %>; -} - -server { - listen 443 ssl http2; - add_header Strict-Transport-Security "max-age=15768000"; - - ssl_certificate <%= @ssl_cert %>; - ssl_certificate_key <%= @ssl_key %>; - - server_name <%= @server_name %>; - - access_log <%= node[:nginx][:log_dir] %>/<%= @server_name %>.access.log json; - error_log <%= node[:nginx][:log_dir] %>/<%= @server_name %>.error.log warn; - - location / { - # Increase number of buffers. Default is 8 - proxy_buffers 1024 8k; - - proxy_pass http://_akkounts; - proxy_http_version 1.1; - } - -} -<% end -%> diff --git a/site-cookbooks/kosmos-akkounts/templates/nginx_conf_akkounts.erb b/site-cookbooks/kosmos-akkounts/templates/nginx_conf_akkounts.erb new file mode 100644 index 0000000..d3f9c96 --- /dev/null +++ b/site-cookbooks/kosmos-akkounts/templates/nginx_conf_akkounts.erb @@ -0,0 +1,54 @@ +# Generated by Chef +<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%> +upstream _akkounts { + server localhost:<%= @port %>; +} + +server { + listen 443 ssl http2; + add_header Strict-Transport-Security "max-age=15768000"; + + ssl_certificate <%= @ssl_cert %>; + ssl_certificate_key <%= @ssl_key %>; + + server_name <%= @domain %>; + + access_log <%= node[:nginx][:log_dir] %>/<%= @domain %>.access.log json; + error_log <%= node[:nginx][:log_dir] %>/<%= @domain %>.error.log warn; + + root <%= @root_dir %>; + + location ~ ^/(assets|packs|images|javascripts|stylesheets|swfs|system)/ { + access_log off; + gzip_static on; + expires max; + add_header Cache-Control public; + } + + try_files $uri/index.html $uri @app; + + location @app { + # an HTTP header important enough to have its own Wikipedia entry: + # http://en.wikipedia.org/wiki/X-Forwarded-For + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + # enable this if and only if you use HTTPS, this helps Rack + # set the proper protocol for doing redirects: + proxy_set_header X-Forwarded-Proto https; + + # pass the Host: header from the client right along so redirects + # can be set properly within the Rack application + proxy_set_header Host $http_host; + + # we don't want nginx trying to do something clever with + # redirects, we set the Host: header above already. + proxy_redirect off; + + # Increase number of buffers. Default is 8 + proxy_buffers 1024 8k; + + proxy_pass http://_akkounts; + proxy_http_version 1.1; + } +} +<% end -%> diff --git a/site-cookbooks/kosmos-akkounts/templates/nodejs.systemd.service.erb b/site-cookbooks/kosmos-akkounts/templates/nodejs.systemd.service.erb deleted file mode 100644 index 76a74e8..0000000 --- a/site-cookbooks/kosmos-akkounts/templates/nodejs.systemd.service.erb +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=Start nodejs app - -[Service] -ExecStart=<%= @entry %> -WorkingDirectory=<%= @app_dir %> -User=<%= @user %> -Group=<%= @group %> -<% if @environment -%> -Environment=<% @environment.each do |key, value| -%>'<%= key %>=<%= value %>' <% end %> -<% end -%> -Restart=always - -[Install] -WantedBy=multi-user.target From 0dc314b1e709e2ff79ddad37f541147f52a04e76 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 21 Nov 2020 13:59:11 +0100 Subject: [PATCH 145/327] Add node data for akkounts-1 --- clients/akkounts-1.json | 4 +++ nodes/akkounts-1.json | 74 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 clients/akkounts-1.json create mode 100644 nodes/akkounts-1.json diff --git a/clients/akkounts-1.json b/clients/akkounts-1.json new file mode 100644 index 0000000..90e44d7 --- /dev/null +++ b/clients/akkounts-1.json @@ -0,0 +1,4 @@ +{ + "name": "akkounts-1", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0LKcqydrG3zgtmThEg+q\nOcw8QvIB2usMkF4kNMFeqhhdr2q/AtRcq4RJ0u0MiZbkHduGWfG9QZpjmbFZcEke\nURJbddqSDPHFAtrK2+BpcMqNN/mSp59f4MJf6wdLnBoeZCF5pCCXibyj+/754Ly+\nEJNiB1sf1Lu82YW2YM7iLhOLk1QQD2DTfBGbj9swdPrgKK+1npQ4A7O8sOB5gDjb\n9QVLCvCEoYFi+9is0vw/YryEr6tfnNw+CroP2uDfyVfWznF8oPUuttAcHgqDA3CV\n7lCRk9yVt1FKwuq2lFcsMqZ7wO4EoxpzCz/XTnpFPFvgeVinyXjSPsQCBAdwJe5T\nWQIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/akkounts-1.json b/nodes/akkounts-1.json new file mode 100644 index 0000000..4e69606 --- /dev/null +++ b/nodes/akkounts-1.json @@ -0,0 +1,74 @@ +{ + "name": "akkounts-1", + "normal": { + "knife_zero": { + "host": "10.147.20.144" + } + }, + "automatic": { + "fqdn": "akkounts-1", + "os": "linux", + "os_version": "5.4.0-54-generic", + "hostname": "akkounts-1", + "ipaddress": "192.168.122.160", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "kosmos-akkounts", + "kosmos-akkounts::default", + "kosmos-akkounts::nginx", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default", + "kosmos-nodejs::default", + "nodejs::nodejs_from_package", + "nodejs::repo", + "nodejs::npm", + "nodejs::install", + "kosmos-nginx::default", + "nginx::default", + "nginx::package", + "nginx::ohai_plugin", + "nginx::repo", + "nginx::commons", + "nginx::commons_dir", + "nginx::commons_script", + "nginx::commons_conf", + "git::default", + "git::package", + "kosmos-base::letsencrypt" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "chef": { + "version": "15.14.0", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib" + }, + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + } + } + }, + "run_list": [ + "recipe[kosmos-base]", + "recipe[kosmos-akkounts::default]", + "recipe[kosmos-akkounts::nginx]" + ] +} \ No newline at end of file From c26fcd5b265794492c5029655e0453af5d8583f9 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 22 Nov 2020 20:26:56 +0100 Subject: [PATCH 146/327] Remove obsolete manual daemon reload --- site-cookbooks/kosmos-akkounts/recipes/default.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/site-cookbooks/kosmos-akkounts/recipes/default.rb b/site-cookbooks/kosmos-akkounts/recipes/default.rb index aa00689..105ea85 100644 --- a/site-cookbooks/kosmos-akkounts/recipes/default.rb +++ b/site-cookbooks/kosmos-akkounts/recipes/default.rb @@ -49,11 +49,6 @@ ruby_version = "2.6.6" bundle_path = "/opt/ruby_build/builds/#{ruby_version}/bin/bundle" rails_env = node.chef_environment == "development" ? "development" : "production" -execute "systemctl daemon-reload" do - command "systemctl daemon-reload" - action :nothing -end - systemd_unit "akkounts.service" do content({ Unit: { From 9efb9cd78c88c56e9aec25dfdd8f4d0d8d547a97 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 23 Nov 2020 17:37:14 +0100 Subject: [PATCH 147/327] Configure/deploy HTTP upload service on uploads.kosmos.chat https://xmpp.org/extensions/xep-0363.html (Does not contain the config for ejabberd itself yet.) --- data_bags/credentials/ejabberd.json | 25 +++++--- .../kosmos-ejabberd/attributes/default.rb | 9 +++ site-cookbooks/kosmos-ejabberd/metadata.rb | 3 +- .../kosmos-ejabberd/recipes/upload_service.rb | 60 +++++++++++++++++++ .../templates/nginx_conf_upload_service.erb | 19 ++++++ .../kosmos-nginx/recipes/with_perl.rb | 33 ++++++++++ 6 files changed, 139 insertions(+), 10 deletions(-) create mode 100644 site-cookbooks/kosmos-ejabberd/recipes/upload_service.rb create mode 100644 site-cookbooks/kosmos-ejabberd/templates/nginx_conf_upload_service.erb create mode 100644 site-cookbooks/kosmos-nginx/recipes/with_perl.rb diff --git a/data_bags/credentials/ejabberd.json b/data_bags/credentials/ejabberd.json index bda5a71..fb14aca 100644 --- a/data_bags/credentials/ejabberd.json +++ b/data_bags/credentials/ejabberd.json @@ -1,23 +1,30 @@ { "id": "ejabberd", "5apps_ldap_password": { - "encrypted_data": "mfV9TyC4OM055JnyV73mq4qY840pH1tZC9LnIaA3A80CY2kVteC4\n", - "iv": "gpEC3IK9BN9RkaYz\n", - "auth_tag": "WXYWOjUCgEw5OR5VMh+Enw==\n", + "encrypted_data": "H7WrXu2iGreO5MSoaNKAAAQOxh92rij4j4UPffs7Rjq1mtd4dMed\n", + "iv": "uEOoET/OOSDjiELM\n", + "auth_tag": "ehYOXsKPHNXrYNy0xJ+BSw==\n", "version": 3, "cipher": "aes-256-gcm" }, "kosmos_ldap_password": { - "encrypted_data": "Q9znUOIIXU+XsPWet4rDCjHsPPxlA3EfNTkEER/EdfoCajd1Txuh\n", - "iv": "7SAOAwSU8rZGopB1\n", - "auth_tag": "X8yIyw2BFbQMAVTMYLA67g==\n", + "encrypted_data": "1u+tUrEj5JZ0F+j59f7VKztBTyn1vqT6V3H3K7uC9kHQCOUFmg3x\n", + "iv": "NjhasM5iVF6tBzps\n", + "auth_tag": "kSNqc3xEQavZifWcPeeFpA==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "uploads_secret": { + "encrypted_data": "2IVxvsaGP1+D0zOT0g9+Zz4Eg42Y8FPe8GiwQDZq6I1f\n", + "iv": "+Ujln/JDnL/afzZ3\n", + "auth_tag": "v0QBCsEemxBaBvi6kazj+w==\n", "version": 3, "cipher": "aes-256-gcm" }, "admins": { - "encrypted_data": "xKtiBOgn4ysJt4byry31cVJUHEsatWDwHEzEve/N5NxTOh1f4QBD+Q68IYzv\nV0ulBjtW91yFcQqKNx/prAVcK3khbnsEzg8uoub9o6hSMwp16LL5x/u6T6u2\n5DwWBEy08yuaujkko57ir0Yv7mfRedT1i5SaH9pgg5VLm56G/PXrlPFfjwaU\n", - "iv": "fpL3EA1VbXxxi+yq\n", - "auth_tag": "iJMJAmw5gHWLFJM5kdzR9A==\n", + "encrypted_data": "3kH8Cbc4Wy1RMd8HLa7aOCZWCZEyjmXq7JC3T0875472F708JjuOXuEqmUeG\nI82OE7lfMVrOup+hiMk9aCTQqxArayWFRZeWnMN2Ji/dbl12wJ/zKWSOPDQ2\nBHzJ/U6NoHBzmAV/PyirmD8KBNkZxCN8vhCq5azZTnmNQmu8CBxM+qUDDhd1\n", + "iv": "dro4RKs1MDD+riaM\n", + "auth_tag": "7yiBW9jyMzcAPWw/XR8zNQ==\n", "version": 3, "cipher": "aes-256-gcm" } diff --git a/site-cookbooks/kosmos-ejabberd/attributes/default.rb b/site-cookbooks/kosmos-ejabberd/attributes/default.rb index f724394..9a91622 100644 --- a/site-cookbooks/kosmos-ejabberd/attributes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/attributes/default.rb @@ -10,3 +10,12 @@ node.override["tor"]["HiddenServices"]["ejabberd"] = { "5269 127.0.0.1:5269" ] } + +node.default["kosmos-ejabberd"]["uploads"] = { + "domain" => "uploads.kosmos.chat", + "max_upload_size_mb" => "100", + "upload.pm" => { + "repo" => "https://gitea.kosmos.org/kosmos/ngx_http_upload.git", + "revision" => "0.2" + } +} diff --git a/site-cookbooks/kosmos-ejabberd/metadata.rb b/site-cookbooks/kosmos-ejabberd/metadata.rb index 1525cc0..4cf04db 100644 --- a/site-cookbooks/kosmos-ejabberd/metadata.rb +++ b/site-cookbooks/kosmos-ejabberd/metadata.rb @@ -19,8 +19,9 @@ chef_version '>= 12.14' if respond_to?(:chef_version) # # source_url 'https://github.com//kosmos-ejabberd' -depends "kosmos-postgresql" depends "kosmos-base" +depends "kosmos-postgresql" +depends "kosmos-nginx" depends "backup" depends "firewall" depends "tor-full" diff --git a/site-cookbooks/kosmos-ejabberd/recipes/upload_service.rb b/site-cookbooks/kosmos-ejabberd/recipes/upload_service.rb new file mode 100644 index 0000000..3fb4038 --- /dev/null +++ b/site-cookbooks/kosmos-ejabberd/recipes/upload_service.rb @@ -0,0 +1,60 @@ +# +# Cookbook:: kosmos-ejabberd +# Recipe:: upload_service +# + +include_recipe "kosmos-nginx::with_perl" + +ejabberd_credentials = data_bag_item("credentials", "ejabberd") +uploads_secret = ejabberd_credentials["uploads_secret"] + +upload_config = node["kosmos-ejabberd"]["uploads"] +domain = upload_config["domain"] + +git "/opt/upload.pm" do + repository upload_config["upload.pm"]["repo"] + revision upload_config["upload.pm"]["revision"] + action :sync +end + +directory "/var/www/upload" do + user node["nginx"]["user"] + group node["nginx"]["group"] + mode "0640" +end + +ruby_block "configure uploads secret" do + block do + file = Chef::Util::FileEdit.new("/opt/upload.pm/upload.pm") + file.search_file_replace(%r{it-is-secret}, uploads_secret) + file.write_file + end +end + +ruby_block "configure perl module in nginx" do + block do + file = Chef::Util::FileEdit.new("/etc/nginx/nginx.conf") + file.insert_line_after_match( + %r{types_hash_bucket_size}, + "\n\n perl_modules /opt/upload.pm;\n perl_require upload.pm;" + ) + file.write_file + end +end + +template "#{node["nginx"]["dir"]}/sites-available/#{domain}" do + source "nginx_conf_upload_service.erb" + owner node["nginx"]["user"] + mode 0640 + variables server_name: domain, + ssl_cert: "/etc/letsencrypt/live/#{domain}/fullchain.pem", + ssl_key: "/etc/letsencrypt/live/#{domain}/privkey.pem", + max_upload_size_mb: upload_config["max_upload_size_mb"] + notifies :reload, "service[nginx]", :delayed +end + +nginx_site domain do + action :enable +end + +nginx_certbot_site domain diff --git a/site-cookbooks/kosmos-ejabberd/templates/nginx_conf_upload_service.erb b/site-cookbooks/kosmos-ejabberd/templates/nginx_conf_upload_service.erb new file mode 100644 index 0000000..bbf25a5 --- /dev/null +++ b/site-cookbooks/kosmos-ejabberd/templates/nginx_conf_upload_service.erb @@ -0,0 +1,19 @@ +<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%> +# Generated by Chef + +server { + listen 443 ssl http2; + server_name <%= @server_name %>; + + ssl_certificate <%= @ssl_cert %>; + ssl_certificate_key <%= @ssl_key %>; + + root /var/www/upload; + + client_max_body_size <%= @max_upload_size_mb %>m; + + location / { + perl upload::handle; + } +} +<% end -%> diff --git a/site-cookbooks/kosmos-nginx/recipes/with_perl.rb b/site-cookbooks/kosmos-nginx/recipes/with_perl.rb new file mode 100644 index 0000000..bac0223 --- /dev/null +++ b/site-cookbooks/kosmos-nginx/recipes/with_perl.rb @@ -0,0 +1,33 @@ +node.override['nginx']['default_site_enabled'] = false +node.override['nginx']['server_tokens'] = 'off' + +node.override['nginx']['package_name'] = 'nginx-core' +include_recipe 'nginx' + +package 'libnginx-mod-http-perl' + +# Generate Strong Diffie-Hellman Group (increases security) +# https://weakdh.org/sysadmin.html +openssl_dhparam "/etc/ssl/private/dhparams.pem" do + key_length 2048 + mode 0600 + owner 'www-data' +end + +cookbook_file "#{node['nginx']['dir']}/conf.d/tls_config.conf" do + source 'nginx_tls_config.conf' + owner 'root' + group 'root' + mode '0644' + notifies :restart, 'service[nginx]' +end + +unless node.chef_environment == "development" + include_recipe 'kosmos-base::firewall' + + firewall_rule 'http/https' do + port [80, 443] + protocol :tcp + command :allow + end +end From 6a89bb9d2e075164d805b98d11030d9a1e35bfa7 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 23 Nov 2020 17:39:47 +0100 Subject: [PATCH 148/327] Add node info for uploads-1 Runs uploads.kosmos.chat --- clients/uploads-1.json | 4 +++ nodes/uploads-1.json | 64 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 clients/uploads-1.json create mode 100644 nodes/uploads-1.json diff --git a/clients/uploads-1.json b/clients/uploads-1.json new file mode 100644 index 0000000..fec1329 --- /dev/null +++ b/clients/uploads-1.json @@ -0,0 +1,4 @@ +{ + "name": "uploads-1", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwJwWaz8TeGv3SFlKzLMx\nqN8GTL/c0N9ppBvv8xNSS/yF9Y40SbL418uxYzm9hIhOXgIygIgLT2EKIXX32t+R\neOJCdYycQFM3At2fhMkjhuUW0gmDRcYBcBJLC5hLh2EZ+A8V7k4qgrBpPLOjEv48\nhQY0vuAw2DGndWr4QLh5NLUmQiOrfuzcZSSNCBOTIgUZgNmRd9QcCHDq4WDH3poa\nosJo4a9JGEGUL1irOivvEdyJPwEd2f++nYAdWwj8pjCYgpRshQlLhxOlylMx7MxB\nQt2bgJC9sahfbfJCOqdlCU3DMJL0bRUiuxK77WeSsxWBJmrsiF3+Ljs2Ix+s7fnS\nywIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/uploads-1.json b/nodes/uploads-1.json new file mode 100644 index 0000000..bb43002 --- /dev/null +++ b/nodes/uploads-1.json @@ -0,0 +1,64 @@ +{ + "name": "uploads-1", + "normal": { + "knife_zero": { + "host": "10.147.20.98" + } + }, + "automatic": { + "fqdn": "uploads-1", + "os": "linux", + "os_version": "5.4.0-54-generic", + "hostname": "uploads-1", + "ipaddress": "192.168.122.230", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "kosmos-ejabberd::upload_service", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default", + "kosmos-nginx::with_perl", + "nginx::default", + "nginx::package", + "nginx::ohai_plugin", + "nginx::repo", + "nginx::commons", + "nginx::commons_dir", + "nginx::commons_script", + "nginx::commons_conf", + "kosmos-base::letsencrypt" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "chef": { + "version": "15.14.0", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib" + }, + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + } + } + }, + "run_list": [ + "recipe[kosmos-base]", + "recipe[kosmos-ejabberd::upload_service]" + ] +} \ No newline at end of file From 0bebdf7635fb3adbc5f0e79ea04fb166adf8bab0 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 23 Nov 2020 17:40:14 +0100 Subject: [PATCH 149/327] Do not require nginx from certbot recipe In order to be able to use different nginx install recipes, we must not require a specific one from this recipe. --- site-cookbooks/kosmos-nginx/resources/nginx_certbot_site.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/site-cookbooks/kosmos-nginx/resources/nginx_certbot_site.rb b/site-cookbooks/kosmos-nginx/resources/nginx_certbot_site.rb index a3aecc2..9d9c0b6 100644 --- a/site-cookbooks/kosmos-nginx/resources/nginx_certbot_site.rb +++ b/site-cookbooks/kosmos-nginx/resources/nginx_certbot_site.rb @@ -8,8 +8,6 @@ property :site, String action :create do return if node.chef_environment == "development" - include_recipe "kosmos-nginx" - domain = new_resource.domain site = new_resource.site || domain root_directory = "/var/www/#{domain}" From 0aef830aa335ed95f7e085b3df9c55d87e3f2a9e Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 23 Nov 2020 20:50:01 +0100 Subject: [PATCH 150/327] Fix upload folder permissions Uploads are failing with the current mode. --- site-cookbooks/kosmos-ejabberd/recipes/upload_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-ejabberd/recipes/upload_service.rb b/site-cookbooks/kosmos-ejabberd/recipes/upload_service.rb index 3fb4038..c772c0e 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/upload_service.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/upload_service.rb @@ -20,7 +20,7 @@ end directory "/var/www/upload" do user node["nginx"]["user"] group node["nginx"]["group"] - mode "0640" + mode "0755" end ruby_block "configure uploads secret" do From 0e29c930ed9b8fc2aa3e715cc5068326a83991fc Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 24 Nov 2020 15:33:34 +0100 Subject: [PATCH 151/327] Configure subdirectory level for upload.pm This allows to post to per-domain subdirectories from XMPP clients. --- data_bags/credentials/ejabberd.json | 24 +++++++++---------- .../kosmos-ejabberd/recipes/upload_service.rb | 6 ++++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/data_bags/credentials/ejabberd.json b/data_bags/credentials/ejabberd.json index fb14aca..5c0c89c 100644 --- a/data_bags/credentials/ejabberd.json +++ b/data_bags/credentials/ejabberd.json @@ -1,30 +1,30 @@ { "id": "ejabberd", "5apps_ldap_password": { - "encrypted_data": "H7WrXu2iGreO5MSoaNKAAAQOxh92rij4j4UPffs7Rjq1mtd4dMed\n", - "iv": "uEOoET/OOSDjiELM\n", - "auth_tag": "ehYOXsKPHNXrYNy0xJ+BSw==\n", + "encrypted_data": "RdzDZk2F4yBvgII84JGt8AF0LT4cyjRQFQvMJ5LhdB54T06Kjq3S\n", + "iv": "+3WlMHiNAFVE4iku\n", + "auth_tag": "mKheQu/KeHSyt8W783lrzA==\n", "version": 3, "cipher": "aes-256-gcm" }, "kosmos_ldap_password": { - "encrypted_data": "1u+tUrEj5JZ0F+j59f7VKztBTyn1vqT6V3H3K7uC9kHQCOUFmg3x\n", - "iv": "NjhasM5iVF6tBzps\n", - "auth_tag": "kSNqc3xEQavZifWcPeeFpA==\n", + "encrypted_data": "fABWhxMuLaF2qLFdIN//R6bgBkD60WRWiBZPErB1eBOxHqOp813o\n", + "iv": "uBPPYY/FM2hee05V\n", + "auth_tag": "cO+zP2QggWIzbuVxtkct2w==\n", "version": 3, "cipher": "aes-256-gcm" }, "uploads_secret": { - "encrypted_data": "2IVxvsaGP1+D0zOT0g9+Zz4Eg42Y8FPe8GiwQDZq6I1f\n", - "iv": "+Ujln/JDnL/afzZ3\n", - "auth_tag": "v0QBCsEemxBaBvi6kazj+w==\n", + "encrypted_data": "03Y8CNBstV7vYopx8X54hkRSlnwwbOg5Y0KwTPV4qys1\n", + "iv": "gLTP7Y2Y70jL+sxH\n", + "auth_tag": "HJoyOF4rYm9ayKfViuKBlA==\n", "version": 3, "cipher": "aes-256-gcm" }, "admins": { - "encrypted_data": "3kH8Cbc4Wy1RMd8HLa7aOCZWCZEyjmXq7JC3T0875472F708JjuOXuEqmUeG\nI82OE7lfMVrOup+hiMk9aCTQqxArayWFRZeWnMN2Ji/dbl12wJ/zKWSOPDQ2\nBHzJ/U6NoHBzmAV/PyirmD8KBNkZxCN8vhCq5azZTnmNQmu8CBxM+qUDDhd1\n", - "iv": "dro4RKs1MDD+riaM\n", - "auth_tag": "7yiBW9jyMzcAPWw/XR8zNQ==\n", + "encrypted_data": "mRX2Lxqxb//Gd76bk+G3V+eObaq+NILiMsHHjFvjBCvJrznvRzezqW1VHhwW\ndH/ZY2gM8CVCcmYNQ8Xtg/1loPYAUjROvDRirj5i9fP7zgJRc1anNmohDOle\n34aNPYverGm+IJ21sFrAv4Xe/KleJBO5ynuiInqqvljcu3LiuvSYBXW34yWB\n", + "iv": "QqJJM8gmox565JUd\n", + "auth_tag": "yWRLb22JwJjjoK6Wdr1ujg==\n", "version": 3, "cipher": "aes-256-gcm" } diff --git a/site-cookbooks/kosmos-ejabberd/recipes/upload_service.rb b/site-cookbooks/kosmos-ejabberd/recipes/upload_service.rb index c772c0e..6b5accd 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/upload_service.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/upload_service.rb @@ -23,10 +23,14 @@ directory "/var/www/upload" do mode "0755" end -ruby_block "configure uploads secret" do +ruby_block "configure uploads.pm" do block do file = Chef::Util::FileEdit.new("/opt/upload.pm/upload.pm") file.search_file_replace(%r{it-is-secret}, uploads_secret) + file.search_file_replace_line( + %r{my \$uri_prefix_components = 0;}, + 'my $uri_prefix_components = 1;' + ) file.write_file end end From f39f953b8a9c430c470aa8f6024c4ee3f15d73c9 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 24 Nov 2020 15:44:59 +0100 Subject: [PATCH 152/327] Configure ejabberd nodes for HTTP upload service --- site-cookbooks/kosmos-ejabberd/recipes/default.rb | 10 ++++++++++ .../kosmos-ejabberd/templates/ejabberd.yml.erb | 4 ---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index 2a73cdb..bc3a132 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -64,6 +64,11 @@ modules: max_user_conferences: 1000 default_room_options: mam: true + mod_http_upload: + put_url: "https://uploads.kosmos.chat/8af2c77" + external_secret: "#{ejabberd_credentials["uploads_secret"]}" + max_size: 104857600 + thumbnail: false # otherwise needs the identify command from ImageMagick installed EOF }, { @@ -89,6 +94,11 @@ modules: public_list: false persistent: true mam: true + mod_http_upload: + put_url: "https://uploads.kosmos.chat/2802cfe" + external_secret: "#{ejabberd_credentials["uploads_secret"]}" + max_size: 104857600 + thumbnail: false # otherwise needs the identify command from ImageMagick installed EOF } ] diff --git a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb index 5ed892b..7889b20 100644 --- a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb +++ b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb @@ -191,10 +191,6 @@ modules: name: "abuse-addresses" urls: ["mailto:abuse@@HOST@"] mod_bosh: {} - mod_http_upload: - docroot: "/opt/ejabberd/uploads/xmpp.@HOST@/" - put_url: "https://xmpp.@HOST@:5443/upload" - thumbnail: false # otherwise needs the identify command from ImageMagick installed mod_last: {} mod_mam: default: always From 8b1f90c568a4e71ff119b5ede25d7f3d2cac0a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 25 Nov 2020 16:32:07 +0100 Subject: [PATCH 153/327] Use the same Erlang cookie to enable clustering Refs #243 --- data_bags/credentials/ejabberd.json | 9 ++++++++- site-cookbooks/kosmos-ejabberd/recipes/default.rb | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/data_bags/credentials/ejabberd.json b/data_bags/credentials/ejabberd.json index 5c0c89c..cb2d066 100644 --- a/data_bags/credentials/ejabberd.json +++ b/data_bags/credentials/ejabberd.json @@ -27,5 +27,12 @@ "auth_tag": "yWRLb22JwJjjoK6Wdr1ujg==\n", "version": 3, "cipher": "aes-256-gcm" + }, + "erlang_cookie": { + "encrypted_data": "UDCzEWgVLH0z33Exx5G+OjUXw1odz4xO8qRLXODo5jBzMQdyYQCd\n", + "iv": "mm+fYYceD1nPsuo1\n", + "auth_tag": "77un6mkgrHAmnBQhrhpPfQ==\n", + "version": 3, + "cipher": "aes-256-gcm" } -} \ No newline at end of file +} diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index bc3a132..528de76 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -43,6 +43,13 @@ dpkg_package "ejabberd" do notifies :create, "file[/lib/systemd/system/ejabberd.service]", :immediately end +file "/opt/ejabberd/.erlang.cookie" do + mode "0400" + owner "ejabberd" + group "ejabberd" + content ejabberd_credentials['erlang_cookie'] +end + postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') hosts = [ From 7636f6ed195eac0dd83ee6ec6a2c97b1d906437b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 25 Nov 2020 16:26:11 +0100 Subject: [PATCH 154/327] Move the Gandi DNS certbot hook to kosmos-ejabberd --- site-cookbooks/kosmos-base/recipes/letsencrypt.rb | 8 -------- site-cookbooks/kosmos-ejabberd/recipes/letsencrypt.rb | 11 +++++++++-- .../templates}/gandi_dns_certbot_hook.sh.erb | 0 3 files changed, 9 insertions(+), 10 deletions(-) rename site-cookbooks/{kosmos-base/templates/default => kosmos-ejabberd/templates}/gandi_dns_certbot_hook.sh.erb (100%) diff --git a/site-cookbooks/kosmos-base/recipes/letsencrypt.rb b/site-cookbooks/kosmos-base/recipes/letsencrypt.rb index ac5016e..d047bba 100644 --- a/site-cookbooks/kosmos-base/recipes/letsencrypt.rb +++ b/site-cookbooks/kosmos-base/recipes/letsencrypt.rb @@ -63,14 +63,6 @@ systemctl reload nginx group "root" end -# gandi_api_data_bag_item = data_bag_item('credentials', 'gandi_api_5apps') - -# TODO only write to machines that actually need it (e.g. via role) -# template "/root/gandi_dns_certbot_hook.sh" do -# variables gandi_api_key: gandi_api_data_bag_item["key"] -# mode 0770 -# end - # include_recipe 'kosmos-base::systemd_emails' # TODO Check the deployed certs expiration dates instead of overwriting supplied systemd services diff --git a/site-cookbooks/kosmos-ejabberd/recipes/letsencrypt.rb b/site-cookbooks/kosmos-ejabberd/recipes/letsencrypt.rb index bfff01b..6b29885 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/letsencrypt.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/letsencrypt.rb @@ -54,10 +54,17 @@ file "/etc/letsencrypt/renewal-hooks/post/ejabberd" do group "root" end +gandi_api_data_bag_item = data_bag_item('credentials', 'gandi_api_5apps') + +template "/root/gandi_dns_certbot_hook.sh" do + variables gandi_api_key: gandi_api_data_bag_item["key"] + mode 0770 +end + # Generate a Let's Encrypt cert (only if no cert has been generated before). # The systemd timer will take care of renewing execute "letsencrypt cert for kosmos xmpp" do - command "/usr/bin/certbot certonly --manual --preferred-challenges dns --manual-public-ip-logging-ok --agree-tos --manual-auth-hook \"/root/gandi_dns_certbot_hook.sh auth\" --manual-cleanup-hook \"/root/gandi_dns_certbot_hook.sh cleanup\" --deploy-hook \"/etc/letsencrypt/renewal-hooks/post/ejabberd\" --email ops@kosmos.org -d kosmos.org -d xmpp.kosmos.org -d chat.kosmos.org -d kosmos.chat -n" + command "certbot certonly --manual --preferred-challenges dns --manual-public-ip-logging-ok --agree-tos --manual-auth-hook \"/root/gandi_dns_certbot_hook.sh auth\" --manual-cleanup-hook \"/root/gandi_dns_certbot_hook.sh cleanup\" --deploy-hook \"/etc/letsencrypt/renewal-hooks/post/ejabberd\" --email ops@kosmos.org -d kosmos.org -d xmpp.kosmos.org -d chat.kosmos.org -d kosmos.chat -d uploads.xmpp.kosmos.org -n" not_if do File.exist?("/etc/letsencrypt/live/kosmos.org/fullchain.pem") end @@ -66,7 +73,7 @@ end # Generate a Let's Encrypt cert (only if no cert has been generated before). # The systemd timer will take care of renewing execute "letsencrypt cert for 5apps xmpp" do - command "/usr/bin/certbot certonly --manual --preferred-challenges dns --manual-public-ip-logging-ok --agree-tos --manual-auth-hook \"/root/gandi_dns_certbot_hook.sh auth\" --manual-cleanup-hook \"/root/gandi_dns_certbot_hook.sh cleanup\" --deploy-hook \"/etc/letsencrypt/renewal-hooks/post/ejabberd\" --email ops@5apps.com -d 5apps.com -d muc.5apps.com -d xmpp.5apps.com -n" + command "certbot certonly --manual --preferred-challenges dns --manual-public-ip-logging-ok --agree-tos --manual-auth-hook \"/root/gandi_dns_certbot_hook.sh auth\" --manual-cleanup-hook \"/root/gandi_dns_certbot_hook.sh cleanup\" --deploy-hook \"/etc/letsencrypt/renewal-hooks/post/ejabberd\" --email ops@5apps.com -d 5apps.com -d muc.5apps.com -d xmpp.5apps.com -d uploads.xmpp.5apps.com -n" not_if do File.exist?("/etc/letsencrypt/live/5apps.com/fullchain.pem") end diff --git a/site-cookbooks/kosmos-base/templates/default/gandi_dns_certbot_hook.sh.erb b/site-cookbooks/kosmos-ejabberd/templates/gandi_dns_certbot_hook.sh.erb similarity index 100% rename from site-cookbooks/kosmos-base/templates/default/gandi_dns_certbot_hook.sh.erb rename to site-cookbooks/kosmos-ejabberd/templates/gandi_dns_certbot_hook.sh.erb From 085bd8abd505e3357e7240ee55f5290cf6e3ed03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 25 Nov 2020 16:28:13 +0100 Subject: [PATCH 155/327] Move TURN port to a different range It landed on a port used by PostgreSQL. Also switch STUN/TURN to TCP because HAProxy does not support UDP. Closes #240 --- site-cookbooks/kosmos-ejabberd/attributes/default.rb | 4 ++-- site-cookbooks/kosmos-ejabberd/recipes/default.rb | 4 ++-- site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/site-cookbooks/kosmos-ejabberd/attributes/default.rb b/site-cookbooks/kosmos-ejabberd/attributes/default.rb index 9a91622..fa4e89f 100644 --- a/site-cookbooks/kosmos-ejabberd/attributes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/attributes/default.rb @@ -1,7 +1,7 @@ node.default["kosmos-ejabberd"]["version"] = "20.04" node.default["kosmos-ejabberd"]["checksum"] = "5377ff18960a399e661fa23f4a1d9f57c78d4579ed108c52b8f68e7cd9268868" -node.default["kosmos-ejabberd"]["turn_min_port"] = 49152 -node.default["kosmos-ejabberd"]["turn_max_port"] = 59152 +node.default["kosmos-ejabberd"]["turn_min_port"] = 50000 +node.default["kosmos-ejabberd"]["turn_max_port"] = 55000 node.override["tor"]["HiddenServices"]["ejabberd"] = { "HiddenServicePorts" => [ diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index 528de76..334ad98 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -205,13 +205,13 @@ unless node.chef_environment == "development" firewall_rule 'ejabberd_stun_turn' do port 3478 - protocol :udp + protocol :tcp command :allow end firewall_rule 'ejabberd_turn' do port node["kosmos-ejabberd"]["turn_min_port"]..node["kosmos-ejabberd"]["turn_max_port"] - protocol :udp + protocol :tcp command :allow end end diff --git a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb index 7889b20..0c82cc1 100644 --- a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb +++ b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb @@ -76,7 +76,7 @@ listen: captcha: false - port: 3478 - transport: udp + transport: tcp module: ejabberd_stun auth_realm: <%= @stun_auth_realm %> use_turn: true From ddb706b61c9da9defd7f015e746000b8308ceaf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 25 Nov 2020 16:30:35 +0100 Subject: [PATCH 156/327] Add a missing dependency on kosmos-dirsrv --- site-cookbooks/kosmos-ejabberd/metadata.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/site-cookbooks/kosmos-ejabberd/metadata.rb b/site-cookbooks/kosmos-ejabberd/metadata.rb index 4cf04db..6e90702 100644 --- a/site-cookbooks/kosmos-ejabberd/metadata.rb +++ b/site-cookbooks/kosmos-ejabberd/metadata.rb @@ -22,6 +22,7 @@ chef_version '>= 12.14' if respond_to?(:chef_version) depends "kosmos-base" depends "kosmos-postgresql" depends "kosmos-nginx" +depends "kosmos-dirsrv" depends "backup" depends "firewall" depends "tor-full" From 23ca3552d203fb80a2da2119f17cc40b452ced82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 25 Nov 2020 16:31:06 +0100 Subject: [PATCH 157/327] Remove the absolute path of certbot to use the new package --- site-cookbooks/kosmos-dirsrv/resources/instance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-dirsrv/resources/instance.rb b/site-cookbooks/kosmos-dirsrv/resources/instance.rb index 7b99f9e..55aafc4 100644 --- a/site-cookbooks/kosmos-dirsrv/resources/instance.rb +++ b/site-cookbooks/kosmos-dirsrv/resources/instance.rb @@ -164,7 +164,7 @@ done # Generate a Let's Encrypt cert (only if the nginx vhost exists and no cert # has been generated before. The renew cron will take care of renewing execute "letsencrypt cert for #{new_resource.hostname}" do - command "/usr/bin/certbot certonly --webroot --agree-tos --email ops@kosmos.org --webroot-path /var/www/#{new_resource.hostname} --deploy-hook /etc/letsencrypt/renewal-hooks/deploy/dirsrv -d #{new_resource.hostname} -n" + command "certbot certonly --webroot --agree-tos --email ops@kosmos.org --webroot-path #{root_directory} --deploy-hook /etc/letsencrypt/renewal-hooks/deploy/dirsrv -d #{new_resource.hostname} -n" only_if do ::File.exist?("#{node['nginx']['dir']}/sites-enabled/#{new_resource.hostname}_certbot") && !::File.exist?("/etc/letsencrypt/live/#{new_resource.hostname}/fullchain.pem") From 3a8af26b5f9a6f0e234ce5af33369815da20d5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 25 Nov 2020 16:32:50 +0100 Subject: [PATCH 158/327] Remove firewall rule for an unused port --- site-cookbooks/kosmos-ejabberd/recipes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index 334ad98..aabb097 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -198,7 +198,7 @@ end unless node.chef_environment == "development" firewall_rule 'ejabberd' do - port [5222, 5223, 5269, 5280, 5443] + port [5222, 5223, 5269, 5443] protocol :tcp command :allow end From 613b316588642d58dd4300c37bbf6ed08a78c73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 25 Nov 2020 16:33:54 +0100 Subject: [PATCH 159/327] Add comment about needing to run Chef a second time... ... after the TLS certs are generated --- site-cookbooks/kosmos-ejabberd/templates/vhost.yml.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/site-cookbooks/kosmos-ejabberd/templates/vhost.yml.erb b/site-cookbooks/kosmos-ejabberd/templates/vhost.yml.erb index eb6c943..77fe955 100644 --- a/site-cookbooks/kosmos-ejabberd/templates/vhost.yml.erb +++ b/site-cookbooks/kosmos-ejabberd/templates/vhost.yml.erb @@ -1,4 +1,6 @@ # Generated by Chef for <%= @host[:name] %> +# FIXME: The files only exist after the certbot hook created them, meaning +# we need to run Chef a second time <% if File.exist?("/opt/ejabberd/conf/#{@host[:name]}.crt") && File.exist?("/opt/ejabberd/conf/#{@host[:name]}.key") -%> certfiles: - "/opt/ejabberd/conf/<%= @host[:name] %>.crt" From fbd71204c2d43bb73be5031b30b7993270be7eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 25 Nov 2020 16:34:37 +0100 Subject: [PATCH 160/327] Use the production run list when no Chef environment was set --- roles/ejabberd.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/ejabberd.rb b/roles/ejabberd.rb index 561ca33..824fd67 100644 --- a/roles/ejabberd.rb +++ b/roles/ejabberd.rb @@ -12,7 +12,7 @@ production_run_list = %w( kosmos-ejabberd::backup ) env_run_lists( - 'production' => production_run_list, 'development' => default_run_list, - '_default' => default_run_list + 'production' => production_run_list, + '_default' => production_run_list ) From bbf01711f832390cbe22236002b59024bab99ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 25 Nov 2020 16:34:54 +0100 Subject: [PATCH 161/327] Add ejabberd-1 client and node file --- clients/ejabberd-1.json | 4 +++ nodes/ejabberd-1.json | 62 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 clients/ejabberd-1.json create mode 100644 nodes/ejabberd-1.json diff --git a/clients/ejabberd-1.json b/clients/ejabberd-1.json new file mode 100644 index 0000000..1d6a89b --- /dev/null +++ b/clients/ejabberd-1.json @@ -0,0 +1,4 @@ +{ + "name": "ejabberd-1", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtoVmQAEmmAWjjzi5X8Ia\n9sl2aH8Lh0AsckM0aE3hvw9lGfbNCPpYWrr0uh7R6/+13Z0OghrT3yDAZ+XfH39Y\nuGomazTzSMMOEofjepo+nXSgq4meFfX5vobYG7rpBdz1EsIT1bElHduItA2zsw9J\nFpXtGd4BjumMq1VykSTA+QaEE8byes/+groQTtXPqXf5gJMxyGlh4SU0MzmkGHaW\n8c9BPCQrV0CMiuGOGJ5mZ28HajbvSg3+bpgwThh3M5uQaQ6on1N2pvJuBypUySS6\nyc4TauocUcUsULYXq9wM8/rqDYsUah0PR0WSiOi90m5thGeBchFAmhdCvrS34FlR\nVQIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/ejabberd-1.json b/nodes/ejabberd-1.json new file mode 100644 index 0000000..c7d54b7 --- /dev/null +++ b/nodes/ejabberd-1.json @@ -0,0 +1,62 @@ +{ + "name": "ejabberd-1", + "normal": { + "knife_zero": { + "host": "10.147.20.166" + } + }, + "automatic": { + "fqdn": "ejabberd-1", + "os": "linux", + "os_version": "5.4.0-54-generic", + "hostname": "ejabberd-1", + "ipaddress": "192.168.122.62", + "roles": [ + "ejabberd", + "postgresql_client" + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "kosmos-ejabberd", + "kosmos-ejabberd::default", + "kosmos-ejabberd::letsencrypt", + "kosmos-ejabberd::backup", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default", + "tor-full::default", + "kosmos-base::letsencrypt", + "backup::default", + "logrotate::default" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "chef": { + "version": "15.14.0", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib" + }, + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + } + } + }, + "run_list": [ + "recipe[kosmos-base]", + "role[ejabberd]" + ] +} \ No newline at end of file From 7a1a5c03e3060f6e2e376762b0f53c4fa4331146 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 25 Nov 2020 17:30:48 +0100 Subject: [PATCH 162/327] Set up ejabberd-2 VM --- clients/ejabberd-2.json | 4 ++++ nodes/ejabberd-2.json | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 clients/ejabberd-2.json create mode 100644 nodes/ejabberd-2.json diff --git a/clients/ejabberd-2.json b/clients/ejabberd-2.json new file mode 100644 index 0000000..1d3e5f3 --- /dev/null +++ b/clients/ejabberd-2.json @@ -0,0 +1,4 @@ +{ + "name": "ejabberd-2", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAudueTsPYnRXRu/rmMGZe\nI7LdyrWKdY9FJaRhkXR5J9Yb8QnIcDS7ZXDJsVhyQW8pZ2DuaIs5dmGYvRtmx0ol\nqHTEel01Q3/xI1blJoq4uRm639PB5M9dSJ0w+s6P5zj7rbFKpvMBYxBSK6z+gXIc\n/L1ayJ6JOssX5/tEvcvx/d4GIxof/Q+puACAXawx7W88Wl7yYWdBQ78uTPHzuMyB\n8BRYz24tki/O1fa9JijW32d3EELD0EccI3iJ+/CR4BFEEM2QdDczY/Q6Ny7h7inH\n/TdU246nvtJIx7bAZHmDIDva8YPtL27RIOQ3JqBBe7prQP5Q9MBGPyCXWAglj99a\n6QIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/ejabberd-2.json b/nodes/ejabberd-2.json new file mode 100644 index 0000000..c12924a --- /dev/null +++ b/nodes/ejabberd-2.json @@ -0,0 +1,52 @@ +{ + "name": "ejabberd-2", + "normal": { + "knife_zero": { + "host": "10.147.20.44" + } + }, + "automatic": { + "fqdn": "ejabberd-2", + "os": "linux", + "os_version": "5.4.0-54-generic", + "hostname": "ejabberd-2", + "ipaddress": "192.168.122.5", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "chef": { + "version": "15.14.0", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib" + }, + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + } + } + }, + "run_list": [ + "recipe[kosmos-base]" + ] +} \ No newline at end of file From 8c60279fe1980486620d948f0a7b9a4615c9f6c6 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 25 Nov 2020 21:02:46 +0100 Subject: [PATCH 163/327] Add cluster configs to ejabberd recipe --- .../kosmos-ejabberd/recipes/default.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index aabb097..0cde474 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -50,6 +50,28 @@ file "/opt/ejabberd/.erlang.cookie" do content ejabberd_credentials['erlang_cookie'] end +file "/opt/ejabberd/.hosts.erlang" do + mode "0644" + owner "ejabberd" + group "ejabberd" + content <<-EOF +"andromeda.kosmos.org". +"centaurus.kosmos.org". +"draco.kosmos.org". + EOF +end + +ruby_block "configure ERLANG_NODE" do + block do + file = Chef::Util::FileEdit.new("/opt/ejabberd/conf/ejabberdctl.cfg") + file.search_file_replace_line( + %r{#ERLANG_NODE=ejabberd@localhost}, + "ERLAND_NODE=#{node['kosmos-ejabberd']['erlang_node']}" + ) + file.write_file + end +end + postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') hosts = [ @@ -203,6 +225,18 @@ unless node.chef_environment == "development" command :allow end + firewall_rule 'ejabberd_cluster' do + port [4369] + protocol :tcp + command :allow + end + + firewall_rule 'erlang_cluster' do + port [4200..4210] + protocol :tcp + command :allow + end + firewall_rule 'ejabberd_stun_turn' do port 3478 protocol :tcp From 137d90ed8a081c8c6ccba7993516d66d5c9b97c4 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 25 Nov 2020 21:03:16 +0100 Subject: [PATCH 164/327] Configure ejabberd on ejabberd-2 --- nodes/ejabberd-2.json | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/nodes/ejabberd-2.json b/nodes/ejabberd-2.json index c12924a..664c3e8 100644 --- a/nodes/ejabberd-2.json +++ b/nodes/ejabberd-2.json @@ -12,11 +12,16 @@ "hostname": "ejabberd-2", "ipaddress": "192.168.122.5", "roles": [ - + "ejabberd", + "postgresql_client" ], "recipes": [ "kosmos-base", "kosmos-base::default", + "kosmos-ejabberd", + "kosmos-ejabberd::default", + "kosmos-ejabberd::letsencrypt", + "kosmos-ejabberd::backup", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -30,7 +35,11 @@ "postfix::_common", "postfix::_attributes", "postfix::sasl_auth", - "hostname::default" + "hostname::default", + "tor-full::default", + "kosmos-base::letsencrypt", + "backup::default", + "logrotate::default" ], "platform": "ubuntu", "platform_version": "20.04", @@ -47,6 +56,7 @@ } }, "run_list": [ - "recipe[kosmos-base]" + "recipe[kosmos-base]", + "role[ejabberd]" ] } \ No newline at end of file From 58854da64817e6ac0f97fa757e2793cee3abe896 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 25 Nov 2020 21:04:33 +0100 Subject: [PATCH 165/327] Add erland_node fqdn to ejabberd node configs --- nodes/ejabberd-1.json | 5 ++++- nodes/ejabberd-2.json | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nodes/ejabberd-1.json b/nodes/ejabberd-1.json index c7d54b7..296c803 100644 --- a/nodes/ejabberd-1.json +++ b/nodes/ejabberd-1.json @@ -3,6 +3,9 @@ "normal": { "knife_zero": { "host": "10.147.20.166" + }, + "kosmos-ejabberd": { + "erlang_node": "ejabberd@draco.kosmos.org" } }, "automatic": { @@ -59,4 +62,4 @@ "recipe[kosmos-base]", "role[ejabberd]" ] -} \ No newline at end of file +} diff --git a/nodes/ejabberd-2.json b/nodes/ejabberd-2.json index 664c3e8..5e7726c 100644 --- a/nodes/ejabberd-2.json +++ b/nodes/ejabberd-2.json @@ -3,6 +3,9 @@ "normal": { "knife_zero": { "host": "10.147.20.44" + }, + "kosmos-ejabberd": { + "erlang_node": "ejabberd@centaurus.kosmos.org" } }, "automatic": { @@ -59,4 +62,4 @@ "recipe[kosmos-base]", "role[ejabberd]" ] -} \ No newline at end of file +} From 58c5fad2a78c99cdfac4a9439b3b87c1b10dac5f Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 27 Nov 2020 13:22:09 +0100 Subject: [PATCH 166/327] Add new nickname config for wormhole --- site-cookbooks/kosmos-hubot/recipes/wormhole.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/site-cookbooks/kosmos-hubot/recipes/wormhole.rb b/site-cookbooks/kosmos-hubot/recipes/wormhole.rb index f2341ae..40063a9 100644 --- a/site-cookbooks/kosmos-hubot/recipes/wormhole.rb +++ b/site-cookbooks/kosmos-hubot/recipes/wormhole.rb @@ -84,6 +84,7 @@ application app_path do "HUBOT_WORMHOLE_XMPP_PASSWORD" => data_bag['xmpp_password'], "HUBOT_WORMHOLE_XMPP_HOST" => "xmpp.kosmos.org", "HUBOT_WORMHOLE_XMPP_PORT" => "5222", + "HUBOT_WORMHOLE_XMPP_NICKNAME" => "wormhole", "HUBOT_WORMHOLE_XMPP_ROOMS" => "kosmos@kosmos.chat,kosmos-dev@kosmos.chat,kosmos-random@kosmos.chat,sockethub@kosmos.chat" } ) From dace63b667c60c81f86e08c82fd4abdf7b2698d7 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 27 Nov 2020 13:22:29 +0100 Subject: [PATCH 167/327] Remove akkounts recipe from barnard runlist Must have been committed accidentally. --- nodes/barnard.kosmos.org.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nodes/barnard.kosmos.org.json b/nodes/barnard.kosmos.org.json index db6fdf3..4ee09fc 100644 --- a/nodes/barnard.kosmos.org.json +++ b/nodes/barnard.kosmos.org.json @@ -111,7 +111,6 @@ "recipe[kosmos-hubot::wormhole]", "recipe[sockethub]", "recipe[sockethub::proxy]", - "recipe[kosmos-akkounts]", "recipe[kosmos-dirsrv]" ] -} \ No newline at end of file +} From 9dbe5bcfcbaeddae9004b0798ec3dc221a3421a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 4 Dec 2020 16:21:52 +0100 Subject: [PATCH 168/327] Deploy a script to create new VMs It uses `virt-install` with the official Ubuntu 20.04 cloud image as a starting point, with cloud-init to add our SSH keys to the ubuntu user and set up Zerotier. USAGE: create_vm VMNAME Closes #244 --- site-cookbooks/kosmos_kvm/.gitignore | 22 ++++ site-cookbooks/kosmos_kvm/CHANGELOG.md | 5 + site-cookbooks/kosmos_kvm/LICENSE | 21 ++++ site-cookbooks/kosmos_kvm/README.md | 4 + site-cookbooks/kosmos_kvm/chefignore | 110 +++++++++++++++++++ site-cookbooks/kosmos_kvm/files/create_vm | 91 +++++++++++++++ site-cookbooks/kosmos_kvm/kitchen.yml | 32 ++++++ site-cookbooks/kosmos_kvm/metadata.rb | 20 ++++ site-cookbooks/kosmos_kvm/recipes/default.rb | 32 ++++++ 9 files changed, 337 insertions(+) create mode 100644 site-cookbooks/kosmos_kvm/.gitignore create mode 100644 site-cookbooks/kosmos_kvm/CHANGELOG.md create mode 100644 site-cookbooks/kosmos_kvm/LICENSE create mode 100644 site-cookbooks/kosmos_kvm/README.md create mode 100644 site-cookbooks/kosmos_kvm/chefignore create mode 100644 site-cookbooks/kosmos_kvm/files/create_vm create mode 100644 site-cookbooks/kosmos_kvm/kitchen.yml create mode 100644 site-cookbooks/kosmos_kvm/metadata.rb create mode 100644 site-cookbooks/kosmos_kvm/recipes/default.rb diff --git a/site-cookbooks/kosmos_kvm/.gitignore b/site-cookbooks/kosmos_kvm/.gitignore new file mode 100644 index 0000000..9abf29f --- /dev/null +++ b/site-cookbooks/kosmos_kvm/.gitignore @@ -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 diff --git a/site-cookbooks/kosmos_kvm/CHANGELOG.md b/site-cookbooks/kosmos_kvm/CHANGELOG.md new file mode 100644 index 0000000..79223d6 --- /dev/null +++ b/site-cookbooks/kosmos_kvm/CHANGELOG.md @@ -0,0 +1,5 @@ +# kosmos_kvm CHANGELOG + +# 0.1.0 + +Initial release. diff --git a/site-cookbooks/kosmos_kvm/LICENSE b/site-cookbooks/kosmos_kvm/LICENSE new file mode 100644 index 0000000..dd321fd --- /dev/null +++ b/site-cookbooks/kosmos_kvm/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +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. diff --git a/site-cookbooks/kosmos_kvm/README.md b/site-cookbooks/kosmos_kvm/README.md new file mode 100644 index 0000000..650ceaf --- /dev/null +++ b/site-cookbooks/kosmos_kvm/README.md @@ -0,0 +1,4 @@ +# kosmos_kvm + +TODO: Enter the cookbook description here. + diff --git a/site-cookbooks/kosmos_kvm/chefignore b/site-cookbooks/kosmos_kvm/chefignore new file mode 100644 index 0000000..5039e1c --- /dev/null +++ b/site-cookbooks/kosmos_kvm/chefignore @@ -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 diff --git a/site-cookbooks/kosmos_kvm/files/create_vm b/site-cookbooks/kosmos_kvm/files/create_vm new file mode 100644 index 0000000..4b83d01 --- /dev/null +++ b/site-cookbooks/kosmos_kvm/files/create_vm @@ -0,0 +1,91 @@ +#!/bin/bash +set -e + +# The base VM was downloaded using the following commands: +# mkdir /var/lib/libvirt/images/base +# curl -o http://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64-disk-kvm.img /var/lib/libvirt/images/base/ubuntu-20.04-server-cloudimg-amd64-disk-kvm.qcow2 +# chown -R libvirt-qemu:root /var/lib/libvirt/images/base + +if [[ $# -eq 0 ]] ; then + echo 'USAGE: create_vm VMNAME' + exit 1 +fi +VMNAME=$1 + + +# Directory where image files will be stored +IMAGE_DIR=/var/lib/libvirt/images +IMAGE_FILE=${VMNAME}.qcow2 +IMAGE_PATH=$IMAGE_DIR/$IMAGE_FILE +CIDATA_PATH=${IMAGE_DIR}/cidata-${VMNAME}.iso +BASE_FILE=${IMAGE_DIR}/base/ubuntu-20.04-server-cloudimg-amd64-disk-kvm.qcow2 + +# Disk size assigned to the VM +DISKSIZE=10 # Unit: GB + +# Create the VM image if it does not already exist +if [ ! -f "$IMAGE_PATH" ]; then + echo "info: image file $IMAGE_PATH not found. creating new image" + # Important: -F qcow2 is required to set the image format + qemu-img create -b "$BASE_FILE" -f qcow2 -F qcow2 "$IMAGE_PATH" ${DISKSIZE}G + chmod 600 "$IMAGE_PATH" + if [ $? -ne 0 ]; then + echo "error: failed to create image" + exit 1 + fi +fi + +# Dump the image info +qemu-img info "$IMAGE_PATH" + +# Check if the cloud-init metadata file exists +# if not, generate it +if [ ! -r $CIDATA_PATH ]; then + pushd $(dirname $CIDATA_PATH) + mkdir -p $VMNAME + cd $VMNAME + + cat > user-data <<-EOS +#cloud-config +ssh_authorized_keys: + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCw0I82gT8R4tpsqWGovLyjm2SR2F863MqNz224h3h/wl0xA5Eu0eRro+ELLv2hoebqQbcMsb89X5+7ObhDRar+b7tzDlXq4x+ECkAy6WbDSmBp3kNVd7muT4c9Zw7UxKsIvIm1ven1TkJ3UG80o6PyGiAUlBj4puIQwhp7OVknVutBBe8Rpp4f6BEuWluwpnPxc3KSaGhhr9p10xeX69cfspH40r8vHpI0zp19O5GpfYSOEH64UbwRpN2QypNB8ISmDHFsNGwdz0Ba4qrEOSGU9GveyOcsvEtt630/0fHqtbPBovOYu/FJISQZya2tofDig4EngBCJNfsPCbXFHtlp greg@karekinian.com + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDDyUDR7ZE6HWmjvlfKrG8Ci+q5E4adbyboKvyYVkUXaTYt+DgisPPAqfGkd0yAHgVnmOS/3f5c3D6RrIXcxFmzwpV2BtmGZztBnEYvC5q8XPQhmu6AFl6ZDjh9XzUeO52py8tt5ZJ9W1R2ob/rlgX8txNHi6XwzuvPxZ7NR/iNup7cruBzkHABhwTvTfwaErufr6eNmNjh5VatNTei1ld6yWtmvbYJqJlpq6YyPu9vYNYPg0AB7I+OqOJhzHXhelY28GSP9KF3GDcHDtN1bV21g9+COcdKhMShQaw1WIkfQKdiuFictZIOCP0/uYSiFhyyoSvISiC3eT8zIimRbDRj basti@skddc.local + +runcmd: + # Enable serial console (for virsh) + - systemctl enable serial-getty@ttyS0.service && systemctl start serial-getty@ttyS0.service + - curl -s 'https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg' | gpg --import + - if z=\$(curl -s 'https://install.zerotier.com/' | gpg"); then echo "$z" | sudo bash; fi +EOS + + cat > meta-data <<-EOS +instance-id: $VMNAME +local-hostname: $VMNAME +EOS + + genisoimage -output "$CIDATA_PATH" -volid cidata -joliet -rock user-data meta-data + chown libvirt-qemu:kvm "$CIDATA_PATH" + chmod 600 "$CIDATA_PATH" + popd +fi + +# setting --os-variant to ubuntu20.04 and ubuntu18.04 breaks SSH and networking +virt-install \ + --name cloudinit-1 \ + --ram 2048 \ + --vcpus 1\ + --cpu host \ + --arch x86_64 \ + --os-type linux \ + --os-variant ubuntu16.04 \ + --hvm \ + --virt-type kvm \ + --disk "$IMAGE_PATH" \ + --cdrom "$CIDATA_PATH" \ + --boot hd \ + --network=bridge=virbr0,model=virtio \ + --graphics none \ + --serial pty \ + --console pty \ + --autostart \ + --import diff --git a/site-cookbooks/kosmos_kvm/kitchen.yml b/site-cookbooks/kosmos_kvm/kitchen.yml new file mode 100644 index 0000000..e5bbf3c --- /dev/null +++ b/site-cookbooks/kosmos_kvm/kitchen.yml @@ -0,0 +1,32 @@ +--- +driver: + name: vagrant + +## The forwarded_port port feature lets you connect to ports on the VM guest via +## localhost on the host. +## see also: https://www.vagrantup.com/docs/networking/forwarded_ports.html + +# network: +# - ["forwarded_port", {guest: 80, host: 8080}] + +provisioner: + name: chef_zero + + ## product_name and product_version specifies a specific Chef product and version to install. + ## see the Chef documentation for more details: https://docs.chef.io/config_yml_kitchen.html + # product_name: chef + # product_version: 15 + +verifier: + name: inspec + +platforms: + - name: ubuntu-18.04 + - name: centos-7 + +suites: + - name: default + verifier: + inspec_tests: + - test/integration/default + attributes: diff --git a/site-cookbooks/kosmos_kvm/metadata.rb b/site-cookbooks/kosmos_kvm/metadata.rb new file mode 100644 index 0000000..ecf09da --- /dev/null +++ b/site-cookbooks/kosmos_kvm/metadata.rb @@ -0,0 +1,20 @@ +name 'kosmos_kvm' +maintainer 'Kosmos Developers' +maintainer_email 'mail@kosmos.org' +license 'MIT' +description 'Installs/Configures kosmos_kvm' +long_description 'Installs/Configures kosmos_kvm' +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//kosmos_kvm/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//kosmos_kvm' diff --git a/site-cookbooks/kosmos_kvm/recipes/default.rb b/site-cookbooks/kosmos_kvm/recipes/default.rb new file mode 100644 index 0000000..baba371 --- /dev/null +++ b/site-cookbooks/kosmos_kvm/recipes/default.rb @@ -0,0 +1,32 @@ +# +# Cookbook:: kosmos_kvm +# 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. + +package 'virtinst' + +cookbook_file "/usr/local/sbin/create_vm" do + source "create_vm" + mode "0750" +end From e6b7794e20920cd6f676154fe5d53fc50757f237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 4 Dec 2020 16:27:42 +0100 Subject: [PATCH 169/327] Extract firewall definitions to their own recipe This allows us to use them for KVM hosts as well. Until now we had set up ufw rules manually on the two KVM hosts (draco and centaurus) Refs #244 --- site-cookbooks/kosmos-base/recipes/default.rb | 2 +- .../kosmos-bitcoin/recipes/firewall.rb | 32 +++++++++++ .../kosmos-bitcoin/recipes/source.rb | 7 +-- .../kosmos-btcpayserver/recipes/proxy.rb | 3 +- .../kosmos-dirsrv/recipes/default.rb | 9 +-- .../kosmos-dirsrv/recipes/firewall.rb | 33 +++++++++++ .../kosmos-ejabberd/recipes/default.rb | 30 +--------- .../kosmos-ejabberd/recipes/firewall.rb | 57 +++++++++++++++++++ .../kosmos-ipfs/attributes/default.rb | 1 + site-cookbooks/kosmos-ipfs/recipes/default.rb | 7 +-- .../recipes/firewall_public_gateway.rb | 32 +++++++++++ .../kosmos-ipfs/recipes/firewall_swarm.rb | 32 +++++++++++ .../kosmos-ipfs/recipes/public_gateway.rb | 7 +-- .../kosmos-nginx/recipes/default.rb | 8 +-- .../kosmos-nginx/recipes/firewall.rb | 33 +++++++++++ .../kosmos-nginx/recipes/with_perl.rb | 8 +-- .../kosmos-postgresql/recipes/default.rb | 14 ++--- .../recipes/firewall_replicas.rb | 36 ++++++++++++ .../kosmos-postgresql/recipes/replica.rb | 2 +- .../kosmos_gitea/recipes/default.rb | 4 -- site-cookbooks/sockethub/recipes/_firewall.rb | 3 +- 21 files changed, 274 insertions(+), 86 deletions(-) create mode 100644 site-cookbooks/kosmos-bitcoin/recipes/firewall.rb create mode 100644 site-cookbooks/kosmos-dirsrv/recipes/firewall.rb create mode 100644 site-cookbooks/kosmos-ejabberd/recipes/firewall.rb create mode 100644 site-cookbooks/kosmos-ipfs/recipes/firewall_public_gateway.rb create mode 100644 site-cookbooks/kosmos-ipfs/recipes/firewall_swarm.rb create mode 100644 site-cookbooks/kosmos-nginx/recipes/firewall.rb create mode 100644 site-cookbooks/kosmos-postgresql/recipes/firewall_replicas.rb diff --git a/site-cookbooks/kosmos-base/recipes/default.rb b/site-cookbooks/kosmos-base/recipes/default.rb index 9ee8ab8..d5df463 100644 --- a/site-cookbooks/kosmos-base/recipes/default.rb +++ b/site-cookbooks/kosmos-base/recipes/default.rb @@ -64,7 +64,7 @@ unless node.chef_environment == "development" ] end - include_recipe 'kosmos-base::firewall' + include_recipe "kosmos-base::firewall" include_recipe 'kosmos-postfix' diff --git a/site-cookbooks/kosmos-bitcoin/recipes/firewall.rb b/site-cookbooks/kosmos-bitcoin/recipes/firewall.rb new file mode 100644 index 0000000..f1018d1 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/recipes/firewall.rb @@ -0,0 +1,32 @@ +# +# Cookbook:: kosmos-bitcoin +# Recipe:: firewall +# +# 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. +# + +firewall_rule 'bitcoind' do + port [8333] # TODO adjust for testnet + protocol :tcp + command :allow +end diff --git a/site-cookbooks/kosmos-bitcoin/recipes/source.rb b/site-cookbooks/kosmos-bitcoin/recipes/source.rb index d93f004..0d60853 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/source.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/source.rb @@ -158,9 +158,4 @@ systemd_unit 'bitcoind.service' do action [:create, :enable, :start] end -# TODO move to custom kosmos cookbook before publishing bitcoin cookbook -firewall_rule 'bitcoind' do - port [8333] # TODO adjust for testnet - protocol :tcp - command :allow -end +include_recipe "kosmos-bitcoin::firewall" diff --git a/site-cookbooks/kosmos-btcpayserver/recipes/proxy.rb b/site-cookbooks/kosmos-btcpayserver/recipes/proxy.rb index 4a47729..621161e 100644 --- a/site-cookbooks/kosmos-btcpayserver/recipes/proxy.rb +++ b/site-cookbooks/kosmos-btcpayserver/recipes/proxy.rb @@ -25,7 +25,8 @@ end nginx_certbot_site server_name unless node.chef_environment == "development" - include_recipe "firewall" + include_recipe "kosmos-base::firewall" + firewall_rule "btcpayserver" do port node["kosmos-btcpayserver"]["port"] protocol :tcp diff --git a/site-cookbooks/kosmos-dirsrv/recipes/default.rb b/site-cookbooks/kosmos-dirsrv/recipes/default.rb index 2f189df..6bcb871 100644 --- a/site-cookbooks/kosmos-dirsrv/recipes/default.rb +++ b/site-cookbooks/kosmos-dirsrv/recipes/default.rb @@ -37,14 +37,9 @@ end # with the run context is confusing: # # https://github.com/chef-cookbooks/firewall/issues/134 -unless node.chef_environment == "development" - include_recipe "firewall" - firewall_rule "ldap" do - port [389, 636] - protocol :tcp - command :allow - end +include_recipe "kosmos-dirsrv::firewall" +unless node.chef_environment == "development" # backup the data dir and the config files node.override["backup"]["archives"]["dirsrv"] = ["/etc/dirsrv", "/var/lib/dirsrv"] include_recipe "backup" diff --git a/site-cookbooks/kosmos-dirsrv/recipes/firewall.rb b/site-cookbooks/kosmos-dirsrv/recipes/firewall.rb new file mode 100644 index 0000000..b466666 --- /dev/null +++ b/site-cookbooks/kosmos-dirsrv/recipes/firewall.rb @@ -0,0 +1,33 @@ +# +# Cookbook Name:: kosmos-dirsrv +# Recipe:: firewall +# +# 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-base::firewall" + +firewall_rule "ldap" do + port [389, 636] + protocol :tcp + command :allow +end diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index 0cde474..01225cb 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -219,35 +219,7 @@ service "ejabberd" do end unless node.chef_environment == "development" - firewall_rule 'ejabberd' do - port [5222, 5223, 5269, 5443] - protocol :tcp - command :allow - end - - firewall_rule 'ejabberd_cluster' do - port [4369] - protocol :tcp - command :allow - end - - firewall_rule 'erlang_cluster' do - port [4200..4210] - protocol :tcp - command :allow - end - - firewall_rule 'ejabberd_stun_turn' do - port 3478 - protocol :tcp - command :allow - end - - firewall_rule 'ejabberd_turn' do - port node["kosmos-ejabberd"]["turn_min_port"]..node["kosmos-ejabberd"]["turn_max_port"] - protocol :tcp - command :allow - end + include_recipe "kosmos-ejabberd::firewall" end # diff --git a/site-cookbooks/kosmos-ejabberd/recipes/firewall.rb b/site-cookbooks/kosmos-ejabberd/recipes/firewall.rb new file mode 100644 index 0000000..5d2ac3a --- /dev/null +++ b/site-cookbooks/kosmos-ejabberd/recipes/firewall.rb @@ -0,0 +1,57 @@ +# +# Cookbook:: kosmos-ejabberd +# Recipe:: firewall +# +# 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-base::firewall" + +firewall_rule "ejabberd" do + port [5222, 5223, 5269, 5443] + protocol :tcp + command :allow +end + +firewall_rule 'ejabberd_cluster' do + port [4369] + protocol :tcp + command :allow +end + +firewall_rule 'erlang_cluster' do + port [4200..4210] + protocol :tcp + command :allow +end + +firewall_rule 'ejabberd_stun_turn' do + port 3478 + protocol :tcp + command :allow +end + +firewall_rule 'ejabberd_turn' do + port node["kosmos-ejabberd"]["turn_min_port"]..node["kosmos-ejabberd"]["turn_max_port"] + protocol :tcp + command :allow +end diff --git a/site-cookbooks/kosmos-ipfs/attributes/default.rb b/site-cookbooks/kosmos-ipfs/attributes/default.rb index bce7a81..860fb87 100644 --- a/site-cookbooks/kosmos-ipfs/attributes/default.rb +++ b/site-cookbooks/kosmos-ipfs/attributes/default.rb @@ -17,6 +17,7 @@ node.default['kosmos-ipfs']['ipfs']['config'] = { node.default['kosmos-ipfs']['nginx']['api_port'] = 5001 node.default['kosmos-ipfs']['nginx']['gateway_port'] = 9090 node.default['kosmos-ipfs']['nginx']['external_api_port'] = 5444 +node.default['kosmos-ipfs']['nginx']['swarm_p2p_port'] = 4001 node.default['kosmos-ipfs']['nginx']['domain'] = "ipfs.kosmos.org" node.default['kosmos-ipfs']['kredits-pinner']['revision'] = "v1.0.2" diff --git a/site-cookbooks/kosmos-ipfs/recipes/default.rb b/site-cookbooks/kosmos-ipfs/recipes/default.rb index 202faf4..b642a8c 100644 --- a/site-cookbooks/kosmos-ipfs/recipes/default.rb +++ b/site-cookbooks/kosmos-ipfs/recipes/default.rb @@ -34,10 +34,5 @@ node['kosmos-ipfs']['ipfs']['config'].each do |k, v| end unless node.chef_environment == "development" - include_recipe 'firewall' - firewall_rule 'ipfs_swarm_p2p' do - port 4001 - protocol :tcp - command :allow - end + include_recipe "kosmos-ipfs::firewall_swarm" end diff --git a/site-cookbooks/kosmos-ipfs/recipes/firewall_public_gateway.rb b/site-cookbooks/kosmos-ipfs/recipes/firewall_public_gateway.rb new file mode 100644 index 0000000..116c436 --- /dev/null +++ b/site-cookbooks/kosmos-ipfs/recipes/firewall_public_gateway.rb @@ -0,0 +1,32 @@ +# +# Cookbook Name:: kosmos-ipfs +# Recipe:: firewall_public_gateway +# +# 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 'firewall' +firewall_rule 'ipfs_api' do + port node['kosmos-ipfs']['nginx']['external_api_port'] + protocol :tcp + command :allow +end diff --git a/site-cookbooks/kosmos-ipfs/recipes/firewall_swarm.rb b/site-cookbooks/kosmos-ipfs/recipes/firewall_swarm.rb new file mode 100644 index 0000000..056d288 --- /dev/null +++ b/site-cookbooks/kosmos-ipfs/recipes/firewall_swarm.rb @@ -0,0 +1,32 @@ +# +# Cookbook Name:: kosmos-ipfs +# Recipe:: firewall_swarm +# +# 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 'firewall' +firewall_rule 'ipfs_swarm_p2p' do + port node['kosmos-ipfs']['nginx']['swarm_p2p_port'] + protocol :tcp + command :allow +end diff --git a/site-cookbooks/kosmos-ipfs/recipes/public_gateway.rb b/site-cookbooks/kosmos-ipfs/recipes/public_gateway.rb index 3ed5fe1..7d9927f 100644 --- a/site-cookbooks/kosmos-ipfs/recipes/public_gateway.rb +++ b/site-cookbooks/kosmos-ipfs/recipes/public_gateway.rb @@ -49,10 +49,5 @@ end nginx_certbot_site domain unless node.chef_environment == "development" - include_recipe "firewall" - firewall_rule 'ipfs_api' do - port node['kosmos-ipfs']['nginx']['external_api_port'] - protocol :tcp - command :allow - end + include_recipe "kosmos-ipfs::firewall_public_gateway" end diff --git a/site-cookbooks/kosmos-nginx/recipes/default.rb b/site-cookbooks/kosmos-nginx/recipes/default.rb index 87f386f..c01301e 100644 --- a/site-cookbooks/kosmos-nginx/recipes/default.rb +++ b/site-cookbooks/kosmos-nginx/recipes/default.rb @@ -84,11 +84,5 @@ cookbook_file "#{node["nginx"]["user_home"]}/maintenance.html" do end unless node.chef_environment == "development" - include_recipe 'kosmos-base::firewall' - - firewall_rule 'http/https' do - port [80, 443] - protocol :tcp - command :allow - end + include_recipe "kosmos-nginx::firewall" end diff --git a/site-cookbooks/kosmos-nginx/recipes/firewall.rb b/site-cookbooks/kosmos-nginx/recipes/firewall.rb new file mode 100644 index 0000000..ca6cbe2 --- /dev/null +++ b/site-cookbooks/kosmos-nginx/recipes/firewall.rb @@ -0,0 +1,33 @@ +# +# Cookbook Name:: kosmos-nginx +# Recipe:: firewall +# +# 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-base::firewall" + +firewall_rule "http/https" do + port [80, 443] + protocol :tcp + command :allow +end diff --git a/site-cookbooks/kosmos-nginx/recipes/with_perl.rb b/site-cookbooks/kosmos-nginx/recipes/with_perl.rb index bac0223..5be4fda 100644 --- a/site-cookbooks/kosmos-nginx/recipes/with_perl.rb +++ b/site-cookbooks/kosmos-nginx/recipes/with_perl.rb @@ -23,11 +23,5 @@ cookbook_file "#{node['nginx']['dir']}/conf.d/tls_config.conf" do end unless node.chef_environment == "development" - include_recipe 'kosmos-base::firewall' - - firewall_rule 'http/https' do - port [80, 443] - protocol :tcp - command :allow - end + include_recipe 'kosmos-nginx::firewall' end diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb index c7d289b..b3c9f4f 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/default.rb @@ -76,14 +76,8 @@ postgresql_replicas.each do |replica| notifies :reload, "service[#{postgresql_service}]", :immediately end - unless node.chef_environment == "development" - include_recipe "firewall" - - firewall_rule "postgresql replica #{replica[:hostname]}" do - port 5432 - protocol :tcp - command :allow - source replica[:ipaddress] - end - end +end + +unless node.chef_environment == "development" + include_recipe "kosmos-postgresql::firewall_replicas" end diff --git a/site-cookbooks/kosmos-postgresql/recipes/firewall_replicas.rb b/site-cookbooks/kosmos-postgresql/recipes/firewall_replicas.rb new file mode 100644 index 0000000..0ad0a47 --- /dev/null +++ b/site-cookbooks/kosmos-postgresql/recipes/firewall_replicas.rb @@ -0,0 +1,36 @@ +# +# Cookbook:: kosmos-postgresql +# Recipe:: firewall_replicas +# +# 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-base::firewall" + +postgresql_replicas.each do |replica| + firewall_rule "postgresql replica #{replica[:hostname]}" do + port 5432 + protocol :tcp + command :allow + source replica[:ipaddress] + end +end diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index b063edf..651b18a 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -70,7 +70,7 @@ systemctl start #{postgresql_service} node.normal['kosmos-postgresql']['ready_to_set_up_replica'] = true unless node.chef_environment == "development" - include_recipe "firewall" + include_recipe "kosmos-base::firewall" firewall_rule "postgresql primary #{primary[:hostname]}" do port 5432 diff --git a/site-cookbooks/kosmos_gitea/recipes/default.rb b/site-cookbooks/kosmos_gitea/recipes/default.rb index 2cc43c5..724572e 100644 --- a/site-cookbooks/kosmos_gitea/recipes/default.rb +++ b/site-cookbooks/kosmos_gitea/recipes/default.rb @@ -159,7 +159,3 @@ nginx_site domain do end nginx_certbot_site domain - -unless node.chef_environment == "development" - include_recipe "firewall" -end diff --git a/site-cookbooks/sockethub/recipes/_firewall.rb b/site-cookbooks/sockethub/recipes/_firewall.rb index 0c46c53..dd61637 100644 --- a/site-cookbooks/sockethub/recipes/_firewall.rb +++ b/site-cookbooks/sockethub/recipes/_firewall.rb @@ -25,7 +25,8 @@ # THE SOFTWARE. unless node.chef_environment == "development" - include_recipe "firewall" + include_recipe "kosmos-base::firewall" + firewall_rule 'sockethub' do port node['sockethub']['external_port'].to_i protocol :tcp From ee7a117d630ebdc8f143903c7baf8cdbd3d1e669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 4 Dec 2020 16:29:22 +0100 Subject: [PATCH 170/327] Add initial kosmos_zerotier cookbook For now it only includes the firewall rule Refs #244 --- site-cookbooks/kosmos_zerotier/.gitignore | 22 ++++ site-cookbooks/kosmos_zerotier/CHANGELOG.md | 7 ++ site-cookbooks/kosmos_zerotier/LICENSE | 21 ++++ site-cookbooks/kosmos_zerotier/README.md | 4 + .../kosmos_zerotier/attributes/default.rb | 1 + site-cookbooks/kosmos_zerotier/chefignore | 110 ++++++++++++++++++ site-cookbooks/kosmos_zerotier/kitchen.yml | 32 +++++ site-cookbooks/kosmos_zerotier/metadata.rb | 10 ++ .../kosmos_zerotier/recipes/default.rb | 25 ++++ .../kosmos_zerotier/recipes/firewall.rb | 31 +++++ 10 files changed, 263 insertions(+) create mode 100644 site-cookbooks/kosmos_zerotier/.gitignore create mode 100644 site-cookbooks/kosmos_zerotier/CHANGELOG.md create mode 100644 site-cookbooks/kosmos_zerotier/LICENSE create mode 100644 site-cookbooks/kosmos_zerotier/README.md create mode 100644 site-cookbooks/kosmos_zerotier/attributes/default.rb create mode 100644 site-cookbooks/kosmos_zerotier/chefignore create mode 100644 site-cookbooks/kosmos_zerotier/kitchen.yml create mode 100644 site-cookbooks/kosmos_zerotier/metadata.rb create mode 100644 site-cookbooks/kosmos_zerotier/recipes/default.rb create mode 100644 site-cookbooks/kosmos_zerotier/recipes/firewall.rb diff --git a/site-cookbooks/kosmos_zerotier/.gitignore b/site-cookbooks/kosmos_zerotier/.gitignore new file mode 100644 index 0000000..9abf29f --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/.gitignore @@ -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 diff --git a/site-cookbooks/kosmos_zerotier/CHANGELOG.md b/site-cookbooks/kosmos_zerotier/CHANGELOG.md new file mode 100644 index 0000000..a5b0f4e --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/CHANGELOG.md @@ -0,0 +1,7 @@ +# kosmos_zerotier CHANGELOG + +# 0.1.0 + +Initial release. + +- For now this only contains the firewall rule diff --git a/site-cookbooks/kosmos_zerotier/LICENSE b/site-cookbooks/kosmos_zerotier/LICENSE new file mode 100644 index 0000000..dd321fd --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +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. diff --git a/site-cookbooks/kosmos_zerotier/README.md b/site-cookbooks/kosmos_zerotier/README.md new file mode 100644 index 0000000..8645fb0 --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/README.md @@ -0,0 +1,4 @@ +# kosmos_zerotier + +TODO: Enter the cookbook description here. + diff --git a/site-cookbooks/kosmos_zerotier/attributes/default.rb b/site-cookbooks/kosmos_zerotier/attributes/default.rb new file mode 100644 index 0000000..5f017af --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/attributes/default.rb @@ -0,0 +1 @@ +node.default["kosmos_zerotier"]["server_port"] = 9993 diff --git a/site-cookbooks/kosmos_zerotier/chefignore b/site-cookbooks/kosmos_zerotier/chefignore new file mode 100644 index 0000000..5039e1c --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/chefignore @@ -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 diff --git a/site-cookbooks/kosmos_zerotier/kitchen.yml b/site-cookbooks/kosmos_zerotier/kitchen.yml new file mode 100644 index 0000000..e5bbf3c --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/kitchen.yml @@ -0,0 +1,32 @@ +--- +driver: + name: vagrant + +## The forwarded_port port feature lets you connect to ports on the VM guest via +## localhost on the host. +## see also: https://www.vagrantup.com/docs/networking/forwarded_ports.html + +# network: +# - ["forwarded_port", {guest: 80, host: 8080}] + +provisioner: + name: chef_zero + + ## product_name and product_version specifies a specific Chef product and version to install. + ## see the Chef documentation for more details: https://docs.chef.io/config_yml_kitchen.html + # product_name: chef + # product_version: 15 + +verifier: + name: inspec + +platforms: + - name: ubuntu-18.04 + - name: centos-7 + +suites: + - name: default + verifier: + inspec_tests: + - test/integration/default + attributes: diff --git a/site-cookbooks/kosmos_zerotier/metadata.rb b/site-cookbooks/kosmos_zerotier/metadata.rb new file mode 100644 index 0000000..d090fa9 --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/metadata.rb @@ -0,0 +1,10 @@ +name 'kosmos_zerotier' +maintainer 'Kosmos Developers' +maintainer_email 'mail@kosmos.org' +license 'MIT' +description 'Installs/Configures kosmos_zerotier' +long_description 'Installs/Configures kosmos_zerotier' +version '0.1.0' +chef_version '>= 14.0' + +depends 'kosmos-base' diff --git a/site-cookbooks/kosmos_zerotier/recipes/default.rb b/site-cookbooks/kosmos_zerotier/recipes/default.rb new file mode 100644 index 0000000..1125c4a --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/recipes/default.rb @@ -0,0 +1,25 @@ +# +# Cookbook:: kosmos_zerotier +# 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. diff --git a/site-cookbooks/kosmos_zerotier/recipes/firewall.rb b/site-cookbooks/kosmos_zerotier/recipes/firewall.rb new file mode 100644 index 0000000..b179103 --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/recipes/firewall.rb @@ -0,0 +1,31 @@ +# +# Cookbook:: kosmos_zerotier +# Recipe:: firewall +# +# 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. + +firewall_rule "zerotier" do + port node["kosmos_zerotier"]["server_port"] + protocol :tcp + command :allow +end From 1837285b79d79a9d24d89edc16d9d6a8516c5480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 4 Dec 2020 16:33:18 +0100 Subject: [PATCH 171/327] Add the kosmos_kvm recipe and the firewall rules ... to the KVM hosts, centaurus and draco Refs #244 --- nodes/centaurus.kosmos.org.json | 8 ++++++-- nodes/draco.kosmos.org.json | 12 ++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/nodes/centaurus.kosmos.org.json b/nodes/centaurus.kosmos.org.json index dd3d075..3ba9afa 100644 --- a/nodes/centaurus.kosmos.org.json +++ b/nodes/centaurus.kosmos.org.json @@ -81,6 +81,10 @@ "role[gitea]", "role[postgresql_replica]", "role[discourse]", - "role[drone]" + "role[drone]", + "recipe[kosmos_kvm]", + "recipe[kosmos-ejabberd::firewall]", + "recipe[kosmos-postgresql::firewall_replicas]", + "recipe[kosmos_zerotier::firewall]" ] -} \ No newline at end of file +} diff --git a/nodes/draco.kosmos.org.json b/nodes/draco.kosmos.org.json index 34a8a7c..f2ce70d 100644 --- a/nodes/draco.kosmos.org.json +++ b/nodes/draco.kosmos.org.json @@ -57,6 +57,14 @@ "recipe[kosmos-base]", "recipe[kosmos_encfs]", "role[postgresql_replica]", - "recipe[kosmos-bitcoin::source]" + "recipe[kosmos-bitcoin::source]", + "recipe[kosmos_kvm]", + "recipe[kosmos-ejabberd::firewall]", + "recipe[kosmos-ipfs::firewall_swarm]", + "recipe[kosmos-ipfs::firewall_public_gateway]", + "recipe[kosmos-postgresql::firewall_replicas]", + "recipe[kosmos-bitcoin::firewall]", + "recipe[kosmos_zerotier::firewall]", + "recipe[kosmos-nginx::firewall]" ] -} \ No newline at end of file +} From 02239dd9a849b6d245e896455fe746c6f79ae780 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 8 Dec 2020 13:13:05 +0100 Subject: [PATCH 172/327] Update ejabberd doc --- doc/ejabberd.md | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/doc/ejabberd.md b/doc/ejabberd.md index 2e9713d..29044a5 100644 --- a/doc/ejabberd.md +++ b/doc/ejabberd.md @@ -1,26 +1,11 @@ # ejabberd -The kosmos.org XMPP server is running on `andromeda.kosmos.org`. JIDs are -username@kosmos.org, with the server being configured in DNS to use -`xmpp.kosmos.org` and MUC on `chat.kosmos.org`. +The kosmos.org XMPP service is running as an ejabberd cluster on [various +machines][1]. JIDs are `username@kosmos.org`, with the service being configured +in DNS to use `xmpp.kosmos.org` and MUC on `kosmos.chat`. * [Configuring ejabberd](https://docs.ejabberd.im/admin/configuration) * [XEP compliance tester](https://compliance.conversations.im/server/kosmos.org/) * [ejabberdctl reference](https://docs.ejabberd.im/admin/guide/managing/#ejabberdctl-commands) -### Common ejabberdctl tasks - -(These things can also be done through a client that supports admin actions, or -through the admin web interface.) - -## Create a user account - - sudo /opt/ejabberd-18.06/bin/ejabberdctl register username kosmos.org password - -## Change a user's password - - sudo /opt/ejabberd-18.06/bin/ejabberdctl change_password username kosmos.org new_password - -## List users - - sudo /opt/ejabberd-18.06/bin/ejabberdctl registered_users kosmos.org +[1]: https://wiki.kosmos.org/Infrastructure From 56d9144ad6b644e29127d83377b84fa0978e625e Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 8 Dec 2020 14:30:29 +0100 Subject: [PATCH 173/327] Disable ACME Throws a warning when reloading the config, because it is enabled by default, but not configured entirely. Disabling it explicitly removes the warning. --- site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb index 0c82cc1..32db826 100644 --- a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb +++ b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb @@ -32,6 +32,9 @@ s2s_ciphers: 'TLS_CIPHERS' c2s_protocol_options: 'TLS_OPTIONS' s2s_protocol_options: 'TLS_OPTIONS' +acme: + auto: false + listen: - port: 5222 From 89c8f42a464cf3ba8b89c2a290c6ecf2b118e405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 8 Dec 2020 16:03:18 +0100 Subject: [PATCH 174/327] Set the description for the kosmos_kvm cookbook --- site-cookbooks/kosmos_kvm/metadata.rb | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/site-cookbooks/kosmos_kvm/metadata.rb b/site-cookbooks/kosmos_kvm/metadata.rb index ecf09da..966d2da 100644 --- a/site-cookbooks/kosmos_kvm/metadata.rb +++ b/site-cookbooks/kosmos_kvm/metadata.rb @@ -2,19 +2,7 @@ name 'kosmos_kvm' maintainer 'Kosmos Developers' maintainer_email 'mail@kosmos.org' license 'MIT' -description 'Installs/Configures kosmos_kvm' -long_description 'Installs/Configures kosmos_kvm' +description 'Install virt-install and deploy a script to create VMs' +long_description 'Install virt-install and deploy a script to create VMs with KVM' 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//kosmos_kvm/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//kosmos_kvm' From 176083497cbd662ebfbe59a1e4f876de85ec4498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 8 Dec 2020 16:25:04 +0100 Subject: [PATCH 175/327] Install the libvirt-daemon-system package It creates the libvirt-qemu user --- site-cookbooks/kosmos_kvm/recipes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_kvm/recipes/default.rb b/site-cookbooks/kosmos_kvm/recipes/default.rb index baba371..971ab49 100644 --- a/site-cookbooks/kosmos_kvm/recipes/default.rb +++ b/site-cookbooks/kosmos_kvm/recipes/default.rb @@ -24,7 +24,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -package 'virtinst' +package %w(virtinst libvirt-daemon-system) cookbook_file "/usr/local/sbin/create_vm" do source "create_vm" From 6f7b493173b6fe8c30a85ea1a2fb6ab01e5da6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 8 Dec 2020 16:25:32 +0100 Subject: [PATCH 176/327] Create the base Ubuntu 20.04 cloud image with code --- site-cookbooks/kosmos_kvm/files/create_vm | 5 ----- site-cookbooks/kosmos_kvm/recipes/default.rb | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/site-cookbooks/kosmos_kvm/files/create_vm b/site-cookbooks/kosmos_kvm/files/create_vm index 4b83d01..4702bb6 100644 --- a/site-cookbooks/kosmos_kvm/files/create_vm +++ b/site-cookbooks/kosmos_kvm/files/create_vm @@ -1,11 +1,6 @@ #!/bin/bash set -e -# The base VM was downloaded using the following commands: -# mkdir /var/lib/libvirt/images/base -# curl -o http://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64-disk-kvm.img /var/lib/libvirt/images/base/ubuntu-20.04-server-cloudimg-amd64-disk-kvm.qcow2 -# chown -R libvirt-qemu:root /var/lib/libvirt/images/base - if [[ $# -eq 0 ]] ; then echo 'USAGE: create_vm VMNAME' exit 1 diff --git a/site-cookbooks/kosmos_kvm/recipes/default.rb b/site-cookbooks/kosmos_kvm/recipes/default.rb index 971ab49..c5e5901 100644 --- a/site-cookbooks/kosmos_kvm/recipes/default.rb +++ b/site-cookbooks/kosmos_kvm/recipes/default.rb @@ -26,6 +26,21 @@ package %w(virtinst libvirt-daemon-system) +directory "/var/lib/libvirt/images/base" do + recursive true + owner "libvirt-qemu" + group "root" + mode "0750" +end + +# Base Ubuntu 20.04 image +remote_file "/var/lib/libvirt/images/base/ubuntu-20.04-server-cloudimg-amd64-disk-kvm.qcow2" do + source "http://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64-disk-kvm.img" + owner "libvirt-qemu" + group "root" + mode "0640" +end + cookbook_file "/usr/local/sbin/create_vm" do source "create_vm" mode "0750" From b3c1f81ec63faaba0b90809f2bb61d9d11890da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 8 Dec 2020 16:26:14 +0100 Subject: [PATCH 177/327] Set the description of the kosmos_zerotier cookbook --- site-cookbooks/kosmos_zerotier/metadata.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos_zerotier/metadata.rb b/site-cookbooks/kosmos_zerotier/metadata.rb index d090fa9..a67848b 100644 --- a/site-cookbooks/kosmos_zerotier/metadata.rb +++ b/site-cookbooks/kosmos_zerotier/metadata.rb @@ -2,8 +2,8 @@ name 'kosmos_zerotier' maintainer 'Kosmos Developers' maintainer_email 'mail@kosmos.org' license 'MIT' -description 'Installs/Configures kosmos_zerotier' -long_description 'Installs/Configures kosmos_zerotier' +description 'Installs/Configures zerotier' +long_description 'Installs/Configures zerotier' version '0.1.0' chef_version '>= 14.0' From 94a34e4758ce6f0bd2a6d629cf6a9ba340dc383d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 8 Dec 2020 16:33:27 +0100 Subject: [PATCH 178/327] Add arguments for RAM and number of CPUs --- site-cookbooks/kosmos_kvm/files/create_vm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/site-cookbooks/kosmos_kvm/files/create_vm b/site-cookbooks/kosmos_kvm/files/create_vm index 4702bb6..bdb0b81 100644 --- a/site-cookbooks/kosmos_kvm/files/create_vm +++ b/site-cookbooks/kosmos_kvm/files/create_vm @@ -1,12 +1,17 @@ #!/bin/bash set -e -if [[ $# -eq 0 ]] ; then - echo 'USAGE: create_vm VMNAME' +if [[ $# -lt 3 ]] ; then + cat <<-EOF +USAGE (RAM in megabytes) + +create_vm VMNAME RAM CPUS +EOF exit 1 fi VMNAME=$1 - +RAM=$2 +CPUS=$3 # Directory where image files will be stored IMAGE_DIR=/var/lib/libvirt/images @@ -67,8 +72,8 @@ fi # setting --os-variant to ubuntu20.04 and ubuntu18.04 breaks SSH and networking virt-install \ --name cloudinit-1 \ - --ram 2048 \ - --vcpus 1\ + --ram "$RAM" \ + --vcpus "$CPUS" \ --cpu host \ --arch x86_64 \ --os-type linux \ From 8f304d00ced42d93ee9b4a4bac88b86139099050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 8 Dec 2020 16:34:24 +0100 Subject: [PATCH 179/327] Remove unused kitchen.yml files --- site-cookbooks/kosmos_kvm/kitchen.yml | 32 ---------------------- site-cookbooks/kosmos_zerotier/kitchen.yml | 32 ---------------------- 2 files changed, 64 deletions(-) delete mode 100644 site-cookbooks/kosmos_kvm/kitchen.yml delete mode 100644 site-cookbooks/kosmos_zerotier/kitchen.yml diff --git a/site-cookbooks/kosmos_kvm/kitchen.yml b/site-cookbooks/kosmos_kvm/kitchen.yml deleted file mode 100644 index e5bbf3c..0000000 --- a/site-cookbooks/kosmos_kvm/kitchen.yml +++ /dev/null @@ -1,32 +0,0 @@ ---- -driver: - name: vagrant - -## The forwarded_port port feature lets you connect to ports on the VM guest via -## localhost on the host. -## see also: https://www.vagrantup.com/docs/networking/forwarded_ports.html - -# network: -# - ["forwarded_port", {guest: 80, host: 8080}] - -provisioner: - name: chef_zero - - ## product_name and product_version specifies a specific Chef product and version to install. - ## see the Chef documentation for more details: https://docs.chef.io/config_yml_kitchen.html - # product_name: chef - # product_version: 15 - -verifier: - name: inspec - -platforms: - - name: ubuntu-18.04 - - name: centos-7 - -suites: - - name: default - verifier: - inspec_tests: - - test/integration/default - attributes: diff --git a/site-cookbooks/kosmos_zerotier/kitchen.yml b/site-cookbooks/kosmos_zerotier/kitchen.yml deleted file mode 100644 index e5bbf3c..0000000 --- a/site-cookbooks/kosmos_zerotier/kitchen.yml +++ /dev/null @@ -1,32 +0,0 @@ ---- -driver: - name: vagrant - -## The forwarded_port port feature lets you connect to ports on the VM guest via -## localhost on the host. -## see also: https://www.vagrantup.com/docs/networking/forwarded_ports.html - -# network: -# - ["forwarded_port", {guest: 80, host: 8080}] - -provisioner: - name: chef_zero - - ## product_name and product_version specifies a specific Chef product and version to install. - ## see the Chef documentation for more details: https://docs.chef.io/config_yml_kitchen.html - # product_name: chef - # product_version: 15 - -verifier: - name: inspec - -platforms: - - name: ubuntu-18.04 - - name: centos-7 - -suites: - - name: default - verifier: - inspec_tests: - - test/integration/default - attributes: From 6c907419aaa9324626e8904c06ae44d6f29fe3e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 8 Dec 2020 17:10:40 +0100 Subject: [PATCH 180/327] Set the VM name from the script argument --- site-cookbooks/kosmos_kvm/files/create_vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_kvm/files/create_vm b/site-cookbooks/kosmos_kvm/files/create_vm index bdb0b81..9c86baa 100644 --- a/site-cookbooks/kosmos_kvm/files/create_vm +++ b/site-cookbooks/kosmos_kvm/files/create_vm @@ -71,7 +71,7 @@ fi # setting --os-variant to ubuntu20.04 and ubuntu18.04 breaks SSH and networking virt-install \ - --name cloudinit-1 \ + --name "$VMNAME" \ --ram "$RAM" \ --vcpus "$CPUS" \ --cpu host \ From 8e0a66184cadcb156ede6cc8ea0a8a1ad7d995dd Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 8 Dec 2020 19:59:51 +0100 Subject: [PATCH 181/327] Use role for akkounts Lets us search by role --- nodes/akkounts-1.json | 5 ++--- roles/akkounts.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 roles/akkounts.rb diff --git a/nodes/akkounts-1.json b/nodes/akkounts-1.json index 4e69606..b85f6d1 100644 --- a/nodes/akkounts-1.json +++ b/nodes/akkounts-1.json @@ -68,7 +68,6 @@ }, "run_list": [ "recipe[kosmos-base]", - "recipe[kosmos-akkounts::default]", - "recipe[kosmos-akkounts::nginx]" + "role[akkounts]" ] -} \ No newline at end of file +} diff --git a/roles/akkounts.rb b/roles/akkounts.rb new file mode 100644 index 0000000..1dae0bb --- /dev/null +++ b/roles/akkounts.rb @@ -0,0 +1,12 @@ +name "akkounts" + +default_run_list = %w( + kosmos-akkounts::default + kosmos-akkounts::nginx +) + +env_run_lists( + '_default' => default_run_list, + 'development' => default_run_list, + 'production' => default_run_list +) From 239b6aed51c4d8a58b573927d67bd66690698017 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 8 Dec 2020 20:00:31 +0100 Subject: [PATCH 182/327] Add API permissions for akkounts VMs Using the zerotier IP, which is the same as the knife-zero host. --- site-cookbooks/kosmos-ejabberd/recipes/default.rb | 8 +++++++- site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index 0cde474..9533351 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -169,6 +169,11 @@ hosts.each do |host| end end +akkounts_ip_addresses = [] +search(:node, "role:akkounts").each do |node| + akkounts_ip_addresses << node["knife_zero"]["host"] +end + template "/opt/ejabberd/conf/ejabberd.yml" do source "ejabberd.yml.erb" mode 0640 @@ -178,7 +183,8 @@ template "/opt/ejabberd/conf/ejabberd.yml" do stun_auth_realm: "kosmos.org", turn_ip_address: node['ipaddress'], turn_min_port: node["kosmos-ejabberd"]["turn_min_port"], - turn_max_port: node["kosmos-ejabberd"]["turn_max_port"] + turn_max_port: node["kosmos-ejabberd"]["turn_max_port"], + akkounts_ip_addresses: akkounts_ip_addresses notifies :run, "execute[ejabberdctl reload_config]", :delayed end diff --git a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb index 32db826..e1dca82 100644 --- a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb +++ b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb @@ -174,6 +174,14 @@ api_permissions: what: - "status" - "connected_users_number" + "akkounts": + who: +<% @akkounts_ip_addresses.each do |ip| -%> + - ip: "<%= ip %>/8" +<% end -%> + what: + - "add_rosteritem" + - "delete_rosteritem" language: "en" From 12125bf0b285626c527cdff4f2cde8f7b077b4f7 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 8 Dec 2020 20:31:01 +0100 Subject: [PATCH 183/327] Add hosts entries for ejabberd private IPs --- .../kosmos-akkounts/recipes/default.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/site-cookbooks/kosmos-akkounts/recipes/default.rb b/site-cookbooks/kosmos-akkounts/recipes/default.rb index 105ea85..88ef6b2 100644 --- a/site-cookbooks/kosmos-akkounts/recipes/default.rb +++ b/site-cookbooks/kosmos-akkounts/recipes/default.rb @@ -23,6 +23,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # +require 'ipaddr' + app_name = "akkounts" deploy_user = "deploy" deploy_group = "deploy" @@ -143,4 +145,19 @@ application deploy_path do end end +ejabberd_private_ip_addresses = [] +search(:node, "role:ejabberd").each do |node| + ejabberd_private_ip_addresses << node["knife_zero"]["host"] +end + +ejabberd_private_ip_addresses.each do |ip_address| + IPAddr.new ip_address + hostsfile_entry ip_address do + hostname 'xmpp.kosmos.org' + action :create + end +rescue IPAddr::InvalidAddressError + next +end + include_recipe 'kosmos-akkounts::nginx' From 7ceb9af3ed14408621faffda0bd4f252f34af2a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 9 Dec 2020 11:19:13 +0100 Subject: [PATCH 184/327] Rename the kosmos_kvm default recipe to host It makes it clear it is meant for KVM hosts --- nodes/centaurus.kosmos.org.json | 2 +- nodes/draco.kosmos.org.json | 2 +- site-cookbooks/kosmos_kvm/recipes/{default.rb => host.rb} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename site-cookbooks/kosmos_kvm/recipes/{default.rb => host.rb} (98%) diff --git a/nodes/centaurus.kosmos.org.json b/nodes/centaurus.kosmos.org.json index 3ba9afa..9740d3f 100644 --- a/nodes/centaurus.kosmos.org.json +++ b/nodes/centaurus.kosmos.org.json @@ -82,7 +82,7 @@ "role[postgresql_replica]", "role[discourse]", "role[drone]", - "recipe[kosmos_kvm]", + "recipe[kosmos_kvm::host]", "recipe[kosmos-ejabberd::firewall]", "recipe[kosmos-postgresql::firewall_replicas]", "recipe[kosmos_zerotier::firewall]" diff --git a/nodes/draco.kosmos.org.json b/nodes/draco.kosmos.org.json index f2ce70d..116ce07 100644 --- a/nodes/draco.kosmos.org.json +++ b/nodes/draco.kosmos.org.json @@ -58,7 +58,7 @@ "recipe[kosmos_encfs]", "role[postgresql_replica]", "recipe[kosmos-bitcoin::source]", - "recipe[kosmos_kvm]", + "recipe[kosmos_kvm::host]", "recipe[kosmos-ejabberd::firewall]", "recipe[kosmos-ipfs::firewall_swarm]", "recipe[kosmos-ipfs::firewall_public_gateway]", diff --git a/site-cookbooks/kosmos_kvm/recipes/default.rb b/site-cookbooks/kosmos_kvm/recipes/host.rb similarity index 98% rename from site-cookbooks/kosmos_kvm/recipes/default.rb rename to site-cookbooks/kosmos_kvm/recipes/host.rb index c5e5901..a89f7eb 100644 --- a/site-cookbooks/kosmos_kvm/recipes/default.rb +++ b/site-cookbooks/kosmos_kvm/recipes/host.rb @@ -1,6 +1,6 @@ # # Cookbook:: kosmos_kvm -# Recipe:: default +# Recipe:: host # # The MIT License (MIT) # From 6273271d40785c41fc1c26a0bf4f92f19d22d183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 9 Dec 2020 15:42:19 +0100 Subject: [PATCH 185/327] Remove kosmos-bitcoin::source from draco Bitcoind runs inside a VM, not directly on the host --- nodes/draco.kosmos.org.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/nodes/draco.kosmos.org.json b/nodes/draco.kosmos.org.json index 116ce07..394291c 100644 --- a/nodes/draco.kosmos.org.json +++ b/nodes/draco.kosmos.org.json @@ -20,7 +20,6 @@ "kosmos_encfs", "kosmos_encfs::default", "kosmos-postgresql::replica", - "kosmos-bitcoin::source", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -57,7 +56,6 @@ "recipe[kosmos-base]", "recipe[kosmos_encfs]", "role[postgresql_replica]", - "recipe[kosmos-bitcoin::source]", "recipe[kosmos_kvm::host]", "recipe[kosmos-ejabberd::firewall]", "recipe[kosmos-ipfs::firewall_swarm]", From 77ab77afe833aaccb99948d5bae1fa35edde5c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 9 Dec 2020 15:42:49 +0100 Subject: [PATCH 186/327] Update the centaurus and draco nodes after Chef run --- nodes/centaurus.kosmos.org.json | 9 ++++++--- nodes/draco.kosmos.org.json | 13 ++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/nodes/centaurus.kosmos.org.json b/nodes/centaurus.kosmos.org.json index 9740d3f..59c6b79 100644 --- a/nodes/centaurus.kosmos.org.json +++ b/nodes/centaurus.kosmos.org.json @@ -31,6 +31,10 @@ "kosmos_discourse::default", "kosmos_drone", "kosmos_drone::default", + "kosmos_kvm::host", + "kosmos-ejabberd::firewall", + "kosmos-postgresql::firewall_replicas", + "kosmos_zerotier::firewall", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -54,8 +58,7 @@ "nginx::commons_dir", "nginx::commons_script", "nginx::commons_conf", - "firewall::default", - "chef-sugar::default", + "kosmos-nginx::firewall", "backup::default", "logrotate::default", "kosmos-base::letsencrypt", @@ -87,4 +90,4 @@ "recipe[kosmos-postgresql::firewall_replicas]", "recipe[kosmos_zerotier::firewall]" ] -} +} \ No newline at end of file diff --git a/nodes/draco.kosmos.org.json b/nodes/draco.kosmos.org.json index 394291c..f463aad 100644 --- a/nodes/draco.kosmos.org.json +++ b/nodes/draco.kosmos.org.json @@ -8,7 +8,7 @@ "automatic": { "fqdn": "draco.kosmos.org", "os": "linux", - "os_version": "5.4.0-42-generic", + "os_version": "5.4.0-54-generic", "hostname": "draco", "ipaddress": "148.251.237.73", "roles": [ @@ -20,6 +20,14 @@ "kosmos_encfs", "kosmos_encfs::default", "kosmos-postgresql::replica", + "kosmos_kvm::host", + "kosmos-ejabberd::firewall", + "kosmos-ipfs::firewall_swarm", + "kosmos-ipfs::firewall_public_gateway", + "kosmos-postgresql::firewall_replicas", + "kosmos-bitcoin::firewall", + "kosmos_zerotier::firewall", + "kosmos-nginx::firewall", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -35,7 +43,6 @@ "hostname::default", "firewall::default", "chef-sugar::default", - "ark::default", "build-essential::default" ], "platform": "ubuntu", @@ -65,4 +72,4 @@ "recipe[kosmos_zerotier::firewall]", "recipe[kosmos-nginx::firewall]" ] -} +} \ No newline at end of file From a92205bd65783b93cceebb2140d7ed8d6cdc18bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 9 Dec 2020 16:29:15 +0100 Subject: [PATCH 187/327] Fix the VM creation script Also join the zerotier network --- site-cookbooks/kosmos_kvm/files/create_vm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_kvm/files/create_vm b/site-cookbooks/kosmos_kvm/files/create_vm index 9c86baa..93375da 100644 --- a/site-cookbooks/kosmos_kvm/files/create_vm +++ b/site-cookbooks/kosmos_kvm/files/create_vm @@ -55,7 +55,9 @@ runcmd: # Enable serial console (for virsh) - systemctl enable serial-getty@ttyS0.service && systemctl start serial-getty@ttyS0.service - curl -s 'https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg' | gpg --import - - if z=\$(curl -s 'https://install.zerotier.com/' | gpg"); then echo "$z" | sudo bash; fi + - curl -s -o /tmp/install_zerotier 'https://install.zerotier.com/' + - cat /tmp/install_zerotier | gpg && bash /tmp/install_zerotier + - zerotier-cli join 12ac4a1e719d706e EOS cat > meta-data <<-EOS From cb8fc25fc8e7e211f58fa932caced75a9e060567 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 10 Dec 2020 22:51:35 +0100 Subject: [PATCH 188/327] Configure a zerotier-one network controller --- clients/zerotier-1.json | 4 + nodes/zerotier-1.json | 56 ++++ site-cookbooks/kosmos_zerotier/README.md | 3 +- .../kosmos_zerotier/files/zerotier-ctl.sh | 306 ++++++++++++++++++ .../kosmos_zerotier/recipes/controller.rb | 9 + .../kosmos_zerotier/recipes/default.rb | 21 -- .../kosmos_zerotier/recipes/firewall.rb | 23 +- 7 files changed, 377 insertions(+), 45 deletions(-) create mode 100644 clients/zerotier-1.json create mode 100644 nodes/zerotier-1.json create mode 100644 site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh create mode 100644 site-cookbooks/kosmos_zerotier/recipes/controller.rb diff --git a/clients/zerotier-1.json b/clients/zerotier-1.json new file mode 100644 index 0000000..f493753 --- /dev/null +++ b/clients/zerotier-1.json @@ -0,0 +1,4 @@ +{ + "name": "zerotier-1", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx59liuiEXuAykaiQhjvO\nMimzWH2MOE/GdfPdlGG0IupDtGbDgpsu6lHB/Tc8ct+SEsj55KuamEmUew3EzWRQ\ngVWAPjWtlk6gqVlpU+8eJjTAxT1vaEOvetzliPDNzRBk1AAzS0IkMQwPAIqOD2Vm\nz+QDrTiEFNnbKyBDQ54uY9jBtEgTHgzZyc9KHTjcodJu/oCmOuO0ieTtMS4CDWVl\no2auyABpXX6PzW3hFvH/GB0IlVC5IBa7XS6JrbIFbZCvoAYf/egcQUTToNiKH45e\n2tPZbFpOt955zwInKTioW+Ak3qVVEPvCZ9IBTN7jZkSQuP4Ob5SA4+IbDJcXGulG\nZQIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/zerotier-1.json b/nodes/zerotier-1.json new file mode 100644 index 0000000..685171d --- /dev/null +++ b/nodes/zerotier-1.json @@ -0,0 +1,56 @@ +{ + "name": "zerotier-1", + "normal": { + "knife_zero": { + "host": "10.147.20.147" + } + }, + "automatic": { + "fqdn": "zerotier-1", + "os": "linux", + "os_version": "5.4.0-1028-kvm", + "hostname": "zerotier-1", + "ipaddress": "192.168.122.72", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "kosmos_zerotier::controller", + "kosmos_zerotier::firewall", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "chef": { + "version": "15.14.0", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib" + }, + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + } + } + }, + "run_list": [ + "recipe[kosmos-base]", + "recipe[kosmos_zerotier::controller]", + "recipe[kosmos_zerotier::firewall]" + ] +} \ No newline at end of file diff --git a/site-cookbooks/kosmos_zerotier/README.md b/site-cookbooks/kosmos_zerotier/README.md index 8645fb0..9ff88d7 100644 --- a/site-cookbooks/kosmos_zerotier/README.md +++ b/site-cookbooks/kosmos_zerotier/README.md @@ -1,4 +1,3 @@ # kosmos_zerotier -TODO: Enter the cookbook description here. - +Configures zerotier controllers and firewall rules. diff --git a/site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh b/site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh new file mode 100644 index 0000000..f95865c --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh @@ -0,0 +1,306 @@ +#!/bin/bash + +# +# team: devops/zerotier-ctl +# status: laboratory +# author: Makersphere Labs +# +VERSION=1.1.14 +# +# +# +ZT_AUTHFILE='/var/lib/zerotier-one/authtoken.secret' +ZT_PUBLICID='/var/lib/zerotier-one/identity.public' +ZT_NETWORK_PRIVATE=1 +ZT_NETWORK_BRIDGING=0 +ZT_NETWORK_V4_ASSIGN_MODE='zt' +ZT_NETWORK_V6_ASSIGN_MODE='none' +# +# Colors +# +RED='\033[0;31m' +ORANGE='\033[0;33m' +GREEN='\033[0;32m' +NC='\033[0m' +# +# Main Application +# +if [ "$1" != '' ]; then + # + # List all networks on this controller + # + if [ "$1" == 'listnetworks' ] || [ "$1" == 'list' ] || [ "$1" == '-l' ]; then + echo + echo -e "${ORANGE}=> List Networks${NC}"; + echo + # Check if authtoken.secret exists + if [ -f $ZT_AUTHFILE ]; then + echo -e "${ORANGE}> Loading networks...${NC}"; + echo + ZT_AUTHTOKEN=`cat $ZT_AUTHFILE` + # Make a GET request to the API + # Tested with ZeroTier One (1.1.4) API v1. + ZT_API_RESPONSE=$(curl -LsfSw '\n%{http_code}' \ + -X GET http://localhost:9993/controller/network?auth=${ZT_AUTHTOKEN}) + if [ "$(echo "$ZT_API_RESPONSE" | tail -n1 )" == '200' ]; then + echo -e "> $(echo "$ZT_API_RESPONSE" | head -n-1 )"; + echo + echo -e "${GREEN}==> Success${NC}"; + echo + exit 0; + else + echo -e "${RED}==> Failed to connect to Controller${NC}"; + exit 1; + fi + else + echo -e "${RED}==> The AuthFile is missing${NC}"; + exit 1; + fi + # + # Add a new network to this controller + # + elif [ "$1" == 'create' ] || [ "$1" == '-c' ]; then + echo + echo -e "${ORANGE}=> Create Network${NC}"; + echo + if [ "$2" != '' ]; then + # Check if authtoken.secret exists + if [ -f $ZT_AUTHFILE ]; then + ZT_NETWORK_NAME=$2 + ZT_NETWORK_SERVER_ID=`head -c 10 $ZT_PUBLICID`; + ZT_AUTHTOKEN=`cat $ZT_AUTHFILE` + echo "> Add a configuration for network '${2}'..." + read -p '> Enter a start IP address (e.g. 10.1.1.1): ' READ_IP + if [ "$READ_IP" != '' ]; then + ZT_NETWORK_IP_START=$READ_IP + read -p '> Enter the last IP address (e.g. 10.1.1.254): ' READ_IP2 + if [ "$READ_IP2" != '' ]; then + ZT_NETWORK_IP_END=$READ_IP2 + read -p '> Enter the network address (e.g. 10.1.1.0): ' READ_ROUTE + if [ "$READ_ROUTE" != '' ]; then + ZT_NETWORK_IP_LOCAL_ROUTE=$READ_ROUTE + read -p '> Enter the network submask (e.g. /24): /' READ_MASK + if [ "$READ_MASK" != '' ]; then + ZT_NETWORK_IP_LOCAL_ROUTE_MASK=$READ_MASK + else + echo -e "${RED}==> Please enter a vaild submask${NC}"; + exit 1; + fi + else + echo -e "${RED}==> Please enter a network address${NC}"; + exit 1; + fi + else + echo -e "${RED}==> Please enter the last IP address${NC}"; + exit 1; + fi + else + echo -e "${RED}==> Please enter a start IP address${NC}"; + exit 1; + fi + # Huge JSON file ahead + # Do not change this JSON string! + ZT_NETWORK_CONFIG="{\"auth\":\"${ZT_AUTHTOKEN}\",\"name\":\"${ZT_NETWORK_NAME}\",\"private\":${ZT_NETWORK_PRIVATE},\"allowPassiveBridging\":${ZT_NETWORK_BRIDGING},\"v4AssignMode\":\"${ZT_NETWORK_V4_ASSIGN_MODE}\",\"v6AssignMode\":\"${ZT_NETWORK_V6_ASSIGN_MODE}\",\"routes\":[{\"target\":\"${ZT_NETWORK_IP_LOCAL_ROUTE}/${ZT_NETWORK_IP_LOCAL_ROUTE_MASK}\",\"via\":null,\"flags\":0,\"metric\":0}],\"ipAssignmentPools\":[{\"ipRangeStart\":\"${ZT_NETWORK_IP_START}\",\"ipRangeEnd\":\"${ZT_NETWORK_IP_END}\"}],\"rules\":[{\"ruleNo\":10,\"action\":\"accept\"}]}" + echo '> Do you wish to add this network?' + select ZT_ADD_NET_YN in 'Yes' 'No'; do + case $ZT_ADD_NET_YN in + 'Yes' ) + # Make a POST request to the API + # Tested with ZeroTier One (1.1.4) API v1. + ZT_API_RESPONSE=$(curl -LsfSw '\n%{http_code}' \ + -X POST -d "$ZT_NETWORK_CONFIG" \ + http://localhost:9993/controller/network/${ZT_NETWORK_SERVER_ID}______?auth=${ZT_AUTHTOKEN}) + if [ "$(echo "$ZT_API_RESPONSE" | tail -n1 )" == '200' ]; then + ZT_NETWORK_NWID=$(echo "$(echo "$ZT_API_RESPONSE" | head -n-1 )" | grep -Po '(?<="nwid": ")[^"]*') + echo -e "${GREEN}==> Network '${ZT_NETWORK_NAME}' (ID ${ZT_NETWORK_NWID}) was successfully added to controller '${ZT_NETWORK_SERVER_ID}'${NC}"; + echo + exit 0; + else + echo -e "${RED}==> Failed to connect to Controller${NC}"; + exit 1; + fi + #DEBUG: echo $ZT_NETWORK_CONFIG + break;; + 'No' ) + echo -e "${ORANGE}==> Nothing was added${NC}"; + echo + exit 0; + exit;; + esac + done + else + echo -e "${RED}==> The AuthFile is missing${NC}"; + exit 1; + fi + else + echo -e "${RED}==> Please specify a network${NC}"; + exit 1; + fi + # + # Remove a new network from this controller + # + elif [ "$1" == 'delete' ] || [ "$1" == '-d' ]; then + echo + echo -e "${ORANGE}=> Delete Network${NC}"; + echo + if [ "$2" != '' ]; then + # Check if authtoken.secret exists + if [ -f $ZT_AUTHFILE ]; then + ZT_NETWORK_ID=$2 + ZT_AUTHTOKEN=`cat $ZT_AUTHFILE` + echo '> Do you wish to remove this network?' + select ZT_DEL_NET_YN in 'Yes' 'No'; do + case $ZT_DEL_NET_YN in + 'Yes' ) + # Make a DELETE request to the API + # Tested with ZeroTier One (1.1.4) API v1. + ZT_API_RESPONSE=$(curl -LsfSw '\n%{http_code}' \ + -X DELETE http://localhost:9993/controller/network/${ZT_NETWORK_ID}?auth=${ZT_AUTHTOKEN}) + if [ "$(echo "$ZT_API_RESPONSE" | tail -n1 )" == '200' ]; then + echo -e "${GREEN}==> Network '${ZT_NETWORK_ID}' was removed${NC}"; + echo + exit 0; + else + echo -e "${RED}==> Failed to connect to Controller${NC}"; + exit 1; + fi + break;; + 'No' ) + echo -e "${ORANGE}==> Nothing was removed${NC}"; + echo + exit 0; + exit;; + esac + done + + else + echo -e "${RED}==> The AuthFile is missing${NC}"; + exit 1; + fi + else + echo -e "${RED}==> Please specify a network${NC}"; + exit 1; + fi + # + # Authorize a new client to a network + # + elif [ "$1" == 'auth' ] || [ "$1" == '-a' ]; then + echo + echo -e "${ORANGE}=> Authorize Client${NC}"; + echo + if [ "$2" != '' ] && [ "$3" != '' ]; then + # Check if authtoken.secret exists + if [ -f $ZT_AUTHFILE ]; then + ZT_NETWORK=$2 + ZT_MEMBER=$3 + ZT_AUTHTOKEN=`cat $ZT_AUTHFILE` + echo "> Do you wish to authorize this client (${ZT_MEMBER})?" + select ZT_ADD_MEM_YN in 'Yes' 'No'; do + case $ZT_ADD_MEM_YN in + 'Yes' ) + # Make a POST request to the API + # Tested with ZeroTier One (1.1.4) API v1. + ZT_API_RESPONSE=$(curl -LsfSw '\n%{http_code}' \ + -X POST -d "{\"authorized\":true}" \ + http://localhost:9993/controller/network/${ZT_NETWORK}/member/${ZT_MEMBER}?auth=${ZT_AUTHTOKEN}) + if [ "$(echo "$ZT_API_RESPONSE" | tail -n1 )" == '200' ]; then + echo -e "${GREEN}==> Client '${3}' was authorized to network '${2}'${NC}"; + echo + exit 0; + else + echo -e "${RED}==> Failed to connect to Controller${NC}"; + exit 1; + fi + break;; + 'No' ) + echo -e "${ORANGE}==> Nothing was added${NC}"; + echo + exit 0; + exit;; + esac + done + else + echo -e "${RED}==> The AuthFile is missing${NC}"; + exit 1; + fi + else + echo -e "${RED}==> Please specify a network & client${NC}"; + exit 1; + fi + # + # Deauthorize a client + # + elif [ "$1" == 'deauth' ] || [ "$1" == '-da' ]; then + echo + echo -e "${ORANGE}=> Deauthorize Client${NC}"; + echo + if [ "$2" != '' ] && [ "$3" != '' ]; then + # Check if authtoken.secret exists + if [ -f $ZT_AUTHFILE ]; then + ZT_NETWORK=$2 + ZT_MEMBER=$3 + ZT_AUTHTOKEN=`cat $ZT_AUTHFILE` + echo "> Do you wish to deauthorize this client (${ZT_MEMBER})?" + select ZT_DEL_MEM_YN in 'Yes' 'No'; do + case $ZT_DEL_MEM_YN in + 'Yes' ) + # Make a DELETE request to the API + # Tested with ZeroTier One (1.1.4) API v1. + ZT_API_RESPONSE=$(curl -LsfSw '\n%{http_code}' \ + -X DELETE http://localhost:9993/controller/network/${ZT_NETWORK}/member/${ZT_MEMBER}?auth=${ZT_AUTHTOKEN}) + echo $ZT_API_RESPONSE + if [ "$(echo "$ZT_API_RESPONSE" | tail -n1 )" == '200' ]; then + echo -e "${GREEN}==> Client '${3}' was deauthorized${NC}"; + echo + exit 0; + else + echo -e "${RED}==> Failed to connect to Controller${NC}"; + exit 1; + fi + break;; + 'No' ) + echo -e "${ORANGE}==> Nothing was removed${NC}"; + echo + exit 0; + exit;; + esac + done + else + echo -e "${RED}==> The AuthFile is missing${NC}"; + exit 1; + fi + else + echo -e "${RED}==> Please specify a network & client${NC}"; + exit 1; + fi + # + # Display help + # + elif [ "$1" == 'help' ] || [ "$1" == '-h' ]; then + echo -e " +${ORANGE}+++ ZeroTier Controller CLI +++${NC} + +Version ${VERSION} + +Copyright © 2016 Makersphere Labs +Licensed under GNU GPL v3 + +Usage: zerotier-ctl [] + +Available commands: +help - Display this help +listnetworks - List all network IDs +create - Create a new network +delete - Delete a network +auth - Authorize a client +deauth - Deauthorize a client"; + echo + exit 0; + else + echo -e "${ORANGE}==> Use 'help' to get started${NC}"; + exit 1; + fi +else + echo -e "${ORANGE}==> Use 'help' to get started${NC}"; + exit 1; +fi diff --git a/site-cookbooks/kosmos_zerotier/recipes/controller.rb b/site-cookbooks/kosmos_zerotier/recipes/controller.rb new file mode 100644 index 0000000..a754868 --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/recipes/controller.rb @@ -0,0 +1,9 @@ +# +# Cookbook:: kosmos_zerotier +# Recipe:: controller +# + +cookbook_file "/usr/local/sbin/zerotier-ctl" do + source "zerotier-ctl.sh" + mode "0750" +end diff --git a/site-cookbooks/kosmos_zerotier/recipes/default.rb b/site-cookbooks/kosmos_zerotier/recipes/default.rb index 1125c4a..12c2304 100644 --- a/site-cookbooks/kosmos_zerotier/recipes/default.rb +++ b/site-cookbooks/kosmos_zerotier/recipes/default.rb @@ -2,24 +2,3 @@ # Cookbook:: kosmos_zerotier # 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. diff --git a/site-cookbooks/kosmos_zerotier/recipes/firewall.rb b/site-cookbooks/kosmos_zerotier/recipes/firewall.rb index b179103..df99a7f 100644 --- a/site-cookbooks/kosmos_zerotier/recipes/firewall.rb +++ b/site-cookbooks/kosmos_zerotier/recipes/firewall.rb @@ -2,30 +2,9 @@ # Cookbook:: kosmos_zerotier # Recipe:: firewall # -# 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. firewall_rule "zerotier" do port node["kosmos_zerotier"]["server_port"] - protocol :tcp + protocol :none command :allow end From 1cb366a160e97a86d670bbd356148ab0255374f1 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 10 Dec 2020 23:39:59 +0100 Subject: [PATCH 189/327] Add commands for running Chef against VMs --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 45a23ea..713e89b 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,26 @@ bundle install -### Run Chef Solo +### Bootstrap a new server + + knife zero bootstrap root@dev.kosmos.org --run-list "recipe[kosmos-base],..." -j '{"example_cookbook":{"memory_max":"256M"}}' --secret-file .chef/encrypted_data_bag_secret + +### Bootstrap a new VM + + knife zero bootstrap ubuntu@zerotier-ip-address -x ubuntu --sudo --run-list "recipe[kosmos-base]" --secret-file .chef/encrypted_data_bag_secret + +### Run Chef Zero knife zero converge name:dev.kosmos.org +### Run Chef Zero on a VM + + knife zero converge -a knife_zero.host name:vm-name-23 + ### Update Chef Client on a server: knife zero converge name:dev.kosmos.org --client-version 15.3.14 -### Bootstrap a new server - - knife zero bootstrap root@dev.kosmos.org --run-list "recipe[kosmos-base],..." -j '{"example_cookbook":{"memory_max":"256M"}}' --secret-file .chef/encrypted_data_bag_secret - ### Managing cookbooks Cookbooks are managed via Berkshelf. Run `berks --help` for command help. From 2de9d5fe1776a076f92d28f53a55a0d5bac0f3cd Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 11 Dec 2020 17:40:40 +0100 Subject: [PATCH 190/327] Fix typo --- site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh b/site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh index f95865c..a815f0a 100644 --- a/site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh +++ b/site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh @@ -83,7 +83,7 @@ if [ "$1" != '' ]; then if [ "$READ_MASK" != '' ]; then ZT_NETWORK_IP_LOCAL_ROUTE_MASK=$READ_MASK else - echo -e "${RED}==> Please enter a vaild submask${NC}"; + echo -e "${RED}==> Please enter a valid submask${NC}"; exit 1; fi else From c4dbed8d6579904090796b862a7b11609f0e1cc6 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 11 Dec 2020 17:40:48 +0100 Subject: [PATCH 191/327] Fix zerotier network creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using outdated/invalid rules syntax. Remove the property entirely, so the API will create the default rule (which is the same) on creation. Co-authored-by: Greg Karékinian --- site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh b/site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh index a815f0a..6a498f0 100644 --- a/site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh +++ b/site-cookbooks/kosmos_zerotier/files/zerotier-ctl.sh @@ -100,7 +100,7 @@ if [ "$1" != '' ]; then fi # Huge JSON file ahead # Do not change this JSON string! - ZT_NETWORK_CONFIG="{\"auth\":\"${ZT_AUTHTOKEN}\",\"name\":\"${ZT_NETWORK_NAME}\",\"private\":${ZT_NETWORK_PRIVATE},\"allowPassiveBridging\":${ZT_NETWORK_BRIDGING},\"v4AssignMode\":\"${ZT_NETWORK_V4_ASSIGN_MODE}\",\"v6AssignMode\":\"${ZT_NETWORK_V6_ASSIGN_MODE}\",\"routes\":[{\"target\":\"${ZT_NETWORK_IP_LOCAL_ROUTE}/${ZT_NETWORK_IP_LOCAL_ROUTE_MASK}\",\"via\":null,\"flags\":0,\"metric\":0}],\"ipAssignmentPools\":[{\"ipRangeStart\":\"${ZT_NETWORK_IP_START}\",\"ipRangeEnd\":\"${ZT_NETWORK_IP_END}\"}],\"rules\":[{\"ruleNo\":10,\"action\":\"accept\"}]}" + ZT_NETWORK_CONFIG="{\"auth\":\"${ZT_AUTHTOKEN}\",\"name\":\"${ZT_NETWORK_NAME}\",\"private\":${ZT_NETWORK_PRIVATE},\"allowPassiveBridging\":${ZT_NETWORK_BRIDGING},\"v4AssignMode\":\"${ZT_NETWORK_V4_ASSIGN_MODE}\",\"v6AssignMode\":\"${ZT_NETWORK_V6_ASSIGN_MODE}\",\"routes\":[{\"target\":\"${ZT_NETWORK_IP_LOCAL_ROUTE}/${ZT_NETWORK_IP_LOCAL_ROUTE_MASK}\",\"via\":null,\"flags\":0,\"metric\":0}],\"ipAssignmentPools\":[{\"ipRangeStart\":\"${ZT_NETWORK_IP_START}\",\"ipRangeEnd\":\"${ZT_NETWORK_IP_END}\"}]}" echo '> Do you wish to add this network?' select ZT_ADD_NET_YN in 'Yes' 'No'; do case $ZT_ADD_NET_YN in From ebfd36bab8b2f9f6743b5bf7e4e26dd7f7f785aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 11 Dec 2020 18:54:32 +0100 Subject: [PATCH 192/327] Add nodejs-1 client and node file Refs #259 --- clients/nodejs-1.json | 4 ++++ nodes/nodejs-1.json | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 clients/nodejs-1.json create mode 100644 nodes/nodejs-1.json diff --git a/clients/nodejs-1.json b/clients/nodejs-1.json new file mode 100644 index 0000000..27b5f11 --- /dev/null +++ b/clients/nodejs-1.json @@ -0,0 +1,4 @@ +{ + "name": "nodejs-1", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA9L4BQgLEpQSSbSLwXOab\nfFey5VSk8ynDmj2I9sOpPMIXkXpmbONkyXqZ4CqKrMRtesXAg1F1lIwzE/WJy0wP\n9CRhEgnclHRHE3TVqWt8dC6+u5kx5o48EF8X9UWgV1098c21gcn68NZ7+l/janws\ntLYrgMynikcadaGtAkRszGG0dX+qdeRx9hRzhTNUIG4AYe6bUA6/LfOEPyRyuo3Q\ncaN5fAJSK+RRMWr1d7Mzd8k+l3xXzcUTMUL2To+Zh0Fw2SIEocM4NS1W9nAm4+Cq\nhlQUhsoHDwk7bDsIQtRNfy3bX59PSIVMcWLNkWilLzZW1yRtFGPTJfPlR4Y1XJb5\nuwIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/nodejs-1.json b/nodes/nodejs-1.json new file mode 100644 index 0000000..c51a42b --- /dev/null +++ b/nodes/nodejs-1.json @@ -0,0 +1,52 @@ +{ + "name": "nodejs-1", + "normal": { + "knife_zero": { + "host": "10.1.1.3" + } + }, + "automatic": { + "fqdn": "nodejs-1", + "os": "linux", + "os_version": "5.4.0-1028-kvm", + "hostname": "nodejs-1", + "ipaddress": "192.168.122.57", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "chef": { + "version": "15.14.0", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib" + }, + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + } + } + }, + "run_list": [ + "recipe[kosmos-base]" + ] +} \ No newline at end of file From 396fe6e71477ae1fe0f9e4e76bcfdec4ad51a123 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 11 Dec 2020 18:44:17 +0100 Subject: [PATCH 193/327] Whitelist ejabberd custom node attributes fixes #256 --- .chef/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chef/config.rb b/.chef/config.rb index 96bb67b..0609bb3 100644 --- a/.chef/config.rb +++ b/.chef/config.rb @@ -26,5 +26,5 @@ knife[:automatic_attribute_whitelist] = %w[ chef_packages ] knife[:default_attribute_whitelist] = [] -knife[:normal_attribute_whitelist] = ['knife_zero'] +knife[:normal_attribute_whitelist] = ['knife_zero','kosmos-ejabberd'] knife[:override_attribute_whitelist] = [] From fb996e9abfd5373467f3af2c98e80a9c72fc0af2 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 11 Dec 2020 18:44:41 +0100 Subject: [PATCH 194/327] Join new zerotier network on VM creation --- site-cookbooks/kosmos_kvm/files/create_vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_kvm/files/create_vm b/site-cookbooks/kosmos_kvm/files/create_vm index 93375da..db4cf8e 100644 --- a/site-cookbooks/kosmos_kvm/files/create_vm +++ b/site-cookbooks/kosmos_kvm/files/create_vm @@ -57,7 +57,7 @@ runcmd: - curl -s 'https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg' | gpg --import - curl -s -o /tmp/install_zerotier 'https://install.zerotier.com/' - cat /tmp/install_zerotier | gpg && bash /tmp/install_zerotier - - zerotier-cli join 12ac4a1e719d706e + - zerotier-cli join 8541e5153eb4327c EOS cat > meta-data <<-EOS From 4b9dfd9c60ee45c542b15bb1eac767352760132b Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 11 Dec 2020 19:24:12 +0100 Subject: [PATCH 195/327] Update node configs --- nodes/akkounts-1.json | 7 ++++--- nodes/bitcoin-2.json | 4 ++-- nodes/ejabberd-1.json | 3 ++- nodes/ejabberd-2.json | 3 ++- nodes/ipfs-1.json | 4 ++-- nodes/uploads-1.json | 3 ++- nodes/wiki-1.json | 5 +++-- nodes/zerotier-1.json | 2 +- 8 files changed, 18 insertions(+), 13 deletions(-) diff --git a/nodes/akkounts-1.json b/nodes/akkounts-1.json index b85f6d1..27dd090 100644 --- a/nodes/akkounts-1.json +++ b/nodes/akkounts-1.json @@ -2,7 +2,7 @@ "name": "akkounts-1", "normal": { "knife_zero": { - "host": "10.147.20.144" + "host": "10.1.1.144" } }, "automatic": { @@ -12,7 +12,7 @@ "hostname": "akkounts-1", "ipaddress": "192.168.122.160", "roles": [ - + "akkounts" ], "recipes": [ "kosmos-base", @@ -48,6 +48,7 @@ "nginx::commons_dir", "nginx::commons_script", "nginx::commons_conf", + "kosmos-nginx::firewall", "git::default", "git::package", "kosmos-base::letsencrypt" @@ -70,4 +71,4 @@ "recipe[kosmos-base]", "role[akkounts]" ] -} +} \ No newline at end of file diff --git a/nodes/bitcoin-2.json b/nodes/bitcoin-2.json index c888e0c..2290685 100644 --- a/nodes/bitcoin-2.json +++ b/nodes/bitcoin-2.json @@ -2,7 +2,7 @@ "name": "bitcoin-2", "normal": { "knife_zero": { - "host": "10.147.20.163" + "host": "10.1.1.163" } }, "automatic": { @@ -57,4 +57,4 @@ "recipe[kosmos-bitcoin::source]", "recipe[kosmos-bitcoin::lnd]" ] -} \ No newline at end of file +} diff --git a/nodes/ejabberd-1.json b/nodes/ejabberd-1.json index 296c803..713af49 100644 --- a/nodes/ejabberd-1.json +++ b/nodes/ejabberd-1.json @@ -2,7 +2,7 @@ "name": "ejabberd-1", "normal": { "knife_zero": { - "host": "10.147.20.166" + "host": "10.1.1.166" }, "kosmos-ejabberd": { "erlang_node": "ejabberd@draco.kosmos.org" @@ -39,6 +39,7 @@ "postfix::_attributes", "postfix::sasl_auth", "hostname::default", + "kosmos-ejabberd::firewall", "tor-full::default", "kosmos-base::letsencrypt", "backup::default", diff --git a/nodes/ejabberd-2.json b/nodes/ejabberd-2.json index 5e7726c..31f8b9b 100644 --- a/nodes/ejabberd-2.json +++ b/nodes/ejabberd-2.json @@ -2,7 +2,7 @@ "name": "ejabberd-2", "normal": { "knife_zero": { - "host": "10.147.20.44" + "host": "10.1.1.44" }, "kosmos-ejabberd": { "erlang_node": "ejabberd@centaurus.kosmos.org" @@ -39,6 +39,7 @@ "postfix::_attributes", "postfix::sasl_auth", "hostname::default", + "kosmos-ejabberd::firewall", "tor-full::default", "kosmos-base::letsencrypt", "backup::default", diff --git a/nodes/ipfs-1.json b/nodes/ipfs-1.json index 5428880..2e9ba52 100644 --- a/nodes/ipfs-1.json +++ b/nodes/ipfs-1.json @@ -2,7 +2,7 @@ "name": "ipfs-1", "normal": { "knife_zero": { - "host": "10.147.20.198" + "host": "10.1.1.198" } }, "automatic": { @@ -72,4 +72,4 @@ "recipe[kosmos-ipfs]", "recipe[kosmos-ipfs::public_gateway]" ] -} \ No newline at end of file +} diff --git a/nodes/uploads-1.json b/nodes/uploads-1.json index bb43002..3c65fbf 100644 --- a/nodes/uploads-1.json +++ b/nodes/uploads-1.json @@ -2,7 +2,7 @@ "name": "uploads-1", "normal": { "knife_zero": { - "host": "10.147.20.98" + "host": "10.1.1.98" } }, "automatic": { @@ -41,6 +41,7 @@ "nginx::commons_dir", "nginx::commons_script", "nginx::commons_conf", + "kosmos-nginx::firewall", "kosmos-base::letsencrypt" ], "platform": "ubuntu", diff --git a/nodes/wiki-1.json b/nodes/wiki-1.json index b69ecff..d4ef9fb 100644 --- a/nodes/wiki-1.json +++ b/nodes/wiki-1.json @@ -2,13 +2,13 @@ "name": "wiki-1", "normal": { "knife_zero": { - "host": "10.147.20.206" + "host": "10.1.1.206" } }, "automatic": { "fqdn": "wiki-1", "os": "linux", - "os_version": "5.4.0-45-generic", + "os_version": "5.4.0-54-generic", "hostname": "wiki-1", "ipaddress": "192.168.122.26", "roles": [ @@ -51,6 +51,7 @@ "nginx::commons_dir", "nginx::commons_script", "nginx::commons_conf", + "kosmos-nginx::firewall", "mediawiki::nginx", "backup::default", "logrotate::default", diff --git a/nodes/zerotier-1.json b/nodes/zerotier-1.json index 685171d..355a4f8 100644 --- a/nodes/zerotier-1.json +++ b/nodes/zerotier-1.json @@ -2,7 +2,7 @@ "name": "zerotier-1", "normal": { "knife_zero": { - "host": "10.147.20.147" + "host": "10.1.1.147" } }, "automatic": { From 83736d2a8566c32dccd57e9737921bf2f8b9244d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 11 Dec 2020 19:28:34 +0100 Subject: [PATCH 196/327] Update the bitcoin-2 node file after running chef --- nodes/bitcoin-2.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nodes/bitcoin-2.json b/nodes/bitcoin-2.json index 2290685..9bd540c 100644 --- a/nodes/bitcoin-2.json +++ b/nodes/bitcoin-2.json @@ -8,7 +8,7 @@ "automatic": { "fqdn": "bitcoin-2", "os": "linux", - "os_version": "5.4.0-42-generic", + "os_version": "5.4.0-54-generic", "hostname": "bitcoin-2", "ipaddress": "192.168.122.148", "roles": [ @@ -34,6 +34,7 @@ "postfix::sasl_auth", "hostname::default", "ark::default", + "kosmos-bitcoin::firewall", "git::default", "git::package", "golang::default" @@ -57,4 +58,4 @@ "recipe[kosmos-bitcoin::source]", "recipe[kosmos-bitcoin::lnd]" ] -} +} \ No newline at end of file From 1551fe6d1befbdf40fc420a52f4cb9e84a053364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 11 Dec 2020 19:29:56 +0100 Subject: [PATCH 197/327] Update the ipfs-1 node file after running chef --- nodes/ipfs-1.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nodes/ipfs-1.json b/nodes/ipfs-1.json index 2e9ba52..13008a6 100644 --- a/nodes/ipfs-1.json +++ b/nodes/ipfs-1.json @@ -8,7 +8,7 @@ "automatic": { "fqdn": "ipfs-1", "os": "linux", - "os_version": "5.4.0-52-generic", + "os_version": "5.4.0-54-generic", "hostname": "ipfs-1", "ipaddress": "192.168.122.195", "roles": [ @@ -40,6 +40,7 @@ "kosmos-nodejs::default", "nodejs::nodejs_from_package", "nodejs::repo", + "kosmos-ipfs::firewall_swarm", "firewall::default", "chef-sugar::default", "kosmos-nginx::default", @@ -51,6 +52,8 @@ "nginx::commons_dir", "nginx::commons_script", "nginx::commons_conf", + "kosmos-nginx::firewall", + "kosmos-ipfs::firewall_public_gateway", "kosmos-base::letsencrypt" ], "platform": "ubuntu", @@ -72,4 +75,4 @@ "recipe[kosmos-ipfs]", "recipe[kosmos-ipfs::public_gateway]" ] -} +} \ No newline at end of file From db51f1f33240f54e047ede63a4bb42c01606ef0b Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 17 Dec 2020 14:09:41 +0100 Subject: [PATCH 198/327] Add new Zoom meeting ID to whitelist --- site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb index acfb650..fbf290f 100644 --- a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb +++ b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb @@ -121,7 +121,7 @@ application app_path do "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_MEETING_WHITELIST" => "414901303" + "KREDITS_ZOOM_MEETING_WHITELIST" => "414901303,82557072771" } ) notifies :run, "execute[systemctl daemon-reload]", :delayed From f75aeaf9b5aab25e415ca9dacfa55ede3264bb5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 18 Dec 2020 17:02:13 +0100 Subject: [PATCH 199/327] Always set the promote trigger file config Only setting it for standby servers isn't useful, as we need to be able to touch this file to trigger the promotion of a new primary server after running Chef on it. --- site-cookbooks/kosmos-postgresql/resources/server.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/site-cookbooks/kosmos-postgresql/resources/server.rb b/site-cookbooks/kosmos-postgresql/resources/server.rb index b677c77..8e1ff58 100644 --- a/site-cookbooks/kosmos-postgresql/resources/server.rb +++ b/site-cookbooks/kosmos-postgresql/resources/server.rb @@ -67,9 +67,7 @@ action :create do listen_addresses: "0.0.0.0" } - if new_resource.role == "replica" - additional_config[:promote_trigger_file] = "#{postgresql_data_dir}/failover.trigger" - end + additional_config[:promote_trigger_file] = "#{postgresql_data_dir}/failover.trigger" ssl_cert = postgresql_data_bag_item['ssl_cert'] ssl_cert_path = "#{postgresql_data_dir}/server.crt" From c700f9897620fb408706504f0e166614622b9d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 18 Dec 2020 17:53:28 +0100 Subject: [PATCH 200/327] Add a firewall rule to allow clients to connect Previously it was not an issue because services that connected to the PostgreSQL primary were also on the same server as a standby server. --- site-cookbooks/kosmos-postgresql/recipes/default.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb index b3c9f4f..8055b8b 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/default.rb @@ -64,6 +64,13 @@ postgresql_clients.each do |client| access_method "md5" notifies :reload, "service[#{postgresql_service}]", :immediately end + + firewall_rule "postgresql #{hostname}" do + port 5432 + protocol :tcp + command :allow + source ip + end end postgresql_replicas.each do |replica| From 87388ac69d35d1a1e270b7847ff21729b450b468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 18 Dec 2020 17:54:31 +0100 Subject: [PATCH 201/327] Add the postgresql_client role to the mastodon role This will add the firewall rule and pg_hba access rule on the PostgreSQL servers --- nodes/andromeda.kosmos.org.json | 5 ++--- roles/mastodon.rb | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nodes/andromeda.kosmos.org.json b/nodes/andromeda.kosmos.org.json index 338bb9c..a4bd9a3 100644 --- a/nodes/andromeda.kosmos.org.json +++ b/nodes/andromeda.kosmos.org.json @@ -24,9 +24,9 @@ "ipaddress": "46.4.18.160", "roles": [ "base", - "postgresql_primary", "mastodon", - "ejabberd" + "ejabberd", + "postgresql_client" ], "recipes": [ "kosmos-base", @@ -130,7 +130,6 @@ "recipe[kosmos-base::andromeda_firewall]", "recipe[kosmos-ipfs]", "recipe[kosmos-ipfs::public_gateway]", - "role[postgresql_primary]", "recipe[kosmos-btcpayserver::proxy]", "role[mastodon]", "role[ejabberd]", diff --git a/roles/mastodon.rb b/roles/mastodon.rb index 44bbcdc..5bb39e4 100644 --- a/roles/mastodon.rb +++ b/roles/mastodon.rb @@ -3,4 +3,5 @@ name "mastodon" run_list %w( kosmos-mastodon kosmos-mastodon::nginx + role[postgresql_client] ) From a2b76c7d76a1ffbae04e0bdab312fa85ed04e360 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 21 Dec 2020 11:00:55 +0100 Subject: [PATCH 202/327] New recipe: Install .NET Core SDK --- nodes/bitcoin-2.json | 8 +++-- roles/btcpay.rb | 5 +++ .../kosmos-bitcoin/attributes/default.rb | 4 +++ .../kosmos-bitcoin/recipes/dotnet.rb | 33 +++++++++++++++++++ .../kosmos-bitcoin/recipes/source.rb | 26 +-------------- 5 files changed, 48 insertions(+), 28 deletions(-) create mode 100644 roles/btcpay.rb create mode 100644 site-cookbooks/kosmos-bitcoin/recipes/dotnet.rb diff --git a/nodes/bitcoin-2.json b/nodes/bitcoin-2.json index 9bd540c..eb83606 100644 --- a/nodes/bitcoin-2.json +++ b/nodes/bitcoin-2.json @@ -8,17 +8,18 @@ "automatic": { "fqdn": "bitcoin-2", "os": "linux", - "os_version": "5.4.0-54-generic", + "os_version": "5.4.0-58-generic", "hostname": "bitcoin-2", "ipaddress": "192.168.122.148", "roles": [ - + "btcpay" ], "recipes": [ "kosmos-base", "kosmos-base::default", "kosmos-bitcoin::source", "kosmos-bitcoin::lnd", + "kosmos-bitcoin::dotnet", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -56,6 +57,7 @@ "run_list": [ "recipe[kosmos-base]", "recipe[kosmos-bitcoin::source]", - "recipe[kosmos-bitcoin::lnd]" + "recipe[kosmos-bitcoin::lnd]", + "role[btcpay]" ] } \ No newline at end of file diff --git a/roles/btcpay.rb b/roles/btcpay.rb new file mode 100644 index 0000000..42017d8 --- /dev/null +++ b/roles/btcpay.rb @@ -0,0 +1,5 @@ +name "btcpay" + +run_list %w( + kosmos-bitcoin::dotnet +) diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 306c2c7..29e39f5 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -28,3 +28,7 @@ node.default['bitcoin']['conf'] = { node.default['lnd']['repo'] = 'https://github.com/lightningnetwork/lnd' node.default['lnd']['revision'] = 'v0.11.0-beta' node.default['lnd']['source_dir'] = '/opt/lnd' + +node.default['dotnet']['ms_packages_src_url'] = "https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb" +node.default['dotnet']['ms_packages_src_checksum'] = "4df5811c41fdded83eb9e2da9336a8dfa5594a79dc8a80133bd815f4f85b9991" + diff --git a/site-cookbooks/kosmos-bitcoin/recipes/dotnet.rb b/site-cookbooks/kosmos-bitcoin/recipes/dotnet.rb new file mode 100644 index 0000000..4af8314 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/recipes/dotnet.rb @@ -0,0 +1,33 @@ +# +# Cookbook:: kosmos-bitcoin +# Recipe:: dotnet +# + +build_essential + +apt_repository 'universe' do + uri 'http://archive.ubuntu.com/ubuntu/' + distribution 'focal' + components ['universe'] +end + +apt_package 'apt-transport-https' + +remote_file '/opt/packages-microsoft-prod.deb' do + source node['dotnet']['ms_packages_src_url'] + checksum node['dotnet']['ms_packages_src_checksum'] + action :create_if_missing +end + +dpkg_package 'packages-microsoft-prod' do + source '/opt/packages-microsoft-prod.deb' + action :install + notifies :run, 'execute[apt_update]' +end + +execute 'apt_update' do + command 'apt update' + action :nothing +end + +apt_package 'dotnet-sdk-3.1' diff --git a/site-cookbooks/kosmos-bitcoin/recipes/source.rb b/site-cookbooks/kosmos-bitcoin/recipes/source.rb index 0d60853..cac64c4 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/source.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/source.rb @@ -2,28 +2,6 @@ # Cookbook:: kosmos-bitcoin # Recipe:: source # -# 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. -# # TODO move to custom kosmos cookbook before publshing bitcoin cookbook systemd_unit "mnt-data-bitcoin.mount" do @@ -46,10 +24,8 @@ systemd_unit "mnt-data-bitcoin.mount" do action [:create, :enable, :start] end - -include_recipe 'ark' - build_essential +include_recipe 'ark' %w{ libtool autotools-dev make automake cmake curl g++-multilib libtool binutils-gold bsdmainutils pkg-config python3 patch }.each do |pkg| From aa2aa59e28963f5e61afda7148273a2356609be5 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 21 Dec 2020 11:12:14 +0100 Subject: [PATCH 203/327] Download and build NBXplorer and BTCPay --- nodes/bitcoin-2.json | 2 ++ roles/btcpay.rb | 2 ++ .../kosmos-bitcoin/attributes/default.rb | 7 ++++++ .../kosmos-bitcoin/recipes/btcpay.rb | 23 +++++++++++++++++++ .../kosmos-bitcoin/recipes/nbxplorer.rb | 23 +++++++++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb create mode 100644 site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb diff --git a/nodes/bitcoin-2.json b/nodes/bitcoin-2.json index eb83606..fc6a2c9 100644 --- a/nodes/bitcoin-2.json +++ b/nodes/bitcoin-2.json @@ -20,6 +20,8 @@ "kosmos-bitcoin::source", "kosmos-bitcoin::lnd", "kosmos-bitcoin::dotnet", + "kosmos-bitcoin::nbxplorer", + "kosmos-bitcoin::btcpay", "apt::default", "timezone_iii::default", "timezone_iii::debian", diff --git a/roles/btcpay.rb b/roles/btcpay.rb index 42017d8..05749c1 100644 --- a/roles/btcpay.rb +++ b/roles/btcpay.rb @@ -2,4 +2,6 @@ name "btcpay" run_list %w( kosmos-bitcoin::dotnet + kosmos-bitcoin::nbxplorer + kosmos-bitcoin::btcpay ) diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 29e39f5..c0d59b2 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -32,3 +32,10 @@ node.default['lnd']['source_dir'] = '/opt/lnd' node.default['dotnet']['ms_packages_src_url'] = "https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb" node.default['dotnet']['ms_packages_src_checksum'] = "4df5811c41fdded83eb9e2da9336a8dfa5594a79dc8a80133bd815f4f85b9991" +node.default['nbxplorer']['repo'] = 'https://github.com/dgarage/NBXplorer' +node.default['nbxplorer']['revision'] = 'latest' +node.default['nbxplorer']['source_dir'] = '/opt/nbxplorer' + +node.default['btcpay']['repo'] = 'https://github.com/btcpayserver/btcpayserver' +node.default['btcpay']['revision'] = 'latest' +node.default['btcpay']['source_dir'] = '/opt/btcpay' diff --git a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb new file mode 100644 index 0000000..bb91106 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb @@ -0,0 +1,23 @@ +# +# Cookbook:: kosmos-bitcoin +# Recipe:: btcpay +# + +build_essential + +include_recipe "git" + +git node['nbxplorer']['source_dir'] do + repository node['nbxplorer']['repo'] + revision node['nbxplorer']['revision'] + action :sync + notifies :run, 'bash[build_nbxplorer]', :immediately +end + +bash 'build_nbxplorer' do + cwd node['nbxplorer']['source_dir'] + code <<-EOH + ./build.sh + EOH + action :nothing +end diff --git a/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb b/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb new file mode 100644 index 0000000..7d80d3a --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb @@ -0,0 +1,23 @@ +# +# Cookbook:: kosmos-bitcoin +# Recipe:: btcpay +# + +build_essential + +include_recipe "git" + +git node['btcpay']['source_dir'] do + repository node['btcpay']['repo'] + revision node['btcpay']['revision'] + action :sync + notifies :run, 'bash[build_btcpay]', :immediately +end + +bash 'build_btcpay' do + cwd node['btcpay']['source_dir'] + code <<-EOH + ./build.sh + EOH + action :nothing +end From 5277bce20be662a80cef535e850d94250da35056 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 21 Dec 2020 11:14:19 +0100 Subject: [PATCH 204/327] Formatting --- site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb | 4 +--- site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb index bb91106..25cb6b5 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb @@ -16,8 +16,6 @@ end bash 'build_nbxplorer' do cwd node['nbxplorer']['source_dir'] - code <<-EOH - ./build.sh - EOH + code './build.sh' action :nothing end diff --git a/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb b/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb index 7d80d3a..e4e67a1 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb @@ -16,8 +16,6 @@ end bash 'build_btcpay' do cwd node['btcpay']['source_dir'] - code <<-EOH - ./build.sh - EOH + code './build.sh' action :nothing end From 570a692bb2f7c3e73d66245bdf013945de1314f7 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 21 Dec 2020 12:19:30 +0100 Subject: [PATCH 205/327] Configure and run nbxplorer --- .../kosmos-bitcoin/attributes/default.rb | 2 + .../kosmos-bitcoin/recipes/nbxplorer.rb | 55 +++++++++++++++++++ .../templates/nbxplorer-settings.config.erb | 5 ++ 3 files changed, 62 insertions(+) create mode 100644 site-cookbooks/kosmos-bitcoin/templates/nbxplorer-settings.config.erb diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index c0d59b2..6199ee3 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -35,6 +35,8 @@ node.default['dotnet']['ms_packages_src_checksum'] = "4df5811c41fdded83eb9e2da93 node.default['nbxplorer']['repo'] = 'https://github.com/dgarage/NBXplorer' node.default['nbxplorer']['revision'] = 'latest' node.default['nbxplorer']['source_dir'] = '/opt/nbxplorer' +node.default['nbxplorer']['config_path'] = "/home/#{node['bitcoin']['username']}/.nbxplorer/Main/settings.config" +node.default['nbxplorer']['port'] = '24445' node.default['btcpay']['repo'] = 'https://github.com/btcpayserver/btcpayserver' node.default['btcpay']['revision'] = 'latest' diff --git a/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb b/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb index e4e67a1..0200533 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb @@ -19,3 +19,58 @@ bash 'build_btcpay' do code './build.sh' action :nothing end + +bitcoin_credentials = Chef::EncryptedDataBagItem.load('credentials', 'bitcoin') + +directory File.dirname(node['nbxplorer']['config_path']) do + owner node['bitcoin']['username'] + group node['bitcoin']['usergroup'] + mode '0750' + recursive true +end + +template node['nbxplorer']['config_path'] do + source "nbxplorer-settings.config.erb" + owner node['bitcoin']['username'] + group node['bitcoin']['usergroup'] + mode '0640' + variables bitcoin_rpc_user: node['bitcoin']['conf']['rpcuser'], + bitcoin_rpc_password: bitcoin_credentials["rpcpassword"], + bitcoin_rpc_url: "http://#{node['bitcoin']['conf']['rpcbind']}", + nbxplorer_port: node['nbxplorer']['port'] +end + +directory '/run/nbxplorer' do + owner node['bitcoin']['username'] + group node['bitcoin']['usergroup'] + mode '0640' +end + +systemd_unit 'nbxplorer.service' do + content({ + Unit: { + Description: 'NBXplorer daemon', + Documentation: ['https://github.com/dgarage/NBXplorer'], + Requires: 'bitcoind.service', + After: 'bitcoind.service' + }, + Service: { + User: node['bitcoin']['username'], + Group: node['bitcoin']['usergroup'], + Type: 'simple', + ExecStart: "/usr/bin/dotnet '#{node['nbxplorer']['source_dir']}/NBXplorer/bin/Release/netcoreapp3.1/NBXplorer.dll' -c #{node['nbxplorer']['config_path']}", + PIDFile: "/run/nbxplorer/nbxplorer.pid", + Restart: 'on-failure', + PrivateTmp: true, + ProtectSystem: 'full', + NoNewPrivileges: true, + PrivateDevices: true + }, + Install: { + WantedBy: 'multi-user.target' + } + }) + verify false + triggers_reload true + action [:create, :enable, :start] +end diff --git a/site-cookbooks/kosmos-bitcoin/templates/nbxplorer-settings.config.erb b/site-cookbooks/kosmos-bitcoin/templates/nbxplorer-settings.config.erb new file mode 100644 index 0000000..b16efc9 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/templates/nbxplorer-settings.config.erb @@ -0,0 +1,5 @@ +btc.rpc.auth=<%= @bitcoin_rpc_user %>:<%= @bitcoin_rpc_password %> +btc.rpc.url=<%= @bitcoin_rpc_url %> +btc.node.endpoint=127.0.0.1:8333 +port=<%= @nbxplorer_port %> +mainnet=1 From ca373a15034a7f74861911de19b69c8829bc0de5 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 21 Dec 2020 12:25:13 +0100 Subject: [PATCH 206/327] Don't require auth cookie for nbxplorer API --- site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb b/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb index 0200533..0800c87 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb @@ -58,7 +58,7 @@ systemd_unit 'nbxplorer.service' do User: node['bitcoin']['username'], Group: node['bitcoin']['usergroup'], Type: 'simple', - ExecStart: "/usr/bin/dotnet '#{node['nbxplorer']['source_dir']}/NBXplorer/bin/Release/netcoreapp3.1/NBXplorer.dll' -c #{node['nbxplorer']['config_path']}", + ExecStart: "/usr/bin/dotnet '#{node['nbxplorer']['source_dir']}/NBXplorer/bin/Release/netcoreapp3.1/NBXplorer.dll' -c #{node['nbxplorer']['config_path']} --noauth", PIDFile: "/run/nbxplorer/nbxplorer.pid", Restart: 'on-failure', PrivateTmp: true, From bbd5500982eec01d397578f15ea9606dbc6285cb Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 21 Dec 2020 13:50:28 +0100 Subject: [PATCH 207/327] Configure and run BTCPay Server --- data_bags/credentials/btcpay.json | 10 +++ .../kosmos-bitcoin/attributes/default.rb | 6 ++ .../kosmos-bitcoin/recipes/btcpay.rb | 80 +++++++++++++++++-- .../kosmos-bitcoin/recipes/nbxplorer.rb | 23 ++++-- .../kosmos-bitcoin/recipes/source.rb | 1 + .../templates/btcpay-settings.config.erb | 8 ++ 6 files changed, 114 insertions(+), 14 deletions(-) create mode 100644 data_bags/credentials/btcpay.json create mode 100644 site-cookbooks/kosmos-bitcoin/templates/btcpay-settings.config.erb diff --git a/data_bags/credentials/btcpay.json b/data_bags/credentials/btcpay.json new file mode 100644 index 0000000..352f5f5 --- /dev/null +++ b/data_bags/credentials/btcpay.json @@ -0,0 +1,10 @@ +{ + "id": "btcpay", + "postgres_password": { + "encrypted_data": "sDiikAwXFqRCguREzzL0ybo33pl3CiSnJt5pqqnY7Q==\n", + "iv": "2qY/agvlvTJCGaj+\n", + "auth_tag": "kC5KmBBtlR0Yzi44WU5Ntw==\n", + "version": 3, + "cipher": "aes-256-gcm" + } +} \ No newline at end of file diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 6199ee3..f7336e9 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -41,3 +41,9 @@ node.default['nbxplorer']['port'] = '24445' node.default['btcpay']['repo'] = 'https://github.com/btcpayserver/btcpayserver' node.default['btcpay']['revision'] = 'latest' node.default['btcpay']['source_dir'] = '/opt/btcpay' +node.default['btcpay']['config_path'] = "/home/#{node['bitcoin']['username']}/.btcpayserver/Main/settings.config" +node.default['btcpay']['log_path'] = "/home/#{node['bitcoin']['username']}/.btcpayserver/debug.log" +node.default['btcpay']['port'] = '23001' +node.default['btcpay']['postgres']['port'] = 5432 +node.default['btcpay']['postgres']['database'] = 'btcpayserver' +node.default['btcpay']['postgres']['user'] = 'satoshi' diff --git a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb index 25cb6b5..3d15031 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb @@ -7,15 +7,83 @@ build_essential include_recipe "git" -git node['nbxplorer']['source_dir'] do - repository node['nbxplorer']['repo'] - revision node['nbxplorer']['revision'] +git node['btcpay']['source_dir'] do + repository node['btcpay']['repo'] + revision node['btcpay']['revision'] action :sync - notifies :run, 'bash[build_nbxplorer]', :immediately + notifies :run, 'bash[build_btcpay]', :immediately end -bash 'build_nbxplorer' do - cwd node['nbxplorer']['source_dir'] +bash 'build_btcpay' do + cwd node['btcpay']['source_dir'] code './build.sh' action :nothing end + +directory "/home/#{node['bitcoin']['username']}/.btcpayserver" do + owner node['bitcoin']['username'] + group node['bitcoin']['usergroup'] + mode '0750' + recursive true +end + +directory File.dirname(node['btcpay']['config_path']) do + owner node['bitcoin']['username'] + group node['bitcoin']['usergroup'] + mode '0750' + recursive true +end + +credentials = Chef::EncryptedDataBagItem.load('credentials', 'btcpay') + +template node['btcpay']['config_path'] do + source "btcpay-settings.config.erb" + owner node['bitcoin']['username'] + group node['bitcoin']['usergroup'] + mode '0640' + variables bitcoin_network: node['bitcoin']['network'], + nbxplorer_url: "http://127.0.0.1:#{node['nbxplorer']['port']}", + btcpay_port: node['btcpay']['port'], + btcpay_log_path: node['btcpay']['log_path'], + postgres_host: "192.168.122.1", + postgres_port: node['btcpay']['postgres']['port'], + postgres_database: node['btcpay']['postgres']['database'], + postgres_user: node['btcpay']['postgres']['user'], + postgres_password: credentials['postgres_password'] +end + +directory '/run/btcpayserver' do + owner node['bitcoin']['username'] + group node['bitcoin']['usergroup'] + mode '0640' +end + +systemd_unit 'btcpayserver.service' do + content({ + Unit: { + Description: 'BTCPay Server daemon', + Documentation: ['https://docs.btcpayserver.org/ManualDeployment/'], + Requires: 'nbxplorer.service', + After: 'nbxplorer.service' + }, + Service: { + User: node['bitcoin']['username'], + Group: node['bitcoin']['usergroup'], + Type: 'simple', + WorkingDirectory: node['btcpay']['source_dir'], + ExecStart: "#{node['btcpay']['source_dir']}/run.sh --conf=#{node['btcpay']['config_path']}", + PIDFile: '/run/btcpayserver/btcpayserver.pid', + Restart: 'on-failure', + PrivateTmp: true, + ProtectSystem: 'full', + NoNewPrivileges: true, + PrivateDevices: true + }, + Install: { + WantedBy: 'multi-user.target' + } + }) + verify false + triggers_reload true + action [:create, :enable, :start] +end diff --git a/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb b/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb index 0800c87..729e076 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb @@ -1,27 +1,34 @@ # # Cookbook:: kosmos-bitcoin -# Recipe:: btcpay +# Recipe:: nbxplorer # build_essential include_recipe "git" -git node['btcpay']['source_dir'] do - repository node['btcpay']['repo'] - revision node['btcpay']['revision'] +git node['nbxplorer']['source_dir'] do + repository node['nbxplorer']['repo'] + revision node['nbxplorer']['revision'] action :sync - notifies :run, 'bash[build_btcpay]', :immediately + notifies :run, 'bash[build_nbxplorer]', :immediately end -bash 'build_btcpay' do - cwd node['btcpay']['source_dir'] +bash 'build_nbxplorer' do + cwd node['nbxplorer']['source_dir'] code './build.sh' action :nothing end bitcoin_credentials = Chef::EncryptedDataBagItem.load('credentials', 'bitcoin') +directory "/home/#{node['bitcoin']['username']}/.nbxplorer" do + owner node['bitcoin']['username'] + group node['bitcoin']['usergroup'] + mode '0750' + recursive true +end + directory File.dirname(node['nbxplorer']['config_path']) do owner node['bitcoin']['username'] group node['bitcoin']['usergroup'] @@ -59,7 +66,7 @@ systemd_unit 'nbxplorer.service' do Group: node['bitcoin']['usergroup'], Type: 'simple', ExecStart: "/usr/bin/dotnet '#{node['nbxplorer']['source_dir']}/NBXplorer/bin/Release/netcoreapp3.1/NBXplorer.dll' -c #{node['nbxplorer']['config_path']} --noauth", - PIDFile: "/run/nbxplorer/nbxplorer.pid", + PIDFile: '/run/nbxplorer/nbxplorer.pid', Restart: 'on-failure', PrivateTmp: true, ProtectSystem: 'full', diff --git a/site-cookbooks/kosmos-bitcoin/recipes/source.rb b/site-cookbooks/kosmos-bitcoin/recipes/source.rb index cac64c4..34e138d 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/source.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/source.rb @@ -27,6 +27,7 @@ end build_essential include_recipe 'ark' + %w{ libtool autotools-dev make automake cmake curl g++-multilib libtool binutils-gold bsdmainutils pkg-config python3 patch }.each do |pkg| apt_package pkg diff --git a/site-cookbooks/kosmos-bitcoin/templates/btcpay-settings.config.erb b/site-cookbooks/kosmos-bitcoin/templates/btcpay-settings.config.erb new file mode 100644 index 0000000..fc6ed31 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/templates/btcpay-settings.config.erb @@ -0,0 +1,8 @@ +network=<%= @bitcoin_network %> +port=<%= @btcpay_port %> +bind=127.0.0.1 +chains=btc +BTC.explorer.url=<%= @nbxplorer_url %> +postgres=User ID=<%= @postgres_user %>;Password=<%= @postgres_password %>;Host=<%= @postgres_host %>;Port=<%= @postgres_port %>;Database=<%= @postgres_database %>; +debuglog=<%= @btcpay_log_path %> +<%# TODO BTC.lightning=type=clightning;server=/mnt/data/lightningd/lightning-rpc %> From f88354c67c7fcb0996d2d0e8c0326934d579166e Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 21 Dec 2020 16:53:22 +0100 Subject: [PATCH 208/327] Compile and install c-lightning --- nodes/bitcoin-2.json | 2 ++ .../kosmos-bitcoin/attributes/default.rb | 6 +++- .../kosmos-bitcoin/recipes/c-lightning.rb | 32 +++++++++++++++++++ site-cookbooks/kosmos-bitcoin/recipes/lnd.rb | 22 ------------- 4 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb diff --git a/nodes/bitcoin-2.json b/nodes/bitcoin-2.json index fc6a2c9..e873c80 100644 --- a/nodes/bitcoin-2.json +++ b/nodes/bitcoin-2.json @@ -18,6 +18,7 @@ "kosmos-base", "kosmos-base::default", "kosmos-bitcoin::source", + "kosmos-bitcoin::c-lightning", "kosmos-bitcoin::lnd", "kosmos-bitcoin::dotnet", "kosmos-bitcoin::nbxplorer", @@ -59,6 +60,7 @@ "run_list": [ "recipe[kosmos-base]", "recipe[kosmos-bitcoin::source]", + "recipe[kosmos-bitcoin::c-lightning]", "recipe[kosmos-bitcoin::lnd]", "role[btcpay]" ] diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index f7336e9..745055d 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -25,8 +25,12 @@ node.default['bitcoin']['conf'] = { zmqpubrawtx: 'tcp://127.0.0.1:8338' } +node.default['c-lightning']['repo'] = 'https://github.com/ElementsProject/lightning' +node.default['c-lightning']['revision'] = 'v0.9.2' +node.default['c-lightning']['source_dir'] = '/opt/c-lightning' + node.default['lnd']['repo'] = 'https://github.com/lightningnetwork/lnd' -node.default['lnd']['revision'] = 'v0.11.0-beta' +node.default['lnd']['revision'] = 'v0.11.1-beta' node.default['lnd']['source_dir'] = '/opt/lnd' node.default['dotnet']['ms_packages_src_url'] = "https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb" diff --git a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb new file mode 100644 index 0000000..209d4f7 --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb @@ -0,0 +1,32 @@ +# +# Cookbook:: kosmos-bitcoin +# Recipe:: c-lightning +# + +build_essential +include_recipe "git" + +%w{ + autoconf automake libtool libgmp-dev libsqlite3-dev + python3 python3-mako net-tools zlib1g-dev + libsodium-dev gettext +}.each do |pkg| + apt_package pkg +end + +git node['c-lightning']['source_dir'] do + repository node['c-lightning']['repo'] + revision node['c-lightning']['revision'] + action :sync + notifies :run, 'bash[compile_c-lightning]', :immediately +end + +bash "compile_c-lightning" do + cwd node['c-lightning']['source_dir'] + code <<-EOH + ./configure + make + make install + EOH + action :nothing +end diff --git a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb index 4708447..b730a8e 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb @@ -2,28 +2,6 @@ # Cookbook:: kosmos-bitcoin # Recipe:: lnd # -# 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 "git" include_recipe "golang" From 5892e3c0ab6c2ed3bcd70930ca6ce0526ddaaee7 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 22 Dec 2020 12:28:09 +0100 Subject: [PATCH 209/327] Configure and run c-lightning daemon --- .../kosmos-bitcoin/attributes/default.rb | 5 ++ .../kosmos-bitcoin/recipes/c-lightning.rb | 64 +++++++++++++++++++ .../templates/c-lightning.config.erb | 13 ++++ 3 files changed, 82 insertions(+) create mode 100644 site-cookbooks/kosmos-bitcoin/templates/c-lightning.config.erb diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 745055d..e5ba53a 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -28,6 +28,11 @@ node.default['bitcoin']['conf'] = { node.default['c-lightning']['repo'] = 'https://github.com/ElementsProject/lightning' node.default['c-lightning']['revision'] = 'v0.9.2' node.default['c-lightning']['source_dir'] = '/opt/c-lightning' +node.default['c-lightning']['lightning_dir'] = "/home/#{node['bitcoin']['username']}/.lightning" +node.default['c-lightning']['alias'] = 'ln3.kosmos.org' +node.default['c-lightning']['rgb'] = '0D4F99' +node.default['c-lightning']['log_level'] = 'info' +node.default['c-lightning']['public_ip'] = '148.251.237.73' node.default['lnd']['repo'] = 'https://github.com/lightningnetwork/lnd' node.default['lnd']['revision'] = 'v0.11.1-beta' diff --git a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb index 209d4f7..cb9f14d 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb @@ -29,4 +29,68 @@ bash "compile_c-lightning" do make install EOH action :nothing + notifies :restart, "systemd_unit[lightningd.service]", :delayed +end + +bitcoin_user = node['bitcoin']['username'] +bitcoin_group = node['bitcoin']['usergroup'] +lightning_dir = node['c-lightning']['lightning_dir'] + +bitcoin_credentials = Chef::EncryptedDataBagItem.load('credentials', 'bitcoin') + +directory lightning_dir do + owner bitcoin_user + group bitcoin_group + mode '0750' + action :create +end + +template "#{lightning_dir}/config" do + source "c-lightning.config.erb" + owner bitcoin_user + group bitcoin_group + mode '0640' + variables lighting_dir: lightning_dir, + lightning_alias: node['c-lightning']['alias'], + lightning_rgb: node['c-lightning']['rgb'], + lightning_log_level: node['c-lightning']['log_level'], + bitcoin_datadir: node['bitcoin']['datadir'], + bitcoin_rpc_user: node['bitcoin']['conf']['rpcuser'], + bitcoin_rpc_password: bitcoin_credentials["rpcpassword"], + bitcoin_rpc_host: node['bitcoin']['conf']['rpcbind'], + public_ip: node['c-lightning']['public_ip'] + notifies :restart, "systemd_unit[lightningd.service]", :delayed +end + +systemd_unit 'lightningd.service' do + content({ + Unit: { + Description: 'C-Lightning daemon', + Documentation: ['https://github.com/ElementsProject/lightning'], + Requires: 'bitcoind.service', + After: 'bitcoind.service' + }, + Service: { + User: node['bitcoin']['username'], + Group: node['bitcoin']['usergroup'], + Type: 'simple', + ExecStart: "/usr/local/bin/lightningd", + Restart: 'always', + RestartSec: '30', + TimeoutSec: '240', + RuntimeDirectory: 'lightningd', # /run/lightningd + RuntimeDirectoryMode: '0710', + PrivateTmp: true, + ProtectSystem: 'full', + NoNewPrivileges: true, + PrivateDevices: true, + MemoryDenyWriteExecute: true + }, + Install: { + WantedBy: 'multi-user.target' + } + }) + verify false + triggers_reload true + action [:create, :enable, :start] end diff --git a/site-cookbooks/kosmos-bitcoin/templates/c-lightning.config.erb b/site-cookbooks/kosmos-bitcoin/templates/c-lightning.config.erb new file mode 100644 index 0000000..7f9700e --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/templates/c-lightning.config.erb @@ -0,0 +1,13 @@ +network=bitcoin +bitcoin-datadir=<%= @bitcoin_datadir %> +alias=<%= @lightning_alias %> +rgb=<%= @lightning_rgb %> +bitcoin-rpcuser=<%= @bitcoin_rpc_user %> +bitcoin-rpcpassword=<%= @bitcoin_rpc_password %> +bitcoin-rpcconnect=<%= @bitcoin_rpc_host %> +log-level=<%= @lightning_log_level %> +bind-addr=0.0.0.0 +announce-addr=<%= @public_ip %> +disable-dns +<%# plugin=/home/satoshi/lightning-plugins/summary/summary.py %> +<%# plugin=/home/satoshi/lightning-plugins/rebalance/rebalance.py %> From 61accc05c2eae65be1bc75873b08291915ab9644 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 29 Dec 2020 15:56:53 +0100 Subject: [PATCH 210/327] Add nginx proxy for BTCPay --- nodes/bitcoin-2.json | 13 +++- .../kosmos-bitcoin/attributes/default.rb | 1 + site-cookbooks/kosmos-bitcoin/metadata.rb | 1 + .../kosmos-bitcoin/recipes/btcpay.rb | 24 +++++++ .../templates/nginx_conf_btcpayserver.erb | 70 +++++++++++++++++++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 site-cookbooks/kosmos-bitcoin/templates/nginx_conf_btcpayserver.erb diff --git a/nodes/bitcoin-2.json b/nodes/bitcoin-2.json index e873c80..60bc247 100644 --- a/nodes/bitcoin-2.json +++ b/nodes/bitcoin-2.json @@ -41,7 +41,18 @@ "kosmos-bitcoin::firewall", "git::default", "git::package", - "golang::default" + "golang::default", + "kosmos-nginx::default", + "nginx::default", + "nginx::package", + "nginx::ohai_plugin", + "nginx::repo", + "nginx::commons", + "nginx::commons_dir", + "nginx::commons_script", + "nginx::commons_conf", + "kosmos-nginx::firewall", + "kosmos-base::letsencrypt" ], "platform": "ubuntu", "platform_version": "20.04", diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index e5ba53a..e61fe0f 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -53,6 +53,7 @@ node.default['btcpay']['source_dir'] = '/opt/btcpay' node.default['btcpay']['config_path'] = "/home/#{node['bitcoin']['username']}/.btcpayserver/Main/settings.config" node.default['btcpay']['log_path'] = "/home/#{node['bitcoin']['username']}/.btcpayserver/debug.log" node.default['btcpay']['port'] = '23001' +node.default["btcpay"]["domain"] = 'btcpay.kosmos.org' node.default['btcpay']['postgres']['port'] = 5432 node.default['btcpay']['postgres']['database'] = 'btcpayserver' node.default['btcpay']['postgres']['user'] = 'satoshi' diff --git a/site-cookbooks/kosmos-bitcoin/metadata.rb b/site-cookbooks/kosmos-bitcoin/metadata.rb index a462885..992350f 100644 --- a/site-cookbooks/kosmos-bitcoin/metadata.rb +++ b/site-cookbooks/kosmos-bitcoin/metadata.rb @@ -22,3 +22,4 @@ chef_version '>= 14.0' depends 'ark' depends 'git' depends 'golang' +depends 'kosmos-nginx' diff --git a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb index 3d15031..dc0657b 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb @@ -87,3 +87,27 @@ systemd_unit 'btcpayserver.service' do triggers_reload true action [:create, :enable, :start] end + +# +# HTTPS Reverse Proxy +# + +include_recipe "kosmos-nginx" +server_name = node["btcpay"]["domain"] + +template "#{node["nginx"]["dir"]}/sites-available/#{server_name}" do + source "nginx_conf_btcpayserver.erb" + owner node["nginx"]["user"] + mode 0640 + variables btcpay_port: node["btcpay"]["port"], + server_name: server_name, + ssl_cert: "/etc/letsencrypt/live/#{server_name}/fullchain.pem", + ssl_key: "/etc/letsencrypt/live/#{server_name}/privkey.pem" + notifies :reload, "service[nginx]", :delayed +end + +nginx_site server_name do + action :enable +end + +nginx_certbot_site server_name diff --git a/site-cookbooks/kosmos-bitcoin/templates/nginx_conf_btcpayserver.erb b/site-cookbooks/kosmos-bitcoin/templates/nginx_conf_btcpayserver.erb new file mode 100644 index 0000000..bf17dab --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/templates/nginx_conf_btcpayserver.erb @@ -0,0 +1,70 @@ +<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%> +upstream _btcpayserver { + server localhost:<%= @btcpay_port %>; +} + +# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the +# scheme used to connect to this server +map $http_x_forwarded_proto $proxy_x_forwarded_proto { + default $http_x_forwarded_proto; + '' $scheme; +} + +# If we receive X-Forwarded-Port, pass it through; otherwise, pass along the +# server port the client connected to +map $http_x_forwarded_port $proxy_x_forwarded_port { + default $http_x_forwarded_port; + '' $server_port; +} + +# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any +# Connection header that may have been passed to this server +map $http_upgrade $proxy_connection { + default upgrade; + '' close; +} + +# Set appropriate X-Forwarded-Ssl header +map $scheme $proxy_x_forwarded_ssl { + default off; + https on; +} + +# HTTP 1.1 support +proxy_http_version 1.1; +proxy_buffering off; +proxy_set_header Host $http_host; +proxy_set_header Upgrade $http_upgrade; +proxy_set_header Connection $proxy_connection; +proxy_set_header X-Real-IP $remote_addr; +proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto; +proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl; +proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port; + +# Mitigate httpoxy attack +proxy_set_header Proxy ""; + +server { + client_max_body_size 100M; + server_name <%= @server_name %>; + listen 443 ssl http2; + + access_log <%= node[:nginx][:log_dir] %>/btcpayserver.access.log json; + error_log <%= node[:nginx][:log_dir] %>/btcpayserver.error.log warn; + + ssl_prefer_server_ciphers on; + ssl_session_timeout 5m; + ssl_session_cache shared:SSL:50m; + ssl_session_tickets off; + + ssl_certificate <%= @ssl_cert %>; + ssl_certificate_key <%= @ssl_key %>; + + add_header Strict-Transport-Security "max-age=15768000"; + + location / { + proxy_pass http://_btcpayserver; + } +} +<% end -%> From 3fcdc8b056f6af202b029f2f9e5e692c2b774483 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 30 Dec 2020 19:21:54 +0100 Subject: [PATCH 211/327] Configure and run LND --- .../kosmos-bitcoin/attributes/default.rb | 11 +++ .../kosmos-bitcoin/recipes/c-lightning.rb | 6 +- site-cookbooks/kosmos-bitcoin/recipes/lnd.rb | 74 +++++++++++++++++-- .../kosmos-bitcoin/templates/lnd.conf.erb | 28 +++++++ 4 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index e61fe0f..f87ed71 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -37,6 +37,17 @@ node.default['c-lightning']['public_ip'] = '148.251.237.73' node.default['lnd']['repo'] = 'https://github.com/lightningnetwork/lnd' node.default['lnd']['revision'] = 'v0.11.1-beta' node.default['lnd']['source_dir'] = '/opt/lnd' +node.default['lnd']['lnd_dir'] = "/home/#{node['bitcoin']['username']}/.lnd" +node.default['lnd']['alias'] = 'ln4.kosmos.org' +node.default['lnd']['color'] = '#5e0c99' +node.default['lnd']['log_level'] = 'info' +node.default['lnd']['public_ip'] = '148.251.237.111' +node.default['lnd']['port'] = '9736' +node.default['lnd']['minchansize'] = '1000000' +node.default['lnd']['basefee'] = '500' +node.default['lnd']['feerate'] = '1' +# node.default['lnd']['rpclisten'] = '127.0.0.1:10002' +# node.default['lnd']['restlisten'] = '127.0.0.1:8002' node.default['dotnet']['ms_packages_src_url'] = "https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb" node.default['dotnet']['ms_packages_src_checksum'] = "4df5811c41fdded83eb9e2da9336a8dfa5594a79dc8a80133bd815f4f85b9991" diff --git a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb index cb9f14d..1dd72e5 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb @@ -71,10 +71,10 @@ systemd_unit 'lightningd.service' do After: 'bitcoind.service' }, Service: { - User: node['bitcoin']['username'], - Group: node['bitcoin']['usergroup'], + User: bitcoin_user, + Group: bitcoin_group, Type: 'simple', - ExecStart: "/usr/local/bin/lightningd", + ExecStart: '/usr/local/bin/lightningd', Restart: 'always', RestartSec: '30', TimeoutSec: '240', diff --git a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb index b730a8e..b114e49 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb @@ -6,11 +6,6 @@ include_recipe "git" include_recipe "golang" -# bitcoin_user = node['bitcoin']['username'] -# bitcoin_group = node['bitcoin']['usergroup'] -# bitcoin_datadir = node['bitcoin']['datadir'] -# bitcoin_conf_path = node['bitcoin']['conf_path'] - git node['lnd']['source_dir'] do repository node['lnd']['repo'] revision node['lnd']['revision'] @@ -26,3 +21,72 @@ bash "compile_lnd" do EOH action :nothing end + +bitcoin_user = node['bitcoin']['username'] +bitcoin_group = node['bitcoin']['usergroup'] +lnd_dir = node['lnd']['lnd_dir'] + +bitcoin_credentials = Chef::EncryptedDataBagItem.load('credentials', 'bitcoin') + +directory lnd_dir do + owner bitcoin_user + group bitcoin_group + mode '0750' + action :create +end + +template "#{lnd_dir}/lnd.conf" do + source "lnd.conf.erb" + owner bitcoin_user + group bitcoin_group + mode '0640' + variables lnd_alias: node['lnd']['alias'], + lnd_color: node['lnd']['color'], + lnd_log_level: node['lnd']['log_level'], + lnd_public_ip: node['lnd']['public_ip'], + lnd_port: node['lnd']['port'], + lnd_minchansize: node['lnd']['minchansize'], + lnd_basefee: node['lnd']['basefee'], + lnd_feerate: node['lnd']['feerate'], + bitcoin_datadir: node['bitcoin']['datadir'], + bitcoin_rpc_user: node['bitcoin']['conf']['rpcuser'], + bitcoin_rpc_password: bitcoin_credentials["rpcpassword"], + bitcoin_rpc_host: node['bitcoin']['conf']['rpcbind'], + bitcoin_zmqpubrawblock: node['bitcoin']['conf']['zmqpubrawblock'], + bitcoin_zmqpubrawtx: node['bitcoin']['conf']['zmqpubrawtx'] + notifies :restart, "systemd_unit[lnd.service]", :delayed +end + +systemd_unit 'lnd.service' do + content({ + Unit: { + Description: 'Lightning Network Daemon', + Documentation: ['https://github.com/lightningnetwork/lnd/tree/master/docs'], + Requires: 'bitcoind.service', + After: 'bitcoind.service' + }, + Service: { + User: bitcoin_user, + Group: bitcoin_group, + Type: 'simple', + ExecStart: '/opt/go/bin/lnd', + Restart: 'always', + RestartSec: '30', + TimeoutSec: '240', + LimitNOFILE: '128000', + RuntimeDirectory: 'lnd', # /run/lnd + RuntimeDirectoryMode: '0710', + PrivateTmp: true, + ProtectSystem: 'full', + NoNewPrivileges: true, + PrivateDevices: true, + MemoryDenyWriteExecute: true + }, + Install: { + WantedBy: 'multi-user.target' + } + }) + verify false + triggers_reload true + action [:create, :enable, :start] +end diff --git a/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb b/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb new file mode 100644 index 0000000..ae9c29f --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb @@ -0,0 +1,28 @@ +[Application Options] +debuglevel=<%= @lnd_log_level %> +listen=0.0.0.0:<%= @lnd_port %> +; rpclisten=127.0.0.1:10002 +; restlisten=127.0.0.1:8002 +externalip=<%= @lnd_public_ip %>:<%= @lnd_port %> +alias=<%= @lnd_alias %> +color=<%= @lnd_color %> +maxpendingchannels=2 +minchansize=<%= @lnd_minchansize %> + +[autopilot] +autopilot.active=0 + +[Bitcoin] +bitcoin.active=1 +bitcoin.mainnet=1 +bitcoin.node=bitcoind +bitcoin.basefee=<%= @lnd_basefee %> +bitcoin.feerate=<%= @lnd_feerate %> + +[bitcoind] +bitcoind.dir=<%= @bitcoin_datadir %> +bitcoind.rpchost=<%= @bitcoin_rpc_host %> +bitcoind.rpcuser=<%= @bitcoin_rpc_user %> +bitcoind.rpcpass=<%= @bitcoin_rpc_password %> +bitcoind.zmqpubrawblock=<%= @bitcoin_zmqpubrawblock %> +bitcoind.zmqpubrawtx=<%= @bitcoin_zmqpubrawtx %> From 456639bdf8ac50489fb3b87a864c434271d07e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 31 Dec 2020 11:38:49 +0100 Subject: [PATCH 212/327] Fix a syntax error in certbot dirsrv hook The newline was not escaped and rendered as an actual newline Fixes #272 --- site-cookbooks/kosmos-dirsrv/resources/instance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-dirsrv/resources/instance.rb b/site-cookbooks/kosmos-dirsrv/resources/instance.rb index 55aafc4..8470e55 100644 --- a/site-cookbooks/kosmos-dirsrv/resources/instance.rb +++ b/site-cookbooks/kosmos-dirsrv/resources/instance.rb @@ -135,7 +135,7 @@ for domain in $RENEWED_DOMAINS; do pk12util -i #{Chef::Config[:file_cache_path]}/#{new_resource.hostname}.p12 -d #{inst_dir} -W '' # Remove the encryption key entries from the current database. # They will be recreated on restart for the new certificate - awk '! /^dn: cn=3D|AES,cn=encrypted attribute keys,cn=userRoot/ {print; printf "\n" ; }' RS="" #{inst_dir}/dse.ldif > #{inst_dir}/dse_new.ldif + awk '! /^dn: cn=3D|AES,cn=encrypted attribute keys,cn=userRoot/ {print; printf "\\n" ; }' RS="" #{inst_dir}/dse.ldif > #{inst_dir}/dse_new.ldif mv #{inst_dir}/dse_new.ldif #{inst_dir}/dse.ldif systemctl restart #{service_name} ;; From f5f234c0fddff530d9a05e869b7944286ddefba4 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 1 Jan 2021 14:13:17 +0100 Subject: [PATCH 213/327] Use name of existing node Migrated from andromeda to bitcoin-2. --- site-cookbooks/kosmos-bitcoin/attributes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index f87ed71..d877e5f 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -38,7 +38,7 @@ node.default['lnd']['repo'] = 'https://github.com/lightningnetwork/lnd' node.default['lnd']['revision'] = 'v0.11.1-beta' node.default['lnd']['source_dir'] = '/opt/lnd' node.default['lnd']['lnd_dir'] = "/home/#{node['bitcoin']['username']}/.lnd" -node.default['lnd']['alias'] = 'ln4.kosmos.org' +node.default['lnd']['alias'] = 'ln2.kosmos.org' node.default['lnd']['color'] = '#5e0c99' node.default['lnd']['log_level'] = 'info' node.default['lnd']['public_ip'] = '148.251.237.111' From 37f1fa79e71a5cc1c16b8c2e3beae87fc7826b11 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 1 Jan 2021 14:13:58 +0100 Subject: [PATCH 214/327] Use standard Lightning Network port for LND Only use the non-standard one internally, so we can run both c-lightning and lnd on the same machine. --- site-cookbooks/kosmos-bitcoin/attributes/default.rb | 1 + site-cookbooks/kosmos-bitcoin/recipes/lnd.rb | 2 +- site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index d877e5f..80d5af4 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -42,6 +42,7 @@ node.default['lnd']['alias'] = 'ln2.kosmos.org' node.default['lnd']['color'] = '#5e0c99' node.default['lnd']['log_level'] = 'info' node.default['lnd']['public_ip'] = '148.251.237.111' +node.default['lnd']['public_port'] = '9375' node.default['lnd']['port'] = '9736' node.default['lnd']['minchansize'] = '1000000' node.default['lnd']['basefee'] = '500' diff --git a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb index b114e49..71ef860 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb @@ -43,7 +43,7 @@ template "#{lnd_dir}/lnd.conf" do variables lnd_alias: node['lnd']['alias'], lnd_color: node['lnd']['color'], lnd_log_level: node['lnd']['log_level'], - lnd_public_ip: node['lnd']['public_ip'], + lnd_externalip: "#{node['lnd']['public_ip']}:#{node['lnd']['public_port']}", lnd_port: node['lnd']['port'], lnd_minchansize: node['lnd']['minchansize'], lnd_basefee: node['lnd']['basefee'], diff --git a/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb b/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb index ae9c29f..d912a79 100644 --- a/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb +++ b/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb @@ -3,7 +3,7 @@ debuglevel=<%= @lnd_log_level %> listen=0.0.0.0:<%= @lnd_port %> ; rpclisten=127.0.0.1:10002 ; restlisten=127.0.0.1:8002 -externalip=<%= @lnd_public_ip %>:<%= @lnd_port %> +externalip=<%= @lnd_externalip %> alias=<%= @lnd_alias %> color=<%= @lnd_color %> maxpendingchannels=2 From 19e3dfa7b90bfd075b1817e992e6a5940939fd29 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 1 Jan 2021 14:14:59 +0100 Subject: [PATCH 215/327] Remove obsolete non-standard RPC and REST ports We'll just run those on default ports without custom config. --- site-cookbooks/kosmos-bitcoin/attributes/default.rb | 2 -- site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb | 2 -- 2 files changed, 4 deletions(-) diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 80d5af4..a16f92c 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -47,8 +47,6 @@ node.default['lnd']['port'] = '9736' node.default['lnd']['minchansize'] = '1000000' node.default['lnd']['basefee'] = '500' node.default['lnd']['feerate'] = '1' -# node.default['lnd']['rpclisten'] = '127.0.0.1:10002' -# node.default['lnd']['restlisten'] = '127.0.0.1:8002' node.default['dotnet']['ms_packages_src_url'] = "https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb" node.default['dotnet']['ms_packages_src_checksum'] = "4df5811c41fdded83eb9e2da9336a8dfa5594a79dc8a80133bd815f4f85b9991" diff --git a/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb b/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb index d912a79..b96f7d8 100644 --- a/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb +++ b/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb @@ -1,8 +1,6 @@ [Application Options] debuglevel=<%= @lnd_log_level %> listen=0.0.0.0:<%= @lnd_port %> -; rpclisten=127.0.0.1:10002 -; restlisten=127.0.0.1:8002 externalip=<%= @lnd_externalip %> alias=<%= @lnd_alias %> color=<%= @lnd_color %> From 2b765e744aaa5cd8a071c60b1bd2651bb24c0f8d Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 1 Jan 2021 17:38:15 +0100 Subject: [PATCH 216/327] Configure and run RTL Ride The Lightning is a Web UI for Lightning Network nodes. It is accessible via the bitcoin VM's private zerotier IP on port 3000. --- data_bags/credentials/rtl.json | 10 ++ nodes/bitcoin-2.json | 7 ++ .../kosmos-bitcoin/attributes/default.rb | 5 + site-cookbooks/kosmos-bitcoin/metadata.rb | 7 +- .../kosmos-bitcoin/recipes/c-lightning.rb | 2 - site-cookbooks/kosmos-bitcoin/recipes/lnd.rb | 3 +- site-cookbooks/kosmos-bitcoin/recipes/rtl.rb | 110 ++++++++++++++++++ 7 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 data_bags/credentials/rtl.json create mode 100644 site-cookbooks/kosmos-bitcoin/recipes/rtl.rb diff --git a/data_bags/credentials/rtl.json b/data_bags/credentials/rtl.json new file mode 100644 index 0000000..fcf28ba --- /dev/null +++ b/data_bags/credentials/rtl.json @@ -0,0 +1,10 @@ +{ + "id": "rtl", + "multiPassHashed": { + "encrypted_data": "Kg84dRDmB91Yq5vRwmgBf6CikZQYtQdJrVSgF2Ka8KDAbi2hjFvJMaBWJazl\nJWung87YbwszuqA0eN7fCoTsG70N/lJhfTv0NOArD1Jq+BPxQeM=\n", + "iv": "Fc6bk+8wqcs+kuhw\n", + "auth_tag": "QApw1XUQy+YxYTN9Xj/WEQ==\n", + "version": 3, + "cipher": "aes-256-gcm" + } +} \ No newline at end of file diff --git a/nodes/bitcoin-2.json b/nodes/bitcoin-2.json index 60bc247..c99a571 100644 --- a/nodes/bitcoin-2.json +++ b/nodes/bitcoin-2.json @@ -20,6 +20,7 @@ "kosmos-bitcoin::source", "kosmos-bitcoin::c-lightning", "kosmos-bitcoin::lnd", + "kosmos-bitcoin::rtl", "kosmos-bitcoin::dotnet", "kosmos-bitcoin::nbxplorer", "kosmos-bitcoin::btcpay", @@ -42,6 +43,11 @@ "git::default", "git::package", "golang::default", + "kosmos-nodejs::default", + "nodejs::nodejs_from_package", + "nodejs::repo", + "firewall::default", + "chef-sugar::default", "kosmos-nginx::default", "nginx::default", "nginx::package", @@ -73,6 +79,7 @@ "recipe[kosmos-bitcoin::source]", "recipe[kosmos-bitcoin::c-lightning]", "recipe[kosmos-bitcoin::lnd]", + "recipe[kosmos-bitcoin::rtl]", "role[btcpay]" ] } \ No newline at end of file diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index a16f92c..dc11a70 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -48,6 +48,11 @@ node.default['lnd']['minchansize'] = '1000000' node.default['lnd']['basefee'] = '500' node.default['lnd']['feerate'] = '1' +node.default['rtl']['repo'] = 'https://github.com/Ride-The-Lightning/RTL.git' +node.default['rtl']['revision'] = 'v0.10.0' +node.default['rtl']['host'] = '10.1.1.163' +node.default['rtl']['port'] = '3000' + node.default['dotnet']['ms_packages_src_url'] = "https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb" node.default['dotnet']['ms_packages_src_checksum'] = "4df5811c41fdded83eb9e2da9336a8dfa5594a79dc8a80133bd815f4f85b9991" diff --git a/site-cookbooks/kosmos-bitcoin/metadata.rb b/site-cookbooks/kosmos-bitcoin/metadata.rb index 992350f..fe6cd0c 100644 --- a/site-cookbooks/kosmos-bitcoin/metadata.rb +++ b/site-cookbooks/kosmos-bitcoin/metadata.rb @@ -2,8 +2,8 @@ name 'kosmos-bitcoin' maintainer 'Kosmos Developers' maintainer_email 'mail@kosmos.org' license 'MIT' -description 'Installs/Configures Bitcoin Core' -long_description 'Installs/Configures Bitcoin Core' +description 'Installs/configures bitcoin-related software' +long_description 'Installs/configures bitcoin-related software' version '0.1.0' chef_version '>= 14.0' @@ -23,3 +23,6 @@ depends 'ark' depends 'git' depends 'golang' depends 'kosmos-nginx' +depends 'kosmos-nodejs' +depends 'firewall' +depends 'application_javascript' diff --git a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb index 1dd72e5..b86b184 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb @@ -78,8 +78,6 @@ systemd_unit 'lightningd.service' do Restart: 'always', RestartSec: '30', TimeoutSec: '240', - RuntimeDirectory: 'lightningd', # /run/lightningd - RuntimeDirectoryMode: '0710', PrivateTmp: true, ProtectSystem: 'full', NoNewPrivileges: true, diff --git a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb index 71ef860..b179c42 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb @@ -20,6 +20,7 @@ bash "compile_lnd" do make clean && make && make install EOH action :nothing + notifies :restart, "systemd_unit[lnd.service]", :delayed end bitcoin_user = node['bitcoin']['username'] @@ -74,8 +75,6 @@ systemd_unit 'lnd.service' do RestartSec: '30', TimeoutSec: '240', LimitNOFILE: '128000', - RuntimeDirectory: 'lnd', # /run/lnd - RuntimeDirectoryMode: '0710', PrivateTmp: true, ProtectSystem: 'full', NoNewPrivileges: true, diff --git a/site-cookbooks/kosmos-bitcoin/recipes/rtl.rb b/site-cookbooks/kosmos-bitcoin/recipes/rtl.rb new file mode 100644 index 0000000..31b619e --- /dev/null +++ b/site-cookbooks/kosmos-bitcoin/recipes/rtl.rb @@ -0,0 +1,110 @@ +# +# Cookbook:: kosmos-bitcoin +# Recipe:: rtl +# + +include_recipe 'kosmos-nodejs' + +app_name = "rtl" +rtl_dir = "/opt/#{app_name}" +lnd_dir = node['lnd']['lnd_dir'] +bitcoin_user = node['bitcoin']['username'] +bitcoin_group = node['bitcoin']['usergroup'] +credentials = Chef::EncryptedDataBagItem.load('credentials', 'rtl') + +rtl_config = { + host: node['rtl']['host'], + port: node['rtl']['port'], + defaultNodeIndex: 1, + SSO: { + rtlSSO: 0, + rtlCookiePath: "", + logoutRedirectLink: "" + }, + nodes: [ + { + index: 1, + lnNode: node['lnd']['alias'], + lnImplementation: "LND", + Authentication: { + macaroonPath: "#{lnd_dir}/data/chain/bitcoin/mainnet", + configPath: "#{lnd_dir}/lnd.conf" + }, + Settings: { + userPersona: "MERCHANT", + themeMode: "NIGHT", + themeColor: "TEAL", + channelBackupPath: "", + enableLogging: true, + lnServerUrl: "https://localhost:8080", + fiatConversion: true, + currencyUnit: "EUR" + } + } + ], + multiPassHashed: credentials["multiPassHashed"] +}.to_json + +application rtl_dir do + owner bitcoin_user + group bitcoin_group + + git do + user bitcoin_user + group bitcoin_group + repository node['rtl']['repo'] + revision node['rtl']['revision'] + notifies :restart, "systemd_unit[rtl.service]", :delayed + end + + npm_install do + user bitcoin_user + end + + file "#{rtl_dir}/RTL-Config.json" do + owner bitcoin_user + group bitcoin_group + mode '0640' + content rtl_config + notifies :restart, "systemd_unit[rtl.service]", :delayed + end + + systemd_unit 'rtl.service' do + content({ + Unit: { + Description: 'Ride The Lightning', + Documentation: ['https://github.com/Ride-The-Lightning/RTL'], + Requires: 'lnd.service', + After: 'lnd.service' + }, + Service: { + User: bitcoin_user, + Group: bitcoin_group, + Type: 'simple', + # ExecStartPre: '/bin/sleep 120', + ExecStart: "/usr/bin/node #{rtl_dir}/rtl.js", + Restart: 'always', + RestartSec: '30', + TimeoutSec: '120', + PrivateTmp: true, + ProtectSystem: 'full', + NoNewPrivileges: true, + PrivateDevices: true, + }, + Install: { + WantedBy: 'multi-user.target' + } + }) + verify false + triggers_reload true + action [:create, :enable, :start] + end +end + +include_recipe 'firewall' +firewall_rule 'rtl_private' do + port node['rtl']['port'].to_i + source "10.1.1.0/24" + protocol :tcp + command :allow +end From adfd76aa64d72d2dfe8c6a706a3744e8abb713ad Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 2 Jan 2021 09:59:50 +0100 Subject: [PATCH 217/327] Configure local LND as Lightning node in BTCPay Server --- site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb | 7 ++++++- .../kosmos-bitcoin/templates/btcpay-settings.config.erb | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb index dc0657b..ac864dc 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb @@ -18,6 +18,7 @@ bash 'build_btcpay' do cwd node['btcpay']['source_dir'] code './build.sh' action :nothing + notifies :restart, "systemd_unit[btcpayserver.service]", :delayed end directory "/home/#{node['bitcoin']['username']}/.btcpayserver" do @@ -36,6 +37,8 @@ end credentials = Chef::EncryptedDataBagItem.load('credentials', 'btcpay') +lnd_admin_macaroon_path = "#{node['lnd']['lnd_dir']}/data/chain/bitcoin/mainnet/admin.macaroon" rescue nil + template node['btcpay']['config_path'] do source "btcpay-settings.config.erb" owner node['bitcoin']['username'] @@ -49,7 +52,9 @@ template node['btcpay']['config_path'] do postgres_port: node['btcpay']['postgres']['port'], postgres_database: node['btcpay']['postgres']['database'], postgres_user: node['btcpay']['postgres']['user'], - postgres_password: credentials['postgres_password'] + postgres_password: credentials['postgres_password'], + lnd_admin_macaroon_path: lnd_admin_macaroon_path + notifies :restart, "systemd_unit[btcpayserver.service]", :delayed end directory '/run/btcpayserver' do diff --git a/site-cookbooks/kosmos-bitcoin/templates/btcpay-settings.config.erb b/site-cookbooks/kosmos-bitcoin/templates/btcpay-settings.config.erb index fc6ed31..8bdbf55 100644 --- a/site-cookbooks/kosmos-bitcoin/templates/btcpay-settings.config.erb +++ b/site-cookbooks/kosmos-bitcoin/templates/btcpay-settings.config.erb @@ -2,7 +2,9 @@ network=<%= @bitcoin_network %> port=<%= @btcpay_port %> bind=127.0.0.1 chains=btc -BTC.explorer.url=<%= @nbxplorer_url %> postgres=User ID=<%= @postgres_user %>;Password=<%= @postgres_password %>;Host=<%= @postgres_host %>;Port=<%= @postgres_port %>;Database=<%= @postgres_database %>; debuglog=<%= @btcpay_log_path %> -<%# TODO BTC.lightning=type=clightning;server=/mnt/data/lightningd/lightning-rpc %> +BTC.explorer.url=<%= @nbxplorer_url %> +<% if @lnd_admin_macaroon_path %> +BTC.lightning=type=lnd-rest;server=https://127.0.0.1:8080/;macaroonfilepath=<%= @lnd_admin_macaroon_path %>;allowinsecure=true +<% end %> From ddded6fbaed0b2af69435d27f81aa68a92fbc140 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 5 Jan 2021 11:30:31 +0100 Subject: [PATCH 218/327] Create new nodejs VM, move kredits-github to it --- clients/nodejs-2.json | 4 ++ nodes/barnard.kosmos.org.json | 1 - nodes/{nodejs-1.json => nodejs-2.json} | 44 +++++++++++++------ .../kredits-github/attributes/default.rb | 6 +-- 4 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 clients/nodejs-2.json rename nodes/{nodejs-1.json => nodejs-2.json} (55%) diff --git a/clients/nodejs-2.json b/clients/nodejs-2.json new file mode 100644 index 0000000..c763933 --- /dev/null +++ b/clients/nodejs-2.json @@ -0,0 +1,4 @@ +{ + "name": "nodejs-2", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuWyrBQXathrKzRO7HbX7\nZXqkeGo7X0q3qckO/Uh4Ht67bFb6iQDRo/gRkaVA0PM++2AhtW7wV2NYXR/3qowc\n1gGtO0zuQq56crcL7k9nVuFJ1IbYDyasEq+5nUKzEUVT0hK1/Vzh12gLFhDkBOX+\nCvISLTTQgEGljwNQLf1kZTraJcdDSN0R2k2jl+idJkeAuK5cjMEJa7Fog8scM2rR\nzGhB8gDRp+iq4HQ+yE3R1yXW9rBfWoConnXiNxholt3e2aAte2V1KnEmVLO/8ceo\nvqIp5xEcDKIAIrSqsmopRFXJ0PjS/nbS0Z2ynxpyh1BV4sqr/y4oOryrnwO+LqBB\nHwIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/barnard.kosmos.org.json b/nodes/barnard.kosmos.org.json index 4ee09fc..efddfab 100644 --- a/nodes/barnard.kosmos.org.json +++ b/nodes/barnard.kosmos.org.json @@ -103,7 +103,6 @@ }, "run_list": [ "role[base]", - "role[kredits_github]", "recipe[kosmos-ipfs]", "recipe[kosmos-hubot::botka_freenode]", "recipe[kosmos-hubot::hal8000]", diff --git a/nodes/nodejs-1.json b/nodes/nodejs-2.json similarity index 55% rename from nodes/nodejs-1.json rename to nodes/nodejs-2.json index c51a42b..cc7861e 100644 --- a/nodes/nodejs-1.json +++ b/nodes/nodejs-2.json @@ -1,22 +1,25 @@ { - "name": "nodejs-1", + "name": "nodejs-2", "normal": { "knife_zero": { - "host": "10.1.1.3" + "host": "10.1.1.229" } }, "automatic": { - "fqdn": "nodejs-1", + "fqdn": "nodejs-2", "os": "linux", - "os_version": "5.4.0-1028-kvm", - "hostname": "nodejs-1", - "ipaddress": "192.168.122.57", + "os_version": "5.4.0-1031-kvm", + "hostname": "nodejs-2", + "ipaddress": "192.168.122.243", "roles": [ - + "kredits_github" ], "recipes": [ "kosmos-base", "kosmos-base::default", + "kredits-github", + "kredits-github::default", + "kredits-github::nginx", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -30,23 +33,38 @@ "postfix::_common", "postfix::_attributes", "postfix::sasl_auth", - "hostname::default" + "hostname::default", + "kosmos-nodejs::default", + "nodejs::nodejs_from_package", + "nodejs::repo", + "kosmos-nginx::default", + "nginx::default", + "nginx::package", + "nginx::ohai_plugin", + "nginx::repo", + "nginx::commons", + "nginx::commons_dir", + "nginx::commons_script", + "nginx::commons_conf", + "kosmos-nginx::firewall", + "kosmos-base::letsencrypt" ], "platform": "ubuntu", "platform_version": "20.04", "cloud": null, "chef_packages": { - "chef": { - "version": "15.14.0", - "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib" - }, "ohai": { "version": "15.12.0", "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + }, + "chef": { + "version": "15.14.0", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib" } } }, "run_list": [ - "recipe[kosmos-base]" + "recipe[kosmos-base]", + "role[kredits_github]" ] } \ No newline at end of file diff --git a/site-cookbooks/kredits-github/attributes/default.rb b/site-cookbooks/kredits-github/attributes/default.rb index d024a64..686cb01 100644 --- a/site-cookbooks/kredits-github/attributes/default.rb +++ b/site-cookbooks/kredits-github/attributes/default.rb @@ -1,3 +1,3 @@ -node.default['kredits-github']['port'] = '3000' -node.default['kredits-github']['revision'] = 'master' -node.default['kredits-github']['domain'] = 'kredits-github.kosmos.org' +node.default['kredits-github']['port'] = '3000' +node.default['kredits-github']['revision'] = 'master' +node.default['kredits-github']['domain'] = 'kredits-github.kosmos.org' From fe63f01f7be50d270c213042b5d9b30395aa25d3 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 5 Jan 2021 18:03:15 +0100 Subject: [PATCH 219/327] Move wormhole from barnard to nodejs-2 Fixed two small bugs in the recipe: * hubot user wasn't created when necessary * systemd template always included redis service dependency --- nodes/barnard.kosmos.org.json | 1 - nodes/nodejs-2.json | 3 ++- site-cookbooks/kosmos-hubot/recipes/wormhole.rb | 3 +++ .../kosmos-hubot/templates/default/nodejs.systemd.service.erb | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/nodes/barnard.kosmos.org.json b/nodes/barnard.kosmos.org.json index efddfab..fea3485 100644 --- a/nodes/barnard.kosmos.org.json +++ b/nodes/barnard.kosmos.org.json @@ -107,7 +107,6 @@ "recipe[kosmos-hubot::botka_freenode]", "recipe[kosmos-hubot::hal8000]", "recipe[kosmos-hubot::hal8000_xmpp]", - "recipe[kosmos-hubot::wormhole]", "recipe[sockethub]", "recipe[sockethub::proxy]", "recipe[kosmos-dirsrv]" diff --git a/nodes/nodejs-2.json b/nodes/nodejs-2.json index cc7861e..b5c676c 100644 --- a/nodes/nodejs-2.json +++ b/nodes/nodejs-2.json @@ -65,6 +65,7 @@ }, "run_list": [ "recipe[kosmos-base]", + "recipe[kosmos-hubot::wormhole]", "role[kredits_github]" ] -} \ No newline at end of file +} diff --git a/site-cookbooks/kosmos-hubot/recipes/wormhole.rb b/site-cookbooks/kosmos-hubot/recipes/wormhole.rb index 40063a9..c10d64d 100644 --- a/site-cookbooks/kosmos-hubot/recipes/wormhole.rb +++ b/site-cookbooks/kosmos-hubot/recipes/wormhole.rb @@ -32,6 +32,7 @@ build_essential app_name do end include_recipe "kosmos-nodejs" +include_recipe "kosmos-hubot::_user" application app_path do data_bag = Chef::EncryptedDataBagItem.load('credentials', app_name) @@ -62,6 +63,7 @@ application app_path do action :nothing end + # TODO use chef systemd_service resource template "/lib/systemd/system/#{app_name}.service" do source 'nodejs.systemd.service.erb' owner 'root' @@ -70,6 +72,7 @@ application app_path do variables( user: app_user, group: app_group, + without_redis: true, app_dir: app_path, entry: "#{app_path}/bin/hubot -a irc --name #{app_name}", environment: { diff --git a/site-cookbooks/kosmos-hubot/templates/default/nodejs.systemd.service.erb b/site-cookbooks/kosmos-hubot/templates/default/nodejs.systemd.service.erb index 8dc98a9..8e27347 100644 --- a/site-cookbooks/kosmos-hubot/templates/default/nodejs.systemd.service.erb +++ b/site-cookbooks/kosmos-hubot/templates/default/nodejs.systemd.service.erb @@ -1,7 +1,9 @@ [Unit] Description=Start nodejs app +<% unless @without_redis %> Requires=redis-server.service After=redis-server.service +<% end %> [Service] ExecStart=<%= @entry %> From eb4764026b51035c280e6c305efbe2cab29eb56f Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 6 Jan 2021 11:27:50 +0100 Subject: [PATCH 220/327] Add script for notifying Kosmos channels from Ruby An example for notifying Kosmos XMPP channels from plain Ruby, with no dependencies. --- scripts/util/notify_xmpp.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 scripts/util/notify_xmpp.rb diff --git a/scripts/util/notify_xmpp.rb b/scripts/util/notify_xmpp.rb new file mode 100644 index 0000000..c481e7a --- /dev/null +++ b/scripts/util/notify_xmpp.rb @@ -0,0 +1,15 @@ +require 'uri' +require 'net/http' +require 'json' + +WEBHOOK_TOKEN = "foo" + +def send_notification(msg) + uri = URI.parse('https://hal8000.chat.kosmos.org/incoming/#{WEBHOOK_TOKEN}') + https = Net::HTTP.new(uri.host, uri.port) + https.use_ssl = true + request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json') + request.body = { room: "ops@kosmos.chat", message: msg }.to_json + response = https.request(request) + puts response.inspect +end From 1eb73711a2c510a91449be6a4020117627521aed Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 6 Jan 2021 19:12:36 +0100 Subject: [PATCH 221/327] Remove application_javascript usage from wormhole recipe --- nodes/nodejs-2.json | 6 +- .../kosmos-hubot/attributes/default.rb | 5 +- site-cookbooks/kosmos-hubot/metadata.rb | 1 + .../kosmos-hubot/recipes/wormhole.rb | 155 ++++++++---------- 4 files changed, 80 insertions(+), 87 deletions(-) diff --git a/nodes/nodejs-2.json b/nodes/nodejs-2.json index b5c676c..17fcf80 100644 --- a/nodes/nodejs-2.json +++ b/nodes/nodejs-2.json @@ -17,6 +17,7 @@ "recipes": [ "kosmos-base", "kosmos-base::default", + "kosmos-hubot::wormhole", "kredits-github", "kredits-github::default", "kredits-github::nginx", @@ -37,6 +38,9 @@ "kosmos-nodejs::default", "nodejs::nodejs_from_package", "nodejs::repo", + "kosmos-hubot::_user", + "git::default", + "git::package", "kosmos-nginx::default", "nginx::default", "nginx::package", @@ -68,4 +72,4 @@ "recipe[kosmos-hubot::wormhole]", "role[kredits_github]" ] -} +} \ No newline at end of file diff --git a/site-cookbooks/kosmos-hubot/attributes/default.rb b/site-cookbooks/kosmos-hubot/attributes/default.rb index 49c7a2e..9172f36 100644 --- a/site-cookbooks/kosmos-hubot/attributes/default.rb +++ b/site-cookbooks/kosmos-hubot/attributes/default.rb @@ -6,6 +6,8 @@ node.default['botka_freenode']['domain'] = "freenode.botka.kosmos.org" node.default['hal8000_xmpp']['http_port'] = 8082 node.default['hal8000_xmpp']['domain'] = "hal8000.chat.kosmos.org" +node.default['wormhole']['http_port'] = 8083 + node.default['hal8000_xmpp']['hubot_scripts'] = [ "hubot-help", "hubot-redis-brain", "hubot-rules", "hubot-shipit", "hubot-plusplus", "hubot-tell", "hubot-seen", "hubot-incoming-webhook", @@ -16,7 +18,8 @@ node.default['hal8000_xmpp']['rooms'] = [ 'kosmos@kosmos.chat', 'kosmos-dev@kosmos.chat', 'kredits@kosmos.chat', - 'info@kosmos.chat' + 'info@kosmos.chat', + 'ops@kosmos.chat', ] node.default['hal8000_xmpp']['auth_admins'] = [] diff --git a/site-cookbooks/kosmos-hubot/metadata.rb b/site-cookbooks/kosmos-hubot/metadata.rb index d606c40..0bca208 100644 --- a/site-cookbooks/kosmos-hubot/metadata.rb +++ b/site-cookbooks/kosmos-hubot/metadata.rb @@ -11,3 +11,4 @@ depends 'kosmos-redis' depends 'firewall' depends 'application_javascript' depends 'kosmos-ipfs' +depends 'git' diff --git a/site-cookbooks/kosmos-hubot/recipes/wormhole.rb b/site-cookbooks/kosmos-hubot/recipes/wormhole.rb index c10d64d..f502ee6 100644 --- a/site-cookbooks/kosmos-hubot/recipes/wormhole.rb +++ b/site-cookbooks/kosmos-hubot/recipes/wormhole.rb @@ -2,100 +2,85 @@ # Cookbook Name:: kosmos-hubot # Recipe:: wormhole # -# Copyright:: 2019, 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. -# + app_name = "wormhole" -app_path = "/opt/#{app_name}" app_user = "hubot" app_group = "hubot" +app_path = "/opt/#{app_name}" +data_bag = Chef::EncryptedDataBagItem.load('credentials', app_name) -build_essential app_name do - compile_time true -end +app_env = { + "HUBOT_LOG_LEVEL" => node.chef_environment == "development" ? "debug" : "info", + "HUBOT_IRC_SERVER" => "irc.freenode.net", + "HUBOT_IRC_ROOMS" => "#kosmos,#kosmos-dev,#kosmos-random,#sockethub", + "HUBOT_IRC_NICK" => app_name, + "HUBOT_IRC_NICKSERV_USERNAME" => app_name, + "HUBOT_IRC_NICKSERV_PASSWORD" => data_bag['nickserv_password'], + "HUBOT_IRC_UNFLOOD" => "100", + "HUBOT_WORMHOLE_XMPP_JID" => "wormhole@kosmos.org", + "HUBOT_WORMHOLE_XMPP_PASSWORD" => data_bag['xmpp_password'], + "HUBOT_WORMHOLE_XMPP_HOST" => "xmpp.kosmos.org", + "HUBOT_WORMHOLE_XMPP_PORT" => "5222", + "HUBOT_WORMHOLE_XMPP_NICKNAME" => "wormhole", + "HUBOT_WORMHOLE_XMPP_ROOMS" => "kosmos@kosmos.chat,kosmos-dev@kosmos.chat,kosmos-random@kosmos.chat,sockethub@kosmos.chat", + "EXPRESS_PORT" => node['wormhole']['http_port'] +} +build_essential include_recipe "kosmos-nodejs" include_recipe "kosmos-hubot::_user" +include_recipe "git" -application app_path do - data_bag = Chef::EncryptedDataBagItem.load('credentials', app_name) +git app_path do + user app_user + group app_group + repository "https://gitea.kosmos.org/kosmos/wormhole.git" + revision "master" + action :sync + notifies :run, "bash[npm_install_#{app_name}]", :immediately + notifies :restart, "systemd_unit[#{app_name}.service]", :delayed +end +bash "npm_install_#{app_name}" do + user app_user + cwd app_path + code 'npm install' + action :nothing +end + +file "#{app_path}/external-scripts.json" do + mode "0640" owner app_user group app_group - - git do - user app_user - group app_group - repository "https://gitea.kosmos.org/kosmos/wormhole.git" - revision "master" - end - - file "#{app_path}/external-scripts.json" do - mode "0640" - owner app_user - group app_group - content [].to_json - end - - npm_install do - user app_user - end - - execute "systemctl daemon-reload" do - command "systemctl daemon-reload" - action :nothing - end - - # TODO use chef systemd_service resource - template "/lib/systemd/system/#{app_name}.service" do - source 'nodejs.systemd.service.erb' - owner 'root' - group 'root' - mode '0644' - variables( - user: app_user, - group: app_group, - without_redis: true, - app_dir: app_path, - entry: "#{app_path}/bin/hubot -a irc --name #{app_name}", - environment: { - "HUBOT_LOG_LEVEL" => node.chef_environment == "development" ? "debug" : "info", - "HUBOT_IRC_SERVER" => "irc.freenode.net", - "HUBOT_IRC_ROOMS" => "#kosmos,#kosmos-dev,#kosmos-random,#sockethub", - "HUBOT_IRC_NICK" => app_name, - "HUBOT_IRC_NICKSERV_USERNAME" => app_name, - "HUBOT_IRC_NICKSERV_PASSWORD" => data_bag['nickserv_password'], - "HUBOT_IRC_UNFLOOD" => "100", - "HUBOT_WORMHOLE_XMPP_JID" => "wormhole@kosmos.org", - "HUBOT_WORMHOLE_XMPP_PASSWORD" => data_bag['xmpp_password'], - "HUBOT_WORMHOLE_XMPP_HOST" => "xmpp.kosmos.org", - "HUBOT_WORMHOLE_XMPP_PORT" => "5222", - "HUBOT_WORMHOLE_XMPP_NICKNAME" => "wormhole", - "HUBOT_WORMHOLE_XMPP_ROOMS" => "kosmos@kosmos.chat,kosmos-dev@kosmos.chat,kosmos-random@kosmos.chat,sockethub@kosmos.chat" - } - ) - notifies :run, "execute[systemctl daemon-reload]", :delayed - notifies :restart, "service[#{app_name}]", :delayed - end - - service app_name do - action [:enable, :start] - end + content [].to_json +end + +systemd_unit "#{app_name}.service" do + content({ + Unit: { + Description: "#{app_name} (node.js app)", + Documentation: ['https://gitea.kosmos.org/kosmos/wormhole'], + }, + Service: { + User: app_user, + Group: app_group, + ExecStart: "#{app_path}/bin/hubot -a irc --name #{app_name}", + WorkingDirectory: app_path, + Environment: app_env.map{|k, v| "'#{k}=#{v}'"}.join(' '), + Type: 'simple', + Restart: 'always', + RestartSec: '2', + TimeoutSec: '10', + PrivateTmp: true, + ProtectSystem: 'full', + NoNewPrivileges: true, + PrivateDevices: true + }, + Install: { + WantedBy: 'multi-user.target' + } + }) + verify false + triggers_reload true + action [:create, :enable, :start] end From f6086e2f6a38d5a0688284dab2575010f97c373c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 7 Jan 2021 12:02:35 +0100 Subject: [PATCH 222/327] Add the firewall rules to the postgresql role --- nodes/centaurus.kosmos.org.json | 3 +-- nodes/draco.kosmos.org.json | 10 +++++----- roles/postgresql_primary.rb | 1 + roles/postgresql_replica.rb | 1 + 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/nodes/centaurus.kosmos.org.json b/nodes/centaurus.kosmos.org.json index 59c6b79..38bc7d4 100644 --- a/nodes/centaurus.kosmos.org.json +++ b/nodes/centaurus.kosmos.org.json @@ -27,13 +27,13 @@ "kosmos_gitea::default", "kosmos_gitea::backup", "kosmos-postgresql::replica", + "kosmos-postgresql::firewall_replicas", "kosmos_discourse", "kosmos_discourse::default", "kosmos_drone", "kosmos_drone::default", "kosmos_kvm::host", "kosmos-ejabberd::firewall", - "kosmos-postgresql::firewall_replicas", "kosmos_zerotier::firewall", "apt::default", "timezone_iii::default", @@ -87,7 +87,6 @@ "role[drone]", "recipe[kosmos_kvm::host]", "recipe[kosmos-ejabberd::firewall]", - "recipe[kosmos-postgresql::firewall_replicas]", "recipe[kosmos_zerotier::firewall]" ] } \ No newline at end of file diff --git a/nodes/draco.kosmos.org.json b/nodes/draco.kosmos.org.json index f463aad..ece1685 100644 --- a/nodes/draco.kosmos.org.json +++ b/nodes/draco.kosmos.org.json @@ -12,19 +12,20 @@ "hostname": "draco", "ipaddress": "148.251.237.73", "roles": [ - "postgresql_replica" + "postgresql_primary" ], "recipes": [ "kosmos-base", "kosmos-base::default", "kosmos_encfs", "kosmos_encfs::default", - "kosmos-postgresql::replica", + "kosmos-postgresql", + "kosmos-postgresql::default", + "kosmos-postgresql::firewall_replicas", "kosmos_kvm::host", "kosmos-ejabberd::firewall", "kosmos-ipfs::firewall_swarm", "kosmos-ipfs::firewall_public_gateway", - "kosmos-postgresql::firewall_replicas", "kosmos-bitcoin::firewall", "kosmos_zerotier::firewall", "kosmos-nginx::firewall", @@ -62,12 +63,11 @@ "run_list": [ "recipe[kosmos-base]", "recipe[kosmos_encfs]", - "role[postgresql_replica]", + "role[postgresql_primary]", "recipe[kosmos_kvm::host]", "recipe[kosmos-ejabberd::firewall]", "recipe[kosmos-ipfs::firewall_swarm]", "recipe[kosmos-ipfs::firewall_public_gateway]", - "recipe[kosmos-postgresql::firewall_replicas]", "recipe[kosmos-bitcoin::firewall]", "recipe[kosmos_zerotier::firewall]", "recipe[kosmos-nginx::firewall]" diff --git a/roles/postgresql_primary.rb b/roles/postgresql_primary.rb index 0cb0ccd..16db3d9 100644 --- a/roles/postgresql_primary.rb +++ b/roles/postgresql_primary.rb @@ -2,4 +2,5 @@ name "postgresql_primary" run_list %w( kosmos-postgresql::default + kosmos-postgresql::firewall_replicas ) diff --git a/roles/postgresql_replica.rb b/roles/postgresql_replica.rb index 8ee5100..3b247b2 100644 --- a/roles/postgresql_replica.rb +++ b/roles/postgresql_replica.rb @@ -2,4 +2,5 @@ name "postgresql_replica" run_list %w( kosmos-postgresql::replica + kosmos-postgresql::firewall_replicas ) From af547772509f3d89632b1aaf1da1bb5b1a0481f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 7 Jan 2021 12:04:21 +0100 Subject: [PATCH 223/327] Create postgresql-1 VM Refs #280 --- clients/postgres-1.json | 4 +++ nodes/postgres-1.json | 59 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 clients/postgres-1.json create mode 100644 nodes/postgres-1.json diff --git a/clients/postgres-1.json b/clients/postgres-1.json new file mode 100644 index 0000000..ff604f3 --- /dev/null +++ b/clients/postgres-1.json @@ -0,0 +1,4 @@ +{ + "name": "postgres-1", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6M27iQm/yjXQ3hQ2O2HJ\nJtzB3reCo+Rkb5G8inOgrMPk458vn9NeSjsxtjh0oOZQEFM7tpRa7XVZuR8/H8PX\nvtzDljvmODmZmF+Qdhxw0+gUK/HQKlFAhKCoa3W04UyEJvafG9comNws0X3TWepu\n9RFlTxla9fmj7miXFidTLoNTkm9SbfZTQCBzhUq4QGvRMnbjIQkbkpUgT6WPU3q3\nJDldWk9xBZ7hjTSCN14ASdMVQMQZQlbtxRo2J6pKEdIwkstw+M8BUp2XBHppncpG\n/oY8ov4w9bIBX0U2Qy6lngmZnNYbhQkyxJVoH5qQJusW7EVNNc7QgZ1cujl+F6+A\nWQIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/postgres-1.json b/nodes/postgres-1.json new file mode 100644 index 0000000..5dbad0d --- /dev/null +++ b/nodes/postgres-1.json @@ -0,0 +1,59 @@ +{ + "name": "postgres-1", + "normal": { + "knife_zero": { + "host": "10.1.1.208" + } + }, + "automatic": { + "fqdn": "postgres-1", + "os": "linux", + "os_version": "5.4.0-1026-kvm", + "hostname": "postgres-1", + "ipaddress": "192.168.122.249", + "roles": [ + "postgresql_replica" + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "kosmos_encfs", + "kosmos_encfs::default", + "kosmos-postgresql::replica", + "kosmos-postgresql::firewall_replicas", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default", + "build-essential::default" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + }, + "chef": { + "version": "15.14.0", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib" + } + } + }, + "run_list": [ + "recipe[kosmos-base]", + "recipe[kosmos_encfs]", + "role[postgresql_replica]" + ] +} \ No newline at end of file From 4309efd228f15250ecab8a22b4f376d1475c186f Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 7 Jan 2021 12:53:20 +0100 Subject: [PATCH 224/327] Add postgres-2 VM --- clients/postgres-2.json | 4 ++++ nodes/postgres-2.json | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 clients/postgres-2.json create mode 100644 nodes/postgres-2.json diff --git a/clients/postgres-2.json b/clients/postgres-2.json new file mode 100644 index 0000000..c7d7da8 --- /dev/null +++ b/clients/postgres-2.json @@ -0,0 +1,4 @@ +{ + "name": "postgres-2", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoQmrHoW5X6jpN6cJnafW\nWKz1LpT2DvOFPeRmrlSPOPIUSVPUMZI8ojdxzmri/dzC8C4quCIYaL5ssARhe17L\no16LG3z/wdPENYONBj/oH5GRvmG1/uCgzL5+QQENk3kAWVAUb7EL3EgHNx90b2oC\nDNoHcjuoi3ZkCUXxkX7BESvw1jII4hP+HyoIqGh8TZLIAQ25/mS9aNL3TbcLYp5d\npqoM0Ruc4DHVuZTamN+zBZwNRCBz6uxMmaEBD+piYTEPJOnf7yUT7d2l/QzLftfE\nkSo80KOyrPOFdIPCpqKJyPOJZgg7fSgpR0YC6BH7I/JgIsIwUsQcMS8/ELUC5+Zg\nfwIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/postgres-2.json b/nodes/postgres-2.json new file mode 100644 index 0000000..f170a95 --- /dev/null +++ b/nodes/postgres-2.json @@ -0,0 +1,52 @@ +{ + "name": "postgres-2", + "normal": { + "knife_zero": { + "host": "10.1.1.99" + } + }, + "automatic": { + "fqdn": "postgres-2", + "os": "linux", + "os_version": "5.4.0-59-generic", + "hostname": "postgres-2", + "ipaddress": "192.168.122.244", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "chef": { + "version": "15.15.0", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.15.0/lib" + }, + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + } + } + }, + "run_list": [ + "recipe[kosmos-base]" + ] +} \ No newline at end of file From 9d9907f0ed7d07280a13426e29583664084c31e3 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 7 Jan 2021 12:53:44 +0100 Subject: [PATCH 225/327] Remove extra license copy from recipe, update year --- site-cookbooks/kosmos-postgresql/LICENSE | 2 +- .../kosmos-postgresql/recipes/replica.rb | 21 ------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/site-cookbooks/kosmos-postgresql/LICENSE b/site-cookbooks/kosmos-postgresql/LICENSE index f3b5d1c..c150a1f 100644 --- a/site-cookbooks/kosmos-postgresql/LICENSE +++ b/site-cookbooks/kosmos-postgresql/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2019 Kosmos Developers +Copyright (c) 2019-2020 Kosmos Developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index 651b18a..5418ad9 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -2,27 +2,6 @@ # Cookbook:: kosmos-postgresql # Recipe:: replica # -# The MIT License (MIT) -# -# Copyright:: 2019, 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. postgresql_version = "12" postgresql_service = "postgresql@#{postgresql_version}-main" From 4872677066ed553cd84aed336f3c98c33486a312 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 7 Jan 2021 13:53:30 +0100 Subject: [PATCH 226/327] Configure postgres recipes for VMs and zerotier access * Remove encfs (using encrypted volumes instead) * Allow access without TLS from zerotier network --- nodes/postgres-2.json | 7 +- roles/postgresql_primary.rb | 4 +- roles/postgresql_replica.rb | 2 +- .../kosmos-postgresql/recipes/default.rb | 90 ------------------- .../kosmos-postgresql/recipes/firewall.rb | 15 ++++ .../recipes/firewall_replicas.rb | 36 -------- .../kosmos-postgresql/recipes/primary.rb | 33 +++++++ .../kosmos-postgresql/recipes/replica.rb | 47 +++++----- .../kosmos-postgresql/resources/server.rb | 57 ++---------- 9 files changed, 86 insertions(+), 205 deletions(-) delete mode 100644 site-cookbooks/kosmos-postgresql/recipes/default.rb create mode 100644 site-cookbooks/kosmos-postgresql/recipes/firewall.rb delete mode 100644 site-cookbooks/kosmos-postgresql/recipes/firewall_replicas.rb create mode 100644 site-cookbooks/kosmos-postgresql/recipes/primary.rb diff --git a/nodes/postgres-2.json b/nodes/postgres-2.json index f170a95..64d44bc 100644 --- a/nodes/postgres-2.json +++ b/nodes/postgres-2.json @@ -12,11 +12,13 @@ "hostname": "postgres-2", "ipaddress": "192.168.122.244", "roles": [ - + "postgresql_replica" ], "recipes": [ "kosmos-base", "kosmos-base::default", + "kosmos-postgresql::replica", + "kosmos-postgresql::firewall", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -47,6 +49,7 @@ } }, "run_list": [ - "recipe[kosmos-base]" + "recipe[kosmos-base]", + "role[postgresql_replica]" ] } \ No newline at end of file diff --git a/roles/postgresql_primary.rb b/roles/postgresql_primary.rb index 16db3d9..ba5e5be 100644 --- a/roles/postgresql_primary.rb +++ b/roles/postgresql_primary.rb @@ -1,6 +1,6 @@ name "postgresql_primary" run_list %w( - kosmos-postgresql::default - kosmos-postgresql::firewall_replicas + kosmos-postgresql::primary + kosmos-postgresql::firewall ) diff --git a/roles/postgresql_replica.rb b/roles/postgresql_replica.rb index 3b247b2..07fc7c6 100644 --- a/roles/postgresql_replica.rb +++ b/roles/postgresql_replica.rb @@ -2,5 +2,5 @@ name "postgresql_replica" run_list %w( kosmos-postgresql::replica - kosmos-postgresql::firewall_replicas + kosmos-postgresql::firewall ) diff --git a/site-cookbooks/kosmos-postgresql/recipes/default.rb b/site-cookbooks/kosmos-postgresql/recipes/default.rb deleted file mode 100644 index 8055b8b..0000000 --- a/site-cookbooks/kosmos-postgresql/recipes/default.rb +++ /dev/null @@ -1,90 +0,0 @@ -# -# Cookbook:: kosmos-postgresql -# Recipe:: default -# -# The MIT License (MIT) -# -# Copyright:: 2019, 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. - -postgresql_version = "12" -postgresql_service = "postgresql@#{postgresql_version}-main" - -service postgresql_service do - supports restart: true, status: true, reload: true -end - -postgresql_custom_server postgresql_version do - role "primary" -end - -# This will only be run once, if the /var/lib/postgresql/10/main directory -# exists. The old data directory is then moved. -execute "upgrade postgresql to 12" do - command <<-EOF -systemctl stop postgresql@12-main -systemctl stop postgresql@10-main -su - postgres -c "/usr/lib/postgresql/12/bin/pg_upgrade --old-bindir=/usr/lib/postgresql/10/bin/ --new-bindir=/usr/lib/postgresql/12/bin/ --old-datadir=/etc/postgresql/10/main/ --new-datadir=/etc/postgresql/12/main/" -mv /var/lib/postgresql/10/main /var/lib/postgresql/10/main.old -systemctl start postgresql@12-main - EOF - only_if { ::File.exist? "/var/lib/postgresql/10/main" } -end - -# Services that connect to PostgreSQL need to have the postgresql_client role -# as part of their run list. See the gitea and ejabberd roles. -postgresql_clients = search(:node, "roles:postgresql_client AND chef_environment:#{node.chef_environment}") || [] - -postgresql_clients.each do |client| - ip = ip_for(client) - hostname = client[:hostname] - - postgresql_access "#{hostname} all" do - access_type "host" - access_db "all" - access_user "all" - access_addr "#{ip}/32" - access_method "md5" - notifies :reload, "service[#{postgresql_service}]", :immediately - end - - firewall_rule "postgresql #{hostname}" do - port 5432 - protocol :tcp - command :allow - source ip - end -end - -postgresql_replicas.each do |replica| - postgresql_access "#{replica[:hostname]} replication" do - access_type "host" - access_db "replication" - access_user "replication" - access_addr "#{replica[:ipaddress]}/32" - access_method "md5" - notifies :reload, "service[#{postgresql_service}]", :immediately - end - -end - -unless node.chef_environment == "development" - include_recipe "kosmos-postgresql::firewall_replicas" -end diff --git a/site-cookbooks/kosmos-postgresql/recipes/firewall.rb b/site-cookbooks/kosmos-postgresql/recipes/firewall.rb new file mode 100644 index 0000000..7b9b380 --- /dev/null +++ b/site-cookbooks/kosmos-postgresql/recipes/firewall.rb @@ -0,0 +1,15 @@ +# +# Cookbook:: kosmos-postgresql +# Recipe:: firewall +# + +unless node.chef_environment == "development" + include_recipe "kosmos-base::firewall" + + firewall_rule "postgresql zerotier members" do + port 5432 + protocol :tcp + command :allow + source "10.1.1.0/24" + end +end diff --git a/site-cookbooks/kosmos-postgresql/recipes/firewall_replicas.rb b/site-cookbooks/kosmos-postgresql/recipes/firewall_replicas.rb deleted file mode 100644 index 0ad0a47..0000000 --- a/site-cookbooks/kosmos-postgresql/recipes/firewall_replicas.rb +++ /dev/null @@ -1,36 +0,0 @@ -# -# Cookbook:: kosmos-postgresql -# Recipe:: firewall_replicas -# -# 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-base::firewall" - -postgresql_replicas.each do |replica| - firewall_rule "postgresql replica #{replica[:hostname]}" do - port 5432 - protocol :tcp - command :allow - source replica[:ipaddress] - end -end diff --git a/site-cookbooks/kosmos-postgresql/recipes/primary.rb b/site-cookbooks/kosmos-postgresql/recipes/primary.rb new file mode 100644 index 0000000..b3a7534 --- /dev/null +++ b/site-cookbooks/kosmos-postgresql/recipes/primary.rb @@ -0,0 +1,33 @@ +# +# Cookbook:: kosmos-postgresql +# Recipe:: primary +# + +postgresql_version = "12" +postgresql_service = "postgresql@#{postgresql_version}-main" + +service postgresql_service do + supports restart: true, status: true, reload: true +end + +postgresql_custom_server postgresql_version do + role "primary" +end + +postgresql_access "zerotier members" do + access_type "host" + access_db "all" + access_user "all" + access_addr "10.1.1.0/24" + access_method "md5" + notifies :reload, "service[#{postgresql_service}]", :immediately +end + +postgresql_access "zerotier members replication" do + access_type "host" + access_db "replication" + access_user "replication" + access_addr "10.1.1.0/24" + access_method "md5" + notifies :reload, "service[#{postgresql_service}]", :immediately +end diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index 5418ad9..a5b82b9 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -19,43 +19,38 @@ postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') primary = postgresql_primary unless primary.nil? - postgresql_data_dir = "#{node["kosmos_encfs"]["data_directory"]}/postgresql/#{postgresql_version}/main" + # TODO + postgresql_data_dir = "/var/lib/postgresql/#{postgresql_version}/main" - if node['kosmos-postgresql']['ready_to_set_up_replica'] - execute "set up replication" do - command <<-EOF + # FIXME get zerotier IP + execute "set up replication" do + command <<-EOF systemctl stop #{postgresql_service} mv #{postgresql_data_dir} #{postgresql_data_dir}.old -pg_basebackup -h #{primary[:ipaddress]} -U replication -D #{postgresql_data_dir} -R +pg_basebackup -h 10.1.1.167 -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 + EOF + environment 'PGPASSWORD' => postgresql_data_bag_item['replication_password'] + sensitive true + not_if { ::File.exist? "#{postgresql_data_dir}/standby.signal" } end - postgresql_access "replication" do + postgresql_access "zerotier members" do access_type "host" - access_db "replication" - access_user "replication" - access_addr "#{primary[:ipaddress]}/32" + access_db "all" + access_user "all" + access_addr "10.1.1.0/24" access_method "md5" notifies :reload, "service[#{postgresql_service}]", :immediately end - # On the next Chef run the replica will be set up - node.normal['kosmos-postgresql']['ready_to_set_up_replica'] = true - - unless node.chef_environment == "development" - include_recipe "kosmos-base::firewall" - - firewall_rule "postgresql primary #{primary[:hostname]}" do - port 5432 - protocol :tcp - command :allow - source primary[:ipaddress] - end + postgresql_access "zerotier members replication" do + access_type "host" + access_db "replication" + access_user "replication" + access_addr "10.1.1.0/24" + access_method "md5" + notifies :reload, "service[#{postgresql_service}]", :immediately end end diff --git a/site-cookbooks/kosmos-postgresql/resources/server.rb b/site-cookbooks/kosmos-postgresql/resources/server.rb index 8e1ff58..c131023 100644 --- a/site-cookbooks/kosmos-postgresql/resources/server.rb +++ b/site-cookbooks/kosmos-postgresql/resources/server.rb @@ -4,22 +4,13 @@ property :postgresql_version, String, required: true, name_property: true property :role, String, required: true # Can be primary or replica action :create do - encfs_data_dir = node["kosmos_encfs"]["data_directory"] postgresql_version = new_resource.postgresql_version - postgresql_data_dir = "#{encfs_data_dir}/postgresql/#{postgresql_version}/main" + postgresql_data_dir = "/var/lib/postgresql/#{postgresql_version}/main" postgresql_service = "postgresql@#{postgresql_version}-main" + postgresql_credentials = data_bag_item('credentials', 'postgresql') - node.override['build-essential']['compile_time'] = true - include_recipe 'build-essential::default' - - user "postgres" do - manage_home false - end - - directory "#{encfs_data_dir}/postgresql" do - owner "postgres" - group "postgres" - mode "0750" + build_essential do + compile_time true end package("libpq-dev") { action :nothing }.run_action(:install) @@ -28,13 +19,14 @@ action :create do compile_time true end - postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') + user "postgres" do + manage_home false + end postgresql_server_install "main" do version postgresql_version setup_repo true - password postgresql_data_bag_item['server_password'] - data_directory postgresql_data_dir + password postgresql_credentials['server_password'] action :install end @@ -43,9 +35,6 @@ action :create do action :start end - # Activates the postgres service when encrypted data dir is mounted - encfs_path_activation_unit postgresql_service - # This service is a dependency that will auto-start our cluster service on # boot if it's enabled, so we disable it explicitly service "postgresql" do @@ -69,36 +58,8 @@ action :create do additional_config[:promote_trigger_file] = "#{postgresql_data_dir}/failover.trigger" - ssl_cert = postgresql_data_bag_item['ssl_cert'] - ssl_cert_path = "#{postgresql_data_dir}/server.crt" - ssl_key = postgresql_data_bag_item['ssl_key'] - ssl_key_path = "#{postgresql_data_dir}/server.key" - - file ssl_cert_path do - content ssl_cert - owner "postgres" - group "postgres" - mode "0640" - sensitive true - end - - file ssl_key_path do - content ssl_key - owner "postgres" - group "postgres" - mode "0600" - sensitive true - end - - additional_config[:ssl] = "on" - additional_config[:ssl_cert_file] = ssl_cert_path - additional_config[:ssl_key_file] = ssl_key_path - # ejabberd does not support 1.3 yet - additional_config[:ssl_min_protocol_version] = "TLSv1.2" - postgresql_server_conf "main" do version postgresql_version - data_directory postgresql_data_dir additional_config additional_config notifies :reload, "service[#{postgresql_service}]", :delayed end @@ -106,7 +67,7 @@ action :create do postgresql_user "replication" do action :create replication true - password postgresql_data_bag_item['replication_password'] + password postgresql_credentials['replication_password'] end end From 74cf26846eab6b5ebc0a0f89f76dd1dbf93a7dcd Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 12 Jan 2021 18:06:16 +0100 Subject: [PATCH 227/327] Fix ejabberd API permission for akkounts VMs It should have been using a /32, not a /8 subnet, in order to only allow the akkounts VM(s) to use the API endpoints without further authorization. --- site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb index e1dca82..a46759d 100644 --- a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb +++ b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb @@ -177,7 +177,7 @@ api_permissions: "akkounts": who: <% @akkounts_ip_addresses.each do |ip| -%> - - ip: "<%= ip %>/8" + - ip: "<%= ip %>/32" <% end -%> what: - "add_rosteritem" From c4fa9e6ec195c457debdf9313be5d242c89edc8c Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 12 Jan 2021 18:41:31 +0100 Subject: [PATCH 228/327] Remove extra license headers And update year in LICENSE file --- site-cookbooks/kosmos-mastodon/LICENSE | 2 +- .../kosmos-mastodon/recipes/default.rb | 21 ------------------- .../kosmos-mastodon/recipes/nginx.rb | 21 ------------------- .../kosmos-mastodon/recipes/pg_db.rb | 21 ------------------- 4 files changed, 1 insertion(+), 64 deletions(-) diff --git a/site-cookbooks/kosmos-mastodon/LICENSE b/site-cookbooks/kosmos-mastodon/LICENSE index f3b5d1c..967d43c 100644 --- a/site-cookbooks/kosmos-mastodon/LICENSE +++ b/site-cookbooks/kosmos-mastodon/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2019 Kosmos Developers +Copyright (c) 2019-2021 Kosmos Developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/site-cookbooks/kosmos-mastodon/recipes/default.rb b/site-cookbooks/kosmos-mastodon/recipes/default.rb index 053b232..50c7098 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/default.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/default.rb @@ -2,27 +2,6 @@ # Cookbook Name:: kosmos-mastodon # Recipe:: default # -# The MIT License (MIT) -# -# Copyright:: 2019, 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-nodejs" include_recipe "kosmos-redis" diff --git a/site-cookbooks/kosmos-mastodon/recipes/nginx.rb b/site-cookbooks/kosmos-mastodon/recipes/nginx.rb index 268e973..fde87cd 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/nginx.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/nginx.rb @@ -2,27 +2,6 @@ # Cookbook Name:: kosmos-mastodon # Recipe:: nginx # -# The MIT License (MIT) -# -# Copyright:: 2019, 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. mastodon_path = node["kosmos-mastodon"]["directory"] server_name = node["kosmos-mastodon"]["server_name"] diff --git a/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb b/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb index 4f0ee9f..af15e80 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb @@ -2,27 +2,6 @@ # Cookbook Name:: kosmos-mastodon # Recipe:: pg_db # -# 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. postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') From 4d0259493f972c55b13dbd51e81ae15916a48ab5 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 09:48:23 +0100 Subject: [PATCH 229/327] Update system package dependencies for 20.04 --- site-cookbooks/kosmos-mastodon/recipes/default.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-mastodon/recipes/default.rb b/site-cookbooks/kosmos-mastodon/recipes/default.rb index 50c7098..ee9d5d6 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/default.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/default.rb @@ -42,8 +42,9 @@ user mastodon_user do home mastodon_path end -package %w(imagemagick ffmpeg libxml2-dev libxslt1-dev file git curl pkg-config - libprotobuf-dev protobuf-compiler libidn11 libidn11-dev libjemalloc1) +package %w(build-essential imagemagick ffmpeg libxml2-dev libxslt1-dev file git + curl pkg-config libprotobuf-dev protobuf-compiler libidn11 + libidn11-dev libjemalloc2 libpq-dev) npm_package "yarn" do version "1.22.4" From 9d13acd41ae7662a1588af4539fa8e691e4fc4e0 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 09:49:03 +0100 Subject: [PATCH 230/327] Don't fail on first run, when Tor hostname missing --- site-cookbooks/kosmos-mastodon/recipes/nginx.rb | 4 +++- .../kosmos-mastodon/templates/default/nginx_conf_mastodon.erb | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-mastodon/recipes/nginx.rb b/site-cookbooks/kosmos-mastodon/recipes/nginx.rb index fde87cd..65717a1 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/nginx.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/nginx.rb @@ -24,6 +24,8 @@ template "#{node['nginx']['dir']}/snippets/mastodon.conf" do notifies :reload, 'service[nginx]', :delayed end +onion_address = File.read("/var/lib/tor/mastodon/hostname").strip rescue nil + template "#{node['nginx']['dir']}/sites-available/#{server_name}" do source 'nginx_conf_mastodon.erb' owner 'www-data' @@ -32,7 +34,7 @@ template "#{node['nginx']['dir']}/sites-available/#{server_name}" do ssl_cert: "/etc/letsencrypt/live/#{server_name}/fullchain.pem", ssl_key: "/etc/letsencrypt/live/#{server_name}/privkey.pem", shared_config_path: "#{node['nginx']['dir']}/snippets/mastodon.conf", - onion_address: File.read("/var/lib/tor/mastodon/hostname").strip + onion_address: onion_address notifies :reload, 'service[nginx]', :delayed end diff --git a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb index c07686e..20d2efa 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb @@ -1,8 +1,10 @@ +<% if @onion_address %> server { listen 80; server_name mastodon.<%= @onion_address %>; include <%= @shared_config_path %>; } +<% end %> map $http_upgrade $connection_upgrade { default upgrade; From 047526e0fcf9c921abcb9e205423e6258ae6cfe6 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 09:49:49 +0100 Subject: [PATCH 231/327] Don't configure HTTPS site when certs missing --- .../templates/default/nginx_conf_mastodon.erb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb index 20d2efa..6991f7a 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb @@ -11,17 +11,16 @@ map $http_upgrade $connection_upgrade { '' close; } +<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) %> server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name <%= @server_name %>; include <%= @shared_config_path %>; - <% if File.exist?(@ssl_cert) && - File.exist?(@ssl_key) -%> ssl_certificate <%= @ssl_cert %>; ssl_certificate_key <%= @ssl_key %>; - <% end -%> add_header Strict-Transport-Security "max-age=31536000"; } +<% end %> From c622f81572cc5a5d8e59adeffb19a14e90b04edc Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 09:50:10 +0100 Subject: [PATCH 232/327] Remove extra license header --- .../kosmos-redis/recipes/default.rb | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/site-cookbooks/kosmos-redis/recipes/default.rb b/site-cookbooks/kosmos-redis/recipes/default.rb index d5ee76d..06e440d 100644 --- a/site-cookbooks/kosmos-redis/recipes/default.rb +++ b/site-cookbooks/kosmos-redis/recipes/default.rb @@ -2,27 +2,6 @@ # Cookbook Name:: kosmos-redis # Recipe:: default # -# The MIT License (MIT) -# -# Copyright:: 2019, 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. node.override['redis']['unixsocket'] = '' include_recipe 'redis::server' From 62320106cb727686bc054b58856cc5ed8e8dc478 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 09:50:37 +0100 Subject: [PATCH 233/327] Set up mastodon-1 VM --- nodes/mastodon-1.json | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 nodes/mastodon-1.json diff --git a/nodes/mastodon-1.json b/nodes/mastodon-1.json new file mode 100644 index 0000000..c1a7a49 --- /dev/null +++ b/nodes/mastodon-1.json @@ -0,0 +1,86 @@ +{ + "name": "mastodon-1", + "normal": { + "knife_zero": { + "host": "10.1.1.156" + } + }, + "automatic": { + "fqdn": "mastodon-1", + "os": "linux", + "os_version": "5.4.0-1031-kvm", + "hostname": "mastodon-1", + "ipaddress": "192.168.122.197", + "roles": [ + "mastodon", + "postgresql_client" + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "kosmos-mastodon", + "kosmos-mastodon::default", + "kosmos-mastodon::nginx", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default", + "kosmos-nodejs::default", + "nodejs::nodejs_from_package", + "nodejs::repo", + "kosmos-redis::default", + "redis::server", + "redis::default", + "backup::default", + "logrotate::default", + "java::default", + "java::set_attributes_from_version", + "java::openjdk", + "java::notify", + "java::default_java_symlink", + "java::set_java_home", + "nodejs::npm", + "nodejs::install", + "kosmos-nginx::default", + "nginx::default", + "nginx::package", + "nginx::ohai_plugin", + "nginx::repo", + "nginx::commons", + "nginx::commons_dir", + "nginx::commons_script", + "nginx::commons_conf", + "kosmos-nginx::firewall", + "tor-full::default", + "git::default", + "git::package" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + }, + "chef": { + "version": "15.14.0", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib" + } + } + }, + "run_list": [ + "recipe[kosmos-base]", + "role[mastodon]" + ] +} \ No newline at end of file From 9224aa9d97830349a0bebadce19b3b376e17bd31 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 17:06:25 +0100 Subject: [PATCH 234/327] Update node data --- nodes/mastodon-1.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nodes/mastodon-1.json b/nodes/mastodon-1.json index c1a7a49..b06ab5f 100644 --- a/nodes/mastodon-1.json +++ b/nodes/mastodon-1.json @@ -63,7 +63,8 @@ "kosmos-nginx::firewall", "tor-full::default", "git::default", - "git::package" + "git::package", + "kosmos-base::letsencrypt" ], "platform": "ubuntu", "platform_version": "20.04", From 12a3fa5b4e1ee47bafa32b29609d9cbbdc3fd268 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 17:06:36 +0100 Subject: [PATCH 235/327] Use default Redis database now --- site-cookbooks/kosmos-mastodon/attributes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-mastodon/attributes/default.rb b/site-cookbooks/kosmos-mastodon/attributes/default.rb index eb91556..f04a577 100644 --- a/site-cookbooks/kosmos-mastodon/attributes/default.rb +++ b/site-cookbooks/kosmos-mastodon/attributes/default.rb @@ -2,7 +2,7 @@ node.default["kosmos-mastodon"]["directory"] = "/opt/mastodon" node.default["kosmos-mastodon"]["puma_port"] = 3000 node.default["kosmos-mastodon"]["streaming_port"] = 4000 node.default["kosmos-mastodon"]["server_name"] = "kosmos.social" -node.default["kosmos-mastodon"]["redis_url"] = "redis://localhost:6379/1" +node.default["kosmos-mastodon"]["redis_url"] = "redis://localhost:6379/0" node.default["kosmos-mastodon"]["sidekiq_threads"] = 25 # Allocate this amount of RAM to the Java heap for Elasticsearch node.default["kosmos-mastodon"]["elasticsearch"]["allocated_memory"] = "1536m" From 6c6026958badaeea2f002a18b486fafc52e01c9f Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 14 Jan 2021 21:23:03 +0100 Subject: [PATCH 236/327] Fix typo in port number of externalip config --- site-cookbooks/kosmos-bitcoin/attributes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index dc11a70..b595fb7 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -42,7 +42,7 @@ node.default['lnd']['alias'] = 'ln2.kosmos.org' node.default['lnd']['color'] = '#5e0c99' node.default['lnd']['log_level'] = 'info' node.default['lnd']['public_ip'] = '148.251.237.111' -node.default['lnd']['public_port'] = '9375' +node.default['lnd']['public_port'] = '9735' node.default['lnd']['port'] = '9736' node.default['lnd']['minchansize'] = '1000000' node.default['lnd']['basefee'] = '500' From 775ec691efcd0fc230fb454e80506218471e4ce0 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 14 Jan 2021 21:23:20 +0100 Subject: [PATCH 237/327] Add firewall rules for LND and c-lightning --- site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb | 6 ++++++ site-cookbooks/kosmos-bitcoin/recipes/lnd.rb | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb index b86b184..b8f2865 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb @@ -92,3 +92,9 @@ systemd_unit 'lightningd.service' do triggers_reload true action [:create, :enable, :start] end + +firewall_rule 'lightningd' do + port [9735] # TODO use attribute + protocol :tcp + command :allow +end diff --git a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb index b179c42..4e2464a 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb @@ -89,3 +89,9 @@ systemd_unit 'lnd.service' do triggers_reload true action [:create, :enable, :start] end + +firewall_rule 'lnd' do + port [node['lnd']['port']] + protocol :tcp + command :allow +end From ab422155e46b6f3325fc9722acac00f837165f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 22 Jan 2021 13:49:23 +0100 Subject: [PATCH 238/327] Add the ability to pass a disk size to the create_vm script Defaults to 10GB --- site-cookbooks/kosmos_kvm/files/create_vm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/site-cookbooks/kosmos_kvm/files/create_vm b/site-cookbooks/kosmos_kvm/files/create_vm index db4cf8e..0c82f2d 100644 --- a/site-cookbooks/kosmos_kvm/files/create_vm +++ b/site-cookbooks/kosmos_kvm/files/create_vm @@ -5,13 +5,14 @@ if [[ $# -lt 3 ]] ; then cat <<-EOF USAGE (RAM in megabytes) -create_vm VMNAME RAM CPUS +create_vm VMNAME RAM CPUS DISKSIZE EOF exit 1 fi VMNAME=$1 RAM=$2 CPUS=$3 +DISKSIZE=${4:-10} # 10GB default # Directory where image files will be stored IMAGE_DIR=/var/lib/libvirt/images @@ -20,9 +21,6 @@ IMAGE_PATH=$IMAGE_DIR/$IMAGE_FILE CIDATA_PATH=${IMAGE_DIR}/cidata-${VMNAME}.iso BASE_FILE=${IMAGE_DIR}/base/ubuntu-20.04-server-cloudimg-amd64-disk-kvm.qcow2 -# Disk size assigned to the VM -DISKSIZE=10 # Unit: GB - # Create the VM image if it does not already exist if [ ! -f "$IMAGE_PATH" ]; then echo "info: image file $IMAGE_PATH not found. creating new image" From 971a3a25a11d87ed94d9406dc74cc5516ff71eed Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 12 Jan 2021 18:41:31 +0100 Subject: [PATCH 239/327] Remove extra license headers And update year in LICENSE file --- site-cookbooks/kosmos-mastodon/LICENSE | 2 +- .../kosmos-mastodon/recipes/default.rb | 21 ------------------- .../kosmos-mastodon/recipes/nginx.rb | 21 ------------------- .../kosmos-mastodon/recipes/pg_db.rb | 21 ------------------- 4 files changed, 1 insertion(+), 64 deletions(-) diff --git a/site-cookbooks/kosmos-mastodon/LICENSE b/site-cookbooks/kosmos-mastodon/LICENSE index f3b5d1c..967d43c 100644 --- a/site-cookbooks/kosmos-mastodon/LICENSE +++ b/site-cookbooks/kosmos-mastodon/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2019 Kosmos Developers +Copyright (c) 2019-2021 Kosmos Developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/site-cookbooks/kosmos-mastodon/recipes/default.rb b/site-cookbooks/kosmos-mastodon/recipes/default.rb index 053b232..50c7098 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/default.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/default.rb @@ -2,27 +2,6 @@ # Cookbook Name:: kosmos-mastodon # Recipe:: default # -# The MIT License (MIT) -# -# Copyright:: 2019, 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-nodejs" include_recipe "kosmos-redis" diff --git a/site-cookbooks/kosmos-mastodon/recipes/nginx.rb b/site-cookbooks/kosmos-mastodon/recipes/nginx.rb index 268e973..fde87cd 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/nginx.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/nginx.rb @@ -2,27 +2,6 @@ # Cookbook Name:: kosmos-mastodon # Recipe:: nginx # -# The MIT License (MIT) -# -# Copyright:: 2019, 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. mastodon_path = node["kosmos-mastodon"]["directory"] server_name = node["kosmos-mastodon"]["server_name"] diff --git a/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb b/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb index 4f0ee9f..af15e80 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/pg_db.rb @@ -2,27 +2,6 @@ # Cookbook Name:: kosmos-mastodon # Recipe:: pg_db # -# 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. postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') From ad64bfc0be1786c0997a95f44b8d4aaee29b539f Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 09:48:23 +0100 Subject: [PATCH 240/327] Update system package dependencies for 20.04 --- site-cookbooks/kosmos-mastodon/recipes/default.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-mastodon/recipes/default.rb b/site-cookbooks/kosmos-mastodon/recipes/default.rb index 50c7098..ee9d5d6 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/default.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/default.rb @@ -42,8 +42,9 @@ user mastodon_user do home mastodon_path end -package %w(imagemagick ffmpeg libxml2-dev libxslt1-dev file git curl pkg-config - libprotobuf-dev protobuf-compiler libidn11 libidn11-dev libjemalloc1) +package %w(build-essential imagemagick ffmpeg libxml2-dev libxslt1-dev file git + curl pkg-config libprotobuf-dev protobuf-compiler libidn11 + libidn11-dev libjemalloc2 libpq-dev) npm_package "yarn" do version "1.22.4" From 8a870f6fd69f344391e2167e96f41f9aa27e0be7 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 09:49:03 +0100 Subject: [PATCH 241/327] Don't fail on first run, when Tor hostname missing --- site-cookbooks/kosmos-mastodon/recipes/nginx.rb | 4 +++- .../kosmos-mastodon/templates/default/nginx_conf_mastodon.erb | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-mastodon/recipes/nginx.rb b/site-cookbooks/kosmos-mastodon/recipes/nginx.rb index fde87cd..65717a1 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/nginx.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/nginx.rb @@ -24,6 +24,8 @@ template "#{node['nginx']['dir']}/snippets/mastodon.conf" do notifies :reload, 'service[nginx]', :delayed end +onion_address = File.read("/var/lib/tor/mastodon/hostname").strip rescue nil + template "#{node['nginx']['dir']}/sites-available/#{server_name}" do source 'nginx_conf_mastodon.erb' owner 'www-data' @@ -32,7 +34,7 @@ template "#{node['nginx']['dir']}/sites-available/#{server_name}" do ssl_cert: "/etc/letsencrypt/live/#{server_name}/fullchain.pem", ssl_key: "/etc/letsencrypt/live/#{server_name}/privkey.pem", shared_config_path: "#{node['nginx']['dir']}/snippets/mastodon.conf", - onion_address: File.read("/var/lib/tor/mastodon/hostname").strip + onion_address: onion_address notifies :reload, 'service[nginx]', :delayed end diff --git a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb index c07686e..20d2efa 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb @@ -1,8 +1,10 @@ +<% if @onion_address %> server { listen 80; server_name mastodon.<%= @onion_address %>; include <%= @shared_config_path %>; } +<% end %> map $http_upgrade $connection_upgrade { default upgrade; From 6da190b110700c8f7efd9c26ddef164cc038cde2 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 09:49:49 +0100 Subject: [PATCH 242/327] Don't configure HTTPS site when certs missing --- .../templates/default/nginx_conf_mastodon.erb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb index 20d2efa..6991f7a 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb @@ -11,17 +11,16 @@ map $http_upgrade $connection_upgrade { '' close; } +<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) %> server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name <%= @server_name %>; include <%= @shared_config_path %>; - <% if File.exist?(@ssl_cert) && - File.exist?(@ssl_key) -%> ssl_certificate <%= @ssl_cert %>; ssl_certificate_key <%= @ssl_key %>; - <% end -%> add_header Strict-Transport-Security "max-age=31536000"; } +<% end %> From 1403d91631309fbc3d36db5b5b9e7c64b1785ec7 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 09:50:10 +0100 Subject: [PATCH 243/327] Remove extra license header --- .../kosmos-redis/recipes/default.rb | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/site-cookbooks/kosmos-redis/recipes/default.rb b/site-cookbooks/kosmos-redis/recipes/default.rb index d5ee76d..06e440d 100644 --- a/site-cookbooks/kosmos-redis/recipes/default.rb +++ b/site-cookbooks/kosmos-redis/recipes/default.rb @@ -2,27 +2,6 @@ # Cookbook Name:: kosmos-redis # Recipe:: default # -# The MIT License (MIT) -# -# Copyright:: 2019, 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. node.override['redis']['unixsocket'] = '' include_recipe 'redis::server' From d121971cca098327a93c74d89e8aa18d9f263708 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 09:50:37 +0100 Subject: [PATCH 244/327] Set up mastodon-1 VM --- nodes/mastodon-1.json | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 nodes/mastodon-1.json diff --git a/nodes/mastodon-1.json b/nodes/mastodon-1.json new file mode 100644 index 0000000..c1a7a49 --- /dev/null +++ b/nodes/mastodon-1.json @@ -0,0 +1,86 @@ +{ + "name": "mastodon-1", + "normal": { + "knife_zero": { + "host": "10.1.1.156" + } + }, + "automatic": { + "fqdn": "mastodon-1", + "os": "linux", + "os_version": "5.4.0-1031-kvm", + "hostname": "mastodon-1", + "ipaddress": "192.168.122.197", + "roles": [ + "mastodon", + "postgresql_client" + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "kosmos-mastodon", + "kosmos-mastodon::default", + "kosmos-mastodon::nginx", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default", + "kosmos-nodejs::default", + "nodejs::nodejs_from_package", + "nodejs::repo", + "kosmos-redis::default", + "redis::server", + "redis::default", + "backup::default", + "logrotate::default", + "java::default", + "java::set_attributes_from_version", + "java::openjdk", + "java::notify", + "java::default_java_symlink", + "java::set_java_home", + "nodejs::npm", + "nodejs::install", + "kosmos-nginx::default", + "nginx::default", + "nginx::package", + "nginx::ohai_plugin", + "nginx::repo", + "nginx::commons", + "nginx::commons_dir", + "nginx::commons_script", + "nginx::commons_conf", + "kosmos-nginx::firewall", + "tor-full::default", + "git::default", + "git::package" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + }, + "chef": { + "version": "15.14.0", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib" + } + } + }, + "run_list": [ + "recipe[kosmos-base]", + "role[mastodon]" + ] +} \ No newline at end of file From 69c199484045bf561519b8499ad1a8fb288621e8 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 17:06:25 +0100 Subject: [PATCH 245/327] Update node data --- nodes/mastodon-1.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nodes/mastodon-1.json b/nodes/mastodon-1.json index c1a7a49..b06ab5f 100644 --- a/nodes/mastodon-1.json +++ b/nodes/mastodon-1.json @@ -63,7 +63,8 @@ "kosmos-nginx::firewall", "tor-full::default", "git::default", - "git::package" + "git::package", + "kosmos-base::letsencrypt" ], "platform": "ubuntu", "platform_version": "20.04", From d018b6570dbcdc916dfd62f63b7515eec4e6bfef Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 17:06:36 +0100 Subject: [PATCH 246/327] Use default Redis database now --- site-cookbooks/kosmos-mastodon/attributes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-mastodon/attributes/default.rb b/site-cookbooks/kosmos-mastodon/attributes/default.rb index eb91556..f04a577 100644 --- a/site-cookbooks/kosmos-mastodon/attributes/default.rb +++ b/site-cookbooks/kosmos-mastodon/attributes/default.rb @@ -2,7 +2,7 @@ node.default["kosmos-mastodon"]["directory"] = "/opt/mastodon" node.default["kosmos-mastodon"]["puma_port"] = 3000 node.default["kosmos-mastodon"]["streaming_port"] = 4000 node.default["kosmos-mastodon"]["server_name"] = "kosmos.social" -node.default["kosmos-mastodon"]["redis_url"] = "redis://localhost:6379/1" +node.default["kosmos-mastodon"]["redis_url"] = "redis://localhost:6379/0" node.default["kosmos-mastodon"]["sidekiq_threads"] = 25 # Allocate this amount of RAM to the Java heap for Elasticsearch node.default["kosmos-mastodon"]["elasticsearch"]["allocated_memory"] = "1536m" From fd4844a012a776203be3beffa4fd63bb5516938d Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 12 Jan 2021 18:06:16 +0100 Subject: [PATCH 247/327] Fix ejabberd API permission for akkounts VMs It should have been using a /32, not a /8 subnet, in order to only allow the akkounts VM(s) to use the API endpoints without further authorization. --- site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb index e1dca82..a46759d 100644 --- a/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb +++ b/site-cookbooks/kosmos-ejabberd/templates/ejabberd.yml.erb @@ -177,7 +177,7 @@ api_permissions: "akkounts": who: <% @akkounts_ip_addresses.each do |ip| -%> - - ip: "<%= ip %>/8" + - ip: "<%= ip %>/32" <% end -%> what: - "add_rosteritem" From 9a4420fc114e96374ff969a5f8f560f60beba72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 22 Jan 2021 13:49:23 +0100 Subject: [PATCH 248/327] Add the ability to pass a disk size to the create_vm script Defaults to 10GB --- site-cookbooks/kosmos_kvm/files/create_vm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/site-cookbooks/kosmos_kvm/files/create_vm b/site-cookbooks/kosmos_kvm/files/create_vm index db4cf8e..0c82f2d 100644 --- a/site-cookbooks/kosmos_kvm/files/create_vm +++ b/site-cookbooks/kosmos_kvm/files/create_vm @@ -5,13 +5,14 @@ if [[ $# -lt 3 ]] ; then cat <<-EOF USAGE (RAM in megabytes) -create_vm VMNAME RAM CPUS +create_vm VMNAME RAM CPUS DISKSIZE EOF exit 1 fi VMNAME=$1 RAM=$2 CPUS=$3 +DISKSIZE=${4:-10} # 10GB default # Directory where image files will be stored IMAGE_DIR=/var/lib/libvirt/images @@ -20,9 +21,6 @@ IMAGE_PATH=$IMAGE_DIR/$IMAGE_FILE CIDATA_PATH=${IMAGE_DIR}/cidata-${VMNAME}.iso BASE_FILE=${IMAGE_DIR}/base/ubuntu-20.04-server-cloudimg-amd64-disk-kvm.qcow2 -# Disk size assigned to the VM -DISKSIZE=10 # Unit: GB - # Create the VM image if it does not already exist if [ ! -f "$IMAGE_PATH" ]; then echo "info: image file $IMAGE_PATH not found. creating new image" From 511400a7b88279415268be87ffab8dd0cd444639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 22 Jan 2021 18:27:45 +0100 Subject: [PATCH 249/327] Update hostsfile and add zerotier cookbook --- Berksfile | 3 +- Berksfile.lock | 7 +- cookbooks/hostsfile/CHANGELOG.md | 61 +- cookbooks/hostsfile/CONTRIBUTING.md | 6 + cookbooks/hostsfile/README.md | 151 ++-- cookbooks/hostsfile/attributes/default.rb | 4 +- cookbooks/hostsfile/libraries/entry.rb | 295 ++++---- cookbooks/hostsfile/libraries/manipulator.rb | 513 ++++++------- cookbooks/hostsfile/metadata.json | 30 +- cookbooks/hostsfile/metadata.rb | 7 - cookbooks/hostsfile/providers/entry.rb | 138 ---- cookbooks/hostsfile/resources/entry.rb | 135 +++- cookbooks/zerotier/COPYING | 17 + cookbooks/zerotier/LICENSE.GPL-2 | 339 +++++++++ cookbooks/zerotier/LICENSE.GPL-3 | 674 ++++++++++++++++++ cookbooks/zerotier/README.md | 68 ++ cookbooks/zerotier/attributes/default.rb | 28 + cookbooks/zerotier/chefignore | 107 +++ .../zerotier/libraries/zerotier_network.rb | 74 ++ cookbooks/zerotier/metadata.json | 55 ++ cookbooks/zerotier/metadata.rb | 15 + cookbooks/zerotier/recipes/default.rb | 7 + cookbooks/zerotier/recipes/install.rb | 48 ++ cookbooks/zerotier/recipes/join_networks.rb | 23 + cookbooks/zerotier/recipes/ohai_plugin.rb | 15 + .../templates/default/zerotier_ohai.rb | 71 ++ 26 files changed, 2184 insertions(+), 707 deletions(-) create mode 100644 cookbooks/hostsfile/CONTRIBUTING.md delete mode 100644 cookbooks/hostsfile/metadata.rb delete mode 100644 cookbooks/hostsfile/providers/entry.rb create mode 100644 cookbooks/zerotier/COPYING create mode 100644 cookbooks/zerotier/LICENSE.GPL-2 create mode 100644 cookbooks/zerotier/LICENSE.GPL-3 create mode 100644 cookbooks/zerotier/README.md create mode 100644 cookbooks/zerotier/attributes/default.rb create mode 100644 cookbooks/zerotier/chefignore create mode 100644 cookbooks/zerotier/libraries/zerotier_network.rb create mode 100644 cookbooks/zerotier/metadata.json create mode 100644 cookbooks/zerotier/metadata.rb create mode 100644 cookbooks/zerotier/recipes/default.rb create mode 100644 cookbooks/zerotier/recipes/install.rb create mode 100644 cookbooks/zerotier/recipes/join_networks.rb create mode 100644 cookbooks/zerotier/recipes/ohai_plugin.rb create mode 100644 cookbooks/zerotier/templates/default/zerotier_ohai.rb diff --git a/Berksfile b/Berksfile index 2a32b61..374c10b 100644 --- a/Berksfile +++ b/Berksfile @@ -32,7 +32,7 @@ cookbook 'mysql', '~> 8.7.3' # cookbook 'postgresql', '= 7.1.8' cookbook 'apt', '~> 7.3.0' cookbook 'git', '~> 10.0.0' -cookbook 'hostsfile', '= 2.4.5' +cookbook 'hostsfile', '~> 3.0.1' cookbook 'ohai', '~> 5.2.5' cookbook 'nodejs', '~> 5.0.0' cookbook 'timezone_iii', '= 1.0.4' @@ -52,3 +52,4 @@ cookbook 'elasticsearch', '= 4.2.0' cookbook 'java', '~> 4.3.0' cookbook 'ulimit', '~> 1.0.0' cookbook 'golang', '~> 4.1.0' +cookbook 'zerotier', '~> 1.0.7' diff --git a/Berksfile.lock b/Berksfile.lock index ce0f7d4..20ece54 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -15,7 +15,7 @@ DEPENDENCIES golang (~> 4.1.0) homebrew (= 3.0.0) hostname (= 0.4.2) - hostsfile (= 2.4.5) + hostsfile (~> 3.0.1) ipfs git: https://gitea.kosmos.org/kosmos/ipfs-cookbook.git revision: d7c25b6ce5fa490b6de3529fdc163fb64f1ece8a @@ -51,6 +51,7 @@ DEPENDENCIES timezone_iii (= 1.0.4) ulimit (~> 1.0.0) users (~> 5.3.1) + zerotier (~> 1.0.7) GRAPH apache2 (3.3.0) @@ -91,7 +92,7 @@ GRAPH homebrew (3.0.0) hostname (0.4.2) hostsfile (>= 0.0.0) - hostsfile (2.4.5) + hostsfile (3.0.1) ipfs (0.7.0) ark (>= 0.0.0) java (4.3.0) @@ -156,3 +157,5 @@ GRAPH windows (6.0.0) yum (5.1.0) yum-epel (3.3.0) + zerotier (1.0.7) + ohai (>= 0.0.0) diff --git a/cookbooks/hostsfile/CHANGELOG.md b/cookbooks/hostsfile/CHANGELOG.md index 79838bb..724841a 100644 --- a/cookbooks/hostsfile/CHANGELOG.md +++ b/cookbooks/hostsfile/CHANGELOG.md @@ -1,42 +1,53 @@ -hostsfile Cookbook CHANGELOG -======================= +# hostsfile Cookbook CHANGELOG + This file is used to list changes made in each version of the hostsfile cookbook. +## v3.0.1 (2017-08-22) + +- Add TESTING.md and CONTRIBUTING.md files +- Fix the readme to properly specify Chef 12.7+ as the Chef requirement +- Add a local delivery configuration and remove the existing rakefile +- Resolve _most_ of the ChefSpec failures + +## v3.0.0 (2017-08-22) + +- Converted the LWRP to a custom resource which increases the required Chef release to 12.7 +- Namespaced the helper libraries under the HostsFile module to prevent method collisions with other resources or the chef-client itself + +## v2.4.6 (2017-08-15) + +- use openssl for FIPS compatibility +- Expand priority documentation in README +- Add ::1 loopback to test cases and priority settings + +## v2.4.5 (2014-06-24) -v2.4.5 (2014-06-24) -------------------- - Fix notifications and why-run mode +## v2.4.4 (2014-02-25) -v2.4.4 (2014-02-25) -------------------- - Bump Berkshelf version - Remove scope pieces from IPv6 addresses - -v2.4.3 (2014-02-01) -------------------- +## v2.4.3 (2014-02-01) - Package custom ChefSpec matchers - Update testing harness - Avoid using `Chef::Application.fatal!` - Use Chef::Resource::File for atomic updates +## v2.4.2 -v2.4.2 ------- - Fix Travis CI integration - Remove newline characters - Allow specifying a custom hostsfile path +## v2.4.1 -v2.4.1 ------- - Force a new upload to the community site +## v2.4.0 -v2.4.0 ------- - Convert everything to Ruby 1.9 syntax because I'm tired of people removing trailing commas despite the **massive** warning in the README: ([#29](https://github.com/customink-webops/hostsfile/issues/29), [#30](https://github.com/customink-webops/hostsfile/issues/30), [#32](https://github.com/customink-webops/hostsfile/issues/32), [#33](https://github.com/customink-webops/hostsfile/issues/33), [#34](https://github.com/customink-webops/hostsfile/issues/34), [#35](https://github.com/customink-webops/hostsfile/issues/35), [#36](https://github.com/customink-webops/hostsfile/issues/36), [#38](https://github.com/customink-webops/hostsfile/issues/38), [#39](https://github.com/customink-webops/hostsfile/issues/39)) - Update to the latest and greatest testing gems and practices - Remove strainer in favor of a purer solution @@ -44,30 +55,30 @@ v2.4.0 - Add more platforms to the `.kitchen.yml` - Use `converge_by` and support whyruny mode -v2.0.0 ------- +## v2.0.0 + - Completely manage the hostsfile, ensuring no duplicate entries -v1.0.2 ------- +## v1.0.2 + - Support Windows (thanks @igantt-daptiv) - Specs + Travis support - Throw fatal error if hostsfile does not exist (@jkerzner) - Write priorities in hostsfile so they are read on subsequent Chef runs -v0.2.0 ------- +## v0.2.0 + - Updated README to require Ruby 1.9 - Allow hypens in hostnames - Ensure newline at end of file - Allow priority ordering in hostsfile -v0.1.1 ------- +## v0.1.1 + - Fixed issue #1 - Better unique object filtering - Better handing of aliases -v0.1.0 ------- +## v0.1.0 + - Initial release diff --git a/cookbooks/hostsfile/CONTRIBUTING.md b/cookbooks/hostsfile/CONTRIBUTING.md new file mode 100644 index 0000000..2431ee0 --- /dev/null +++ b/cookbooks/hostsfile/CONTRIBUTING.md @@ -0,0 +1,6 @@ +# Contributing + +1. Fork the project +2. Create a feature branch corresponding to you change +3. Commit and test thoroughly +4. Create a Pull Request on GitHub diff --git a/cookbooks/hostsfile/README.md b/cookbooks/hostsfile/README.md index f4574ce..16e0472 100644 --- a/cookbooks/hostsfile/README.md +++ b/cookbooks/hostsfile/README.md @@ -1,71 +1,31 @@ -hostsfile LWRP -============== -[![Build Status](https://travis-ci.org/customink-webops/hostsfile.png?branch=master)](https://travis-ci.org/customink-webops/hostsfile) +# hostsfile cookbook -`hostsfile` provides an LWRP for managing your `/etc/hosts` (or Windows equivalent) file using Chef. +[![Build Status](https://travis-ci.org/customink-webops/hostsfile.svg?branch=master)](https://travis-ci.org/customink-webops/hostsfile) +`hostsfile` provides a resource for managing your `/etc/hosts` (or Windows equivalent) file using Chef. -Requirements ------------- -- Chef 11 or higher -- **Ruby 1.9.3 or higher** +## Requirements -**Please stop opening Pull Requests to restore Ruby 1.8 support!** Any of the `1.x.y` series of this cookbook will work with Chef 10 and Ruby 1.8. You can use Opscode's [Omnibus installer](http://www.opscode.com/blog/2012/06/29/omnibus-chef-packaging/) to install Ruby 1.9+ and Seth Chisamore's [Vagrant Omnibus plugin](https://github.com/schisamo/vagrant-omnibus) to get Ruby 1.9+ on your Vagrant box. +- Chef 12.7 or higher +## Attributes -Attributes ----------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AttributeDescriptionExampleDefault
ip_address(name attribute) the IP address for the entry1.2.3.4
hostname(required) the hostname associated with the entryexample.com
uniqueremove any existing entries that have the same hostnametruefalse
aliasesarray of aliases for the entry['www.example.com'][]
commenta comment to append to the end of the entry'interal DNS server'nil
prioritythe relative position of this entry20(varies, see **Priorities** section)
+Attribute | Description | Example | Default +---------- | ------------------------------------------------------- | -------------------- | ------------------------------------ +ip_address | (name attribute) the IP address for the entry | 1.2.3.4 | +hostname | (required) the hostname associated with the entry | example.com | +unique | remove any existing entries that have the same hostname | true | false +aliases | array of aliases for the entry | ['www.example.com'] | [] +comment | a comment to append to the end of the entry | 'interal DNS server' | nil +priority | the relative position of this entry | 20 | (varies, see **Priorities** section) +## Actions -Actions -------- **Please note**: In `v0.1.2`, specifying a hostname or alias that existed in another automatically removed that hostname from the other entry before. In `v2.1.0`, the `unique` option was added to give the user case-by-case control of this behavior. For example, given an `/etc/hosts` file that contains: - 1.2.3.4 example.com www.example.com +``` +1.2.3.4 example.com www.example.com +``` when the Chef recipe below is converged: @@ -78,12 +38,15 @@ end then the `/etc/hosts` file will look like this: - 1.2.3.4 example.com - 2.3.4.5 www.example.com +``` +1.2.3.4 example.com +2.3.4.5 www.example.com +``` Not specifying the `unique` parameter will result in duplicate hostsfile entries. -#### `create` +### `create` + Creates a new hosts file entry. If an entry already exists, it will be overwritten by this one. ```ruby @@ -95,9 +58,12 @@ end This will create an entry like this: - 1.2.3.4 example.com +``` +1.2.3.4 example.com +``` + +### `create_if_missing` -#### `create_if_missing` Create a new hosts file entry, only if one does not already exist for the given IP address. If one exists, this does nothing. ```ruby @@ -107,10 +73,13 @@ hostsfile_entry '1.2.3.4' do end ``` -#### `append` +### `append` + Append a hostname or alias to an existing record. If the given IP address doesn't already exist in the hostsfile, this method behaves the same as create. Otherwise, it will append the additional hostname and aliases to the existing entry. - 1.2.3.4 example.com www.example.com # Created by Chef +``` +1.2.3.4 example.com www.example.com # Created by Chef +``` ```ruby hostsfile_entry '1.2.3.4' do @@ -123,10 +92,12 @@ end would yield: - 1.2.3.4 example.com www.example.com www2.example.com foo.com foobar.com # Created by Chef, Appended by Recipe X +``` +1.2.3.4 example.com www.example.com www2.example.com foo.com foobar.com # Created by Chef, Appended by Recipe X +``` +### `update` -#### `update` Updates the given hosts file entry. Does nothing if the entry does not exist. ```ruby @@ -139,11 +110,13 @@ end This will create an entry like this: - 1.2.3.4 example # Updated by Chef +``` +1.2.3.4 example # Updated by Chef +``` -#### `remove` -Removes an entry from the hosts file. Does nothing if the entry does not -exist. +### `remove` + +Removes an entry from the hosts file. Does nothing if the entry does not exist. ```ruby hostsfile_entry '1.2.3.4' do @@ -153,9 +126,8 @@ end This will remove the entry for `1.2.3.4`. +## Usage -Usage ------ If you're using [Berkshelf](http://berkshelf.com/), just add `hostsfile` to your `Berksfile`: ```ruby @@ -164,9 +136,11 @@ cookbook 'hostsfile' Otherwise, install the cookbook from the community site: - knife cookbook site install hostsfile +``` +knife cookbook site install hostsfile +``` -Have any other cookbooks *depend* on hostsfile by editing editing the `metadata.rb` for your cookbook. +Have any other cookbooks _depend_ on hostsfile by editing editing the `metadata.rb` for your cookbook. ```ruby # metadata.rb @@ -176,7 +150,8 @@ depends 'hostsfile' Note that you can specify a custom path to your hosts file in the `['hostsfile']['path']` node attribute. Otherwise, it defaults to sensible paths depending on your OS. ### Testing -If you are using [ChefSpec](https://github.com/sethvargo/chefspec) to unit test a cookbook that implements the `hostsfile_entry` LWRP, this cookbook packages customer matchers that you can use in your unit tests: + +If you are using [ChefSpec](https://github.com/sethvargo/chefspec) to unit test a cookbook that implements the `hostsfile_entry` resource, this cookbook packages customer matchers that you can use in your unit tests: - `append_hostsfile_entry` - `create_hostsfile_entry` @@ -193,27 +168,21 @@ it 'creates a hostsfile entry for the DNS server' do end ``` -Priority --------- +## Priority + Priority is a relatively new addition to the cookbook. It gives you the ability to (somewhat) specify the relative order of entries. By default, the priority is calculated for you as follows: -1. Local, loopback -2. IPV4 -3. IPV6 +82. 127.0.0.1 +81. ::1 +80. 127.0.0.0/8 +60. IPV4 +20. IPV6 +00. default However, you can override it using the `priority` option. +## License & Authors -Contributing ------------- -1. Fork the project -2. Create a feature branch corresponding to you change -3. Commit and test thoroughly -4. Create a Pull Request on github - - -License & Authors ------------------ - Author:: Seth Vargo (sethvargo@gmail.com) ```text diff --git a/cookbooks/hostsfile/attributes/default.rb b/cookbooks/hostsfile/attributes/default.rb index d9175e6..a6a9707 100644 --- a/cookbooks/hostsfile/attributes/default.rb +++ b/cookbooks/hostsfile/attributes/default.rb @@ -3,8 +3,8 @@ # Cookbook:: hostsfile # Attribute:: default # -# Copyright 2012-2013, Seth Vargo -# Copyright 2012, CustomInk, LCC +# Copyright:: 2012-2013, Seth Vargo +# Copyright:: 2012, CustomInk, LCC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/cookbooks/hostsfile/libraries/entry.rb b/cookbooks/hostsfile/libraries/entry.rb index 53b79db..57ddf7b 100644 --- a/cookbooks/hostsfile/libraries/entry.rb +++ b/cookbooks/hostsfile/libraries/entry.rb @@ -3,8 +3,8 @@ # Cookbook:: hostsfile # Library:: entry # -# Copyright 2012-2013, Seth Vargo -# Copyright 2012, CustomInk, LCC +# Copyright:: 2012-2013, Seth Vargo +# Copyright:: 2012, CustomInk, LCC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,160 +24,163 @@ require 'ipaddr' # An object representation of a single line in a hostsfile. # # @author Seth Vargo -class Entry - class << self - # Creates a new Hostsfile::Entry object by parsing a text line. The - # `line` attribute will be in the following format: - # - # 1.2.3.4 hostname [alias[, alias[, alias]]] [# comment [@priority]] - # - # @param [String] line - # the line to parse - # @return [Entry] - # a new entry object - def parse(line) - entry, comment = extract_comment(line) - comment, priority = extract_priority(comment) - entries = extract_entries(entry) +module HostsFile + class Entry + class << self + # Creates a new Hostsfile::Entry object by parsing a text line. The + # `line` attribute will be in the following format: + # + # 1.2.3.4 hostname [alias[, alias[, alias]]] [# comment [@priority]] + # + # @param [String] line + # the line to parse + # @return [Entry] + # a new entry object + def parse(line) + entry, comment = extract_comment(line) + comment, priority = extract_priority(comment) + entries = extract_entries(entry) - # Return nil if the line is empty - return nil if entries.nil? || entries.empty? + # Return nil if the line is empty + return nil if entries.nil? || entries.empty? - # If /etc/hosts has a broken content we throw a descriptive exception - if entries[0].nil? - raise ArgumentError, "/etc/hosts has a line without IP address: #{line}" - end - if entries[1].nil? - raise ArgumentError, "/etc/hosts has a line without hostname: #{line}" + # If /etc/hosts has a broken content we throw a descriptive exception + if entries[0].nil? + raise ArgumentError, "/etc/hosts has a line without IP address: #{line}" + end + if entries[1].nil? + raise ArgumentError, "/etc/hosts has a line without hostname: #{line}" + end + + new( + ip_address: entries[0], + hostname: entries[1], + aliases: entries[2..-1], + comment: comment, + priority: priority + ) end - return self.new( - ip_address: entries[0], - hostname: entries[1], - aliases: entries[2..-1], - comment: comment, - priority: priority, - ) + private + + def extract_comment(line) + return nil if presence(line).nil? + line.split('#', 2).collect { |part| presence(part) } + end + + def extract_priority(comment) + return nil if comment.nil? + + if comment.include?('@') + comment.split('@', 2).collect { |part| presence(part) } + else + [comment, nil] + end + end + + def extract_entries(entry) + return nil if entry.nil? + entry.split(/\s+/).collect { |entry| presence(entry) }.compact + end + + def presence(string) + return nil if string.nil? + return nil if string.strip.empty? + string.strip + end + end + + # @return [String] + attr_accessor :ip_address, :hostname, :aliases, :comment, :priority + + # Creates a new entry from the given options. + # + # @param [Hash] options + # a list of options to create the entry with + # @option options [String] :ip_address + # the IP Address for this entry + # @option options [String] :hostname + # the hostname for this entry + # @option options [String, Array] :aliases + # a alias or array of aliases for this entry + # @option options[String] :comment + # an optional comment for this entry + # @option options [Integer] :priority + # the relative priority of this entry (compared to others) + # + # @raise [ArgumentError] + # if neither :ip_address nor :hostname are supplied + def initialize(options = {}) + if options[:ip_address].nil? || options[:hostname].nil? + raise ArgumentError, ':ip_address and :hostname are both required options' + end + + @ip_address = IPAddr.new(remove_ip_scope(options[:ip_address])) + @hostname = options[:hostname] + @aliases = [options[:aliases]].flatten.compact + @comment = options[:comment] + @priority = options[:priority] || calculated_priority + end + + # Set a the new priority for an entry. + # + # @param [Integer] new_priority + # the new priority to set + def priority=(new_priority) + @calculated_priority = false + @priority = new_priority + end + + # The line representation of this entry. + # + # @return [String] + # the string representation of this entry + def to_line + hosts = [hostname, aliases].flatten.join(' ') + + comments = "# #{comment}".strip + comments << " @#{priority}" unless priority.nil? || @calculated_priority + comments = comments.strip + comments = nil if comments == '#' + + [ip_address, hosts, comments].compact.join("\t").strip + end + + # Returns true if priority is calculated + # + # @return [Boolean] + # true if priority is calculated and false otherwise + def calculated_priority? + @calculated_priority end private - def extract_comment(line) - return nil if presence(line).nil? - line.split('#', 2).collect { |part| presence(part) } + # Calculates the relative priority of this entry. + # + # @return [Integer] + # the relative priority of this item + def calculated_priority + @calculated_priority = true + + return 82 if ip_address == IPAddr.new('127.0.0.1') + return 81 if ip_address == IPAddr.new('::1') + return 80 if IPAddr.new('127.0.0.0/8').include?(ip_address) # local + return 60 if ip_address.ipv4? # ipv4 + return 20 if ip_address.ipv6? # ipv6 + 00 end - def extract_priority(comment) - return nil if comment.nil? - - if comment.include?('@') - comment.split('@', 2).collect { |part| presence(part) } - else - [comment, nil] - end + # Removes the scopes pieces of the address, because reasons. + # + # @see https://bugs.ruby-lang.org/issues/8464 + # @see https://github.com/customink-webops/hostsfile/issues/51 + # + # @return [String, nil] + # + def remove_ip_scope(address) + return nil if address.nil? + address.to_s.sub(/%.*/, '') end - - def extract_entries(entry) - return nil if entry.nil? - entry.split(/\s+/).collect { |entry| presence(entry) }.compact - end - - def presence(string) - return nil if string.nil? - return nil if string.strip.empty? - string.strip - end - end - - # @return [String] - attr_accessor :ip_address, :hostname, :aliases, :comment, :priority - - # Creates a new entry from the given options. - # - # @param [Hash] options - # a list of options to create the entry with - # @option options [String] :ip_address - # the IP Address for this entry - # @option options [String] :hostname - # the hostname for this entry - # @option options [String, Array] :aliases - # a alias or array of aliases for this entry - # @option options[String] :comment - # an optional comment for this entry - # @option options [Fixnum] :priority - # the relative priority of this entry (compared to others) - # - # @raise [ArgumentError] - # if neither :ip_address nor :hostname are supplied - def initialize(options = {}) - if options[:ip_address].nil? || options[:hostname].nil? - raise ArgumentError, ':ip_address and :hostname are both required options' - end - - @ip_address = IPAddr.new(remove_ip_scope(options[:ip_address])) - @hostname = options[:hostname] - @aliases = [options[:aliases]].flatten.compact - @comment = options[:comment] - @priority = options[:priority] || calculated_priority - end - - # Set a the new priority for an entry. - # - # @param [Fixnum] new_priority - # the new priority to set - def priority=(new_priority) - @calculated_priority = false - @priority = new_priority - end - - # The line representation of this entry. - # - # @return [String] - # the string representation of this entry - def to_line - hosts = [hostname, aliases].flatten.join(' ') - - comments = "# #{comment.to_s}".strip - comments << " @#{priority}" unless priority.nil? || @calculated_priority - comments = comments.strip - comments = nil if comments == '#' - - [ip_address, hosts, comments].compact.join("\t").strip - end - - # Returns true if priority is calculated - # - # @return [Boolean] - # true if priority is calculated and false otherwise - def calculated_priority? - @calculated_priority - end - - private - - # Calculates the relative priority of this entry. - # - # @return [Fixnum] - # the relative priority of this item - def calculated_priority - @calculated_priority = true - - return 81 if ip_address == IPAddr.new('127.0.0.1') - return 80 if IPAddr.new('127.0.0.0/8').include?(ip_address) # local - return 60 if ip_address.ipv4? # ipv4 - return 20 if ip_address.ipv6? # ipv6 - return 00 - end - - # Removes the scopes pieces of the address, because reasons. - # - # @see https://bugs.ruby-lang.org/issues/8464 - # @see https://github.com/customink-webops/hostsfile/issues/51 - # - # @return [String, nil] - # - def remove_ip_scope(address) - return nil if address.nil? - address.to_s.sub(/%.*/, '') end end diff --git a/cookbooks/hostsfile/libraries/manipulator.rb b/cookbooks/hostsfile/libraries/manipulator.rb index 6afc047..c215326 100644 --- a/cookbooks/hostsfile/libraries/manipulator.rb +++ b/cookbooks/hostsfile/libraries/manipulator.rb @@ -3,8 +3,8 @@ # Cookbook:: hostsfile # Library:: manipulator # -# Copyright 2012-2013, Seth Vargo -# Copyright 2012, CustomInk, LCC +# Copyright:: 2012-2013, Seth Vargo +# Copyright:: 2012, CustomInk, LCC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,274 +20,283 @@ # require 'chef/application' -require 'digest/sha2' +require 'openssl' -class Manipulator - attr_reader :node - attr_reader :entries +module HostsFile + class Manipulator + attr_reader :node + attr_reader :entries - # Create a new Manipulator object (aka an /etc/hosts manipulator). If a - # hostsfile is not found, an exception is raised. - # - # @param [Chef::node] node - # the current Chef node - # @return [Manipulator] - # a class designed to manipulate the node's /etc/hosts file - def initialize(node) - @node = node + # Create a new Manipulator object (aka an /etc/hosts manipulator). If a + # hostsfile is not found, an exception is raised. + # + # @param [Chef::node] node + # the current Chef node + # @return [Manipulator] + # a class designed to manipulate the node's /etc/hosts file + def initialize(node) + @node = node - # Fail if no hostsfile is found - unless ::File.exists?(hostsfile_path) - raise RuntimeError, "No hostsfile exists at `#{hostsfile_path}'!" - end - - @entries = [] - collect_and_flatten(::File.readlines(hostsfile_path)) - end - - # Return a list of all IP Addresses for this hostsfile. - # - # @return [Array] - # the list of IP Addresses - def ip_addresses - @entries.collect do |entry| - entry.ip_address - end.compact || [] - end - - # Add a new record to the hostsfile. - # - # @param [Hash] options - # a list of options to create the entry with - # @option options [String] :ip_address - # the IP Address for this entry - # @option options [String] :hostname - # the hostname for this entry - # @option options [String, Array] :aliases - # a alias or array of aliases for this entry - # @option options[String] :comment - # an optional comment for this entry - # @option options [Fixnum] :priority - # the relative priority of this entry (compared to others) - def add(options = {}) - entry = Entry.new( - ip_address: options[:ip_address], - hostname: options[:hostname], - aliases: options[:aliases], - comment: options[:comment], - priority: options[:priority], - ) - - @entries << entry - remove_existing_hostnames(entry) if options[:unique] - end - - # Update an existing entry. This method will do nothing if the entry - # does not exist. - # - # @param (see #add) - def update(options = {}) - if entry = find_entry_by_ip_address(options[:ip_address]) - entry.hostname = options[:hostname] - entry.aliases = options[:aliases] - entry.comment = options[:comment] - entry.priority = options[:priority] - - remove_existing_hostnames(entry) if options[:unique] - end - end - - # Append content to an existing entry. This method will add a new entry - # if one does not already exist. - # - # @param (see #add) - def append(options = {}) - if entry = find_entry_by_ip_address(options[:ip_address]) - hosts = normalize(entry.hostname, entry.aliases, options[:hostname], options[:aliases]) - entry.hostname = hosts.shift - entry.aliases = hosts - - unless entry.comment && options[:comment] && entry.comment.include?(options[:comment]) - entry.comment = normalize(entry.comment, options[:comment]).join(', ') + # Fail if no hostsfile is found + unless ::File.exist?(hostsfile_path) + raise "No hostsfile exists at `#{hostsfile_path}'!" end - remove_existing_hostnames(entry) if options[:unique] - else - add(options) + @entries = [] + collect_and_flatten(::File.readlines(hostsfile_path)) end - end - # Remove an entry by it's IP Address - # - # @param [String] ip_address - # the IP Address of the entry to remove - def remove(ip_address) - if entry = find_entry_by_ip_address(ip_address) - @entries.delete(entry) + # Return a list of all IP Addresses for this hostsfile. + # + # @return [Array] + # the list of IP Addresses + def ip_addresses + @entries.collect(&:ip_address).compact || [] end - end - # Save the new hostsfile to the target machine. This method will only write the - # hostsfile if the current version has changed. In other words, it is convergent. - def save - file = Chef::Resource::File.new(hostsfile_path, node.run_context) - file.content(new_content) - file.run_action(:create) - end - - # Determine if the content of the hostfile has changed by comparing sha - # values of existing file and new content - # - # @return [Boolean] - def content_changed? - new_sha = Digest::SHA512.hexdigest(new_content) - new_sha != current_sha - end - - # Find an entry by the given IP Address. - # - # @param [String] ip_address - # the IP Address of the entry to find - # @return [Entry, nil] - # the corresponding entry object, or nil if it does not exist - def find_entry_by_ip_address(ip_address) - @entries.find do |entry| - !entry.ip_address.nil? && entry.ip_address == ip_address - end - end - - # Determine if the current hostsfile contains the given resource. This - # is really just a proxy to {find_resource_by_ip_address} / - # - # @param [Chef::Resource] resource - # - # @return [Boolean] - def contains?(resource) - !!find_entry_by_ip_address(resource.ip_address) - end - - private - - # The path to the current hostsfile. - # - # @return [String] - # the full path to the hostsfile, depending on the operating system - # can also be overriden in the node attributes - def hostsfile_path - return @hostsfile_path if @hostsfile_path - @hostsfile_path = node['hostsfile']['path'] || case node['platform_family'] - when 'windows' - "#{node['kernel']['os_info']['system_directory']}\\drivers\\etc\\hosts" - else - '/etc/hosts' - end - end - - # The header of the new hostsfile - # - # @return [Array] - # an array of header comments - def hostsfile_header - lines = [] - lines << '#' - lines << '# This file is managed by Chef, using the hostsfile cookbook.' - lines << '# Editing this file by hand is highly discouraged!' - lines << '#' - lines << '# Comments containing an @ sign should not be modified or else' - lines << '# hostsfile will be unable to guarantee relative priority in' - lines << '# future Chef runs!' - lines << '#' - lines << '' - end - - # The content that will be written to the hostfile - # - # @return [String] - # the full contents of the hostfile to be written - def new_content - entries = hostsfile_header - entries += unique_entries.map(&:to_line) - entries << '' - entries.join("\n") - end - - # The current sha of the system hostsfile. - # - # @return [String] - # the sha of the current hostsfile - def current_sha - @current_sha ||= Digest::SHA512.hexdigest(File.read(hostsfile_path)) - end - - # Normalize the given list of elements into a single array with no nil - # values and no duplicate values. - # - # @param [Object] things - # - # @return [Array] - # a normalized array of things - def normalize(*things) - things.flatten.compact.uniq - end - - # This is a crazy way of ensuring unique objects in an array using a Hash. - # - # @return [Array] - # the sorted list of entires that are unique - def unique_entries - entries = Hash[*@entries.map { |entry| [entry.ip_address, entry] }.flatten].values - entries.sort_by { |e| [-e.priority.to_i, e.hostname.to_s] } - end - - # Takes /etc/hosts file contents and builds a flattened entries - # array so that each IP address has only one line and multiple hostnames - # are flattened into a list of aliases. - # - # @param [Array] contents - # Array of lines from /etc/hosts file - def collect_and_flatten(contents) - contents.each do |line| - entry = Entry.parse(line) - next if entry.nil? - - append( - ip_address: entry.ip_address, - hostname: entry.hostname, - aliases: entry.aliases, - comment: entry.comment, - priority: !entry.calculated_priority? && entry.priority, + # Add a new record to the hostsfile. + # + # @param [Hash] options + # a list of options to create the entry with + # @option options [String] :ip_address + # the IP Address for this entry + # @option options [String] :hostname + # the hostname for this entry + # @option options [String, Array] :aliases + # a alias or array of aliases for this entry + # @option options[String] :comment + # an optional comment for this entry + # @option options [Integer] :priority + # the relative priority of this entry (compared to others) + def add(options = {}) + entry = HostsFile::Entry.new( + ip_address: options[:ip_address], + hostname: options[:hostname], + aliases: options[:aliases], + comment: options[:comment], + priority: options[:priority] ) + + @entries << entry + remove_existing_hostnames(entry) if options[:unique] end - end - # Removes duplicate hostnames in other files ensuring they are unique - # - # @param [Entry] entry - # the entry to keep the hostname and aliases from - # - # @return [nil] - def remove_existing_hostnames(entry) - @entries.delete(entry) - changed_hostnames = [entry.hostname, entry.aliases].flatten.uniq + # Update an existing entry. This method will do nothing if the entry + # does not exist. + # + # @param (see #add) + def update(options = {}) + if entry = find_entry_by_ip_address(options[:ip_address]) + entry.hostname = options[:hostname] + entry.aliases = options[:aliases] + entry.comment = options[:comment] + entry.priority = options[:priority] - @entries = @entries.collect do |entry| - entry.hostname = nil if changed_hostnames.include?(entry.hostname) - entry.aliases = entry.aliases - changed_hostnames + remove_existing_hostnames(entry) if options[:unique] + end + end - if entry.hostname.nil? - if entry.aliases.empty? - nil + # Append content to an existing entry. This method will add a new entry + # if one does not already exist. + # + # @param (see #add) + def append(options = {}) + if entry = find_entry_by_ip_address(options[:ip_address]) + hosts = normalize(entry.hostname, entry.aliases, options[:hostname], options[:aliases]) + entry.hostname = hosts.shift + entry.aliases = hosts + + unless entry.comment && options[:comment] && entry.comment.include?(options[:comment]) + entry.comment = normalize(entry.comment, options[:comment]).join(', ') + end + + remove_existing_hostnames(entry) if options[:unique] + else + add(options) + end + end + + # Remove an entry by it's IP Address + # + # @param [String] ip_address + # the IP Address of the entry to remove + def remove(ip_address) + if entry = find_entry_by_ip_address(ip_address) + @entries.delete(entry) + end + end + + # Save the new hostsfile to the target machine. This method will only write the + # hostsfile if the current version has changed. In other words, it is convergent. + def save + file = Chef::Resource::File.new(hostsfile_path, node.run_context) + file.content(new_content) + file.atomic_update false if docker_guest? + file.run_action(:create) + end + + # Determine if the content of the hostfile has changed by comparing sha + # values of existing file and new content + # + # @return [Boolean] + def content_changed? + new_sha = OpenSSL::Digest::SHA512.hexdigest(new_content) + new_sha != current_sha + end + + # Find an entry by the given IP Address. + # + # @param [String] ip_address + # the IP Address of the entry to find + # @return [Entry, nil] + # the corresponding entry object, or nil if it does not exist + def find_entry_by_ip_address(ip_address) + @entries.find do |entry| + !entry.ip_address.nil? && entry.ip_address == ip_address + end + end + + # Determine if the current hostsfile contains the given resource. This + # is really just a proxy to {find_resource_by_ip_address} / + # + # @param [Chef::Resource] resource + # + # @return [Boolean] + def contains?(resource) + !!find_entry_by_ip_address(resource.ip_address) + end + + private + + # Determine if we are running inside a Docker container + # + # @return [Boolean] + def docker_guest? + node['virtualization'] && node['virtualization']['systems'] && + node['virtualization']['systems']['docker'] && node['virtualization']['systems']['docker'] == 'guest' + end + + # The path to the current hostsfile. + # + # @return [String] + # the full path to the hostsfile, depending on the operating system + # can also be overriden in the node attributes + def hostsfile_path + return @hostsfile_path if @hostsfile_path + @hostsfile_path = node['hostsfile']['path'] || case node['platform_family'] + when 'windows' + "#{node['kernel']['os_info']['system_directory']}\\drivers\\etc\\hosts" + else + '/etc/hosts' + end + end + + # The header of the new hostsfile + # + # @return [Array] + # an array of header comments + def hostsfile_header + lines = [] + lines << '#' + lines << '# This file is managed by Chef, using the hostsfile cookbook.' + lines << '# Editing this file by hand is highly discouraged!' + lines << '#' + lines << '# Comments containing an @ sign should not be modified or else' + lines << '# hostsfile will be unable to guarantee relative priority in' + lines << '# future Chef runs!' + lines << '#' + lines << '' + end + + # The content that will be written to the hostfile + # + # @return [String] + # the full contents of the hostfile to be written + def new_content + entries = hostsfile_header + entries += unique_entries.map(&:to_line) + entries << '' + entries.join("\n") + end + + # The current sha of the system hostsfile. + # + # @return [String] + # the sha of the current hostsfile + def current_sha + @current_sha ||= OpenSSL::Digest::SHA512.hexdigest(File.read(hostsfile_path)) + end + + # Normalize the given list of elements into a single array with no nil + # values and no duplicate values. + # + # @param [Object] things + # + # @return [Array] + # a normalized array of things + def normalize(*things) + things.flatten.compact.uniq + end + + # This is a crazy way of ensuring unique objects in an array using a Hash. + # + # @return [Array] + # the sorted list of entires that are unique + def unique_entries + entries = Hash[*@entries.map { |entry| [entry.ip_address, entry] }.flatten].values + entries.sort_by { |e| [-e.priority.to_i, e.hostname.to_s] } + end + + # Takes /etc/hosts file contents and builds a flattened entries + # array so that each IP address has only one line and multiple hostnames + # are flattened into a list of aliases. + # + # @param [Array] contents + # Array of lines from /etc/hosts file + def collect_and_flatten(contents) + contents.each do |line| + entry = HostsFile::Entry.parse(line) + next if entry.nil? + + append( + ip_address: entry.ip_address, + hostname: entry.hostname, + aliases: entry.aliases, + comment: entry.comment, + priority: !entry.calculated_priority? && entry.priority + ) + end + end + + # Removes duplicate hostnames in other files ensuring they are unique + # + # @param [Entry] entry + # the entry to keep the hostname and aliases from + # + # @return [nil] + def remove_existing_hostnames(entry) + @entries.delete(entry) + changed_hostnames = [entry.hostname, entry.aliases].flatten.uniq + + @entries = @entries.collect do |entry| + entry.hostname = nil if changed_hostnames.include?(entry.hostname) + entry.aliases = entry.aliases - changed_hostnames + + if entry.hostname.nil? + if entry.aliases.empty? + nil + else + entry.hostname = entry.aliases.shift + entry + end else - entry.hostname = entry.aliases.shift entry end - else - entry - end - end.compact + end.compact - @entries << entry + @entries << entry - nil + nil + end end end diff --git a/cookbooks/hostsfile/metadata.json b/cookbooks/hostsfile/metadata.json index c2296cf..d93c2fc 100644 --- a/cookbooks/hostsfile/metadata.json +++ b/cookbooks/hostsfile/metadata.json @@ -1,29 +1 @@ -{ - "name": "hostsfile", - "version": "2.4.5", - "description": "Provides an LWRP for managing the /etc/hosts file", - "long_description": "hostsfile LWRP\n==============\n[![Build Status](https://travis-ci.org/customink-webops/hostsfile.png?branch=master)](https://travis-ci.org/customink-webops/hostsfile)\n\n`hostsfile` provides an LWRP for managing your `/etc/hosts` (or Windows equivalent) file using Chef.\n\n\nRequirements\n------------\n- Chef 11 or higher\n- **Ruby 1.9.3 or higher**\n\n**Please stop opening Pull Requests to restore Ruby 1.8 support!** Any of the `1.x.y` series of this cookbook will work with Chef 10 and Ruby 1.8. You can use Opscode's [Omnibus installer](http://www.opscode.com/blog/2012/06/29/omnibus-chef-packaging/) to install Ruby 1.9+ and Seth Chisamore's [Vagrant Omnibus plugin](https://github.com/schisamo/vagrant-omnibus) to get Ruby 1.9+ on your Vagrant box.\n\n\nAttributes\n----------\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
AttributeDescriptionExampleDefault
ip_address(name attribute) the IP address for the entry1.2.3.4
hostname(required) the hostname associated with the entryexample.com
uniqueremove any existing entries that have the same hostnametruefalse
aliasesarray of aliases for the entry['www.example.com'][]
commenta comment to append to the end of the entry'interal DNS server'nil
prioritythe relative position of this entry20(varies, see **Priorities** section)
\n\n\nActions\n-------\n**Please note**: In `v0.1.2`, specifying a hostname or alias that existed in another automatically removed that hostname from the other entry before. In `v2.1.0`, the `unique` option was added to give the user case-by-case control of this behavior. For example, given an `/etc/hosts` file that contains:\n\n 1.2.3.4 example.com www.example.com\n\nwhen the Chef recipe below is converged:\n\n```ruby\nhostsfile_entry '2.3.4.5' do\n hostname 'www.example.com'\n unique true\nend\n```\n\nthen the `/etc/hosts` file will look like this:\n\n 1.2.3.4 example.com\n 2.3.4.5 www.example.com\n\nNot specifying the `unique` parameter will result in duplicate hostsfile entries.\n\n#### `create`\nCreates a new hosts file entry. If an entry already exists, it will be overwritten by this one.\n\n```ruby\nhostsfile_entry '1.2.3.4' do\n hostname 'example.com'\n action :create\nend\n```\n\nThis will create an entry like this:\n\n 1.2.3.4 example.com\n\n#### `create_if_missing`\nCreate a new hosts file entry, only if one does not already exist for the given IP address. If one exists, this does nothing.\n\n```ruby\nhostsfile_entry '1.2.3.4' do\n hostname 'example.com'\n action :create_if_missing\nend\n```\n\n#### `append`\nAppend a hostname or alias to an existing record. If the given IP address doesn't already exist in the hostsfile, this method behaves the same as create. Otherwise, it will append the additional hostname and aliases to the existing entry.\n\n 1.2.3.4 example.com www.example.com # Created by Chef\n\n```ruby\nhostsfile_entry '1.2.3.4' do\n hostname 'www2.example.com'\n aliases ['foo.com', 'foobar.com']\n comment 'Append by Recipe X'\n action :append\nend\n```\n\nwould yield:\n\n 1.2.3.4 example.com www.example.com www2.example.com foo.com foobar.com # Created by Chef, Appended by Recipe X\n\n\n#### `update`\nUpdates the given hosts file entry. Does nothing if the entry does not exist.\n\n```ruby\nhostsfile_entry '1.2.3.4' do\n hostname 'example.com'\n comment 'Update by Chef'\n action :update\nend\n```\n\nThis will create an entry like this:\n\n 1.2.3.4 example # Updated by Chef\n\n#### `remove`\nRemoves an entry from the hosts file. Does nothing if the entry does not\nexist.\n\n```ruby\nhostsfile_entry '1.2.3.4' do\n action :remove\nend\n```\n\nThis will remove the entry for `1.2.3.4`.\n\n\nUsage\n-----\nIf you're using [Berkshelf](http://berkshelf.com/), just add `hostsfile` to your `Berksfile`:\n\n```ruby\ncookbook 'hostsfile'\n```\n\nOtherwise, install the cookbook from the community site:\n\n knife cookbook site install hostsfile\n\nHave any other cookbooks *depend* on hostsfile by editing editing the `metadata.rb` for your cookbook.\n\n```ruby\n# metadata.rb\ndepends 'hostsfile'\n```\n\nNote that you can specify a custom path to your hosts file in the `['hostsfile']['path']` node attribute. Otherwise, it defaults to sensible paths depending on your OS.\n\n### Testing\nIf you are using [ChefSpec](https://github.com/sethvargo/chefspec) to unit test a cookbook that implements the `hostsfile_entry` LWRP, this cookbook packages customer matchers that you can use in your unit tests:\n\n- `append_hostsfile_entry`\n- `create_hostsfile_entry`\n- `create_hostsfile_entry_if_missing`\n- `remove_hostsfile_entry`\n- `update_hostsfile_entry`\n\nFor example:\n\n```ruby\nit 'creates a hostsfile entry for the DNS server' do\n expect(chef_run).to create_hostsfile_entry('1.2.3.4')\n .with_hostname('dns.example.com')\nend\n```\n\nPriority\n--------\nPriority is a relatively new addition to the cookbook. It gives you the ability to (somewhat) specify the relative order of entries. By default, the priority is calculated for you as follows:\n\n1. Local, loopback\n2. IPV4\n3. IPV6\n\nHowever, you can override it using the `priority` option.\n\n\nContributing\n------------\n1. Fork the project\n2. Create a feature branch corresponding to you change\n3. Commit and test thoroughly\n4. Create a Pull Request on github\n\n\nLicense & Authors\n-----------------\n- Author:: Seth Vargo (sethvargo@gmail.com)\n\n```text\nCopyright 2012-2013, Seth Vargo\nCopyright 2012, CustomInk, LLC\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n", - "maintainer": "Seth Vargo", - "maintainer_email": "sethvargo@gmail.com", - "license": "Apache 2.0", - "platforms": { - }, - "dependencies": { - }, - "recommendations": { - }, - "suggestions": { - }, - "conflicting": { - }, - "providing": { - }, - "replacing": { - }, - "attributes": { - }, - "groupings": { - }, - "recipes": { - } -} \ No newline at end of file +{"name":"hostsfile","version":"3.0.1","description":"Provides an resource for managing the /etc/hosts file","long_description":"# hostsfile cookbook\n\n[![Build Status](https://travis-ci.org/customink-webops/hostsfile.svg?branch=master)](https://travis-ci.org/customink-webops/hostsfile)\n\n`hostsfile` provides a resource for managing your `/etc/hosts` (or Windows equivalent) file using Chef.\n\n## Requirements\n\n- Chef 12.7 or higher\n\n## Attributes\n\nAttribute | Description | Example | Default\n---------- | ------------------------------------------------------- | -------------------- | ------------------------------------\nip_address | (name attribute) the IP address for the entry | 1.2.3.4 |\nhostname | (required) the hostname associated with the entry | example.com |\nunique | remove any existing entries that have the same hostname | true | false\naliases | array of aliases for the entry | ['www.example.com'] | []\ncomment | a comment to append to the end of the entry | 'interal DNS server' | nil\npriority | the relative position of this entry | 20 | (varies, see **Priorities** section)\n\n## Actions\n\n**Please note**: In `v0.1.2`, specifying a hostname or alias that existed in another automatically removed that hostname from the other entry before. In `v2.1.0`, the `unique` option was added to give the user case-by-case control of this behavior. For example, given an `/etc/hosts` file that contains:\n\n```\n1.2.3.4 example.com www.example.com\n```\n\nwhen the Chef recipe below is converged:\n\n```ruby\nhostsfile_entry '2.3.4.5' do\n hostname 'www.example.com'\n unique true\nend\n```\n\nthen the `/etc/hosts` file will look like this:\n\n```\n1.2.3.4 example.com\n2.3.4.5 www.example.com\n```\n\nNot specifying the `unique` parameter will result in duplicate hostsfile entries.\n\n### `create`\n\nCreates a new hosts file entry. If an entry already exists, it will be overwritten by this one.\n\n```ruby\nhostsfile_entry '1.2.3.4' do\n hostname 'example.com'\n action :create\nend\n```\n\nThis will create an entry like this:\n\n```\n1.2.3.4 example.com\n```\n\n### `create_if_missing`\n\nCreate a new hosts file entry, only if one does not already exist for the given IP address. If one exists, this does nothing.\n\n```ruby\nhostsfile_entry '1.2.3.4' do\n hostname 'example.com'\n action :create_if_missing\nend\n```\n\n### `append`\n\nAppend a hostname or alias to an existing record. If the given IP address doesn't already exist in the hostsfile, this method behaves the same as create. Otherwise, it will append the additional hostname and aliases to the existing entry.\n\n```\n1.2.3.4 example.com www.example.com # Created by Chef\n```\n\n```ruby\nhostsfile_entry '1.2.3.4' do\n hostname 'www2.example.com'\n aliases ['foo.com', 'foobar.com']\n comment 'Append by Recipe X'\n action :append\nend\n```\n\nwould yield:\n\n```\n1.2.3.4 example.com www.example.com www2.example.com foo.com foobar.com # Created by Chef, Appended by Recipe X\n```\n\n### `update`\n\nUpdates the given hosts file entry. Does nothing if the entry does not exist.\n\n```ruby\nhostsfile_entry '1.2.3.4' do\n hostname 'example.com'\n comment 'Update by Chef'\n action :update\nend\n```\n\nThis will create an entry like this:\n\n```\n1.2.3.4 example # Updated by Chef\n```\n\n### `remove`\n\nRemoves an entry from the hosts file. Does nothing if the entry does not exist.\n\n```ruby\nhostsfile_entry '1.2.3.4' do\n action :remove\nend\n```\n\nThis will remove the entry for `1.2.3.4`.\n\n## Usage\n\nIf you're using [Berkshelf](http://berkshelf.com/), just add `hostsfile` to your `Berksfile`:\n\n```ruby\ncookbook 'hostsfile'\n```\n\nOtherwise, install the cookbook from the community site:\n\n```\nknife cookbook site install hostsfile\n```\n\nHave any other cookbooks _depend_ on hostsfile by editing editing the `metadata.rb` for your cookbook.\n\n```ruby\n# metadata.rb\ndepends 'hostsfile'\n```\n\nNote that you can specify a custom path to your hosts file in the `['hostsfile']['path']` node attribute. Otherwise, it defaults to sensible paths depending on your OS.\n\n### Testing\n\nIf you are using [ChefSpec](https://github.com/sethvargo/chefspec) to unit test a cookbook that implements the `hostsfile_entry` resource, this cookbook packages customer matchers that you can use in your unit tests:\n\n- `append_hostsfile_entry`\n- `create_hostsfile_entry`\n- `create_hostsfile_entry_if_missing`\n- `remove_hostsfile_entry`\n- `update_hostsfile_entry`\n\nFor example:\n\n```ruby\nit 'creates a hostsfile entry for the DNS server' do\n expect(chef_run).to create_hostsfile_entry('1.2.3.4')\n .with_hostname('dns.example.com')\nend\n```\n\n## Priority\n\nPriority is a relatively new addition to the cookbook. It gives you the ability to (somewhat) specify the relative order of entries. By default, the priority is calculated for you as follows:\n\n82. 127.0.0.1\n81. ::1\n80. 127.0.0.0/8\n60. IPV4\n20. IPV6\n00. default\n\nHowever, you can override it using the `priority` option.\n\n## License & Authors\n\n- Author:: Seth Vargo (sethvargo@gmail.com)\n\n```text\nCopyright 2012-2013, Seth Vargo\nCopyright 2012, CustomInk, LLC\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"Seth Vargo","maintainer_email":"sethvargo@gmail.com","license":"Apache-2.0","platforms":{"all":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/customink-webops/hostsfile","issues_url":"https://github.com/customink-webops/hostsfile/issues","chef_version":[[">= 12.7"]],"ohai_version":[]} \ No newline at end of file diff --git a/cookbooks/hostsfile/metadata.rb b/cookbooks/hostsfile/metadata.rb deleted file mode 100644 index 5474e5d..0000000 --- a/cookbooks/hostsfile/metadata.rb +++ /dev/null @@ -1,7 +0,0 @@ -name 'hostsfile' -maintainer 'Seth Vargo' -maintainer_email 'sethvargo@gmail.com' -license 'Apache 2.0' -description 'Provides an LWRP for managing the /etc/hosts file' -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '2.4.5' diff --git a/cookbooks/hostsfile/providers/entry.rb b/cookbooks/hostsfile/providers/entry.rb deleted file mode 100644 index dde469a..0000000 --- a/cookbooks/hostsfile/providers/entry.rb +++ /dev/null @@ -1,138 +0,0 @@ -# -# Author:: Seth Vargo -# Cookbook:: hostsfile -# Provider:: entry -# -# Copyright 2012-2013, Seth Vargo -# Copyright 2012, CustomInk, LCC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# Support whyrun -def whyrun_supported? - true -end - -# Creates a new hosts file entry. If an entry already exists, it will be -# overwritten by this one. -action :create do - if hostsfile.contains?(new_resource) - Chef::Log.debug "#{new_resource} already exists - overwriting." - end - - hostsfile.add( - ip_address: new_resource.ip_address, - hostname: new_resource.hostname, - aliases: new_resource.aliases, - comment: new_resource.comment, - priority: new_resource.priority, - unique: new_resource.unique, - ) - - if hostsfile.content_changed? - converge_by("Create #{new_resource}") { hostsfile.save } - else - Chef::Log.info "#{new_resource} content already matches - nothing to do." - end -end - -# Create a new hosts file entry, only if one does not already exist for -# the given IP address. If one exists, this does nothing. -action :create_if_missing do - if hostsfile.contains?(new_resource) - Chef::Log.info "#{new_resource} already exists - skipping create_if_missing." - else - converge_by("Create #{new_resource} if missing") do - hostsfile.add( - ip_address: new_resource.ip_address, - hostname: new_resource.hostname, - aliases: new_resource.aliases, - comment: new_resource.comment, - priority: new_resource.priority, - unique: new_resource.unique, - ) - hostsfile.save - end - end -end - -# Appends the given data to an existing entry. If an entry does not exist, -# one will be created -action :append do - unless hostsfile.contains?(new_resource) - Chef::Log.info "#{new_resource} does not exist - creating instead." - end - - hostsfile.append( - ip_address: new_resource.ip_address, - hostname: new_resource.hostname, - aliases: new_resource.aliases, - comment: new_resource.comment, - priority: new_resource.priority, - unique: new_resource.unique, - ) - - if hostsfile.content_changed? - converge_by("Append #{new_resource}") { hostsfile.save } - else - Chef::Log.info "#{new_resource} content already matches - nothing to do." - end -end - -# Updates the given hosts file entry. Does nothing if the entry does not -# exist. -action :update do - if hostsfile.contains?(new_resource) - - hostsfile.update( - ip_address: new_resource.ip_address, - hostname: new_resource.hostname, - aliases: new_resource.aliases, - comment: new_resource.comment, - priority: new_resource.priority, - unique: new_resource.unique, - ) - - if hostsfile.content_changed? - converge_by("Update #{new_resource}") { hostsfile.save } - else - Chef::Log.info "#{new_resource} content already matches - nothing to do." - end - else - Chef::Log.info "#{new_resource} does not exist - skipping update." - end -end - -# Removes an entry from the hosts file. Does nothing if the entry does -# not exist. -action :remove do - if hostsfile.contains?(new_resource) - converge_by("Remove #{new_resource}") do - hostsfile.remove(new_resource.ip_address) - hostsfile.save - end - else - Chef::Log.info "#{new_resource} does not exist - skipping remove." - end -end - -private - -# The hostsfile object -# -# @return [Manipulator] -# the manipulator for this hostsfile -def hostsfile - @hostsfile ||= Manipulator.new(node) -end diff --git a/cookbooks/hostsfile/resources/entry.rb b/cookbooks/hostsfile/resources/entry.rb index 781e665..a69c109 100644 --- a/cookbooks/hostsfile/resources/entry.rb +++ b/cookbooks/hostsfile/resources/entry.rb @@ -3,8 +3,8 @@ # Cookbook:: hostsfile # Resource:: entry # -# Copyright 2012-2013, Seth Vargo -# Copyright 2012, CustomInk, LCC +# Copyright:: 2012-2013, Seth Vargo +# Copyright:: 2012, CustomInk, LCC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,18 +19,125 @@ # limitations under the License. # -# List of all actions supported by the provider -actions :create, :create_if_missing, :append, :update, :remove - -# Make create the default action -default_action :create - # Required attributes -attribute :ip_address, kind_of: String, name_attribute: true -attribute :hostname, kind_of: String +property :ip_address, String, name_property: true +property :hostname, String # Optional attributes -attribute :aliases, kind_of: Array -attribute :comment, kind_of: String -attribute :priority, kind_of: Fixnum -attribute :unique, kind_of: [TrueClass, FalseClass] +property :aliases, Array +property :comment, String +property :priority, Integer +property :unique, [TrueClass, FalseClass] + +# Creates a new hosts file entry. If an entry already exists, it will be +# overwritten by this one. +action :create do + if hostsfile.contains?(new_resource) + Chef::Log.debug "#{new_resource} already exists - overwriting." + end + + hostsfile.add( + ip_address: new_resource.ip_address, + hostname: new_resource.hostname, + aliases: new_resource.aliases, + comment: new_resource.comment, + priority: new_resource.priority, + unique: new_resource.unique + ) + + if hostsfile.content_changed? + converge_by("Create #{new_resource}") { hostsfile.save } + else + Chef::Log.info "#{new_resource} content already matches - nothing to do." + end +end + +# Create a new hosts file entry, only if one does not already exist for +# the given IP address. If one exists, this does nothing. +action :create_if_missing do + if hostsfile.contains?(new_resource) + Chef::Log.info "#{new_resource} already exists - skipping create_if_missing." + else + converge_by("Create #{new_resource} if missing") do + hostsfile.add( + ip_address: new_resource.ip_address, + hostname: new_resource.hostname, + aliases: new_resource.aliases, + comment: new_resource.comment, + priority: new_resource.priority, + unique: new_resource.unique + ) + hostsfile.save + end + end +end + +# Appends the given data to an existing entry. If an entry does not exist, +# one will be created +action :append do + unless hostsfile.contains?(new_resource) + Chef::Log.info "#{new_resource} does not exist - creating instead." + end + + hostsfile.append( + ip_address: new_resource.ip_address, + hostname: new_resource.hostname, + aliases: new_resource.aliases, + comment: new_resource.comment, + priority: new_resource.priority, + unique: new_resource.unique + ) + + if hostsfile.content_changed? + converge_by("Append #{new_resource}") { hostsfile.save } + else + Chef::Log.info "#{new_resource} content already matches - nothing to do." + end +end + +# Updates the given hosts file entry. Does nothing if the entry does not +# exist. +action :update do + if hostsfile.contains?(new_resource) + + hostsfile.update( + ip_address: new_resource.ip_address, + hostname: new_resource.hostname, + aliases: new_resource.aliases, + comment: new_resource.comment, + priority: new_resource.priority, + unique: new_resource.unique + ) + + if hostsfile.content_changed? + converge_by("Update #{new_resource}") { hostsfile.save } + else + Chef::Log.info "#{new_resource} content already matches - nothing to do." + end + else + Chef::Log.info "#{new_resource} does not exist - skipping update." + end +end + +# Removes an entry from the hosts file. Does nothing if the entry does +# not exist. +action :remove do + if hostsfile.contains?(new_resource) + converge_by("Remove #{new_resource}") do + hostsfile.remove(new_resource.ip_address) + hostsfile.save + end + else + Chef::Log.info "#{new_resource} does not exist - skipping remove." + end +end + +action_class do + # The hostsfile object + # + # @return [Manipulator] + # the manipulator for this hostsfile + def hostsfile + @hostsfile ||= HostsFile::Manipulator.new(node) + end +end diff --git a/cookbooks/zerotier/COPYING b/cookbooks/zerotier/COPYING new file mode 100644 index 0000000..3bfa853 --- /dev/null +++ b/cookbooks/zerotier/COPYING @@ -0,0 +1,17 @@ +ZeroTier One, an endpoint server for the ZeroTier virtual network layer. +Copyright © 2011–2016 ZeroTier, Inc. + +ZeroTier One is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at +your option) any later version. + +See the file ‘LICENSE.GPL-3’ for the text of the GNU GPL version 3. +If that file is not present, see . + +.. + Local variables: + coding: utf-8 + mode: text + End: + vim: fileencoding=utf-8 filetype=text : diff --git a/cookbooks/zerotier/LICENSE.GPL-2 b/cookbooks/zerotier/LICENSE.GPL-2 new file mode 100644 index 0000000..89e08fb --- /dev/null +++ b/cookbooks/zerotier/LICENSE.GPL-2 @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/cookbooks/zerotier/LICENSE.GPL-3 b/cookbooks/zerotier/LICENSE.GPL-3 new file mode 100644 index 0000000..818433e --- /dev/null +++ b/cookbooks/zerotier/LICENSE.GPL-3 @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/cookbooks/zerotier/README.md b/cookbooks/zerotier/README.md new file mode 100644 index 0000000..1f638f3 --- /dev/null +++ b/cookbooks/zerotier/README.md @@ -0,0 +1,68 @@ +ZeroTier Cookbook +================== + +This is a [Chef](https://www.chef.io/) cookbook to manage [ZeroTier](https://www.zerotier.com) networks on your Chef nodes. + +Supported Platforms +--------------------- +* Debian +* Ubuntu +* CentOS +* RHEL +* Amazon + +Recipes +--------------------- +`zerotier::default` + +Default recipe. Calls `zerotier::install` + +`zerotier::install` + +Install's ZeroTier One on your system via the native package management system. + +`zerotier::ohai_plugin` + +Installs the Ohai plugin for ZeroTier. This is required by the provided LWRP `zerotier_network`. + +`zerotier::join_networks` + +Shortcut to automatically join networks stored in attributes (See example in the Attributes section below) + +Attributes +--------------------- +`node['zerotier']['install_version']` + +Version of ZeroTier to install. Empty by default and defaults to the latest version available. + +`node['zerotier']['central_url']` + +URL to the instance of the ZeroTier Central controller. Defaults to https://my.zerotier.com. Will be useful in the future when Central is distributable to our enterprise customers. + +`node['zerotier']['public_autojoin']` + +List of *public* networks to automatically join when using the `zerotier::join_networks` recipe. These networks do not require any interaction with the network controller. + +`node['zerotier']['private_autojoin']` + +List of *private* networks to automatically join when using the `zerotier::join_networks` recipe. Joining a private network requires an API Access Token generated at https://my.zerotier.com. Each member of the list is a hash as follows: + +``` +{ + :network_id => "your_network_id", + :auth_token => "your_auth_token", # API access token generated at https://my.zerotier.com + :central_url => "URL_to_central_instance" # Not required. Defaults to https://my.zerotier.com +} +``` + +LWRP +--------------------- +The ZeroTier recpie provides the `zerotier_network` lwrp + +Attributes: + +- network_id - Network ID to join. defaults to the name attribute. +- node_name - Name of the node to put in https://my.zerotier.com (only applicable when joining a private network) +- auth_token - API access token generated in your account at https://my.zerotier.com. Required if you wish to automatically authorize the node to join the network. +- central_url - URL to the instance of ZeroTier Central. Defaults to https://my.zerotier.com. +- action - `:join` or `:leave`. Defaults to `:join` diff --git a/cookbooks/zerotier/attributes/default.rb b/cookbooks/zerotier/attributes/default.rb new file mode 100644 index 0000000..aef7207 --- /dev/null +++ b/cookbooks/zerotier/attributes/default.rb @@ -0,0 +1,28 @@ + +# Not set by default. +# default['zerotier']['install_version'] +# + +default['zerotier']['central_url'] = 'https://my.zerotier.com' + +# Public networks to autojoin. +default['zerotier']['public_autojoin'] = [] + +# Private networks to autojoin. Requires ZeroTier Central API api key. +# +# Packed in the following format: +# +# [{ +# :network_id => "", +# :auth_token => "key", +# :central_url => "http://my.zerotier.com" // optional. Defaults to https://my.zerotier.com +# }, +# ... +# ] +# +default['zerotier']['private_autojoin'] = [] + +# Binary path to ZeroTier. Shouldn't be changed unless you know what you're doing +default['zerotier']['binary'] = '/usr/sbin/zerotier-cli' +default['zerotier']['data_dir'] = '/var/lib/zerotier-one' +default['zerotier']['control_port'] = 9993 diff --git a/cookbooks/zerotier/chefignore b/cookbooks/zerotier/chefignore new file mode 100644 index 0000000..7803da7 --- /dev/null +++ b/cookbooks/zerotier/chefignore @@ -0,0 +1,107 @@ +# Put files/directories that should be ignored in this file when uploading +# to a chef-server or supermarket. +# Lines that start with '# ' are comments. + +# OS generated files # +###################### +.DS_Store +Icon? +nohup.out +ehthumbs.db +Thumbs.db + +# SASS # +######## +.sass-cache + +# EDITORS # +########### +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED ## +############## +a.out +*.o +*.pyc +*.so +*.com +*.class +*.dll +*.exe +*/rdoc/ + +# Testing # +########### +.watchr +.rspec +spec/* +spec/fixtures/* +test/* +features/* +examples/* +Guardfile +Procfile +.kitchen* +.rubocop.yml +spec/* +Rakefile +.travis.yml +.foodcritic +.codeclimate.yml + +# SCM # +####### +.git +*/.git +.gitignore +.gitmodules +.gitconfig +.gitattributes +.svn +*/.bzr/* +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +Berksfile +Berksfile.lock +cookbooks/* +tmp + +# Policyfile # +############## +Policyfile.rb +Policyfile.lock.json + +# Cookbooks # +############# +CONTRIBUTING* +CHANGELOG* +TESTING* +MAINTAINERS.toml + +# Strainer # +############ +Colanderfile +Strainerfile +.colander +.strainer + +# Vagrant # +########### +.vagrant +Vagrantfile diff --git a/cookbooks/zerotier/libraries/zerotier_network.rb b/cookbooks/zerotier/libraries/zerotier_network.rb new file mode 100644 index 0000000..0ea1163 --- /dev/null +++ b/cookbooks/zerotier/libraries/zerotier_network.rb @@ -0,0 +1,74 @@ +require "chef/log" +require "uri" +require "mixlib/shellout" +require "net/http" +require "net/https" +require "json" + +module ChefZerotierCookbook + class ZerotierNetwork < Chef::Resource + resource_name :zerotier_network + + default_action :join + + # Set the properties for the resource + property :network_id, String, name_property: true, required: true + property :node_name, String, required: true + property :auth_token, String, required: true + property :central_url, String, default: "https://my.zerotier.com" + + action :join do + if ::File.exists?(format("/var/lib/zerotier-one/networks.d/%s.conf", network_id)) + Chef::Log.info(format("Network %s already joined. Skipping.", network_id)) + else + join = Mixlib::ShellOut.new(format("/usr/sbin/zerotier-cli join %s", network_id)) + join.run_command + raise format("Error joining network %s", network_id) if join.error? + + if auth_token + url = URI.parse(format("%s/api/network/%s/member/%s/", central_url, network_id, node['zerotier']['node_id'])) + + netinfo = { + networkId: network_id, + nodeId: node["zerotier"]["node_id"], + name: node_name, + config: { + nwid: network_id, + authorized: true + } + } + + response = Net::HTTP.start(url.host, url.port, use_ssl: url.scheme == "https") do |http| + post = Net::HTTP::Post.new(url, "Content-Type" => "application/json") + post.add_field("Authorization", format("Bearer %s", auth_token)) + post.body = netinfo.to_json + http.request(post) + end + + case response + when Net::HTTPSuccess + # do nothing + else + leave = Mixlib::ShellOut.new(format("/usr/sbin/zerotier-cli leave %s", network_id)) + leave.run_command + error = JSON.parse(response.body) + raise format("Error %s authorizing network: %s: %s", response.code. error["type"], error["message"]) + end + end + + end + end + + action :leave do + if ::File.exists?(format("/var/lib/zerotier-one/networks.d/%s.conf", network_id)) + converge_by(format("Leaving network %s", network_id)) do + leave = Mixlib::ShellOut.new(format("/usr/sbin/zerotier-cli leave %s", network_id)) + leave.run_command + raise format("Error leaving network %s", network_id) if leave.error? + end + else + Chef::Log.warn(format("Network %s is not joined. Skipping", network_id)) + end + end + end +end \ No newline at end of file diff --git a/cookbooks/zerotier/metadata.json b/cookbooks/zerotier/metadata.json new file mode 100644 index 0000000..82d319d --- /dev/null +++ b/cookbooks/zerotier/metadata.json @@ -0,0 +1,55 @@ +{ + "name": "zerotier", + "description": "Installs/Configures ZeroTier", + "long_description": "ZeroTier Cookbook\n==================\n\nThis is a [Chef](https://www.chef.io/) cookbook to manage [ZeroTier](https://www.zerotier.com) networks on your Chef nodes.\n\nSupported Platforms\n---------------------\n* Debian\n* Ubuntu\n* CentOS\n* RHEL\n* Amazon\n\nRecipes\n---------------------\n`zerotier::default`\n\nDefault recipe. Calls `zerotier::install`\n\n`zerotier::install` \n\nInstall's ZeroTier One on your system via the native package management system.\n\n`zerotier::ohai_plugin` \n\nInstalls the Ohai plugin for ZeroTier. This is required by the provided LWRP `zerotier_network`.\n\n`zerotier::join_networks`\n\nShortcut to automatically join networks stored in attributes (See example in the Attributes section below)\n\nAttributes\n---------------------\n`node['zerotier']['install_version']` \n\nVersion of ZeroTier to install. Empty by default and defaults to the latest version available.\n\n`node['zerotier']['central_url']`\n\nURL to the instance of the ZeroTier Central controller. Defaults to https://my.zerotier.com. Will be useful in the future when Central is distributable to our enterprise customers.\n\n`node['zerotier']['public_autojoin']`\n\nList of *public* networks to automatically join when using the `zerotier::join_networks` recipe. These networks do not require any interaction with the network controller.\n\n`node['zerotier']['private_autojoin']`\n\nList of *private* networks to automatically join when using the `zerotier::join_networks` recipe. Joining a private network requires an API Access Token generated at https://my.zerotier.com. Each member of the list is a hash as follows:\n\n```\n{\n\t:network_id => \"your_network_id\",\n :auth_token => \"your_auth_token\", # API access token generated at https://my.zerotier.com\n :central_url => \"URL_to_central_instance\" # Not required. Defaults to https://my.zerotier.com\n}\n```\n\nLWRP\n---------------------\nThe ZeroTier recpie provides the `zerotier_network` lwrp\n\nAttributes:\n\n- network_id - Network ID to join. defaults to the name attribute.\n- node_name - Name of the node to put in https://my.zerotier.com (only applicable when joining a private network)\n- auth_token - API access token generated in your account at https://my.zerotier.com. Required if you wish to automatically authorize the node to join the network.\n- central_url - URL to the instance of ZeroTier Central. Defaults to https://my.zerotier.com.\n- action - `:join` or `:leave`. Defaults to `:join`\n", + "maintainer": "Grant Limberg", + "maintainer_email": "grant.limberg@zerotier.com", + "license": "GPL v3", + "platforms": { + "redhat": ">= 0.0.0", + "centos": ">= 0.0.0", + "amazon": ">= 0.0.0", + "ubuntu": ">= 0.0.0", + "debian": ">= 0.0.0" + }, + "dependencies": { + "ohai": ">= 0.0.0" + }, + "recommendations": { + + }, + "suggestions": { + + }, + "conflicting": { + + }, + "providing": { + + }, + "replacing": { + + }, + "attributes": { + + }, + "groupings": { + + }, + "recipes": { + + }, + "version": "1.0.7", + "source_url": "https://github.com/zerotier/chef-zerotier", + "issues_url": "https://github.com/zerotier/chef-zerotier/issues", + "privacy": false, + "chef_versions": [ + + ], + "ohai_versions": [ + + ], + "gems": [ + + ] +} diff --git a/cookbooks/zerotier/metadata.rb b/cookbooks/zerotier/metadata.rb new file mode 100644 index 0000000..31b327b --- /dev/null +++ b/cookbooks/zerotier/metadata.rb @@ -0,0 +1,15 @@ +name 'zerotier' +maintainer 'Grant Limberg' +maintainer_email 'grant.limberg@zerotier.com' +license 'GPL v3' +description 'Installs/Configures ZeroTier' +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +version '1.0.7' +issues_url 'https://github.com/zerotier/chef-zerotier/issues' if respond_to?(:issues_url) +source_url 'https://github.com/zerotier/chef-zerotier' if respond_to?(:source_url) + +%w(redhat centos amazon ubuntu debian).each do |os| + supports os +end + +depends 'ohai' diff --git a/cookbooks/zerotier/recipes/default.rb b/cookbooks/zerotier/recipes/default.rb new file mode 100644 index 0000000..f007cbc --- /dev/null +++ b/cookbooks/zerotier/recipes/default.rb @@ -0,0 +1,7 @@ +# +# Cookbook:: zerotier +# Recipe:: default +# +# Copyright:: 2017, ZeroTier, Inc., All Rights Reserved. + +include_recipe 'zerotier::install' diff --git a/cookbooks/zerotier/recipes/install.rb b/cookbooks/zerotier/recipes/install.rb new file mode 100644 index 0000000..7fabf5f --- /dev/null +++ b/cookbooks/zerotier/recipes/install.rb @@ -0,0 +1,48 @@ +# +# Cookbook:: zerotier +# Recipe:: install +# +# Copyright:: 2017, ZeroTier, Inc., All Rights Reserved. + +case node['platform'] +when 'debian', 'ubuntu' + apt_repository 'zerotier' do + uri "http://download.zerotier.com/debian/#{node['lsb']['codename']}" + components ['main'] + key 'https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg' + trusted true + end +when 'rhel', 'centos' + yum_repository 'zerotier' do + description "ZeroTier Repo" + baseurl 'https://download.zerotier.com/redhat/el/$releasever' + gpgkey 'https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg' + end +when 'amazon' + yum_repository 'zerotier' do + description 'ZeroTier Repo' + baseurl 'https://download.zerotier.com/redhat/amzn1/' + gpgkey 'https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg' + end +when 'fedora' + yum_repository 'zerotier' do + description 'ZeroTier Repo' + baseurl 'https://download.zerotier.com/redhat/fc/22' + gpgkey 'https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg' + end +else + Chef::Log.fatal("Platform '#{node['platform']}' is not yet supported by this recipe") +end + +package 'zerotier-one' do + if node['zerotier']['version'] + version node['zerotier']['install_version'] + end +end + +service 'zerotier-one' do + action [:enable, :start] + supports :status => true, :restart => true, :start => true,:stop => true +end + +include_recipe 'zerotier::ohai_plugin' \ No newline at end of file diff --git a/cookbooks/zerotier/recipes/join_networks.rb b/cookbooks/zerotier/recipes/join_networks.rb new file mode 100644 index 0000000..7d3f517 --- /dev/null +++ b/cookbooks/zerotier/recipes/join_networks.rb @@ -0,0 +1,23 @@ +# +# Cookbook:: zerotier +# Recipe:: join_networks +# +# Copyright:: 2017, ZeroTier, Inc., All Rights Reserved. + +include_recipe 'zerotier::ohai_plugin' + +node['zerotier']['public_autojoin'].each do |nwid| + zerotier_network nwid do + action :join + end +end + +node['zerotier']['private_autojoin'].each do |network| + zerotier_network network['network_id'] do + only_if { network.key?("auth_token") } + action :join + auth_token network['auth_token'] + central_url network.key?("central_url") ? network[:central_url] : "https://my.zerotier.com" + node_name node['fqdn'] + end +end \ No newline at end of file diff --git a/cookbooks/zerotier/recipes/ohai_plugin.rb b/cookbooks/zerotier/recipes/ohai_plugin.rb new file mode 100644 index 0000000..aec5587 --- /dev/null +++ b/cookbooks/zerotier/recipes/ohai_plugin.rb @@ -0,0 +1,15 @@ +# +# Cookbook:: zerotier +# Recipe:: ohai_plugin +# +# Copyright:: 2017, ZeroTier, Inc., All Rights Reserved. + +ohai_plugin 'zerotier_ohai' do + compile_time false + resource :template + variables ({ + :zerotier_binary => node['zerotier']['binary'], + :control_port => node['zerotier']['control_port'], + :data_dir => node['zerotier']['data_dir'] + }) +end diff --git a/cookbooks/zerotier/templates/default/zerotier_ohai.rb b/cookbooks/zerotier/templates/default/zerotier_ohai.rb new file mode 100644 index 0000000..a58ecc7 --- /dev/null +++ b/cookbooks/zerotier/templates/default/zerotier_ohai.rb @@ -0,0 +1,71 @@ + +Ohai.plugin(:ZeroTier) do + provides 'zerotier' + + def zerotier_command (subcommand) + return "<%= @zerotier_binary %> <% unless @zerotier_binary.end_with?('-cli') %>-q<% end %> #{subcommand} -p<%= @control_port %> -D<%= @data_dir %>" + end + + def linux_get_networks + networks = Mash.new + cmd = zerotier_command('listnetworks') + Ohai::Log.info(cmd) + so = shell_out(cmd) + first_line = true + so.stdout.lines do |line| + if first_line + # skip the header line + first_line = false + next + end + + data = line.strip.split(/\s+/) + + cur_network = Mash.new + cur_network[:network_name] = data[3] + cur_network[:mac] = data[4] + cur_network[:status] = data[5] + cur_network[:type] = data[6] + cur_network[:interface] = data[7] + cur_network[:addresses] = [] + + data[8].split(',').each do |addr| + cur_network[:addresses].push(addr) + end + + networks[data[2]] = cur_network + end + return networks + end + + def linux_get_node_id + node_id = '' + + if ::File.exists?("<%= @data_dir %>/identity.public") + node_id = ::File.read("<%= @data_dir %>/identity.public") + node_id = node_id[0..9] + Ohai + else + Ohai::Log.warn("<%= @data_dir %>/identity.public' does not exist") + end + + return node_id unless node_id.empty? + end + + def get_version + so = shell_out("<%= @zerotier_binary %> -v 2>&1") + version = so.stdout.strip + return version unless version.empty? + end + + collect_data(:linux) do + if ::File.exists?("<%= @zerotier_binary %>") + zerotier Mash.new + zerotier[:version] = get_version + zerotier[:node_id] = linux_get_node_id + zerotier[:networks] = linux_get_networks + else + Ohai::Log.warn("Cannot find zerotier binary") + end + end +end From 88e52607e3258883366c217db4ac98e57ddb63b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 22 Jan 2021 18:25:51 +0100 Subject: [PATCH 250/327] Add a recipe to set up a hosts entry for the PG primary --- site-cookbooks/kosmos-postgresql/metadata.rb | 1 + .../kosmos-postgresql/recipes/hostsfile.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 site-cookbooks/kosmos-postgresql/recipes/hostsfile.rb diff --git a/site-cookbooks/kosmos-postgresql/metadata.rb b/site-cookbooks/kosmos-postgresql/metadata.rb index 29416f2..1b031b2 100644 --- a/site-cookbooks/kosmos-postgresql/metadata.rb +++ b/site-cookbooks/kosmos-postgresql/metadata.rb @@ -22,3 +22,4 @@ chef_version '>= 12.14' if respond_to?(:chef_version) depends "postgresql", ">= 7.0.0" depends "build-essential" depends "kosmos_encfs" +depends "hostsfile" diff --git a/site-cookbooks/kosmos-postgresql/recipes/hostsfile.rb b/site-cookbooks/kosmos-postgresql/recipes/hostsfile.rb new file mode 100644 index 0000000..265f563 --- /dev/null +++ b/site-cookbooks/kosmos-postgresql/recipes/hostsfile.rb @@ -0,0 +1,16 @@ +# +# Cookbook:: kosmos-postgresql +# Recipe:: hostsfile +# + +begin +primary_ip = postgresql_primary[:ipaddress] +rescue NoMethodError +end + +unless primary_ip.nil? + hostsfile_entry primary_ip do + hostname "pg.kosmos.local" + unique true + end +end From dd78b8cf7e5a592ce790c76a11e428db95f4a302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 22 Jan 2021 18:26:37 +0100 Subject: [PATCH 251/327] Use the PG primary private Zerotier IP if it exists --- site-cookbooks/kosmos-postgresql/libraries/helpers.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-postgresql/libraries/helpers.rb b/site-cookbooks/kosmos-postgresql/libraries/helpers.rb index 775977e..7d3c397 100644 --- a/site-cookbooks/kosmos-postgresql/libraries/helpers.rb +++ b/site-cookbooks/kosmos-postgresql/libraries/helpers.rb @@ -26,7 +26,13 @@ class Chef if node.chef_environment == "development" server_node['network']['interfaces']['eth1']['routes'].first['src'] else - server_node['ipaddress'] + # If the server has a private Zerotier IP, use it + if server_node['knife_zero'] && server_node['knife_zero']['host'] && \ + server_node['knife_zero']['host'].start_with?("10.1.1.") + server_node['knife_zero']['host'] + else + server_node['ipaddress'] + end end end From 9b4756441a2c344a85574c589f7c99d508a96700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 22 Jan 2021 18:33:58 +0100 Subject: [PATCH 252/327] Add a recipe to join the private Zerotier network --- site-cookbooks/kosmos_zerotier/recipes/default.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/site-cookbooks/kosmos_zerotier/recipes/default.rb b/site-cookbooks/kosmos_zerotier/recipes/default.rb index 12c2304..7e47d0f 100644 --- a/site-cookbooks/kosmos_zerotier/recipes/default.rb +++ b/site-cookbooks/kosmos_zerotier/recipes/default.rb @@ -2,3 +2,15 @@ # Cookbook:: kosmos_zerotier # Recipe:: default # + +zerotier_controller = search(:node, "role:zerotier_controller").first + +controller_url = "http://#{zerotier_controller["knife_zero"]["host"]}:#{node['kosmos_zerotier']['server_port']}" + +credentials = data_bag_item("credentials", "zerotier") + +zerotier_network credentials["network_id"] do + node_name node['fqdn'] + auth_token credentials["auth_token"] + central_url controller_url +end From 0e1a73b18f3756ad31a3ad50029335bcde51edb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 22 Jan 2021 18:34:52 +0100 Subject: [PATCH 253/327] Set the private Zerotier IP for draco in the node file --- nodes/draco.kosmos.org.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nodes/draco.kosmos.org.json b/nodes/draco.kosmos.org.json index ece1685..927c64d 100644 --- a/nodes/draco.kosmos.org.json +++ b/nodes/draco.kosmos.org.json @@ -2,7 +2,7 @@ "name": "draco.kosmos.org", "normal": { "knife_zero": { - "host": "draco.kosmos.org" + "host": "10.1.1.167" } }, "automatic": { @@ -72,4 +72,4 @@ "recipe[kosmos_zerotier::firewall]", "recipe[kosmos-nginx::firewall]" ] -} \ No newline at end of file +} From 5fa23fe8727a75bd973d02363a1661694764ca30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 22 Jan 2021 18:37:01 +0100 Subject: [PATCH 254/327] Remove the andromeda client and node files --- clients/andromeda.kosmos.org.json | 4 - nodes/andromeda.kosmos.org.json | 138 ------------------------------ 2 files changed, 142 deletions(-) delete mode 100644 clients/andromeda.kosmos.org.json delete mode 100644 nodes/andromeda.kosmos.org.json diff --git a/clients/andromeda.kosmos.org.json b/clients/andromeda.kosmos.org.json deleted file mode 100644 index 07fde6d..0000000 --- a/clients/andromeda.kosmos.org.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "andromeda.kosmos.org", - "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuAI/4XcdJQ4rL3JtQ86Q\nUtdFSBdMnSPxUoHbhXXTaFEB2D0hqyCjfGmt8JqoBaRmj0zNHQvOMixe+SeyfyDs\nDPHQZ5E45f0eBYPchvOjNOZTP6RYhfa1pBRW6D6JJ+2bYW1jfnTur1Tkeg0ZL6zg\nybmcsYeDYeNXEsAGQIz+zqgNHPsTLL7U+eY9u3AYhOPaBXSnaqxPxvYx9fBRWbrx\ntFz/oXjurvLS5rMhts0s6AyMKEs+5bLhSreqGsh+1CfAt2qGNPPY7J5VL1B+cAfk\nFWYD5uWo2NvYKm94UpKsmZgFKFQBglFYpMidYdbl/NNJFq3EJDRyRlzDB8VliOuG\nnwIDAQAB\n-----END PUBLIC KEY-----\n" -} \ No newline at end of file diff --git a/nodes/andromeda.kosmos.org.json b/nodes/andromeda.kosmos.org.json deleted file mode 100644 index a4bd9a3..0000000 --- a/nodes/andromeda.kosmos.org.json +++ /dev/null @@ -1,138 +0,0 @@ -{ - "name": "andromeda.kosmos.org", - "normal": { - "knife_zero": { - "host": "andromeda.kosmos.org" - }, - "kosmos-ipfs": { - "ipfs": { - "config": { - "Swarm.ConnMgr.LowWater": 100, - "Swarm.ConnMgr.HighWater": 300 - } - } - }, - "ipfs": { - "memory_max": "1G" - } - }, - "automatic": { - "fqdn": "andromeda.kosmos.org", - "os": "linux", - "os_version": "4.15.0-96-generic", - "hostname": "andromeda", - "ipaddress": "46.4.18.160", - "roles": [ - "base", - "mastodon", - "ejabberd", - "postgresql_client" - ], - "recipes": [ - "kosmos-base", - "kosmos-base::default", - "kosmos-base::andromeda_firewall", - "kosmos-ipfs", - "kosmos-ipfs::default", - "kosmos-ipfs::public_gateway", - "kosmos-postgresql", - "kosmos-postgresql::default", - "kosmos-mediawiki", - "kosmos-mediawiki::default", - "kosmos-btcpayserver::proxy", - "kosmos-mastodon", - "kosmos-mastodon::default", - "kosmos-mastodon::nginx", - "kosmos-ejabberd", - "kosmos-ejabberd::default", - "kosmos-ejabberd::letsencrypt", - "kosmos-ejabberd::backup", - "kosmos_gitea::pg_db", - "apt::default", - "timezone_iii::default", - "timezone_iii::debian", - "ntp::default", - "ntp::apparmor", - "kosmos-base::systemd_emails", - "kosmos-base::firewall", - "kosmos-postfix::default", - "postfix::default", - "postfix::_common", - "postfix::_attributes", - "postfix::sasl_auth", - "hostname::default", - "ipfs::default", - "ipfs::_user", - "kosmos-ipfs::kredits_pinner", - "firewall::default", - "chef-sugar::default", - "kosmos-nginx::default", - "nginx::default", - "nginx::package", - "nginx::ohai_plugin", - "nginx::repo", - "nginx::commons", - "nginx::commons_dir", - "nginx::commons_script", - "nginx::commons_conf", - "ark::default", - "composer::default", - "composer::install", - "php::default", - "php::package", - "php::ini", - "composer::global_configs", - "mediawiki::default", - "mediawiki::database", - "mediawiki::nginx", - "php-fpm::default", - "php-fpm::install", - "php-fpm::repository", - "php-fpm::configure", - "backup::default", - "logrotate::default", - "kosmos-nodejs::default", - "nodejs::nodejs_from_package", - "nodejs::repo", - "kosmos-redis::default", - "redis::server", - "redis::default", - "java::default", - "java::set_attributes_from_version", - "java::openjdk", - "java::notify", - "java::default_java_symlink", - "java::set_java_home", - "nodejs::npm", - "nodejs::install", - "tor-full::default", - "kosmos-base::letsencrypt", - "git::default", - "git::package", - "build-essential::default" - ], - "platform": "ubuntu", - "platform_version": "18.04", - "cloud": null, - "chef_packages": { - "ohai": { - "version": "15.3.1", - "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.3.1/lib/ohai" - }, - "chef": { - "version": "15.3.14", - "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.3.14/lib" - } - } - }, - "run_list": [ - "role[base]", - "recipe[kosmos-base::andromeda_firewall]", - "recipe[kosmos-ipfs]", - "recipe[kosmos-ipfs::public_gateway]", - "recipe[kosmos-btcpayserver::proxy]", - "role[mastodon]", - "role[ejabberd]", - "recipe[kosmos_gitea::pg_db]" - ] -} From eba7d63b430a47ee5654ab03252b8f2d8480dbcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 22 Jan 2021 18:37:29 +0100 Subject: [PATCH 255/327] Delete the test-2 client and node file --- clients/test-2.json | 4 ---- nodes/test-2.json | 52 --------------------------------------------- 2 files changed, 56 deletions(-) delete mode 100644 clients/test-2.json delete mode 100644 nodes/test-2.json diff --git a/clients/test-2.json b/clients/test-2.json deleted file mode 100644 index 12c109c..0000000 --- a/clients/test-2.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "test-2", - "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyU+Pg4svFeiLc4/OogiZ\n45MgXWMT7/S28R5lDQ3QwCc4c3mGEfkoiOzBmPpf/JuTIRO6W8hsXQNm5Wr3jGYa\nIKHtfSqNufLievLxymR781Grkzxsy8GefeUajNn0Nypjs4ACso2rdX3KmQ/xJr4n\nFKk6Jj08Fp/7i7kzgC8WA6ZeuVPRw9PODTof7x1BMoTfUXaGPPEIVxtv7cZBdkp1\nQK3F2A8nokqDo3630iOq/P29h80STGmeH8hjpICTGxYDOR/vvp7Zs7z8aueZ6iUT\n3oit8w+gAI4RTgu4bgPbwsh5nfIXZaJeSVrV6zpPO5usMbWWDJgdbhwbAGGYVSFp\nEQIDAQAB\n-----END PUBLIC KEY-----\n" -} \ No newline at end of file diff --git a/nodes/test-2.json b/nodes/test-2.json deleted file mode 100644 index aac9607..0000000 --- a/nodes/test-2.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "name": "test-2", - "normal": { - "knife_zero": { - "host": "10.147.20.109" - } - }, - "automatic": { - "fqdn": "test-2", - "os": "linux", - "os_version": "5.4.0-45-generic", - "hostname": "test-2", - "ipaddress": "192.168.122.166", - "roles": [ - - ], - "recipes": [ - "kosmos-base", - "kosmos-base::default", - "apt::default", - "timezone_iii::default", - "timezone_iii::debian", - "ntp::default", - "ntp::apparmor", - "kosmos-base::systemd_emails", - "apt::unattended-upgrades", - "kosmos-base::firewall", - "kosmos-postfix::default", - "postfix::default", - "postfix::_common", - "postfix::_attributes", - "postfix::sasl_auth", - "hostname::default" - ], - "platform": "ubuntu", - "platform_version": "20.04", - "cloud": null, - "chef_packages": { - "ohai": { - "version": "15.12.0", - "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" - }, - "chef": { - "version": "15.13.8", - "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.13.8/lib" - } - } - }, - "run_list": [ - "recipe[kosmos-base]" - ] -} \ No newline at end of file From cbcb50bc86a61f8a1a7380b6993439e6f2260fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 22 Jan 2021 18:37:59 +0100 Subject: [PATCH 256/327] Create a zerotier_controller role --- nodes/zerotier-1.json | 5 ++--- roles/zerotier_controller.rb | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 roles/zerotier_controller.rb diff --git a/nodes/zerotier-1.json b/nodes/zerotier-1.json index 355a4f8..edf4973 100644 --- a/nodes/zerotier-1.json +++ b/nodes/zerotier-1.json @@ -50,7 +50,6 @@ }, "run_list": [ "recipe[kosmos-base]", - "recipe[kosmos_zerotier::controller]", - "recipe[kosmos_zerotier::firewall]" + "role[zerotier_controller]" ] -} \ No newline at end of file +} diff --git a/roles/zerotier_controller.rb b/roles/zerotier_controller.rb new file mode 100644 index 0000000..e5b1a9b --- /dev/null +++ b/roles/zerotier_controller.rb @@ -0,0 +1,6 @@ +name "zerotier_controller" + +run_list %w( + kosmos_zerotier::controller + kosmos_zerotier::firewall +) From 6ec747d4160389212ee876aa2c092f35b72b12d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 22 Jan 2021 18:43:05 +0100 Subject: [PATCH 257/327] Add missing credentials for zerotier --- data_bags/credentials/zerotier.json | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 data_bags/credentials/zerotier.json diff --git a/data_bags/credentials/zerotier.json b/data_bags/credentials/zerotier.json new file mode 100644 index 0000000..f55e349 --- /dev/null +++ b/data_bags/credentials/zerotier.json @@ -0,0 +1,17 @@ +{ + "id": "zerotier", + "network_id": { + "encrypted_data": "DkiAH6RZGOUTd8ZKTe0lPstTX6cRBvDqw9uTbWlpfe3AqLM=\n", + "iv": "+zdZpn9J9+Z+EbHX\n", + "auth_tag": "kvtayYA+LOeRvulil+tiFA==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "auth_token": { + "encrypted_data": "WZqft2i15jeOIiy6qF46BPbSmn/IYzDgY/VjuMfB3TiG3BNJgoKFR7U4yw==\n", + "iv": "Q0IV0xxa22MHMLdu\n", + "auth_tag": "KNmhh9YnVcEj/LKUvEt/gA==\n", + "version": 3, + "cipher": "aes-256-gcm" + } +} \ No newline at end of file From 05cd38a5b92a3d524abdd11b2369c38b2ead08f2 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 23 Jan 2021 14:22:34 +0100 Subject: [PATCH 258/327] Re-enable and improve Tor access for kosmos.social --- .../kosmos-mastodon/attributes/default.rb | 2 +- site-cookbooks/kosmos-mastodon/recipes/nginx.rb | 1 + .../templates/default/nginx_conf_mastodon.erb | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-mastodon/attributes/default.rb b/site-cookbooks/kosmos-mastodon/attributes/default.rb index f04a577..0a92707 100644 --- a/site-cookbooks/kosmos-mastodon/attributes/default.rb +++ b/site-cookbooks/kosmos-mastodon/attributes/default.rb @@ -8,5 +8,5 @@ node.default["kosmos-mastodon"]["sidekiq_threads"] = 25 node.default["kosmos-mastodon"]["elasticsearch"]["allocated_memory"] = "1536m" node.override["tor"]["HiddenServices"]["mastodon"] = { - "HiddenServicePorts" => ["80 127.0.0.1:80"] + "HiddenServicePorts" => ["80 127.0.0.1:80", "443 127.0.0.1:443"] } diff --git a/site-cookbooks/kosmos-mastodon/recipes/nginx.rb b/site-cookbooks/kosmos-mastodon/recipes/nginx.rb index 65717a1..84caba4 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/nginx.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/nginx.rb @@ -6,6 +6,7 @@ mastodon_path = node["kosmos-mastodon"]["directory"] server_name = node["kosmos-mastodon"]["server_name"] +node.override['nginx']['server_names_hash_bucket_size'] = 128 include_recipe "kosmos-nginx" directory "#{node['nginx']['dir']}/snippets" do diff --git a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb index 6991f7a..e1c6ebb 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb @@ -24,3 +24,16 @@ server { add_header Strict-Transport-Security "max-age=31536000"; } <% end %> + +<% if @onion_address %> +server { + listen 443 ssl http2; + server_name mastodon.<%= @onion_address %>; + include <%= @shared_config_path %>; + + ssl_certificate <%= @ssl_cert %>; + ssl_certificate_key <%= @ssl_key %>; + + add_header Strict-Transport-Security "max-age=31536000"; +} +<% end %> From bd48dab1d8c7f4cad52fd2717539432204a5d655 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 23 Jan 2021 17:06:15 +0100 Subject: [PATCH 259/327] Set up postgres-3 VM --- clients/postgres-3.json | 4 ++++ nodes/postgres-3.json | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 clients/postgres-3.json create mode 100644 nodes/postgres-3.json diff --git a/clients/postgres-3.json b/clients/postgres-3.json new file mode 100644 index 0000000..6537c2e --- /dev/null +++ b/clients/postgres-3.json @@ -0,0 +1,4 @@ +{ + "name": "postgres-3", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxPsFwxISCjy38kw78N2I\nhkxK6S0uARkPggE+OP7jWwZqHtnz1O+ZUbM/o9i/dWgm0Xl+hQ6grPtjS57VzXJq\nlwsVDGTkyb5T6wAcZao/koQbA9ZABknLH/ra52gny+7j3b2q5RIdyhddTYZwsbIG\n9y2BfcUW0Z1mPVkR2NxzFloj0ulsrJs6/5GhqbREqPz5BsyBJlwFsREK2Dy6m2nm\nVMp+GIQlRdhy/D09s/BZ/Ejwe8D3tv3jJT5CRXkndwa5qIc96E1uzRQpyyKvXZDK\nYvUdQwniW4EBNHEo/se+OqP+Du/M1dReX6aTq9axbhKiVWoD3FtMVtGqE3uf/i4I\n0QIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/postgres-3.json b/nodes/postgres-3.json new file mode 100644 index 0000000..8bcb01b --- /dev/null +++ b/nodes/postgres-3.json @@ -0,0 +1,52 @@ +{ + "name": "postgres-3", + "normal": { + "knife_zero": { + "host": "10.1.1.115" + } + }, + "automatic": { + "fqdn": "postgres-3", + "os": "linux", + "os_version": "5.4.0-64-generic", + "hostname": "postgres-3", + "ipaddress": "192.168.122.96", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "chef": { + "version": "15.15.1", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.15.1/lib" + }, + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + } + } + }, + "run_list": [ + "recipe[kosmos-base]" + ] +} \ No newline at end of file From fdd70d18720aea78d34a8fe218f0babe143cbb83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 16:40:29 +0100 Subject: [PATCH 260/327] Remove postgres-1 server It was created with an encfs volume inside a VM, we want full disk encryption instead. I have deleted the VM from centaurus as well as its disk and have also unauthorized its id from the zerotier controller --- clients/postgres-1.json | 4 --- nodes/postgres-1.json | 59 ----------------------------------------- 2 files changed, 63 deletions(-) delete mode 100644 clients/postgres-1.json delete mode 100644 nodes/postgres-1.json diff --git a/clients/postgres-1.json b/clients/postgres-1.json deleted file mode 100644 index ff604f3..0000000 --- a/clients/postgres-1.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "postgres-1", - "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6M27iQm/yjXQ3hQ2O2HJ\nJtzB3reCo+Rkb5G8inOgrMPk458vn9NeSjsxtjh0oOZQEFM7tpRa7XVZuR8/H8PX\nvtzDljvmODmZmF+Qdhxw0+gUK/HQKlFAhKCoa3W04UyEJvafG9comNws0X3TWepu\n9RFlTxla9fmj7miXFidTLoNTkm9SbfZTQCBzhUq4QGvRMnbjIQkbkpUgT6WPU3q3\nJDldWk9xBZ7hjTSCN14ASdMVQMQZQlbtxRo2J6pKEdIwkstw+M8BUp2XBHppncpG\n/oY8ov4w9bIBX0U2Qy6lngmZnNYbhQkyxJVoH5qQJusW7EVNNc7QgZ1cujl+F6+A\nWQIDAQAB\n-----END PUBLIC KEY-----\n" -} \ No newline at end of file diff --git a/nodes/postgres-1.json b/nodes/postgres-1.json deleted file mode 100644 index 5dbad0d..0000000 --- a/nodes/postgres-1.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "name": "postgres-1", - "normal": { - "knife_zero": { - "host": "10.1.1.208" - } - }, - "automatic": { - "fqdn": "postgres-1", - "os": "linux", - "os_version": "5.4.0-1026-kvm", - "hostname": "postgres-1", - "ipaddress": "192.168.122.249", - "roles": [ - "postgresql_replica" - ], - "recipes": [ - "kosmos-base", - "kosmos-base::default", - "kosmos_encfs", - "kosmos_encfs::default", - "kosmos-postgresql::replica", - "kosmos-postgresql::firewall_replicas", - "apt::default", - "timezone_iii::default", - "timezone_iii::debian", - "ntp::default", - "ntp::apparmor", - "kosmos-base::systemd_emails", - "apt::unattended-upgrades", - "kosmos-base::firewall", - "kosmos-postfix::default", - "postfix::default", - "postfix::_common", - "postfix::_attributes", - "postfix::sasl_auth", - "hostname::default", - "build-essential::default" - ], - "platform": "ubuntu", - "platform_version": "20.04", - "cloud": null, - "chef_packages": { - "ohai": { - "version": "15.12.0", - "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" - }, - "chef": { - "version": "15.14.0", - "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.14.0/lib" - } - } - }, - "run_list": [ - "recipe[kosmos-base]", - "recipe[kosmos_encfs]", - "role[postgresql_replica]" - ] -} \ No newline at end of file From bb0e73d1b9b8ae1e2c14e5ba1e5e6f5aa7a84ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 16:43:15 +0100 Subject: [PATCH 261/327] Switch ejabberd, mastodon and gitea to a hostname for Postgres --- site-cookbooks/kosmos-ejabberd/recipes/default.rb | 7 +------ site-cookbooks/kosmos-mastodon/recipes/default.rb | 7 ++----- site-cookbooks/kosmos_gitea/recipes/default.rb | 6 +----- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index dfffa4c..31e5994 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -138,11 +138,6 @@ ldap_base = "cn=users,dc=kosmos,dc=org" admin_users = ejabberd_credentials['admins'] -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] - hosts.each do |host| ldap_rootdn = "uid=xmpp,ou=#{host[:name]},cn=applications,dc=kosmos,dc=org" @@ -153,7 +148,7 @@ hosts.each do |host| group 'ejabberd' sensitive true variables pgsql_password: postgresql_data_bag_item['ejabberd_user_password'], - sql_server: postgresql_server, + sql_server: "pg.kosmos.local", host: host, ldap_base: ldap_base, ldap_server: ldap_domain, diff --git a/site-cookbooks/kosmos-mastodon/recipes/default.rb b/site-cookbooks/kosmos-mastodon/recipes/default.rb index ee9d5d6..37cf214 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/default.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/default.rb @@ -21,10 +21,6 @@ end elasticsearch_service 'elasticsearch' postgresql_data_bag_item = data_bag_item('credentials', 'postgresql') -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] mastodon_path = node["kosmos-mastodon"]["directory"] @@ -138,7 +134,8 @@ application mastodon_path do vapid_private_key: mastodon_credentials['vapid_private_key'], vapid_public_key: mastodon_credentials['vapid_public_key'], db_pass: postgresql_data_bag_item['mastodon_user_password'], - db_host: postgresql_server + db_host: "pg.kosmos.local" + notifies :restart, "application[#{mastodon_path}]", :delayed end execute "bundle install" do diff --git a/site-cookbooks/kosmos_gitea/recipes/default.rb b/site-cookbooks/kosmos_gitea/recipes/default.rb index 724572e..ba39c3c 100644 --- a/site-cookbooks/kosmos_gitea/recipes/default.rb +++ b/site-cookbooks/kosmos_gitea/recipes/default.rb @@ -37,10 +37,6 @@ 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" @@ -110,7 +106,7 @@ template "#{config_directory}/app.ini" do jwt_secret: jwt_secret, internal_token: internal_token, secret_key: secret_key, - postgresql_host: "#{postgresql_server}:5432", + postgresql_host: "pg.kosmos.local:5432", postgresql_password: gitea_data_bag_item["postgresql_password"], smtp_host: smtp_credentials["relayhost"], smtp_user: smtp_credentials["user_name"], From 1e3a2b40d4a639fc565f3fc3e78554f96eab1bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 16:44:28 +0100 Subject: [PATCH 262/327] Add the postgresql_client role to the akkounts role --- roles/akkounts.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/akkounts.rb b/roles/akkounts.rb index 1dae0bb..ba50d23 100644 --- a/roles/akkounts.rb +++ b/roles/akkounts.rb @@ -1,6 +1,7 @@ name "akkounts" default_run_list = %w( + role[postgresql_client] kosmos-akkounts::default kosmos-akkounts::nginx ) From 286cd2f2a377817f96235ad7793c1bafc9c3cfa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 16:44:41 +0100 Subject: [PATCH 263/327] Move the postgresql_client role to the top We want the host file to be written before database connections happen --- roles/mastodon.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/mastodon.rb b/roles/mastodon.rb index 5bb39e4..f1064c4 100644 --- a/roles/mastodon.rb +++ b/roles/mastodon.rb @@ -1,7 +1,7 @@ name "mastodon" run_list %w( + role[postgresql_client] kosmos-mastodon kosmos-mastodon::nginx - role[postgresql_client] ) From ee7b3626beb02f38f6c8b6941c7793c892d53a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 16:45:28 +0100 Subject: [PATCH 264/327] Generate a host entry for the current PostgreSQL primary --- roles/postgresql_client.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/roles/postgresql_client.rb b/roles/postgresql_client.rb index 18771f2..96b5418 100644 --- a/roles/postgresql_client.rb +++ b/roles/postgresql_client.rb @@ -2,4 +2,6 @@ # rules to every server that is a PostgreSQL client name "postgresql_client" -run_list [] +run_list %w( + kosmos-postgresql::hostsfile +) From 39d0304ab43b5af93ec617766d65d978058e92c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 16:46:09 +0100 Subject: [PATCH 265/327] Update the akkounts-1 node after Chef run --- nodes/akkounts-1.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nodes/akkounts-1.json b/nodes/akkounts-1.json index 27dd090..1f606a0 100644 --- a/nodes/akkounts-1.json +++ b/nodes/akkounts-1.json @@ -12,11 +12,13 @@ "hostname": "akkounts-1", "ipaddress": "192.168.122.160", "roles": [ + "postgresql_client", "akkounts" ], "recipes": [ "kosmos-base", "kosmos-base::default", + "kosmos-postgresql::hostsfile", "kosmos-akkounts", "kosmos-akkounts::default", "kosmos-akkounts::nginx", @@ -71,4 +73,4 @@ "recipe[kosmos-base]", "role[akkounts]" ] -} \ No newline at end of file +} From 40fde8a861bded10eeae7523e7d3a9d92f3f14d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 16:54:53 +0100 Subject: [PATCH 266/327] Update the ejabberd nodes after Chef run --- nodes/ejabberd-1.json | 1 + nodes/ejabberd-2.json | 1 + 2 files changed, 2 insertions(+) diff --git a/nodes/ejabberd-1.json b/nodes/ejabberd-1.json index 713af49..ade9b42 100644 --- a/nodes/ejabberd-1.json +++ b/nodes/ejabberd-1.json @@ -21,6 +21,7 @@ "recipes": [ "kosmos-base", "kosmos-base::default", + "kosmos-postgresql::hostsfile", "kosmos-ejabberd", "kosmos-ejabberd::default", "kosmos-ejabberd::letsencrypt", diff --git a/nodes/ejabberd-2.json b/nodes/ejabberd-2.json index 31f8b9b..cbb250b 100644 --- a/nodes/ejabberd-2.json +++ b/nodes/ejabberd-2.json @@ -21,6 +21,7 @@ "recipes": [ "kosmos-base", "kosmos-base::default", + "kosmos-postgresql::hostsfile", "kosmos-ejabberd", "kosmos-ejabberd::default", "kosmos-ejabberd::letsencrypt", From 4e1bd458f32658e9474ce734d891dcf353ddb395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 16:55:21 +0100 Subject: [PATCH 267/327] Update the mastodon-1 node after Chef run --- nodes/mastodon-1.json | 1 + 1 file changed, 1 insertion(+) diff --git a/nodes/mastodon-1.json b/nodes/mastodon-1.json index b06ab5f..df0c363 100644 --- a/nodes/mastodon-1.json +++ b/nodes/mastodon-1.json @@ -18,6 +18,7 @@ "recipes": [ "kosmos-base", "kosmos-base::default", + "kosmos-postgresql::hostsfile", "kosmos-mastodon", "kosmos-mastodon::default", "kosmos-mastodon::nginx", From 5cb390f3403692da3d0235d250bb9ac7b441c17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 16:55:54 +0100 Subject: [PATCH 268/327] Remove the postgresql_replica from centaurus, run Chef I have also deleted the data directory (in /mnt/data) --- nodes/centaurus.kosmos.org.json | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/nodes/centaurus.kosmos.org.json b/nodes/centaurus.kosmos.org.json index 38bc7d4..bff7694 100644 --- a/nodes/centaurus.kosmos.org.json +++ b/nodes/centaurus.kosmos.org.json @@ -2,7 +2,7 @@ "name": "centaurus.kosmos.org", "normal": { "knife_zero": { - "host": "centaurus.kosmos.org" + "host": "10.1.1.186" } }, "automatic": { @@ -14,7 +14,6 @@ "roles": [ "gitea", "postgresql_client", - "postgresql_replica", "discourse", "drone" ], @@ -23,11 +22,10 @@ "kosmos-base::default", "kosmos_encfs", "kosmos_encfs::default", + "kosmos-postgresql::hostsfile", "kosmos_gitea", "kosmos_gitea::default", "kosmos_gitea::backup", - "kosmos-postgresql::replica", - "kosmos-postgresql::firewall_replicas", "kosmos_discourse", "kosmos_discourse::default", "kosmos_drone", @@ -61,8 +59,7 @@ "kosmos-nginx::firewall", "backup::default", "logrotate::default", - "kosmos-base::letsencrypt", - "build-essential::default" + "kosmos-base::letsencrypt" ], "platform": "ubuntu", "platform_version": "20.04", @@ -82,7 +79,6 @@ "recipe[kosmos-base]", "recipe[kosmos_encfs]", "role[gitea]", - "role[postgresql_replica]", "role[discourse]", "role[drone]", "recipe[kosmos_kvm::host]", From a4a35da0ffadbf914ba642e546c9e1cb3167cf0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 17:34:58 +0100 Subject: [PATCH 269/327] Replace the hardcoded primary pg IP with a hostname --- site-cookbooks/kosmos-postgresql/recipes/replica.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-postgresql/recipes/replica.rb b/site-cookbooks/kosmos-postgresql/recipes/replica.rb index a5b82b9..6525948 100644 --- a/site-cookbooks/kosmos-postgresql/recipes/replica.rb +++ b/site-cookbooks/kosmos-postgresql/recipes/replica.rb @@ -27,7 +27,7 @@ unless primary.nil? command <<-EOF systemctl stop #{postgresql_service} mv #{postgresql_data_dir} #{postgresql_data_dir}.old -pg_basebackup -h 10.1.1.167 -U replication -D #{postgresql_data_dir} -R +pg_basebackup -h pg.kosmos.local -U replication -D #{postgresql_data_dir} -R chown -R postgres:postgres #{postgresql_data_dir} systemctl start #{postgresql_service} EOF From a7116b8fe5eed904804750e4fea85caa01816a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 19:08:06 +0100 Subject: [PATCH 270/327] Switch the TLS mode to disabled for Gitea We connect through a Zerotier private IP --- site-cookbooks/kosmos_gitea/templates/default/app.ini.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb b/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb index d85c896..3b80419 100644 --- a/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb +++ b/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb @@ -23,7 +23,7 @@ HOST = <%= @postgresql_host %> NAME = gitea USER = gitea PASSWD = <%= @postgresql_password %> -SSL_MODE = verify-ca +SSL_MODE = disable # [indexer] # ISSUE_INDEXER_PATH = /data/gitea/indexers/issues.bleve From 7e61e9cb457df220e7c6e842fa831468980ebca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 19:09:41 +0100 Subject: [PATCH 271/327] Promote a new PostgreSQL primary: postgres-2 --- nodes/draco.kosmos.org.json | 1 - nodes/postgres-2.json | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/nodes/draco.kosmos.org.json b/nodes/draco.kosmos.org.json index 927c64d..c461387 100644 --- a/nodes/draco.kosmos.org.json +++ b/nodes/draco.kosmos.org.json @@ -63,7 +63,6 @@ "run_list": [ "recipe[kosmos-base]", "recipe[kosmos_encfs]", - "role[postgresql_primary]", "recipe[kosmos_kvm::host]", "recipe[kosmos-ejabberd::firewall]", "recipe[kosmos-ipfs::firewall_swarm]", diff --git a/nodes/postgres-2.json b/nodes/postgres-2.json index 64d44bc..cd48a8c 100644 --- a/nodes/postgres-2.json +++ b/nodes/postgres-2.json @@ -8,7 +8,7 @@ "automatic": { "fqdn": "postgres-2", "os": "linux", - "os_version": "5.4.0-59-generic", + "os_version": "5.4.0-64-generic", "hostname": "postgres-2", "ipaddress": "192.168.122.244", "roles": [ @@ -50,6 +50,6 @@ }, "run_list": [ "recipe[kosmos-base]", - "role[postgresql_replica]" + "role[postgresql_primary]" ] -} \ No newline at end of file +} From 112eb903ec670ea3a55187c464d23f7b13c07b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 19:13:54 +0100 Subject: [PATCH 272/327] Add a script to switch the primary PostgreSQL server Usage: scripts/postgresql/switch_primary.sh --- scripts/postgresql/switch_primary.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 scripts/postgresql/switch_primary.sh diff --git a/scripts/postgresql/switch_primary.sh b/scripts/postgresql/switch_primary.sh new file mode 100755 index 0000000..4af481d --- /dev/null +++ b/scripts/postgresql/switch_primary.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +if [[ $# -ne 2 ]] ; then + echo "Usage: scripts/postgresql/switch_primary.sh " + exit 1; +fi + +old_primary_hostname=$1 +new_primary_hostname=$2 +new_primary_ip=`bundle exec knife node show $new_primary_hostname -a knife_zero.host | grep -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}" -o` + +echo "Switching primary to $new_primary_hostname ($new_primary_ip)" +bundle exec knife ssh name:$new_primary_hostname -a knife_zero.host "sudo su - postgres -c '/usr/lib/postgresql/12/bin/pg_ctl promote -D /var/lib/postgresql/12/main'" +echo "Replacing pg.kosmos.local host entries with $new_primary_ip" +bundle exec knife ssh roles:postgresql_client -a knife_zero.host "sudo sed -r \"s/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s(pg.kosmos.local)/$new_primary_ip\t\1/\" -i /etc/hosts" +echo "Stopping postgresql on $old_primary_hostname" +bundle exec knife ssh name:$old_primary_hostname -a knife_zero.host "sudo systemctl stop postgresql@12-main.service" From 7ce8b7d4616487b50d2d08c4ee47a36ea34dad22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 19:14:55 +0100 Subject: [PATCH 273/327] Enable PostgreSQL service --- site-cookbooks/kosmos-postgresql/resources/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-postgresql/resources/server.rb b/site-cookbooks/kosmos-postgresql/resources/server.rb index c131023..f71520e 100644 --- a/site-cookbooks/kosmos-postgresql/resources/server.rb +++ b/site-cookbooks/kosmos-postgresql/resources/server.rb @@ -32,7 +32,7 @@ action :create do service postgresql_service do supports restart: true, status: true, reload: true - action :start + action [:enable, :start] end # This service is a dependency that will auto-start our cluster service on From b1fea4b09ffe87c48b5b1d8b524cb0968c13fabf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sat, 23 Jan 2021 19:25:49 +0100 Subject: [PATCH 274/327] Update the postgres-3 node after Chef run --- nodes/postgres-3.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nodes/postgres-3.json b/nodes/postgres-3.json index 8bcb01b..71ee87f 100644 --- a/nodes/postgres-3.json +++ b/nodes/postgres-3.json @@ -12,11 +12,14 @@ "hostname": "postgres-3", "ipaddress": "192.168.122.96", "roles": [ - + "postgresql_replica" ], "recipes": [ "kosmos-base", "kosmos-base::default", + "kosmos-postgresql::hostsfile", + "kosmos-postgresql::replica", + "kosmos-postgresql::firewall", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -47,6 +50,7 @@ } }, "run_list": [ - "recipe[kosmos-base]" + "recipe[kosmos-base]", + "role[postgresql_replica]" ] } \ No newline at end of file From 1ad7a6936c62cad8b91e3df01fe3724d2bae4021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sun, 24 Jan 2021 10:11:17 +0100 Subject: [PATCH 275/327] Generate the hosts entry for the PostgreSQL replica --- roles/postgresql_replica.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/postgresql_replica.rb b/roles/postgresql_replica.rb index 07fc7c6..6d73f31 100644 --- a/roles/postgresql_replica.rb +++ b/roles/postgresql_replica.rb @@ -1,6 +1,7 @@ name "postgresql_replica" run_list %w( + kosmos-postgresql::hostsfile kosmos-postgresql::replica kosmos-postgresql::firewall ) From 0e5519a4b7f7770268aefe6abbfb641b8feab2f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sun, 24 Jan 2021 10:12:37 +0100 Subject: [PATCH 276/327] Update Gitea to 1.13.1 Running on centaurus Closes #253 --- site-cookbooks/kosmos_gitea/attributes/default.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos_gitea/attributes/default.rb b/site-cookbooks/kosmos_gitea/attributes/default.rb index 3fa3473..3f9f758 100644 --- a/site-cookbooks/kosmos_gitea/attributes/default.rb +++ b/site-cookbooks/kosmos_gitea/attributes/default.rb @@ -1,6 +1,6 @@ -gitea_version = "1.12.3" +gitea_version = "1.13.1" 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"] = "6bfda9a12dc248360d34954b087ca6319f7310c61dc32b34c5e0675fdd45e0f4" +node.default["kosmos_gitea"]["binary_checksum"] = "8d017378137a2e829caaed93b4cef0975c3307b5af069e4b004d083520488d21" node.default["kosmos_gitea"]["nginx"]["domain"] = "gitea.kosmos.org" node.default["kosmos_gitea"]["working_directory"] = "/var/lib/gitea" From 90ce664f2e5a57f5e03c3384c1d7c1d00ec8b185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Sun, 24 Jan 2021 10:14:29 +0100 Subject: [PATCH 277/327] Update ejabberd to 20.12 It fixes a bug that prevented the config to be reloaded for LDAP options (https://github.com/processone/ejabberd/issues/3181) and more: https://www.process-one.net/blog/ejabberd-20-12/ --- site-cookbooks/kosmos-ejabberd/attributes/default.rb | 4 ++-- site-cookbooks/kosmos-ejabberd/recipes/default.rb | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/site-cookbooks/kosmos-ejabberd/attributes/default.rb b/site-cookbooks/kosmos-ejabberd/attributes/default.rb index fa4e89f..e4e6bf9 100644 --- a/site-cookbooks/kosmos-ejabberd/attributes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/attributes/default.rb @@ -1,5 +1,5 @@ -node.default["kosmos-ejabberd"]["version"] = "20.04" -node.default["kosmos-ejabberd"]["checksum"] = "5377ff18960a399e661fa23f4a1d9f57c78d4579ed108c52b8f68e7cd9268868" +node.default["kosmos-ejabberd"]["version"] = "20.12" +node.default["kosmos-ejabberd"]["checksum"] = "3d2a4e9d1aa2d189017f4f310eff4d0b6c6d7cd911209cfbcca7b0ec5b577b65" node.default["kosmos-ejabberd"]["turn_min_port"] = 50000 node.default["kosmos-ejabberd"]["turn_max_port"] = 55000 diff --git a/site-cookbooks/kosmos-ejabberd/recipes/default.rb b/site-cookbooks/kosmos-ejabberd/recipes/default.rb index dfffa4c..467b489 100644 --- a/site-cookbooks/kosmos-ejabberd/recipes/default.rb +++ b/site-cookbooks/kosmos-ejabberd/recipes/default.rb @@ -159,13 +159,7 @@ hosts.each do |host| ldap_server: ldap_domain, ldap_rootdn: ldap_rootdn, ldap_encryption_type: ldap_encryption_type - # Restarting the service is needed because the LDAP options are only parsed - # on start (https://github.com/processone/ejabberd/issues/3181#issuecomment-594482546) - # This can be changed back to reloading when this is part of a release: - # https://github.com/processone/ejabberd/commit/b39a1e2d74cd4d400a7f062e31056057573298e8 - # - # notifies :run, "execute[ejabberdctl reload_config]", :delayed - notifies :restart, "service[ejabberd]", :delayed + notifies :run, "execute[ejabberdctl reload_config]", :delayed end end From 49c75bbb055f3747eb054dcb89693f2530189540 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 25 Jan 2021 12:09:28 +0100 Subject: [PATCH 278/327] Add Onion-Location header for kosmos.social Tells Tor Browser where to find the native onion site. refs #201 --- .../kosmos-mastodon/templates/default/nginx_conf_mastodon.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb index e1c6ebb..7c7c26d 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb @@ -22,6 +22,7 @@ server { ssl_certificate_key <%= @ssl_key %>; add_header Strict-Transport-Security "max-age=31536000"; + add_header Onion-Location https://mastodon.<%= @onion_address %>$request_uri; } <% end %> From f7d3abc3079058e0e8ebeda34992eaa6eb99ac46 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 26 Jan 2021 11:48:41 +0100 Subject: [PATCH 279/327] Stop BTCPay server before compilation fixes #291 --- site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb index ac864dc..e6cba45 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb @@ -16,7 +16,10 @@ end bash 'build_btcpay' do cwd node['btcpay']['source_dir'] - code './build.sh' + code <<-EOH + systemctl stop btcpayserver.service + ./build.sh + EOH action :nothing notifies :restart, "systemd_unit[btcpayserver.service]", :delayed end From 5a5db43de393b596b069a1f53422b21985875f03 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 26 Jan 2021 11:49:20 +0100 Subject: [PATCH 280/327] Use new postgres client role and config Fixes btcpay having still used the old postgres master, and integrating it into the global client config setup from here on out. --- nodes/bitcoin-2.json | 4 +++- roles/btcpay.rb | 1 + site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/nodes/bitcoin-2.json b/nodes/bitcoin-2.json index c99a571..01bd552 100644 --- a/nodes/bitcoin-2.json +++ b/nodes/bitcoin-2.json @@ -12,7 +12,8 @@ "hostname": "bitcoin-2", "ipaddress": "192.168.122.148", "roles": [ - "btcpay" + "btcpay", + "postgresql_client" ], "recipes": [ "kosmos-base", @@ -21,6 +22,7 @@ "kosmos-bitcoin::c-lightning", "kosmos-bitcoin::lnd", "kosmos-bitcoin::rtl", + "kosmos-postgresql::hostsfile", "kosmos-bitcoin::dotnet", "kosmos-bitcoin::nbxplorer", "kosmos-bitcoin::btcpay", diff --git a/roles/btcpay.rb b/roles/btcpay.rb index 05749c1..c3212d5 100644 --- a/roles/btcpay.rb +++ b/roles/btcpay.rb @@ -1,6 +1,7 @@ name "btcpay" run_list %w( + role[postgresql_client] kosmos-bitcoin::dotnet kosmos-bitcoin::nbxplorer kosmos-bitcoin::btcpay diff --git a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb index e6cba45..562ef67 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb @@ -51,7 +51,7 @@ template node['btcpay']['config_path'] do nbxplorer_url: "http://127.0.0.1:#{node['nbxplorer']['port']}", btcpay_port: node['btcpay']['port'], btcpay_log_path: node['btcpay']['log_path'], - postgres_host: "192.168.122.1", + postgres_host: "pg.kosmos.local", postgres_port: node['btcpay']['postgres']['port'], postgres_database: node['btcpay']['postgres']['database'], postgres_user: node['btcpay']['postgres']['user'], From 461af035acd1e065f98f1ae81fd9bebfa5bc5431 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 26 Jan 2021 12:05:19 +0100 Subject: [PATCH 281/327] Update c-lightning to 0.9.3 --- site-cookbooks/kosmos-bitcoin/attributes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index b595fb7..a270116 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -26,7 +26,7 @@ node.default['bitcoin']['conf'] = { } node.default['c-lightning']['repo'] = 'https://github.com/ElementsProject/lightning' -node.default['c-lightning']['revision'] = 'v0.9.2' +node.default['c-lightning']['revision'] = 'v0.9.3' node.default['c-lightning']['source_dir'] = '/opt/c-lightning' node.default['c-lightning']['lightning_dir'] = "/home/#{node['bitcoin']['username']}/.lightning" node.default['c-lightning']['alias'] = 'ln3.kosmos.org' From c3256a07cc24a3e95abb1ca8bba77db507e4fbd6 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 26 Jan 2021 12:05:29 +0100 Subject: [PATCH 282/327] Fix c-lightning configure not finding python Broke in the latest release. --- site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb index b8f2865..5eedd82 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb @@ -28,6 +28,7 @@ bash "compile_c-lightning" do make make install EOH + environment "PYTHON_VERSION" => "3" action :nothing notifies :restart, "systemd_unit[lightningd.service]", :delayed end From 40fe4038797c20b369f9ef9933a3a219ed80cca4 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 26 Jan 2021 12:33:09 +0100 Subject: [PATCH 283/327] Stop c-lightning before compilation See https://github.com/ElementsProject/lightning/issues/4346 for potential issues with not doing that. --- site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb index 5eedd82..67c6c97 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/c-lightning.rb @@ -24,6 +24,7 @@ end bash "compile_c-lightning" do cwd node['c-lightning']['source_dir'] code <<-EOH + systemctl stop lightningd.service ./configure make make install From 152edbc958185c472330e53c27f8a1691a84a878 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 26 Jan 2021 12:45:17 +0100 Subject: [PATCH 284/327] Update bitcoind to 0.21 --- site-cookbooks/kosmos-bitcoin/attributes/default.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index a270116..3240b96 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -1,5 +1,5 @@ -node.default['bitcoin']['version'] = '0.20.1' -node.default['bitcoin']['checksum'] = '4bbd62fd6acfa5e9864ebf37a24a04bc2dcfe3e3222f056056288d854c53b978' +node.default['bitcoin']['version'] = '0.21.0' +node.default['bitcoin']['checksum'] = '1a91202c62ee49fb64d57a52b8d6d01cd392fffcbef257b573800f9289655f37' node.default['bitcoin']['username'] = 'satoshi' node.default['bitcoin']['usergroup'] = 'bitcoin' node.default['bitcoin']['network'] = 'mainnet' From 0d2a04f8ba259569e4426f6eb1ac79e48450b545 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 26 Jan 2021 12:45:28 +0100 Subject: [PATCH 285/327] Refactor bitcoind recipe Fixes various issues, like compilation not starting on subsequent version updates, service not restarting after compilation, and a TODO note on the compilation script itself. --- .../kosmos-bitcoin/recipes/source.rb | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/source.rb b/site-cookbooks/kosmos-bitcoin/recipes/source.rb index 34e138d..dfd993b 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/source.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/source.rb @@ -37,23 +37,25 @@ ark 'bitcoind' do url "https://bitcoincore.org/bin/bitcoin-core-#{node['bitcoin']['version']}/bitcoin-#{node['bitcoin']['version']}.tar.gz" checksum node['bitcoin']['checksum'] action :put + notifies :run, 'execute[compile_bitcoin-core_dependencies]', :immediately end -execute "Compile bitcoin-core dependencies" do +execute "compile_bitcoin-core_dependencies" do cwd "/usr/local/bitcoind/depends" command "make NO_QT=1" - not_if { ::File.directory?("/usr/local/bitcoind/depends/x86_64-pc-linux-gnu") } + action :nothing + notifies :run, 'bash[compile_bitcoin-core]', :immediately end -execute "Configure, compile bitcoin-core" do +bash "compile_bitcoin-core" do cwd "/usr/local/bitcoind" - # FIXME only executes first array item? - command [ - "./autogen.sh", - "./configure --prefix=$PWD/depends/x86_64-pc-linux-gnu", - "make" - ] - not_if { ::File.exist?("/usr/local/bitcoind/src/bitcoind") } + code <<-EOH + ./autogen.sh + ./configure --prefix=$PWD/depends/x86_64-pc-linux-gnu + make + EOH + action :nothing + notifies :restart, "systemd_unit[bitcoind.service]", :delayed end link "/usr/local/bin/bitcoind" do From 65185b1a1bc4cb4c156c7c47569c07b6cd7e3d87 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 27 Jan 2021 18:05:30 +0100 Subject: [PATCH 286/327] Update lnd to 0.12.0 --- site-cookbooks/kosmos-bitcoin/attributes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 3240b96..812f9c3 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -35,7 +35,7 @@ node.default['c-lightning']['log_level'] = 'info' node.default['c-lightning']['public_ip'] = '148.251.237.73' node.default['lnd']['repo'] = 'https://github.com/lightningnetwork/lnd' -node.default['lnd']['revision'] = 'v0.11.1-beta' +node.default['lnd']['revision'] = 'v0.12.0-beta' node.default['lnd']['source_dir'] = '/opt/lnd' node.default['lnd']['lnd_dir'] = "/home/#{node['bitcoin']['username']}/.lnd" node.default['lnd']['alias'] = 'ln2.kosmos.org' From 1adf3281bfa1f878523a621f4c94c96bb458893c Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 3 Feb 2021 19:53:13 +0100 Subject: [PATCH 287/327] Configure/run Sidekiq for Akkounts --- nodes/akkounts-1.json | 11 +++- site-cookbooks/kosmos-akkounts/metadata.rb | 1 + .../kosmos-akkounts/recipes/default.rb | 58 ++++++++++++------- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/nodes/akkounts-1.json b/nodes/akkounts-1.json index 1f606a0..411d304 100644 --- a/nodes/akkounts-1.json +++ b/nodes/akkounts-1.json @@ -12,8 +12,8 @@ "hostname": "akkounts-1", "ipaddress": "192.168.122.160", "roles": [ - "postgresql_client", - "akkounts" + "akkounts", + "postgresql_client" ], "recipes": [ "kosmos-base", @@ -39,6 +39,11 @@ "kosmos-nodejs::default", "nodejs::nodejs_from_package", "nodejs::repo", + "kosmos-redis::default", + "redis::server", + "redis::default", + "backup::default", + "logrotate::default", "nodejs::npm", "nodejs::install", "kosmos-nginx::default", @@ -73,4 +78,4 @@ "recipe[kosmos-base]", "role[akkounts]" ] -} +} \ No newline at end of file diff --git a/site-cookbooks/kosmos-akkounts/metadata.rb b/site-cookbooks/kosmos-akkounts/metadata.rb index 04b9892..695ce6b 100644 --- a/site-cookbooks/kosmos-akkounts/metadata.rb +++ b/site-cookbooks/kosmos-akkounts/metadata.rb @@ -9,6 +9,7 @@ chef_version '>= 14.0' depends 'kosmos-nginx' depends "kosmos-nodejs" +depends "kosmos-redis" depends "poise-ruby-build" depends "application" depends 'application_git' diff --git a/site-cookbooks/kosmos-akkounts/recipes/default.rb b/site-cookbooks/kosmos-akkounts/recipes/default.rb index 88ef6b2..9b736aa 100644 --- a/site-cookbooks/kosmos-akkounts/recipes/default.rb +++ b/site-cookbooks/kosmos-akkounts/recipes/default.rb @@ -2,27 +2,6 @@ # Cookbook:: kosmos-akkounts # 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. -# require 'ipaddr' app_name = "akkounts" @@ -42,6 +21,7 @@ end package "libpq-dev" include_recipe 'kosmos-nodejs' +include_recipe "kosmos-redis" npm_package "yarn" do version "1.22.4" @@ -54,7 +34,7 @@ rails_env = node.chef_environment == "development" ? "development" : "production systemd_unit "akkounts.service" do content({ Unit: { - Description: "Kosmos account management", + Description: "Kosmos Accounts", Documentation: ["https://gitea.kosmos.org/kosmos/akkounts"], After: "network.target" }, @@ -79,6 +59,36 @@ systemd_unit "akkounts.service" do action [:create, :enable] end +systemd_unit "akkounts-sidekiq.service" do + content({ + Unit: { + Description: "Kosmos Accounts async/background jobs", + Documentation: ["https://gitea.kosmos.org/kosmos/akkounts"], + Requires: "redis-server.service", + After: "syslog.target network.target redis-server.service" + }, + Service: { + Type: "notify", + User: deploy_user, + WorkingDirectory: deploy_path, + Environment: "MALLOC_ARENA_MAX=2", + ExecStart: "#{bundle_path} exec sidekiq -C #{deploy_path}/config/sidekiq.yml -e production", + WatchdogSec: "10", + Restart: "on-failure", + RestartSec: "1", + StandardOutput: "syslog", + StandardError: "syslog", + SyslogIdentifier: "sidekiq" + }, + Install: { + WantedBy: "multi-user.target" + } + }) + verify false + triggers_reload true + action [:create, :enable] +end + application deploy_path do owner deploy_user group deploy_group @@ -143,6 +153,10 @@ application deploy_path do service "akkounts" do action [:enable, :start] end + + service "akkounts-sidekiq" do + action [:enable, :start] + end end ejabberd_private_ip_addresses = [] From e1bcd5efa0142a2c082859a58fdd91fdc11b0463 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 7 Feb 2021 17:44:08 +0100 Subject: [PATCH 288/327] Set up Zerotier Control UI Install/configure ztncui[1], with HTTP access allowed from within the private network. [1]: https://key-networks.com/ztncui/ --- nodes/zerotier-1.json | 5 ++- roles/zerotier_controller.rb | 1 + .../kosmos_zerotier/attributes/default.rb | 7 +++- .../kosmos_zerotier/recipes/zncui.rb | 40 +++++++++++++++++++ .../kosmos_zerotier/templates/ztncui.env.erb | 1 + 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 site-cookbooks/kosmos_zerotier/recipes/zncui.rb create mode 100644 site-cookbooks/kosmos_zerotier/templates/ztncui.env.erb diff --git a/nodes/zerotier-1.json b/nodes/zerotier-1.json index edf4973..13454ae 100644 --- a/nodes/zerotier-1.json +++ b/nodes/zerotier-1.json @@ -12,13 +12,14 @@ "hostname": "zerotier-1", "ipaddress": "192.168.122.72", "roles": [ - + "zerotier_controller" ], "recipes": [ "kosmos-base", "kosmos-base::default", "kosmos_zerotier::controller", "kosmos_zerotier::firewall", + "kosmos_zerotier::zncui", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -52,4 +53,4 @@ "recipe[kosmos-base]", "role[zerotier_controller]" ] -} +} \ No newline at end of file diff --git a/roles/zerotier_controller.rb b/roles/zerotier_controller.rb index e5b1a9b..105a0cf 100644 --- a/roles/zerotier_controller.rb +++ b/roles/zerotier_controller.rb @@ -3,4 +3,5 @@ name "zerotier_controller" run_list %w( kosmos_zerotier::controller kosmos_zerotier::firewall + kosmos_zerotier::zncui ) diff --git a/site-cookbooks/kosmos_zerotier/attributes/default.rb b/site-cookbooks/kosmos_zerotier/attributes/default.rb index 5f017af..5031534 100644 --- a/site-cookbooks/kosmos_zerotier/attributes/default.rb +++ b/site-cookbooks/kosmos_zerotier/attributes/default.rb @@ -1 +1,6 @@ -node.default["kosmos_zerotier"]["server_port"] = 9993 +node.default['kosmos_zerotier']['server_port'] = 9993 + +node.default['ztncui']['version'] = '0.6.6' +node.default['ztncui']['checksum'] = 'fa83679266a571c10e13b11293ebfb9d1c3515019f2af1e7dd066b5a37411018' +node.default['ztncui']['http_all_interfaces'] = true +node.default['ztncui']['http_allow_access_from'] = '10.1.1.0/24' diff --git a/site-cookbooks/kosmos_zerotier/recipes/zncui.rb b/site-cookbooks/kosmos_zerotier/recipes/zncui.rb new file mode 100644 index 0000000..8818488 --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/recipes/zncui.rb @@ -0,0 +1,40 @@ +# +# Cookbook:: kosmos_zerotier +# Recipe:: zncui +# + +package_path = "/opt/ztncui_#{node['ztncui']['version']}_amd64.deb" + +remote_file package_path do + source "https://s3-us-west-1.amazonaws.com/key-networks/deb/ztncui/1/x86_64/ztncui_#{node['ztncui']['version']}_amd64.deb" + checksum node['ztncui']['checksum'] + action :create_if_missing + notifies :run, 'bash[install_ztncui_package]', :immediately +end + +bash 'install_ztncui_package' do + code "apt-get install -y #{package_path}" + action :nothing +end + +service "ztncui" do + action [:enable, :start] +end + +template '/opt/key-networks/ztncui/.env' do + source 'ztncui.env.erb' + mode '0644' + variables http_all_interfaces: node['ztncui']['http_all_interfaces'] + notifies :restart, 'service[ztncui]', :delayed +end + +include_recipe 'kosmos-base::firewall' + +if node['ztncui']['http_allow_access_from'] + firewall_rule 'zncui_http' do + port 3000 + protocol :tcp + command :allow + source node['ztncui']['http_allow_access_from'] + end +end diff --git a/site-cookbooks/kosmos_zerotier/templates/ztncui.env.erb b/site-cookbooks/kosmos_zerotier/templates/ztncui.env.erb new file mode 100644 index 0000000..23d9793 --- /dev/null +++ b/site-cookbooks/kosmos_zerotier/templates/ztncui.env.erb @@ -0,0 +1 @@ +<% if @http_all_interfaces %>HTTP_ALL_INTERFACES=yes<% end %> From 9a54a7554f5dec66a1b982f3ac6a4bd43f112dfc Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 8 Feb 2021 20:01:22 +0100 Subject: [PATCH 289/327] Use package resource instead of custom command --- site-cookbooks/kosmos_zerotier/recipes/zncui.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/site-cookbooks/kosmos_zerotier/recipes/zncui.rb b/site-cookbooks/kosmos_zerotier/recipes/zncui.rb index 8818488..06c54ce 100644 --- a/site-cookbooks/kosmos_zerotier/recipes/zncui.rb +++ b/site-cookbooks/kosmos_zerotier/recipes/zncui.rb @@ -9,12 +9,10 @@ remote_file package_path do source "https://s3-us-west-1.amazonaws.com/key-networks/deb/ztncui/1/x86_64/ztncui_#{node['ztncui']['version']}_amd64.deb" checksum node['ztncui']['checksum'] action :create_if_missing - notifies :run, 'bash[install_ztncui_package]', :immediately end -bash 'install_ztncui_package' do - code "apt-get install -y #{package_path}" - action :nothing +dpkg_package 'ztncui' do + source package_path end service "ztncui" do From f3def7b71da0777b4b2ac2a7134987d7fb3ba169 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 10 Feb 2021 23:47:23 +0100 Subject: [PATCH 290/327] Update node.js (apt repo) --- site-cookbooks/kosmos-nodejs/recipes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-nodejs/recipes/default.rb b/site-cookbooks/kosmos-nodejs/recipes/default.rb index 683edb2..1c8773a 100644 --- a/site-cookbooks/kosmos-nodejs/recipes/default.rb +++ b/site-cookbooks/kosmos-nodejs/recipes/default.rb @@ -36,6 +36,6 @@ if node['lsb']['codename'] == "vivid" end include_recipe "nodejs" else - node.override["nodejs"]["repo"] = "https://deb.nodesource.com/node_10.x" + node.override["nodejs"]["repo"] = "https://deb.nodesource.com/node_12.x" include_recipe "nodejs::nodejs_from_package" end From f7d3736712485870e75163168566ea5a11055e51 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 18 Feb 2021 18:51:11 +0100 Subject: [PATCH 291/327] Update node details Removes unused recipes from generated runlist --- nodes/barnard.kosmos.org.json | 4 --- nodes/test-3.json | 52 +++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 nodes/test-3.json diff --git a/nodes/barnard.kosmos.org.json b/nodes/barnard.kosmos.org.json index fea3485..0cbf082 100644 --- a/nodes/barnard.kosmos.org.json +++ b/nodes/barnard.kosmos.org.json @@ -21,15 +21,11 @@ "recipes": [ "kosmos-base", "kosmos-base::default", - "kredits-github", - "kredits-github::default", - "kredits-github::nginx", "kosmos-ipfs", "kosmos-ipfs::default", "kosmos-hubot::botka_freenode", "kosmos-hubot::hal8000", "kosmos-hubot::hal8000_xmpp", - "kosmos-hubot::wormhole", "sockethub", "sockethub::default", "sockethub::proxy", diff --git a/nodes/test-3.json b/nodes/test-3.json new file mode 100644 index 0000000..86e533e --- /dev/null +++ b/nodes/test-3.json @@ -0,0 +1,52 @@ +{ + "name": "test-3", + "normal": { + "knife_zero": { + "host": "10.1.1.18" + } + }, + "automatic": { + "fqdn": "test-3", + "os": "linux", + "os_version": "5.4.0-1031-kvm", + "hostname": "test-3", + "ipaddress": "192.168.122.22", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "chef": { + "version": "15.15.1", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/chef-15.15.1/lib" + }, + "ohai": { + "version": "15.12.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.6.0/gems/ohai-15.12.0/lib/ohai" + } + } + }, + "run_list": [ + "recipe[kosmos-base]" + ] +} \ No newline at end of file From fd901f6e644f50f416cc9d2a110939c390686cd9 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 18 Feb 2021 18:51:36 +0100 Subject: [PATCH 292/327] Update Zoom JWT --- data_bags/credentials/hal8000_xmpp.json | 48 ++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/data_bags/credentials/hal8000_xmpp.json b/data_bags/credentials/hal8000_xmpp.json index 3e4320e..55d36ef 100644 --- a/data_bags/credentials/hal8000_xmpp.json +++ b/data_bags/credentials/hal8000_xmpp.json @@ -1,58 +1,58 @@ { "id": "hal8000_xmpp", "xmpp_password": { - "encrypted_data": "iSQ/GCJvEj+uJ16Ndp8AfponI0Tg/Z7oYvA80mqAvVA=\n", - "iv": "CUp8NKx/5cu3bqCI\n", - "auth_tag": "BGomAzBuViX38bUKoYYxiw==\n", + "encrypted_data": "QDnK0ZMzbCcM8CwsIcgZJx3KExErTB4ojP9Hu1oyHD8=\n", + "iv": "ZnP+4pnjWRdr2a84\n", + "auth_tag": "Xp8rPcRPA4LAYOEY59emdg==\n", "version": 3, "cipher": "aes-256-gcm" }, "webhook_token": { - "encrypted_data": "g6qSxL7JAQlBy2O5g1GCC6DmXm7vGJaV9P47g4Wyj8buYExD\n", - "iv": "lLAxwl9h5L3j7Gq7\n", - "auth_tag": "zx0Uy/crHGAELYRKaBNXAg==\n", + "encrypted_data": "jRwY92Us504vKwU11qs869mUklDpDCBJ80D/ssLzMHSrq4/e\n", + "iv": "I4khnoXYyZaPDLn+\n", + "auth_tag": "gGIHP5E0aqfdSMsXTw4MNQ==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_webhook_token": { - "encrypted_data": "Ver2bAA7rLBCtmy/VBYtirlercbt3cVUotY3Pv6SdbHG0Ak=\n", - "iv": "cf84lg3B+SQWoRQL\n", - "auth_tag": "UQTb5/NtEbm4I9xINs2yeQ==\n", + "encrypted_data": "JpBDovG888hVeM0ZOyVzXfJrFJ2G3Vsk2YdFxmIlv+itjUk=\n", + "iv": "14b4Igw2oPApOQJH\n", + "auth_tag": "vNLbNV4E6x4vWNHxNfbMlA==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_wallet_password": { - "encrypted_data": "dreUxCjqv0IM2vjI7oe9/l9Ia6DkQljYwPb4ZJwC6m0H4g==\n", - "iv": "Fand4DZjlEbvkcKa\n", - "auth_tag": "prqZA8GlIie+1fidHaYtMw==\n", + "encrypted_data": "A9fGuzvhpNQiVJWGzDzXRZdHNZFmYmLQY7QVuiTRRCQUoA==\n", + "iv": "gNaM0ccaUWjPSXY2\n", + "auth_tag": "qOzVDyRsLQrEK5UOiiw/AQ==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_session_secret": { - "encrypted_data": "s4mhAFFLen7vEHwotcdlccp6LzUuQcW7MegamsyA6sL+ndb7brcghkmTxkFf\nPy74iIYqu+qM\n", - "iv": "3vTP43/hXV8oLeaj\n", - "auth_tag": "hwjX7HV8rUMWq46LMva/SA==\n", + "encrypted_data": "Kfc3RI8z+wRTKZe8mKmXBLOercqAGikF5nVzCrMjSpQtPGi2yq7glq9ZZWeo\nJOsichMMyZAw\n", + "iv": "9XZbR0EC8QdOVAF+\n", + "auth_tag": "pupr2kFS4kQ+umiKC1PDpw==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_github_key": { - "encrypted_data": "89zHSvHE/x58i2ghMsHeUrx6VbeW7dygNnQr0kz4SbMa3yJ+gw9E\n", - "iv": "C5i/SXqmi5UsJ1Xo\n", - "auth_tag": "QufI517NeIyoFRQJ0VNx7g==\n", + "encrypted_data": "IdqQQTXOAisa3sVzQamEd34EbAeYjO0atjBbqapF/XfXkLVMUhSO\n", + "iv": "PbaqtSGt12vnoZjk\n", + "auth_tag": "xpqsDOKjbTYDagFuGSlvxw==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_github_secret": { - "encrypted_data": "Lj5PAFC/71Exg6pFph8/5w9MCYodDPZjz2/00Dirfvh+LhCl6wuwFXJwD21W\ndDV6/k+mNIufmLEAL+U=\n", - "iv": "OrG+cRZASFa1iFrI\n", - "auth_tag": "o+E8v6mMfCC0x9wzVCFoZg==\n", + "encrypted_data": "JK586fy5K2dAjX+wiJmWK+1giBlQu/9tm9/UAzsOyAS6hmGNOsdlFLGrVsjI\nHbOkIn1vS57EHmqZiGo=\n", + "iv": "bTBX91vQgJtdM4MY\n", + "auth_tag": "pcENZKhtxsuOmMIPlhm2tw==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_zoom_jwt": { - "encrypted_data": "piQLeodQKf8P7OY9Wp7En16IXryDPbIWNbl1nDcpBLVGkLbDLmrYw6sNgmlt\nyIjU7PwZGmtl56jaREYT/Kkd9QRcBf31v+pC19uiDzKaQUlEtTUvBQFgrRm8\nWuppievcwa3wUrtKZSAz9wi1jFLPezb92mDTZ0xP4IQi70SUluvq8gztT+40\nhL0FhcAeA6KFXhD98pVNRPXB8TjUg9pQx5z9MkUH798FoPL9kFQfLFEMp1mK\nFhohwA0bEPWYx+NQl6D+LNBHMFCbnzQ=\n", - "iv": "7Y8HdmQDjV+WJgLH\n", - "auth_tag": "n36iqqN51yjNCg4Vw/gTfg==\n", + "encrypted_data": "R/I10igSfB1eIrIbOhtGwYY+6XFFH1enizyJ7N7855m99NXm2660QT4m67N4\nppFihQFedrVV2jZv8Dj7ukG4eqW2bkN5stCaBr/TjBx+yLKc9kwVEOnLcIO+\n4Ai+9RyfVki5kojr8RmeQ1hRpCdYKYlmOLnBL/3O37P47kTucvsfLDL1cYDW\ncfilEvPJ7TKht4n1Wge1rnzjRtjZINMSRhA8Q6+VILnQUx8BGTQf8sLgrddc\nLVqrufffD+Xe0UYHAZZSskNVc9mZsGc=\n", + "iv": "+8jH30NqjhDcQh7T\n", + "auth_tag": "drSgM9mWt49A1pGnVEhwkA==\n", "version": 3, "cipher": "aes-256-gcm" } From 09f0faaddafa1ce465bd0ff9d4a93a2247f38734 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 24 Feb 2021 19:11:53 +0100 Subject: [PATCH 293/327] Add missing header to recipe --- site-cookbooks/kosmos-nginx/recipes/with_perl.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/site-cookbooks/kosmos-nginx/recipes/with_perl.rb b/site-cookbooks/kosmos-nginx/recipes/with_perl.rb index 5be4fda..a5dbc53 100644 --- a/site-cookbooks/kosmos-nginx/recipes/with_perl.rb +++ b/site-cookbooks/kosmos-nginx/recipes/with_perl.rb @@ -1,3 +1,8 @@ +# +# Cookbook Name:: kosmos-nginx +# Recipe:: with_perl +# + node.override['nginx']['default_site_enabled'] = false node.override['nginx']['server_tokens'] = 'off' From 1c47f9ab27ef3376d196aa035d18e19f9496eb66 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 25 Feb 2021 12:12:41 +0100 Subject: [PATCH 294/327] Add cookbook for static asset hosting Configures assets.kosmos.org, only for webfont hosting for now. --- .../kosmos_assets/attributes/default.rb | 3 ++ site-cookbooks/kosmos_assets/metadata.rb | 10 +++++ .../kosmos_assets/recipes/nginx_site.rb | 38 +++++++++++++++++++ .../templates/nginx_conf_assets.erb | 25 ++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 site-cookbooks/kosmos_assets/attributes/default.rb create mode 100644 site-cookbooks/kosmos_assets/metadata.rb create mode 100644 site-cookbooks/kosmos_assets/recipes/nginx_site.rb create mode 100644 site-cookbooks/kosmos_assets/templates/nginx_conf_assets.erb diff --git a/site-cookbooks/kosmos_assets/attributes/default.rb b/site-cookbooks/kosmos_assets/attributes/default.rb new file mode 100644 index 0000000..7133c57 --- /dev/null +++ b/site-cookbooks/kosmos_assets/attributes/default.rb @@ -0,0 +1,3 @@ +node.default["kosmos_assets"]["domain"] = "assets.kosmos.org" +node.default["kosmos_assets"]["repo"] = "https://gitea.kosmos.org/kosmos/assets.kosmos.org.git" +node.default["kosmos_assets"]["revision"] = "master" diff --git a/site-cookbooks/kosmos_assets/metadata.rb b/site-cookbooks/kosmos_assets/metadata.rb new file mode 100644 index 0000000..0b82f51 --- /dev/null +++ b/site-cookbooks/kosmos_assets/metadata.rb @@ -0,0 +1,10 @@ +name 'kosmos_assets' +maintainer 'Kosmos' +maintainer_email 'ops@kosmos.org' +license 'MIT' +description 'Configures static asset Web hosting' +long_description 'Configures static asset Web hosting' +version '1.0.0' +chef_version '>= 15.10' if respond_to?(:chef_version) + +depends "kosmos-nginx" diff --git a/site-cookbooks/kosmos_assets/recipes/nginx_site.rb b/site-cookbooks/kosmos_assets/recipes/nginx_site.rb new file mode 100644 index 0000000..aadeb7a --- /dev/null +++ b/site-cookbooks/kosmos_assets/recipes/nginx_site.rb @@ -0,0 +1,38 @@ +# +# Cookbook:: kosmos_assets +# Recipe:: nginx_site +# + +include_recipe "kosmos-nginx" + +domain = node["kosmos_assets"]["domain"] + +nginx_certbot_site domain + +directory "/var/www/#{domain}/site" do + user node["nginx"]["user"] + group node["nginx"]["group"] + mode "0755" +end + +git "/var/www/#{domain}/site" do + user node["nginx"]["user"] + group node["nginx"]["group"] + repository node["kosmos_assets"]["repo"] + revision node["kosmos_assets"]["revision"] + action :sync +end + +template "#{node["nginx"]["dir"]}/sites-available/#{domain}" do + source "nginx_conf_assets.erb" + owner node["nginx"]["user"] + mode 0640 + variables domain: domain, + ssl_cert: "/etc/letsencrypt/live/#{domain}/fullchain.pem", + ssl_key: "/etc/letsencrypt/live/#{domain}/privkey.pem" + notifies :reload, "service[nginx]", :delayed +end + +nginx_site domain do + action :enable +end diff --git a/site-cookbooks/kosmos_assets/templates/nginx_conf_assets.erb b/site-cookbooks/kosmos_assets/templates/nginx_conf_assets.erb new file mode 100644 index 0000000..14b6235 --- /dev/null +++ b/site-cookbooks/kosmos_assets/templates/nginx_conf_assets.erb @@ -0,0 +1,25 @@ +<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%> +# Generated by Chef + +server { + listen 443 ssl http2; + server_name <%= @domain %>; + + root /var/www/<%= @domain %>/site; + + access_log off; + gzip_static on; + gzip_comp_level 5; + + location ~* .(css)$ { + expires 1d; + } + + location ~* .(woff|woff2)$ { + expires max; + } + + ssl_certificate <%= @ssl_cert %>; + ssl_certificate_key <%= @ssl_key %>; +} +<% end -%> From 6109707f3c14549afb3f3576473db115813916ef Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 25 Feb 2021 12:13:20 +0100 Subject: [PATCH 295/327] Host assets.kosmos.org on centaurus --- nodes/centaurus.kosmos.org.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nodes/centaurus.kosmos.org.json b/nodes/centaurus.kosmos.org.json index bff7694..539fe71 100644 --- a/nodes/centaurus.kosmos.org.json +++ b/nodes/centaurus.kosmos.org.json @@ -30,6 +30,7 @@ "kosmos_discourse::default", "kosmos_drone", "kosmos_drone::default", + "kosmos_assets::nginx_site", "kosmos_kvm::host", "kosmos-ejabberd::firewall", "kosmos_zerotier::firewall", @@ -81,6 +82,7 @@ "role[gitea]", "role[discourse]", "role[drone]", + "recipe[kosmos_assets::nginx_site]", "recipe[kosmos_kvm::host]", "recipe[kosmos-ejabberd::firewall]", "recipe[kosmos_zerotier::firewall]" From 474208ea8e2658da778a4a6da4a52afb98f01c16 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 25 Feb 2021 14:29:41 +0100 Subject: [PATCH 296/327] Use shared Kosmos webfont for Gitea Currently using a custom rule for system fonts. This change also adds a missing new class to the custom rule to cover Markdown-generated content like e.g. comments. --- .../kosmos_gitea/files/custom/templates/custom/header.tmpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_gitea/files/custom/templates/custom/header.tmpl b/site-cookbooks/kosmos_gitea/files/custom/templates/custom/header.tmpl index 61f1c59..10fad3b 100644 --- a/site-cookbooks/kosmos_gitea/files/custom/templates/custom/header.tmpl +++ b/site-cookbooks/kosmos_gitea/files/custom/templates/custom/header.tmpl @@ -1,3 +1,4 @@ From 5559ca41a7667d24056674bedd2cab906ff9484e Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 25 Feb 2021 17:38:11 +0100 Subject: [PATCH 297/327] Support IPv6 and CORS for font hosting --- site-cookbooks/kosmos_assets/templates/nginx_conf_assets.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/site-cookbooks/kosmos_assets/templates/nginx_conf_assets.erb b/site-cookbooks/kosmos_assets/templates/nginx_conf_assets.erb index 14b6235..84562b2 100644 --- a/site-cookbooks/kosmos_assets/templates/nginx_conf_assets.erb +++ b/site-cookbooks/kosmos_assets/templates/nginx_conf_assets.erb @@ -3,6 +3,7 @@ server { listen 443 ssl http2; + listen [::]:443 ssl http2; server_name <%= @domain %>; root /var/www/<%= @domain %>/site; @@ -11,6 +12,8 @@ server { gzip_static on; gzip_comp_level 5; + add_header 'Access-Control-Allow-Origin' '*'; + location ~* .(css)$ { expires 1d; } From 891b5f3feeeaf39e58bbb4d6d0a4f4bc0200e05f Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 26 Feb 2021 20:41:53 +0100 Subject: [PATCH 298/327] Tell browsers to cache Gitea avatars for 30 days fixes #312 --- .../kosmos_gitea/templates/default/nginx_conf.erb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb b/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb index 2540434..7965156 100644 --- a/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb +++ b/site-cookbooks/kosmos_gitea/templates/default/nginx_conf.erb @@ -24,10 +24,15 @@ server { client_max_body_size 20M; - location / { - # Increase number of buffers. Default is 8 + location ~ ^/(avatars|repo-avatars)/.*$ { proxy_buffers 1024 8k; + proxy_pass http://_gitea; + proxy_http_version 1.1; + expires 30d; + } + location / { + proxy_buffers 1024 8k; proxy_pass http://_gitea; proxy_http_version 1.1; } From 9415b719658a617cdde4287d1bee04de7d6f9048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 30 Mar 2021 12:11:03 +0200 Subject: [PATCH 299/327] Deploy hubot with new hubot-kredits It includes a script for creating Kredits for reviews Refs #135 --- data_bags/credentials/hal8000_xmpp.json | 62 ++++++++++------- .../kosmos-hubot/recipes/hal8000_xmpp.rb | 68 ++++++++++--------- 2 files changed, 73 insertions(+), 57 deletions(-) diff --git a/data_bags/credentials/hal8000_xmpp.json b/data_bags/credentials/hal8000_xmpp.json index 55d36ef..bf88cf3 100644 --- a/data_bags/credentials/hal8000_xmpp.json +++ b/data_bags/credentials/hal8000_xmpp.json @@ -1,58 +1,72 @@ { "id": "hal8000_xmpp", "xmpp_password": { - "encrypted_data": "QDnK0ZMzbCcM8CwsIcgZJx3KExErTB4ojP9Hu1oyHD8=\n", - "iv": "ZnP+4pnjWRdr2a84\n", - "auth_tag": "Xp8rPcRPA4LAYOEY59emdg==\n", + "encrypted_data": "fFHM54i7mlfD9dpZWJWIsjSXGzekctbsNZc0DOSOijg=\n", + "iv": "kKkZ9dbk3l9Gygkz\n", + "auth_tag": "Sx2oYaWlrrjn27x/7+Hciw==\n", "version": 3, "cipher": "aes-256-gcm" }, "webhook_token": { - "encrypted_data": "jRwY92Us504vKwU11qs869mUklDpDCBJ80D/ssLzMHSrq4/e\n", - "iv": "I4khnoXYyZaPDLn+\n", - "auth_tag": "gGIHP5E0aqfdSMsXTw4MNQ==\n", + "encrypted_data": "I1b52yjcijL8G/5rQOaK+Us4mqj3zfrS14C1FNX/QGYfk5qo\n", + "iv": "JKhm4WyvV09cW5WY\n", + "auth_tag": "EdbJQ+robm4Ekibbid8WQg==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_webhook_token": { - "encrypted_data": "JpBDovG888hVeM0ZOyVzXfJrFJ2G3Vsk2YdFxmIlv+itjUk=\n", - "iv": "14b4Igw2oPApOQJH\n", - "auth_tag": "vNLbNV4E6x4vWNHxNfbMlA==\n", + "encrypted_data": "xybuwYnGSyOZd+C89mkXYQNp3QOdGCNby7T26VHQw9cJ9BI=\n", + "iv": "p4JRoucq6402kJTA\n", + "auth_tag": "Q9tRvbk9Yeii7BAqB153PA==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_wallet_password": { - "encrypted_data": "A9fGuzvhpNQiVJWGzDzXRZdHNZFmYmLQY7QVuiTRRCQUoA==\n", - "iv": "gNaM0ccaUWjPSXY2\n", - "auth_tag": "qOzVDyRsLQrEK5UOiiw/AQ==\n", + "encrypted_data": "GiWqyYSRipI7+HTV2mlaWZBchPkDSAqf0c0GwmcGXzuc6g==\n", + "iv": "txQNno2CBfscTEZ9\n", + "auth_tag": "NUEYUOOYIczFW11T8RPApg==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_session_secret": { - "encrypted_data": "Kfc3RI8z+wRTKZe8mKmXBLOercqAGikF5nVzCrMjSpQtPGi2yq7glq9ZZWeo\nJOsichMMyZAw\n", - "iv": "9XZbR0EC8QdOVAF+\n", - "auth_tag": "pupr2kFS4kQ+umiKC1PDpw==\n", + "encrypted_data": "BZoUrStW49IHALMNBMZFQwu40VeuUF++JRI7MqggXhSCWu9l5MIuBjwiOd9O\nUXaAfY3NgrYC\n", + "iv": "yGLVq+owGBs7UHle\n", + "auth_tag": "ar81Cg0/ae83pNqkTos+Zg==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "gitea_token": { + "encrypted_data": "8cN3+ptBOv4Ha0VBrq94fXnuLSYUWU3WaRXcblt4KSak3GMziYCTVw2mYxbE\nsfrYH7Ukypht/mEu+kY=\n", + "iv": "Vz7f+khl5VNdbtaG\n", + "auth_tag": "OXWUsIUcazdSfQIlevpKPg==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "github_token": { + "encrypted_data": "13MyNGNRKiKIrfwauhV/XS7rIzaflHL+BARDO/JMMUxoG8vsNvci5gHBHr95\nr9hqRu218czoZFl/O/Q=\n", + "iv": "QuC8lFzZwH73J4Dy\n", + "auth_tag": "ZZdBCh/K3l8i1QKpT8aR1A==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_github_key": { - "encrypted_data": "IdqQQTXOAisa3sVzQamEd34EbAeYjO0atjBbqapF/XfXkLVMUhSO\n", - "iv": "PbaqtSGt12vnoZjk\n", - "auth_tag": "xpqsDOKjbTYDagFuGSlvxw==\n", + "encrypted_data": "5iAJpKHyGIpNnB7xo03p150Gs4chTlx5cWBXXeo8QVzho5aBOhjc\n", + "iv": "6X1u9Y0SPPZrS26f\n", + "auth_tag": "KMB9VG/M3emW6Cd9kX23Zg==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_github_secret": { - "encrypted_data": "JK586fy5K2dAjX+wiJmWK+1giBlQu/9tm9/UAzsOyAS6hmGNOsdlFLGrVsjI\nHbOkIn1vS57EHmqZiGo=\n", - "iv": "bTBX91vQgJtdM4MY\n", - "auth_tag": "pcENZKhtxsuOmMIPlhm2tw==\n", + "encrypted_data": "bY2Aa7h3gJ8owtK9HZ0Fnvi35HtvAKX25R1WF1Lgmqj8tKIASnDjTHTh38b2\nfa8NFt4OAwrOkIDK6sM=\n", + "iv": "quCBdq6e5Hs3O5Yr\n", + "auth_tag": "jOAcMTyqSJ04H8ZPVZz6Zw==\n", "version": 3, "cipher": "aes-256-gcm" }, "kredits_zoom_jwt": { - "encrypted_data": "R/I10igSfB1eIrIbOhtGwYY+6XFFH1enizyJ7N7855m99NXm2660QT4m67N4\nppFihQFedrVV2jZv8Dj7ukG4eqW2bkN5stCaBr/TjBx+yLKc9kwVEOnLcIO+\n4Ai+9RyfVki5kojr8RmeQ1hRpCdYKYlmOLnBL/3O37P47kTucvsfLDL1cYDW\ncfilEvPJ7TKht4n1Wge1rnzjRtjZINMSRhA8Q6+VILnQUx8BGTQf8sLgrddc\nLVqrufffD+Xe0UYHAZZSskNVc9mZsGc=\n", - "iv": "+8jH30NqjhDcQh7T\n", - "auth_tag": "drSgM9mWt49A1pGnVEhwkA==\n", + "encrypted_data": "d/UWwRN99Tel0oHBwrXptDzQ8k2GpWers8+aD4bfVqM4aoHex7+4/IQE529i\n2wm//3yxzPfVicqnYvToWDorKvL7buZdQmTJNRdN7gxjt+NLNtB4FYWImNnI\ntfyufpx3bYsA1ULLfoO14QDm/nfvf8jsftArwXZZMLEbCHrS7E4LYS9+UVQM\nRytRTgQhCtB9hPSUwykZ3OgYrJnm5HCPss+IHaTDmPG5jY8xZs4xvUdeFa6T\nkzsfpXf5aIzxei5UEl75mTm3XXAARvc=\n", + "iv": "6WaZCHRuUp46xTAG\n", + "auth_tag": "ZA2gb03AO/GGq8Kl+You5Q==\n", "version": 3, "cipher": "aes-256-gcm" } diff --git a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb index fbf290f..8dae8b7 100644 --- a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb +++ b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb @@ -87,39 +87,41 @@ application app_path do app_dir: app_path, entry: "#{app_path}/bin/hubot -a xmpp --name hal8000", environment: { - "HUBOT_LOG_LEVEL" => node.chef_environment == "development" ? "debug" : "info", - "HUBOT_XMPP_USERNAME" => "hal8000@kosmos.org/hubot", - "HUBOT_XMPP_PASSWORD" => data_bag['xmpp_password'], - "HUBOT_XMPP_HOST" => "xmpp.kosmos.org", - "HUBOT_XMPP_ROOMS" => node[app_name]['rooms'].join(','), - "HUBOT_AUTH_ADMIN" => node[app_name]['auth_admins'].join(','), - "HUBOT_RSS_PRINTSUMMARY" => "false", - "HUBOT_RSS_PRINTERROR" => "false", - "HUBOT_RSS_IRCCOLORS" => "true", - "HUBOT_PLUSPLUS_POINTS_TERM" => "karma,karma", - "HUBOT_RSS_HEADER" => "Update:", - "HUBOT_HELP_REPLY_IN_PRIVATE" => "true", - "REDIS_URL" => "redis://localhost:6379/#{app_name}", - "EXPRESS_PORT" => node[app_name]['http_port'], - "WEBHOOK_TOKEN" => data_bag['webhook_token'], - "IPFS_API_HOST" => node[app_name]['kredits']['ipfs_host'], - "IPFS_API_PORT" => node[app_name]['kredits']['ipfs_port'], - "IPFS_API_PROTOCOL" => node[app_name]['kredits']['ipfs_protocol'], - "KREDITS_WEB_URL" => node[app_name]['kredits']['web_url'], - "KREDITS_ROOM" => node[app_name]['kredits']['room'], - "KREDITS_WEBHOOK_TOKEN" => data_bag['kredits_webhook_token'], - "KREDITS_PROVIDER_URL" => node[app_name]['kredits']['provider_url'], - "KREDITS_NETWORK_ID" => node[app_name]['kredits']['network_id'], - "KREDITS_WALLET_PATH" => node[app_name]['kredits']['wallet_path'], - "KREDITS_WALLET_PASSWORD" => data_bag['kredits_wallet_password'], - "KREDITS_MEDIAWIKI_URL" => node[app_name]['kredits']['mediawiki_url'], - "KREDITS_GITHUB_REPO_BLACKLIST" => node[app_name]['kredits']['github_repo_blacklist'], - "KREDITS_GITEA_REPO_BLACKLIST" => node[app_name]['kredits']['gitea_repo_blacklist'], - "KREDITS_GRANT_HOST" => node[app_name]['domain'], - "KREDITS_GRANT_PROTOCOL" => "https", - "KREDITS_SESSION_SECRET" => data_bag['kredits_session_secret'], - "KREDITS_GITHUB_KEY" => data_bag['kredits_github_key'], - "KREDITS_GITHUB_SECRET" => data_bag['kredits_github_secret'], + "HUBOT_LOG_LEVEL" => node.chef_environment == "development" ? "debug" : "info", + "HUBOT_XMPP_USERNAME" => "hal8000@kosmos.org/hubot", + "HUBOT_XMPP_PASSWORD" => data_bag['xmpp_password'], + "HUBOT_XMPP_HOST" => "xmpp.kosmos.org", + "HUBOT_XMPP_ROOMS" => node[app_name]['rooms'].join(','), + "HUBOT_AUTH_ADMIN" => node[app_name]['auth_admins'].join(','), + "HUBOT_RSS_PRINTSUMMARY" => "false", + "HUBOT_RSS_PRINTERROR" => "false", + "HUBOT_RSS_IRCCOLORS" => "true", + "HUBOT_PLUSPLUS_POINTS_TERM" => "karma,karma", + "HUBOT_RSS_HEADER" => "Update:", + "HUBOT_HELP_REPLY_IN_PRIVATE" => "true", + "REDIS_URL" => "redis://localhost:6379/#{app_name}", + "EXPRESS_PORT" => node[app_name]['http_port'], + "WEBHOOK_TOKEN" => data_bag['webhook_token'], + "GITEA_TOKEN" => data_bag['gitea_token'], + "GITHUB_TOKEN" => data_bag['github_token'], + "IPFS_API_HOST" => node[app_name]['kredits']['ipfs_host'], + "IPFS_API_PORT" => node[app_name]['kredits']['ipfs_port'], + "IPFS_API_PROTOCOL" => node[app_name]['kredits']['ipfs_protocol'], + "KREDITS_WEB_URL" => node[app_name]['kredits']['web_url'], + "KREDITS_ROOM" => node[app_name]['kredits']['room'], + "KREDITS_WEBHOOK_TOKEN" => data_bag['kredits_webhook_token'], + "KREDITS_PROVIDER_URL" => node[app_name]['kredits']['provider_url'], + "KREDITS_NETWORK_ID" => node[app_name]['kredits']['network_id'], + "KREDITS_WALLET_PATH" => node[app_name]['kredits']['wallet_path'], + "KREDITS_WALLET_PASSWORD" => data_bag['kredits_wallet_password'], + "KREDITS_MEDIAWIKI_URL" => node[app_name]['kredits']['mediawiki_url'], + "KREDITS_GITHUB_REPO_BLACKLIST" => node[app_name]['kredits']['github_repo_blacklist'], + "KREDITS_GITEA_REPO_BLACKLIST" => node[app_name]['kredits']['gitea_repo_blacklist'], + "KREDITS_GRANT_HOST" => node[app_name]['domain'], + "KREDITS_GRANT_PROTOCOL" => "https", + "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_MEETING_WHITELIST" => "414901303,82557072771" } From 45817ba997c11af4473ff41a1a080ee90737ccac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 30 Mar 2021 12:12:27 +0200 Subject: [PATCH 300/327] Update the barnard node file after running Chef --- nodes/barnard.kosmos.org.json | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/nodes/barnard.kosmos.org.json b/nodes/barnard.kosmos.org.json index 0cbf082..c0055b0 100644 --- a/nodes/barnard.kosmos.org.json +++ b/nodes/barnard.kosmos.org.json @@ -15,8 +15,7 @@ "hostname": "barnard", "ipaddress": "104.248.95.16", "roles": [ - "base", - "kredits_github" + "base" ], "recipes": [ "kosmos-base", @@ -29,8 +28,6 @@ "sockethub", "sockethub::default", "sockethub::proxy", - "kosmos-akkounts", - "kosmos-akkounts::default", "kosmos-dirsrv", "kosmos-dirsrv::default", "apt::default", @@ -47,9 +44,21 @@ "postfix::_attributes", "postfix::sasl_auth", "hostname::default", + "ipfs::default", + "ipfs::_user", + "kosmos-ipfs::kredits_pinner", "kosmos-nodejs::default", "nodejs::nodejs_from_package", "nodejs::repo", + "kosmos-ipfs::firewall_swarm", + "firewall::default", + "chef-sugar::default", + "kosmos-redis::default", + "redis::server", + "redis::default", + "backup::default", + "logrotate::default", + "kosmos-base::letsencrypt", "kosmos-nginx::default", "nginx::default", "nginx::package", @@ -59,22 +68,10 @@ "nginx::commons_dir", "nginx::commons_script", "nginx::commons_conf", - "ipfs::default", - "ipfs::_user", - "kosmos-ipfs::kredits_pinner", - "firewall::default", - "chef-sugar::default", - "kosmos-redis::default", - "redis::server", - "redis::default", - "backup::default", - "logrotate::default", - "kosmos-base::letsencrypt", + "kosmos-nginx::firewall", "kosmos-hubot::_user", "sockethub::_firewall", - "kosmos-akkounts::nginx", - "git::default", - "git::package", + "kosmos-dirsrv::firewall", "ulimit::default" ], "platform": "ubuntu", @@ -107,4 +104,4 @@ "recipe[sockethub::proxy]", "recipe[kosmos-dirsrv]" ] -} +} \ No newline at end of file From 346b6540d104cd3385a41d86ae513d2ece3892f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 30 Mar 2021 12:14:40 +0200 Subject: [PATCH 301/327] Fix an undefined variable --- site-cookbooks/kosmos-dirsrv/resources/instance.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/site-cookbooks/kosmos-dirsrv/resources/instance.rb b/site-cookbooks/kosmos-dirsrv/resources/instance.rb index 8470e55..d0f80bc 100644 --- a/site-cookbooks/kosmos-dirsrv/resources/instance.rb +++ b/site-cookbooks/kosmos-dirsrv/resources/instance.rb @@ -164,6 +164,7 @@ done # Generate a Let's Encrypt cert (only if the nginx vhost exists and no cert # has been generated before. The renew cron will take care of renewing execute "letsencrypt cert for #{new_resource.hostname}" do + root_directory = "/var/www/#{new_resource.hostname}" command "certbot certonly --webroot --agree-tos --email ops@kosmos.org --webroot-path #{root_directory} --deploy-hook /etc/letsencrypt/renewal-hooks/deploy/dirsrv -d #{new_resource.hostname} -n" only_if do ::File.exist?("#{node['nginx']['dir']}/sites-enabled/#{new_resource.hostname}_certbot") && From f937e5dc68049b72f97b650a7b121406ed591784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 30 Mar 2021 13:51:20 +0200 Subject: [PATCH 302/327] Set the environment variables in the hubot-kredits dir This is meant to be executed as a script manually, not as part of Hubot. Example usage: cd /opt/hal8000_xmpp/node_modules/hubot-kredits ./scripts/review-kredits.js --start 2021-02-01 --end 2021-02-28T23:59:59Z --dry Closes #315 --- .../kosmos-hubot/recipes/hal8000_xmpp.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb index 8dae8b7..c34d44e 100644 --- a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb +++ b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb @@ -71,6 +71,22 @@ application app_path do user app_user end + file "#{app_path}/node_modules/hubot-kredits/.env" do + mode "0600" + owner app_user + group app_group + content <<-EOF +GITEA_TOKEN=#{data_bag['gitea_token']} +GITHUB_TOKEN=#{data_bag['github_token']} +KREDITS_PROVIDER_URL=#{node[app_name]['kredits']['provider_url']} +IPFS_API_HOST=#{node[app_name]['kredits']['ipfs_host']} +IPFS_API_PORT=#{node[app_name]['kredits']['ipfs_port']} +IPFS_API_PROTOCOL=#{node[app_name]['kredits']['ipfs_protocol']} +KREDITS_WALLET_PATH=../../#{node[app_name]['kredits']['wallet_path']} +KREDITS_WALLET_PASSWORD=#{data_bag['kredits_wallet_password']} + EOF + end + execute "systemctl daemon-reload" do command "systemctl daemon-reload" action :nothing @@ -102,8 +118,6 @@ application app_path do "REDIS_URL" => "redis://localhost:6379/#{app_name}", "EXPRESS_PORT" => node[app_name]['http_port'], "WEBHOOK_TOKEN" => data_bag['webhook_token'], - "GITEA_TOKEN" => data_bag['gitea_token'], - "GITHUB_TOKEN" => data_bag['github_token'], "IPFS_API_HOST" => node[app_name]['kredits']['ipfs_host'], "IPFS_API_PORT" => node[app_name]['kredits']['ipfs_port'], "IPFS_API_PROTOCOL" => node[app_name]['kredits']['ipfs_protocol'], From edf2e071e41a46545e71e7641212fa7856153b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 30 Mar 2021 13:58:55 +0200 Subject: [PATCH 303/327] Upgrade nodejs to the latest version from the repo This is possible in newer versions of the nodejs cookbook, by setting the `node["nodejs"]["package_action"]["nodejs"]` attribute to `:upgrade` --- Berksfile | 2 +- Berksfile.lock | 7 +- cookbooks/nodejs/CHANGELOG.md | 72 ++++++++++++++++--- cookbooks/nodejs/README.md | 43 ++++++++--- cookbooks/nodejs/attributes/default.rb | 13 ++-- cookbooks/nodejs/attributes/packages.rb | 10 ++- cookbooks/nodejs/attributes/repo.rb | 6 +- cookbooks/nodejs/libraries/nodejs_helper.rb | 23 +++++- cookbooks/nodejs/metadata.json | 49 ++++++++++++- cookbooks/nodejs/recipes/default.rb | 2 +- .../nodejs/recipes/nodejs_from_binary.rb | 4 +- .../nodejs/recipes/nodejs_from_package.rb | 5 +- .../nodejs/recipes/nodejs_from_source.rb | 12 ++-- cookbooks/nodejs/recipes/npm_from_source.rb | 2 +- cookbooks/nodejs/recipes/npm_packages.rb | 22 +++--- cookbooks/nodejs/recipes/repo.rb | 3 +- cookbooks/nodejs/resources/npm_package.rb | 17 ++++- .../kosmos-nodejs/recipes/default.rb | 19 ++--- 18 files changed, 234 insertions(+), 77 deletions(-) diff --git a/Berksfile b/Berksfile index 374c10b..bcbf7f6 100644 --- a/Berksfile +++ b/Berksfile @@ -34,7 +34,7 @@ cookbook 'apt', '~> 7.3.0' cookbook 'git', '~> 10.0.0' cookbook 'hostsfile', '~> 3.0.1' cookbook 'ohai', '~> 5.2.5' -cookbook 'nodejs', '~> 5.0.0' +cookbook 'nodejs', '~> 7.3.1' cookbook 'timezone_iii', '= 1.0.4' cookbook 'ark', '>= 5.0.0' cookbook 'logrotate', '= 2.2.0' diff --git a/Berksfile.lock b/Berksfile.lock index 20ece54..aa8574a 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -29,7 +29,7 @@ DEPENDENCIES ref: nginx mysql (~> 8.7.3) nginx (= 9.0.0) - nodejs (~> 5.0.0) + nodejs (~> 7.3.1) ntp (= 3.4.0) ohai (~> 5.2.5) openssl (~> 8.5.5) @@ -74,6 +74,7 @@ GRAPH mingw (>= 1.1) seven_zip (>= 0.0.0) chef-sugar (3.3.0) + chocolatey (3.0.0) compat_resource (12.19.0) composer (2.7.0) apt (>= 0.0.0) @@ -114,9 +115,9 @@ GRAPH build-essential (>= 5.0) ohai (>= 4.1.0) yum-epel (>= 0.0.0) - nodejs (5.0.0) + nodejs (7.3.1) ark (>= 2.0.2) - build-essential (>= 0.0.0) + chocolatey (>= 3.0) ntp (3.4.0) ohai (5.2.5) openssl (8.5.5) diff --git a/cookbooks/nodejs/CHANGELOG.md b/cookbooks/nodejs/CHANGELOG.md index 752de3f..fb7fd29 100644 --- a/cookbooks/nodejs/CHANGELOG.md +++ b/cookbooks/nodejs/CHANGELOG.md @@ -1,5 +1,57 @@ # NodeJS Cookbook Changelog +## 7.3.1 - *2020-12-31* + +- resolved cookstyle error: attributes/packages.rb:15:55 convention: `Layout/TrailingEmptyLines` +- resolved cookstyle error: test/cookbooks/test/recipes/resource.rb:118:1 convention: `Layout/TrailingEmptyLines` +- Enable builds for opensuse-leap-15 +- Add a library method test + +## 7.3.0 (2020-10-21) + +- Add rspec tests for the library methods +- Update the url_invalid? method to return false if it detects an invalid uri +- Add the auto_update option to the npm_package resource. Allows turning off auto_update of npm packages. +- Allow actions and options for OS package installation to be specified as attributes +- Add the live_stream parameter to the npm_package execution to get better installation diagnostics +- Add the auto_update option to the npm_package resource. Allows turning off auto_update of npm packages. +- Update testing + +## 7.2.0 (2020-10-07) + +- Verify the URI of installed packages to help determine if a good URI has been installed +- Add tests that verify npm-package installed packages +- Get the example test cookbook working +- Add support for installing node on windows + +## 7.1.0 (2020-10-01) + +- resolved cookstyle error: recipes/nodejs_from_binary.rb:19:1 refactor: `ChefCorrectness/IncorrectLibraryInjection` +- resolved cookstyle error: recipes/nodejs_from_source.rb:21:1 refactor: `ChefCorrectness/IncorrectLibraryInjection` +- resolved cookstyle error: recipes/npm_from_source.rb:21:1 refactor: `ChefCorrectness/IncorrectLibraryInjection` +- Have ark setup node and npm binaries into PATH +- Add `node_env` to `npm_package` in order to set `NODE_ENV` (useful for some packages) +- Include `npx` as a binary in addition to `npm`, it has been [included since `npm` v5.2.0](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) + +## 7.0.1 (2020-06-04) + +- Minor readme fix + +## 7.0.0 (2020-06-04) + +- Require Chef Infra Client 14+ and remove the build-essential dependency +- Updated the default to Node.js v10.16.3 +- Added compatibility with Chef Infra Client 16.2+ +- Removed Foodcritic testing +- Updated ChefSpec and Kitchen platforms +- Resolved multiple minor cookstyle issues in the cookbook +- Added a vscode editor config + +## 6.0.0 (2018-10-11) + +- Use the build_essential resource in the source install recipe instead of the build-essential::default recipe. This way we can use the new built-in build_essential resource in Chef 14+ +- Set default version to Node.js v8.12.0 + ## 5.0.0 (2017-11-15) - nodejs_npm resource has been converted to a custom resource and renamed to npm_package. The existing resource name will continue to function, but over time code should be updated for the new name. This name change has been made so we can eventually merge this resource into the chef-client. @@ -102,34 +154,34 @@ - implement installation from package on RedHat - ([@vaskas]) -## v1.1.3: +## v1.1.3 - update default version of node to 0.10.13 - and npm - v1.3.4 ([@jodosha][]) -## v1.1.2: +## v1.1.2 - update default version of node to 0.10.2 - ([@bakins]) - fully migrated to test-kitchen 1.alpha and vagrant 1.1.x/berkshelf 1.3.1 -## v1.1.1: +## v1.1.1 - update default versions to the latest: node - v0.10.0 and npm - v1.2.14 - `make_thread` is now a real attribute - ([@ChrisLundquist]) -## v1.1.0: +## v1.1.0 - rewrite the package install; remove rpm support since there are no longer any packages available anywhere - add support to install `legacy_packages` from ubuntu repo as well as the latest 0.10.x branch (this is default). -## v1.0.4: +## v1.0.4 - add support for binary installation method ([@JulesAU]) -## v1.0.3: +## v1.0.3 -- unreleased +- 7.3.1 - *2020-12-31* -## v1.0.2: +## v1.0.2 - add smartos support for package install ([@sax]) - support to compile with all processors available (default 2 if unknown) - ([@ChrisLundquist]) @@ -137,12 +189,12 @@ - ensure npm recipe honours the 'source' or 'package' setting - ([@markbirbeck]) - updated the default versions to the latest stable node/npm -## v1.0.1: +## v1.0.1 - fixed bug that prevented overwritting the node/npm versions (moved the `src_url`s as local variables instead of attributes) - ([@johannesbecker]) - updated the default versions to the latest node/npm -## v1.0.0: +## v1.0.0 - added packages installation support ([@smith]) diff --git a/cookbooks/nodejs/README.md b/cookbooks/nodejs/README.md index 6aa7fc2..bb3f27a 100644 --- a/cookbooks/nodejs/README.md +++ b/cookbooks/nodejs/README.md @@ -1,6 +1,6 @@ # [nodejs-cookbook](https://github.com/redguide/nodejs) -[![CK Version](http://img.shields.io/cookbook/v/nodejs.svg?branch=master)](https://supermarket.chef.io/cookbooks/nodejs) [![Build Status](https://img.shields.io/travis/redguide/nodejs.svg)](https://travis-ci.org/redguide/nodejs) [![Gitter chat](https://badges.gitter.im/redguide/nodejs.svg)](https://gitter.im/redguide/nodejs) +[![CK Version](http://img.shields.io/cookbook/v/nodejs.svg?branch=master)](https://supermarket.chef.io/cookbooks/nodejs) [![Build Status](https://img.shields.io/travis/redguide/nodejs.svg)](https://travis-ci.org/redguide/nodejs) Installs node.js/npm and includes a resource for managing npm packages @@ -11,23 +11,23 @@ Installs node.js/npm and includes a resource for managing npm packages - Debian/Ubuntu - RHEL/CentOS/Scientific/Amazon/Oracle - openSUSE +- Windows Note: Source installs require GCC 4.8+, which is not included on older distro releases ### Chef -- Chef 12.14+ +- Chef Infra Client 14+ ### Cookbooks -- build-essential - ark ## Usage Include the nodejs recipe to install node on your system based on the default installation method: -```chef +```ruby include_recipe "nodejs" ``` @@ -37,7 +37,7 @@ include_recipe "nodejs" Install node from packages: -```chef +```ruby node['nodejs']['install_method'] = 'package' # Not necessary because it's the default include_recipe "nodejs" # Or @@ -50,7 +50,7 @@ By default this will setup deb/rpm repositories from nodesource.com, which inclu Install node from official prebuilt binaries: -```chef +```ruby node['nodejs']['install_method'] = 'binary' include_recipe "nodejs" @@ -72,18 +72,29 @@ node.default['nodejs']['binary']['checksum'] = '0bd86f2a39221b532172c7d1acb57f0b Install node from sources: -```chef +```ruby node['nodejs']['install_method'] = 'source' include_recipe "nodejs" # Or include_recipe "nodejs::nodejs_from_source" ``` +#### Chocolatey + +Install node from chocolatey: + +```chef +node['nodejs']['install_method'] = 'chocolatey' +include_recipe "nodejs" +# Or +include_recipe "nodejs::nodejs_from_chocolatey" +``` + ## NPM Npm is included in nodejs installs by default. By default, we are using it and call it `embedded`. Adding recipe `nodejs::npm` assure you to have npm installed and let you choose install method with `node['nodejs']['npm']['install_method']` -```chef +```ruby include_recipe "nodejs::npm" ``` @@ -95,7 +106,7 @@ _Warning:_ This recipe will include the `nodejs` recipe, which by default includ note: This resource was previously named nodejs_npm. Calls to that resource name will still function, but cookbooks should be updated for the new npm_package resource name. -`npm_package` let you install npm packages from various sources: +`npm_package` lets you install npm packages from various sources: - npm registry: @@ -115,11 +126,17 @@ Packages can be installed globally (by default) or in a directory (by using `att You can specify an `NPM_TOKEN` environment variable for accessing [NPM private modules](https://docs.npmjs.com/private-modules/intro) by using `attribute :npm_token` +You can specify a `NODE_ENV` environment variable, in the case that some element of your installation depends on this by using `attribute :node_env`. E.g., using [`node-config`](https://www.npmjs.com/package/config) as part of your postinstall script. Please note that adding the `--production` option will override this to `NODE_ENV=production`. + You can append more specific options to npm command with `attribute :options` array : +You can specify auto_update as false to stop the npm install command from running and updating an installed package. Running the command will update packages within restrictions imposed by a package.json file. The default behavior is to update automatically. + - use an array of options (w/ dash), they will be added to npm call. - ex: `['--production','--force']` or `['--force-latest']` +You can specify live_stream true for the resource to have the package install information included in the chef-client log outout for better npm package diagnostics and trouble shooting. + This LWRP attempts to use vanilla npm as much as possible (no custom wrapper). ### Packages @@ -139,6 +156,7 @@ npm_package 'grunt' do path '/home/random/grunt' json true user 'random' + node_env 'staging' end npm_package 'my_private_module' do @@ -180,9 +198,12 @@ Or add packages via attributes (which accept the same attributes as the LWRP abo ## License & Authors -**Author:** Marius Ducea (marius@promethost.com) **Author:** Nathan L Smith (nlloyds@gmail.com) **Author:** Guilhem Lettron (guilhem@lettron.fr) **Author:** Barthelemy Vessemont (bvessemont@gmail.com) +**Author:** Marius Ducea (marius@promethost.com) +**Author:** Nathan L Smith (nlloyds@gmail.com) +**Author:** Guilhem Lettron (guilhem@lettron.fr) +**Author:** Barthelemy Vessemont (bvessemont@gmail.com) -**Copyright:** 2008-2017, Chef Software, Inc. +**Copyright:** Chef Software, Inc. ``` Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/cookbooks/nodejs/attributes/default.rb b/cookbooks/nodejs/attributes/default.rb index 2ab61bf..3e043c6 100644 --- a/cookbooks/nodejs/attributes/default.rb +++ b/cookbooks/nodejs/attributes/default.rb @@ -20,21 +20,24 @@ case node['platform_family'] when 'smartos', 'rhel', 'debian', 'fedora', 'mac_os_x', 'suse', 'amazon' default['nodejs']['install_method'] = 'package' +when 'windows' + default['nodejs']['install_method'] = 'chocolatey' else default['nodejs']['install_method'] = 'source' end -default['nodejs']['version'] = '6.10.2' +default['nodejs']['version'] = '10.16.3' default['nodejs']['prefix_url']['node'] = 'https://nodejs.org/dist/' +default['nodejs']['tmpdir'] = '/tmp' default['nodejs']['source']['url'] = nil # Auto generated -default['nodejs']['source']['checksum'] = '9b897dd6604d50ae5fff25fd14b1c4035462d0598735799e0cfb4f17cb6e0d19' +default['nodejs']['source']['checksum'] = 'db5a5e03a815b84a1266a4b48bb6a6d887175705f84fd2472f0d28e5e305a1f8' default['nodejs']['binary']['url'] = nil # Auto generated -default['nodejs']['binary']['checksum']['linux_x64'] = '35accd2d9ccac747eff0f236e2843bc2198ba7765e2340441d6230861bae4e1b' -default['nodejs']['binary']['checksum']['linux_x86'] = '6721221fab4e3b3a1be6573900b9e368c7a74ac1c1c3ae982e49c5583e8962e3' -default['nodejs']['binary']['checksum']['linux_arm64'] = '97de0340b6dbf38e3d995df880a94c58d403c3054676d8fc9192b83a3735f0b8' +default['nodejs']['binary']['checksum']['linux_x64'] = '2f0397bb81c1d0c9901b9aff82a933257bf60f3992227b86107111a75b9030d9' +default['nodejs']['binary']['checksum']['linux_arm64'] = '3bab16e7107092e43426e082ee9fd88ef0a43a35816f662f14563bcc5152600d' +default['nodejs']['binary']['append_env_path'] = true default['nodejs']['make_threads'] = node['cpu'] ? node['cpu']['total'].to_i : 2 diff --git a/cookbooks/nodejs/attributes/packages.rb b/cookbooks/nodejs/attributes/packages.rb index 169e28a..38754b1 100644 --- a/cookbooks/nodejs/attributes/packages.rb +++ b/cookbooks/nodejs/attributes/packages.rb @@ -2,10 +2,14 @@ include_attribute 'nodejs::default' include_attribute 'nodejs::repo' default['nodejs']['packages'] = value_for_platform_family( - 'debian' => node['nodejs']['install_repo'] ? ['nodejs'] : ['nodejs', 'npm', 'nodejs-dev'], - %w(rhel fedora amazon) => node['nodejs']['install_repo'] ? ['nodejs', 'nodejs-devel'] : ['nodejs', 'npm', 'nodejs-dev'], - 'suse' => node['platform_version'].to_i < 42 ? ['nodejs', 'nodejs-devel'] : ['nodejs4', 'npm4', 'nodejs4-devel'], + 'debian' => node['nodejs']['install_repo'] ? ['nodejs'] : %w(nodejs npm nodejs-dev), + %w(rhel fedora amazon) => node['nodejs']['install_repo'] ? %w(nodejs nodejs-devel) : %w(nodejs npm nodejs-dev), + 'suse' => node['platform_version'].to_i < 42 ? %w(nodejs10 npm10 nodejs10-devel) : %w(nodejs4 npm4 nodejs4-devel), 'mac_os_x' => ['node'], 'freebsd' => %w(node npm), 'default' => ['nodejs'] ) + +# Add options and actions by package name +default['nodejs']['package_action'] = { default: :install } +default['nodejs']['package_options'] = { default: '' } diff --git a/cookbooks/nodejs/attributes/repo.rb b/cookbooks/nodejs/attributes/repo.rb index fa95c19..6e6a344 100644 --- a/cookbooks/nodejs/attributes/repo.rb +++ b/cookbooks/nodejs/attributes/repo.rb @@ -1,12 +1,12 @@ case node['platform_family'] when 'debian' default['nodejs']['install_repo'] = true - default['nodejs']['repo'] = 'https://deb.nodesource.com/node_6.x' + default['nodejs']['repo'] = 'https://deb.nodesource.com/node_10.x' default['nodejs']['keyserver'] = 'keyserver.ubuntu.com' default['nodejs']['key'] = '1655a0ab68576280' -when 'rhel', 'amazon' +when 'rhel', 'fedora', 'amazon' default['nodejs']['install_repo'] = true release_ver = platform?('amazon') ? 6 : node['platform_version'].to_i - default['nodejs']['repo'] = "https://rpm.nodesource.com/pub_6.x/el/#{release_ver}/$basearch" + default['nodejs']['repo'] = "https://rpm.nodesource.com/pub_10.x/el/#{release_ver}/$basearch" default['nodejs']['key'] = 'https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL' end diff --git a/cookbooks/nodejs/libraries/nodejs_helper.rb b/cookbooks/nodejs/libraries/nodejs_helper.rb index d566065..f6f46c7 100644 --- a/cookbooks/nodejs/libraries/nodejs_helper.rb +++ b/cookbooks/nodejs/libraries/nodejs_helper.rb @@ -22,7 +22,25 @@ module NodeJs Mixlib::ShellOut.new("npm list #{package} -global -json", environment: environment) end - JSON.parse(cmd.run_command.stdout, max_nesting: false) + begin + JSON.parse(cmd.run_command.stdout, max_nesting: false) + rescue JSON::ParserError => e + Chef::Log.error("nodejs::library::nodejs_helper::npm_list exception #{e}") + {} + end + end + + def url_valid?(list, package) + require 'open-uri' + + begin + URI.parse(list.fetch(package, {}).fetch('resolved')) + rescue KeyError + # the package may have been installed without using a url + true + rescue URI::InvalidURIError + false + end end def version_valid?(list, package, version) @@ -34,7 +52,8 @@ module NodeJs list = npm_list(package, path, environment)['dependencies'] # Return true if package installed and installed to good version - !list.nil? && list.key?(package) && version_valid?(list, package, version) + # see if we really want to add the url check + !list.nil? && list.key?(package) && version_valid?(list, package, version) && url_valid?(list, package) end end end diff --git a/cookbooks/nodejs/metadata.json b/cookbooks/nodejs/metadata.json index 0c1afd9..44a8dc0 100644 --- a/cookbooks/nodejs/metadata.json +++ b/cookbooks/nodejs/metadata.json @@ -1 +1,48 @@ -{"name":"nodejs","version":"5.0.0","description":"Installs/Configures node.js","long_description":"# [nodejs-cookbook](https://github.com/redguide/nodejs)\n\n[![CK Version](http://img.shields.io/cookbook/v/nodejs.svg?branch=master)](https://supermarket.chef.io/cookbooks/nodejs) [![Build Status](https://img.shields.io/travis/redguide/nodejs.svg)](https://travis-ci.org/redguide/nodejs) [![Gitter chat](https://badges.gitter.im/redguide/nodejs.svg)](https://gitter.im/redguide/nodejs)\n\nInstalls node.js/npm and includes a resource for managing npm packages\n\n## Requirements\n\n### Platforms\n\n- Debian/Ubuntu\n- RHEL/CentOS/Scientific/Amazon/Oracle\n- openSUSE\n\nNote: Source installs require GCC 4.8+, which is not included on older distro releases\n\n### Chef\n\n- Chef 12.14+\n\n### Cookbooks\n\n- build-essential\n- ark\n\n## Usage\n\nInclude the nodejs recipe to install node on your system based on the default installation method:\n\n```chef\ninclude_recipe \"nodejs\"\n```\n\n### Install methods\n\n#### Package\n\nInstall node from packages:\n\n```chef\nnode['nodejs']['install_method'] = 'package' # Not necessary because it's the default\ninclude_recipe \"nodejs\"\n# Or\ninclude_recipe \"nodejs::nodejs_from_package\"\n```\n\nBy default this will setup deb/rpm repositories from nodesource.com, which include up to date NodeJS packages. If you prefer to use distro provided package you can disable this behavior by setting `node['nodejs']['install_repo']` to `false`.\n\n#### Binary\n\nInstall node from official prebuilt binaries:\n\n```chef\nnode['nodejs']['install_method'] = 'binary'\ninclude_recipe \"nodejs\"\n\n# Or\ninclude_recipe \"nodejs::nodejs_from_binary\"\n\n# Or set a specific version of nodejs to be installed\nnode.default['nodejs']['install_method'] = 'binary'\nnode.default['nodejs']['version'] = '5.9.0'\nnode.default['nodejs']['binary']['checksum'] = '99c4136cf61761fac5ac57f80544140a3793b63e00a65d4a0e528c9db328bf40'\n\n# Or fetch the binary from your own location\nnode.default['nodejs']['install_method'] = 'binary'\nnode.default['nodejs']['binary']['url'] = 'https://s3.amazonaws.com/my-bucket/node-v7.8.0-linux-x64.tar.gz'\nnode.default['nodejs']['binary']['checksum'] = '0bd86f2a39221b532172c7d1acb57f0b0cba88c7b82ea74ba9d1208b9f6f9697'\n```\n\n#### Source\n\nInstall node from sources:\n\n```chef\nnode['nodejs']['install_method'] = 'source'\ninclude_recipe \"nodejs\"\n# Or\ninclude_recipe \"nodejs::nodejs_from_source\"\n```\n\n## NPM\n\nNpm is included in nodejs installs by default. By default, we are using it and call it `embedded`. Adding recipe `nodejs::npm` assure you to have npm installed and let you choose install method with `node['nodejs']['npm']['install_method']`\n\n```chef\ninclude_recipe \"nodejs::npm\"\n```\n\n_Warning:_ This recipe will include the `nodejs` recipe, which by default includes `nodejs::nodejs_from_package` if you did not set `node['nodejs']['install_method']`.\n\n## Resources\n\n### npm_package\n\nnote: This resource was previously named nodejs_npm. Calls to that resource name will still function, but cookbooks should be updated for the new npm_package resource name.\n\n`npm_package` let you install npm packages from various sources:\n\n- npm registry:\n\n - name: `property :package`\n - version: `property :version` (optional)\n\n- url: `property :url`\n\n - for git use `git://{your_repo}`\n\n- from a json (package.json by default): `property :json`\n\n - use `true` for default\n - use a `String` to specify json file\n\nPackages can be installed globally (by default) or in a directory (by using `attribute :path`)\n\nYou can specify an `NPM_TOKEN` environment variable for accessing [NPM private modules](https://docs.npmjs.com/private-modules/intro) by using `attribute :npm_token`\n\nYou can append more specific options to npm command with `attribute :options` array :\n\n- use an array of options (w/ dash), they will be added to npm call.\n- ex: `['--production','--force']` or `['--force-latest']`\n\nThis LWRP attempts to use vanilla npm as much as possible (no custom wrapper).\n\n### Packages\n\n```ruby\nnpm_package 'express'\n\nnpm_package 'async' do\n version '0.6.2'\nend\n\nnpm_package 'request' do\n url 'github mikeal/request'\nend\n\nnpm_package 'grunt' do\n path '/home/random/grunt'\n json true\n user 'random'\nend\n\nnpm_package 'my_private_module' do\n path '/home/random/myproject' # The root path to your project, containing a package.json file\n json true\n npm_token '12345-abcde-e5d4c3b2a1'\n user 'random'\n options ['--production'] # Only install dependencies. Skip devDependencies\nend\n```\n\n[Working Examples](test/cookbooks/nodejs_test/recipes/npm.rb)\n\nOr add packages via attributes (which accept the same attributes as the LWRP above):\n\n```json\n\"nodejs\": {\n \"npm_packages\": [\n {\n \"name\": \"express\"\n },\n {\n \"name\": \"async\",\n \"version\": \"0.6.2\"\n },\n {\n \"name\": \"request\",\n \"url\": \"github mikeal/request\"\n }\n {\n \"name\": \"grunt\",\n \"path\": \"/home/random/grunt\",\n \"json\": true,\n \"user\": \"random\"\n }\n ]\n}\n```\n\n## License & Authors\n\n**Author:** Marius Ducea (marius@promethost.com) **Author:** Nathan L Smith (nlloyds@gmail.com) **Author:** Guilhem Lettron (guilhem@lettron.fr) **Author:** Barthelemy Vessemont (bvessemont@gmail.com)\n\n**Copyright:** 2008-2017, Chef Software, Inc.\n\n```\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","maintainer":"redguide","maintainer_email":"guilhem@lettron.fr","license":"Apache-2.0","platforms":{"debian":">= 0.0.0","ubuntu":">= 0.0.0","centos":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0","oracle":">= 0.0.0","amazon":">= 0.0.0","smartos":">= 0.0.0","mac_os_x":">= 0.0.0","opensuseleap":">= 0.0.0","suse":">= 0.0.0"},"dependencies":{"build-essential":">= 0.0.0","ark":">= 2.0.2"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/redguide/nodejs","issues_url":"https://github.com/redguide/nodejs/issues","chef_version":[[">= 12.14"]],"ohai_version":[]} \ No newline at end of file +{ + "name": "nodejs", + "description": "Installs/Configures node.js", + "long_description": "", + "maintainer": "redguide", + "maintainer_email": "guilhem@lettron.fr", + "license": "Apache-2.0", + "platforms": { + "debian": ">= 0.0.0", + "ubuntu": ">= 0.0.0", + "centos": ">= 0.0.0", + "redhat": ">= 0.0.0", + "scientific": ">= 0.0.0", + "oracle": ">= 0.0.0", + "amazon": ">= 0.0.0", + "smartos": ">= 0.0.0", + "mac_os_x": ">= 0.0.0", + "opensuseleap": ">= 0.0.0", + "suse": ">= 0.0.0", + "windows": ">= 0.0.0" + }, + "dependencies": { + "ark": ">= 2.0.2", + "chocolatey": ">= 3.0" + }, + "providing": { + + }, + "recipes": { + + }, + "version": "7.3.1", + "source_url": "https://github.com/redguide/nodejs", + "issues_url": "https://github.com/redguide/nodejs/issues", + "privacy": false, + "chef_versions": [ + [ + ">= 14" + ] + ], + "ohai_versions": [ + + ], + "gems": [ + + ], + "eager_load_libraries": true +} diff --git a/cookbooks/nodejs/recipes/default.rb b/cookbooks/nodejs/recipes/default.rb index a4234be..aac903e 100644 --- a/cookbooks/nodejs/recipes/default.rb +++ b/cookbooks/nodejs/recipes/default.rb @@ -1,4 +1,4 @@ -# + # Author:: Marius Ducea (marius@promethost.com) # Cookbook:: nodejs # Recipe:: default diff --git a/cookbooks/nodejs/recipes/nodejs_from_binary.rb b/cookbooks/nodejs/recipes/nodejs_from_binary.rb index 640e12c..0c05710 100644 --- a/cookbooks/nodejs/recipes/nodejs_from_binary.rb +++ b/cookbooks/nodejs/recipes/nodejs_from_binary.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Chef::Recipe.send(:include, NodeJs::Helper) +Chef::DSL::Recipe.include NodeJs::Helper # Shamelessly borrowed from http://docs.chef.io/dsl_recipe_method_platform.html # Surely there's a more canonical way to get arch? @@ -47,6 +47,7 @@ archive_name = 'nodejs-binary' binaries = ['bin/node'] binaries.push('bin/npm') if node['nodejs']['npm']['install_method'] == 'embedded' +binaries.push('bin/npx') if node['nodejs']['npm']['install_method'] == 'embedded' if node['nodejs']['binary']['url'] nodejs_bin_url = node['nodejs']['binary']['url'] @@ -61,5 +62,6 @@ ark archive_name do version node['nodejs']['version'] checksum checksum has_binaries binaries + append_env_path node['nodejs']['binary']['append_env_path'] action :install end diff --git a/cookbooks/nodejs/recipes/nodejs_from_package.rb b/cookbooks/nodejs/recipes/nodejs_from_package.rb index 6bd995d..fdd80e7 100644 --- a/cookbooks/nodejs/recipes/nodejs_from_package.rb +++ b/cookbooks/nodejs/recipes/nodejs_from_package.rb @@ -29,5 +29,8 @@ unless node['nodejs']['packages'] end node['nodejs']['packages'].each do |node_pkg| - package node_pkg + package node_pkg do + action node['nodejs']['package_action'][node_pkg] if node['nodejs']['package_action'][node_pkg] + options node['nodejs']['package_options'][node_pkg] if node['nodejs']['package_options'][node_pkg] + end end diff --git a/cookbooks/nodejs/recipes/nodejs_from_source.rb b/cookbooks/nodejs/recipes/nodejs_from_source.rb index ace91e1..865dbbf 100644 --- a/cookbooks/nodejs/recipes/nodejs_from_source.rb +++ b/cookbooks/nodejs/recipes/nodejs_from_source.rb @@ -18,15 +18,18 @@ # limitations under the License. # -Chef::Recipe.send(:include, NodeJs::Helper) +Chef::DSL::Recipe.include NodeJs::Helper -include_recipe 'build-essential' +build_essential 'install build tools' case node['platform_family'] when 'rhel', 'fedora', 'amazon' - package %w(openssl-devel tar) + # The ark resource uses and requires python2 for builds + package %w(openssl-devel python2 tar) when 'debian' - package 'libssl-dev' + package %w(libssl-dev python) +when 'suse' + package %w(python) end version = "v#{node['nodejs']['version']}/" @@ -42,4 +45,5 @@ ark archive_name do checksum node['nodejs']['source']['checksum'] make_opts ["-j #{node['nodejs']['make_threads']}"] action :install_with_make + environment(PYTHON: 'python2') end diff --git a/cookbooks/nodejs/recipes/npm_from_source.rb b/cookbooks/nodejs/recipes/npm_from_source.rb index bfe6871..d2dc71d 100644 --- a/cookbooks/nodejs/recipes/npm_from_source.rb +++ b/cookbooks/nodejs/recipes/npm_from_source.rb @@ -18,7 +18,7 @@ # limitations under the License. # -Chef::Recipe.send(:include, NodeJs::Helper) +Chef::DSL::Recipe.include NodeJs::Helper include_recipe 'nodejs::nodejs_from_source' diff --git a/cookbooks/nodejs/recipes/npm_packages.rb b/cookbooks/nodejs/recipes/npm_packages.rb index 3331fb3..ec0d3c5 100644 --- a/cookbooks/nodejs/recipes/npm_packages.rb +++ b/cookbooks/nodejs/recipes/npm_packages.rb @@ -1,11 +1,13 @@ -node['nodejs']['npm_packages'].each do |pkg| - pkg_action = pkg.key?('action') ? pkg['action'] : :install - f = npm_package "nodejs_npm-#{pkg['name']}-#{pkg_action}" do - action :nothing - package pkg['name'] +if node['nodejs'].key?('npm_packages') + node['nodejs']['npm_packages'].each do |pkg| + pkg_action = pkg.key?('action') ? pkg['action'] : :install + f = npm_package "nodejs_npm-#{pkg['name']}-#{pkg_action}" do + action :nothing + package pkg['name'] + end + pkg.each do |key, value| + f.send(key, value) unless key == 'name' || key == 'action' + end + f.action(pkg_action) end - pkg.each do |key, value| - f.send(key, value) unless key == 'name' || key == 'action' - end - f.action(pkg_action) -end if node['nodejs'].key?('npm_packages') +end diff --git a/cookbooks/nodejs/recipes/repo.rb b/cookbooks/nodejs/recipes/repo.rb index 6ac4ca2..14b98e4 100644 --- a/cookbooks/nodejs/recipes/repo.rb +++ b/cookbooks/nodejs/recipes/repo.rb @@ -6,12 +6,11 @@ when 'debian' apt_repository 'node.js' do uri node['nodejs']['repo'] - distribution node['lsb']['codename'] components ['main'] keyserver node['nodejs']['keyserver'] key node['nodejs']['key'] end -when 'rhel', 'amazon' +when 'rhel', 'fedora', 'amazon' yum_repository 'node.js' do description 'nodesource.com nodejs repository' baseurl node['nodejs']['repo'] diff --git a/cookbooks/nodejs/resources/npm_package.rb b/cookbooks/nodejs/resources/npm_package.rb index 7bd170a..71ae487 100644 --- a/cookbooks/nodejs/resources/npm_package.rb +++ b/cookbooks/nodejs/resources/npm_package.rb @@ -20,19 +20,23 @@ # resource_name :npm_package +provides :npm_package # backwards compatibility for the old resource name provides :nodejs_npm -property :package, name_property: true +property :package, String, name_property: true property :version, String property :path, String property :url, String -property :json, [String, true] +property :json, [String, true, false] property :npm_token, String property :options, Array, default: [] property :user, String property :group, String +property :live_stream, [false, true], default: false +property :node_env, String +property :auto_update, [true, false], default: true def initialize(*args) super @@ -46,7 +50,8 @@ action :install do user new_resource.user group new_resource.group environment npm_env_vars - not_if { package_installed? } + live_stream new_resource.live_stream + not_if { package_installed? && no_auto_update? } end end @@ -57,6 +62,7 @@ action :uninstall do user new_resource.user group new_resource.group environment npm_env_vars + live_stream new_resource.live_stream only_if { package_installed? } end end @@ -69,6 +75,7 @@ action_class do env_vars['HOME'] = ::Dir.home(new_resource.user) if new_resource.user env_vars['USER'] = new_resource.user if new_resource.user env_vars['NPM_TOKEN'] = new_resource.npm_token if new_resource.npm_token + env_vars['NODE_ENV'] = new_resource.node_env if new_resource.node_env env_vars end @@ -77,6 +84,10 @@ action_class do new_resource.package && npm_package_installed?(new_resource.package, new_resource.version, new_resource.path, new_resource.npm_token) end + def no_auto_update? + new_resource.package && !new_resource.auto_update + end + def npm_options options = '' options << ' -global' unless new_resource.path diff --git a/site-cookbooks/kosmos-nodejs/recipes/default.rb b/site-cookbooks/kosmos-nodejs/recipes/default.rb index 1c8773a..de8e58a 100644 --- a/site-cookbooks/kosmos-nodejs/recipes/default.rb +++ b/site-cookbooks/kosmos-nodejs/recipes/default.rb @@ -24,18 +24,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Get package for trusty when still using vivid -if node['lsb']['codename'] == "vivid" - node.override["nodejs"]["install_repo"] = false - apt_repository "node.js" do - uri "https://deb.nodesource.com/node_8.x" - distribution "trusty" - components ["main"] - keyserver node["nodejs"]["keyserver"] - key node["nodejs"]["key"] - end - include_recipe "nodejs" -else - node.override["nodejs"]["repo"] = "https://deb.nodesource.com/node_12.x" - include_recipe "nodejs::nodejs_from_package" -end +node.override["nodejs"]["repo"] = "https://deb.nodesource.com/node_12.x" +# Allows upgrading +node.override["nodejs"]["package_action"]["nodejs"] = :upgrade +include_recipe "nodejs::nodejs_from_package" From 9939e4d99399534193ba4d24c82d3de44f491204 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 9 Apr 2021 11:35:49 +0200 Subject: [PATCH 304/327] Deploy hubots from Gitea repos The repos have been moved over from GitHub. --- site-cookbooks/kosmos-hubot/recipes/botka_freenode.rb | 2 +- site-cookbooks/kosmos-hubot/recipes/hal8000.rb | 2 +- site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/site-cookbooks/kosmos-hubot/recipes/botka_freenode.rb b/site-cookbooks/kosmos-hubot/recipes/botka_freenode.rb index a974cd4..423291c 100644 --- a/site-cookbooks/kosmos-hubot/recipes/botka_freenode.rb +++ b/site-cookbooks/kosmos-hubot/recipes/botka_freenode.rb @@ -43,7 +43,7 @@ application app_path do git do user app_user group app_group - repository "https://github.com/67P/botka.git" + repository "https://gitea.kosmos.org/kosmos/botka.git" revision "master" end diff --git a/site-cookbooks/kosmos-hubot/recipes/hal8000.rb b/site-cookbooks/kosmos-hubot/recipes/hal8000.rb index b3c787e..96d4234 100644 --- a/site-cookbooks/kosmos-hubot/recipes/hal8000.rb +++ b/site-cookbooks/kosmos-hubot/recipes/hal8000.rb @@ -50,7 +50,7 @@ application hal8000_path do git do user "hubot" group "hubot" - repository "https://github.com/67P/hal8000.git" + repository "https://gitea.kosmos.org/kosmos/hal8000.git" revision "master" end diff --git a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb index c34d44e..04ce0ab 100644 --- a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb +++ b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb @@ -56,7 +56,7 @@ application app_path do git do user app_user group app_group - repository "https://github.com/67P/hal8000.git" + repository "https://gitea.kosmos.org/kosmos/hal8000.git" revision "master" end From 29e1d64ae00c156597bce9ab841f0cd263131b83 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 9 Apr 2021 11:44:36 +0200 Subject: [PATCH 305/327] Remove superfluous license headers from recipe files --- site-cookbooks/kosmos-hubot/recipes/_user.rb | 2 -- .../kosmos-hubot/recipes/botka_freenode.rb | 21 +------------------ .../kosmos-hubot/recipes/default.rb | 2 -- .../kosmos-hubot/recipes/hal8000.rb | 20 ------------------ .../kosmos-hubot/recipes/hal8000_xmpp.rb | 21 +------------------ 5 files changed, 2 insertions(+), 64 deletions(-) diff --git a/site-cookbooks/kosmos-hubot/recipes/_user.rb b/site-cookbooks/kosmos-hubot/recipes/_user.rb index d16d23d..3557dbc 100644 --- a/site-cookbooks/kosmos-hubot/recipes/_user.rb +++ b/site-cookbooks/kosmos-hubot/recipes/_user.rb @@ -2,8 +2,6 @@ # Cookbook Name:: kosmos-hubot # Recipe:: _user # -# Copyright 2019, Kosmos -# group "hubot" do gid 48268 diff --git a/site-cookbooks/kosmos-hubot/recipes/botka_freenode.rb b/site-cookbooks/kosmos-hubot/recipes/botka_freenode.rb index 423291c..bb00c33 100644 --- a/site-cookbooks/kosmos-hubot/recipes/botka_freenode.rb +++ b/site-cookbooks/kosmos-hubot/recipes/botka_freenode.rb @@ -2,26 +2,7 @@ # Cookbook Name:: kosmos-hubot # Recipe:: botka_freenode # -# Copyright:: 2019, 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. -# + app_name = "botka_freenode" app_path = "/opt/#{app_name}" app_user = "hubot" diff --git a/site-cookbooks/kosmos-hubot/recipes/default.rb b/site-cookbooks/kosmos-hubot/recipes/default.rb index 65bcf67..3a787b3 100644 --- a/site-cookbooks/kosmos-hubot/recipes/default.rb +++ b/site-cookbooks/kosmos-hubot/recipes/default.rb @@ -2,8 +2,6 @@ # Cookbook Name:: kosmos-hubot # Recipe:: default # -# Copyright 2017-2018, Kosmos -# include_recipe "kosmos-nodejs" include_recipe "kosmos-redis" diff --git a/site-cookbooks/kosmos-hubot/recipes/hal8000.rb b/site-cookbooks/kosmos-hubot/recipes/hal8000.rb index 96d4234..b8d461d 100644 --- a/site-cookbooks/kosmos-hubot/recipes/hal8000.rb +++ b/site-cookbooks/kosmos-hubot/recipes/hal8000.rb @@ -2,26 +2,6 @@ # Cookbook Name:: kosmos-hubot # Recipe:: hal8000 # -# Copyright:: 2019, 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. -# build_essential 'hal8000' do compile_time true diff --git a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb index 04ce0ab..15fbb3f 100644 --- a/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb +++ b/site-cookbooks/kosmos-hubot/recipes/hal8000_xmpp.rb @@ -2,26 +2,7 @@ # Cookbook Name:: kosmos-hubot # Recipe:: hal8000_xmpp # -# Copyright:: 2019, 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. -# + app_name = "hal8000_xmpp" app_path = "/opt/#{app_name}" app_user = "hubot" From c99f82fcd47c58d73e18b7b8c50e0b6bc28df388 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 9 Apr 2021 11:45:39 +0200 Subject: [PATCH 306/327] Update cookbook version --- site-cookbooks/kosmos-hubot/metadata.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-hubot/metadata.rb b/site-cookbooks/kosmos-hubot/metadata.rb index 0bca208..a325be4 100644 --- a/site-cookbooks/kosmos-hubot/metadata.rb +++ b/site-cookbooks/kosmos-hubot/metadata.rb @@ -4,7 +4,7 @@ maintainer_email 'mail@kosmos.org' license 'MIT' description 'Configures Kosmos chat bots' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '0.1.2' +version '0.2.0' depends 'kosmos-nodejs' depends 'kosmos-redis' From 87d50d067c1678330d606cdcc5f593938324ed27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 9 Apr 2021 13:18:35 +0200 Subject: [PATCH 307/327] Add updated upstream nodejs cookbook ... and its new dependency, chocolatey --- cookbooks/chocolatey/CHANGELOG.md | 118 +++++ cookbooks/chocolatey/README.md | 46 ++ cookbooks/chocolatey/attributes/default.rb | 12 + cookbooks/chocolatey/files/install.ps1 | 421 ++++++++++++++++++ cookbooks/chocolatey/libraries/helpers.rb | 55 +++ cookbooks/chocolatey/metadata.json | 1 + cookbooks/chocolatey/metadata.rb | 13 + cookbooks/chocolatey/recipes/default.rb | 48 ++ cookbooks/nodejs/LICENSE | 202 +++++++++ cookbooks/nodejs/chefignore | 115 +++++ cookbooks/nodejs/kitchen.dokken.yml | 88 ++++ cookbooks/nodejs/metadata.rb | 16 + .../nodejs/recipes/nodejs_from_chocolatey.rb | 24 + 13 files changed, 1159 insertions(+) create mode 100644 cookbooks/chocolatey/CHANGELOG.md create mode 100644 cookbooks/chocolatey/README.md create mode 100644 cookbooks/chocolatey/attributes/default.rb create mode 100644 cookbooks/chocolatey/files/install.ps1 create mode 100644 cookbooks/chocolatey/libraries/helpers.rb create mode 100644 cookbooks/chocolatey/metadata.json create mode 100644 cookbooks/chocolatey/metadata.rb create mode 100644 cookbooks/chocolatey/recipes/default.rb create mode 100644 cookbooks/nodejs/LICENSE create mode 100644 cookbooks/nodejs/chefignore create mode 100644 cookbooks/nodejs/kitchen.dokken.yml create mode 100644 cookbooks/nodejs/metadata.rb create mode 100644 cookbooks/nodejs/recipes/nodejs_from_chocolatey.rb diff --git a/cookbooks/chocolatey/CHANGELOG.md b/cookbooks/chocolatey/CHANGELOG.md new file mode 100644 index 0000000..9837049 --- /dev/null +++ b/cookbooks/chocolatey/CHANGELOG.md @@ -0,0 +1,118 @@ +# Changelog for Chocolatey cookbook + +## v3.0.0 (2019-07-11) + +- Add `node['chocolatey']['sensitive']` attribute (default: false) to give users the option to suppress output spam when the install.ps1 file is pushed to the machine. +- Require Chef Infra Client 12.15 or later +- Resolve minor Cookstyle warnings +- Fix `node['chocolatey']['upgrade']` to properly upgrade the `chocolatey` package +- Upgrade to the latest and greatest Chocolatey install script + +## v2.0.1 (2018-07-03) + +- Remove mentions of the package provider from the readme and metadata + +## v2.0.0 (2018-05-01) + +### Breaking Change + +The package LWRP has been removed from this cookbook. chocolatey_package was integrated into Chef 12.7, which was released in Feb 2016\. This cookbook now requires Chef 12.7 or later. + +### Other Changes + +- This cookbook no longer requires the Windows cookbook +- The install script has been updated to the latest Chocolatey install script +- Converted testing to use Delivery Local Mode from within ChefDK + +## v1.2.1 (2017-08-20) + +- Explicitly use the double-dash long option names for `--source` and `--installargs` + +## v1.2.0 (2017-05-04) + +- Change the default `['chocolatey']['upgrade']` attribute value to `false`. Preventing chocolatey from reinstalling every chef run + +## v1.1.1 (2017-04-22) + +- Fix chef 13 converges renaming conflicting `env_path` method + +## v1.1.0 (2017-01-09) + +- Update the chocolatey install script to match chocolatey.org. + +## v1.0.3 (2016-09-12) + +- Loosen windows-cookbook constraint + +## v1.0.2 (2016-08-29) + +- Ensure `chocolateyVersion` attribute is used and the correct version of chocolatey is installed. + +## v1.0.1 (2016-07-15) + +- Always execute chocolatey installer unless guard is satisfied to allow the install to retry on subsequent attempts if it fails. + +## v1.0.0 (2016-03-07) + +- No longer dependent on chocolatey.org for install script +- Removed deprecated overwriting of the current_resource and fixed visibility problem with `env_path` + +## v0.6.2 (2016-01-07) + +- Fix Chocolatey detection on chef clients older than 12.4.0 + +## v0.6.1 (2015-11-24) + +- Fix LocalJumpError on existing chocolatey package + +## v0.6.0 (2015-11-17) + +- Path Tracking. Tracking additions to the user and machine %PATH% environment and merging them into the current process. +- Downcase package name results from choco upgrade. + +## v0.5.1 (2015-11-10) + +- Prepend library include with :: in provder to fix 12.3.0 and likely other versions older than 12.5.1. +- Add backward compatibiliy to new metadata.rb attributes `source_url` and `issues_url`. + +## v0.5.0 (2015-11-09) + +- Refactored install script (and .kitchen.yml) to support installing Chocolatey in test-kitchen behind a proxy. +- Download `node['chocolatey']['Uri']` via `remote_file` resource instead of .net web client +- Set `chocolateyProxyLocation` environment variable to `Chef::Config['https_proxy']` if one is set before chocolatey install +- Changed helpers module namespacing from: `ChocolateyHelpers` to `Chocolatey::Helpers` +- Add ChefSpec unit tests +- Add ServerSpec integration tests +- Gemfile: bump foodcritic to 5.0 and Berkshelf to 4.0 +- Add ChefSpec matchers + +## v0.4.1 (2015-10-15) + +- Adds example how to install package with version +- use the vanilla script resource to bypass 64bit interpreter builder introduced in Chef 12.5 + +## v0.4.0 (2015-06-30) + +- Refactor script to download Chocolatey install script +- Chocolatey install: add proxy support +- fix for 64-bit chocolatey installs + +## v0.3.0 (2015-04-20) + +- Support for chocolatey >= 0.9.9 +- Make package name case insensitive + +## v0.2.0 (2014-09-24) + +- Allow spaces in the path to the "choco" command. +- Update tests to use Rakefile +- Support Chocolatey version 0.9.8.24+ +- Support custom command line options when installing packages + +## v0.1.0 (2014-02-20) + +- Fix and tests + +## v0.0.5 (2013-04-30) + +- Initial release diff --git a/cookbooks/chocolatey/README.md b/cookbooks/chocolatey/README.md new file mode 100644 index 0000000..7ff7882 --- /dev/null +++ b/cookbooks/chocolatey/README.md @@ -0,0 +1,46 @@ +# chocolatey Cookbook + +[![Cookbook Version](https://img.shields.io/cookbook/v/chocolatey.svg)](https://supermarket.getchef.com/cookbooks/chocolatey) ![delivery](https://github.com/chocolatey-community/chocolatey-cookbook/workflows/delivery/badge.svg) + +Install Chocolatey with the default recipe. + +## Requirements + +### Platform + +- Windows + +### Chef Infra Client + +- 12.15 or greater + +## Notes + +As of Chocolatey version [0.9.8.24](https://github.com/chocolatey/chocolatey/blob/master/CHANGELOG.md#09824-july-3-2014) the install directory for Chocolatey has changed from `C:\Chocolatey` to `C:\ProgramData\Chocolatey`. + +More information can be gotten from the [Chocolateywiki](https://github.com/chocolatey/chocolatey/wiki/DefaultChocolateyInstallReasoning). + +## Attributes + +All attributes below are pre-pended with `node['chocolatey']` + +Attribute | Description | Type | Default +---------------------------------------------------- | ----------------------------------------------------------------------------------------- | ------- | --------------------------------------------------------------------------------- +`['upgrade']` | Whether to upgrade Chocolatey if it's already installed | Boolean | false +`['install_vars']['chocolateyProxyLocation']` | HTTPS proxy for Chocolatey install script | String | Chef::Config['https_proxy'] or ENV['https_proxy'] +`['install_vars']['chocolateyProxyUser']` | Proxy user for authenticating proxies | String | nil +`['install_vars']['chocolateyProxyPassword']` | Proxy user password | String | nil +`['install_vars']['chocolateyVersion']` | Version of Chocolatey to install, e.g. '0.9.9.11' | String | nil (download latest version) +`['install_vars']['chocolateyDownloadUrl']` | Chocolatey .nupkg file URL. Use this if you host an internal copy of the chocolatey.nupkg | String | (download from chocolatey.org) +`['install_vars']['chocolateyUseWindowsCompression']`| To use built-in compression instead of 7zip (requires additional download) set to `true` | String | nil (use 7zip) +`['sensitive']` | When true, will suppress writing the contents of install.ps1 to the console | Boolean | false + +## Recipes + +- `chocolatey::default` - installs Chocolatey + +## License and Maintainer + +Maintainer:: Guilhem Lettron ([guilhem@lettron.fr](mailto:guilhem@lettron.fr)) + +License:: Apache 2.0 diff --git a/cookbooks/chocolatey/attributes/default.rb b/cookbooks/chocolatey/attributes/default.rb new file mode 100644 index 0000000..bebb93c --- /dev/null +++ b/cookbooks/chocolatey/attributes/default.rb @@ -0,0 +1,12 @@ +default['chocolatey']['upgrade'] = false +default['chocolatey']['sensitive'] = false + +# Chocolatey install.ps1 env vars. See https://chocolatey.org/install.ps1 +default['chocolatey']['install_vars'].tap do |env| + env['chocolateyProxyLocation'] = Chef::Config['https_proxy'] || ENV['https_proxy'] + env['chocolateyProxyUser'] = nil + env['chocolateyProxyPassword'] = nil + env['chocolateyVersion'] = nil + env['chocolateyDownloadUrl'] = 'https://chocolatey.org/api/v2/package/chocolatey' + env['chocolateyUseWindowsCompression'] = nil +end diff --git a/cookbooks/chocolatey/files/install.ps1 b/cookbooks/chocolatey/files/install.ps1 new file mode 100644 index 0000000..60121e7 --- /dev/null +++ b/cookbooks/chocolatey/files/install.ps1 @@ -0,0 +1,421 @@ +# ===================================================================== +# Copyright 2017 - 2020 Chocolatey Software, Inc, and the +# original authors/contributors from ChocolateyGallery +# Copyright 2011 - 2017 RealDimensions Software, LLC, and the +# original authors/contributors from ChocolateyGallery +# at https://github.com/chocolatey/chocolatey.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ===================================================================== + +# For organizational deployments of Chocolatey, please see https://chocolatey.org/docs/how-to-setup-offline-installation + +# Environment Variables, specified as $env:NAME in PowerShell.exe and %NAME% in cmd.exe. +# For explicit proxy, please set $env:chocolateyProxyLocation and optionally $env:chocolateyProxyUser and $env:chocolateyProxyPassword +# For an explicit version of Chocolatey, please set $env:chocolateyVersion = 'versionnumber' +# To target a different url for chocolatey.nupkg, please set $env:chocolateyDownloadUrl = 'full url to nupkg file' +# NOTE: $env:chocolateyDownloadUrl does not work with $env:chocolateyVersion. +# To use built-in compression instead of 7zip (requires additional download), please set $env:chocolateyUseWindowsCompression = 'true' +# To bypass the use of any proxy, please set $env:chocolateyIgnoreProxy = 'true' + +#specifically use the API to get the latest version (below) +$url = '' + +$chocolateyVersion = $env:chocolateyVersion +if (![string]::IsNullOrEmpty($chocolateyVersion)){ + Write-Output "Downloading specific version of Chocolatey: $chocolateyVersion" + $url = "https://chocolatey.org/api/v2/package/chocolatey/$chocolateyVersion" +} + +$chocolateyDownloadUrl = $env:chocolateyDownloadUrl +if (![string]::IsNullOrEmpty($chocolateyDownloadUrl)){ + Write-Output "Downloading Chocolatey from : $chocolateyDownloadUrl" + $url = "$chocolateyDownloadUrl" +} + +if ($env:TEMP -eq $null) { + $env:TEMP = Join-Path $env:SystemDrive 'temp' +} +$chocTempDir = Join-Path $env:TEMP "chocolatey" +$tempDir = Join-Path $chocTempDir "chocInstall" +if (![System.IO.Directory]::Exists($tempDir)) {[void][System.IO.Directory]::CreateDirectory($tempDir)} +$file = Join-Path $tempDir "chocolatey.zip" + +# PowerShell v2/3 caches the output stream. Then it throws errors due +# to the FileStream not being what is expected. Fixes "The OS handle's +# position is not what FileStream expected. Do not use a handle +# simultaneously in one FileStream and in Win32 code or another +# FileStream." +function Fix-PowerShellOutputRedirectionBug { + $poshMajorVerion = $PSVersionTable.PSVersion.Major + + if ($poshMajorVerion -lt 4) { + try{ + # http://www.leeholmes.com/blog/2008/07/30/workaround-the-os-handles-position-is-not-what-filestream-expected/ plus comments + $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" + $objectRef = $host.GetType().GetField("externalHostRef", $bindingFlags).GetValue($host) + $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetProperty" + $consoleHost = $objectRef.GetType().GetProperty("Value", $bindingFlags).GetValue($objectRef, @()) + [void] $consoleHost.GetType().GetProperty("IsStandardOutputRedirected", $bindingFlags).GetValue($consoleHost, @()) + $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField" + $field = $consoleHost.GetType().GetField("standardOutputWriter", $bindingFlags) + $field.SetValue($consoleHost, [Console]::Out) + [void] $consoleHost.GetType().GetProperty("IsStandardErrorRedirected", $bindingFlags).GetValue($consoleHost, @()) + $field2 = $consoleHost.GetType().GetField("standardErrorWriter", $bindingFlags) + $field2.SetValue($consoleHost, [Console]::Error) + } catch { + Write-Output "Unable to apply redirection fix." + } + } +} + +Fix-PowerShellOutputRedirectionBug + +# Attempt to set highest encryption available for SecurityProtocol. +# PowerShell will not set this by default (until maybe .NET 4.6.x). This +# will typically produce a message for PowerShell v2 (just an info +# message though) +try { + # Set TLS 1.2 (3072) as that is the minimum required by Chocolatey.org. + # Use integers because the enumeration value for TLS 1.2 won't exist + # in .NET 4.0, even though they are addressable if .NET 4.5+ is + # installed (.NET 4.5 is an in-place upgrade). + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 +} catch { + Write-Output 'Unable to set PowerShell to use TLS 1.2. This is required for contacting Chocolatey as of 03 FEB 2020. https://chocolatey.org/blog/remove-support-for-old-tls-versions. If you see underlying connection closed or trust errors, you may need to do one or more of the following: (1) upgrade to .NET Framework 4.5+ and PowerShell v3+, (2) Call [System.Net.ServicePointManager]::SecurityProtocol = 3072; in PowerShell prior to attempting installation, (3) specify internal Chocolatey package location (set $env:chocolateyDownloadUrl prior to install or host the package internally), (4) use the Download + PowerShell method of install. See https://chocolatey.org/docs/installation for all install options.' +} + +function Get-Downloader { +param ( + [string]$url + ) + + $downloader = new-object System.Net.WebClient + + $defaultCreds = [System.Net.CredentialCache]::DefaultCredentials + if ($defaultCreds -ne $null) { + $downloader.Credentials = $defaultCreds + } + + $ignoreProxy = $env:chocolateyIgnoreProxy + if ($ignoreProxy -ne $null -and $ignoreProxy -eq 'true') { + Write-Debug "Explicitly bypassing proxy due to user environment variable" + $downloader.Proxy = [System.Net.GlobalProxySelection]::GetEmptyWebProxy() + } else { + # check if a proxy is required + $explicitProxy = $env:chocolateyProxyLocation + $explicitProxyUser = $env:chocolateyProxyUser + $explicitProxyPassword = $env:chocolateyProxyPassword + if ($explicitProxy -ne $null -and $explicitProxy -ne '') { + # explicit proxy + $proxy = New-Object System.Net.WebProxy($explicitProxy, $true) + if ($explicitProxyPassword -ne $null -and $explicitProxyPassword -ne '') { + $passwd = ConvertTo-SecureString $explicitProxyPassword -AsPlainText -Force + $proxy.Credentials = New-Object System.Management.Automation.PSCredential ($explicitProxyUser, $passwd) + } + + Write-Debug "Using explicit proxy server '$explicitProxy'." + $downloader.Proxy = $proxy + + } elseif (!$downloader.Proxy.IsBypassed($url)) { + # system proxy (pass through) + $creds = $defaultCreds + if ($creds -eq $null) { + Write-Debug "Default credentials were null. Attempting backup method" + $cred = get-credential + $creds = $cred.GetNetworkCredential(); + } + + $proxyaddress = $downloader.Proxy.GetProxy($url).Authority + Write-Debug "Using system proxy server '$proxyaddress'." + $proxy = New-Object System.Net.WebProxy($proxyaddress) + $proxy.Credentials = $creds + $downloader.Proxy = $proxy + } + } + + return $downloader +} + +function Download-String { +param ( + [string]$url + ) + $downloader = Get-Downloader $url + + return $downloader.DownloadString($url) +} + +function Download-File { +param ( + [string]$url, + [string]$file + ) + #Write-Output "Downloading $url to $file" + $downloader = Get-Downloader $url + + $downloader.DownloadFile($url, $file) +} + +if ($url -eq $null -or $url -eq '') { + Write-Output "Getting latest version of the Chocolatey package for download." + $url = 'https://chocolatey.org/api/v2/Packages()?$filter=((Id%20eq%20%27chocolatey%27)%20and%20(not%20IsPrerelease))%20and%20IsLatestVersion' + [xml]$result = Download-String $url + $url = $result.feed.entry.content.src +} + +# Download the Chocolatey package +Write-Output "Getting Chocolatey from $url." +Download-File $url $file + +# Determine unzipping method +# 7zip is the most compatible so use it by default +$7zaExe = Join-Path $tempDir '7za.exe' +$unzipMethod = '7zip' +$useWindowsCompression = $env:chocolateyUseWindowsCompression +if ($useWindowsCompression -ne $null -and $useWindowsCompression -eq 'true') { + Write-Output 'Using built-in compression to unzip' + $unzipMethod = 'builtin' +} elseif (-Not (Test-Path ($7zaExe))) { + Write-Output "Downloading 7-Zip commandline tool prior to extraction." + # download 7zip + Download-File 'https://chocolatey.org/7za.exe' "$7zaExe" +} + +# unzip the package +Write-Output "Extracting $file to $tempDir..." +if ($unzipMethod -eq '7zip') { + $params = "x -o`"$tempDir`" -bd -y `"$file`"" + # use more robust Process as compared to Start-Process -Wait (which doesn't + # wait for the process to finish in PowerShell v3) + $process = New-Object System.Diagnostics.Process + $process.StartInfo = New-Object System.Diagnostics.ProcessStartInfo($7zaExe, $params) + $process.StartInfo.RedirectStandardOutput = $true + $process.StartInfo.UseShellExecute = $false + $process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden + $process.Start() | Out-Null + $process.BeginOutputReadLine() + $process.WaitForExit() + $exitCode = $process.ExitCode + $process.Dispose() + + $errorMessage = "Unable to unzip package using 7zip. Perhaps try setting `$env:chocolateyUseWindowsCompression = 'true' and call install again. Error:" + switch ($exitCode) { + 0 { break } + 1 { throw "$errorMessage Some files could not be extracted" } + 2 { throw "$errorMessage 7-Zip encountered a fatal error while extracting the files" } + 7 { throw "$errorMessage 7-Zip command line error" } + 8 { throw "$errorMessage 7-Zip out of memory" } + 255 { throw "$errorMessage Extraction cancelled by the user" } + default { throw "$errorMessage 7-Zip signalled an unknown error (code $exitCode)" } + } +} else { + if ($PSVersionTable.PSVersion.Major -lt 5) { + try { + $shellApplication = new-object -com shell.application + $zipPackage = $shellApplication.NameSpace($file) + $destinationFolder = $shellApplication.NameSpace($tempDir) + $destinationFolder.CopyHere($zipPackage.Items(),0x10) + } catch { + throw "Unable to unzip package using built-in compression. Set `$env:chocolateyUseWindowsCompression = 'false' and call install again to use 7zip to unzip. Error: `n $_" + } + } else { + Expand-Archive -Path "$file" -DestinationPath "$tempDir" -Force + } +} + +# Call chocolatey install +Write-Output "Installing chocolatey on this machine" +$toolsFolder = Join-Path $tempDir "tools" +$chocInstallPS1 = Join-Path $toolsFolder "chocolateyInstall.ps1" + +& $chocInstallPS1 + +Write-Output 'Ensuring chocolatey commands are on the path' +$chocInstallVariableName = "ChocolateyInstall" +$chocoPath = [Environment]::GetEnvironmentVariable($chocInstallVariableName) +if ($chocoPath -eq $null -or $chocoPath -eq '') { + $chocoPath = "$env:ALLUSERSPROFILE\Chocolatey" +} + +if (!(Test-Path ($chocoPath))) { + $chocoPath = "$env:SYSTEMDRIVE\ProgramData\Chocolatey" +} + +$chocoExePath = Join-Path $chocoPath 'bin' + +if ($($env:Path).ToLower().Contains($($chocoExePath).ToLower()) -eq $false) { + $env:Path = [Environment]::GetEnvironmentVariable('Path',[System.EnvironmentVariableTarget]::Machine); +} + +Write-Output 'Ensuring chocolatey.nupkg is in the lib folder' +$chocoPkgDir = Join-Path $chocoPath 'lib\chocolatey' +$nupkg = Join-Path $chocoPkgDir 'chocolatey.nupkg' +if (![System.IO.Directory]::Exists($chocoPkgDir)) { [System.IO.Directory]::CreateDirectory($chocoPkgDir); } +Copy-Item "$file" "$nupkg" -Force -ErrorAction SilentlyContinue + +# SIG # Begin signature block +# MIIcpwYJKoZIhvcNAQcCoIIcmDCCHJQCAQExDzANBglghkgBZQMEAgEFADB5Bgor +# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG +# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCDNxwdauklvXMYd +# R6F324woy4ZDT1pBVoUMp0tAZ0LTVKCCF7EwggUwMIIEGKADAgECAhAECRgbX9W7 +# ZnVTQ7VvlVAIMA0GCSqGSIb3DQEBCwUAMGUxCzAJBgNVBAYTAlVTMRUwEwYDVQQK +# EwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xJDAiBgNV +# BAMTG0RpZ2lDZXJ0IEFzc3VyZWQgSUQgUm9vdCBDQTAeFw0xMzEwMjIxMjAwMDBa +# Fw0yODEwMjIxMjAwMDBaMHIxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2Vy +# dCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xMTAvBgNVBAMTKERpZ2lD +# ZXJ0IFNIQTIgQXNzdXJlZCBJRCBDb2RlIFNpZ25pbmcgQ0EwggEiMA0GCSqGSIb3 +# DQEBAQUAA4IBDwAwggEKAoIBAQD407Mcfw4Rr2d3B9MLMUkZz9D7RZmxOttE9X/l +# qJ3bMtdx6nadBS63j/qSQ8Cl+YnUNxnXtqrwnIal2CWsDnkoOn7p0WfTxvspJ8fT +# eyOU5JEjlpB3gvmhhCNmElQzUHSxKCa7JGnCwlLyFGeKiUXULaGj6YgsIJWuHEqH +# CN8M9eJNYBi+qsSyrnAxZjNxPqxwoqvOf+l8y5Kh5TsxHM/q8grkV7tKtel05iv+ +# bMt+dDk2DZDv5LVOpKnqagqrhPOsZ061xPeM0SAlI+sIZD5SlsHyDxL0xY4PwaLo +# LFH3c7y9hbFig3NBggfkOItqcyDQD2RzPJ6fpjOp/RnfJZPRAgMBAAGjggHNMIIB +# yTASBgNVHRMBAf8ECDAGAQH/AgEAMA4GA1UdDwEB/wQEAwIBhjATBgNVHSUEDDAK +# BggrBgEFBQcDAzB5BggrBgEFBQcBAQRtMGswJAYIKwYBBQUHMAGGGGh0dHA6Ly9v +# Y3NwLmRpZ2ljZXJ0LmNvbTBDBggrBgEFBQcwAoY3aHR0cDovL2NhY2VydHMuZGln +# aWNlcnQuY29tL0RpZ2lDZXJ0QXNzdXJlZElEUm9vdENBLmNydDCBgQYDVR0fBHow +# eDA6oDigNoY0aHR0cDovL2NybDQuZGlnaWNlcnQuY29tL0RpZ2lDZXJ0QXNzdXJl +# ZElEUm9vdENBLmNybDA6oDigNoY0aHR0cDovL2NybDMuZGlnaWNlcnQuY29tL0Rp +# Z2lDZXJ0QXNzdXJlZElEUm9vdENBLmNybDBPBgNVHSAESDBGMDgGCmCGSAGG/WwA +# AgQwKjAoBggrBgEFBQcCARYcaHR0cHM6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzAK +# BghghkgBhv1sAzAdBgNVHQ4EFgQUWsS5eyoKo6XqcQPAYPkt9mV1DlgwHwYDVR0j +# BBgwFoAUReuir/SSy4IxLVGLp6chnfNtyA8wDQYJKoZIhvcNAQELBQADggEBAD7s +# DVoks/Mi0RXILHwlKXaoHV0cLToaxO8wYdd+C2D9wz0PxK+L/e8q3yBVN7Dh9tGS +# dQ9RtG6ljlriXiSBThCk7j9xjmMOE0ut119EefM2FAaK95xGTlz/kLEbBw6RFfu6 +# r7VRwo0kriTGxycqoSkoGjpxKAI8LpGjwCUR4pwUR6F6aGivm6dcIFzZcbEMj7uo +# +MUSaJ/PQMtARKUT8OZkDCUIQjKyNookAv4vcn4c10lFluhZHen6dGRrsutmQ9qz +# sIzV6Q3d9gEgzpkxYz0IGhizgZtPxpMQBvwHgfqL2vmCSfdibqFT+hKUGIUukpHq +# aGxEMrJmoecYpJpkUe8wggU6MIIEIqADAgECAhAH+0XZ9wtVKQNgl7T04UNwMA0G +# CSqGSIb3DQEBCwUAMHIxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJ +# bmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xMTAvBgNVBAMTKERpZ2lDZXJ0 +# IFNIQTIgQXNzdXJlZCBJRCBDb2RlIFNpZ25pbmcgQ0EwHhcNMTgwMzMwMDAwMDAw +# WhcNMjEwNDE0MTIwMDAwWjB3MQswCQYDVQQGEwJVUzEPMA0GA1UECBMGS2Fuc2Fz +# MQ8wDQYDVQQHEwZUb3Bla2ExIjAgBgNVBAoTGUNob2NvbGF0ZXkgU29mdHdhcmUs +# IEluYy4xIjAgBgNVBAMTGUNob2NvbGF0ZXkgU29mdHdhcmUsIEluYy4wggEiMA0G +# CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC4irdLWVJryfKSgPPCyMN+nBmxtZIm +# mTBhJMaYVJ6gtfvHcFakH7IC8TcjcEIrkK7wB/2vEJkEqiOTgbVQPZLnfX8ZAxhd +# UiJmwQHEiSwLzoo2B35ROQ9qdOsn1bYIEzDpaqm/XwYH925LLpxhr9oCkBNf5dZs +# e5bc/s1J5sQ9HRYwpb3MimmNHGpNP/YhjXX/kNFCZIv3mUadFHi+talYIN5dp6ai +# /k+qgZeL5klPdmjyIgf3JiDywCf7j5nSbm3sWarYjM5vLe/oD+eK70fez30a17Cy +# 97Jtqmdz6WUV1BcbMWeb9b8x369UJq5vt7vGwVFDOeGjwffuVHLRvWLnAgMBAAGj +# ggHFMIIBwTAfBgNVHSMEGDAWgBRaxLl7KgqjpepxA8Bg+S32ZXUOWDAdBgNVHQ4E +# FgQUqRlYCMLOvsDUS4mx9UA1avD3fvgwDgYDVR0PAQH/BAQDAgeAMBMGA1UdJQQM +# MAoGCCsGAQUFBwMDMHcGA1UdHwRwMG4wNaAzoDGGL2h0dHA6Ly9jcmwzLmRpZ2lj +# ZXJ0LmNvbS9zaGEyLWFzc3VyZWQtY3MtZzEuY3JsMDWgM6Axhi9odHRwOi8vY3Js +# NC5kaWdpY2VydC5jb20vc2hhMi1hc3N1cmVkLWNzLWcxLmNybDBMBgNVHSAERTBD +# MDcGCWCGSAGG/WwDATAqMCgGCCsGAQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2Vy +# dC5jb20vQ1BTMAgGBmeBDAEEATCBhAYIKwYBBQUHAQEEeDB2MCQGCCsGAQUFBzAB +# hhhodHRwOi8vb2NzcC5kaWdpY2VydC5jb20wTgYIKwYBBQUHMAKGQmh0dHA6Ly9j +# YWNlcnRzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydFNIQTJBc3N1cmVkSURDb2RlU2ln +# bmluZ0NBLmNydDAMBgNVHRMBAf8EAjAAMA0GCSqGSIb3DQEBCwUAA4IBAQA+ddcs +# z/NB/+V+AIlUNOVTlGDNCtn1AfvwoRZg9XMmx0/S0EKayfVFTk/x96WMQgxL+/5x +# B8Uhw6anlhbPC6bjBcIxRj/IUgR7yJ/NAykyM1x+pWvkPZV3slwe0GDPwhaqGUTU +# aG8njO4EvA682a1o7wqQFR1MIltjtuPB2gp311LLxP1k5dpUMgaA0lAfnbRr+5dc +# QOFWslkho1eBf0xlzSrhRGPy0e/IYWpl+/sEwXhD88QUkN7dSXY0fMlyGQfn6H4f +# ozBQvCk37eoE0uAtkUrWAlJxO/4Esi83ko4hokwQJHaN64/7NdNaKlG3shC9+2QM +# kY3j3BU+Ym2GZgtBMIIGajCCBVKgAwIBAgIQAwGaAjr/WLFr1tXq5hfwZjANBgkq +# hkiG9w0BAQUFADBiMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5j +# MRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSEwHwYDVQQDExhEaWdpQ2VydCBB +# c3N1cmVkIElEIENBLTEwHhcNMTQxMDIyMDAwMDAwWhcNMjQxMDIyMDAwMDAwWjBH +# MQswCQYDVQQGEwJVUzERMA8GA1UEChMIRGlnaUNlcnQxJTAjBgNVBAMTHERpZ2lD +# ZXJ0IFRpbWVzdGFtcCBSZXNwb25kZXIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw +# ggEKAoIBAQCjZF38fLPggjXg4PbGKuZJdTvMbuBTqZ8fZFnmfGt/a4ydVfiS457V +# WmNbAklQ2YPOb2bu3cuF6V+l+dSHdIhEOxnJ5fWRn8YUOawk6qhLLJGJzF4o9GS2 +# ULf1ErNzlgpno75hn67z/RJ4dQ6mWxT9RSOOhkRVfRiGBYxVh3lIRvfKDo2n3k5f +# 4qi2LVkCYYhhchhoubh87ubnNC8xd4EwH7s2AY3vJ+P3mvBMMWSN4+v6GYeofs/s +# jAw2W3rBerh4x8kGLkYQyI3oBGDbvHN0+k7Y/qpA8bLOcEaD6dpAoVk62RUJV5lW +# MJPzyWHM0AjMa+xiQpGsAsDvpPCJEY93AgMBAAGjggM1MIIDMTAOBgNVHQ8BAf8E +# BAMCB4AwDAYDVR0TAQH/BAIwADAWBgNVHSUBAf8EDDAKBggrBgEFBQcDCDCCAb8G +# A1UdIASCAbYwggGyMIIBoQYJYIZIAYb9bAcBMIIBkjAoBggrBgEFBQcCARYcaHR0 +# cHM6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzCCAWQGCCsGAQUFBwICMIIBVh6CAVIA +# QQBuAHkAIAB1AHMAZQAgAG8AZgAgAHQAaABpAHMAIABDAGUAcgB0AGkAZgBpAGMA +# YQB0AGUAIABjAG8AbgBzAHQAaQB0AHUAdABlAHMAIABhAGMAYwBlAHAAdABhAG4A +# YwBlACAAbwBmACAAdABoAGUAIABEAGkAZwBpAEMAZQByAHQAIABDAFAALwBDAFAA +# UwAgAGEAbgBkACAAdABoAGUAIABSAGUAbAB5AGkAbgBnACAAUABhAHIAdAB5ACAA +# QQBnAHIAZQBlAG0AZQBuAHQAIAB3AGgAaQBjAGgAIABsAGkAbQBpAHQAIABsAGkA +# YQBiAGkAbABpAHQAeQAgAGEAbgBkACAAYQByAGUAIABpAG4AYwBvAHIAcABvAHIA +# YQB0AGUAZAAgAGgAZQByAGUAaQBuACAAYgB5ACAAcgBlAGYAZQByAGUAbgBjAGUA +# LjALBglghkgBhv1sAxUwHwYDVR0jBBgwFoAUFQASKxOYspkH7R7for5XDStnAs0w +# HQYDVR0OBBYEFGFaTSS2STKdSip5GoNL9B6Jwcp9MH0GA1UdHwR2MHQwOKA2oDSG +# Mmh0dHA6Ly9jcmwzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEFzc3VyZWRJRENBLTEu +# Y3JsMDigNqA0hjJodHRwOi8vY3JsNC5kaWdpY2VydC5jb20vRGlnaUNlcnRBc3N1 +# cmVkSURDQS0xLmNybDB3BggrBgEFBQcBAQRrMGkwJAYIKwYBBQUHMAGGGGh0dHA6 +# Ly9vY3NwLmRpZ2ljZXJ0LmNvbTBBBggrBgEFBQcwAoY1aHR0cDovL2NhY2VydHMu +# ZGlnaWNlcnQuY29tL0RpZ2lDZXJ0QXNzdXJlZElEQ0EtMS5jcnQwDQYJKoZIhvcN +# AQEFBQADggEBAJ0lfhszTbImgVybhs4jIA+Ah+WI//+x1GosMe06FxlxF82pG7xa +# FjkAneNshORaQPveBgGMN/qbsZ0kfv4gpFetW7easGAm6mlXIV00Lx9xsIOUGQVr +# NZAQoHuXx/Y/5+IRQaa9YtnwJz04HShvOlIJ8OxwYtNiS7Dgc6aSwNOOMdgv420X +# Ewbu5AO2FKvzj0OncZ0h3RTKFV2SQdr5D4HRmXQNJsQOfxu19aDxxncGKBXp2JPl +# VRbwuwqrHNtcSCdmyKOLChzlldquxC5ZoGHd2vNtomHpigtt7BIYvfdVVEADkitr +# wlHCCkivsNRu4PQUCjob4489yq9qjXvc2EQwggbNMIIFtaADAgECAhAG/fkDlgOt +# 6gAK6z8nu7obMA0GCSqGSIb3DQEBBQUAMGUxCzAJBgNVBAYTAlVTMRUwEwYDVQQK +# EwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xJDAiBgNV +# BAMTG0RpZ2lDZXJ0IEFzc3VyZWQgSUQgUm9vdCBDQTAeFw0wNjExMTAwMDAwMDBa +# Fw0yMTExMTAwMDAwMDBaMGIxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2Vy +# dCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xITAfBgNVBAMTGERpZ2lD +# ZXJ0IEFzc3VyZWQgSUQgQ0EtMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +# ggEBAOiCLZn5ysJClaWAc0Bw0p5WVFypxNJBBo/JM/xNRZFcgZ/tLJz4FlnfnrUk +# FcKYubR3SdyJxArar8tea+2tsHEx6886QAxGTZPsi3o2CAOrDDT+GEmC/sfHMUiA +# fB6iD5IOUMnGh+s2P9gww/+m9/uizW9zI/6sVgWQ8DIhFonGcIj5BZd9o8dD3QLo +# Oz3tsUGj7T++25VIxO4es/K8DCuZ0MZdEkKB4YNugnM/JksUkK5ZZgrEjb7Szgau +# rYRvSISbT0C58Uzyr5j79s5AXVz2qPEvr+yJIvJrGGWxwXOt1/HYzx4KdFxCuGh+ +# t9V3CidWfA9ipD8yFGCV/QcEogkCAwEAAaOCA3owggN2MA4GA1UdDwEB/wQEAwIB +# hjA7BgNVHSUENDAyBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMDBggrBgEF +# BQcDBAYIKwYBBQUHAwgwggHSBgNVHSAEggHJMIIBxTCCAbQGCmCGSAGG/WwAAQQw +# ggGkMDoGCCsGAQUFBwIBFi5odHRwOi8vd3d3LmRpZ2ljZXJ0LmNvbS9zc2wtY3Bz +# LXJlcG9zaXRvcnkuaHRtMIIBZAYIKwYBBQUHAgIwggFWHoIBUgBBAG4AeQAgAHUA +# cwBlACAAbwBmACAAdABoAGkAcwAgAEMAZQByAHQAaQBmAGkAYwBhAHQAZQAgAGMA +# bwBuAHMAdABpAHQAdQB0AGUAcwAgAGEAYwBjAGUAcAB0AGEAbgBjAGUAIABvAGYA +# IAB0AGgAZQAgAEQAaQBnAGkAQwBlAHIAdAAgAEMAUAAvAEMAUABTACAAYQBuAGQA +# IAB0AGgAZQAgAFIAZQBsAHkAaQBuAGcAIABQAGEAcgB0AHkAIABBAGcAcgBlAGUA +# bQBlAG4AdAAgAHcAaABpAGMAaAAgAGwAaQBtAGkAdAAgAGwAaQBhAGIAaQBsAGkA +# dAB5ACAAYQBuAGQAIABhAHIAZQAgAGkAbgBjAG8AcgBwAG8AcgBhAHQAZQBkACAA +# aABlAHIAZQBpAG4AIABiAHkAIAByAGUAZgBlAHIAZQBuAGMAZQAuMAsGCWCGSAGG +# /WwDFTASBgNVHRMBAf8ECDAGAQH/AgEAMHkGCCsGAQUFBwEBBG0wazAkBggrBgEF +# BQcwAYYYaHR0cDovL29jc3AuZGlnaWNlcnQuY29tMEMGCCsGAQUFBzAChjdodHRw +# Oi8vY2FjZXJ0cy5kaWdpY2VydC5jb20vRGlnaUNlcnRBc3N1cmVkSURSb290Q0Eu +# Y3J0MIGBBgNVHR8EejB4MDqgOKA2hjRodHRwOi8vY3JsMy5kaWdpY2VydC5jb20v +# RGlnaUNlcnRBc3N1cmVkSURSb290Q0EuY3JsMDqgOKA2hjRodHRwOi8vY3JsNC5k +# aWdpY2VydC5jb20vRGlnaUNlcnRBc3N1cmVkSURSb290Q0EuY3JsMB0GA1UdDgQW +# BBQVABIrE5iymQftHt+ivlcNK2cCzTAfBgNVHSMEGDAWgBRF66Kv9JLLgjEtUYun +# pyGd823IDzANBgkqhkiG9w0BAQUFAAOCAQEARlA+ybcoJKc4HbZbKa9Sz1LpMUer +# Vlx71Q0LQbPv7HUfdDjyslxhopyVw1Dkgrkj0bo6hnKtOHisdV0XFzRyR4WUVtHr +# uzaEd8wkpfMEGVWp5+Pnq2LN+4stkMLA0rWUvV5PsQXSDj0aqRRbpoYxYqioM+Sb +# OafE9c4deHaUJXPkKqvPnHZL7V/CSxbkS3BMAIke/MV5vEwSV/5f4R68Al2o/vsH +# OE8Nxl2RuQ9nRc3Wg+3nkg2NsWmMT/tZ4CMP0qquAHzunEIOz5HXJ7cW7g/DvXwK +# oO4sCFWFIrjrGBpN/CohrUkxg0eVd3HcsRtLSxwQnHcUwZ1PL1qVCCkQJjGCBEww +# ggRIAgEBMIGGMHIxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMx +# GTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xMTAvBgNVBAMTKERpZ2lDZXJ0IFNI +# QTIgQXNzdXJlZCBJRCBDb2RlIFNpZ25pbmcgQ0ECEAf7Rdn3C1UpA2CXtPThQ3Aw +# DQYJYIZIAWUDBAIBBQCggYQwGAYKKwYBBAGCNwIBDDEKMAigAoAAoQKAADAZBgkq +# hkiG9w0BCQMxDAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4wDAYKKwYBBAGC +# NwIBFTAvBgkqhkiG9w0BCQQxIgQgVOMYjIaBHu7LkOhlbFNa1FFBBUFQu8BKOfZZ +# AK2CtCUwDQYJKoZIhvcNAQEBBQAEggEAccxIsQDitasvwWmCy+JQLBU4qNfShPld +# fVFg7Dte5/KpHMEd6rgw0ECoN1H8nabSf3dVMPDWGTdXzYVc+zB5Nmhlwy/9CGAs +# XmIICX16xcwYb18miih52j/m5JXT4NhTIl/+e5mF4nyoJUJeBJwIUSDuV3rHyOpE +# 90BGZXJPX2ItGbp1J//bMDECzkxRtSRDxNCQ8QlS0YBc2h+ftQFmlmb86N8XCqdB +# 32paBD1OmhH7tVB9eXQRQ9rtNLbVUB790d/IGYkHU7zlVMwxpI7wYNqgdcV9bv5z +# O9GaG8QaQXxxtIB/hH5m5wWvcberqJb2qr5Ke6U1mPV1T6G6TGdctKGCAg8wggIL +# BgkqhkiG9w0BCQYxggH8MIIB+AIBATB2MGIxCzAJBgNVBAYTAlVTMRUwEwYDVQQK +# EwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xITAfBgNV +# BAMTGERpZ2lDZXJ0IEFzc3VyZWQgSUQgQ0EtMQIQAwGaAjr/WLFr1tXq5hfwZjAJ +# BgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0B +# CQUxDxcNMjAwNDE2MDA1MDU0WjAjBgkqhkiG9w0BCQQxFgQUSnVQXFG9NidxPlpR +# Zbf9t65cx2kwDQYJKoZIhvcNAQEBBQAEggEAlpX/WR+PI6eEsARfNpjEQAdcOOG6 +# Kp1TyXOaikIUh0BI7IjCiGRr7LbXQdkZIMcl3UD8TN+GQ59RsHSsYaAQJozUW9uo +# pj3NaQJaKwHB15zHzcD1TMi18zCCPlebPmUTDsbICWBWangCST0zqU849+3tlx7E +# LLjYjs/ybeS7aQffy1Dv87ElCYWsVuoQ0n9U/7hqJ3pv88SM52xmg9IlexfOanCz +# tTAM+ke9OcXuPhoZJuDL3c8gaWxELpkokMoqX0UCgCgY4RTmJ44mC9GcYKSnpMQZ +# qFot8MXA8t5cdxN2EL8j0ASufyE0oucys4cs+yiN65GWds7YbjYC/ihG6A== +# SIG # End signature block diff --git a/cookbooks/chocolatey/libraries/helpers.rb b/cookbooks/chocolatey/libraries/helpers.rb new file mode 100644 index 0000000..1d4b36c --- /dev/null +++ b/cookbooks/chocolatey/libraries/helpers.rb @@ -0,0 +1,55 @@ +module Chocolatey + module Helpers + # include the PowershellOut module from the windows cookbook + # in case we are running an older chef client + include Chef::Mixin::PowershellOut + + # Get the ChocolateyInstall directory from the environment. + def chocolatey_install + ENV.fetch('ChocolateyInstall') { |env_var| machine_env_var(env_var) } + end + + # The Chocolatey command. + # + # Reference: https://github.com/chocolatey/chocolatey-cookbook/pull/16#issuecomment-47975896 + def chocolatey_executable + "\"#{::File.join(chocolatey_install, 'bin', 'choco')}\"" + end + + def chocolatey_lib_dir + File.join(chocolatey_install, 'lib', 'chocolatey') + end + + # Check if Chocolatey is installed + def chocolatey_installed? + return @is_chocolatey_installed if @is_chocolatey_installed + return false if chocolatey_install.nil? + # choco /? returns an exit status of -1 with chocolatey 0.9.9 => use list + cmd = Mixlib::ShellOut.new("#{chocolatey_executable} list -l chocolatey") + cmd.run_command + @is_chocolatey_installed = cmd.exitstatus == 0 + end + + # combine the local path with the user and machine paths + def environment_path(local_path) + machine = env_var('PATH', 'MACHINE').split(';') + user = env_var('PATH', 'USER').split(';') + local = local_path.split(';') + combined = local.concat(machine).concat(user).uniq.compact + combined.join(';') + end + + private + + def machine_env_var(env_var) + env_var(env_var, 'MACHINE') + end + + def env_var(env_var, scope) + env_var = powershell_out!( + "[System.Environment]::GetEnvironmentVariable('#{env_var}', '#{scope}')" + ) + env_var.stdout.chomp + end + end +end diff --git a/cookbooks/chocolatey/metadata.json b/cookbooks/chocolatey/metadata.json new file mode 100644 index 0000000..c8f12e3 --- /dev/null +++ b/cookbooks/chocolatey/metadata.json @@ -0,0 +1 @@ +{"name":"chocolatey","version":"3.0.0","description":"Install Chocolatey on Windows","long_description":"","maintainer":"Guilhem Lettron","maintainer_email":"guilhem.lettron@youscribe.com","license":"Apache-2.0","platforms":{"windows":">= 0.0.0"},"dependencies":{},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chocolatey/chocolatey-cookbook","issues_url":"https://github.com/chocolatey/chocolatey-cookbook/issues","chef_version":[[">= 12.15"]],"ohai_version":[]} \ No newline at end of file diff --git a/cookbooks/chocolatey/metadata.rb b/cookbooks/chocolatey/metadata.rb new file mode 100644 index 0000000..9d80216 --- /dev/null +++ b/cookbooks/chocolatey/metadata.rb @@ -0,0 +1,13 @@ +name 'chocolatey' +maintainer 'Guilhem Lettron' +maintainer_email 'guilhem.lettron@youscribe.com' +license 'Apache-2.0' +description 'Install Chocolatey on Windows' +version '3.0.0' + +source_url 'https://github.com/chocolatey/chocolatey-cookbook' +issues_url 'https://github.com/chocolatey/chocolatey-cookbook/issues' + +supports 'windows' + +chef_version '>= 12.15' diff --git a/cookbooks/chocolatey/recipes/default.rb b/cookbooks/chocolatey/recipes/default.rb new file mode 100644 index 0000000..f56d4c9 --- /dev/null +++ b/cookbooks/chocolatey/recipes/default.rb @@ -0,0 +1,48 @@ +# +# Cookbook:: chocolatey +# recipe:: default +# Author:: Guilhem Lettron +# +# Copyright:: 2012, Societe Publica. +# Copyright:: 2015, Doug Ireton +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +unless platform_family?('windows') + return "Chocolatey install not supported on #{node['platform_family']}" +end + +Chef::Resource.include Chocolatey::Helpers + +install_ps1 = File.join(Chef::Config['file_cache_path'], 'chocolatey-install.ps1') + +cookbook_file install_ps1 do + action :create + backup false + source 'install.ps1' + sensitive node['chocolatey']['sensitive'] +end + +powershell_script 'Install Chocolatey' do + environment node['chocolatey']['install_vars'] + cwd Chef::Config['file_cache_path'] + code install_ps1 + not_if { chocolatey_installed? } +end + +if node['chocolatey']['upgrade'] + chocolatey_package 'chocolatey' do + action :upgrade + version node['chocolatey']['install_vars']['chocolateyVersion'] + end +end diff --git a/cookbooks/nodejs/LICENSE b/cookbooks/nodejs/LICENSE new file mode 100644 index 0000000..8f71f43 --- /dev/null +++ b/cookbooks/nodejs/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/cookbooks/nodejs/chefignore b/cookbooks/nodejs/chefignore new file mode 100644 index 0000000..cc170ea --- /dev/null +++ b/cookbooks/nodejs/chefignore @@ -0,0 +1,115 @@ +# 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 +.envrc + +# EDITORS # +########### +.#* +.project +.settings +*_flymake +*_flymake.* +*.bak +*.sw[a-z] +*.tmproj +*~ +\#* +REVISION +TAGS* +tmtags +.vscode +.editorconfig + +## COMPILED ## +############## +*.class +*.com +*.dll +*.exe +*.o +*.pyc +*.so +*/rdoc/ +a.out +mkmf.log + +# Testing # +########### +.circleci/* +.codeclimate.yml +.delivery/* +.foodcritic +.kitchen* +.mdlrc +.overcommit.yml +.rspec +.rubocop.yml +.travis.yml +.watchr +.yamllint +azure-pipelines.yml +Dangerfile +examples/* +features/* +Guardfile +kitchen.yml* +mlc_config.json +Procfile +Rakefile +spec/* +test/* + +# SCM # +####### +.git +.gitattributes +.gitconfig +.github/* +.gitignore +.gitkeep +.gitmodules +.svn +*/.bzr/* +*/.git +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +Berksfile +Berksfile.lock +cookbooks/* +tmp + +# Bundler # +########### +vendor/* +Gemfile +Gemfile.lock + +# Policyfile # +############## +Policyfile.rb +Policyfile.lock.json + +# Documentation # +############# +CODE_OF_CONDUCT* +CONTRIBUTING* +documentation/* +TESTING* +UPGRADING* + +# Vagrant # +########### +.vagrant +Vagrantfile diff --git a/cookbooks/nodejs/kitchen.dokken.yml b/cookbooks/nodejs/kitchen.dokken.yml new file mode 100644 index 0000000..4047cea --- /dev/null +++ b/cookbooks/nodejs/kitchen.dokken.yml @@ -0,0 +1,88 @@ +--- +driver: + name: dokken + privileged: true # because Docker and SystemD + chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> + chef_license: accept-no-persist + +transport: + name: dokken + +provisioner: + name: dokken + deprecations_as_errors: true + +verifier: + name: inspec + +platforms: + - name: amazonlinux + driver: + image: dokken/amazonlinux + pid_one_command: /sbin/init + + - name: amazonlinux-2 + driver: + image: dokken/amazonlinux-2 + pid_one_command: /usr/lib/systemd/systemd + + - name: debian-8 + driver: + image: dokken/debian-8 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + + - name: debian-9 + driver: + image: dokken/debian-9 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + + - name: debian-10 + driver: + image: dokken/debian-10 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + + - name: centos-7 + driver: + image: dokken/centos-7 + pid_one_command: /usr/lib/systemd/systemd + + - name: centos-8 + driver: + image: dokken/centos-8 + pid_one_command: /usr/lib/systemd/systemd + + - name: fedora-latest + driver: + image: dokken/fedora-latest + pid_one_command: /usr/lib/systemd/systemd + + - name: opensuse-leap-15 + driver: + image: dokken/opensuse-leap-15 + pid_one_command: /bin/systemd + + - name: ubuntu-18.04 + driver: + image: dokken/ubuntu-18.04 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + + - name: ubuntu-20.04 + driver: + image: dokken/ubuntu-20.04 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + - RUN /usr/bin/apt-get install python -y + + - name: opensuse-leap-15 + driver: + image: dokken/opensuse-leap-15 + pid_one_command: /bin/systemd diff --git a/cookbooks/nodejs/metadata.rb b/cookbooks/nodejs/metadata.rb new file mode 100644 index 0000000..17dd723 --- /dev/null +++ b/cookbooks/nodejs/metadata.rb @@ -0,0 +1,16 @@ +name 'nodejs' +maintainer 'redguide' +maintainer_email 'guilhem@lettron.fr' +license 'Apache-2.0' +description 'Installs/Configures node.js' +source_url 'https://github.com/redguide/nodejs' +issues_url 'https://github.com/redguide/nodejs/issues' +chef_version '>= 14' +version '7.3.1' + +depends 'ark', '>= 2.0.2' +depends 'chocolatey', '>= 3.0' + +%w(debian ubuntu centos redhat scientific oracle amazon smartos mac_os_x opensuseleap suse windows).each do |os| + supports os +end diff --git a/cookbooks/nodejs/recipes/nodejs_from_chocolatey.rb b/cookbooks/nodejs/recipes/nodejs_from_chocolatey.rb new file mode 100644 index 0000000..a0fa9d0 --- /dev/null +++ b/cookbooks/nodejs/recipes/nodejs_from_chocolatey.rb @@ -0,0 +1,24 @@ +# +# Author:: Hossein Margani (hossein@margani.dev) +# Cookbook:: nodejs +# Recipe:: install_from_chocolatey +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +include_recipe 'chocolatey' + +chocolatey_package 'nodejs-lts' do + version node['nodejs']['version'] if node['nodejs']['version'] + action :upgrade +end From 7624bcec1170ef7be25b207598aa525a448f6ae4 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 10 Apr 2021 11:00:00 +0200 Subject: [PATCH 308/327] Upgrade Gitea from 1.13.1 to 1.13.7 --- site-cookbooks/kosmos_gitea/attributes/default.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos_gitea/attributes/default.rb b/site-cookbooks/kosmos_gitea/attributes/default.rb index 3f9f758..fff9277 100644 --- a/site-cookbooks/kosmos_gitea/attributes/default.rb +++ b/site-cookbooks/kosmos_gitea/attributes/default.rb @@ -1,6 +1,6 @@ -gitea_version = "1.13.1" +gitea_version = "1.13.7" 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"] = "8d017378137a2e829caaed93b4cef0975c3307b5af069e4b004d083520488d21" +node.default["kosmos_gitea"]["binary_checksum"] = "f1c0d3368d49f544183ec799005e7149fa566e3fd6eca1091d67d75b3f89f716" node.default["kosmos_gitea"]["nginx"]["domain"] = "gitea.kosmos.org" node.default["kosmos_gitea"]["working_directory"] = "/var/lib/gitea" From 6bd76ebec61c41cdabf778f95590c7035d2053d2 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 28 May 2021 14:36:07 +0200 Subject: [PATCH 309/327] Don't require old bundler version --- Gemfile.lock | 3 --- 1 file changed, 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 23e38fa..00f3c32 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -250,6 +250,3 @@ DEPENDENCIES cookstyle knife-zero test-kitchen - -BUNDLED WITH - 1.17.3 From ec75f1446c20e98d10897552e36cdad3d8392fd4 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 28 May 2021 14:40:02 +0200 Subject: [PATCH 310/327] Use chef-workstation Ruby with rbenv See https://github.com/docwhat/rbenv-chef-workstation for painlessly using Chef Workstation's Ruby with rbenv. --- .ruby-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..214e092 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +chef-workstation From bda100313e225c45a98e647559b19451bdc64cb5 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 28 May 2021 14:51:42 +0200 Subject: [PATCH 311/327] Update README Add some info about Chef Workstation and rbenv. --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 713e89b..7ff3f92 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,15 @@ -### Install dependencies +### Install Chef Workstation + +* macOS, Windows, RHEL, Ubuntu: https://docs.chef.io/workstation/install_workstation/ +* Arch Linux: https://aur.archlinux.org/packages/chef-workstation + +#### rbenv + +If you use rbenv to manage Ruby versions on your system, install the +(rbenv-chef-workstation)[https://github.com/docwhat/rbenv-chef-workstation] +plugin. + +### Install gem dependencies bundle install From d7af1a57d1906ae15e05338aab4ed7e0c886cc05 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 12 Jun 2021 14:52:36 +0200 Subject: [PATCH 312/327] Create RSK testnet VM --- clients/rsk-testnet-1.json | 4 +++ nodes/rsk-testnet-1.json | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 clients/rsk-testnet-1.json create mode 100644 nodes/rsk-testnet-1.json diff --git a/clients/rsk-testnet-1.json b/clients/rsk-testnet-1.json new file mode 100644 index 0000000..827cf39 --- /dev/null +++ b/clients/rsk-testnet-1.json @@ -0,0 +1,4 @@ +{ + "name": "rsk-testnet-1", + "public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0JU46rCyLGOi5OdeeE2M\nobUUxO+Jqd9t9bP75Pyj0uH8WaxNv1PIdWZJiR+fcE+draBV86/YLxHzOFvsnMi+\nE/qgeXLKErGtTSb12mWq0gYv/wz9uqRbtcsv40gpu2BtNv9ycdXYACB/s0ipnuUO\nX/os4YHDvWV1cshwzgsQ87ad7OdT/Nldggtp4go60TkBi49VaftiJzYqVm1ey3xz\nd7+EsQWqhQHAac6POEuPjwNuM2valf/8+nI4Uday/CiFrDDV1SffRG30sd4rJF15\nh1S1Kxyetr72EmQwIGbJuDJL7eUU7blXjg6UtTxDDsl6rYUO5s/j7wZLoFhmC854\npQIDAQAB\n-----END PUBLIC KEY-----\n" +} \ No newline at end of file diff --git a/nodes/rsk-testnet-1.json b/nodes/rsk-testnet-1.json new file mode 100644 index 0000000..dddf579 --- /dev/null +++ b/nodes/rsk-testnet-1.json @@ -0,0 +1,53 @@ +{ + "name": "rsk-testnet-1", + "normal": { + "knife_zero": { + "host": "10.1.1.136" + } + }, + "automatic": { + "fqdn": "rsk-testnet-1", + "os": "linux", + "os_version": "5.4.0-1026-kvm", + "hostname": "rsk-testnet-1", + "ipaddress": "192.168.122.196", + "roles": [ + + ], + "recipes": [ + "kosmos-base", + "kosmos-base::default", + "apt::default", + "timezone_iii::default", + "timezone_iii::debian", + "ntp::default", + "ntp::apparmor", + "kosmos-base::systemd_emails", + "apt::unattended-upgrades", + "kosmos-base::firewall", + "kosmos-postfix::default", + "postfix::default", + "postfix::_common", + "postfix::_attributes", + "postfix::sasl_auth", + "hostname::default" + ], + "platform": "ubuntu", + "platform_version": "20.04", + "cloud": null, + "chef_packages": { + "ohai": { + "version": "16.13.0", + "ohai_root": "/opt/chef/embedded/lib/ruby/gems/2.7.0/gems/ohai-16.13.0/lib/ohai" + }, + "chef": { + "version": "16.13.16", + "chef_root": "/opt/chef/embedded/lib/ruby/gems/2.7.0/gems/chef-16.13.16/lib", + "chef_effortless": null + } + } + }, + "run_list": [ + "recipe[kosmos-base]" + ] +} \ No newline at end of file From 2063f5c953ed17ced7173edf174bbaf929f2add6 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 13 Jun 2021 16:58:53 +0200 Subject: [PATCH 313/327] WIP RSK cookbook --- .gitignore | 2 + .../kosmos_rsk/.delivery/project.toml | 32 +++++ site-cookbooks/kosmos_rsk/.gitignore | 25 ++++ site-cookbooks/kosmos_rsk/Berksfile | 3 + site-cookbooks/kosmos_rsk/CHANGELOG.md | 10 ++ site-cookbooks/kosmos_rsk/LICENSE | 3 + site-cookbooks/kosmos_rsk/README.md | 4 + .../kosmos_rsk/attributes/default.rb | 1 + site-cookbooks/kosmos_rsk/chefignore | 115 ++++++++++++++++++ site-cookbooks/kosmos_rsk/kitchen.yml | 35 ++++++ site-cookbooks/kosmos_rsk/metadata.rb | 11 ++ site-cookbooks/kosmos_rsk/recipes/rskj.rb | 38 ++++++ .../kosmos_rsk/templates/rskj-preseed.cfg.erb | 6 + .../test/integration/rskj/rskj_test.rb | 23 ++++ 14 files changed, 308 insertions(+) create mode 100644 site-cookbooks/kosmos_rsk/.delivery/project.toml create mode 100644 site-cookbooks/kosmos_rsk/.gitignore create mode 100644 site-cookbooks/kosmos_rsk/Berksfile create mode 100644 site-cookbooks/kosmos_rsk/CHANGELOG.md create mode 100644 site-cookbooks/kosmos_rsk/LICENSE create mode 100644 site-cookbooks/kosmos_rsk/README.md create mode 100644 site-cookbooks/kosmos_rsk/attributes/default.rb create mode 100644 site-cookbooks/kosmos_rsk/chefignore create mode 100644 site-cookbooks/kosmos_rsk/kitchen.yml create mode 100644 site-cookbooks/kosmos_rsk/metadata.rb create mode 100644 site-cookbooks/kosmos_rsk/recipes/rskj.rb create mode 100644 site-cookbooks/kosmos_rsk/templates/rskj-preseed.cfg.erb create mode 100644 site-cookbooks/kosmos_rsk/test/integration/rskj/rskj_test.rb diff --git a/.gitignore b/.gitignore index 6bf6e4a..7883c5e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ /.chef/encrypted_data_bag_secret +.chef/chef_guid /.bundle/ /.vagrant/ +/.kitchen /nodes/vagrant-node.json diff --git a/site-cookbooks/kosmos_rsk/.delivery/project.toml b/site-cookbooks/kosmos_rsk/.delivery/project.toml new file mode 100644 index 0000000..3496f78 --- /dev/null +++ b/site-cookbooks/kosmos_rsk/.delivery/project.toml @@ -0,0 +1,32 @@ +# Delivery for Local Phases Execution +# +# This file allows you to execute test phases locally on a workstation or +# in a CI pipeline. The delivery-cli will read this file and execute the +# command(s) that are configured for each phase. You can customize them +# by just modifying the phase key on this file. +# +# By default these phases are configured for Cookbook Workflow only +# + +[local_phases] +unit = "echo skipping unit phase." +lint = "chef exec cookstyle" +# foodcritic has been deprecated in favor of cookstyle so we skip the syntax +# phase now. +syntax = "echo skipping syntax phase. Use lint phase instead." +provision = "chef exec kitchen create" +deploy = "chef exec kitchen converge" +smoke = "chef exec kitchen verify" +# The functional phase is optional, you can define it by uncommenting +# the line below and running the command: `delivery local functional` +# functional = "" +cleanup = "chef exec kitchen destroy" + +# Remote project.toml file +# +# Instead of the local phases above, you may specify a remote URI location for +# the `project.toml` file. This is useful for teams that wish to centrally +# manage the behavior of the `delivery local` command across many different +# projects. +# +# remote_file = "https://url/project.toml" \ No newline at end of file diff --git a/site-cookbooks/kosmos_rsk/.gitignore b/site-cookbooks/kosmos_rsk/.gitignore new file mode 100644 index 0000000..f1e57b8 --- /dev/null +++ b/site-cookbooks/kosmos_rsk/.gitignore @@ -0,0 +1,25 @@ +.vagrant +*~ +*# +.#* +\#*# +.*.sw[a-z] +*.un~ + +# Bundler +Gemfile.lock +gems.locked +bin/* +.bundle/* + +# test kitchen +.kitchen/ +kitchen.local.yml + +# Chef Infra +Berksfile.lock +.zero-knife.rb +Policyfile.lock.json + +.idea/ + diff --git a/site-cookbooks/kosmos_rsk/Berksfile b/site-cookbooks/kosmos_rsk/Berksfile new file mode 100644 index 0000000..34fea21 --- /dev/null +++ b/site-cookbooks/kosmos_rsk/Berksfile @@ -0,0 +1,3 @@ +source 'https://supermarket.chef.io' + +metadata diff --git a/site-cookbooks/kosmos_rsk/CHANGELOG.md b/site-cookbooks/kosmos_rsk/CHANGELOG.md new file mode 100644 index 0000000..1f6dfc0 --- /dev/null +++ b/site-cookbooks/kosmos_rsk/CHANGELOG.md @@ -0,0 +1,10 @@ +# kosmos_rsk CHANGELOG + +This file is used to list changes made in each version of the kosmos_rsk cookbook. + +## 0.1.0 + +Initial release. + +- change 0 +- change 1 diff --git a/site-cookbooks/kosmos_rsk/LICENSE b/site-cookbooks/kosmos_rsk/LICENSE new file mode 100644 index 0000000..080dee9 --- /dev/null +++ b/site-cookbooks/kosmos_rsk/LICENSE @@ -0,0 +1,3 @@ +Copyright 2021 The Authors + +All rights reserved, do not redistribute. diff --git a/site-cookbooks/kosmos_rsk/README.md b/site-cookbooks/kosmos_rsk/README.md new file mode 100644 index 0000000..2dc44e4 --- /dev/null +++ b/site-cookbooks/kosmos_rsk/README.md @@ -0,0 +1,4 @@ +# kosmos_rsk + +TODO: Enter the cookbook description here. + diff --git a/site-cookbooks/kosmos_rsk/attributes/default.rb b/site-cookbooks/kosmos_rsk/attributes/default.rb new file mode 100644 index 0000000..03904ba --- /dev/null +++ b/site-cookbooks/kosmos_rsk/attributes/default.rb @@ -0,0 +1 @@ +node.default['rskj']['network'] = 'testnet' diff --git a/site-cookbooks/kosmos_rsk/chefignore b/site-cookbooks/kosmos_rsk/chefignore new file mode 100644 index 0000000..cc170ea --- /dev/null +++ b/site-cookbooks/kosmos_rsk/chefignore @@ -0,0 +1,115 @@ +# 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 +.envrc + +# EDITORS # +########### +.#* +.project +.settings +*_flymake +*_flymake.* +*.bak +*.sw[a-z] +*.tmproj +*~ +\#* +REVISION +TAGS* +tmtags +.vscode +.editorconfig + +## COMPILED ## +############## +*.class +*.com +*.dll +*.exe +*.o +*.pyc +*.so +*/rdoc/ +a.out +mkmf.log + +# Testing # +########### +.circleci/* +.codeclimate.yml +.delivery/* +.foodcritic +.kitchen* +.mdlrc +.overcommit.yml +.rspec +.rubocop.yml +.travis.yml +.watchr +.yamllint +azure-pipelines.yml +Dangerfile +examples/* +features/* +Guardfile +kitchen.yml* +mlc_config.json +Procfile +Rakefile +spec/* +test/* + +# SCM # +####### +.git +.gitattributes +.gitconfig +.github/* +.gitignore +.gitkeep +.gitmodules +.svn +*/.bzr/* +*/.git +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +Berksfile +Berksfile.lock +cookbooks/* +tmp + +# Bundler # +########### +vendor/* +Gemfile +Gemfile.lock + +# Policyfile # +############## +Policyfile.rb +Policyfile.lock.json + +# Documentation # +############# +CODE_OF_CONDUCT* +CONTRIBUTING* +documentation/* +TESTING* +UPGRADING* + +# Vagrant # +########### +.vagrant +Vagrantfile diff --git a/site-cookbooks/kosmos_rsk/kitchen.yml b/site-cookbooks/kosmos_rsk/kitchen.yml new file mode 100644 index 0000000..2f1b756 --- /dev/null +++ b/site-cookbooks/kosmos_rsk/kitchen.yml @@ -0,0 +1,35 @@ +--- +driver: + name: vagrant + ## The forwarded_port port feature lets you connect to ports on the VM guest via + ## localhost on the host. + ## see also: https://www.vagrantup.com/docs/networking/forwarded_ports + network: + - ["forwarded_port", { guest: 4444, host: 4444 }] + +provisioner: + name: chef_zero + # You may wish to disable always updating cookbooks in CI or other testing environments. + # For example: + # always_update_cookbooks: <%= !ENV['CI'] %> + always_update_cookbooks: true + + ## product_name and product_version specifies a specific Chef product and version to install. + ## see the Chef documentation for more details: https://docs.chef.io/workstation/config_yml_kitchen/ + # product_name: chef + # product_version: 16 + +verifier: + name: inspec + +platforms: + - name: ubuntu-20.04 + +suites: + - name: rskj + run_list: + - recipe[kosmos_rsk::rskj] + verifier: + inspec_tests: + - test/integration/rskj + attributes: diff --git a/site-cookbooks/kosmos_rsk/metadata.rb b/site-cookbooks/kosmos_rsk/metadata.rb new file mode 100644 index 0000000..b5cd6c7 --- /dev/null +++ b/site-cookbooks/kosmos_rsk/metadata.rb @@ -0,0 +1,11 @@ +name 'kosmos_rsk' +maintainer 'Kosmos Developers' +maintainer_email 'ops@kosmos.org' +license 'MIT' +description 'Installs/configures RSK and related software' +version '0.1.0' +chef_version '>= 15.0' +issues_url 'https://gitea.kosmos.org/kosmos/chef/issues' +source_url 'https://gitea.kosmos.org/kosmos/chef' + +depends 'firewall' diff --git a/site-cookbooks/kosmos_rsk/recipes/rskj.rb b/site-cookbooks/kosmos_rsk/recipes/rskj.rb new file mode 100644 index 0000000..6bb98cd --- /dev/null +++ b/site-cookbooks/kosmos_rsk/recipes/rskj.rb @@ -0,0 +1,38 @@ +# +# Cookbook:: kosmos_rsk +# Recipe:: rskj +# + +group 'rsk' do + gid 888 +end + +user 'rsk' do + uid 888 + gid 888 + home '/var/lib/rsk' + shell '/sbin/nologin' +end + +apt_repository 'rskj' do + uri 'ppa:rsksmart/rskj' + key '5EED9995C84A49BC02D4F507DF10691F518C7BEA' +end + +apt_package 'rskj' do + response_file 'rskj-preseed.cfg.erb' + response_file_variables network: node['rskj']['network'] + options '--assume-yes' +end + +service "rsk" do + action [:enable, :start] +end + +include_recipe 'firewall' + +firewall_rule 'rskj' do + port [4444,50505] + protocol :tcp + command :allow +end diff --git a/site-cookbooks/kosmos_rsk/templates/rskj-preseed.cfg.erb b/site-cookbooks/kosmos_rsk/templates/rskj-preseed.cfg.erb new file mode 100644 index 0000000..d0b825b --- /dev/null +++ b/site-cookbooks/kosmos_rsk/templates/rskj-preseed.cfg.erb @@ -0,0 +1,6 @@ +#_preseed_V1 +# Do you agree to the terms of the applicable licenses? +rskj shared/accepted-rsk-license-v1-1 boolean true +# Choose a configuration environment to run your node. +# Choices: mainnet, testnet, regtest +rskj shared/config select <%= @network %> diff --git a/site-cookbooks/kosmos_rsk/test/integration/rskj/rskj_test.rb b/site-cookbooks/kosmos_rsk/test/integration/rskj/rskj_test.rb new file mode 100644 index 0000000..3f5cac9 --- /dev/null +++ b/site-cookbooks/kosmos_rsk/test/integration/rskj/rskj_test.rb @@ -0,0 +1,23 @@ +# InSpec test for recipe kosmos_rsk::rskj + +# The Chef InSpec reference, with examples and extensive documentation, can be +# found at https://docs.chef.io/inspec/resources/ + +describe user('rsk') do + it { should exist } +end + +describe package('rskj') do + it { should be_installed } + its('version') { should eq '2.2.0' } +end + +describe service('rsk') do + it { should be_enabled } + it { should be_installed } + it { should be_running } +end + +describe port(4444) do + it { should be_listening } +end From 37787ce3e6388bb1acbeb3a08741b0db9b844a76 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 13 Jun 2021 17:49:59 +0200 Subject: [PATCH 314/327] Specify package version for rskj --- site-cookbooks/kosmos_rsk/attributes/default.rb | 1 + site-cookbooks/kosmos_rsk/recipes/rskj.rb | 1 + site-cookbooks/kosmos_rsk/test/integration/rskj/rskj_test.rb | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos_rsk/attributes/default.rb b/site-cookbooks/kosmos_rsk/attributes/default.rb index 03904ba..48cc220 100644 --- a/site-cookbooks/kosmos_rsk/attributes/default.rb +++ b/site-cookbooks/kosmos_rsk/attributes/default.rb @@ -1 +1,2 @@ +node.default['rskj']['version'] = '2.2.0~focal' node.default['rskj']['network'] = 'testnet' diff --git a/site-cookbooks/kosmos_rsk/recipes/rskj.rb b/site-cookbooks/kosmos_rsk/recipes/rskj.rb index 6bb98cd..0ec4a5d 100644 --- a/site-cookbooks/kosmos_rsk/recipes/rskj.rb +++ b/site-cookbooks/kosmos_rsk/recipes/rskj.rb @@ -23,6 +23,7 @@ apt_package 'rskj' do response_file 'rskj-preseed.cfg.erb' response_file_variables network: node['rskj']['network'] options '--assume-yes' + version node['rskj']['version'] end service "rsk" do diff --git a/site-cookbooks/kosmos_rsk/test/integration/rskj/rskj_test.rb b/site-cookbooks/kosmos_rsk/test/integration/rskj/rskj_test.rb index 3f5cac9..503dcaf 100644 --- a/site-cookbooks/kosmos_rsk/test/integration/rskj/rskj_test.rb +++ b/site-cookbooks/kosmos_rsk/test/integration/rskj/rskj_test.rb @@ -9,7 +9,7 @@ end describe package('rskj') do it { should be_installed } - its('version') { should eq '2.2.0' } + its('version') { should eq '2.2.0~focal' } end describe service('rsk') do From cbdbb9c2eb83bdffb1a09f36498dc31d3b24251b Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 13 Jun 2021 17:50:32 +0200 Subject: [PATCH 315/327] Switch to dokken for testing in kitchen --- site-cookbooks/kosmos_rsk/kitchen.yml | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/site-cookbooks/kosmos_rsk/kitchen.yml b/site-cookbooks/kosmos_rsk/kitchen.yml index 2f1b756..2723336 100644 --- a/site-cookbooks/kosmos_rsk/kitchen.yml +++ b/site-cookbooks/kosmos_rsk/kitchen.yml @@ -1,18 +1,28 @@ --- driver: - name: vagrant + name: dokken + pull_platform_image: false + pull_chef_image: false + memory_limit: 2147483648 # 2GB + volumes: + # saves the apt archieves outside of the container + - /var/cache/apt/archives/:/var/cache/apt/archives/ ## The forwarded_port port feature lets you connect to ports on the VM guest via ## localhost on the host. ## see also: https://www.vagrantup.com/docs/networking/forwarded_ports - network: - - ["forwarded_port", { guest: 4444, host: 4444 }] + # network: + # - ["forwarded_port", { guest: 4444, host: 4444 }] + +transport: + name: dokken provisioner: - name: chef_zero + name: dokken + clean_dokken_sandbox: false # You may wish to disable always updating cookbooks in CI or other testing environments. # For example: # always_update_cookbooks: <%= !ENV['CI'] %> - always_update_cookbooks: true + # always_update_cookbooks: false ## product_name and product_version specifies a specific Chef product and version to install. ## see the Chef documentation for more details: https://docs.chef.io/workstation/config_yml_kitchen/ @@ -24,6 +34,13 @@ verifier: platforms: - name: ubuntu-20.04 + driver: + image: dokken/ubuntu-20.04 + privileged: true + pid_one_command: /usr/lib/systemd/systemd + intermediate_instructions: + # prevent APT from deleting the APT folder + - RUN rm /etc/apt/apt.conf.d/docker-clean suites: - name: rskj From 9a3565c11fdad1319705a5299312f9d8879a51af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 15 Jun 2021 22:21:04 +0200 Subject: [PATCH 316/327] Only keep the knife-zero gem in the Gemfile The rest is already shipped with Chef Workstation --- Gemfile | 4 - Gemfile.lock | 351 ++++++++++++++++++++++++++------------------------- 2 files changed, 176 insertions(+), 179 deletions(-) diff --git a/Gemfile b/Gemfile index c858bc7..6aafbc2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,3 @@ source 'https://rubygems.org' -gem 'chef', '~> 15.3.14' -gem 'berkshelf', '~> 7.0' gem 'knife-zero' -gem 'cookstyle' -gem 'test-kitchen' diff --git a/Gemfile.lock b/Gemfile.lock index 00f3c32..555c830 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,250 +3,251 @@ GEM specs: addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) - ast (2.4.0) - bcrypt_pbkdf (1.0.1) - berkshelf (7.0.8) - chef (>= 13.6.52) - chef-config - cleanroom (~> 1.0) - concurrent-ruby (~> 1.0) - minitar (>= 0.6) - mixlib-archive (>= 0.4, < 2.0) - mixlib-config (>= 2.2.5) - mixlib-shellout (>= 2.0, < 4.0) - octokit (~> 4.0) - retryable (>= 2.0, < 4.0) - solve (~> 4.0) - thor (>= 0.20) - builder (3.2.3) - chef (15.3.14) + builder (3.2.4) + chef (17.2.29) addressable - bcrypt_pbkdf (~> 1.0) - bundler (>= 1.10) - chef-config (= 15.3.14) + chef-config (= 17.2.29) + chef-utils (= 17.2.29) + chef-vault chef-zero (>= 14.0.11) - diff-lcs (~> 1.2, >= 1.2.4) - ed25519 (~> 1.2) + diff-lcs (>= 1.2.4, < 1.4.0) erubis (~> 2.7) - ffi (~> 1.9, >= 1.9.25) - ffi-libarchive + ffi (>= 1.5.0) + ffi-libarchive (~> 1.0, >= 1.0.3) ffi-yajl (~> 2.2) - highline (>= 1.6.9, < 2) iniparse (~> 1.4) - license-acceptance (~> 1.0, >= 1.0.5) + inspec-core (~> 4.23) + license-acceptance (>= 1.0.5, < 3) mixlib-archive (>= 0.4, < 2.0) - mixlib-authentication (~> 2.1) + mixlib-authentication (>= 2.1, < 4) mixlib-cli (>= 2.1.1, < 3.0) mixlib-log (>= 2.0.3, < 4.0) - mixlib-shellout (>= 3.0.3, < 4.0) - net-sftp (~> 2.1, >= 2.1.2) - net-ssh (>= 4.2, < 6) - net-ssh-multi (~> 1.2, >= 1.2.1) - ohai (~> 15.0) + mixlib-shellout (>= 3.1.1, < 4.0) + net-sftp (>= 2.1.2, < 4.0) + ohai (~> 17.0) plist (~> 3.2) proxifier (~> 1.0) syslog-logger (~> 1.6) - train-core (~> 3.0) - train-winrm - tty-screen (~> 0.6) - uuidtools (~> 2.1.5) - chef-config (15.3.14) + train-core (~> 3.2, >= 3.2.28) + train-winrm (>= 0.2.5) + uuidtools (>= 2.1.5, < 3.0) + chef-config (17.2.29) addressable + chef-utils (= 17.2.29) fuzzyurl mixlib-config (>= 2.2.12, < 4.0) mixlib-shellout (>= 2.0, < 4.0) tomlrb (~> 1.2) - chef-zero (14.0.13) + chef-telemetry (1.0.29) + chef-config + concurrent-ruby (~> 1.0) + chef-utils (17.2.29) + concurrent-ruby + chef-vault (4.1.0) + chef-zero (15.0.4) ffi-yajl (~> 2.2) - hashie (>= 2.0, < 4.0) + hashie (>= 2.0, < 5.0) mixlib-log (>= 2.0, < 4.0) rack (~> 2.0, >= 2.0.6) uuidtools (~> 2.1) - cleanroom (1.0.0) - concurrent-ruby (1.1.5) - cookstyle (5.7.0) - rubocop (= 0.72.0) + webrick + coderay (1.1.3) + concurrent-ruby (1.1.9) diff-lcs (1.3) - ed25519 (1.2.4) - equatable (0.6.1) + erubi (1.10.0) erubis (2.7.0) - faraday (0.17.0) + faraday (1.4.2) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.1) multipart-post (>= 1.2, < 3) - ffi (1.11.1) - ffi-libarchive (0.4.10) + ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) + faraday-excon (1.1.0) + faraday-net_http (1.0.1) + faraday-net_http_persistent (1.1.0) + faraday_middleware (1.0.0) + faraday (~> 1.0) + ffi (1.15.1) + ffi-libarchive (1.0.17) ffi (~> 1.0) - ffi-yajl (2.3.1) - libyajl2 (~> 1.2) + ffi-yajl (2.4.0) + libyajl2 (>= 1.2) fuzzyurl (0.9.0) - gssapi (1.3.0) + gssapi (1.3.1) ffi (>= 1.0.1) gyoku (1.3.1) builder (>= 2.1.2) - hashie (3.6.0) - highline (1.7.10) + hashie (4.1.0) httpclient (2.8.3) - iniparse (1.4.4) + iniparse (1.5.0) + inspec-core (4.37.25) + addressable (~> 2.4) + chef-telemetry (~> 1.0, >= 1.0.8) + faraday (>= 0.9.0, < 1.5) + faraday_middleware (~> 1.0) + hashie (>= 3.4, < 5.0) + license-acceptance (>= 0.2.13, < 3.0) + method_source (>= 0.8, < 2.0) + mixlib-log (~> 3.0) + multipart-post (~> 2.0) + parallel (~> 1.9) + parslet (>= 1.5, < 2.0) + pry (~> 0.13) + rspec (>= 3.9, < 3.11) + rspec-its (~> 1.2) + rubyzip (>= 1.2.2, < 3.0) + semverse (~> 3.0) + sslshake (~> 1.2) + thor (>= 0.20, < 2.0) + tomlrb (>= 1.2, < 2.1) + train-core (~> 3.0) + tty-prompt (~> 0.17) + tty-table (~> 0.10) ipaddress (0.8.3) - jaro_winkler (1.5.3) - json (2.2.0) - knife-zero (2.1.0) + json (2.5.1) + knife-zero (2.3.2) chef (>= 15.0) - libyajl2 (1.2.0) - license-acceptance (1.0.13) + libyajl2 (2.1.0) + license-acceptance (2.1.13) pastel (~> 0.7) - tomlrb (~> 1.2) - tty-box (~> 0.3) - tty-prompt (~> 0.18) + tomlrb (>= 1.2, < 3.0) + tty-box (~> 0.6) + tty-prompt (~> 0.20) little-plugger (1.1.4) - logging (2.2.2) + logging (2.3.0) little-plugger (~> 1.1) - multi_json (~> 1.10) - minitar (0.9) - mixlib-archive (1.0.1) + multi_json (~> 1.14) + method_source (1.0.0) + mixlib-archive (1.1.7) mixlib-log - mixlib-authentication (2.1.1) - mixlib-cli (2.1.1) - mixlib-config (3.0.1) + mixlib-authentication (3.0.10) + mixlib-cli (2.1.8) + mixlib-config (3.0.9) tomlrb - mixlib-install (3.11.21) - mixlib-shellout - mixlib-versioning - thor - mixlib-log (3.0.1) - mixlib-shellout (3.0.7) - mixlib-versioning (1.2.7) - molinillo (0.6.6) - multi_json (1.13.1) + mixlib-log (3.0.9) + mixlib-shellout (3.2.5) + chef-utils + multi_json (1.15.0) multipart-post (2.1.1) - necromancer (0.5.0) - net-scp (2.0.0) - net-ssh (>= 2.6.5, < 6.0.0) - net-sftp (2.1.2) - net-ssh (>= 2.6.5) - net-ssh (5.2.0) - net-ssh-gateway (2.0.0) - net-ssh (>= 4.0.0) - net-ssh-multi (1.2.1) - net-ssh (>= 2.6.5) - net-ssh-gateway (>= 1.2.0) + net-scp (3.0.0) + net-ssh (>= 2.6.5, < 7.0.0) + net-sftp (3.0.0) + net-ssh (>= 5.0.0, < 7.0.0) + net-ssh (6.1.0) nori (2.6.0) - octokit (4.14.0) - sawyer (~> 0.8.0, >= 0.5.3) - ohai (15.3.1) - chef-config (>= 12.8, < 16) + ohai (17.1.0) + chef-config (>= 14.12, < 18) + chef-utils (>= 16.0, < 18) ffi (~> 1.9) ffi-yajl (~> 2.2) ipaddress mixlib-cli (>= 1.7.0) mixlib-config (>= 2.0, < 4.0) mixlib-log (>= 2.0.1, < 4.0) - mixlib-shellout (>= 2.0, < 4.0) + mixlib-shellout (~> 3.2, >= 3.2.5) plist (~> 3.1) - systemu (~> 2.6.4) + train-core wmi-lite (~> 1.0) - parallel (1.18.0) - parser (2.6.5.0) - ast (~> 2.4.0) - pastel (0.7.3) - equatable (~> 0.6) + parallel (1.20.1) + parslet (1.8.2) + pastel (0.8.0) tty-color (~> 0.5) - plist (3.5.0) + plist (3.6.0) proxifier (1.0.3) - public_suffix (4.0.1) - rack (2.0.7) - rainbow (3.0.0) - retryable (3.0.4) - rubocop (0.72.0) - jaro_winkler (~> 1.5.1) - parallel (~> 1.10) - parser (>= 2.6) - rainbow (>= 2.2.2, < 4.0) - ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 1.7) - ruby-progressbar (1.10.1) - rubyntlm (0.6.2) - rubyzip (1.3.0) - sawyer (0.8.2) - addressable (>= 2.3.5) - faraday (> 0.8, < 2.0) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + public_suffix (4.0.6) + rack (2.2.3) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + rspec-core (3.10.1) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-its (1.3.0) + rspec-core (>= 3.0.0) + rspec-expectations (>= 3.0.0) + rspec-mocks (3.10.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-support (3.10.2) + ruby2_keywords (0.0.4) + rubyntlm (0.6.3) + rubyzip (2.3.0) semverse (3.0.0) - solve (4.0.2) - molinillo (~> 0.6) - semverse (>= 1.1, < 4.0) - strings (0.1.6) - strings-ansi (~> 0.1) - unicode-display_width (~> 1.5) + sslshake (1.3.1) + strings (0.2.1) + strings-ansi (~> 0.2) + unicode-display_width (>= 1.5, < 3.0) unicode_utils (~> 1.4) - strings-ansi (0.1.0) + strings-ansi (0.2.0) syslog-logger (1.6.8) - systemu (2.6.5) - test-kitchen (2.3.3) - bcrypt_pbkdf (~> 1.0) - ed25519 (~> 1.2) - license-acceptance (~> 1.0, >= 1.0.11) - mixlib-install (~> 3.6) - mixlib-shellout (>= 1.2, < 4.0) - net-scp (>= 1.1, < 3.0) - net-ssh (>= 2.9, < 6.0) - net-ssh-gateway (>= 1.2, < 3.0) - thor (~> 0.19) - winrm (~> 2.0) - winrm-elevated (~> 1.0) - winrm-fs (~> 1.1) - thor (0.20.3) - tomlrb (1.2.8) - train-core (3.1.3) + thor (1.1.0) + tomlrb (1.3.0) + train-core (3.7.2) + addressable (~> 2.5) + ffi (!= 1.13.0) json (>= 1.8, < 3.0) mixlib-shellout (>= 2.0, < 4.0) - net-scp (>= 1.2, < 3.0) - net-ssh (>= 2.9, < 6.0) - train-winrm (0.2.5) - winrm (~> 2.0) + net-scp (>= 1.2, < 4.0) + net-ssh (>= 2.9, < 7.0) + train-winrm (0.2.12) + winrm (>= 2.3.6, < 3.0) + winrm-elevated (~> 1.2.2) winrm-fs (~> 1.0) - tty-box (0.4.1) - pastel (~> 0.7.2) - strings (~> 0.1.6) + tty-box (0.7.0) + pastel (~> 0.8) + strings (~> 0.2.0) tty-cursor (~> 0.7) - tty-color (0.5.0) - tty-cursor (0.7.0) - tty-prompt (0.19.0) - necromancer (~> 0.5.0) - pastel (~> 0.7.0) - tty-reader (~> 0.6.0) - tty-reader (0.6.0) + tty-color (0.6.0) + tty-cursor (0.7.1) + tty-prompt (0.23.1) + pastel (~> 0.8) + tty-reader (~> 0.8) + tty-reader (0.9.0) tty-cursor (~> 0.7) - tty-screen (~> 0.7) - wisper (~> 2.0.0) - tty-screen (0.7.0) - unicode-display_width (1.6.0) + tty-screen (~> 0.8) + wisper (~> 2.0) + tty-screen (0.8.1) + tty-table (0.12.0) + pastel (~> 0.8) + strings (~> 0.2.0) + tty-screen (~> 0.8) + unicode-display_width (2.0.0) unicode_utils (1.4.0) - uuidtools (2.1.5) - winrm (2.3.2) + uuidtools (2.2.0) + webrick (1.7.0) + winrm (2.3.6) builder (>= 2.1.2) - erubis (~> 2.7) + erubi (~> 1.8) gssapi (~> 1.2) gyoku (~> 1.0) httpclient (~> 2.2, >= 2.2.0.2) logging (>= 1.6.1, < 3.0) nori (~> 2.0) - rubyntlm (~> 0.6.0, >= 0.6.1) - winrm-elevated (1.1.1) + rubyntlm (~> 0.6.0, >= 0.6.3) + winrm-elevated (1.2.3) + erubi (~> 1.8) winrm (~> 2.0) winrm-fs (~> 1.0) - winrm-fs (1.3.2) - erubis (~> 2.7) + winrm-fs (1.3.5) + erubi (~> 1.8) logging (>= 1.6.1, < 3.0) - rubyzip (~> 1.1) + rubyzip (~> 2.0) winrm (~> 2.0) - wisper (2.0.0) - wmi-lite (1.0.2) + wisper (2.0.1) + wmi-lite (1.0.5) PLATFORMS - ruby + x86_64-darwin-18 DEPENDENCIES - berkshelf (~> 7.0) - chef (~> 15.3.14) - cookstyle knife-zero - test-kitchen From 40a943354a54ec76e02bde57de0c9856e85ec66b Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 16 Jun 2021 11:35:40 +0200 Subject: [PATCH 317/327] Update generated docs --- site-cookbooks/kosmos_rsk/CHANGELOG.md | 3 --- site-cookbooks/kosmos_rsk/README.md | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/site-cookbooks/kosmos_rsk/CHANGELOG.md b/site-cookbooks/kosmos_rsk/CHANGELOG.md index 1f6dfc0..8f3ba6e 100644 --- a/site-cookbooks/kosmos_rsk/CHANGELOG.md +++ b/site-cookbooks/kosmos_rsk/CHANGELOG.md @@ -5,6 +5,3 @@ This file is used to list changes made in each version of the kosmos_rsk cookboo ## 0.1.0 Initial release. - -- change 0 -- change 1 diff --git a/site-cookbooks/kosmos_rsk/README.md b/site-cookbooks/kosmos_rsk/README.md index 2dc44e4..18cafc8 100644 --- a/site-cookbooks/kosmos_rsk/README.md +++ b/site-cookbooks/kosmos_rsk/README.md @@ -1,4 +1,3 @@ # kosmos_rsk -TODO: Enter the cookbook description here. - +Configures/deploys RSK-related software. From bbaeeb509951df6584baf777a8c49eb9b217fdb9 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 21 Jun 2021 17:47:30 +0200 Subject: [PATCH 318/327] Upgrade Gitea to 1.14.3 Adds a new config for the repository root directory. closes #322 --- site-cookbooks/kosmos_gitea/attributes/default.rb | 4 ++-- site-cookbooks/kosmos_gitea/recipes/default.rb | 2 ++ site-cookbooks/kosmos_gitea/templates/default/app.ini.erb | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos_gitea/attributes/default.rb b/site-cookbooks/kosmos_gitea/attributes/default.rb index fff9277..88706d9 100644 --- a/site-cookbooks/kosmos_gitea/attributes/default.rb +++ b/site-cookbooks/kosmos_gitea/attributes/default.rb @@ -1,6 +1,6 @@ -gitea_version = "1.13.7" +gitea_version = "1.14.3" 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"] = "f1c0d3368d49f544183ec799005e7149fa566e3fd6eca1091d67d75b3f89f716" +node.default["kosmos_gitea"]["binary_checksum"] = "50c25c094ae109f49e276cd00ddc48a0a240b7670e487ae1286cc116d4cdbcf2" node.default["kosmos_gitea"]["nginx"]["domain"] = "gitea.kosmos.org" node.default["kosmos_gitea"]["working_directory"] = "/var/lib/gitea" diff --git a/site-cookbooks/kosmos_gitea/recipes/default.rb b/site-cookbooks/kosmos_gitea/recipes/default.rb index ba39c3c..7700eef 100644 --- a/site-cookbooks/kosmos_gitea/recipes/default.rb +++ b/site-cookbooks/kosmos_gitea/recipes/default.rb @@ -30,6 +30,7 @@ domain = node["kosmos_gitea"]["nginx"]["domain"] working_directory = node["kosmos_gitea"]["working_directory"] git_home_directory = "/home/git" +repository_root_directory = "#{git_home_directory}/gitea-repositories" config_directory = "/etc/gitea" gitea_binary_path = "/usr/local/bin/gitea" gitea_data_bag_item = data_bag_item("credentials", "gitea") @@ -101,6 +102,7 @@ template "#{config_directory}/app.ini" do sensitive true variables working_directory: working_directory, git_home_directory: git_home_directory, + repository_root_directory: repository_root_directory, config_directory: config_directory, gitea_binary_path: gitea_binary_path, jwt_secret: jwt_secret, diff --git a/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb b/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb index 3b80419..04eab6e 100644 --- a/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb +++ b/site-cookbooks/kosmos_gitea/templates/default/app.ini.erb @@ -25,6 +25,9 @@ USER = gitea PASSWD = <%= @postgresql_password %> SSL_MODE = disable +[repository] +ROOT = <%= @repository_root_directory %> + # [indexer] # ISSUE_INDEXER_PATH = /data/gitea/indexers/issues.bleve From b6d0bafce0fe7c00946389f150ede6f5ff775cba Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 21 Jun 2021 17:50:23 +0200 Subject: [PATCH 319/327] Remove license header, improve formatting --- .../kosmos_gitea/recipes/default.rb | 42 +++++-------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/site-cookbooks/kosmos_gitea/recipes/default.rb b/site-cookbooks/kosmos_gitea/recipes/default.rb index 7700eef..22d148e 100644 --- a/site-cookbooks/kosmos_gitea/recipes/default.rb +++ b/site-cookbooks/kosmos_gitea/recipes/default.rb @@ -2,42 +2,20 @@ # 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" +domain = node["kosmos_gitea"]["nginx"]["domain"] +working_directory = node["kosmos_gitea"]["working_directory"] +git_home_directory = "/home/git" repository_root_directory = "#{git_home_directory}/gitea-repositories" -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"] +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"] # Dependency package "git" From 3dcb9e76ce532d2162031ca1fc59546e58d3c867 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 29 Jun 2021 15:53:22 +0200 Subject: [PATCH 320/327] Update node info --- nodes/bitcoin-2.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodes/bitcoin-2.json b/nodes/bitcoin-2.json index 01bd552..ee268e9 100644 --- a/nodes/bitcoin-2.json +++ b/nodes/bitcoin-2.json @@ -8,7 +8,7 @@ "automatic": { "fqdn": "bitcoin-2", "os": "linux", - "os_version": "5.4.0-58-generic", + "os_version": "5.4.0-77-generic", "hostname": "bitcoin-2", "ipaddress": "192.168.122.148", "roles": [ From f095094cf78ad966ced9a191e10f8695a6dfd07c Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 29 Jun 2021 15:53:52 +0200 Subject: [PATCH 321/327] Fix compilation issue with dotnet services Compilation fails while the executable is running. Fixed by stopping the services before upgrades. --- site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb | 1 + site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb index 562ef67..42cf3c6 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/btcpay.rb @@ -11,6 +11,7 @@ git node['btcpay']['source_dir'] do repository node['btcpay']['repo'] revision node['btcpay']['revision'] action :sync + notifies :stop, "systemd_unit[btcpayserver.service]", :immediately notifies :run, 'bash[build_btcpay]', :immediately end diff --git a/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb b/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb index 729e076..d771ede 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/nbxplorer.rb @@ -11,6 +11,7 @@ git node['nbxplorer']['source_dir'] do repository node['nbxplorer']['repo'] revision node['nbxplorer']['revision'] action :sync + notifies :stop, "systemd_unit[nbxplorer.service]", :immediately notifies :run, 'bash[build_nbxplorer]', :immediately end From a65065c793ab119f20f8af4c4207180d8137434b Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 29 Jun 2021 15:55:20 +0200 Subject: [PATCH 322/327] Upgrade all bitcoin software to latest versions --- .../kosmos-bitcoin/attributes/default.rb | 14 +++++++------- site-cookbooks/kosmos-bitcoin/recipes/source.rb | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 812f9c3..8111a5e 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -1,5 +1,5 @@ -node.default['bitcoin']['version'] = '0.21.0' -node.default['bitcoin']['checksum'] = '1a91202c62ee49fb64d57a52b8d6d01cd392fffcbef257b573800f9289655f37' +node.default['bitcoin']['version'] = '0.21.1' +node.default['bitcoin']['checksum'] = 'caff23449220cf45753f312cefede53a9eac64000bb300797916526236b6a1e0' node.default['bitcoin']['username'] = 'satoshi' node.default['bitcoin']['usergroup'] = 'bitcoin' node.default['bitcoin']['network'] = 'mainnet' @@ -26,7 +26,7 @@ node.default['bitcoin']['conf'] = { } node.default['c-lightning']['repo'] = 'https://github.com/ElementsProject/lightning' -node.default['c-lightning']['revision'] = 'v0.9.3' +node.default['c-lightning']['revision'] = 'v0.10.0' node.default['c-lightning']['source_dir'] = '/opt/c-lightning' node.default['c-lightning']['lightning_dir'] = "/home/#{node['bitcoin']['username']}/.lightning" node.default['c-lightning']['alias'] = 'ln3.kosmos.org' @@ -35,7 +35,7 @@ node.default['c-lightning']['log_level'] = 'info' node.default['c-lightning']['public_ip'] = '148.251.237.73' node.default['lnd']['repo'] = 'https://github.com/lightningnetwork/lnd' -node.default['lnd']['revision'] = 'v0.12.0-beta' +node.default['lnd']['revision'] = 'v0.13.0-beta' node.default['lnd']['source_dir'] = '/opt/lnd' node.default['lnd']['lnd_dir'] = "/home/#{node['bitcoin']['username']}/.lnd" node.default['lnd']['alias'] = 'ln2.kosmos.org' @@ -49,7 +49,7 @@ node.default['lnd']['basefee'] = '500' node.default['lnd']['feerate'] = '1' node.default['rtl']['repo'] = 'https://github.com/Ride-The-Lightning/RTL.git' -node.default['rtl']['revision'] = 'v0.10.0' +node.default['rtl']['revision'] = 'v0.11.0' node.default['rtl']['host'] = '10.1.1.163' node.default['rtl']['port'] = '3000' @@ -57,13 +57,13 @@ node.default['dotnet']['ms_packages_src_url'] = "https://packages.microsoft.com/ node.default['dotnet']['ms_packages_src_checksum'] = "4df5811c41fdded83eb9e2da9336a8dfa5594a79dc8a80133bd815f4f85b9991" node.default['nbxplorer']['repo'] = 'https://github.com/dgarage/NBXplorer' -node.default['nbxplorer']['revision'] = 'latest' +node.default['nbxplorer']['revision'] = 'v2.1.52' node.default['nbxplorer']['source_dir'] = '/opt/nbxplorer' node.default['nbxplorer']['config_path'] = "/home/#{node['bitcoin']['username']}/.nbxplorer/Main/settings.config" node.default['nbxplorer']['port'] = '24445' node.default['btcpay']['repo'] = 'https://github.com/btcpayserver/btcpayserver' -node.default['btcpay']['revision'] = 'latest' +node.default['btcpay']['revision'] = 'v1.1.2' node.default['btcpay']['source_dir'] = '/opt/btcpay' node.default['btcpay']['config_path'] = "/home/#{node['bitcoin']['username']}/.btcpayserver/Main/settings.config" node.default['btcpay']['log_path'] = "/home/#{node['bitcoin']['username']}/.btcpayserver/debug.log" diff --git a/site-cookbooks/kosmos-bitcoin/recipes/source.rb b/site-cookbooks/kosmos-bitcoin/recipes/source.rb index dfd993b..e92a80f 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/source.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/source.rb @@ -27,7 +27,6 @@ end build_essential include_recipe 'ark' - %w{ libtool autotools-dev make automake cmake curl g++-multilib libtool binutils-gold bsdmainutils pkg-config python3 patch }.each do |pkg| apt_package pkg From 2ca576468ed13cb8482d4b779ea7e703987d4626 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 30 Jun 2021 17:09:31 +0200 Subject: [PATCH 323/327] Auto-unlock LND wallet/node The latest release added a new config option for auto-unlocking the wallet/node using a password file. This changeset adds support for just that to the lnd recipe, so that nobody has to manually unlock it after reboots or service restarts. --- site-cookbooks/kosmos-bitcoin/attributes/default.rb | 5 +++-- site-cookbooks/kosmos-bitcoin/recipes/lnd.rb | 13 +++++++++++++ .../kosmos-bitcoin/templates/lnd.conf.erb | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 8111a5e..054639a 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -45,8 +45,9 @@ node.default['lnd']['public_ip'] = '148.251.237.111' node.default['lnd']['public_port'] = '9735' node.default['lnd']['port'] = '9736' node.default['lnd']['minchansize'] = '1000000' -node.default['lnd']['basefee'] = '500' -node.default['lnd']['feerate'] = '1' +node.default['lnd']['basefee'] = '1000' +node.default['lnd']['feerate'] = '50' +node.default['lnd']['auto_unlock'] = true # requires credentials/lnd data bag item node.default['rtl']['repo'] = 'https://github.com/Ride-The-Lightning/RTL.git' node.default['rtl']['revision'] = 'v0.11.0' diff --git a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb index 4e2464a..6f36bb7 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb @@ -36,6 +36,17 @@ directory lnd_dir do action :create end +if node['lnd']['auto_unlock'] + lnd_credentials = Chef::EncryptedDataBagItem.load('credentials', 'lnd') + + file "#{lnd_dir}/.unlock.txt" do + content lnd_credentials['password'] + mode '0600' + owner bitcoin_user + group bitcoin_group + end +end + template "#{lnd_dir}/lnd.conf" do source "lnd.conf.erb" owner bitcoin_user @@ -49,6 +60,8 @@ template "#{lnd_dir}/lnd.conf" do lnd_minchansize: node['lnd']['minchansize'], lnd_basefee: node['lnd']['basefee'], lnd_feerate: node['lnd']['feerate'], + lnd_dir: lnd_dir, + auto_unlock: node['lnd']['auto_unlock'], bitcoin_datadir: node['bitcoin']['datadir'], bitcoin_rpc_user: node['bitcoin']['conf']['rpcuser'], bitcoin_rpc_password: bitcoin_credentials["rpcpassword"], diff --git a/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb b/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb index b96f7d8..57c7caf 100644 --- a/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb +++ b/site-cookbooks/kosmos-bitcoin/templates/lnd.conf.erb @@ -6,6 +6,7 @@ alias=<%= @lnd_alias %> color=<%= @lnd_color %> maxpendingchannels=2 minchansize=<%= @lnd_minchansize %> +<% if @auto_unlock %>wallet-unlock-password-file=<%= @lnd_dir %>/.unlock.txt<% end %> [autopilot] autopilot.active=0 From 4bda4d7857f21cb7395b1e9a6156cbfbf1818642 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 30 Jun 2021 17:10:57 +0200 Subject: [PATCH 324/327] Install LND with all subsystems enabled This allows to run loopd and other tools. --- site-cookbooks/kosmos-bitcoin/recipes/lnd.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb index 6f36bb7..bcf1cd0 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb @@ -17,7 +17,7 @@ bash "compile_lnd" do cwd node['lnd']['source_dir'] code <<-EOH source /etc/profile.d/golang.sh - make clean && make && make install + make clean && make && make install tags="signrpc walletrpc chainrpc invoicesrpc" EOH action :nothing notifies :restart, "systemd_unit[lnd.service]", :delayed From 37873fb881de437b842fd7ed3467f12edb029376 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 1 Jul 2021 13:17:51 +0200 Subject: [PATCH 325/327] Add data bag for LND credentials --- data_bags/credentials/lnd.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 data_bags/credentials/lnd.json diff --git a/data_bags/credentials/lnd.json b/data_bags/credentials/lnd.json new file mode 100644 index 0000000..5e61dcb --- /dev/null +++ b/data_bags/credentials/lnd.json @@ -0,0 +1,10 @@ +{ + "id": "lnd", + "password": { + "encrypted_data": "etEgstimoXqyD8HhZZ7rKW0+LW3rnYAR3f++AOv6SA==\n", + "iv": "g9LA7GpA6eV1ZAJu\n", + "auth_tag": "wv67Nliq0HGqAhVeyhNO/g==\n", + "version": 3, + "cipher": "aes-256-gcm" + } +} \ No newline at end of file From 9f0b5f0e6408af50b0a4457e52a6cc33989f649d Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 1 Jul 2021 15:32:28 +0200 Subject: [PATCH 326/327] (tor) Add support for ControlPort and CookieAuthentication Allow to configure Tor to be controlled by other applications, so they can manage hidden services and such. --- site-cookbooks/tor-full/README.md | 2 ++ site-cookbooks/tor-full/templates/default/torrc.erb | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/tor-full/README.md b/site-cookbooks/tor-full/README.md index 6b2a6c4..415cbf7 100644 --- a/site-cookbooks/tor-full/README.md +++ b/site-cookbooks/tor-full/README.md @@ -32,6 +32,8 @@ The following platform families are supported: * `node['tor']['MinLogLevel']` - The minimum log level to log. Possible values include debug, info, notice, warn, and err. * `node['tor']['LogDestination']` - Where logs should be written. Valid values include a path to a file or "syslog" * `node['tor']['SocksPorts']` - List of 'address:port' to open tor socks proxy on. Defaults to disabled +* `node['tor']['ControlPort']` - The port on which Tor will listen for local connections from Tor controller applications +* `node['tor']['CookieAuthentication']` - Enable this (`true`) when using ControlPort ### Hidden Services config section diff --git a/site-cookbooks/tor-full/templates/default/torrc.erb b/site-cookbooks/tor-full/templates/default/torrc.erb index f5dd682..ca07818 100644 --- a/site-cookbooks/tor-full/templates/default/torrc.erb +++ b/site-cookbooks/tor-full/templates/default/torrc.erb @@ -65,11 +65,11 @@ DataDirectory <%= node['tor']['DataDirectory'] %> ## The port on which Tor will listen for local connections from Tor ## controller applications, as documented in control-spec.txt. -#ControlPort 9051 +<% if node['tor']['ControlPort'] %>ControlPort <%= node['tor']['ControlPort'] %><% else %>#ControlPort 9051<% end %> ## If you enable the controlport, be sure to enable one of these ## authentication methods, to prevent attackers from accessing it. #HashedControlPassword 16:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C -#CookieAuthentication 1 +<% if node['tor']['CookieAuthentication'] %>CookieAuthentication 1<% else %>#CookieAuthentication 1<% end %> ############### This section is just for location-hidden services ### From b7af04e8be59a223ee315ff06380fc5309ca116a Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 1 Jul 2021 15:34:06 +0200 Subject: [PATCH 327/327] Support Tor connections for LND Adds basics for general Tor support in bitcoin recipes, and specific support for Tor to the lnd recipe. --- nodes/bitcoin-2.json | 5 ++++- site-cookbooks/kosmos-bitcoin/attributes/default.rb | 3 +++ site-cookbooks/kosmos-bitcoin/metadata.rb | 1 + site-cookbooks/kosmos-bitcoin/recipes/lnd.rb | 10 +++++++++- site-cookbooks/kosmos-bitcoin/recipes/source.rb | 8 ++++++++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/nodes/bitcoin-2.json b/nodes/bitcoin-2.json index ee268e9..1a71313 100644 --- a/nodes/bitcoin-2.json +++ b/nodes/bitcoin-2.json @@ -26,6 +26,8 @@ "kosmos-bitcoin::dotnet", "kosmos-bitcoin::nbxplorer", "kosmos-bitcoin::btcpay", + "tor-full", + "tor-full::default", "apt::default", "timezone_iii::default", "timezone_iii::debian", @@ -82,6 +84,7 @@ "recipe[kosmos-bitcoin::c-lightning]", "recipe[kosmos-bitcoin::lnd]", "recipe[kosmos-bitcoin::rtl]", - "role[btcpay]" + "role[btcpay]", + "recipe[tor-full]" ] } \ No newline at end of file diff --git a/site-cookbooks/kosmos-bitcoin/attributes/default.rb b/site-cookbooks/kosmos-bitcoin/attributes/default.rb index 054639a..1cf96a2 100644 --- a/site-cookbooks/kosmos-bitcoin/attributes/default.rb +++ b/site-cookbooks/kosmos-bitcoin/attributes/default.rb @@ -25,6 +25,9 @@ node.default['bitcoin']['conf'] = { zmqpubrawtx: 'tcp://127.0.0.1:8338' } +# Also enables Tor for LND +node.default['bitcoin']['tor_enabled'] = true + node.default['c-lightning']['repo'] = 'https://github.com/ElementsProject/lightning' node.default['c-lightning']['revision'] = 'v0.10.0' node.default['c-lightning']['source_dir'] = '/opt/c-lightning' diff --git a/site-cookbooks/kosmos-bitcoin/metadata.rb b/site-cookbooks/kosmos-bitcoin/metadata.rb index fe6cd0c..c8bb476 100644 --- a/site-cookbooks/kosmos-bitcoin/metadata.rb +++ b/site-cookbooks/kosmos-bitcoin/metadata.rb @@ -26,3 +26,4 @@ depends 'kosmos-nginx' depends 'kosmos-nodejs' depends 'firewall' depends 'application_javascript' +depends 'tor-full' diff --git a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb index bcf1cd0..47bbe7e 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/lnd.rb @@ -71,6 +71,9 @@ template "#{lnd_dir}/lnd.conf" do notifies :restart, "systemd_unit[lnd.service]", :delayed end +exec_flags = "" +exec_flags += "--tor.active --tor.v3" if node['bitcoin']['tor_enabled'] + systemd_unit 'lnd.service' do content({ Unit: { @@ -83,7 +86,7 @@ systemd_unit 'lnd.service' do User: bitcoin_user, Group: bitcoin_group, Type: 'simple', - ExecStart: '/opt/go/bin/lnd', + ExecStart: "/opt/go/bin/lnd #{exec_flags}", Restart: 'always', RestartSec: '30', TimeoutSec: '240', @@ -108,3 +111,8 @@ firewall_rule 'lnd' do protocol :tcp command :allow end + +if node['bitcoin']['tor_enabled'] + node.override['tor']['ControlPort'] = 9051 + node.override['tor']['CookieAuthentication'] = true +end diff --git a/site-cookbooks/kosmos-bitcoin/recipes/source.rb b/site-cookbooks/kosmos-bitcoin/recipes/source.rb index e92a80f..51df04f 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/source.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/source.rb @@ -81,6 +81,14 @@ user bitcoin_user do shell "/bin/bash" end +if node['bitcoin']['tor_enabled'] + group 'debian-tor' do + action :modify + members bitcoin_user + append true + end +end + [bitcoin_datadir, bitcoin_walletdir].each do |path| directory path do owner bitcoin_user