Compare commits
2 Commits
f88354c67c
...
61accc05c2
| Author | SHA1 | Date | |
|---|---|---|---|
|
61accc05c2
|
|||
|
5892e3c0ab
|
@@ -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",
|
||||
|
||||
@@ -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'
|
||||
@@ -48,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'
|
||||
|
||||
@@ -22,3 +22,4 @@ chef_version '>= 14.0'
|
||||
depends 'ark'
|
||||
depends 'git'
|
||||
depends 'golang'
|
||||
depends 'kosmos-nginx'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 %>
|
||||
@@ -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 -%>
|
||||
Reference in New Issue
Block a user